Unable to connect to Atlas cluster using "Standard Connection String" format

Hi,

I am trying to connect to my Atlas cluster using “Standard Connection String” format.

mongo "mongodb://xxx:xxx@xxx-shard-00-02.m32cu.mongodb.net:27017,xxx-shard-00-01.m32cu.mongodb.net:27017, xxx-shard-00-00.m32cu.mongodb.net:27017/myDatabase"
MongoDB shell version v4.4.6

Is there anything wrong in the connection string or am I missing something silly?

My IP is whitelisted, I’ve also tried with “open to all” access. My username and password is correct, my password doesn’t container special character.

{“t”:{"$date":“2021-06-26T12:43:35.156Z”},“s”:“I”, “c”:“NETWORK”, “id”:4648601, “ctx”:“main”,“msg”:“Implicit TCP FastOpen unavailable. If TCP FastOpen is required, set tcpFastOpenServer, tcpFastOpenClient, and tcpFastOpenQueueSize.”}
{“t”:{"$date":“2021-06-26T12:43:35.156Z”},“s”:“D1”, “c”:“EXECUTOR”, “id”:23104, “ctx”:“OCSPManagerHTTP-0”,“msg”:“Starting thread”,“attr”:{“threadName”:“OCSPManagerHTTP-0”,“poolName”:“OCSPManagerHTTP”}}
MongoDB shell version v4.4.6
connecting to: mongodb://xxx-shard-00-02.m32cu.mongodb.net:27017,xxx-shard-00-01.m32cu.mongodb.net:27017,xxx-shard-00-00.m32cu.mongodb.net:27017/ycsb?compressors=disabled&gssapiServiceName=mongodb
{“t”:{"$date":“2021-06-26T12:43:35.196Z”},“s”:“D1”, “c”:“NETWORK”, “id”:20109, “ctx”:“js”,“msg”:“Creating new connection”,“attr”:{“hostAndPort”:“xxx-shard-00-02.m32cu.mongodb.net:27017”}}
{“t”:{"$date":“2021-06-26T12:43:35.452Z”},“s”:“D1”, “c”:“NETWORK”, “id”:20119, “ctx”:“js”,“msg”:“Connected to host”,“attr”:{“connString”:“xxx-shard-00-02.m32cu.mongodb.net:27017”}}
{“t”:{"$date":“2021-06-26T12:43:35.667Z”},“s”:“I”, “c”:“NETWORK”, “id”:20125, “ctx”:“js”,“msg”:“DBClientConnection failed to receive message”,“attr”:{“connString”:“xxx-shard-00-02.m32cu.mongodb.net:27017”,“error”:“HostUnreachable: Connection closed by peer”}}
{“t”:{"$date":“2021-06-26T12:43:35.667Z”},“s”:“D1”, “c”:"-", “id”:23074, “ctx”:“js”,“msg”:“User assertion”,“attr”:{“error”:“HostUnreachable: network error while attempting to run command ‘isMaster’ on host ‘xxx-shard-00-02.m32cu.mongodb.net:27017’ “,“file”:“src/mongo/client/dbclient_base.cpp”,“line”:225}}
{“t”:{”$date”:“2021-06-26T12:43:35.667Z”},“s”:“D1”, “c”:“NETWORK”, “id”:20109, “ctx”:“js”,“msg”:“Creating new connection”,“attr”:{“hostAndPort”:“xxx-shard-00-01.m32cu.mongodb.net:27017”}}
{“t”:{"$date":“2021-06-26T12:43:36.673Z”},“s”:“D1”, “c”:“NETWORK”, “id”:20119, “ctx”:“js”,“msg”:“Connected to host”,“attr”:{“connString”:“xxx-shard-00-01.m32cu.mongodb.net:27017”}}

“msg”:“DBClientConnection failed to receive message”

This is what I am getting back.

Any help would be appreciated!

The IP seen by Atlas is not necessarly the IP of your workstation. VPN and NAT routers have their own IP. Try allowing from anywhere.

1 Like

Yep @steevej .

It is set to “allow from anywhere” (0.0.0.0/0) but still the results are same.

Is your connect string complete/correct?
Did you take it from Atlas or prepared yourselves
I think replicaset name & SSL are missing

Is SRV connect string not working for you?

2 Likes

I notice 2 things about your connection string. You have a space between the 2nd and 3rd host of the replica set. The other thing is that your connection string mentionned myDatabase yet the error message indicates ycsb as the database. I am affraid that we trying to diagnosed with missing or wrong information. If you have good password, there is no reason why you are hiding your cluster hosts. It makes it hard for us to make a good investigation.

1 Like

Hi @steevej ,

There are no space I can confirm that. I’ve strong password set already, I am not worried about that. Here is my host.

mongodb://xxx:xxx@benchmarkcluster-shard-00-02.m32cu.mongodb.net:27017,benchmarkcluster-shard-00-01.m32cu.mongodb.net:27017,benchmarkcluster-shard-00-00.m32cu.mongodb.net:27017/ycsb

@Ramachandra_Tummala , I tried to add replicaset name as well as ssl options.

mongodb://xxx:xxx@benchmarkcluster-shard-00-02.m32cu.mongodb.net:27017,benchmarkcluster-shard-00-01.m32cu.mongodb.net:27017,benchmarkcluster-shard-00-00.m32cu.mongodb.net:27017/ycsb?replicaSet=replica-set-name&ssl=true

But the error is still same!

I would be surprised if the replica set from Atlas is name replica-set-name. Can you share the SRV so that we can verify.

with SRV, it is working

“mongodb+srv://xxx:xxx@benchmarkcluster.m32cu.mongodb.net/ycsb?retryWrites=true&w=majority”

Your replica xet name is atlas-12120x-shard-0.

Yep. Tried that too.

*** 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-12120x-shard-0/benchmarkcluster-shard-00-01.m32cu.mongodb.net:27017,benchmarkcluster-shard-00-02.m32cu.mongodb.net:27017,benchmarkcluster-shard-00-00.m32cu.mongodb.net:27017 :
connect@src/mongo/shell/mongo.js:374:17
@(connect):2:6
{"t":{"$date":"2021-06-26T16:43:29.878Z"},"s":"D1", "c":"-",        "id":23074,   "ctx":"js","msg":"User assertion","attr":{"error":"Location12513: connect failed","file":"src/mongo/shell/shell_utils.cpp","line":520}}
{"t":{"$date":"2021-06-26T16:43:29.879Z"},"s":"I",  "c":"QUERY",    "id":22787,   "ctx":"js","msg":"MozJS GC heap stats","attr":{"phase":"prologue","total":4528265,"limit":0}}
{"t":{"$date":"2021-06-26T16:43:29.882Z"},"s":"I",  "c":"QUERY",    "id":22787,   "ctx":"js","msg":"MozJS GC heap stats","attr":{"phase":"epilogue","total":2825,"limit":0}}
{"t":{"$date":"2021-06-26T16:43:29.882Z"},"s":"D1", "c":"-",        "id":23074,   "ctx":"main","msg":"User assertion","attr":{"error":"Location12513: connect failed","file":"src/mongo/scripting/mozjs/proxyscope.cpp","line":310}}
exception: connect failed
exiting with code 1

Connect string should look like this

Try in this format and see if it works

mongo “mongodb://cluster0-shard-00-00.xxxx.mongodb.net:27017,cluster0-shard-00-01.xxxx.mongodb.net:27017,cluster0-shard-00-02.xxxx.mongodb.net:27017/myFirstDatabase?replicaSet=Cluster0-shard-0” --ssl --authenticationDatabase admin --username --password

Yes. If I write connection this way it is working.

But what I want & I learned is, we can include “username:password” in connection string itself and can also pass ssl as an option. Connection String Options

Let’s say, I am removing ycsb or any database after /, then it will take admin db as a default authSource. Then it should work, because the users are created on admin db. But it’s still not working.

May be you are missing something in your connect string

Try this string which is as per your requirement without dbname in the string
It connects to class cluster and puts you in test DB(default)

mongo “mongodb://m121:aggregations@cluster0-shard-00-00-jxeqq.mongodb.net:27017,cluster0-shard-00-01-jxeqq.mongodb.net:27017,cluster0-shard-00-02-jxeqq.mongodb.net:27017/?replicaSet=Cluster0-shard-0&ssl=true