Unable to connect to MongoDB Cluster

You are using Enterprise Edition and I have community edition installed. Does this make any difference? I was told it doesn’t, not in M001 course at least.

Here is the ping result:

ping: ajbozdarcluster0-srzz3.mongodb.net: No address associated with hostname

It shouldn’t make a difference. It’s most likely your machine or network. Are you using a work laptop? And are you connected to a corporate network?

Here are the correct hostnames for pinging:

  • ping ajbozdarcluster0-shard-00-00-srzz3.mongodb.net
  • ping ajbozdarcluster0-shard-00-01-srzz3.mongodb.net
  • ping ajbozdarcluster0-shard-00-02-srzz3.mongodb.net

And test the port 27017 by opening this page:

Or you can use telnet.


From the second screenshot, you are connected to the mongo shell.
Run the following commands:
show dbs
show collections

Outcomes of each of above commands:

Something is fishy!

You most likely ran mongo --nodb at some point in the past. Open a new terminal and try again.

Error: Authentication failed. :

Let’s see a full screenshot

Let’s see the results of my post #23?

I am going to sleep now. It is already 03:59 here, 3 hours and 20 minutes more to dawn.
Enough nerd work! You too take some rest, hacker! I’m leaving all settings, usernames and passwords as they are.

Million thanks for the time. This work needs an article to be published on medium.

Same error for me but solved by add
–AuthenticationDatabase admin --TLS to command

Interesting observation @Mk.elsawy. Those two options are supposed to be implied by Atlas when you make a connection:

But worth a try! Let’s see if it works for @ajbozdar:
mongo "mongodb+srv://ajbozdarcluster0-srzz3.mongodb.net/test" --username user --password mypass12 --authenticationDatabase admin --tls
NB: Swap --tls for --ssl for older versions of mongo < 4.2.

If that still doesn’t work, do a portquiz test (i.e. from post #23) to port 27015.

Last try will be this connection string:
mongo "mongodb://ajbozdarcluster0-shard-00-00-srzz3.mongodb.net:27017,ajbozdarcluster0-shard-00-01-srzz3.mongodb.net:27017,ajbozdarcluster0-shard-00-02-srzz3.mongodb.net:27017/test?replicaSet=ajbozdarCluster0-shard-0" --ssl --authenticationDatabase admin --username user --password mypass12

NB: I can see that you’re using mongo shell version 4.2 and I vaguely recall someone else having the same issue as you. And just in case you’re using a VPN, either disconnect it or connect to a US or Europe zone.

I tried below connection string for both readwrite and readonly user and it worked. It worked on all old and new user credentials without any VPN in the middle.

mongo "mongodb+srv://ajbozdarcluster0-srzz3.mongodb.net/test" --username user --password mypass12 --authenticationDatabase admin --tls


MongoDB shell version v4.2.2
connecting to: mongodb://ajbozdarcluster0-shard-00-00-srzz3.mongodb.net:27017,ajbozdarcluster0-shard-00-01-srzz3.mongodb.net:27017,ajbozdarcluster0-shard-00-02-srzz3.mongodb.net:27017/test?authSource=admin&compressors=disabled&gssapiServiceName=mongodb&ssl=true
Implicit session: session { "id" : UUID("842e251a-2479-42d4-a666-c37e3bbe3008") }
MongoDB server version: 4.0.13
WARNING: shell and server versions do not match
Error while trying to show server startup warnings: user is not allowed to do action [getLog] on [admin.]
MongoDB Enterprise ajbozdarCluster0-shard-0:SECONDARY> 

I usually get connected to secondary replica rather than primary one. I am checking this with a VPN and see if it connects to primary.

You should be redirected to the Primary. Try the longer connection I gave in my last post.

Yes, it does. No VPN in the middle.

So now the conclusion is that the Atlas doesn’t resolve connection string as admin and tls itself. The user has to include it himself to connect with the cluster. Atlas then accepts connection on secondary replica rather than on primary until it is explicitly told to connect with the primary replica.

What does?

For the sake of testing, try swapping tls for ssl:
mongo "mongodb+srv://ajbozdarcluster0-srzz3.mongodb.net/test" --username user --password mypass12 --authenticationDatabase admin --ssl

The observation is here:

Mongo Version 4.2 doesn’t play well with the Atlas SRV connection string.

Longer connection string.

It gave me a deprecated ssl warning and asked to use tls but connected with primary replica without any further issue.

For clarity, you’re saying that both the longer connection string and the SRV (shorter) connection string (with explicit authDb + tls) directs you to the PRIMARY now? What happens when you have VPN on?

Quite right!