0

I'm trying to connect to MongoDB using mongosh on the localhost, and when I type this command:

mongosh --port <PORT> <DATABASE_NAME> -u <USERNAME> -p <PASSWORD>

this what I got:

...
MongoServerError: Authentication failed.
Tayan
  • 1,707
  • 13
  • 18
  • Like nobody knows how to search over the Internet.... – Aksen P Apr 08 '23 at 05:29
  • Does this answer your question? [How to specify a database on a Linux mongosh command line along with authentication](https://stackoverflow.com/questions/69778370/how-to-specify-a-database-on-a-linux-mongosh-command-line-along-with-authenticat) – Aksen P Apr 08 '23 at 05:29
  • Does this answer your question? [Authentication failure while trying to save to mongodb](https://stackoverflow.com/questions/63754742/authentication-failure-while-trying-to-save-to-mongodb) – Wernfried Domscheit Apr 08 '23 at 10:37

1 Answers1

0

To solve this problem add this option and argument to your mongosh command:

--authenticationDatabase admin

So the full command will be like that:

mongosh --port <PORT> <DATABASE_NAME> -u <USERNAME> -p <PASSWORD> --authenticationDatabase admin

Tayan
  • 1,707
  • 13
  • 18