Can't connect to Mongodb Atlas from Render Web-Hosted App

I have a small webapp that runs locally with a local MongoDB database just fine. I moved it to Render, and created a DB cluster on mongoDB atlas, and the webapp appears to build on render, but every time I start the webapp on Render, it says it can’t connect with MongoDB.

Here’s my app.js connection code:

1 Like

Here’s the Render log entry informing me that it couldn’t connect. to the MongoDB Atlas DB. :

Note that I am able to connect manually using mongosh from my Terminal app on my Mac.

For some reason, the connection code screencap is not visible in the first post. Here it is again:


I should also say that I have whitelisted both my ip address and all ip addresses (via whitelisting 0.0.0.0/0).

From the Render machine running your app try to access:

http://portquiz.net:27017/

If it fails then you have to communicate with the Render people since they are blocking outgoing traffic on the given port.

@Daniel_Winterbottom I just ran into a similar problem (connecting Mongo Atlas to render web service). I had a slightly more vague error, but my issue was resolved by adding my render project’s outbound IP addresses to mongodb project’s network access.

  1. On render.com web service main page, click the Connect button in top right. Select the Outbound tab. Copy these IPs
  2. On your mongo project Atlas page, click Network access. Add the IPs

Posting on the off chance that this is helpful. I had found this guide, but had already been following those steps to no avail.

9 Likes

Thanks Billy, I was migrating an app from Heroku and this resolved my issues to access my mongo Data Base.

2 Likes

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.