How Can I Get the MongoDB Atlas IP Address for Whitelisting in My Hosting Provider?

I am developing an application that uses MongoDB Atlas as a database. Currently, my application is hosted on a server, but we are having trouble accessing the database because ports 27015 to 27017 used by MongoDB Atlas are closed on our hosting server.

To open these ports, the hosting server asks for the IP address of MongoDB Atlas to be whitelisted, but I don’t know the specific IP of the MongoDB Atlas cluster that I am using. Since MongoDB Atlas uses a DNS-based connection and does not provide a static IP, I cannot get the IP address directly.

Is there a solution or steps that I can do to allow access to MongoDB Atlas without requiring a specific IP address? Can I use the hostname to whitelist or is there another way I can try?

Thank you for your attention and help

There are tow most commanly used methods

  1. You can use the Return All IP Addresses for One Project API endpoint to retrieve the IP addresses for all cluster nodes within a project. An API key pair with sufficient project permissions is required (the Project Read Only role at the very least).

  2. Use DNS to query the cluster hostname SRV record.
    You can retrieve the list of hostnames using DNS, query the SRV record of the cluster hostname. This can be done using any DNS querying tool such as nslookup or dig. The service and protocol prefix of _mongodb._tcp. must also be included when querying the SRV record.

As an example, given the cluster hostname of examplecluster.a01bc3.mongodb.net, a DNS query would need to lookup the SRV record for _mongodb._tcp.examplecluster.a01bc3.mongodb.net: