简体   繁体   English

连接到 Mongo 时 WSL2 中的连接错误

[英]Connection error in WSL2 when connecting to Mongo

I have a POC account for MongoDB cloud which I am trying to connect to using mongo shell.我有一个 MongoDB 云的 POC 帐户,我正在尝试使用 mongo shell 连接它。 After providing pass I get below error.提供通行证后,我得到以下错误。 Converting back to WSL1 is a fix but I would rather stay on WSL2.转换回 WSL1 是一种解决方法,但我宁愿继续使用 WSL2。

When I do simple ping google.com everything seems to be working ok.当我执行简单的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

Check in Windows settings if the network is public or private, firewall configuration may be different for each one (usually with more restrictions for public networks).检查 Windows 设置,如果网络是公共网络或私有网络,防火墙配置可能因每个而异(通常对公共网络有更多限制)。 I had connection issues with Mongo Atlas from WSL 2 and it was because of having the network as public, so some Node JS operations were being blocked by the firewall (Windows Defender in my setup).我在 WSL 2 中遇到了与 Mongo Atlas 的连接问题,这是因为网络是公共的,所以一些 Node JS 操作被防火墙(我的设置中的 Windows Defender)阻止了。

Ok, the issue was with firewall setting in Avast.好的,问题出在 Avast 中的防火墙设置上。

Solution I found: https://github.com/MicrosoftDocs/WSL/issues/481 states:我找到的解决方案: https://github.com/MicrosoftDocs/WSL/issues/481状态:

go to Settings -> Protection -> Firewall -> Check the "Internet Connection Sharing Mode".

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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