home / databases / mongosh

MongoDB Shell

Official · MongoDB
383

Official MongoDB shell for querying, scripting, and administering MongoDB deployments from the terminal.

$npx mongosh
Language
TypeScript
Stars
383
Category
Databases
Agent
Ready
Agent Compatibility
JSON Output
Agent Skill
MCP Support
AI Analysis

Mongosh is MongoDB's official shell for connecting to databases, running JavaScript against the MongoDB Shell API, and working interactively or from scripts. It covers both everyday data inspection and server-side admin tasks from one terminal entry point.

What It Enables
  • Connect to local or remote MongoDB deployments and run collection queries, CRUD operations, and aggregation pipelines through db and collection APIs.
  • Execute repeatable .js files or one-off --eval snippets for data checks, maintenance tasks, migrations, or smoke tests with connection, auth, TLS, and API-version flags on the same command.
  • Inspect or administer replica set and sharding state through built-in helpers such as rs and sh, including status, balancing, and topology-related operations.
Agent Fit
  • --eval plus --json[=canonical|relaxed] gives machine-readable Extended JSON results and serialized errors, which is useful for inspect and verify steps.
  • Automation is less uniform than in subcommand-driven CLIs: structured output is limited to --eval, while file execution and REPL output stay human-oriented unless your script prints its own machine-readable data.
  • Best fit when an agent can generate or reuse Mongo shell JavaScript for database workflows; less ideal when you want narrow verbs and consistent JSON on every path.
Caveats
  • Useful work requires a reachable MongoDB deployment plus the right credentials, and some auth flows can still prompt interactively.
  • This is a programmable shell rather than a small set of fixed commands, so safety and repeatability depend heavily on the script you run.