updated 6-10-2020

This note is for students who are using MongoDB Atlas per the course lecture note here:

https://www.udemy.com/node-with-react-fullstack-web-development/learn/v4/t/lecture/13733504

In the upcoming lecture, we are going to be creating a separate production database for use with Heroku. Here are the steps required to do this with MongoDB Atlas. (The most important part is the global whitelisting in step 9)

1. Sign in to your MongoDB account

2. Once logged in, you will be taken to your MongoDB Atlas Dashboard. Click the current project button listed under "Context" and click the "New Project" link. As a free tier user, you can have only one cluster per project, however, you can have as many projects as you wish.

3. Name your project and then click the "Next" Button:

4. Click the "Create Project" button:

5. After the project finishes initializing, you will be taken to the "Clusters" page of your Database. Click the "Build a Cluster" button

6. Leave all of the Free Tier options selected and scroll down to the bottom. Click the "Create a Cluster" button:

7. After the Cluster has been created, you will be taken back to the Clusters page of the database. Click the "Connect" button


8. Click the "Add a Different IP Address button:


9. Enter 0.0.0.0/0 into the IP Address field and click the "Add IP Address" button. This part is extremely important as our Heroku server will not be able to connect to our database unless we whitelist all IP addresses.

In a real production app, you would typically have a static IP and a Fully Qualified Domain Name. In this case, we would whitelist only the static IP. You can read up on this more here:

https://help.heroku.com/JS13Y78I/i-need-to-whitelist-heroku-dynos-what-are-ip-address-ranges-in-use-at-heroku


10. Next, enter a new username and then click the "Autogenerate Secure Password" button. Then click "Create MongoDB User"


11. After the user is created, click the "Choose a Connection Method" button:


12. Select "Connect Your Application"


13. Copy the address under "Connection String Only"

When you paste this string into the Heroku Dashboard, you will need to replace <username> and <password> with the actual info created earlier and swap out the <dbname> placeholder with any arbitrary name.

14. Click the "Close" button and head back over to your application.