Cannot connect to Cluster through mongo shell [Solved]

Hello, I’m using MongoDB server shell and trying to connect to Cluster with command
mongo “mongodb+srv://m220student:m220password@YOUR_CLUSTER_URI” but have an error

Is there any solution how to fix this?

Hi, try with this:
mongo “mongodb://cluster0-shard-00-00-ji0ez.mongodb.net:27017/test?replicaSet=cluster0-shard-0” --ssl --authenticationDatabase admin --username m220student --password m220password

Are you shure that “cluster0…” is with lower “c”?

1 Like

Thanks for reply, I was using wrong Cluster URI for connecting.

1 Like

Hi,

I used the following command and got errors:

./mongo “mongodb://cluster0-shard-00-00-ji0ez.mongodb.net:27017/test?replicaSet=cluster0-shard-0” --ssl --authenticationDatabase admin --username m220student --password m220password

Errors:
2019-02-17T19:50:09.559-0500 I NETWORK [thread1] Cannot reach any nodes for set cluster0-shard-0. Please check network connectivity and the status of the set. This has happened for 21 checks in a row.

HI I am getting below error when connecting DB to atlas

Could some please assist on the same.

I tried with another version for mongo shell version 3.6+ still facing issues

This is my ATLAS config

Steps to solve your problems:

  1. Open cmd
  2. Open Atlas cluster and click CONNECT button
  3. Click on Connect with Mongo Shell
  4. Click Standart connection string(shell 3.4+)
  5. Copy all that command
  6. Paste to opened cmd
  7. Replace password with your own
  8. Hit Enter button
1 Like

Hi,

I have already done the same steps but no luck at all. Could you please help me the SSL/TSL connection from mongo client to mongodb server. I am using Ubuntu 16.04 for the setup purpose

Could someone please help on this. I have tried to connect to the mongo atlas using mongo client as well as using the Java driver but no luck It is failing always leading to these errors:
abhishek@ubuntu:~/Downloads/mongodb-linux-x86_64-ubuntu1604-4.0.6$ mongo “mongodb+srv://test:test@mflix-0y2y9.mongodb.net/test?retryWrites=true”
MongoDB shell version v4.0.6
connecting to: mongodb://mflix-shard-00-00-0y2y9.mongodb.net.:27017,mflix-shard-00-01-0y2y9.mongodb.net.:27017,mflix-shard-00-02-0y2y9.mongodb.net.:27017/test?authSource=admin&gssapiServiceName=mongodb&replicaSet=mflix-shard-0&retryWrites=true&ssl=true
2019-02-19T17:29:29.454+0530 I NETWORK [js] Starting new replica set monitor for mflix-shard-0/mflix-shard-00-00-0y2y9.mongodb.net.:27017,mflix-shard-00-01-0y2y9.mongodb.net.:27017,mflix-shard-00-02-0y2y9.mongodb.net.:27017
2019-02-19T17:29:31.463+0530 W NETWORK [js] Unable to reach primary for set mflix-shard-0
2019-02-19T17:29:31.464+0530 I NETWORK [js] Cannot reach any nodes for set mflix-shard-0. Please check network connectivity and the status of the set. This has happened for 1 checks in a row.
2019-02-19T17:29:34.982+0530 W NETWORK [js] Unable to reach primary for set mflix-shard-0
2019-02-19T17:29:34.982+0530 I NETWORK [js] Cannot reach any nodes for set mflix-shard-0. Please check network connectivity and the status of the set. This has happened for 2 checks in a row.
2019-02-19T17:29:38.503+0530 W NETWORK [js] Unable to reach primary for set mflix-shard-0
2019-02-19T17:29:38.503+0530 I NETWORK [js] Cannot reach any nodes for set mflix-shard-0. Please check network connectivity and the status of the set. This has happened for 3 checks in a row.
2019-02-19T17:29:42.026+0530 W NETWORK [js] Unable to reach primary for set mflix-shard-0
2019-02-19T17:29:42.026+0530 I NETWORK [js] Cannot reach any nodes for set mflix-shard-0. Please check network connectivity and the status of the set. This has happened for 4 checks in a row.
2019-02-19T17:29:45.544+0530 W NETWORK [js] Unable to reach primary for set mflix-shard-0
2019-02-19T17:29:45.544+0530 I NETWORK [js] Cannot reach any nodes for set mflix-shard-0. Please check network connectivity and the status of the set. This has happened for 5 checks in a row.
2019-02-19T17:29:45.544+0530 E QUERY [js] Error: connect failed to replica set mflix-shard-0/mflix-shard-00-00-0y2y9.mongodb.net.:27017,mflix-shard-00-01-0y2y9.mongodb.net.:27017,mflix-shard-00-02-0y2y9.mongodb.net.:27017 :
connect@src/mongo/shell/mongo.js:343:13
@(connect):1:6
exception: connect failed

Same is the case when I try to connect through Java code:
Caused by: java.net.ConnectException: Connection refused (Connection refused)
at java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:1.8.0_191]
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) ~[na:1.8.0_191]
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[na:1.8.0_191]
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[na:1.8.0_191]
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[na:1.8.0_191]
at java.net.Socket.connect(Socket.java:589) ~[na:1.8.0_191]
at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:666) ~[na:1.8.0_191]
at com.mongodb.internal.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:64) ~[mongodb-driver-core-3.9.1.jar:na]
at com.mongodb.internal.connection.SocketStream.initializeSocket(SocketStream.java:79) ~[mongodb-driver-core-3.9.1.jar:na]
at com.mongodb.internal.connection.SocketStream.open(SocketStream.java:65) ~[mongodb-driver-core-3.9.1.jar:na]
… 3 common frames omitted

I am frustated a bit as I have tried the same process through multiple routes. Also tried to run to variour Atlas accounts but no luck at all.

Hi @abhishek_sikka,

I’ve managed to connect without any issues.
Are you connecting from a network where AWS is blocked ?

Can test if port 27017 is allowed?
Just go to this url:
http://portquiz.net:27017/

The issue is most likely related with connectivity issues from your end.

N.

@Fisher093
I have the same issue. I am not sure what the solution is. Could you please share the URI you used or where you found?

Thanks, Prasad.

Hi Prasad,

I think that you could check if the network connectivity works for you using this suggestion from Norberto. If that doesn’t work, I’d also suggest double checking that your Mongo Shell version and the version of your Atlas Cluster are the same version.

Hope this helps!
Eoin

Thanks for replying.

I got the issue sorted out. I was doing somethings incorrectly - I got the URI right (something like this) and it worked to test the connection on mongo shell: mongodb+srv://m220student:m220password@mflix-uck23.mongodb.net/test

1 Like