Can’t maintain a connection to the cloud mongodb database as my IP address keeps changing

  Kiến thức lập trình

So I am building a node application where I am using the cloud mongodb atlas database. I have whitelisted my IP but the problem is after sometime my IP address changes and the connection to the mongodb server breaks. I cant manually set up my new IP address everytie, its not sustainable. I get the following 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

I googled and found out that I can actually whitelist all IP addresses using 0.0.0.0. but it is not recommended. I am stuck and dont know what to do. Please help.

WHAT I TRIED:

  • Manually adding my previous IP address to the MongoDB database whitelist.

WHAT I EXPECT:

  • I’m looking for a solution that allows me to maintain a stable connection to my MongoDB database despite the frequent changes in my IP address. Ideally, this solution should be scalable and not reliant on manual updates. Any suggestions or insights would be greatly appreciated.

New contributor

Debanjan Ghosal is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

LEAVE A COMMENT