Reputation: 175
I am new to mongodb please excuse my language. I have deployed backend of the application to heroku and tring to connect it with Mongodb. The steps I followed as below.
I created a project on mongodb.com, added a user(with role atlasAdmin@admin), added IP.
I connected it to MongoDB Compass and added the data required using compass
I used connect your application
and saved below string in heroku config enviornment variable after editing username, password and dbname.
mongodb+srv://<username>:<password>@vidly.5pn3u.azure.mongodb.net/<dbname>?retryWrites=true&w=majority
but it is giving error as 'MongoError: (Unauthorized) not authorized on admin to execute command
I tried below options to fix error:
mongo "mongodb+srv://vidly.5pn3u.azure.mongodb.net/<dbname>" --username <username>
to connect to mongo and thenuse admin
db.createUser(
{
user: 'admin',
pwd: 'password',
roles: [ { role: 'root', db: 'admin' } ]
}
);
exit;
But it is giving error : uncaught exception: Error: couldn't add user: (Unauthorized) not authorized on admin to execute command
cloud.mongodb.com
I changed a role on mongodb server to (dbAdminAnyDatabase@admin, backup@admin, readWriteAnyDatabase@admin, clusterMonitor@admin)
but its giving same error.Please advice how this error can be resolved?
Edit:
I am able to access database using mongo connect with the mongo shell
using show dbs
on shell (but not able to create user) and connect using mongodb compass
and edit database in compass.
But when I try connect your application
option it is giving this error.
The user added has these access (dbAdminAnyDatabase@admin, backup@admin, readWriteAnyDatabase@admin, clusterMonitor@admin), even with this user its not working.
Upvotes: 2
Views: 742
Reputation: 339
You need to install the recent version of mongoose. For example, you can install mongoose by using "yarn add mongoose".
Upvotes: 0