Docs Menu

Docs HomeMongoDB Compass

Embedded MongoDB Shell

On this page

  • Open the Embedded MongoDB Shell
  • Use the Embedded MongoDB Shell

Starting in version 1.22, MongoDB Compass contains an embedded shell, mongosh. mongosh is a JavaScript environment for interacting with MongoDB deployments. You can use mongosh to test queries and operations in your database.

To open the embedded mongosh, click _MONGOSH at the bottom of the MongoDB Compass window.

By default, mongosh, connects to the test database. To use a different database, run the following command in mongosh

use <database name>

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

The following example runs a db.collection.find() operation:

Example

db.employees.find( { "last_name": "Smith" } )

To write an operation that spans multiple lines in the embedded mongosh, begin with the first line, then press Shift + Enter to move to the next line of code.

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

The following multi-line example runs the $match stage in an aggregation pipeline:

Example

db.employees.aggregate( [ // press Shift + Enter
{ $match: { "last_name": "Smith" } } // press Shift + Enter
] ) // Press Enter

The following links direct to the mongosh documentation, which contains more a complete reference for mongosh, including syntax and behaviors.

←  Import and Export DataAggregation Pipeline Builder →
Give Feedback
© 2022 MongoDB, Inc.

About

  • Careers
  • Investor Relations
  • Legal Notices
  • Privacy Notices
  • Security Information
  • Trust Center
© 2022 MongoDB, Inc.