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!

1 Like

Hi @Pedro_Dantas,

Which versions are you using?

  • Compass
  • MongoDB Atlas cluster
  • Mongosh

Also, this topic had a solution: https://www.mongodb.com/community/forums/t/readme-running-application-error-querysrv-enotfound-solved/85196/3

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.

2 Likes

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.

2 Likes

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

1 Like

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.

1 Like

On my side I was having the same issue and by disabling my VPN, the connection worked.

Due to work, I need to use a VPN so how can we fix this issue other than disabling the VPN?

Your work probably disabled connections to port 27017 or maybe they have even more restrictive rules in place. You need to talk to your IT support. Pity that your work system & network doesn’t allow you to work :sweat_smile:. I guess they are just missing an exception on this port in their gateway rules. But I’m not an expert :confused:.

Try http://portquiz.net:27017/ to see if it is the above.

1 Like

This is happening to me now after Windows automatically updated to version 10.0.19042 Build 19042.

Last night things were working fine, got up today and my machine had restarted & updated. Skipped Windows 11 spam at startup, started up my dev environment in WSL1 like always, and now I can’t work. Anyone else experiencing this?

I can connect with Compass just fine.

I’m not connected to VPN (which does mess up connections to Atlas, although with a different error). Until today I have never seen the error in OP’s post.

telnet portquiz.net 27017 is failing, so I’m guessing something in the Windows update affected Windows Defender.

Couldn’t ping google.com either.

[SOLVED]

This worked for me: edit /etc/wsl.conf and set generateResolvConf = true

Thanks, here it worked.

1 Like

I have the same problem because I was connected to a VPN, when I disconnect it it works immediately.

1 Like

Having run into a host of issues using private endpoints, some or most self inflicted, I have come the assumption that the “Error: querySrv ENOTFOUND” has to do with the inability of the driver to resolve a FQDN of the “mongodb+srv” to names of the replica set members.

2 Likes

The error generally indicates the FQDN for the associated host(s) for the SRV record were not able to be resolved by the DNS in use.

As of the time of this message, the SRV record prefix for Atlas clusters is _mongodb._tcp.

Below is a reproduction that shows this error. Let’s say I have a cluster which has an associated SRV record which resolves to the following hostnames:

nslookup -type=SRV _mongodb._tcp.cluster0.k0ke7qa.mongodb.net
<REDACTED INFO>

Non-authoritative answer:
_mongodb._tcp.cluster0.k0ke7qa.mongodb.net	service = 0 0 27017 ac-omkxrjv-shard-00-00.k0ke7qa.mongodb.net.
_mongodb._tcp.cluster0.k0ke7qa.mongodb.net	service = 0 0 27017 ac-omkxrjv-shard-00-01.k0ke7qa.mongodb.net.
_mongodb._tcp.cluster0.k0ke7qa.mongodb.net	service = 0 0 27017 ac-omkxrjv-shard-00-02.k0ke7qa.mongodb.net.

Although not exactly the case for all similar errors generated and only for demonstration purposes, I will pass through an invalid SRV record (to some degree attempt to mimic the DNS being unable to resolve the SRV records):

nslookup -type=SRV _mongodb._tcp.cluster0.abcdefg.mongodb.net
<REDACTED INFO>

** server can't find _mongodb._tcp.cluster0.abcdefg.mongodb.net: NXDOMAIN

Using the DNS seed list connection format with the invalid SRV record above in Compass results in the querySrv ENOTFOUND error:

In conclusion, the error querySrv ENOTFOUND was caused by DNS resolving issues, likely from the client side. Also as several people have noted in this thread, if you’re using VPN and encountering this issue only on the VPN (i.e. Connection works fine without querySRV error outside of the VPN connection) then it is probably due to how the VPN is configured. To my knowledge there are some VPN’s which assign a new DNS for the VPN session which could result in this error.

4 Likes