MongoDB CLI Configuration File¶
The MongoDB CLI configuration file stores your profiles. You can update the settings stored in your configuration file by editing the file with a text editor or by using the mongocli config set command.
Your API keys are like passwords. The configuration file stores API keys in plaintext, so ensure that you secure the configuration file appropriately.
Configuration File Location¶
The first time you run the mongocli config command, the
MongoDB CLI creates a configuration file called
MongoDB CLI grants the user who ran the command read and write access to
the file. The MongoDB CLI saves the configuration file to the folder where
the system stores application configuration files, which is defined by
$XDG_CONFIG_HOME environment variable. By default, this location
/.config folder of the user's home directory. If this folder
doesn't exist, the MongoDB CLI creates the folder and grants the user read,
write, and execute permissions.
The MongoDB CLI configuration file stores related settings and API keys in groups called profiles. You can create or define multiple profiles so that you can use the MongoDB CLI to access different MongoDB services or projects from the same terminal.
Any settings stored in envronment variables take precedence over settings stored in profiles.
To run MongoDB CLI with a specific profile, append the
<profileName> option to the command.
If you run a command without the
--profile option, the MongoDB CLI uses
the settings in the default profile. The MongoDB CLI determines the default
profile by the number of profiles you have configured:
- If you have only one profile, the MongoDB CLI uses that profile as the default.
- If you have multiple profiles, the MongoDB CLI uses the profile named
defaultas the default. If you don't have a profile named
defaultand run a command that requires certain settings, the MongoDB CLI returns an error for the missing settings.
The following example configuration file contains two profiles,
default profile connects to an Atlas deployment and contains
the following settings:
- An organization ID
- API keys
- A project ID
myOpsManager profile connects to an Ops Manager deployment and
contains the following settings:
- The Ops Manager base URL .
- An organization ID.
- API keys.
- A project ID.
- Optional The full path on your local system to the PEM-encoded Certificate Authority (CA) certificate used to sign the client and Ops Manager TLS certificates
- Optional Flag indicating whether the CA TLS certificate is verified.
# ~/.config/mongocli.toml [default] organization_id = "qwer5678uiop23jb45lk78mn" public_api_key = "ABCDEFG" project_id= "5e2f04ecf10fcd33c7d4077e" private_api_key = "e750d2bf-1234-4cde-5678-ca4dcbcac9a4" service = "cloud" [myOpsManager] ops_manager_ca_certificate = /etc/ssl/certs/ca.pem ops_manager_skip_verify = no ops_manager_url = "http://localhost:9080/" organization_id = "jklsa23123dsdf3jj456hs2" public_api_key = "HIJKLMN" project_id = "kk12jdn43jd123dkdkf97jg" private_api_key = "e750d2bf-9101-4cde-1121-ca4dcbcac9a5" service = "ops-manager"
To use MongoDB CLI with the
default profile, omit the
option from the command:
To use MongoDB CLI with the
myOpsManager profile, append the
--profile myOpsManager option to the command:
mongocli <command> --profile myOpsManager