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 |
---|---|---|---|
Planning MongoDB Replica Set upgrade 4.4.18 to 6.0.15 | 1 | 692 | May 2024 |
How to migrate MongoDB server from RHEL7 to RHEL8 | 2 | 599 | Sep 2024 |
Attempting to upgrade from 3.6.23 to latest version and having issues | 0 | 61 | Aug 2024 |
Reduce Mongo Docker logs | 0 | 135 | Jan 13 |
set parameter on the mongodb .conf fails to start eh server | 1 | 30 | Mar 10 |