Error: querySrv ESERVFAIL _mongodb._tcp.cluster0.abcd0.mongodb.net

Viewed 5353

My nodejs app was working fine with mongodb connection and suddenly this error got appeared. Then I tried to connect to mongodb with mongo compass and same error is there. I could not find out any reason for this.

Error: querySrv ESERVFAIL _mongodb._tcp.cluster0.abcd0.mongodb.net
[nodemon] app crashed - waiting for file changes before starting...

Then I changed the mongodb connection url to old url and after that I got this error.

Error: Could not connect to any servers in your MongoDB Atlas cluster. One common reason is that you're trying to access the database from an IP that isn't whitelisted. Make sure your current IP address is on your Atlas cluster's IP whitelist: https://docs.atlas.mongodb.com/security-whitelist/
[nodemon] app crashed - waiting for file changes before starting...

I have already white listed my ips and my configurations are correct (I double checked). 0.0.0.0/0 (includes your current IP address)

What is the reason for this ?

Thank you.

5 Answers

querySrv ESERVFAIL is a DNS error.

This means that your local machine is not able to get a response from your DNS resolver for the SRV record _mongodb._tcp.cluster0.abcd0.mongodb.net (I assume that's not your real hostname, but it will work for an example)

From your local machine, test SRV lookup from a command line, possibly one of these:

nslookup -type=SRV _mongodb._tcp.cluster0.abcd0.mongodb.net
host -t SRV _mongodb._tcp.cluster0.abcd0.mongodb.net

If that fails, feel free to say bad things about your DNS provider.

Then go to the Atlas UI and get the pre-3.6 connection string. It will start with mongodb:// and not mongodb+srv://.

Joe's identification of the problem is spot on and help me with a resolution. This was fixed for me after adding Google's DNS server (8.8.8.8) to the Wifi settings of my computer.

On MacOS its in Settings > Network > Wi-Fi (select the appropriate network) > Advanced > DNS Then add the DNS Server 8.8.8.8

Stop the server and run again your server and it will solve the problem.

I was a windows10 user and I was facing exactly the same problem. I have figure out it's a DNS problem. the following process worked for me

-Open the Control Panel.
-Click Network and Internet.
-Click Network and Sharing Center.
-On the left pane, click Change adapter settings.
-Right-click the network interface connected to the internet, then click Properties.
-Choose Internet Protocol Version 4 (TCP/IPv4).
-Click Properties.
-Click Use the following DNS server addresses.
-Click Advanced.
-Enter 208.67.222.222 and 208.67.220.220 in the DNS server fields.
-Click OK, then click Close.

Check this! if you are non windows 10 user

Hey Guys!

So i was having this weird error below :(

Error: querySrv ESERVFAIL _mongodb._tcp.cluster0.velr6at.mongodb.net

So what might be causeing this error?

  • make sure the database you trying to create n your mongoDB collections exist for me it was "userDB" that was the issue for me!

enter image description here

mongoose.connect(
    `mongodb+srv://admin-eniola:${process.env.PASSWORD}@cluster0.velr6at.mongodb.net/userDB`
);

  • makes sure you check whatever password you using, it must correlate with your user password not account password!
  • check where your password is stored your program either dotenv or secrets file and make sure it match with your user account password.

Thanks and i hope this solutions works for you as well!

Related