我在通过 mongo shell 连接到 MongoDB 图集时遇到问题,即使我已经做对了所有事情并且三重检查了数据用户名和密码,将我的 IP 包含在白名单中,将数据库名称更改为 test,并尝试添加 --password在同一行
`$ mongo "mongodb+srv://cluster******.mongodb.net/test" --username admin --password admin MongoDB shell 版本 v4.4.6 连接到: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
*** 您未能连接到 MongoDB Atlas 集群。请确保您的 IP 白名单允许来自您网络的连接。
错误:身份验证错误:身份验证失败。 :
connect@src/mongo/shell/mongo.js:374:17
@(连接):2:6
异常:连接失败
退出代码 1`
答案 0 :(得分:1)
MongoDB Atlas 在管理数据库中创建所有用户。
您尝试的输出并不表明它正在使用 admin 数据库进行身份验证,因此您可能需要使用 --authenticationDatabase
命令行选项,或在 URL 中包含 authSource=
,即其中之一:
mongo "mongodb+srv://cluster******.mongodb.net/test" --username admin --password admin --authenticationDatabase admin
或
mongo "mongodb+srv://cluster******.mongodb.net/test?authSource=admin" --username admin --password admin