I'm building a website, and am using MongoDB Atlas for my database. In the MongoDB Network Access section, I have to specify an IP address to connect from in order to establish the database connection, and since I'm using a cloud service to run my server from, I have to select the "Allow access from anywhere" option, which sets the IP address to 0.0.0.0. Is there an alternative to selecting this option and still using the cloud IDE? I'm assuming allowing access to the database from anywhere is not secure, though I also don't know exactly how under this setting other people could access my database and post to it without the source code and/or my MongoDB Atlas login information.
From the mongodb documentation, if you have strong credentials and you're not sharing it, you should be good.
IMPORTANT: Adding the CIDR 0.0.0.0/0 allows access from anywhere. Ensure that strong credentials (username and password) are used for all database users when allowing access from anywhere.
I had this same problem and came up with a solution that essentially auto-updates the IP whitelist every time your cloud server IP changes.
I finally got around to opensourcing a solution I've been using for my own apps. If your using nodejs, you can find it at: https://www.npmjs.com/package/mongodbautoip?activeTab=readme
MongoDBAutoIP essentially keeps track of all of the IP addresses used on your application server over the last 24 hours, updating new ones and deleting old ones after that limit which prevents any downtime. This is done through the mongoDB api.
© 2022 - 2025 — McMap. All rights reserved.