1

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

    net: port: 12345 bindIp: 0.0.0.0 #default value is 127.0.0.1

  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 127.0.0.1:60240 #3 (1 connection now open) 2020-10-04T02:53:11.835+0530 I NETWORK [conn3] received client metadata from 127.0.0.1:60240 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 127.0.0.1:60240 ; UserNotFound: Could not find user nameuser@mydb 2020-10-04T02:53:11.837+0530 I NETWORK [conn3] end connection 127.0.0.1:60240 (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.

2
  • 2
    Try running db.getUsers() in each database to see which user is where.
    – Joe
    Oct 9, 2020 at 5:14
  • The server says the user doesn't exist. Are you sure step 5 succeeded?
    – Joe
    Nov 19, 2020 at 9:36

1 Answer 1

0

You need to use

--authenticationDatabase admin

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

So,

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

1
  • I tried this. There was still an error. I tried making owner of same name for that database too. and then try this command but still there is same error. Oct 4, 2020 at 13:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.