mongodb - 连接到 Mongo 时 WSL2 中的连接错误
问题描述
我有一个 MongoDB 云的 POC 帐户,我正在尝试使用 mongo shell 连接它。提供通行证后,我得到以下错误。转换回 WSL1 是一种解决方法,但我宁愿继续使用 WSL2。
当我做简单的事情时ping google.com
,一切似乎都正常。
MongoDB shell version v3.6.8
Enter password:
connecting to: mongodb+srv://yyyy-yyy-yyyy.yyyyy.mongodb.net/node_db
2020-11-28T13:20:18.780+0100 I NETWORK [thread1] Starting new replica set monitor for atlas-qtxfdg-shard-0/yyyy-yyy-shop-yyy-00-02.yyyy.mongodb.net.:27017,yyyy-yyy-yyyy-shard-00-00.yyyyy.mongodb.net.:27017,yyy-yyyy-yyyy-yyyy-00-01.yyyyy.mongodb.net.:27017
2020-11-28T13:20:23.848+0100 W NETWORK [thread1] Failed to connect to 20.67.41.218:27017 after 5000ms milliseconds, giving up.
2020-11-28T13:20:23.914+0100 W NETWORK [ReplicaSetMonitor-TaskExecutor-0] Failed to connect to 20.56.152.73:27017 after 5000ms milliseconds, giving up.
2020-11-28T13:20:28.940+0100 W NETWORK [thread1] Failed to connect to 20.61.168.228:27017 after 5000ms milliseconds, giving up.
2020-11-28T13:20:28.940+0100 W NETWORK [thread1] Unable to reach primary for set atlas-qtxfdg-shard-0
2020-11-28T13:20:28.940+0100 I NETWORK [thread1] Cannot reach any nodes for set atlas-qtxfdg-shard-0. Please check network connectivity and the status of the set. This has happened for 1 checks in a row.
2020-11-28T13:20:34.449+0100 W NETWORK [thread1] Failed to connect to 20.67.41.218:27017 after 5000ms milliseconds, giving up.
2020-11-28T13:20:39.459+0100 W NETWORK [thread1] Failed to connect to 20.61.168.228:27017 after 5000ms milliseconds, giving up.
2020-11-28T13:20:44.468+0100 W NETWORK [thread1] Failed to connect to 20.56.152.73:27017 after 5000ms milliseconds, giving up.
2020-11-28T13:20:44.468+0100 W NETWORK [thread1] Unable to reach primary for set atlas-qtxfdg-shard-0
2020-11-28T13:20:44.468+0100 I NETWORK [thread1] Cannot reach any nodes for set atlas-qtxfdg-shard-0. Please check network connectivity and the status of the set. This has happened for 2 checks in a row.
2020-11-28T13:20:44.471+0100 E QUERY [thread1] Error: connect failed to replica set atlas-qtxfdg-yyyy-0/yyyy-yyyy-yyyy-yyyyy-00-02.yyyyyy.mongodb.net.:27017,yyyy-yyyy-yyy-yyyyy-00-00.yyyyy.mongodb.net.:27017,yyyy-yyyy-yyyy-yyyy-00-01.yyyyyy.mongodb.net.:27017 :
connect@src/mongo/shell/mongo.js:257:13
@(connect):1:6
exception: connect failed
解决方案
如果网络是公共网络或私有网络,请检查 Windows 设置,每个防火墙配置可能不同(通常对公共网络有更多限制)。我在 WSL 2 中遇到了与 Mongo Atlas 的连接问题,这是因为网络是公共的,所以一些 Node JS 操作被防火墙(我的设置中的 Windows Defender)阻止了。
推荐阅读
- ably-realtime - Ably Pub/Sub 实时 ILoggerSink LogEvent 不工作
- c - 添加两个多项式表达式时出错
- opencart - 无法在我的 Opencart 网站错误日志中打开图像的流错误
- google-drive-api - 谷歌驱动快速入门nodejs教程——quickstart如何命名应用程序?
- java - 在 scopeJava(16777238) 中无法访问 XXXX 类型的封闭实例
- html - Colab markdown 单元格创建了不需要的链接
- sharepoint - Uipath 共享点活动 - GetListItem 获取不需要的元数据列和数据
- c# - 具有可序列化属性编码的 Dotnet Core 模型绑定 XML
- javascript - 如何在 JS 中只指定被点击的元素
- sql - 在 SQL Server 中更改日期格式