0

Do you why i can't log in with a connetion string like this: mongodb://root:*****@localhost:27017/Database But, i can log in with a one like this: mongodb://root:*****@localhost:27017/ I had an "authentication failed"

Also, i can log in like that: mongodb://root:*****@localhost:27017/admin

I don't know where i can looking for a solution.

Thank you for your help

I've tried with a database with a name in lowercase but nothing works.

1

1 Answer 1

1

MongoDB uses admin DB for authentication and authorization purposes.

From official MongoDB document on Connection URI,

If specified, the client will attempt to authenticate the user to the authSource. If authSource is unspecified, the client will attempt to authenticate the user to the defaultauthdb. And if the defaultauthdb is unspecified, to the admin database.

As you are providing username:password@, you are implying the usage of defaultauthdb.

  • mongodb://root:*****@localhost:27017/admin works because you specified admin as the defaultauthdb
  • mongodb://root:*****@localhost:27017/ works because defaultauthdb is unspecified. So it is referred to the admin database

mongodb://root:*****@localhost:27017/Database does not work because you are using database other than admin db to perform the auth.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.