Navigation

    MongoDB Shell

    Beta

    MongoDB Shell is currently available as a Beta release. The product, its features, and the corresponding documentation may change during the Beta stage.

    The MongoDB Shell is a fully functional JavaScript environment for interacting with MongoDB deployments. You can use the MongoDB Shell to test queries and operations directly with your database.

    The MongoDB Shell is available as a standalone package in the MongoDB download center.

    Download and Install the MongoDB Shell

    To learn how to download and install the MongoDB Shell, see Install the MongoDB Shell.

    Connect to a MongoDB Deployment

    Once you have installed the MongoDB Shell and added it to you system PATH, you can connect to a MongoDB deployment. To learn more, see Connect to a Deployment.

    MongoDB Shell Editor Mode

    Run the .editor command within the MongoDB Shell to open the editor and manage comprehensive multiline functions:

    example

    Run the following command within the MongoDB Shell:

    .editor

    The MongoDB Shell enters editor mode:

    // Entering editor mode (^D to finish, ^C to cancel)
    const { Writable } = require('stream');
    
      const myWritable = new Writable({
        write(chunk, encoding, callback) {
          // ...
        },
        writev(chunks, callback) {
          // ...
        }
      });
    • Press Cmd/Ctrl + d to finish and run your function.
    • Press Cmd/Ctrl + c to cancel and exit without running your function.

    When you close the editor, the MongoDB Shell does not save any functions you had entered into the editor.

    The MongoDB Shell versus the Legacy mongo Shell

    The MongoDB Shell offers numerous advantages over the legacy mongo shell, such as:

    • Improved syntax highlighting.
    • Improved command history.
    • Improved logging.

    During the beta stage, the MongoDB Shell supports a subset of the legacy mongo shell commands. Extending the MongoDB Shell API coverage is an ongoing effort.

    The commands that the MongoDB Shell supports use the same syntax as the corresponding commands in the legacy mongo shell.

    Learn More