Reputation: 612
I'm trying to connect my first mongo-db application to server :
const express = require('express');
const mongoose = require('mongoose');
const app = express();
const URI = "";
mongoose
.connect(URI,{useUnifiedTopology:true,useNewUrlParser:true})
.then((res)=>{
console.log(res);
console.log(res.data);
})
.catch((err)=>{
console.log("Encountered error...");
console.log("error : "+err);
});
const port = process.env.PORT || 5000;
app.listen(port);
console.log('App is listening on port ' + port);
But it gives me error : MongooseServerSelectionError: connection to 35.223.140.90:27017 closed.
I have white listed my IP address.
Upvotes: 1
Views: 607
Reputation: 4983
You need to whitelist the IP address on ATLAS
This is for development only, for prod, you can add your server ip.
Upvotes: 2
Reputation: 725
Did you have this line in your app.js app.use(cors())
?
Try to delete this line and delete everything that involves cors.
If this don't work, check your IP Whitelist inside Network Access in MongoDB Atlas and add your current IP or write this 0.0.0.0/0 to allow all IPs.
Upvotes: 3