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, run the following command to enable autocomplete in your current shell:

% echo "autoload -U compinit; compinit" >> ~/.zshrc

To enable autocomplete for all future shell sessions:

    • If you use MacOS, run the following command:

      % mongocli completion zsh > /usr/local/share/zsh/site-functions/_mongocli
    • If you use Linux, run the following command:

      % mongocli completion zsh > "${fpath[1]}/_mongocli"
  1. Start a new shell for the setup to take effect.

If you use Bash to run the MongoDB CLI, install the bash-completion package via your OS's package manager. Then, run the following command to enable autocomplete in your current shell:

$ source <(mongocli completion bash)

To enable autocomplete for all future shell sessions:

    • If you use MacOS, run the following command:

      $ mongocli completion bash > /usr/local/etc/bash_completion.d/mongocli
    • If you use Linux, run the following command:

      $ mongocli completion bash > /etc/bash_completion.d/mongocli
  1. Start a new shell for the setup to take effect.

If you use fish to run the MongoDB CLI, run the following command to enable autocomplete in your current shell:

> mongocli completion fish | source

To enable autocomplete for all future shell sessions:

  1. Run the following command:

    > mongocli completion fish > ~/.config/fish/completions/mongocli.fish
  2. Start a new shell for the setup to take effect.

If you use PowerShell to run the MongoDB CLI, run the following command to enable autocomplete in your current shell:

PS C:\> mongocli completion powershell | Out-String | Invoke-Expression

To enable autocomplete for all future shells, add the output of the above command to your PowerShell profile. To learn how to edit a PowerShell profile, see Windows Documentation.

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