I am new to coding. I know it’s probably a dumb question to everyone, but it’s still quite confusing to me.
I tried in vain to connect MongoDB in office but it completely works at home.
Here my code:
const express = require('express');
const mongoose = require('mongoose');
const app = express();
const dburl = 'mongodb+srv://admin:[email protected]/testing?retryWrites=true&w=majority'
mongoose.connect(dburl, {
useNewUrlParser: true,
useUnifiedTopology: true
})
.then((result) => {
console.log(result);
})
.catch((err) => {
console.log(err);
});
app.listen(3000, () => {
console.log('listening to port 3000');
});
And I got this error message:
Node.js v20.2.0
[nodemon] app crashed - waiting for file changes before starting...
[nodemon] restarting due to changes...
[nodemon] starting `node app.js`
listening to port 3000
Error: querySrv ENOTFOUND _mongodb._tcp.cluster0.954cidx.mongodb.net
at QueryReqWrap.onresolve [as oncomplete] (node:internal/dns/promises:251:17) {
errno: undefined,
code: 'ENOTFOUND',
syscall: 'querySrv',
hostname: '_mongodb._tcp.cluster0.954cidx.mongodb.net'
}
Honestly, I can’t even understand a single word in it. Could anyone help me to figure out what’s happen?
2
Answers
Go to mongodb.com
Alternatively you can enable any access from anywhere with 0.0.0.0/0 Not Recommended
I think it’s a network problem.
Verify the database host address: Make sure you have correctly provided the host address of your MongoDB database in your code. Check if you entered the correct host address and if you included the correct prefix (for example, mongodb://).
Also try to check if you have the necessary permissions inside the db.