I am facing an issue connecting to my MongoDB Atlas cluster via Node.js, express and mongoose:
{ MongoNetworkError: connection 4 to mongodb-passport-auth-shard-00-00-vp7yg.mongodb.net:27017 closed
at TLSSocket.<anonymous> (C:\Users\Vishesh\Documents\Projects\nodejs-passport-auth\node_modules\mongodb-core\lib\connection\connection.js:276:9)
at Object.onceWrapper (events.js:273:13)
at TLSSocket.emit (events.js:187:15)
at _handle.close (net.js:606:12)
at TCP.done (_tls_wrap.js:386:7)
name: 'MongoNetworkError',
errorLabels: [ 'TransientTransactionError' ],
[Symbol(mongoErrorContextSymbol)]: {} }
Here is the code I used for connecting to my cluster via a Short SRV connection string:
mongoose
.connect(
'mongodb+srv://myname:[email protected]/test?retryWrites=true',
{ useNewUrlParser: true }
)
.then(() => console.log("Connected to mongodb..."))
.catch(err => console.log(err));
I think you must add your IP address to the IP Whitelist in mongoDB.atlas console.
I was getting error
MongoNetworkError: connection 1 to ......-shard-00-00.b2zap.mongodb.net:27017 closed
even if I added allow access from anywhere in IP whitelist.
After adding my IP address along with allow access from anywhere, it worked for me.
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