How to create a free MongoDB Atlas cluster and connect to MongoDB Compass
Introduction
In this tutorial, we will walk through the process of creating a free MongoDB Atlas cluster. MongoDB Atlas offers a cloud-based platform for hosting MongoDB databases, and the free tier allows developers to explore and experiment with the database without incurring any costs. Follow the steps below to set up your own MongoDB Atlas cluster.
Steps
To create a free MongoDB Atlas cluster, follow these steps:
Step 1: Visit the MongoDB Atlas Website To get started, go to the MongoDB Atlas website at https://www.mongodb.com/cloud/atlas. Click on the “Get started free” button to proceed.
Step 2: Create a MongoDB Atlas Account Provide the required information, including your name, email address, and password, to create a MongoDB Atlas account. Click “Get Started” to move forward. You can also create an account using google email here
Step 3: Choose a Project Name Select a suitable project name for your cluster. This helps you organize and manage your MongoDB Atlas resources effectively. Once you’ve chosen a name, click “Next” to continue.
Step 4: Select Cloud Provider and Region You can choose between AWS, Google Cloud, or Azure as your cloud provider. Pick the region that is closest to your location to ensure optimal performance. Click “Create Cluster” to proceed. This steps is important if you want to integrate a VPC peering with your cloud provider.
Step 5: Select the Free Tier (M0 Sandbox) On the following page, scroll down to the “Cluster Tier” section. Here, you can select the free tier option called “M0 Sandbox”. This tier provides a free cluster with limited resources, perfect for development and testing purposes. Click “Create Cluster” to initiate the cluster creation process.
Step 6: Wait for Cluster Creation MongoDB Atlas will now start setting up your cluster. This process may take a few minutes, so please be patient.
Step 7: Explore Cluster Configuration Once the cluster is created, you’ll be redirected to the cluster overview page. Here, you can explore various configuration options for your cluster. The default settings are generally sufficient for most development needs. You can configure your database username and password. Let’s configure appUser and 0lR040clSGnMy1Ag for testing porpuse. Finally click on “Create User”.
Step 8: (Optional) Configure IP Whitelist In the “Cluster Overview” page, you can find the “IP Whitelist” section. You can add specific IP addresses to allow access to your cluster. By default, your current IP address is added to the whitelist. This step is optional but can be useful if you need to access the cluster from specific IP addresses.
Step 9: Connect to the Cluster To connect to your newly created cluster, click the “Connect” button on the cluster overview page. In the “Connect to Cluster” modal, choose the “Connect your application” option.
Our string connection is mongodb+srv://appUser:<password>@devcluster.iiejdkx.mongodb.net/ we will need to replace password with the real password.
Step 10: Download and install Mongo Compass from here
Step 11: Once you have installed Mongo Compas, go and create a new connection and paste the connection string from above, remember to replace the password. Finally click on save & connect.
Step 12: Click on create new database (yellow circle)
Step 13: Click on “add data” button, then select insert document and paste the following Json:
/**
* Paste one or more documents here
*/
{
"_id": {
"$oid": "64a5a5f3eaa905e2da0fe99f"
},
"name": "DevUser",
"role": "name"
}
Click on insert
You can also check this from the cluster manager, click on Browser collections:
If you are looking for more real data just to practice queries, you can import a sample dataset.
Then go to your collections and now you will see more collections and data.
Conclusion
That’s it! You have successfully created a free MongoDB Atlas cluster. You can now use the provided connection string to connect to the cluster from your application and start using MongoDB.
You can find more information on the official documentation