MongoDB Atlas VPC Connection Error

Hi Guys,

I switched from using Static IPs to VPC peering to connect to my MongoDB cluster and for some reason after an application restart in my Prod Env it won’t connect anymore. I tried restarting my Staging app and it’s working fine.

Error:

error: MongooseServerSelectionError: Could not connect to any servers in your MongoDB Atlas cluster. One common reason is that you're trying to access the database from an IP that isn't whitelisted. Make sure your current IP address is on your Atlas cluster's IP whitelist: https://docs.atlas.mongodb.com/security-whitelist/

It looks to be a configuration issue MongoDB Atlas side. I’m not familiar at all with MongoAtlas, but is it possible that Whitelisting security remains active once you’ve used VPC peering?

If yes, maybe you can try to disable it. It makes sense because VPC is a private network.

This was a 100% the case! Atlas for some reason did not automatically whitelist the VPC CIDR. I had to manually add it so it can accept connections from it.

1 Like

Nice to see you’ve found the solution :slight_smile: