簡體   English   中英

連接到 Mongo 時 WSL2 中的連接錯誤

[英]Connection error in WSL2 when connecting to Mongo

我有一個 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)阻止了。

好的,問題出在 Avast 中的防火牆設置上。

我找到的解決方案: 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