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
2.4k views
in Technique[技术] by (71.8m points)

javascript - Error: querySrv ENOTFOUND _mongodb._tcp.dbname.fzofb.mongodb.net

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' }

question from:https://stackoverflow.com/questions/65623404/error-querysrv-enotfound-mongodb-tcp-dbname-fzofb-mongodb-net

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

1 Answer

0 votes
by (71.8m points)

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.


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

...