Trying to setup MongoDB in Ubunutu VPS for a MERN app.
I’ve enabled authentication in the mongodb settings.
Set up the usernames with password with the roles of read and dbOwner of the target DB.
And I have the mongoURI string setup in the nodeJS server like this:
mongodb://${MONGO_USERNAME}:${MONGO_PASSWORD}@${MONGO_HOSTNAME}:${MONGO_PORT}/${MONGO_DB}?authSource={admindb}
In the dry run, without any data in the db, pm2 monit only shows:
“command find requires authentication”
Despite that, mongoURI string from above can log me into the mongo and mongo shell without propblem.
Is there something I’ve forgot?
I would guess you have not correctly set up roles for the MONGO_USERNAME.
A user can log into MongoDB but not be able to do very much if the user does not have certain roles.
If this is your problem, see Built-in Roles and Create a User.
The roles are read and dbOwner.
Both roles should be able to use find function.
If you are able to login with shell can you query your collections or run that find command
For authsource what exactly is the value given
authsource is admin, it’s a different db from MONGO_DB.
Ok
Can you run find query from shell?
Can you show output of db.getUsers()
The problem was resolved when readWrite role added to the user with database access.
Is it because of POST requests?
@Jae_Hong you said in your first post “In the dry run, without any data in the db”.
What sort of find()
did you try without any data?
If the find()
implied creating a collection in the empty db, I believe you would need readWrite
.
Perhaps the problem was related to “without any data in the db”.
New & Unread Topics
Topic | Replies | Views | Activity |
---|---|---|---|
MongoDB shard cluster 8.0rc -> grafana-agent monitoring problems | 0 | 415 | Jun 2024 |
Run mongodb from a read-only storage device? | 5 | 395 | Jul 2024 |
Changing the default data directory permissions | 3 | 413 | Aug 2024 |
Mongodb startup crash with illegal inctruction on recent CPU | 1 | 108 | Sep 2024 |
Version Upgrade of MongoDB from 3.2 to 7.x | 2 | 104 | Jan 21 |