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: https://www.mongodb.com/cloud/atlas
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.
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.
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.
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.