Setting up MongoDB
Every application needs a persistence layer. This lesson will show you how to enroll for free Atlas cloud MongoDB instance. You will also feed your database with data.
Before you start coding the backend, you need a MongoDB instance where you will keep your application data.
There are a few ways to do this. You can either 1. install MongoDB on your local machine and test it that way or 2. use a cloud MongoDB instance.
In both cases, you will also need to fed your database with data. If you wish, you can use the same objects as I used. To do that, download the db_dump - you will import it into your DB during this lesson.
Setting up MongoDB locally#
Below, we're going to describe how to use a cloud MongoDB instance, but if you'd rather use a local installation, then the MongoDB docs are very good. For your convenience here are the relevant links, depending on your system:
Because local development environments vary so widely, we can't describe each scenario in detail. But if you follow the above instructions and run into trouble, join our Discord server and someone can probably help you out.
Provisioning a MongoDB Atlas cloud instance#
Once your application is ready, navigate to https://cloud.mongodb.com/user and sign in to your account. Then create a new cluster in a region that is closest to your default Heroku region:
When your cluster is ready, click the Connect button and follow the prompts in the Connect to Cluster panel to:
Allow access from anywhere
Create a MongoDB user
When creating your password, avoid using characters that will have to be URL-encoded when entered on your system's command line. Be sure to save your MongoDB username and password in a safe place.
In the Choose a connection method step, select Connect with the Mongo Shell. Follow directions for downloading, installing, and configuring the MongoDB Shell to run on your system.
When you've configured the MongoDB Shell to run on your system, copy the supplied command-line instructions to a safe place.