mongodb - 无法通过 Mongodb shell 连接到 Mongodb 集群

标签 mongodb mongo-shell mongodb-cluster

我一直在尝试使用 shell 通过终端连接到 Mongodb Atlas 集群,但发生了一些有趣的事情,它总是向我抛出这些日志:

MongoDB shell version v4.2.0
Enter password:
connecting to: mongodb://cluster0-shard-00-00-m0uql.mongodb.net:27017,cluster0-shard-00-01-m0uql.mongodb.net:27017,cluster0-shard-00-02-m0uql.mongodb.net:27017/test?authSource=admin&compressors=disabled&gssapiServiceName=mongodb&replicaSet=Cluster0-shard-0&ssl=true
2019-12-08T12:32:06.915+0000 I  NETWORK  [js] Starting new replica set monitor for Cluster0-shard-0/cluster0-shard-00-00-m0uql.mongodb.net:27017,cluster0-shard-00-01-m0uql.mongodb.net:27017,cluster0-shard-00-02-m0uql.mongodb.net:27017
2019-12-08T12:32:06.916+0000 I  CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cluster0-shard-00-01-m0uql.mongodb.net:27017
2019-12-08T12:32:06.916+0000 I  CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cluster0-shard-00-02-m0uql.mongodb.net:27017
2019-12-08T12:32:06.916+0000 I  CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cluster0-shard-00-00-m0uql.mongodb.net:27017
2019-12-08T12:32:07.098+0000 W  NETWORK  [ReplicaSetMonitor-TaskExecutor] Unable to reach primary for set Cluster0-shard-0
2019-12-08T12:32:07.098+0000 I  NETWORK  [ReplicaSetMonitor-TaskExecutor] Cannot reach any nodes for set Cluster0-shard-0. Please check network connectivity and the status of the set. This has happened for 1 checks in a row.
2019-12-08T12:32:07.534+0000 W  NETWORK  [ReplicaSetMonitor-TaskExecutor] Unable to reach primary for set Cluster0-shard-0
2019-12-08T12:32:07.534+0000 I  NETWORK  [ReplicaSetMonitor-TaskExecutor] Cannot reach any nodes for set Cluster0-shard-0. Please check network connectivity and the status of the set. This has happened for 2 checks in a row.
2019-12-08T12:32:07.917+0000 I  CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cluster0-shard-00-00-m0uql.mongodb.net:27017
2019-12-08T12:32:07.917+0000 I  CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cluster0-shard-00-02-m0uql.mongodb.net:27017
2019-12-08T12:32:07.917+0000 I  CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cluster0-shard-00-01-m0uql.mongodb.net:27017
2019-12-08T12:32:08.032+0000 W  NETWORK  [ReplicaSetMonitor-TaskExecutor] Unable to reach primary for set Cluster0-shard-0
2019-12-08T12:32:08.032+0000 I  NETWORK  [ReplicaSetMonitor-TaskExecutor] Cannot reach any nodes for set Cluster0-shard-0. Please check network connectivity and the status of the set. This has happened for 3 checks in a row.
2019-12-08T12:32:08.539+0000 W  NETWORK  [ReplicaSetMonitor-TaskExecutor] Unable to reach primary for set Cluster0-shard-0
2019-12-08T12:32:08.539+0000 I  NETWORK  [ReplicaSetMonitor-TaskExecutor] Cannot reach any nodes for set Cluster0-shard-0. Please check network connectivity and the status of the set. This has happened for 4 checks in a row.
2019-12-08T12:32:09.038+0000 W  NETWORK  [ReplicaSetMonitor-TaskExecutor] Unable to reach primary for set Cluster0-shard-0
2019-12-08T12:32:09.039+0000 I  NETWORK  [ReplicaSetMonitor-TaskExecutor] Cannot reach any nodes for set Cluster0-shard-0. Please check network connectivity and the status of the set. This has happened for 5 checks in a row.
2019-12-08T12:32:09.425+0000 I  CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cluster0-shard-00-01-m0uql.mongodb.net:27017
2019-12-08T12:32:09.426+0000 I  CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cluster0-shard-00-02-m0uql.mongodb.net:27017
2019-12-08T12:32:09.426+0000 I  CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cluster0-shard-00-00-m0uql.mongodb.net:27017
2019-12-08T12:32:09.543+0000 W  NETWORK  [ReplicaSetMonitor-TaskExecutor] Unable to reach primary for set Cluster0-shard-0
2019-12-08T12:32:09.543+0000 I  NETWORK  [ReplicaSetMonitor-TaskExecutor] Cannot reach any nodes for set Cluster0-shard-0. Please check network connectivity and the status of the set. This has happened for 6 checks in a row.
2019-12-08T12:32:10.035+0000 W  NETWORK  [ReplicaSetMonitor-TaskExecutor] Unable to reach primary for set Cluster0-shard-0
2019-12-08T12:32:10.035+0000 I  NETWORK  [ReplicaSetMonitor-TaskExecutor] Cannot reach any nodes for set Cluster0-shard-0. Please check network connectivity and the status of the set. This has happened for 7 checks in a row.
2019-12-08T12:32:10.430+0000 I  CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cluster0-shard-00-02-m0uql.mongodb.net:27017
2019-12-08T12:32:10.430+0000 I  CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cluster0-shard-00-01-m0uql.mongodb.net:27017
2019-12-08T12:32:10.431+0000 I  CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cluster0-shard-00-00-m0uql.mongodb.net:27017
2019-12-08T12:32:10.546+0000 W  NETWORK  [ReplicaSetMonitor-TaskExecutor] Unable to reach primary for set Cluster0-shard-0
2019-12-08T12:32:10.546+0000 I  NETWORK  [ReplicaSetMonitor-TaskExecutor] Cannot reach any nodes for set Cluster0-shard-0. Please check network connectivity and the status of the set. This has happened for 8 checks in a row.
2019-12-08T12:32:11.036+0000 W  NETWORK  [ReplicaSetMonitor-TaskExecutor] Unable to reach primary for set Cluster0-shard-0
2019-12-08T12:32:11.036+0000 I  NETWORK  [ReplicaSetMonitor-TaskExecutor] Cannot reach any nodes for set Cluster0-shard-0. Please check network connectivity and the status of the set. This has happened for 9 checks in a row.
2019-12-08T12:32:11.433+0000 I  CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cluster0-shard-00-01-m0uql.mongodb.net:27017
2019-12-08T12:32:11.433+0000 I  CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cluster0-shard-00-02-m0uql.mongodb.net:27017
2019-12-08T12:32:11.433+0000 I  CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cluster0-shard-00-00-m0uql.mongodb.net:27017
2019-12-08T12:32:11.549+0000 W  NETWORK  [ReplicaSetMonitor-TaskExecutor] Unable to reach primary for set Cluster0-shard-0
2019-12-08T12:32:11.549+0000 I  NETWORK  [ReplicaSetMonitor-TaskExecutor] Cannot reach any nodes for set Cluster0-shard-0. Please check network connectivity and the status of the set. This has happened for 10 checks in a row.
2019-12-08T12:32:12.046+0000 W  NETWORK  [ReplicaSetMonitor-TaskExecutor] Unable to reach primary for set Cluster0-shard-0
2019-12-08T12:32:12.046+0000 I  NETWORK  [ReplicaSetMonitor-TaskExecutor] Cannot reach any nodes for set Cluster0-shard-0. Please check network connectivity and the status of the set. This has happened for 11 checks in a row.
2019-12-08T12:32:12.435+0000 I  CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cluster0-shard-00-00-m0uql.mongodb.net:27017
2019-12-08T12:32:12.435+0000 I  CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cluster0-shard-00-01-m0uql.mongodb.net:27017
2019-12-08T12:32:12.435+0000 I  CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cluster0-shard-00-02-m0uql.mongodb.net:27017
2019-12-08T12:32:12.551+0000 W  NETWORK  [ReplicaSetMonitor-TaskExecutor] Unable to reach primary for set Cluster0-shard-0
2019-12-08T12:32:13.048+0000 W  NETWORK  [ReplicaSetMonitor-TaskExecutor] Unable to reach primary for set Cluster0-shard-0
2019-12-08T12:32:13.568+0000 W  NETWORK  [ReplicaSetMonitor-TaskExecutor] Unable to reach primary for set Cluster0-shard-0
2019-12-08T12:32:13.928+0000 I  CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cluster0-shard-00-01-m0uql.mongodb.net:27017
2019-12-08T12:32:13.928+0000 I  CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cluster0-shard-00-00-m0uql.mongodb.net:27017
2019-12-08T12:32:13.928+0000 I  CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cluster0-shard-00-02-m0uql.mongodb.net:27017
2019-12-08T12:32:14.049+0000 W  NETWORK  [ReplicaSetMonitor-TaskExecutor] Unable to reach primary for set Cluster0-shard-0
2019-12-08T12:32:14.555+0000 W  NETWORK  [ReplicaSetMonitor-TaskExecutor] Unable to reach primary for set Cluster0-shard-0
2019-12-08T12:32:14.930+0000 I  CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cluster0-shard-00-01-m0uql.mongodb.net:27017
2019-12-08T12:32:14.930+0000 I  CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cluster0-shard-00-02-m0uql.mongodb.net:27017
2019-12-08T12:32:14.931+0000 I  CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cluster0-shard-00-00-m0uql.mongodb.net:27017
2019-12-08T12:32:15.051+0000 W  NETWORK  [ReplicaSetMonitor-TaskExecutor] Unable to reach primary for set Cluster0-shard-0
2019-12-08T12:32:15.556+0000 W  NETWORK  [ReplicaSetMonitor-TaskExecutor] Unable to reach primary for set Cluster0-shard-0
2019-12-08T12:32:15.934+0000 I  CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cluster0-shard-00-01-m0uql.mongodb.net:27017
2019-12-08T12:32:15.934+0000 I  CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cluster0-shard-00-00-m0uql.mongodb.net:27017
2019-12-08T12:32:15.934+0000 I  CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cluster0-shard-00-02-m0uql.mongodb.net:27017
2019-12-08T12:32:16.053+0000 W  NETWORK  [ReplicaSetMonitor-TaskExecutor] Unable to reach primary for set Cluster0-shard-0
2019-12-08T12:32:16.561+0000 W  NETWORK  [ReplicaSetMonitor-TaskExecutor] Unable to reach primary for set Cluster0-shard-0
2019-12-08T12:32:16.935+0000 I  CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cluster0-shard-00-01-m0uql.mongodb.net:27017
2019-12-08T12:32:16.936+0000 I  CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cluster0-shard-00-02-m0uql.mongodb.net:27017
2019-12-08T12:32:16.936+0000 I  CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cluster0-shard-00-00-m0uql.mongodb.net:27017
2019-12-08T12:32:17.052+0000 W  NETWORK  [ReplicaSetMonitor-TaskExecutor] Unable to reach primary for set Cluster0-shard-0
2019-12-08T12:32:17.052+0000 I  NETWORK  [ReplicaSetMonitor-TaskExecutor] Cannot reach any nodes for set Cluster0-shard-0. Please check network connectivity and the status of the set. This has happened for 21 checks in a row.
2019-12-08T12:32:17.562+0000 W  NETWORK  [ReplicaSetMonitor-TaskExecutor] Unable to reach primary for set Cluster0-shard-0
2019-12-08T12:32:17.936+0000 I  CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cluster0-shard-00-01-m0uql.mongodb.net:27017
2019-12-08T12:32:18.054+0000 W  NETWORK  [ReplicaSetMonitor-TaskExecutor] Unable to reach primary for set Cluster0-shard-0
2019-12-08T12:32:18.449+0000 I  CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cluster0-shard-00-00-m0uql.mongodb.net:27017
2019-12-08T12:32:18.449+0000 I  CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cluster0-shard-00-02-m0uql.mongodb.net:27017
2019-12-08T12:32:18.564+0000 W  NETWORK  [ReplicaSetMonitor-TaskExecutor] Unable to reach primary for set Cluster0-shard-0
2019-12-08T12:32:18.938+0000 I  CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cluster0-shard-00-01-m0uql.mongodb.net:27017
2019-12-08T12:32:19.060+0000 W  NETWORK  [ReplicaSetMonitor-TaskExecutor] Unable to reach primary for set Cluster0-shard-0
2019-12-08T12:32:19.453+0000 I  CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cluster0-shard-00-02-m0uql.mongodb.net:27017
2019-12-08T12:32:19.453+0000 I  CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cluster0-shard-00-00-m0uql.mongodb.net:27017
2019-12-08T12:32:19.575+0000 W  NETWORK  [ReplicaSetMonitor-TaskExecutor] Unable to reach primary for set Cluster0-shard-0
2019-12-08T12:32:19.941+0000 I  CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cluster0-shard-00-01-m0uql.mongodb.net:27017
2019-12-08T12:32:20.060+0000 W  NETWORK  [ReplicaSetMonitor-TaskExecutor] Unable to reach primary for set Cluster0-shard-0
2019-12-08T12:32:20.570+0000 W  NETWORK  [ReplicaSetMonitor-TaskExecutor] Unable to reach primary for set Cluster0-shard-0
2019-12-08T12:32:20.941+0000 I  CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cluster0-shard-00-02-m0uql.mongodb.net:27017
2019-12-08T12:32:20.941+0000 I  CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cluster0-shard-00-00-m0uql.mongodb.net:27017
2019-12-08T12:32:21.066+0000 W  NETWORK  [ReplicaSetMonitor-TaskExecutor] Unable to reach primary for set Cluster0-shard-0
2019-12-08T12:32:21.453+0000 I  CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cluster0-shard-00-01-m0uql.mongodb.net:27017
2019-12-08T12:32:21.574+0000 W  NETWORK  [ReplicaSetMonitor-TaskExecutor] Unable to reach primary for set Cluster0-shard-0
2019-12-08T12:32:21.945+0000 I  CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cluster0-shard-00-00-m0uql.mongodb.net:27017
2019-12-08T12:32:21.946+0000 I  CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cluster0-shard-00-02-m0uql.mongodb.net:27017
2019-12-08T12:32:22.062+0000 W  NETWORK  [ReplicaSetMonitor-TaskExecutor] Unable to reach primary for set Cluster0-shard-0
2019-12-08T12:32:22.062+0000 I  NETWORK  [ReplicaSetMonitor-TaskExecutor] Cannot reach any nodes for set Cluster0-shard-0. Please check network connectivity and the status of the set. This has happened for 31 checks in a row.


*** It looks like this is a MongoDB Atlas cluster. Please ensure that your IP whitelist allows connections from your network.


2019-12-08T12:32:22.063+0000 E  QUERY    [js] Error: connect failed to replica set Cluster0-shard-0/cluster0-shard-00-00-m0uql.mongodb.net:27017,cluster0-shard-00-01-m0uql.mongodb.net:27017,cluster0-shard-00-02-m0uql.mongodb.net:27017 :
connect@src/mongo/shell/mongo.js:341:17
@(connect):2:6
2019-12-08T12:32:22.065+0000 F  -        [main] exception: connect failed
2019-12-08T12:32:22.066+0000 E  -        [main] exiting with code 1

所以,需要明确的是,我的 IP 地址在列表中,所以这应该不是问题。

我注意到我的Atlas集群的版本是4.0.13,我下载了相同版本的mongodb-community。但是,每当我尝试安装 shell 时,它只提供我的 4.2 版本(您可以在日志中看到它)。我个人认为版本不兼容是一个问题,但也许有人知道不同的原因?

最佳答案

谢谢大家,我已经知道问题所在了。在我工作的笔记本电脑上,IP 与终端和网络首选项中显示的 IP 不同。我通过“事件”部分找到了它,它记录了我的本地事件。 enter image description here

关于mongodb - 无法通过 Mongodb shell 连接到 Mongodb 集群,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59235499/

相关文章:

c# - 用于更新的 Mongodb 驱动程序 C# 聚合

mongodb - 如何在 Linux 中禁用对 MongoDB 3.0.x 的匿名访问

ruby-on-rails - Mongoid 不在查询中

node.js - 身份验证错误 : [Symbol(mongoErrorContextSymbol)]: {}

mongodb - Spark Mongo 连接器,MongoShardedPartitioner 不起作用

node.js - 当新的主 Node 当选后,Express 无法连接到 mongodb 副本集

node.js - MongoDB req.body 问题

javascript - 如何使用 Javascript 处理 Mongo shell 中文件中的数百万?

mongodb - 如何使用 Sharding 查看 Mongodb 中的 Oplog

mongodb - 如何在 mongo shell 中运行本地脚本 - 解决方案 load()