Text of mongodb.com › docs › compass › embedded-shell as Styx crawled it on Nov 19, 2026. The page may have changed since. Only its words are kept, without pictures or layout.

Open the live page

Embedded MongoDB Shell - Compass - MongoDB Docs

For AI agents: a documentation index is available at https://www.mongodb.com/docs/llms.txt — markdown versions of all pages are available by appending .md to any URL path. Embedded MongoDB Shell MongoDB Compass Readonly Edition will be deprecated in a future release. To replicate the read-only behavior in a standard Compass edition, assign users read access at the database level and enable the readOnly option in Compass.

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. Open the Embedded MongoDB Shell To open the embedded mongosh ,you can either: Click >_ on the right of your deployment name in the Connections Sidebar . Click >_Open MongoDB shell in the top right of any tab connected to a MongoDB deployment.

Use the Embedded MongoDB Shell 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" } ) Multi-Line Operations in the Embedded MongoDB Shell 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 Disable the Embedded MongoDB Shell You can disable the embedded MongoDB shell in Compass to avoid running unauthorized commands on mongosh .

To disable the embedded MongoDB shell: 1 In the Compass top menu bar, click MongoDB Compass . 2 In the MongoDB Compass menu, click Settings . Compass opens a dialog box where you configure your MongoDB Compass settings. 3 Toggle Enable MongoDB Shell . If you select Set Read-Only Mode , Compass automatically unchecks the Enable MongoDB Shell setting. 4 Click Save . Learn More The following links direct to the mongosh documentation , which contains more a complete reference for mongosh , including syntax and behaviors.

Learn how to perform CRUD operations in mongosh . Learn how to run aggregation pipelines in mongosh . See a complete list of mongosh methods. Back Import Diagram Next Create an Aggregation Pipeline Rate this page On this page Open the Embedded MongoDB Shell Use the Embedded MongoDB Shell Disable the Embedded MongoDB Shell On this page Open the Embedded MongoDB Shell Use the Embedded MongoDB Shell Disable the Embedded MongoDB Shell