简体   繁体   中英

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. After providing pass I get below error. Converting back to WSL1 is a fix but I would rather stay on WSL2.

When I do simple ping google.com everything seems to be working ok.

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). 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).

Ok, the issue was with firewall setting in Avast.

Solution I found: https://github.com/MicrosoftDocs/WSL/issues/481 states:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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