How I used MongoDB in my full stack MERN application

Hey everyone! In this blog, I wanted to talk about how I used MongoDB in my application. Just briefly explain what MongoDB is; straight from the website, “MongoDB is a document database with the scalability and flexibility that you want with the querying and indexing that you need”. With that let me show you I implemented MongoDB into the application.

For this project I used MongoDB, but more specifically I used the Cloud Atlas version. In order to do that.

Step 1 → Go to the MongoDB Atlas website. Here is the link:

The website link should take you here!

Step 2 → Click the start free button if you do not have an account and sign up for a free account. If you already have one then just hit sign in.

Step 3 → Since we want to create a cluster to act as our online database let's start with creating a cluster. Hit the green build a cluster button as shown below.

Click the green button that says ‘Build a Cluster’

Step 4 → We are going to get prompted with three options that say choose a path. We are going to hit Shared Clusters which is the free option.

Click the one all the way on the left!

Step 5 → Hit the create cluster shown on the bottom of the page.

Step 6 → Our cluster should be getting created. This took a couple of minutes for me so be patient!

Step 7 → Go into Database access and hit the top right green button that says ‘Add a new database user’.

Step 8 → This will prompt you to create a username and password.

Step 9 → Hit the add user button that pops up on the bottom right.

Step 10 → Go into Network Access and on the top right hit the green Add IP Address button.

This is is going to lead to a popup and you can click add the current IP address and then the green ‘confirm’ button on the bottom right of the popup box.

Step 11 → Go back into the Clusters tab and hit the connect button.

Hit the connect button!

Step 12 → We get promoted to choose a connection method. Let’s click ‘Connect your application’. The middle option!

Step 13 → The next popup gives us the connection string to put into our code. We copy and paste that into and can use it in our code to connect to our database.

Step 14 → For my application specifically, the string that MongoDB gave back to me I saved under the ‘CONNECTION_URL’ variable, and below is how I accessed it.

I hope this helped give a good explanation on how to connect MongoDB to your application. The application I built was based on this full-stack MERN tutorial by Javascript Mastery on Youtube. The video is so helpful and informative and I learned so much. I would definitely recommend checking it out. Here is the link!