Error: querySrv ENOTFOUND _mongodb._tcp.dbname.fzofb.mongodb.net
Asked Answered
A

15

5

I'm learning Node.js and just started working with MongoDB.

I'm making a connection with the MongoDB Cluster I've created

const dbURI = 'mongodb+srv://testuser:[email protected]/mydb?retryWrites=true&w=majority';
mongoose.connect(dbURI, { useNewUrlParser: true, useUnifiedTopology: true })
    .then((result) => console.log('connected to db'))
    .catch((err) => console.log(err));

When I run it nodemon app I get this error:

Error: querySrv ENOTFOUND _mongodb._tcp.mydb.fzofb.mongodb.net at QueryReqWrap.onresolve [as oncomplete] (node:dns:206:19) { errno: undefined, code: 'ENOTFOUND', syscall: 'querySrv',
hostname: '_mongodb._tcp.mydb.fzofb.mongodb.net' }

Assassinate answered 8/1, 2021 at 4:19 Comment(1)
Does this answer your question? How to fix 'Error: querySrv EREFUSED' when connecting to MongoDB Atlas?Ornithosis
A
5

The error indicates that there is no error in the code. This leaves you with three potential possibilities:

  1. Ensure you have MongoDB installed on your computer.
  2. Make sure you're connected to wifi that is not public.
  3. Make sure you have allowed the IP in network access of MongoDB as shown in the image below:

enter image description here

In my case, I was connected to public wifi in a coworking space. I change my connection to my personal hotspot and it worked.

Assassinate answered 8/1, 2021 at 4:49 Comment(0)
I
14

If you have your mongodb Atlas cluster inactive after some time. It could get paused, and then when you run a server it returns the error you had.

Login to your Atlas account and confirm if it hasn't been paused. Well, this option of mine should only be considered after trying the options above.

Interflow answered 29/10, 2021 at 15:2 Comment(2)
@Bracken How is this not an answer to the question? I got the same error and this solved my problem. It couldn't be any more clear.Clemenciaclemency
Apologies, your post does contain an answer, but you've written it in the form of a commentary on the previous answer. Try to write your answers in a self contained manor, as if they might be the top answer. Don't start with "Also".Mcclurg
A
5

The error indicates that there is no error in the code. This leaves you with three potential possibilities:

  1. Ensure you have MongoDB installed on your computer.
  2. Make sure you're connected to wifi that is not public.
  3. Make sure you have allowed the IP in network access of MongoDB as shown in the image below:

enter image description here

In my case, I was connected to public wifi in a coworking space. I change my connection to my personal hotspot and it worked.

Assassinate answered 8/1, 2021 at 4:49 Comment(0)
M
4

I had the same issue. I was using the latest srv string. I don't know if this will help you. But using the olderve

mongodb://<username>:<password>@cluster0-shard-00-00.2pznz.mongodb.net:27017,cluster0-shard-00-01.2pznz.mongodb.net:27017,cluster0-shard-00-02.2pznz.mongodb.net:27017/myFirstDatabase?ssl=true&replicaSet=atlas-s5orlv-shard-0&authSource=admin&retryWrites=true&w=majority```
Magdeburg answered 1/5, 2021 at 7:49 Comment(1)
This comment helped me to resolve an issue running MongoDB on my localhost in WSL2. By removing +srv from the connection string, the connection worked as expected.Indorse
W
4

Try disabling VPN if enabled. It helped me.

Weaver answered 4/11, 2021 at 18:47 Comment(0)
M
4

You need to convert special characters in connection string password to percent encoding.

I had the same issue with mongodb-compass. For me it was incorrect connection string format. So in my case it required to convert @ symbol in my password to %40 (percent encoding).

You can read more about this in here. and here.

Maziar answered 10/1, 2022 at 4:39 Comment(0)
W
1

This error happens if the IP Address you try to access the database with is not on the IP Access List. Go to MongoDB Login and under security click on the Network Access and check if your IP is added there.

Wooton answered 11/12, 2021 at 17:47 Comment(0)
S
0

I've observed this issue as well. Common cause for the error is that your cluster is stopped as no activity for more than 60 days.

Solution:

  1. To resolve this issue go to mongoDB website & login.
  2. You will observe the "Resume" button once you click on Database and under cluster created in the past.
  3. Once you click resume it'll take some time to resume the cluster.
  4. Then use Connect option on the site to connect via multiple options provided on the site.

Check the below images for your reference.

Resume

Connect Options

Subtreasury answered 8/1, 2021 at 4:19 Comment(0)
M
0

In my case, the problem got solved when I sign in to my MongoDB atlas account.

Memphis answered 3/7, 2022 at 1:11 Comment(0)
B
0

In my case, I was re-using a string connection from another project. I copied my original string connection from MongoDB site and worked fine.

Blaseio answered 27/10, 2022 at 13:11 Comment(1)
This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From ReviewMchugh
W
0

Most of the answers are mentioning about the network connectivity. Even though there is a rare scenario can make this error. That is the mismatch of mongo URI in the mongodb Compass and the mongo atlas URI. I had the same issue when I initiated with the passwords, the URI was setup there. After that I havent used the mongoDb through compass. After 6 months when I run the project. I got this connection issue. So I try to connect that from the compass. It failed, then I tried in the mongo Atlas, by restarting the paused cluster services. Then I copy the URI and put in the compass and try again to run the project, it worked.

As summarized steps we need to check for this errors are,

  1. Check the URI in the project and the mongo Atlas are same,
  2. Check the network connected to your local IP in mongo atlas settings,
  3. Check whether the cluster is paused due to inactive for 6months. Then reactivate
  4. click connect in the mongo Atlas and run the project
Winder answered 22/4, 2023 at 18:31 Comment(0)
H
0

For me it was an issue with mongo connection string. Instead of "mongodb+srv", use just "mongo"...

It worked for me without any issue in my vscode + nodejs + typescript environment.

Heroism answered 2/1, 2024 at 4:5 Comment(0)
A
0

This generally happens if your internet connection is poor or if your system is not connected to the internet.

Accessible answered 17/9, 2024 at 4:17 Comment(0)
I
-1

FIX : : previously my cluster password was "chaudhary@786" which contained the special character "@", due to which the compass string connecting compiler got confused hence in the next turn I changed my password to "gghjkl98", i.e without any special characters. and I got connected without any errors.

SOLUTION : password of the cluster should not contain characters like \backslash or @ or any other characters

Interdental answered 18/1, 2022 at 11:10 Comment(0)
O
-1

In my case was due to the connection to VPN. Try disconnecting from VPN

Orfield answered 6/3, 2024 at 14:41 Comment(0)
M
-2

For Windows 10

  1. Go to control Panel
  2. Go to network and setting
  3. Click on Change Adapter settings
  4. Choose Internet Protocol Version 4(IPv4)
  5. Click Properties
  6. Select Use the following DNS server address
  7. Enter 208.67.222.222 and Alternate 208.67.220.220
  8. CLick Ok then click close
Mather answered 2/4, 2024 at 6:20 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.