MongoDB Atlas is a cloud database fully managed and secured and can be deployed on different cloud providers such as Amazon, Azure or Google and the likes of your choice. Prior to the introduction of the cloud technologies, companies managed, deploys and fine tune their own databases at their own premises. This introduces several complexities in terms of maintenance and fine tuning. The concept Database as a Service was coined to resolve these complexities. In this Mongodb Atlas overview, I am going to show you on how to provision your own MongoDB cluster and get started on this.
You can choose to install MongoDB as a standalone application just what I did in my previous post. I used Windows as my workstation if you want to manage the database yourself and for situation where you are not connected to the internet. I personally will use MongoDB Atlas or MongoDB in future Internet of Things (IOT) projects so watch out for that!
What is MongoDB?
Let us first give an introduction to what is MongoDB before we go deep dive on what is MongoDB Atlas. MongoDB is a NoSQL or ‘non-relational‘ database which stores it’s data in JSON Format.
As you can see from the image above record is represented in JSON Notation. It uses Documents and Collection instead of the traditional rows and columns in relational. These type of databases are ideal for large sets of data especially for Internet of Things (IOT) projects which gathers data from different sensor reads.
Prerequisites to follow this Mongodb Atlas Overview
In order to continue with this post, you will need a google or github account account that is fully authenticated with 2FA.
Setting up MongoDB Atlas
The general steps are fairly documented by the MongoDB team in this link but I am going to put up the steps that I followed since the screenshot is a little bit dated.
Create an account
Go to this link to register for a MongoDB Atlas account. You can either fill in your personal information and your email and set your password or you can choose to use your google account. I used my personal google account to register so that it would take care of the authentication mechanism.
Deploying free cluster
You can either use the MongoDB CLI (Command Line Interface) or the MongoDB UI to do this. I have used MongoDB UI in my case but learning how to do this in the CLI is a good skill to learn as well.
Once your registration is successful then it will ask you to create a cluster for your account. As you can see, mongodb offers a Paid Tier and a Free Tier. You can select the Paid tier later once you have a running application and is ready to release your project. The cost is dependent on the amount of data or storage that you are gonna be using. We will just use the Free Tier in this blog. Click the Create button.
I picked the Azure and the Asia – Hongkong deployment in the cluster creation. You may choose other depending on the region that is nearest to you. Set the cluster name section depending on what is appropriate for you. The provisioning might take some time so be patient while waiting.
Add Your Connection IP Address to Your IP Access List
We then need to add our IP Address to the list of IP that can connect to our cluster. You can add as many IP address to this list. To do that we just need to click the Database then click the Connect button.
Then click the Add IP Address button from the prompt. This will add our current IP address to the list that is able to access our cluster. Wait for the message that the IP address is added.
If you click the Network Access link then you would see that your IP Address is now included in the list.
Create a database user for your cluster
You need to create a user for your cluster and set the credentials accordingly. We will use this in connecting to our database. To do that, click the Connect button again.
Connect to our cluster
Once we have setup our cluster then it is time to connect to it. We can use several driver module to connect to our cluster like the Node.js driver or the PyMongo driver. In our case, we are gonna be using the MongoDB Compass to connect and view the objects in our database. Download the MongoDB compass from here and install it in your workstation.
Once you have successfully setup your MongoDB Compass then open it. We need to supply it with the connection string to connect to our cluster. To do that, open the Database section again and then click the Connect button again.
Select the Connect using MongoDB Compass link then copy the connection string. Make sure to replace the <password> field with the password of the user that we created earlier.
In your MongoDB Compass paste the connection string and then click Connect.
If everything goes well then we should be able to connect to our cluster.
We have not created any database for our cluster but if you want to load sample dataset then just follow the following link.
We now have successfully setup our cluster in our MongoDB Atlas and is now ready to begin using it as our database for our future Internet of Things (IOT) projects.