MongooseServerSelectionError: Could not connect to any servers in your MongoDB Atlas cluster

I am trying to upload one of my full stack applications on render.com since heroku free hosting is dying , although the uploading is successfull , i get this error when deploying the server side of my app.
It says my Ip may not be whitelisted , however it very much is , i even did allow access to any IP and it still wouldnt work …

1 Like

May i also mention i am using mongoose in nodejs with express
And also M0 Sandbox (General) cluster tier

this is what i get , so i assume the request is made successfully and i do get a response , however mongodb has not connected i guess

This is the uri i am using to connect

Hey I had the same issue. On Render there is a “connect” button at the top; right beside manual deploy. It has some Static Outbound IP Addresses. I added those IP addresses to my Mongo DB account and it worked. Hope that helps.

1 Like

were you able to solve this issue… it would work fine and after some point, this error would pop up in logs… faced it in the lambda function is this related to the total number of connections or something?

Hi @santhosh_h,

My team and I faced the same problem and we could solve it by setting up a static IP address for the lambda, we put it in a private subnet and then used a NAT gateway, then you can add that IP to your MongoDB whitelist or you can keep your IP access list as 0.0.0.0/0, it will work both ways.

I don’t know how aws make requests through lambdas or why is a static IP needed, but that solution works.

Hope that can help you

Why are there three IP Addresses? Thank you for this that was brilliant what you just did, Mick.

Despite using the given connection string and whitlisting all IPs I’m not able to connect to the Atlas Cluster.


How do I proceed with this ?

If you running a VPN try stopping it.

If it is still does not work, turn off your firewall.

1 Like

I’ve tried that too. It still doesn’t work. I am unable to run the mongodb shell too.


Unable to find a solution for these errors.

Why do you ping mongodb.net or mongodb.com while you try to connect to local instance at 127.0.0.1?

Where do you want to connect exactly?

I was just trying to test my connection to mongodb.net
Since all server connection strings end with that.

I’ve used the Atlas CLI to create a cluster, and even that isn’t able to run any mongosh commands.



Anything else I should try out to test the extent of the issue ?

I was able to connect successfully to your cluster. This means the issue is on your side of the connection.

Are you sure you are not using a VPN?

Try a different internet provider.

Ohhh
Okay…
I’ll try a mobile network and see if the issue persists.

Thank you, this work for me