MongoDB Operations Toolkit
Schema design patterns, aggregation pipelines, sharding strategies, backup scripts, and monitoring dashboards.
📄 Product Preview
Try the interactive reader and demo tools below, or get the full product with all content unlocked.
📖 Interactive Reader (Free Preview) ⚙ Try Demo Tools 📦 Download Free Sample📁 File Structure 24 files
📖 Documentation Preview README excerpt
MongoDB Operations Toolkit
A hands-on toolkit for running MongoDB well: schema design that matches how you
query, indexes that the planner actually uses, aggregation pipelines that read
clearly, plus the replica-set, sharding, profiling, and backup operations you
need day to day.
Everything here is runnable, not slideware:
mongoshscripts (scripts/*.js) you canload()or pipe straight into a
shell — real index builders, aggregation pipelines, profiler queries, and
replica-set / shard status reports.
- Shell scripts (
shell/*.sh) formongodumpbackups (with PITR notes) and
bringing up a local replica set to practice against.
- An annotated
mongod.confthat explains every block — WiredTiger cache,
journaling, the profiler, replication, and the security settings you must not
skip.
- Sample data + schema (
examples/) so every pipeline and index in the docs
runs against concrete documents.
Who this is for
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.
Prerequisites
- MongoDB 6.0+ (7.0 recommended). The aggregation stages used here
($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 legacymongoshell is not supported).- Database Tools (
mongodump,mongorestore) on yourPATHfor the backup
scripts. They ship separately from the server as mongodb-database-tools.
- A MongoDB you can connect to. Scripts default to
mongodb://127.0.0.1:27017; override with the MONGO_URI environment variable.
Hostnames such as mongo-rs0-01.example.com are placeholders — replace them
with your own. No real infrastructure, addresses, or credentials appear
anywhere in this product.
How to run
# 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
*... continues with setup instructions, usage examples, and more.*