Directory Compare FCRS-1.0 /llms.txt
← Back to Directory

MongoDB Shell (mongosh)

$ mongosh Official High Risk
MongoDB · Database & Data · Apache-2.0 · macos / linux / windows

mongosh is the modern Node.js-based MongoDB shell replacing legacy mongo. For AI agents, --quiet combined with --eval "EJSON.stringify(...)" or --json=canonical executes queries cleanly and exits without entering the interactive REPL.

FCRS-1.0 Score
82 /100
Good
Medium Confidence
Zero-Friction Install
brew install mongosh
CLI vs MCP Decision Hybrid (CLI + MCP)

mongosh --quiet --json=canonical --eval is great for deterministic shell scripts and migrations; MongoDB's official MCP server helps when exploring unfamiliar collections.

Agent-Readiness Checklist

✓ JSON Output
— Field Filtering
✓ Non-Interactive
— Dry-Run
— Read-Only Mode
— NO_COLOR Clean
✓ Self-Describing
— Official SKILL.md

Static evaluation (not yet probed on this host). Run npm run data:probe locally to capture live verification.

FCRS-1.0 6-Dimension Breakdown

Agent-Readiness 21 / 25

--quiet, --json=canonical/relaxed, and --eval enable clean JSON output and one-shot execution.

  • Supports --quiet, --eval, and --json=canonical / --json=relaxed
Trust & Safety 19 / 25

Read/write safety depends on MongoDB connection user roles (readPreference=secondary etc.); --eval runs arbitrary JS.

  • No client-side --readonly flag; relies on MongoDB RBAC user permissions
Setup & Portability 13 / 15

Standalone binary packaged via Homebrew, apt/yum, and downloads for macOS, Linux, and Windows.

  • Cross-platform standalone mongosh distribution
Utility & Efficiency 13 / 15

Full JavaScript/MongoDB shell expression power in a single CLI command.

  • Supports aggregation pipelines, EJSON, and admin helpers
Maintenance & Lineage 9 / 10

Official mongodb-js/mongosh maintained by MongoDB under Apache-2.0.

  • Official mongodb-js/mongosh repository
Docs & Verifiability 7 / 10

Comprehensive official documentation with flag reference.

  • Official docs at mongodb.com/docs/mongodb-shell

Security, Auth & Guardrails

Auth Modes
Env API Key Config File
Credential Storage

Connection string URI passed via $MONGODB_URI or --username / --password flags.

Side Effects
Read-Only Remote Write Destructive
Cost & Quotas

100% free and Apache-2.0 open-source.

Copyable Guardrail for CLAUDE.md / AGENTS.md
# mongosh Agent Rules
- Always pass `--quiet` and `--eval "<js>"` (never start interactive `mongosh`).
- Always attach `.limit(...)` to `find()` queries and prefer `--json=canonical` or `EJSON.stringify(...)`.
- NEVER run `drop()`, `dropDatabase()`, or `deleteMany({})` without explicit approval.

Agent-Ready Command Recipes

Safe Read-Only Queries

List collections in JSON via --eval
mongosh "$MONGODB_URI" --quiet --json=canonical --eval "db.getCollectionNames()"

Lists database collections cleanly as canonical Extended JSON without banner noise.

Sample documents with limit and projection
mongosh "$MONGODB_URI" --quiet --eval "EJSON.stringify(db.users.find({}, {passwordHash: 0}).limit(5).toArray())"

Fetches a bounded sample while omitting sensitive fields.

Strengths for Agents

  • + --quiet --json=canonical --eval suppresses startup banners and outputs strict Extended JSON.
  • + Supports full MongoDB aggregation pipelines and EJSON helpers inline.
  • + Cleanly replaces the deprecated mongo shell.

Caveats & Pitfalls

  • ! Bundled Node.js runtime gives mongosh noticeable cold-start latency (~0.5–1s).
  • ! No client-side --readonly flag; use a read-only database user for agent queries.

Tested Agent Hosts

Claude Code Codex CLI Gemini CLI