I am simply trying to connect to mongodb atlas via node.js with Mongoose but get the following error:
“MongooseServerSelectionError: Could not connect to any servers in your MongoDB Atlas cluster. One common reason is that you’re trying to access the database from an IP that isn’t whitelisted.”
I have whitelisted 0.0.0.0/0 and also set my actual IP too locally.
I find this happens frequently when i setup a new cluster.
I am running a stand alone script.
const mongoose = require('mongoose');
const intialDbConnection = async () => {
try {
await mongoose.connect("mongodb+srv://testuser:testpassword@cluster0.v51itw1.mongodb.net/?retryWrites=true&w=majority", {
useNewUrlParser: true,
useUnifiedTopology: true
})
console.log("db connected")
}
catch (error) {
console.error(error);
}
}
intialDbConnection()
.then(() => console.log('connected'))
Why can’t I connect?