Navigation

Configure the MongoDB CLI

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.

Prerequisites

To configure the MongoDB CLI, you must have or generate a Programmatic API Key for your MongoDB service. You must grant the Programmatic API Key the Project Owner role and add your IP or CIDR block to the API whitelist. To learn more about generating a Programmatic API Key for your MongoDB service, see the following documentation:

Procedure

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

1

Create a profile.

This command creates a profile called default in the MongoDB CLI Configuration File. The MongoDB CLI uses this profile by default.

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, you must specify it with the --profile flag in every MongoDB CLI command.

Run the mongocli config command:

mongocli config  --profile <profile-name>
2

Enter your Programmatic API Key and Project ID.

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

? Public API Key: abcdef
? Private API Key: [? for help] ************************************
? Project ID [optional]: 7ehf04abc10defb66c7d1234c

If you don’t save your project ID in your profile, you must specify the --projectId option every time you run a MongoDB CLI command.

3

Verify your profile.

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

In this example, the following command returns the settings in the default profile:

mongocli config describe default

The command returns the following settings. The default profile has a Programmatic API Key, which is redacted in the command output for security purposes, and project ID for an Atlas deployment.

private_api_key = redacted
public_api_key = redacted
project_id = 7ehf04abc10defb66c7d1234c
service = cloud

Example

In this example, the following command returns the settings in the profile named myMongoDB:

mongocli config describe myMongoDB

The command returns following settings. The myMongoDB profile has a Programmatic API Key, which is redacted in the command output for security purposes, and project ID for an Atlas deployment.

private_api_key = redacted
public_api_key = redacted
project_id = 7ehf04abc10defb66c7d1234c
service = cloud
1

Create a profile.

This command creates a profile called default in the MongoDB CLI Configuration File. The MongoDB CLI uses this profile by default.

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, you must specify it with the --profile flag in every MongoDB CLI command.

Run the mongocli config command:

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

Enter your Cloud Manager API Access and Project ID.

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

? Public API Key: abcdef
? Private API Key: [? for help] ************************************
? Project ID [optional]: 7ehf04abc10defb66c7d1234c

If you don’t save your project ID in your profile, you must specify the --projectId option every time you run a MongoDB CLI command.

3

Verify your profile.

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

In this example, the following command returns the settings in the default profile:

mongocli config describe default

The command returns the following settings. The default profile has a Programmatic API Key, which is redacted in the command output for security purposes, and project ID for an MongoDB Cloud Manager deployment.

private_api_key = redacted
public_api_key = redacted
project_id = 7ehf04abc10defb66c7d1234c
service = cloud-manager

Example

In this example, the following command returns the settings in the profile named myMongoDB:

mongocli config describe myMongoDB

The command returns following settings. The myMongoDB profile has a Programmatic API Key, which is redacted in the command output for security purposes, and project ID for an MongoDB Cloud Manager deployment.

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

Create a profile.

This command creates a profile called default in the MongoDB CLI Configuration File. The MongoDB CLI uses this profile by default.

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, you must specify it with the --profile flag in every MongoDB CLI command.

Run the mongocli config command:

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

Enter your Ops Manager Base URL

The Ops Manager Base URL is the URL you use to access Ops Manager.

? Ops Manager Base URL: http://mms.example.com:8080
3

Enter your Ops Manager API Acess and Project ID.

When prompted, enter the Public API Key, Private API Key, and Project ID for your Ops Manager deployment.

? Public API Key: abcdef
? Private API Key: [? for help] ************************************
? Project ID [optional]: 7ehf04abc10defb66c7d1234c

If you don’t save your project ID in your profile, you must specify the --projectId option every time you run a MongoDB CLI command.

4

Verify your profile.

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

In this example, the following command returns the settings in the default profile:

mongocli config describe default

The command returns the following settings. The default profile has a Programmatic API Key, which is redacted in the command output for security purposes, and project ID for an Ops Manager deployment.

private_api_key = redacted
public_api_key = redacted
project_id = 7ehf04abc10defb66c7d1234c
service = ops-manager

Example

In this example, the following command returns the settings in the profile named myMongoDB:

mongocli config describe myMongoDB

The command returns following settings. The myMongoDB profile has a Programmatic API Key, which is redacted in the command output for security purposes, and project ID for an Ops Manager deployment.

private_api_key = redacted
public_api_key = redacted
project_id = 7ehf04abc10defb66c7d1234c
service = ops-manager

Next Steps