Reputation: 63
{ MongoNetworkError: connection 3 to cluster0-shard-00-02-z0urk.mongodb.net:27017 closed at TLSSocket. (/home/fahad/Personal Work/Nodejs/Node js start/node_modules/mongoose/node_modules/mongodb-core/lib/connection/connection.js:352:9) at Object.onceWrapper (events.js:276:13) at TLSSocket.emit (events.js:188:13) at _handle.close (net.js:610:12) at TCP.done (_tls_wrap.js:386:7) name: 'MongoNetworkError', errorLabels: [ 'TransientTransactionError' ],
[Symbol(mongoErrorContextSymbol)]: {} }
module.exports = (app, express , mongoose, path, bodyParser) => {
app.use(express.static(path.resolve(__dirname, "../../dist")));
app.use(bodyParser.json());
mongoose.connect('mongodb+srv://fahad:[email protected]/test?retryWrites=true', {useNewUrlParser: true})
.then(()=>console.log("DB server connect"))
.catch(e => console.log("DB error", e));
};
Upvotes: 3
Views: 4611
Reputation: 85
from mongo-db
go to cluster
find security
check the IP, list
add the current ip or the global ip or both you can add any other ip for development
check step by step in the link below
good luck
Upvotes: 4
Reputation: 136
I had same problem when i want to connect to https://cloud.mongodb.com "mongoDB Atlas" This problem happened to me because when I built project, my IP in this time store in security -> IP Whitelist.
You will only be able to connect to your cluster from the following list of IP Addresses in IP Whitelist.
I manage to solve this problem by using IP 0.0.0.0/0 this help me to connect from anywhere.
Would that help you?
Upvotes: 12