0

Trying to connect my express app with mongodb atlas, but I keep getting this MongodbNetworkError

Server.js file

 const express = require("express") const mongoose = require("mongoose") const dotenv = require("dotenv") dotenv.config() const app = express() mongoose .connect(process.env.MONGODB_KEY, { useNewUrlParser: true, useUnifiedTopology: true }) .then(() => console.log("MongoDB connected")) .catch(err => console.error(err)) const PORT = process.env.PORT || 5000 app.listen(PORT, () => console.log(`Server running on port ${PORT}`)) 

Command Line

 [nodemon] starting `node server.js` Server running on port 5000 { Error: getaddrinfo ENOTFOUND coolcluster-shard-00-00-wqaqv.mongodb.net coolcluster-shard-00-00- wqaqv.mongodb.net:27017 at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:56:26) name: 'MongoNetworkError', errorLabels: [ 'TransientTransactionError' ], [Symbol(mongoErrorContextSymbol)]: {} } 
1

1 Answer 1

1

You need to whitelist the IP address of your nodejs server in MongoDB. After login to the account, Follow the steps

Go to IP Whitelist view. a)In the Security section of the left navigation, click Network Access. The IP Whitelist tab displays. b)Click plus icon Add IP Address. 

https://docs.atlas.mongodb.com/security-whitelist/#add-whitelist-entries

Sign up to request clarification or add additional context in comments.

1 Comment

I do have an ip address of 0.0.0.0/0 including my current ip address added

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.