Navigation

Enable Autocomplete for the MongoDB CLI

You can enable autocomplete for MongoDB CLI commands to see available commands and their syntax directly in your shell.

Enable Autocomplete

If you installed the MongoDB CLI with Homebrew, autocomplete functionality is included with the installation. You must configure your shell to enable its completion support. To enable autocomplete for your shell, refer to the Homebrew Documentation.

If you did not install the MongoDB CLI with Homebrew, the procedure to enable autocomplete depends on the shell in which you run the MongoDB CLI.

Z Shell

If you use zsh to run the MongoDB CLI, add the following to your ~/.zshrc:

autoload -Uz compinit
compinit

source <(mongocli completion zsh)
compdef _mongocli mongocli

Run the following command to reload your zsh profile:

source ~/.zshrc

Bash

If you use Bash to run the MongoDB CLI, add the following to your ~/.bash_profile:

eval "$(mongocli completion bash)"

Run the following command to reload your Bash profile:

source ~/.bash_profile

Use Tab to Autocomplete Commands

Once you have autocomplete configured, you can autocomplete commands by typing mongocli in your shell and pressing the Tab key. Press Tab multiple times to cycle through available autocompletion options.

You can press Tab at any stage of writing your command to see available autocomplete options.

Examples

When you type mongocli in your shell and press Tab, the output resembles the following:

atlas          -- Atlas operations.
cloud-manager  -- Cloud Manager operations.
completion     -- Generate shell completion scripts
config         -- Configure a profile to store access settings for your MongoDB deployment.
help           -- Help about any command
iam            -- Organization and projects operations.
ops-manager    -- Ops Manager operations.

If you type a specific property such as atlas as part of your command, you can see autocompletion options for your selected property.

For example, when you type mongocli atlas in your shell and press Tab, the output resembles the following:

alerts     -- Manage alerts for your project.
backups    -- Manage backups for your project.
clusters   -- Manage clusters for your project.
dbusers    -- Manage database users for your project.
events     -- Manage events for your project.
logs       -- Download host logs for your project.
metrics    -- Get measurements on the state of the MongoDB process.
processes  -- Manage MongoDB processes for your project.
whitelist  -- Manage the IP whitelist for a project.