Sefism is free for learners. We are here to help you grow, one step at a time.Join for free
Sefism.
Tool · Web DevelopmentFree

MongoDB Shell (mongosh)

mongosh is MongoDB's official command line shell: a JavaScript and Node.js REPL for running queries, aggregation pipelines and admin commands against a local or Atlas database. It is the fastest way to try a query before putting it in code, and the syntax most MongoDB docs and tutorials use. Free and open source.

GitHub stars

403 (mongodb-js/mongosh)

GitHub · Sept 2026

Latest release

2.12.0 (September 2026)

GitHub · Sept 2026

Licence

Apache 2.0

GitHub · Sept 2026

Format

Tool

Topic

Web Development

Provider

MongoDB

Time needed

Installed in minutes, used daily

Level

All

Access

Free

What mongosh is

The MongoDB Shell, mongosh, is described by MongoDB as "a JavaScript and Node.js REPL environment for interacting with MongoDB deployments in Atlas, locally, or on another remote host". You connect with a connection string and then type commands such as db.orders.find({ status: "paid" }) or db.orders.aggregate([...]) and see the results immediately.

It replaced the legacy mongo shell, which was removed from the server download in MongoDB 6.0. If an old tutorial tells you to run mongo, use mongosh instead; most commands carry over.

Why learn it before a GUI or a driver

Almost every page of the MongoDB Manual, and most answers you will find online, show queries in shell syntax. If you can run and adjust those queries in mongosh, you can learn from any of them. It is also the quickest feedback loop there is: try a filter, look at the output, add a projection, run .explain("executionStats") to see whether an index was used, then copy the working query into your application.

Because it is a real JavaScript environment, you can use variables, loops and functions, which makes it handy for small data fixes and seeding test data.

What you can do with it

  • Connect to a local server, a replica set or an Atlas cluster with a connection string.
  • Run CRUD operations and aggregation pipelines.
  • Create and inspect indexes, and read query plans.
  • Manage users, roles, replication and sharding if you administer a deployment.
  • Write scripts that run in the shell for repeatable tasks, and store your own helper functions in a .mongoshrc.js config file.
  • Use the built-in or an external editor for multi-line commands, and look back through session logs.

Installing it

Official builds are available for Windows (MSI installer), macOS and Linux, and macOS users can also install it with Homebrew (brew install mongosh). MongoDB notes that the Homebrew build does not carry every guarantee of the official builds, for example automatic client-side field level encryption. mongosh is also embedded inside MongoDB Compass, so if you already use Compass you have a shell one click away.

Common questions

Do I need to know JavaScript? Only a little. Queries are JSON-like objects, and you will pick up the rest as you go.

Is it the same as the Node.js driver? No, but it is close. The shell runs on Node.js and its methods resemble the driver's, so moving a query from mongosh into a Node.js app is mostly copying and adding await.

Is it free? Yes. It is open source under the Apache 2.0 licence.

Best for: everyone learning MongoDB. Keep a shell open while you read the manual and run every example yourself.

databasebackendopen sourcebeginner friendly

Ready to start?

Opens on MongoDB in a new tab.

Open resource
Link broken or out of date?

Report a problem

With "MongoDB Shell (mongosh)". Only Tauseef reads this.

Work with me

Stuck on something specific?

Writing only gets you so far. If you want an answer to your situation rather than the general case, book a session and we will work through it together. Sessions are free for approved Sefism members, and a few slots open each week.