MongoDB CLI Configuration File
On this page
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.
Important
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 mongocli.toml
. The
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
the $XDG_CONFIG_HOME
environment variable. By default, this location
is the /.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.
Profiles
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.
Note
Any settings stored in envronment variables take precedence over settings stored in profiles.
To run MongoDB CLI with a specific profile, append the --profile
<profileName>
option to the command.
Default Profile
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
default
as the default. If you don't have a profile nameddefault
and run a command that requires certain settings, the MongoDB CLI returns an error for the missing settings.
Example
The following example configuration file contains the path to the
MongoDB Shell, mongosh
, and two profiles, default
and
myOpsManager
.
The default
profile connects to an Atlas deployment and contains
the following settings:
An organization ID
API keys
A project ID
The 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 mongosh_path = "/usr/local/bin/mongosh" [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 --profile
option from the command:
mongocli <command>
To use MongoDB CLI with the myOpsManager
profile, append the
--profile myOpsManager
option to the command:
mongocli <command> --profile myOpsManager