Navigation

    Embedded MongoDB Shell

    Starting in version 1.22, MongoDB Compass contains an embedded MongoDB Shell. 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.

    To open the embedded MongoDB Shell, click MongoSH Beta along the bottom of MongoDB Compass.

    When you initially open the MongoDB Shell, it connects to the test database. To switch to a different database, run the following command in the MongoDB Shell:

    use <database name>

    To run an operation in the embedded MongoDB Shell, type the operation into the shell and press Enter.

    Beaker IconExample
    db.employees.find( { "last_name": "Smith" } )
    Bulb IconTip
    See Also:

    To write an operation that spans multiple lines in the embedded MongoDB Shell, press Shift + Enter to begin the next line of code.

    When you are finished writing your operation, press Enter to run it.

    Beaker IconExample
    db.employees.aggregate( [ // press Shift + Enter
    { $match: { "last_name": "Smith" } } // press Shift + Enter
    ] ) // Press Enter
    Bulb IconTip
    See Also:

    The following links direct to the MongoDB Shell Documentation, which contains more complete reference for the MongoDB Shell, including syntax and behaviors.

    Give Feedback