Unable to connect to cluster from shell

I am trying to connect to the cluster from cmd and i get the below

cmd:

mongo “mongodb+srv://m001-student:m001-student-basics@sandbox.ml8oc.mongodb.net/admin”

MongoDB shell version v4.4.2

connecting to: mongodb://sandbox-shard-00-01.ml8oc.mongodb.net:27017,sandbox-shard-00-00.ml8oc.mongodb.net:27017,sandbox-shard-00-02.ml8oc.mongodb.net:27017/admin?authSource=admin&compressors=disabled&gssapiServiceName=mongodb&replicaSet=atlas-42y1yr-shard-0&ssl=true
{"t":{"$date":"2021-05-15T11:58:50.914Z"},"s":"W",  "c":"NETWORK",  "id":23019,   "ctx":"ReplicaSetMonitor-TaskExecutor","msg":"DNS resolution while connecting to peer was slow","attr":{"peer":"sandbox-shard-00-02.ml8oc.mongodb.net:27017","durationMillis":1008}}
{"t":{"$date":"2021-05-15T11:59:04.905Z"},"s":"I",  "c":"NETWORK",  "id":4333208, "ctx":"ReplicaSetMonitor-TaskExecutor","msg":"RSM host selection timeout","attr":{"replicaSet":"atlas-42y1yr-shard-0","error":"FailedToSatisfyReadPreference: Could not find host matching read preference { mode: \"nearest\" } for set atlas-42y1yr-shard-0"}}

*** You have failed to connect to a MongoDB Atlas cluster. Please ensure that your IP whitelist allows connections from your network.

Error: connect failed to replica set atlas-42y1yr-shard-0/sandbox-shard-00-01.ml8oc.mongodb.net:27017,sandbox-shard-00-00.ml8oc.mongodb.net:27017,sandbox-shard-00-02.ml8oc.mongodb.net:27017 :
connect@src/mongo/shell/mongo.js:374:17
@(connect):2:6
exception: connect failed
exiting with code 1

FYI, i am using work laptop with VPN enabled

Hi @Sumanth_BKS,

Welcome to the MongoDB University.

So, here according to the error log msg it seems like mongos process is not able to connect to nearest replica set.

Make sure all nodes are up and running. Can you connect to replicaset and individual nodes?

Also, kindly make sure that your IP address is whitelisted. You will find it under the Network Access tab of your MongoDB Atlas Cloud Server.

We suggest you to use 0.0.0.0/0 for all university courses.

EDIT 1: This isn’t a recommended setting for production environments, but will help with access to your course cluster if you do not have a fixed IP address.

If problem still persist kindly check your network/ISP, and make sure that your connection is not obstructed by a firewall or an anti-virus. If an antivirus is blocking connection requests to/from your local network, then try to allow Atlas access through your Antivirus settings menu.

If a firewall is blocking your access, then try to connect from a different location such as your home network.

Hope it helps!

:slightly_smiling_face:
Thank you,
Kushagra

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.