I would like to know why it is necessary to add an ip on the whitelist. And also how can I connect my project to an ip. I’m hosting my project on Heroku.
A whitelist limits the originating IP addresses that can connect to your deployment and is part of the general best practice of Principle of least privilege and limiting network exposure to trusted sources.
If you are using a Heroku dyno, your application may have a large range of originating IP addresses. See: I need to add Heroku dynos to our allowlist - what are IP address ranges in use at Heroku?.
In addition to whitelisting trusted originating IP addresses (where possible), you should also enable other security measures such as Role-Based Access Control and Encrypted Communication (TLS/SSL).
Please review the MongoDB Security Checklist for available security measures and links to relevant tutorials.
You have to use an addon that provides your app with a static IP address, like Fixie Socks or Fixie. Unfortunately I tried this and it didn’t work.