Unable to connect Atlas from Mongo Shell in Mac OS

Getting following error while executing the following command from Mac terminal

———————————————————————————
$ mongo “mongodb+srv://sandbox-w45fy.mongodb.net/test” --username m001-student --password m001-mongodb-basics

DNSHostNotFound: Failed to look up service “_mongodb._tcp.sandbox-w45fy.mongodb.net”: Connection refused

try ‘mongo --help’ for more information
——————————————————————————————————————

Mongo shell version in my system is v4.2.3

Could you please suggest how to resolve this issue?

Your URI looks fine. But it might be the fancy Mac double quotes. Try with single quotes or standard double quotes.

Hi steevej-1495,
I just tried both the options, with single quote and with standard double quotes. In both the cases I am getting same DNSHost not found error.

Must be a firewall issue or something like that.

I connected just fine with your URI.

: steevej @ asus-laptop ;  mongo mongodb+srv://sandbox-w45fy.mongodb.net/test --username m001-student --password m001-mongodb-basics
MongoDB shell version v4.0.5
connecting to: mongodb://sandbox-shard-00-00-w45fy.mongodb.net.:27017,sandbox-shard-00-01-w45fy.mongodb.net.:27017,sandbox-shard-00-02-w45fy.mongodb.net.:27017/test?authSource=admin&gssapiServiceName=mongodb&replicaSet=Sandbox-shard-0&ssl=true
2020-02-03T09:38:24.529-0500 I NETWORK  [js] Starting new replica set monitor for Sandbox-shard-0/sandbox-shard-00-00-w45fy.mongodb.net.:27017,sandbox-shard-00-01-w45fy.mongodb.net.:27017,sandbox-shard-00-02-w45fy.mongodb.net.:27017
2020-02-03T09:38:24.648-0500 I NETWORK  [ReplicaSetMonitor-TaskExecutor] Successfully connected to sandbox-shard-00-01-w45fy.mongodb.net.:27017 (1 connections now open to sandbox-shard-00-01-w45fy.mongodb.net.:27017 with a 5 second timeout)
2020-02-03T09:38:24.649-0500 I NETWORK  [js] Successfully connected to sandbox-shard-00-02-w45fy.mongodb.net.:27017 (1 connections now open to sandbox-shard-00-02-w45fy.mongodb.net.:27017 with a 5 second timeout)
2020-02-03T09:38:24.671-0500 I NETWORK  [js] changing hosts to Sandbox-shard-0/sandbox-shard-00-00-w45fy.mongodb.net:27017,sandbox-shard-00-01-w45fy.mongodb.net:27017,sandbox-shard-00-02-w45fy.mongodb.net:27017 from Sandbox-shard-0/sandbox-shard-00-00-w45fy.mongodb.net.:27017,sandbox-shard-00-01-w45fy.mongodb.net.:27017,sandbox-shard-00-02-w45fy.mongodb.net.:27017
2020-02-03T09:38:24.741-0500 I NETWORK  [js] Successfully connected to sandbox-shard-00-01-w45fy.mongodb.net:27017 (1 connections now open to sandbox-shard-00-01-w45fy.mongodb.net:27017 with a 5 second timeout)
2020-02-03T09:38:24.742-0500 I NETWORK  [ReplicaSetMonitor-TaskExecutor] Successfully connected to sandbox-shard-00-02-w45fy.mongodb.net:27017 (1 connections now open to sandbox-shard-00-02-w45fy.mongodb.net:27017 with a 5 second timeout)

Hi @Sujay_38319,

It looks like your cluster is unhealthy. I am not able to connect to your cluster. If you are still facing this issue then I will recommend you to create another cluster.

@steevej-1495 Can you please confirm if you are still able to connect to this cluster ?

Thanks,
Shubham Ranjan
Curriculum Services Engineer

No. This morning it is not working.

Hi steevej-1495,
I created a new Custer but getting same error
mongo “mongodb+srv://cluster0-imdxd.mongodb.net/test” --username m001-student --password m001-mongodb-basics

Thanks and Regards,
Sujay Dey

As already mentioned

With your fancy Mac double quotes I get:

: steevej @ xps ; mongo “mongodb+srv://cluster0-imdxd.mongodb.net/test” --username m001-student --password m001-mongodb-basics
MongoDB shell version v3.6.16
exception: No digits

But with simple and normal double quotes I was able to connect with both the shell and compass.

Hi steevej,
Could you please share the URI that is working for you? It will be very helpful. Because I already used standard quotes and getting DNSHost not found error from two MAC system and with that same standard quote I am able to connect the URI given in earlier chapter.

Few more observation

Observation 1: While I am executing following URI

mongo "mongodb+srv://cluster0-imdxd.mongodb.net/test"  --username m001-student --password m001-mongodb-basics

Output is => DNSHostNotFound: Failed to look up service “_mongodb._tcp.cluster0-imdxd.mongodb.net”: Connection refused

try ‘mongo --help’ for more information

Observation 2: While I am executing

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

The output is => 2020-02-04T23:14:23.457+0800 W CONTROL [main] Option: ssl is deprecated. Please use tls instead.

MongoDB shell version v4.2.3

connecting to: mongodb://cluster0-shard-00-00-imdxd.mongodb.net:27017,cluster0-shard-00-01-imdxd.mongodb.net:27017,cluster0-shard-00-02-imdxd.mongodb.net:27017/test?authSource=admin&compressors=disabled&gssapiServiceName=mongodb&replicaSet=Cluster0-shard-0

2020-02-04T23:14:23.599+0800 I NETWORK [js] Starting new replica set monitor for Cluster0-shard-0/cluster0-shard-00-00-imdxd.mongodb.net:27017,cluster0-shard-00-01-imdxd.mongodb.net:27017,cluster0-shard-00-02-imdxd.mongodb.net:27017
2020-02-04T23:14:23.599+0800 I CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cluster0-shard-00-00-imdxd.mongodb.net:27017
2020-02-04T23:14:23.599+0800 I CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cluster0-shard-00-01-imdxd.mongodb.net:27017
2020-02-04T23:14:23.599+0800 I CONNPOOL [ReplicaSetMonitor-TaskExecutor] Connecting to cluster0-shard-00-02-imdxd.mongodb.net:27017
2020-02-04T23:14:25.759+0800 I NETWORK [ReplicaSetMonitor-TaskExecutor] Confirmed replica set for Cluster0-shard-0 is Cluster0-shard-0/cluster0-shard-00-00-imdxd.mongodb.net:27017,cluster0-shard-00-01-imdxd.mongodb.net:27017,cluster0-shard-00-02-imdxd.mongodb.net:27017

Implicit session: session { "id" : UUID("f94ae331-2892-4d47-b57c-6405c691839d") }

MongoDB server version: 4.2.3

Error while trying to show server startup warnings: user is not allowed to do action [getLog] on [admin.]

MongoDB Enterprise Cluster0-shard-0:PRIMARY>

In both the case I am using same quote.

I am using the URI you supplied.

: steevej @ xps ; mongo 'mongodb+srv://cluster0-imdxd.mongodb.net/test' --username m001-student --password m001-mongodb-basics
MongoDB shell version v3.6.16
connecting to: mongodb://cluster0-shard-00-00-imdxd.mongodb.net.:27017,cluster0-shard-00-01-imdxd.mongodb.net.:27017,cluster0-shard-00-02-imdxd.mongodb.net.:27017/test?authSource=admin&gssapiServiceName=mongodb&replicaSet=Cluster0-shard-0&ssl=true
2020-02-04T10:22:01.323-0500 I NETWORK  [thread1] Starting new replica set monitor for Cluster0-shard-0/cluster0-shard-00-00-imdxd.mongodb.net.:27017,cluster0-shard-00-01-imdxd.mongodb.net.:27017,cluster0-shard-00-02-imdxd.mongodb.net.:27017
2020-02-04T10:22:01.454-0500 I NETWORK  [thread1] Successfully connected to cluster0-shard-00-00-imdxd.mongodb.net.:27017 (1 connections now open to cluster0-shard-00-00-imdxd.mongodb.net.:27017 with a 5 second timeout)
2020-02-04T10:22:01.470-0500 I NETWORK  [ReplicaSetMonitor-TaskExecutor-0] Successfully connected to cluster0-shard-00-02-imdxd.mongodb.net.:27017 (1 connections now open to cluster0-shard-00-02-imdxd.mongodb.net.:27017 with a 5 second timeout)
2020-02-04T10:22:01.601-0500 I NETWORK  [thread1] Successfully connected to cluster0-shard-00-01-imdxd.mongodb.net:27017 (1 connections now open to cluster0-shard-00-01-imdxd.mongodb.net:27017 with a 5 second timeout)
2020-02-04T10:22:01.603-0500 I NETWORK  [ReplicaSetMonitor-TaskExecutor-0] Successfully connected to cluster0-shard-00-01-imdxd.mongodb.net.:27017 (1 connections now open to cluster0-shard-00-01-imdxd.mongodb.net.:27017 with a 5 second timeout)
2020-02-04T10:22:01.624-0500 I NETWORK  [thread1] changing hosts to Cluster0-shard-0/cluster0-shard-00-00-imdxd.mongodb.net:27017,cluster0-shard-00-01-imdxd.mongodb.net:27017,cluster0-shard-00-02-imdxd.mongodb.net:27017 from Cluster0-shard-0/cluster0-shard-00-00-imdxd.mongodb.net.:27017,cluster0-shard-00-01-imdxd.mongodb.net.:27017,cluster0-shard-00-02-imdxd.mongodb.net.:27017
2020-02-04T10:22:01.742-0500 I NETWORK  [ReplicaSetMonitor-TaskExecutor-0] Successfully connected to cluster0-shard-00-00-imdxd.mongodb.net:27017 (1 connections now open to cluster0-shard-00-00-imdxd.mongodb.net:27017 with a 5 second timeout)
2020-02-04T10:22:01.874-0500 I NETWORK  [ReplicaSetMonitor-TaskExecutor-0] Successfully connected to cluster0-shard-00-02-imdxd.mongodb.net:27017 (1 connections now open to cluster0-shard-00-02-imdxd.mongodb.net:27017 with a 5 second timeout)
Implicit session: session { "id" : UUID("e49746ad-ee0e-4442-a0c1-4afa4323b005") }
MongoDB server version: 4.2.3
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 Cluster0-shard-0:PRIMARY> exit
bye
: steevej @ xps ; 

I starting to suspect that your are using a dated DNS server. May be your are using a VPN and their DNS does not understand the new SRV. It also could be your internet provider that uses a dated server. If you could setup your system to connect to DNS server 8.8.8.8 and 8.8.4.4 (google’s public DNS server) it might solve the issue.

that double quote thing is worked for me. thanks a lot.

Hey @emre_samurlu,

Welcome to MongoDB Community Forums,

We are glad that you found this thread useful.

In case of any questions, please feel free to reach out to us!

Good Luck,
Kushagra