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.
Open the Embedded MongoDB Shell¶
To open the embedded MongoDB Shell, click MongoSH Beta along the bottom of MongoDB Compass.
Use the Embedded MongoDB Shell¶
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" } )
Multi-Line Operations in the Embedded MongoDB Shell¶
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
Learn More¶
The following links direct to the MongoDB Shell Documentation, which contains more complete reference for the MongoDB Shell, including syntax and behaviors.
- Learn how to Perform CRUD Operations in the MongoDB Shell.
- Learn how to Run Aggregation Pipelines in the MongoDB Shell.
- See a complete list of Available MongoDB Shell Methods.