Docs Menu
Docs Home
/ /
MongoDB Command Line Interface
/

Enable Autocomplete for the MongoDB CLI

On this page

  • Enable Autocomplete
  • Use Tab to Autocomplete Commands

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

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.

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

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

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.

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:

accessLists -- Manage the IP access list for your project.
accessLogs -- Manage the access logs of a cluster.
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.

Back

Environment Variables