Software Development

Getting Started with MongoDB Atlas

MongoDB Atlas is a fully managed cloud database service that makes it easy to deploy, manage, and scale MongoDB databases in the cloud. Atlas provides a user-friendly interface and features to simplify database management. This article will guide you through the process of setting up your first MongoDB Atlas cluster, connecting to it using MongoDB Shell, and loading sample data to explore.

1. What Is MongoDB Atlas?

MongoDB Atlas is a cloud database service that allows you to run and scale MongoDB clusters on platforms like AWS, Azure, and Google Cloud. It uses flexible, JSON-like documents to store data, making it a great alternative to traditional table-based databases. MongoDB Atlas provides all the features of the MongoDB NoSQL database along with automated backup, scaling, and monitoring tools. MongoDB Atlas allows us to:

  • Deploy and manage MongoDB clusters across multiple cloud providers.
  • Set up highly available clusters with minimal configuration.
  • Scale storage and compute resources on demand.
  • Ensure data security with built-in encryption, auditing, and access controls.

1.1 Features of MongoDB Atlas

  • Fully Managed Service: MongoDB Atlas handles database setup, monitoring, and maintenance automatically, allowing teams to focus on application development.
  • Multi-Cloud Availability: Users can deploy clusters across AWS, Google Cloud Platform (GCP), and Microsoft Azure, providing flexibility and redundancy.
  • Automatic Scaling: Atlas supports both vertical and horizontal scaling. It can scale up to accommodate increased data loads and traffic with minimal configuration.
  • Advanced Security: Atlas includes features like IP whitelisting, encryption, VPC peering, and private endpoints, making it a secure option for applications.
  • Global Distribution: MongoDB Atlas allows users to distribute data globally, ensuring low latency and high availability for users worldwide.
  • Built-in Monitoring & Analytics: Atlas offers real-time performance monitoring, data visualization, and query optimization tools.

2. Getting Started With MongoDB Atlas

MongoDB Atlas is very beginner-friendly, with a quick sign-up process that takes only seconds to access the free tier. The setup is guided by an interactive web interface that helps you choose the best deployment options, making it easy to follow even if you’re new to databases. With MongoDB Atlas, getting started doesn’t require specialized knowledge, and its user-friendly interface simplifies every step.

Once set up, the MongoDB Atlas UI provides an intuitive dashboard where you can view and manage clusters, databases, and collections. The interface makes it straightforward to set up your first cluster, monitor database performance, and handle data with ease. In the following steps, we’ll walk you through the process of setting up and exploring MongoDB Atlas.

Create an Atlas Account

To get started, visit the MongoDB Atlas landing page and register for an account. If you have a Google account, you can quickly sign up by selecting the “Sign Up with Google” button. Otherwise, simply fill in your email address, first and last name, and create a password. After registering, Atlas will automatically set up a default organization and project for you, allowing you to deploy your first cluster right away.

mongodb atlas homepage
MongoDB Atlas Landing Page: Source https://www.mongodb.com/products/platform/atlas-database

3. Setting Up a Cluster

Once logged in, you will be taken to a page where you can specify your goals, the type of application you are building, and your preferred programming language. Fill in these details based on your preferences.

Next, you will be guided through creating your first cluster by selecting a cloud provider—Amazon AWS, Google Cloud, or Microsoft Azure—and specifying the preferred data centre region. The MongoDB Atlas UI also lets you choose server types like M0, Serverless, or M10, along with customizable security settings, to tailor the cluster to your specific needs.

The MongoDB Atlas free M0 tier provides a starter cluster with 512 MB of storage, shared RAM, and highly available replica sets. This tier supports up to 100 simultaneous connections and is a great entry point for small applications or learning MongoDB.

In the Provider section, AWS is selected as the default provider, but you can choose any provider. All three platforms offer support for the free tier. In the Cluster Name section, enter “JCGCluster” or any name you prefer in the text box.

mongodb atlas deploy cluster

Next, Click the Create Deployment button at the bottom of the web page. Atlas will proceed with deploying and initializing the database cluster, notifying you once it is complete.

3.1 Whitelist Your Connection IP Address

Next, you will be asked to set up your Internet Protocol (IP) settings and whitelist your IP address. This step is essential to secure your cluster. Alternatively, you can allow access from any IP address, but this means that anyone would be able to connect to your cluster.

mongodb atlas add IP address

3.2 Create a MongoDB User for Your Cluster

Next, create a MongoDB user by entering a new username and password, which will allow you to connect to your JCGCluster.

mongodb atlas create database user

4. Connect to Your Cluster

With your user created, you are ready to connect to your cluster. On the dashboard, click the “Connect your application” button and choose how you would like to connect: via MongoDB Shell, your application, Atlas SQL or MongoDB Compass (MongoDB’s GUI). For this example, we will connect using MongoDB Shell.

The “mongodb+srv:…” string shown in the screenshot above is the connection string. Click the copy icon next to it to copy the string. You will notice that the username and cluster-name fields in the copied URI are already filled in for you. Remember to store this connection string securely. We will use the completed connection string/URI when connecting to the cluster with MongoDB Shell.

4.1 View Data in Your Cluster

Once connected to your cluster, you can start adding and working with sample data. The MongoDB Atlas UI lets you view, create, and delete databases, collections, and indexes within your cluster. Additionally, you can insert, edit, and delete documents, as well as build and execute aggregation pipelines to analyze and process your data.

To load a sample dataset into your MongoDB Atlas cluster, start by navigating to the Clusters section of the MongoDB Atlas dashboard. Select your cluster, and look for the Load Sample Dataset option. By clicking this option, MongoDB Atlas will begin loading a pre-defined dataset into your cluster. The sample dataset includes various databases and collections, such as movie and weather data, which are useful for exploring MongoDB Atlas’s features and practising different types of queries and aggregations.

After the data is loaded, you can access it in the MongoDB Atlas UI by clicking the Collections button (or through Mongo Shell). The import process takes a few minutes, and once the data loading process is complete, you will see 9 databases added to your cluster. You will be able to view and interact with these sample databases directly from the MongoDB Atlas UI.

4.2 Connecting to a Cluster with MongoDB Shell

The MongoDB Shell (mongosh) is an interactive JavaScript shell for MongoDB, allowing us to perform database operations and execute scripts. To connect to your JCGCluster using MongoDB Shell, follow these steps:

  • Access the Cluster Connection String: First, go to the MongoDB Atlas dashboard and navigate to your JCGCluster. Click on the Connect button, which will prompt a window with various connection options.
  • Choose MongoDB Shell: In the connection options, select MongoDB Shell. Atlas will display a connection string that you can use in MongoDB Shell. This string contains your cluster’s credentials and connection details, such as the cluster address and the authentication method.
  • Install MongoDB Shell (if necessary): If you don’t have MongoDB Shell installed, follow the instructions on the MongoDB website to install it on your machine. The installation steps will vary depending on your operating system.
  • Run the Connection Command: Copy the connection string provided by Atlas and paste it into your terminal or command prompt. The connection string will look something like this:
mongosh "mongodb+srv://jcgcluster.nw9f0.mongodb.net/" --apiVersion 1 --username jcgadmin

Press Enter to execute the command, and once connected, MongoDB Shell will enable you to interact directly with your Cluster, allowing you to query data, insert documents, and manage collections.

4. Conclusion

In this article, we explored how to get started with MongoDB Atlas, from registering for an account and setting up your first cluster to connecting using MongoDB Shell. We also covered how to load sample datasets into your cluster and interact with your data through the Atlas UI. With MongoDB Atlas, setting up and managing your clusters is a seamless process, allowing you to focus on building your applications without worrying about infrastructure.

Omozegie Aziegbe

Omos Aziegbe is a technical writer and web/application developer with a BSc in Computer Science and Software Engineering from the University of Bedfordshire. Specializing in Java enterprise applications with the Jakarta EE framework, Omos also works with HTML5, CSS, and JavaScript for web development. As a freelance web developer, Omos combines technical expertise with research and writing on topics such as software engineering, programming, web application development, computer science, and technology.
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Back to top button