Can't connect to primary in Mongo Shell

connecting to: mongodb://cluster0-shard-00-00-jxeqq.mongodb.net:27017,cluster0-shard-00-01-jxeqq.mongodb.net:27017,cluster0-shard-00-02-jxeqq.mongodb.net:27017/test?authSource=admin&compressors=disabled&gssapiServiceName=mongodb&replicaSet=Cluster0-shard-0
2019-09-09T23:50:54.311+0530 I NETWORK [js] Starting new replica set monitor for Cluster0-shard-0/cluster0-shard-00-00-jxeqq.mongodb.net:27017,cluster0-shard-00-01-jxeqq.mongodb.net:27017,cluster0-shard-00-02-jxeqq.mongodb.net:27017
2019-09-09T23:50:54.312+0530 I CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cluster0-shard-00-01-jxeqq.mongodb.net:27017
2019-09-09T23:50:54.314+0530 I CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cluster0-shard-00-00-jxeqq.mongodb.net:27017
2019-09-09T23:50:54.314+0530 I CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cluster0-shard-00-02-jxeqq.mongodb.net:27017
2019-09-09T23:50:59.312+0530 W NETWORK [ReplicaSetMonitor-TaskExecutor] Unable to reach primary for set Cluster0-shard-0
2019-09-09T23:51:00.921+0530 I NETWORK [js] Successfully connected to cluster0-shard-00-00-jxeqq.mongodb.net:27017 (1 connections now open to cluster0-shard-00-00-jxeqq.mongodb.net:27017 with a 0 second timeout)
2019-09-09T23:51:04.319+0530 W NETWORK [ReplicaSetMonitor-TaskExecutor] Unable to reach primary for set Cluster0-shard-0
2019-09-09T23:51:09.593+0530 W NETWORK [ReplicaSetMonitor-TaskExecutor] Unable to reach primary for set Cluster0-shard-0
2019-09-09T23:51:14.312+0530 I CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cluster0-shard-00-01-jxeqq.mongodb.net:27017
2019-09-09T23:51:14.600+0530 W NETWORK [ReplicaSetMonitor-TaskExecutor] Unable to reach primary for set Cluster0-shard-0
2019-09-09T23:51:19.604+0530 W NETWORK [ReplicaSetMonitor-TaskExecutor] Unable to reach primary for set Cluster0-shard-0

*** It looks like this is a MongoDB Atlas cluster. Please ensure that your IP whitelist allows connections from your network.

2019-09-09T23:51:19.610+0530 E QUERY [js] Error: Could not find host matching read preference { mode: “primary”, tags: [ {} ] } for set Cluster0-shard-0 :
connect@src/mongo/shell/mongo.js:341:17
@(connect):2:6
2019-09-09T23:51:19.623+0530 F - [main] exception: connect failed
2019-09-09T23:51:19.626+0530 E - [main] exiting with code 1

Hi @khushboo_tolat,

The first thing that I will request you to do is to share the connection string that you are using to connect to the cluster.

Also, this is the connection string that we use to connect to our Atlas class cluster. If yours is not the same then please use this one.

mongo "mongodb://cluster0-shard-00-00-jxeqq.mongodb.net:27017,cluster0-shard-00-01-jxeqq.mongodb.net:27017,cluster0-shard-00-02-jxeqq.mongodb.net:27017/test?replicaSet=Cluster0-shard-0" --authenticationDatabase admin --ssl --username m001-student --password m001-mongodb-basics

Can you please make sure you are able to ping the cluster by executing the below mentioned command in the terminal or cmd ?

Note : Please run this command outside the mongo shell and share the output.

ping cluster0-shard-00-00-jxeqq.mongodb.net 

Thanks,
Shubham Ranjan
Curriculum Support Engineer

1 Like

I used this connection string to connect to cluster:

mongo “mongodb://cluster0-shard-00-00-jxeqq.mongodb.net:27017,cluster0-shard-00-01-jxeqq.mongodb.net:27017,cluster0-shard-00-02-jxeqq.mongodb.net:27017/test?replicaSet=Cluster0-shard-0” --authenticationDatabase admin --ssl --username m001-student --password m001-mongodb-basics

And I am able to ping the cluster. It is working fine.

Hi @khushboo_tolat,

I am able to connect to the cluster using this connection string.

mongo "mongodb://cluster0-shard-00-00-jxeqq.mongodb.net:27017,cluster0-shard-00-01-jxeqq.mongodb.net:27017,cluster0-shard-00-02-jxeqq.mongodb.net:27017/test?replicaSet=Cluster0-shard-0" --authenticationDatabase admin --ssl --username m001-student --password m001-mongodb-basics

05%20AM

Can you please make sure you are not behind a firewall or using a VPN connection to connect to the cluster. Please verify that your port is not blocked by opening this URL.

http://portquiz.net:27017/

I would recommend you to try to connect from some other network such as your home network. If the issue still persists please feel free to get back to us.

Happy Learning :slight_smile:

Thanks,
Shubham Ranjan
Curriculum Support Engineer

Issue solved. It was network problem. Thanks