When connecting to my MongoDB Atlas server from a node.js server, the following code works completely fine on Heroku:
mongoose.connect(process.env.dbLink, {
useNewUrlParser: true,
useUnifiedTopology: true
})
const db = mongoose.connection
db.once("open", () => {
console.log("Database connected")
})
However, when I run this on my computer, I get the following error:
const serverSelectionError = new ServerSelectionError();
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. Make sure your current IP address is on your Atlas cluster's IP whitelist: https://docs.atlas.mongodb.com/security-whitelist/
However, my IP address is whitelisted.
How can I make this work on my local environment?