Control Your Atlas Data: Connect MongoDB with MongoSH Fast
Did you know its easy to connect to your MongoDB Database hosted on Mongo DB Atlas using a CLI. Step up MongoSH, the easy way to manage MongoDB from the command line.
This article will show you how to install MongoSH on Linux and Windows. Then explain exactly how to connect to the database.
Step1 – Installing mongosh
:
How to Install MongoSH on Linux (Ubuntu/Debian)
- Import the MongoDB GPG key:
This step verifies the authenticity of the MongoDB packages.
wget -qO - https://www.mongodb.org/static/pgp/server-7.0.asc | sudo apt-key add -
- Create a list file for MongoDB
This adds the official MongoDB repository to your system’s package sources.
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu $(lsb_release -cs)/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list
- Update package lists
This refreshes the package lists to include the new repository.
sudo apt update -y
- Install
mongosh
This refreshes the package lists to include the new repository.
sudo apt-get install -y mongodb-mongosh
Windows (MSI Installer):
- Download the MSI Installer:
- Go to the MongoDB Download Center: https://www.mongodb.com/try/download/shell
- Select the Windows platform and download the MSI installer.
- Run the Installer:
- Double-click the downloaded MSI file.
- Follow the installation wizard.
- Ensure you add
mongosh
to your PATH environment variable during installation (the installer usually offers to do this).
- Verify Installation:
- Open a new Command Prompt or PowerShell window.
- Type
mongosh --version
and press Enter.

Step 2 – Connecting to MongoDB Atlas:
- Get Your Connection String:
- Log in to your MongoDB Atlas account.
- Navigate to your cluster.
- Click the “Connect” button.
- Choose if you connect via a Private Endpoint or Standard Endpoint
- If you choose private endpoint you will most likely need VPN access into MongoDB
- If you use Standard Endpoint you will need to enable you IP Address from Security > Network Access page.

- Select “Connect with the MongoDB Shell”.

- Copy the connection string. It will look like this:
mongosh
mongosh "mongodb+srv://xfw-xxxxxxxxx-eu-prd.vltue.mongodb.net/" --apiVersion 1 --username rbailey

You will be prompted to enter your password after you press [ENTER]
- Connect Using
mongosh
:- Open a terminal (Linux/macOS) or Command Prompt/PowerShell (Windows).
- Paste the connection string, replacing
<username>
, mongosh “mongodb+srv://xfw-xxxxxxxxx-xxx-xxx.vltue.mongodb.net/” –apiVersion 1 –username rbailey - Press Enter.
- If you’re prompted for your password, enter it.
You should see something like this:
richard@UK-PF4WYXXA:~$ mongosh "mongodb+srv://xfw-xxxx.xxxxxxxx.mongodb.net/" --apiVersion 1 --username rbailey
Enter password: ****************
Current Mongosh Log ID: 111111111111111111111111111
Connecting to: mongodb+srv://<credentials>@xfw-xxxxxxxxxxxxxx.mongodb.net/?appName=mongosh+2.0.0
Using MongoDB: 7.0.17 (API Version 1)
Using Mongosh: 2.0.0
mongosh 2.4.0 is available for download: https://www.mongodb.com/try/download/shell
For mongosh info see: https://docs.mongodb.com/mongodb-shell/
------
The server generated these startup warnings when booting
2025-02-25T22:25:51.277+00:00: /sys/kernel/mm/transparent_hugepage/enabled is 'always'. We suggest setting it to 'never' in this binary version
------
Atlas atlas-xxxxxxxxxxxxxxxxxxxxxxxxxxxxx-shard-0 [primary] test>
Recent Comments