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.

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