- I have standalone MongoDB on RHEL 8 with all default configuration.
- Accessed DB via Compass and API works fine.
- then created user with super admin role, enabled security in mongod.conf, restarted DB.
-
User created using below:
db.createUser({user: "myusername", pwd: "mypassword",roles:[{role: "userAdminAnyDatabase" , db:"admin"},{ role: "readWriteAnyDatabase", db: "admin" }]})
-
Using the above connection string:
conn_str = "mongodb://myusername:mypassword@{my_hostname}:27017/?authSource=admin"
Authentication failure when tried both via Compass or API. However I am able to login using mongosh with same user and password for the user created.
What am I missing here? Any help is much appreciated.