Using MongoDB Atlas
We will use MongoDB Atlas to host the database. We will create a free tier cluster and we will use the connection string to connect to the database.
Here are some guides that will help you:
- How to create a free tier cluster: https://docs.atlas.mongodb.com/tutorial/create-new-cluster/
- How to connect to the database: https://www.mongodb.com/docs/atlas/driver-connection/
In my case, I created a free tier cluster called nodejs-for-beginners
, as you can see in the following screenshot:
Figure 16.6 – Web browser screenshot showing the cluster creation details
At the end of the process, you will have a connection string like this (but with your own credentials):
mongodb+srv://<username>:<password>@<cluster-url>/test?retryWrites=true&w=majority
You can use that connection string to connect to the database from the application. You only need to replace the value of the MONGODB_URI
environment...