I'm having an issue with trying to connect to MongoDB. I'm using mongoose here,
console.log("trying here"); // prints
await mongoose.connect(db, {
useNewUrlParser: true,
useCreateIndex: true,
useFindAndModify: false
});
console.log("Mongo DB connected"); // never reached
And it throws an error
getaddrinfo ENOTFOUND cluster0-shard-00-01-abcde.mongodb.net
I have never had this error before, it used to work just fine -- not sure where to go from here. I've tried building a new cluster and network access by IP is set to public 0.0.0.0. It just keeps throwing the same error.
Note that if you specify useNewUrlParser: true, you must specify a port in your connection string,
like mongodb://localhost:27017/dbname.
The new url parser does not support connection strings that do not have a port, like mongodb://localhost/dbname.
see more info here
one more option, if you use node.js +mongo Atlas:
you will get connection string that start with mongodb://
insted of mongodb+srv:// (for node js 3.0 or later)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With