How to Connect to MongoDB Atlas Using Shell?
Last Updated :
21 Feb, 2025
MongoDB is a highly scalable NoSQL database, renowned for its ability to manage vast amounts of complex and unstructured data. Unlike traditional databases that use a tabular format, MongoDB employs a document-oriented approach, storing data in a flexible, JSON-like format. This makes MongoDB highly scalable and suitable for various modern applications.
In this article, We will learn about How to Connect to MongoDB Atlas Using Shell in detail, step by step, including cluster creation, connection setup, and basic queries.
What is MongoDB Atlas?
MongoDB Atlas is a fully managed multi-cloud database. It handles all the complexity of deploying and managing on cloud service providers like AWS, Google Cloud Platform and Microsoft Azure. Atlas is a good way to deploy, run and scale MongoDB in the cloud. Atlas offers a free tier (M0) which makes it an excellent choice for small projects, testing, and learning MongoDB in the cloud without incurring any cost.
What is MongoDB Shell?
The MongoDB Shell (also called mongosh) is a JavaScript-based interface that allows you to interact with MongoDB databases from the command line. It enables data manipulation, querying, and performing administrative tasks on the MongoDB database. MongoDB Shell is a powerful tool for developers working with MongoDB in local or cloud-based environments like MongoDB Atlas.
Steps to connect MongoDB Atlas using Shell
We need to follow the following steps to create a connection with MongoDB Atlas using Shell,
Step 1. Install MongoDB on your local computer
First, install MongoDB on your local system. If you haven't already, download and install MongoDB from the official MongoDB download page.
Verify Installation
After installing MongoDB. Now open any terminal and write the following command and check whether it is installed properly in our system or not.
mongod
Starting MongoDB server on port: 27017It starts the MongoDB server on the port 27017.
Now, keep this MongoDB Mongo window and open a new tab to run the Mongo shell that will connect to the MongoDB. Write the following command.
mongo
Connecting the Mongo Shell to the local MongoDB ServerThis connects your Mongo Shell to the local MongoDB server. Next, we'll connect the Mongo Shell to MongoDB Atlas.
Step 2. Creating a Cluster in MongoDB Atlas
1. Sign Up for MongoDB Atlas
Go to the MongoDB Atlas website and sign up for an account, We can sign up using your email or directly with Google.

2. Build a Database
Now, go to the database option and click on the "Build a Database" button.
Creating a Database- Select the Free Tier Cluster (M0) option.
- Choose your preferred cloud provider: AWS, Google Cloud, or Microsoft Azure.
- Select the region where you want the cluster to be hosted (e.g., North Virginia, Frankfurt, etc.).
- Rename the cluster if desired, then click "Create" to set up the free cluster.
Creating a Free M0 Cluster in MongoDB Atlas
Configuring & Selecting the Hosting RegionStep 4: Set Up Access
Create a username and password for the MongoDB user and configure network access settings, allowing you to connect from any IP address. These credentials will be used to connect to MongoDB Atlas.
Creating an user for the DatabaseStep 3. Establishing a Connection to MongoDB Atlas from Mongo Shell
1. Connect Using Mongo Shell
- In the MongoDB Atlas dashboard, click on the "Connect" button for your newly created cluster.
- Choose "Connect with MongoDB Shell".
- Select the appropriate Mongo Shell version (Mongosh) and follow the instructions.
Connecting to MongoDB using Shell2. Run the Connection Command
Copy the connection string and run the command in our terminal, Then we can enter the password that we have set earlier with the username and password.
Connection established with the MongoDB cluster via Mongo ShellYou are successfully connected with the MongoDB Atlas using Mongo shell. You are ready to write queries in the Mongo Shell and that will be reflected in the MongoDB Atlas cluster.
Step 4: Writing Queries in Mongo Shell
After successfully connecting to MongoDB Atlas, you can start writing queries to interact with your data. Here are some basic examples to get started
1. Show Databases
This command lists all the databases in your MongoDB cluster:
show dbs
2. Create and Switch to a Database
Create a new database (if it doesn’t exist) and switch to it:
use GFG
3. Insert a Document into a Collection
It will create a collection "student" in the "GFG" database and insert a new JSON document in the "student" collection.
db. student.insertOne({"username": "arindam369", "college": "JU"})
QueriesOutput:
After executing the queries in the Mongo Shell, open the Collections in the MongoDB Atlas Cluster. We get the output given below.
After executing queries in the mongo shell, result in MongoDB AtlasConclusion
Connecting to MongoDB Atlas using the Mongo Shell provides an efficient way to manage our databases in the cloud. This guide walked us through the steps of setting up a MongoDB Atlas cluster, configuring access, and establishing a Mongo Shell connection. We also covered basic queries to interact with our data. MongoDB Atlas, paired with the Mongo Shell, offers a robust environment for managing and scaling databases across multiple cloud providers.
Similar Reads
How to Connect Node.js To MongoDB Atlas Using Mongoose?
MongoDB Atlas is a cloud-based database service that offers robust features and scalability for managing our data. Here we will use Express.js for the server framework and Mongoose for interacting with MongoDB. And also we use the Ejs for our front end to render the simple HTML form. In this tutoria
6 min read
How to use MongoDB atlas to save data ?
As modern applications require a database for storing data, MongoDB is a great choice. MongoDB Atlas is the global cloud database service for modern applications. We can use it for storing our application data on its server. Follows these steps for how to use MongoDB Atlas for saving data:Step 1: Vi
3 min read
How to Connect to a MongoDB Database Using Node.js
MongoDB is a NoSQL database used to store large amounts of data without any traditional relational database table. To connect to a MongoDB database using NodeJS we use the MongoDB library "mongoose". Steps to Connect to a MongoDB Database Using NodeJSStep 1: Create a NodeJS App: First create a NodeJ
4 min read
How to Connect Mongo DB with AWS using ATLAS?
The MongoDB Atlas provides the Application deployment solution by MongoDB hosting on AWS. MongoDB Atlas handles operational tasks such as backups, updates, and security configurations. There are many ways to connect MongoDB with AWS depending on specific use cases and requirements: MongoDB Atlas (Fu
5 min read
How to use MongoDB Connection String
MongoDB connection strings are essential for establishing connections between applications and MongoDB databases. These strings contain crucial information such as server addresses, authentication credentials and optional parameters, enabling seamless communication. Understanding the structure and c
6 min read
How to Get Data from MongoDB using Node.js?
One can create a simple Node.js application that allows us to get data to a MongoDB database. Here we will use Express.js for the server framework and Mongoose for interacting with MongoDB. Also, we use the EJS for our front end to render the simple HTML form and a table to show the data. Prerequisi
6 min read
How To Use the MongoDB Shell
The MongoDB Shell, also known as mongosh is a powerful command-line interface that allows users to interact with MongoDB databases. It provides a REPL (Read-Eval-Print Loop) environment that facilitates database management, data manipulation, and administrative tasks with ease In this comprehensive
7 min read
How to drop database of MongoDB using Node.js ?
MongoDB, the most popular NoSQL database, is an open-source document-oriented database. The term âNoSQLâ means ânon-relationalâ. It means that MongoDB isnât based on the table-like relational database structure but provides an altogether different mechanism for storage and retrieval of data. This fo
2 min read
Troubleshooting MongoDB Atlas Connection Errors
MongoDB Atlas is MongoDB's fully managed cloud service which offers high availability, automatic scaling, and robust security for your databases. However, when connecting to MongoDB Atlas, we may encounter connection errors that can be difficult to detect and resolve. These errors can arise from net
8 min read
How to Connect to a MongoDB Database Using the Node.js Driver ?
MongoDB is a popular, open-source, NoSQL (non-relational) database that provides high performance, high availability, and easy scalability. Unlike traditional relational databases, MongoDB stores a JSON-like format called BSON (Binary JSON). In this article, we connect the MongoDB database to your b
4 min read