Docs Menu
Docs Home
/ /
MongoDB Command Line Interface

Configure the MongoDB CLI

On this page

  • Prerequisites
  • Procedure
  • Next Steps

You can define the settings that the MongoDB CLI uses to interact with MongoDB services like Atlas, Cloud Manager, and Ops Manager by using the mongocli config command. The first time you run this command, the MongoDB CLI creates a configuration file called mongocli.toml to store your settings.

To configure the MongoDB CLI:

  • Add your IP or CIDR block to the API access list for your MongoDB service.

  • Generate a Programmatic API Key if you don't already have one.

    Note

    Programmatic API Keys are role-based. Different roles have different privileges and capabilities, and some MongoDB CLI commands are available to some roles but not others. Be sure that the roles assisgned to your Programmatic API Key are appropriate for the commands you intend to use.

To learn more about generating a Programmatic API Key for your MongoDB service, see the following documentation:

The mongocli config command varies slightly depending on the MongoDB service for which you want to configure the MongoDB CLI.

1

This command creates a profile called default in the MongoDB CLI Configuration File.

Run the mongocli config command:

mongocli config

This command creates a profile with a custom name in the MongoDB CLI Configuration File. To use this profile in a command, you must specify the profile with the --profile flag.

Run the mongocli config command:

mongocli config --profile <profile-name>
2

When prompted, enter the Public API Key and Private API Key for your Atlas deployment.

? Public API Key: abcdef
? Private API Key: [? for help]
************************************
3

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

  1. Select your organization:

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

    • Type the organization name to filter the available organizations.

    ? Choose a default organization: [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 Project 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.

    ? Choose a default project: [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 Organization ID.

5

View the configuration file or run the mongocli config describe command to verify your profile.

Important

Your API keys are like passwords. The configuration file stores API keys in plaintext, so ensure that you secure the configuration file appropriately.

Example

The following command returns the settings in the default profile:

mongocli config describe default

The command returns the following settings. For security purposes, the command redacts API keys in the output.

org_id = 5f1f39ffc902201990f12345
private_api_key = redacted
project_id = 7ehf04abc10defb66c7d1234c
public_api_key = redacted
service = cloud

Example

The following command returns the settings in the profile named myMongoDB:

mongocli config describe myMongoDB

The command returns following settings. For security purposes, the command redacts API keys in the output.

org_id = 5f1f39ffc902201990f12345
private_api_key = redacted
project_id = 7ehf04abc10defb66c7d1234c
public_api_key = redacted
service = cloud
1

This command creates a profile called default in the MongoDB CLI Configuration File.

Run the mongocli config command:

mongocli config --service cloud-manager

This command creates a profile with a custom name in the MongoDB CLI Configuration File. To use this profile in a command, you must specify the profile with the --profile flag.

Run the mongocli config command:

mongocli config --service cloud-manager --profile <profile-name>
2

When prompted, enter the Public API Key and Private API Key for your MongoDB Cloud Manager deployment.

? Public API Key: abcdef
? Private API Key: [? for help]
************************************
3

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

  1. Select your organization:

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

    • Type the organization name to filter the available organizations.

    ? Choose a default organization: [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 Project 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.

    ? Choose a default project: [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 Organization ID.

5

View the configuration file or run the mongocli config describe command to verify your profile.

Important

Your API keys are like passwords. The configuration file stores API keys in plaintext, so ensure that you secure the configuration file appropriately.

Example

The following command returns the settings in the default profile:

mongocli config describe default

The command returns the following settings. For security purposes, the command redacts API keys in the output.

org_id = 5f1f39ffc902201990f12345
private_api_key = redacted
project_id = 7ehf04abc10defb66c7d1234c
public_api_key = redacted
service = cloud-manager

Example

The following command returns the settings in the profile named myMongoDB:

mongocli config describe myMongoDB

The command returns following settings. For security purposes, the command redacts API keys in the output.

org_id = 5f1f39ffc902201990f12345
private_api_key = redacted
project_id = 7ehf04abc10defb66c7d1234c
public_api_key = redacted
service = cloud-manager
1

This command creates a profile called default in the MongoDB CLI Configuration File.

Run the mongocli config command:

mongocli config --service ops-manager

This command creates a profile with a custom name in the MongoDB CLI Configuration File. To use this profile in a command, you must specify the profile with the --profile flag.

Run the mongocli config command:

mongocli config --service ops-manager --profile <profile-name>
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: abcdef
? Private API Key: [? for help]
************************************
4

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

  1. Select your organization:

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

    • Type the organization name to filter the available organizations.

    ? Choose a default organization: [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 Project 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.

    ? Choose a default project: [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 Organization ID.

6

View the configuration file or run the mongocli config describe command to verify your profile.

Important

Your API keys are like passwords. The configuration file stores API keys in plaintext, so ensure that you secure the configuration file appropriately.

Example

The following command returns the settings in the default profile:

mongocli config describe default

The command returns the following settings. For security purposes, the command redacts API keys in the output.

ops_manager_url = https://mms.example.com:8080/
org_id = 5f1f39ffc902201990f12345
private_api_key = redacted
project_id = 7ehf04abc10defb66c7d1234c
public_api_key = redacted
service = ops-manager

Example

The following command returns the settings in the profile named myMongoDB:

mongocli config describe myMongoDB

The command returns following settings. For security purposes, the command redacts API keys in the output.

ops_manager_url = https://mms.example.com:8080/
org_id = 5f1f39ffc902201990f12345
private_api_key = redacted
project_id = 7ehf04abc10defb66c7d1234c
public_api_key = redacted
service = ops-manager

Back

Compatibility