Docs Menu

Embedded MongoDB Shellicons/link.png

On this page

  • Open the Embedded MongoDB Shell
  • Use the 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.

db.employees.find( { "last_name": "Smith" } )
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.

db.employees.aggregate( [ // press Shift + Enter
{ $match: { "last_name": "Smith" } } // press Shift + Enter
] ) // Press Enter
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
MongoDB logo
© 2021 MongoDB, Inc.


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