简体   繁体   中英

MongoDB atlas through mongo shell: “Error: bad auth : Authentication failed.” what could possibly cause this Authentication failure?

I have a problem connecting to MongoDB atlas through mongo shell, even though I have done everything right and triple checked data username and password, included my IP in the whitelist, changed the database name to test, and tried adding --password in the same line

`$ mongo "mongodb+srv://cluster******.mongodb.net/test" --username admin --password admin MongoDB shell version v4.4.6 connecting to: mongodb://cluster0-shard-00-00.4d5jd.mongodb.net:27017,cluster0-shard-00-01.4d5jd.mongodb.net:27017,cluster0-shard-00-02.4d5jd.mongodb.net:27017/test?compressors=disabled&gssapiServiceName=mongodb&ssl=true

*** You have failed to connect to a MongoDB Atlas cluster. Please ensure that your IP whitelist allows connections from your network.

Error: bad auth : Authentication failed. : connect@src/mongo/shell/mongo.js:374:17
@(connect):2:6 exception: connect failed exiting with code 1`

MongoDB Atlas creates all users in the admin database.

The output from your attempt does not indicate that it was using the admin database for authentication, so you will likely need to use either the --authenticationDatabase command line option, or include authSource= in the URL, ie one of:

mongo "mongodb+srv://cluster******.mongodb.net/test" --username admin --password admin --authenticationDatabase admin

or

mongo "mongodb+srv://cluster******.mongodb.net/test?authSource=admin" --username admin --password admin

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM