Creating and Deploying an Atlas Cluster in MongoDB
MongoDB Atlas is a multi-cloud database that is used to deploy, run, and scale the MongoDB database in the cloud. It is a developer-oriented and open-source database. It is used to handle all the complexities that come across deploying, managing, and deploying on the cloud service providers. It helps us to build efficient and versatile global applications.
Cluster
Now, Letβs know something about βClusterβ for MongoDB. Cluster is a word that is used to represent either a sharded cluster or a replica set, whereas a group of duplicate MongoDB servers that have copies of similar data is known as a Replica Set, and where data is distributed among several MongoDB Servers is known as Sharded Cluster.
With the help of MongoDB Atlas, you can run a MongoDB database within a few clicks, in just a few minutes.
How to Setup Atlas Cluster in MongoDB
Setting up an Atlas cluster in MongoDB comprises both the steps that are to Creating an Atlas Cluster and then Deploying it, To setup your Atlas Cluster you need to follow the steps given below:
- Creating Atlas Cluster.
- Whitelisting of IP Address.
- Setup a MongoDB user for your Cluster.
- Connecting Atlas Cluster to MongoDB Compass.
1. Creating Atlas Cluster
Now, the first step is to initialize an Atlas Cluster such that everyone can easily Create a Cluster, The steps are:
- First, we need to go to MongoDB Atlas and register as a user.
- After that, Fill in all the mandatory or required details about yourself and the project for which you are using Atlas cloud and accept the terms & conditions then click on βFinishβ.
- Choose the Cloud database Tier for Cluster from the given below in the MongoDB atlas page as per your project convenience. Now, Letβs use the βM0β Free version, and in the region select βMumbaiβ if you want to name your cluster so that you can rename it as well but by, default it will have the name βcluster0β if you are creating for the first time then, Click on βCreateβ.
2. Whitelisting of IP Address
Now, you will be redirected to the home page, where you will be able to see all the details about your databases, organizations, projects, and other relevant information the next steps are:
- Click on βDatabaseβ on the left panel of your screen. After that you will be able to see your created cluster by name, We have created a Cluster named βCluster0β you can see a button βConnectβ and then simply click on it.
- Next, we will have to click on βAdd your Current IP Addressβ and it will fetch our IP Address automatically and ask you for reconfirmation.
- Click on βAdd IP Addressβ. Now, you have successfully added your current IP Address.
3. Setup a MongoDB user for your Cluster
Now, you need to create a user for your cluster So, that you can connect your Cloud database to your application. The Steps for Creating Username and Password for Authentication are given below :
- On the Dashboard alongside the cluster name, you can see the βConnectβ button, then click on it.
- After that you can see an option βCreate a database userβ, In this you can create a username and a password for the Database user and click on βCreate database userβ. If you donβt want to create a password you can also click on βAutogenerate secure Passwordβ and simply copy it and save the password in your local file because you will not be able to get it again.
4. Connecting Atlas Cluster to MongoDB Compass
Now, The last step is to deploy or connect your Atlas cloud database. To connect, you can connect through MongoDB Compass or MongoDB shell. So, Connecting through MongoDB Compass is easy. In this, we are connecting through MongoDB Compass because it is GUI based and it is very easy for a beginner to connect through MongoDB Compass.
- First, go and Download the MongoDB Compass.
- Then, Go to your MongoDB Atlas Cluster Dashboard and click on the βConnectβ Button.
- After that, Click on βChoose a connection methodβ or it will automatically take you to that part if you have already completed steps 2 and steps 3 described above in this article.
- Now, here you can click on βCompassβ.
- After that click on βI have MongoDB Compass Installedβ copy the connection string and replace the password with the password you have created for the database user in step 3.
- Now, Open the MongoDB Compass Paste the connection string with your database password and, Click on βConnectβ.
- You have been successfully connected to the cloud database.
You have successfully connected your Database with MongoDB Atlas Cluster and If you want to know more about MongoDB you can visit their official site and read the documentation.