Docs Menu
Docs Home
/ /
MongoDB Command Line Interface

Quick Start

On this page

  • Prerequisites
  • Download and Install MongoDB CLI
  • Generate Programmatic Access Keys
  • Configure the MongoDB CLI
  • Next Steps

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.

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

See Install or Update the MongoDB CLI for information on downloading and installing MongoDB CLI. After installing MongoDB CLI, run the following command to verify installation:

mongocli help

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 role

  • The access list entry for your IP address or CIDR range

To learn more about generating the Programmatic API Key, see:

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.

1

Run the following command to create a profile called default.

mongocli config
2

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]
************************************
3

If you entered API keys, the command displays the name and ID of the organization that your API key can access. Press Enter to confirm your organization.

If you didn't enter API keys, the command prompts you to enter your Default Organization ID.

4

If you entered API keys, the command displays the name and ID of projects that your API key can access.

  1. Select your project:

    • Press the Down Arrow and Up Arrow keys to highlight the desired project, or

    • Type 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)
  2. Press Enter.

If you didn't enter API keys, the command prompts you to enter your Default Project ID.

5

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.

1

Run the following command to create a profile called default.

mongocli config --service cloud-manager
2

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]
************************************
3

If you entered API keys, the command displays the name and ID of the organization that your API key can access. Press Enter to confirm your organization.

If you didn't enter API keys, the command prompts you to enter your Default Organization ID.

4

If you entered API keys, the command displays the name and ID of projects that your API key can access.

  1. Select your project:

    • Press the Down Arrow and Up Arrow keys to highlight the desired project, or

    • Type 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)
  2. Press Enter.

If you didn't enter API keys, the command prompts you to enter your Default Project ID.

5

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.

1

Run the following command to create a profile called default.

mongocli config --service ops-manager
2
? URL to Access Ops Manager: http://mms.example.com:8080
3

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]
************************************
4

If you entered API keys, the command displays the name and ID of the organizations that your API key can access.

  1. Select your organization.

    ? Default Org ID: [Use arrows to move, type to filter]
    > Org1 (5e39bf1212121e685774c81c)
  2. Press Enter.

If you didn't enter API keys, the command prompts you to enter your Default Organization ID.

5

If you entered API keys, the command displays the name and ID of projects that your API key can access.

  1. Select your project:

    • Press the Down Arrow and Up Arrow keys to highlight the desired project, or

    • Type 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)
  2. Press Enter.

If you didn't enter API keys, the command prompts you to enter your Default Project ID.

6

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.

Now that you've installed and configured MongoDB CLI for accessing your MongoDB service, proceed to:

Back

Customize the MongoDB CLI Output Using a Go Template