19

我在 MongoDB Atlas 上设置了一个集群并让自己成为管理员,但我无法从 shell 连接到集群。在 Atlas 上,我点击了连接按钮,点击了与 Mongo Shell 的连接,下载了最新的 Mongo Shell,并复制了连接集群的命令:

mongo "mongodb://testcluster-shard-00-00-acqhf.mongodb.net:27017,testcluster-shard-00-01-acqhf.mongodb.net:27017,testcluster-shard-00-02-acqhf.mongodb.net:27017/test?replicaSet=TestCluster-shard-0" --authenticationDatabase admin --ssl --username <USERNAME> --password <PASSWORD>

当我运行这个命令时,我得到了流:

MongoDB shell version v3.4.10
connecting to: mongodb://testcluster-shard-00-00-
acqhf.mongodb.net:27017,testcluster-shard-00-01-
acqhf.mongodb.net:27017,testcluster-shard-00-02-
acqhf.mongodb.net:27017/test?replicaSet=TestCluster-shard-0
2017-11-20T11:58:31.883-0500 I NETWORK  [thread1] Starting new replica set monitor for TestCluster-shard-0/testcluster-shard-00-00-
acqhf.mongodb.net:27017,testcluster-shard-00-01-
acqhf.mongodb.net:27017,testcluster-shard-00-02-acqhf.mongodb.net:27017
2017-11-20T11:58:32.119-0500 I NETWORK  [thread1] Successfully connected to testcluster-shard-00-01-acqhf.mongodb.net:27017 (1 connections now open to testcluster-shard-00-01-acqhf.mongodb.net:27017 with a 5 second timeout)
2017-11-20T11:58:32.131-0500 I NETWORK  [ReplicaSetMonitor-TaskExecutor-0] Successfully connected to testcluster-shard-00-00-acqhf.mongodb.net:27017 (1 connections now open to testcluster-shard-00-00-acqhf.mongodb.net:27017 with a 5 second timeout)
MongoDB server version: 3.4.10
2017-11-20T11:58:32.407-0500 I NETWORK  [ReplicaSetMonitor-TaskExecutor-0] Successfully connected to testcluster-shard-00-02-acqhf.mongodb.net:27017 (1 connections now open to testcluster-shard-00-02-acqhf.mongodb.net:27017 with a 5 second timeout)
2017-11-20T11:58:32.497-0500 I NETWORK  [thread1] Marking host testcluster-shard-00-01-acqhf.mongodb.net:27017 as failed :: caused by :: Location8000: can't authenticate against replica set node testcluster-shard-00-01-acqhf.mongodb.net:27017: bad auth Authentication failed.
2017-11-20T11:58:32.639-0500 I NETWORK  [thread1] Successfully connected to testcluster-shard-00-02-acqhf.mongodb.net:27017 (1 connections now open to testcluster-shard-00-02-acqhf.mongodb.net:27017 with a 0 second timeout)
2017-11-20T11:58:32.756-0500 I NETWORK  [thread1] Marking host testcluster-shard-00-02-acqhf.mongodb.net:27017 as failed :: caused by :: Location8000: can't authenticate against replica set node testcluster-shard-00-02-acqhf.mongodb.net:27017: bad auth Authentication failed.
2017-11-20T11:58:32.899-0500 I NETWORK  [thread1] Successfully connected to testcluster-shard-00-00-acqhf.mongodb.net:27017 (1 connections now open to testcluster-shard-00-00-acqhf.mongodb.net:27017 with a 0 second timeout)
2017-11-20T11:58:32.995-0500 I NETWORK  [thread1] Marking host testcluster-shard-00-00-acqhf.mongodb.net:27017 as failed :: caused by :: Location8000: can't authenticate against replica set node testcluster-shard-00-00-acqhf.mongodb.net:27017: bad auth Authentication failed.
2017-11-20T11:58:33.100-0500 I NETWORK  [thread1] Marking host testcluster-shard-00-01-acqhf.mongodb.net:27017 as failed :: caused by :: Location8000: can't authenticate against replica set node testcluster-shard-00-01-acqhf.mongodb.net:27017: bad auth Authentication failed.
2017-11-20T11:58:33.101-0500 E QUERY    [thread1] Error: can't authenticate against replica set node testcluster-shard-00-01-acqhf.mongodb.net:27017: bad auth Authentication failed. :
DB.prototype._authOrThrow@src/mongo/shell/db.js:1461:20
@(auth):6:1
@(auth):1:2
exception: login failed

我将 and 替换为我的用户名和密码,但仍然无法连接。我需要在后台运行 mongod 吗?如果不是,我需要做什么才能成功连接?谢谢你。

4

6 回答 6

20

我必须使用不同的用户名和密码创建一个新用户,当我使用这些新凭据运行命令时,我可以连接。

于 2017-11-20T18:01:36.380 回答
3

我的问题是我最近才在 Atlas UI 中设置/更改了密码 - 他们需要一分钟左右的时间来部署任何更改,甚至密码重置等。一旦我等待部署更改,我就可以登录

于 2018-08-09T06:58:08.967 回答
2

和其他人一样,不喜欢我的密码。从命令行工作正常,但不是从指南针。检查故障排除页面https://docs.atlas.mongodb.com/troubleshoot-connection/#special-characters-in-connection-string-password。我的密码中有特殊字符。尝试逃避它们,然后返回并将我的密码重置为没有特殊字符的简单密码 - 花了一分钟,但后来我很容易连接。

于 2019-09-25T13:29:02.477 回答
1

只需从您的密码中删除特殊字符。

于 2019-12-28T08:02:42.120 回答
0

我遇到了同样的错误,转到网络访问并对其进行编辑以从 IP 0.0.0.0/0 的任何地方访问,并确保您没有使用会导致连接缓慢和超时的 VPN 软件。

于 2022-02-20T08:42:41.347 回答
0

有时值得重置本地服务。运行brew services stop mongodb-community,然后brew services start mongodb-community

于 2021-07-11T13:54:42.900 回答