UserNotFound mongodb error

Posted on

Question :

I know there are lot of articles with the same issue and I explored every other article trying everything and still this error persists.

Here are the steps I followed:

  1. use admin.

  2. created an admin user with role: dbAdminAnyDatabase

  3. use mydb.

  4. created an admin user with different name for mydb

  5. created a readonly user with: db.createUser({user: "nameuser", pwd: "password", roles: [{role: "read", db: "mydb"}]});

  6. setup a mongod.conf file with:

  7. security:
    authorization: enabled

    port: 12345
    bindIp: #default value is

  8. then run the command: sudo mongod --port 27017 --dbpath ~/data/mongodb --config /etc/mongod.conf

  9. and then on localhost i run the command to check:

    mongo -u nameuser -p password localhost:12345/mydb

  10. then the error come as:

    connecting to: mongodb://localhost:12345/mydb MongoDB server version: 3.6.3 2020-10-04T03:05:37.054+0530 E QUERY [thread1] Error: Authentication failed. : DB.prototype._authOrThrow@src/mongo/shell/db.js:1608:20 @(auth):6:1 @(auth):1:2 exception: login failed

  11. and on server side the error looks like this:

    2020-10-04T02:53:11.835+0530 I NETWORK [listener] connection accepted from #3 (1 connection now open) 2020-10-04T02:53:11.835+0530 I NETWORK [conn3] received client metadata from conn: { application: { name: "MongoDB Shell" }, driver: { name: "MongoDB Internal Client", version: "3.6.3" }, os: { type: "Linux", name: "Ubuntu", architecture: "x86_64", version: "18.04" } } 2020-10-04T02:53:11.836+0530 I ACCESS [conn3] SCRAM-SHA-1 authentication failed for nameuser on mydb from client ; UserNotFound: Could not find user nameuser@mydb 2020-10-04T02:53:11.837+0530 I NETWORK [conn3] end connection (0 connections now open)

Now please tell me if I can try anything new. I have tried so many articles from stackoverflow but none address the issue. Every resolved issue is the common mistake which I have checked already and I am not doing any of these. Tell me if you have any suggestion to work this out.

Answer :

You need to use

–authenticationDatabase admin

parameter… Because, even you give “use mydb” before creating user… User is created at the admin -database.


mongo -u nameuser -p password –authenticationDatabase admin localhost:12345/mydb

Leave a Reply

Your email address will not be published. Required fields are marked *