Error: queryTxt ETIMEOUT when connecting to MongoDb Atlas using mongoose
Asked Answered
P

12

27

Im trying to connect my mongoose with my MongoDB Atlas Cluster. It currently has no database or anything but whenever I try:

mongoose.connect( uri || 'mongodb://localhost/test',options)
.then(()=>{
    console.log("Connected to the Database. Yayzow!");
})
.catch(err => {
    console.log(err);
});

I get this message:

Error: queryTxt ETIMEOUT cluster0-ghis2.mongodb.net
at QueryReqWrap.onresolve [as oncomplete] (dns.js:202:19) {
errno: 'ETIMEOUT',
  code: 'ETIMEOUT',
  syscall: 'queryTxt',
  hostname: 'cluster0-ghis2.mongodb.net'
}

My dependencies:

  "dependencies": {
    "express": "^4.17.1",
    "mongodb": "^3.5.7",
    "mongoose": "^5.9.14"
  }

I've whitelisted all IPs as off now (0.0.0.0/0). Also I've made sure my firewall is disconnected and so is my anti-virus. I made my friend check it out too and it did work for him but not me

Any help is appreciated!

EDIT

Solved the error by changing my DNS to Google's Public DNS! If anyone get this error just make sure to change your DNS. Throwing a link for the same here

Prodrome answered 14/5, 2020 at 14:35 Comment(5)
Two things: 1. Today (14/05/2020) MongoDb Atlas has been extremely slow (at least for me). As I write this I can barely access the website, so maybe it's not just you and it's a connection problem. 2. Once I had a similar problem after I whitelisted all IPs, so I also whitelisted my actual IP (ex: 192.xxx.xxx...) and solved my problem, so try doing that.Kozak
Even i thought that it'd be their problem but then i gave my friends my credentials and it worked for him. I'll try the second one and let you know. Appreciate your help by the wayProdrome
Thanks but turned out it was my net issue. Solved it by changing the DNS as mentioned in the EDIT section of my question.Prodrome
Its wokring for me in localhost but when I deploy my app to Heroku and run it I get error "Operation users.insertOne() buffering timed out after 10000ms". have whitelisted all ip for clusterBangs
Thanks for adding edit for DNS setting, it worked for me!Rosamariarosamond
M
22

Changing DNS to 8.8.8.8 works for me.

Before changing my DNS, I tried to reinstall mongoose, check my connection, and turn off my vpn. None of them worked.

Mouthwatering answered 26/4, 2021 at 2:44 Comment(4)
This solution is included in an edit in the question.Berg
you saved my dayLefevre
This worked by changing IPV4 DNS to 8.8.8.8 and reconnected to Internet.Shenashenan
Can't believe it, this worked! On Mac: Network Settings > Wifi > Advanced > DNS > 8.8.8.8Borkowski
M
54

The error because of the version of you node and npm, to remove this error you just need to change you connection String by going to Connect and connect to Application

  1. change the version to 2.2.122 or later
  2. copy String and paste then try to connect it again. as shown in Picture enter image description here
Madeline answered 15/9, 2020 at 14:28 Comment(5)
But the question is why? @BilalKeele
@wiki this sometimes occurs because of lower node and npm versionsMadeline
why this happensSemibreve
@Semibreve as i mentioned above this occurs because of lower version of node installed on your systemMadeline
@BilalKhursheed I also encountered the same mongoDB connectivity issue all of a sudden in my next js application. And your solution works. Thanks! But I'm wondering, even though I had node version 16.15.1 installed on my system which is higher than the default Node Js Driver version 5.5 or later, why does it work after degrading it to 2.2.1 2 or later?Gooch
M
22

Changing DNS to 8.8.8.8 works for me.

Before changing my DNS, I tried to reinstall mongoose, check my connection, and turn off my vpn. None of them worked.

Mouthwatering answered 26/4, 2021 at 2:44 Comment(4)
This solution is included in an edit in the question.Berg
you saved my dayLefevre
This worked by changing IPV4 DNS to 8.8.8.8 and reconnected to Internet.Shenashenan
Can't believe it, this worked! On Mac: Network Settings > Wifi > Advanced > DNS > 8.8.8.8Borkowski
M
15

You need to add &ssl=true in your url, and your complete url should look like this

mongodb+srv://<user>:<password>@********.mongodb.net/<db name>?authSource=admin&compressors=zlib&retryWrites=true&w=majority&ssl=true
Misogamy answered 6/7, 2020 at 20:10 Comment(2)
Wow that was it. Why in the world. Thank you!Hypotaxis
ssl shouldn't be true, as tls will be false. "Use of the +srv connection string modifier automatically sets the tls (or the equivalent ssl) option to true for the connection. " DocsOcta
R
11

to solve this issue make sure to choose older version of node (2.2.12) or later

enter image description here

and then make sure to add your ip address whitelisted

enter image description here

Remit answered 16/9, 2020 at 2:30 Comment(0)
S
9

Only switching from my mobile hotspot to fiber connection worked. I have no clue how that happened , it solved the issue. (P.S. I had whitelisted my IP when connected to mobile hotspot, so this reasoning is eliminated)

Saffier answered 28/9, 2021 at 3:28 Comment(4)
This solution works for me, I switch my connection from mobile data to WiFi and everything magically works. Does anyone know what the reason of this?Synapsis
ironically, that worked :(Bewray
is there any way to make the monogodb connection work with WIFI?Gretel
same, i use mobile hotspot and it goes to timeout everytime, i switch to my home wifi it worked, i try with hotspot again and change DNS to 1.1.1.1 it worked.... i assume the ISP blocked the domain or smth related...Deepen
C
2

I suspect that several of these answers really come down to the same thing - the network needs to be reset. I just had an odd experience - I had to different apps running on different ports but both accessing the same mongo instance. One had the connection error, the other did not. I rebooted and both were fine going forward.

The other scenario that caused this is an instance where I did not have an async / await around the mongoose call.

Compassion answered 27/1, 2021 at 21:12 Comment(1)
What do you mean by "the network has to be reset"?Borkowski
L
1

I turned my wi-fi off and on again and it worked

Linehan answered 19/8, 2022 at 0:31 Comment(1)
Same, dude, same!T
W
0

try to change your dns to google dns :

For windows:

  1. go to control panel
  2. search for network and sharing center
  3. click on your internet or wifi
  4. select properties
  5. search for internet protocol version 4(TCP/IPv4)
  6. enter this to the fields :

enter image description here

Worshipful answered 21/4, 2023 at 19:19 Comment(0)
M
-1

Please check your connection string. The password must be a encoded one not as a plain text.

Marmoreal answered 6/2, 2021 at 19:45 Comment(0)
S
-1

In my case problem was in Database Network Access. I should choose my current IP address instead of ALLOW ACCESS FROM ANYWHERE

Snore answered 15/3, 2021 at 21:26 Comment(0)
M
-1

Just off my mobile data connection, on it, and connect the hotspot again. It's started working.

Marr answered 1/7, 2023 at 15:3 Comment(0)
I
-2

Ensure your Connection URL is ok. In .env file(one for environment variables), remove the double quotes around the connection string. Keep it: URL = mongodb+srv://..............

Indifferentism answered 14/4, 2021 at 12:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.