This chapter covers the core features and capabilities of MongoDB Operations Toolkit.
Backend engineers and DBAs who already use MongoDB and want correct, opinionated
patterns for the decisions that are easy to get wrong: embed vs. reference, the
ESR index rule, choosing a shard key you will not regret, reading an explain
plan, and taking a backup you can actually restore.
($setWindowFields, $densify, $merge) need 5.0+; $lookup on sharded
collections needs 5.1+. Where a feature needs a newer server, the doc says so.
mongosh (the modern shell — the legacy mongo shell is not supported).mongodump, mongorestore) on your PATH for the backupscripts. They ship separately from the server as mongodb-database-tools.
mongodb://127.0.0.1:27017; override with the MONGO_URI environment variable.
Hostnames such as
mongo-rs0-01.example.comare placeholders — replace themwith your own. No real infrastructure, addresses, or credentials appear
anywhere in this product.
Follow this guide to get MongoDB Operations Toolkit up and running in your environment.
# 1. Load the sample data so every example has something to query
mongosh "mongodb://127.0.0.1:27017/shop" examples/sample_schema.js
# 2. Build the indexes the queries rely on
mongosh "mongodb://127.0.0.1:27017/shop" scripts/create_indexes.js
# 3. Run the aggregation pipelines (sales rollups, RFM, funnel, top-N)
mongosh "mongodb://127.0.0.1:27017/shop" scripts/aggregation_pipelines.js
# 4. Turn on the profiler and inspect slow operations
mongosh "mongodb://127.0.0.1:27017/shop" scripts/profiling_queries.js
# 5. Check cluster health
mongosh "mongodb://127.0.0.1:27017" scripts/replica_set_status.js
mongosh "mongodb://127.0.0.1:27017" scripts/shard_status.js
# 6. Take a backup
bash shell/mongodump_backup.sh
# 7. (Optional) spin up a local 3-node replica set to practice against
bash shell/replica_set_init.shmongosh runs a script against a connection. Inside an interactive
shell you can instead load('scripts/aggregation_pipelines.js').
mongodb-operations-toolkit/
├── README.md This file
├── LICENSE MIT
├── config/
│ └── mongod.conf Annotated: WiredTiger cache, journal, profiler, repl, security
├── docs/
│ ├── schema-design-patterns.md Embed vs reference + 6 named patterns (subset, bucket, outlier, ...)
│ ├── indexing-guide.md Compound order (ESR), partial/TTL/text, covered queries, $regex traps
│ ├── replica-sets.md Elections, read/write concern, oplog sizing, lag, maintenance
│ ├── sharding.md Shard-key selection, hashed vs ranged, chunks, balancer, anti-patterns
│ ├── performance-profiling.md Profiler levels, explain() plans, the slow-query workflow
│ └── backup-and-restore.md mongodump/restore, filesystem snapshots, PITR, restore drills
├── scripts/
│ ├── create_indexes.js Index builders with rationale per index (ESR applied)
│ ├── aggregation_pipelines.js Six worked pipelines on the sample data
│ ├── profiling_queries.js Enable profiler, find slow ops, COLLSCANs, unused indexes
│ ├── replica_set_status.js Health, lag, oplog window, election readiness report
│ └── shard_status.js Shard distribution, chunk balance, jumbo-chunk check
├── shell/
│ ├── mongodump_backup.sh Timestamped dump + gzip + retention + restore note
│ └── replica_set_init.sh Bring up a local 3-node replica set for practice
└── examples/
├── sample_schema.js Creates collections + validators and inserts sample docs
└── sample_data.json The raw sample documents (orders, users, products, events)
Get the full MongoDB Operations Toolkit and unlock everything.
Get the complete guide with every chapter unlocked, including code samples, diagrams, and best practices.
Access all interactive tools with complete data, all workload profiles, and the full scenario library.
Downloadable source code, configuration files, and working examples from every chapter.
Free updates for life. Every new chapter, tool, and improvement included.