Docs Menu

Docs HomeLaunch & Manage MongoDBMongoDB CLI

Environment Variables

On this page

  • Precedence
  • Supported Environment Variables

For easier scripting, you can specify configuration settings by using environment variables.

  • When you run a command, any settings that you specified with environment variables take precedence over the profile stored in the configuration file.

  • When you run a command using the --projectId option, the command line option takes precedence over both the environment variable and the profile stored in the configuration file.

The MongoDB CLI supports the following environment variables:

Variable
Description
MCLI_PUBLIC_API_KEY
Sets the public API key for commands that interact with your MongoDB service.
MCLI_PRIVATE_API_KEY
Sets the private API key for commands that interact with your MongoDB service.
MCLI_ORG_ID
Sets the organization ID for commands that require the --orgId option.
MCLI_PROJECT_ID
Sets the project ID for commands that require the --projectId option.
MCLI_OPS_MANAGER_URL
For Ops Manager only, sets the base URL for API calls. The URL must end with a forward slash (i.e. /).
MCLI_SERVICE

Sets the MongoDB service type. Valid values are:

Value
Service
cloud
default

MongoDB Atlas

cloudgov
cloud-manager
ops-manager
MCLI_OUTPUT

Sets the output fields and format. Valid values are:

Value
Output Format
Empty
default
Human-readable output that includes all fields that MongoDB CLI returns.
json
JSON output that includes all fields that MongoDB CLI returns.
json-path
JSON output that includes the fields that you specify.
go-template
Custom-formatted output that includes the fields that you specify in a Go template.
MCLI_MONGOSH_PATH
The full path on your local system to the MongoDB Shell, mongosh.
MCLI_SKIP_UPDATE_CHECK
When set to yes, the MongoDB CLI does not prompt you to update to new versions.
MCLI_OPS_MANAGER_CA_CERTIFICATE
Ops Manager only
If applicable, 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.
MCLI_OPS_MANAGER_SKIP_VERIFY
Ops Manager only

When set to yes, the MCLI_OPS_MANAGER_CA_CERTIFICATE TLS certificate is not verified. This prevents your connections from being rejected due to an invalid certificate.

Important

Setting MCLI_OPS_MANAGER_SKIP_VERIFY to yes is insecure and is not recommended in production environments.

HTTP_PROXY, http_proxy

The absolute URL or the hostname and port in the hostname[:port] format.

Example

The following example shows how to set up the environment variable if your proxy configuration doesn't require authentication.

HTTP_PROXY=<my.proxy.address>

The following example shows how to set up the environment variable if your proxy configuration requires authentication.

HTTP_PROXY=username:password@<my.proxy.address>

The following example shows how to set up the environment variable if the scheme is socks5.

HTTP_PROXY=socks5://<my.proxy.address>
HTTPS_PROXY, https_proxy

The absolute URL. If HTTP_PROXY is also set, this takes precedence over HTTP_PROXY for all requests.

Example

The following example shows how to set up the environment variable.

HTTPS_PROXY=https://<my.proxy.address>
NO_PROXY, no_proxy
Indicates no proxy for the URL because proxy isn't configured for the URL.
←  MongoDB CLI Configuration FileEnable Autocomplete for the MongoDB CLI →