Navigation

Alpha Release of MongoDB CLI

This is a pre-release early version of MongoDB CLI. Do not use MongoDB CLI to manage production environments.

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.

Run the mongocli config command:

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

If you don’t specify a profile name, MongoDB CLI names this profile default.

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 mongocli.toml configuration file 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 configuration file is stored in the /.config folder of your home directory. View the file using the cat command:

cat ~/.config/mongocli.toml

The command returns the contents of the configuration file, which contains a default profile that has a Programmatic API Key for an Atlas deployment.

[default]
private_api_key = "abcdef"
public_api_key = "d5199648-abcd-1234-efgh-3ed4396a3096"
service = "cloud"
1

Create a profile.

Run the mongocli config command:

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

If you don’t specify a profile name, MongoDB CLI names this profile default.

2

Enter your Programmatic API Key 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 mongocli.toml configuration file 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 configuration file is stored in the /.config folder of your home directory. View the file using the cat command:

cat ~/.config/mongocli.toml

The command returns the contents of the configuration file, which contains a default profile that has a Programmatic API Key for an MongoDB Cloud Manager deployment.

[default]
private_api_key = "abcdef"
public_api_key = "d5199648-abcd-1234-efgh-3ed4396a3096"
service = "cloud-manager"
1

Create a profile.

Run the mongocli config command:

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

If you don’t specify a profile name, MongoDB CLI names this profile default.

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 Programmatic API Key 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 mongocli.toml configuration file 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 configuration file is stored in the /.config folder of your home directory. View the file using the cat command:

cat ~/.config/mongocli.toml

The command returns the contents of the configuration file, which contains a default profile that has a Programmatic API Key for an Ops Manager deployment.

[default]
private_api_key = "abcdef"
public_api_key = "d5199648-abcd-1234-efgh-3ed4396a3096"
service = "ops-manager"

Next Steps