Can't connect to MongoDB Atlas - querySrv ENOTFOUND

Hi all,

First of all, if this is not the right category, please let me know which one is.

I’m new to MongoDB. Made a local deploy and it’s running fine. Now I’m trying to set up an Atlas instance, but can’t seem to be able to connect to it.
I’m trying to use the string

mongodb+srv://pdantas:@cluster0.n2hlh.mongodb.net/test

as suggested in the “connect” session in Atlas console, however, when I enter this string in Compass I get the error

querySrv ENOTFOUND _mongodb._tcp.cluster0.n2hlh.mongodb.net

I’ve also tried connecting through mongosh and get the same error

C:\Users\OS16S8898>mongosh “mongodb+srv://cluster0.c0tbu.mongodb.net/myFirstDatabase” --username pdantas
Enter password: *******
Current Mongosh Log ID: 6165e8a56936fb42f0cbf229
Connecting to: mongodb+srv://cluster0.c0tbu.mongodb.net/myFirstDatabase
Error: querySrv ENOTFOUND _mongodb._tcp.cluster0.c0tbu.mongodb.net

I’ve whitelisted my IP, and even added 0.0.0.0/0 to the IP access list, to no avail. Can someone please help me find out what is it that I’m doing wrong?

Thanks!

Hi @Pedro_Dantas,

Which versions are you using?

  • Compass
  • MongoDB Atlas cluster
  • Mongosh

Also, this topic had a solution: README "Running Application" Error: querySrv ENOTFOUND [SOLVED] - #3 by Jason_Chiang_84661

Does it work for you too?

1 Like

Try using google’s DNS 8.8.8.8 and 8.8.4.4.

See Public DNS  |  Google Developers for more details.

1 Like

Hi @MaBeuLux88.

  • Compass 1.28.4
  • MongoDB Atlas cluster 4.4.9
  • Mongosh 1.1.0

Those were the latest versions that I could find.

About the solution detailed in the link, I tried formatting the string as instructed (using the mongodb protocol and a lista of the URLs for each shard separated by a comma) but still can’t get a connection (it does seem to be able to resolve the IP address, though).

C:\Users\OS16S8898>mongosh mongodb://pdantas:pdantas@cluster0-shard-00-00.c0tbu.mongodb.net:27017,cluster0-shard-00-01.c0tbu.mongodb.net:27017,cluster0-shard-00-02.c0tbu.mongodb.net:27017/test
Current Mongosh Log ID: 6166f8446f2747e87b767609
Connecting to:          mongodb://<credentials>@cluster0-shard-00-00.c0tbu.mongodb.net:27017,cluster0-shard-00-01.c0tbu.mongodb.net:27017,cluster0-shard-00-02.c0tbu.mongodb.net:27017/test
MongoServerSelectionError: connection <monitor> to 108.129.24.16:27017 closed

Am I still missing something?

Thanks.

Hi @steevej I added those IP’s to the whitelist but nothing happened, was I supposed to do something else?

Thanks.

The 2 IPs I provided are not at all related to the white list of your cluster. It has to do with host name resolution, aka DNS. In the link I provided you will find instructions for

Configure your network settings to use the IP addresses 8.8.8.8 and 8.8.4.4 as your DNS servers.

Your ISP or VPN provider probably uses old DNS software that cannot resolve SRV connection strings.

I have just notice that your original post contains 2 different connection strings, one with c0tbu and one with n2hlh.

Make sure to retrieve the Compass connection string from the MongoDB Atlas UI like this:

Of course make sure to change the values for the username and password.
They come from this menu. It’s not the Atlas user/pwd.

In the end, it should look like this:

mongodb+srv://readonly:readonly@covid-19.hip2i.mongodb.net/test

Try to connect using the above connection string in Compass to see if it works. This is the public cluster where I’m hosting the Open Data COVID-19 data set.

If that doesn’t work - then you have a DNS problem like @steevej explained and you have to add 8.8.8.8 and/or 8.8.4.4 in your DNS list.

For me on linux, I would have to add on the first line of /etc/resolv.conf:

nameserver 8.8.8.8
<keep the former DNS line in here>

Cheers,
Maxime.

Hi guys,

I was already using the connection string provided by the Atlas console, to no avail.
I changed the DNS to Google’s

SSID:	Pivonet 5G
Protocol:	Wi-Fi 5 (802.11ac)
Security type:	WPA2-Personal
Network band:	5 GHz
Network channel:	100
IPv6 address:	2001:818:e348:c700:2093:b4f9:eef:80a8
Link-local IPv6 address:	fe80::2093:b4f9:eef:80a8%19
IPv6 DNS servers:	2001:4860:4860::8888
2001:4860:4860::8844
IPv4 address:	192.168.1.143
IPv4 DNS servers:	8.8.8.8
8.8.4.4
Manufacturer:	Intel Corporation
Description:	Intel(R) Wireless-AC 9560 160MHz
Driver version:	21.120.0.9
Physical address (MAC):	84-C5-A6-6A-70-6B

but it’s still not working

I also tried to connect to the Covid19 DB as suggested by Maxime but get the same error.

However, I found out that I do can connect through mongoshell :smiley:

C:\Users\OS16S8898>mongosh mongodb+srv://readonly:readonly@covid-19.hip2i.mongodb.net/covid19
Current Mongosh Log ID: 61680c1143666d0fa2a10a77
Connecting to:          mongodb+srv://<credentials>@covid-19.hip2i.mongodb.net/covid19
Using MongoDB:          4.4.9
Using Mongosh:          1.1.0

For mongosh info see: https://docs.mongodb.com/mongodb-shell/

Atlas covid-19-shard-0 [primary] covid19>

So I’m guessing I can work through here, but if you have any further idea on why the connection though Compass isn’t working I’d love to hear, as I’d rather work that way if possible.

Thanks for the assistance so far :slight_smile:

PD

Can you connect to

mongodb+srv://readonly:readonly@covid-19.hip2i.mongodb.net/test

Using MongoDB Compass?

@MaBeuLux88 No, as I said I get the same error

What’s your OS & are you up-to-date ? Looks like there is definitely something wrong with your Internet connection. Are you behind a VPN maybe? Firewall? Or maybe it’s just a DNS issue as @steevej suggested.
Can you try a different internet connection & disable everything than can cause connection issues? Antivirus software can block connections sometimes as well. If it works reactive them one by one and eliminate the troublemaker :smiley: !

Cheers,
Maxime.