Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
6.8k views
in Technique[技术] by (71.8m points)

Error: queryTxt ETIMEOUT when connecting to MongoDb Atlas using mongoose

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
 
Best answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...