In this guide, you will learn how to create a MongoDB Atlas deployment locally or in the cloud. Then, you will learn how to create an application that connects to your deployment. To learn how to install MongoDB Community or MongoDB Enterprise editions on your own infrastructure, see the Install MongoDB guide.
Create a MongoDB Atlas Deployment
This section shows how to set up a local or cloud MongoDB Atlas deployment and connect to the deployment by using the MongoDB Shell.
Install dependencies
Before you begin this tutorial, you must install the following dependencies in your development environment:
Atlas CLI: Command-line interface that allows you to manage your deployments from the terminal
MongoDB Shell: Interactive tool that connects to a deployment and provides database operation support
Docker: Platform that allows you to run software within containers, including local MongoDB deployments
Select the tab corresponding to your operating system to view the commands that install these required development tools.
Run the following commands to install the dependencies by using the Homebrew package manager. If you do not have Homebrew, you can install it by following the instructions on the Homebrew website.
brew install mongodb-atlas brew install --cask docker
Run the following commands to install the dependencies by using the Chocolatey package manager. If you do not have Chocolatey, you can install it by following the instructions on the Chocolatey website.
choco install mongodb-atlas choco install docker-desktop
For other ways to install the Atlas CLI, see Atlas CLI install page.
Note
Docker Desktop
The preceding commands install the Docker Desktop application. After the installation completes, ensure that you create a Docker account and start the application.
Set up a fully-featured deployment
Run the following command and follow the prompts in the shell to deploy a cluster. If you do not have an Atlas account, the following command prompts you to create one.
This command creates a single-member replica set in a container that runs on your local machine.
atlas deployments setup myDeployment --type local \ --mdbVersion 8.0 --port <port number> --connectWith skip
Note
Replace the <port number> placeholder with the port
you want to use. The default port is 27017, but you
can specify a different port if 27017 is not available.
The command outputs the following information:
Deployment created! Connection string: "<connection string URI>"
Save the connection string URI for use in a future step.
This command creates a free tier cluster on MongoDB Atlas.
atlas deployments setup myDeployment --type atlas \ --provider AWS -r us-east-1 --skipSampleData \ --username <database username> --password <database user password> \ --connectWith skip --force
Note
Replace the following placeholder values to create a new database user with atlasAdmin privileges in your deployment:
<database username>: Specify a username for your new database user<database user password>: Specify a password for your new database user
The command outputs the following information:
Cluster created. Your connection string: "<connection string URI>"
Save the connection string URI for use in a future step.
Connect to your deployment
You can connect to your deployment with the MongoDB Shell (mongosh) by running the
following command:
atlas deployments connect myDeployment --connectWith mongosh
atlas deployments connect myDeployment --username <database username> \ --password <database user password> --connectWith mongosh
Note
Replace the <database username> and <database user password> placeholders
with the username and password you created for your database user.
After connecting, you can run the following command to test your connection:
show dbs
The command returns a list of databases in your deployment.
Congratulations! You have successfully set up your MongoDB Atlas deployment and connected to it. To learn more about how to interact with your deployment by using the MongoDB Shell, see the MongoDB Shell documentation.
In the next section, you will learn how to create an application that connects to your deployment and interacts with data.
Create Your First MongoDB Application
To connect to your MongoDB Atlas deployment in an application, you can use one of the official MongoDB client libraries.
Select your preferred programming language from the following dropdown menu to learn how to connect to your MongoDB Atlas deployment in that language.
Tip
Before running the steps in this section, ensure that you exit the MongoDB Shell
by running the exit command.