Another possibility: when you created the user, you could accidentally use a database other than admin , or the one you wanted. You need to install --authenticationDatabase for the database in which the user was actually created.
mongodb apparently puts you in the default test database when you open the shell, so you will need to write --authenticationDatabase test --authenticationDatabase admin if you accidentally use test with db.createUser(...)
Assuming that you have access to the computer where the mongodb instance is running, y can disable authorization in /etc/mongod.conf (comment out authorization which is protected), and then restart the server and run:
mongo show users
And you can get something like this:
{ "_id" : "test.myusername", "user" : "myusername", "db" : "test", "roles" : [ { "role" : "dbOwner", "db" : "mydatabasename" } ], "mechanisms" : [ "SCRAM-SHA-1", "SCRAM-SHA-256" ] }
Note that the db value is test . This is because when I created the user, I did not start use admin or use desiredDatabaseName . Thus, you can delete the user using db.dropUser("myusername") and then create another user in the desired database, for example:
use desiredDatabaseName db.createUser(...)
Hope this helps someone who was in my position as a newbie in this business.
user993683 Aug 31 '18 at 10:47 2018-08-31 10:47
source share