MongoDB Atlas Setup

Learn to create a cloud database using MongoDB Atlas.

We'll cover the following

Up until now, we’ve been using MongoDB on our platform as our database. When our applications are deployed and running on Heroku, we’ll need a new database in the cloud for our API to work with. To do this, we’ll use MongoDB Atlas.

Note: Occasionally, services such as MongoDB Atlas will update their registration flows, which will affect the steps outlined here.

Steps to perform setup

  1. You’ll need to create an account here.

  2. Once you’ve created an account, you should be redirected to a setup page to create a new organization. Click on the “Create an Organization” button.

  3. Add the organization’s name and click “next.” Keep everything set to default and click on the “create” button.

  4. You will be directed to your organization’s “projects” section. From there, click on the “new Project” button. Then, add the project’s name, click “next,” skip the “Add Members and Set Permissions” section, and click “Create Project.”

  5. Once your project is created, you’ll be redirected to the “clusters” page. From there, let’s create our MongoDB Atlas Cluster.

  6. Click on the “Build a Cluster” button. Then, create the free plan, Shared Clusters.

  7. In the “Cloud Provider & Region” section, select “AWS” and choose one of the free tier regions near you. You can also leave everything set to their defaults, as we have. Next, let’s expand the “Cluster Name” tab and give your MongoDB Atlas cluster a name. Then, click “Create Cluster.”

  8. This process should take anywhere between 7 and 10 minutes. Once it’s done, you should see a dashboard like the one shown below in slide 8.

  9. Click “Connect” under your cluster name and a setup wizard should open. First, we’ll need to update the whitelist so that our database can receive requests from Heroku. Add an IP address of 0.0.0.0/0, with an optional description next to it. Then, click “Add IP Address.”

  10. Now, you’ll need to create an admin user for this database to connect to it from the API. Add your username and password and be sure to remember the credentials, because you’ll need them in our next steps. Then, click “Create Database User.”

  11. Once this user has been created, click “Choose a connection method,” which should redirect you to this screen in the setup wizard. Click the middle option, “Connect Your Application.”

  12. Update the driver version of Node.js to 2.2.12 or later. This will more than likely not be the default option, but it’s very important that it’s set to this, or your API won’t be able to connect to your database. With that option selected, you should see the “Connection String Only” section update with your connection string.

We’ll use this connection string when we deploy the API to Heroku, so keep this information in mind.

Get hands-on with 1400+ tech skills courses.