Abinash Panda
Abinash Panda

Reputation: 11

MongoNetworkError: failed to connect to server on first connect [MongoNetworkError: connect ECONNREFUSED ]

I got this error as soon as I tried to run the nodejs app in Godaddy shared hosting cPanel terminal while trying to connect to mongo atlas cluster.

Error

I have whitelisted both the IP of the server and set access to all still not working.

Same code is working fine in local system enter image description here

My node.js code goes as: enter image description here

Here is the DB url enter image description here

If anyone has experienced this issue and able to solve it, then please provide me the solution. Thanks :) in advance.

Upvotes: 1

Views: 1618

Answers (1)

AlexZeDim
AlexZeDim

Reputation: 4352

I am pretty sure, that you IP is a provider's IP, not you own. According to a console, problem is in whitelisting.

So make sure that you are enable in your driver, all connections options, like this: (if you are using mongoose)

connect(`mongodb+srv://${process.env.login}:${process.env.password}@${process.env.hostname}/${process.env.auth_db}`, {
    useNewUrlParser: true,
    useFindAndModify: false,
    useUnifiedTopology: true,
    w: "majority",
    family: 4
});

And then white-list every IP in your Atlas console, like that:

enter image description here

Upvotes: 1

Related Questions