Quick Start
On this page
MongoDB CLI provides a command-line interface for managing your MongoDB Atlas, MongoDB Cloud Manager, and MongoDB Ops Manager projects and clusters. This tutorial demonstrates how to download, install, and configure MongoDB CLI. Then, for each platform, it demonstrates how to create a ready-to-go MongoDB cluster.
The reference pages for the commands mentioned in this tutorial are available in the mongocli section.
Prerequisites
Before you begin, review and ensure that your environment is compatible for installing and using MongoDB CLI.
This tutorial requires the following:
A MongoDB account for Atlas and Cloud Manager only
An Atlas, Cloud Manager, or Ops Manager organization and project
Download and Install MongoDB CLI
See Install the MongoDB CLI for information on downloading and installing MongoDB CLI. After installing MongoDB CLI, run the following command to verify installation:
mongocli help
Generate Programmatic Access Keys
MongoDB CLI uses Programmatic Access Keys to access the Atlas, Cloud Manager, or Ops Manager projects. Your Programmatic API Key must have:
The
project owner
or higher roleThe access list entry for your IP address or CIDR range
To learn more about generating the Programmatic API Key, see:
Configure the MongoDB CLI
You can configure MongoDB CLI access to your MongoDB service using the mongocli config and mongocli config set commands.
The following procedure creates the default profile in the configuration file. You can use this profile with all the other commands in this tutorial.
Optional: Enter your Programmatic API Key.
When prompted, enter the Public API Key
and Private API Key
for your Atlas deployment.
? Public API Key: [? for help] abcdef ? Private API Key: [? for help] ************************************
Choose your default organization.
If you entered API keys, the command displays the name and ID of organizations that your API key can access.
Select your organization:
Press the
Down Arrow
andUp Arrow
keys to highlight the desired organization, orType the organization name to filter the available organizations.
? Default Org ID: [Use arrows to move, type to filter] Org1 (5e39bf1212121e685774c81c) Press
Enter
.
If you didn't enter API keys, the command prompts you to enter your
Default Organization ID
.
Choose your default project.
If you entered API keys, the command displays the name and ID of projects that your API key can access.
Select your project:
Press the
Down Arrow
andUp Arrow
keys to highlight the desired project, orType the project name to filter the available projects.
? Default Project ID: [Use arrows to move, type to filter] Project1 (5e5ebffd0c04a97009061234) Project2 (5cfacee6014b761b07f15678) Project3 (5e39bf4979358e6857741212) Project4 (5c815cc7014b768fb67e3434) Press
Enter
.
If you didn't enter API keys, the command prompts you to enter your
Default Project ID
.
Optional: Customize the MongoDB CLI output using a Go template.
To learn more about customizing the MongoDB CLI output fields and format
using a Go
template, see Customize the MongoDB CLI Output Using a Go Template.
You can configure MongoDB CLI access to your MongoDB service using the mongocli config and mongocli config set commands.
The following procedure creates the default profile in the configuration file. You can use this profile with all the other commands in this tutorial.
Optional: Enter your API keys.
When prompted, enter the Public API Key
and Private API Key
for your MongoDB Cloud Manager deployment.
? Public API Key: [? for help] abcdef ? Private API Key: [? for help] ************************************
Choose your default organization.
If you entered API keys, the command displays the name and ID of organizations that your API key can access.
Select your organization:
Press the
Down Arrow
andUp Arrow
keys to highlight the desired organization, orType the organization name to filter the available organizations.
? Default Org ID: [Use arrows to move, type to filter] Org1 (5e39bf1212121e685774c81c) Press
Enter
.
If you didn't enter API keys, the command prompts you to enter your
Default Organization ID
.
Choose your default project.
If you entered API keys, the command displays the name and ID of projects that your API key can access.
Select your project:
Press the
Down Arrow
andUp Arrow
keys to highlight the desired project, orType the project name to filter the available projects.
? Default Project ID: [Use arrows to move, type to filter] Project1 (5e5ebffd0c04a97009061234) Project2 (5cfacee6014b761b07f15678) Project3 (5e39bf4979358e6857741212) Project4 (5c815cc7014b768fb67e3434) Press
Enter
.
If you didn't enter API keys, the command prompts you to enter your
Default Project ID
.
Optional: Customize the MongoDB CLI output using a Go template.
To learn more about customizing the MongoDB CLI output fields and format
using a Go
template, see Customize the MongoDB CLI Output Using a Go Template.
You can configure MongoDB CLI access to your MongoDB service using the mongocli config and mongocli config set commands.
The following procedure creates the default profile in the configuration file. You can use this profile with all the other commands in this tutorial.
Enter the URL you use to access Ops Manager.
? URL to Access Ops Manager: http://mms.example.com:8080
Optional: Enter your API keys.
When prompted, enter the Public API Key
and Private API Key
for your Ops Manager deployment.
? Public API Key: [? for help] abcdef ? Private API Key: [? for help] ************************************
Choose your default organization.
If you entered API keys, the command displays the name and ID of organizations that your API key can access.
Select your organization:
Press the
Down Arrow
andUp Arrow
keys to highlight the desired organization, orType the organization name to filter the available organizations.
? Default Org ID: [Use arrows to move, type to filter] Org1 (5e39bf1212121e685774c81c) Press
Enter
.
If you didn't enter API keys, the command prompts you to enter your
Default Organization ID
.
Choose your default project.
If you entered API keys, the command displays the name and ID of projects that your API key can access.
Select your project:
Press the
Down Arrow
andUp Arrow
keys to highlight the desired project, orType the project name to filter the available projects.
? Default Project ID: [Use arrows to move, type to filter] Project1 (5e5ebffd0c04a97009061234) Project2 (5cfacee6014b761b07f15678) Project3 (5e39bf4979358e6857741212) Project4 (5c815cc7014b768fb67e3434) Press
Enter
.
If you didn't enter API keys, the command prompts you to enter your
Default Project ID
.
Optional: Customize the MongoDB CLI output using a Go template.
To learn more about customizing the MongoDB CLI output fields and format
using a Go
template, see Customize the MongoDB CLI Output Using a Go Template.
Next Steps
Now that you've installed and configured MongoDB CLI for accessing your MongoDB service, proceed to: