MongoDB — modeling, indexing, aggregation, transactions, ops
Engine-level MongoDB 8.2 guidance: model documents for the queries you actually run, pick the
index the planner will use, write aggregation pipelines that stay index-eligible, run
multi-document transactions with correct retry, and operate/secure a deployment. Driver-agnostic —
every example is mongosh shell syntax that maps 1:1 to the official drivers (Node, Python, Go,
Java, Rust). This skill owns the server's query and the index it picks, not any ODM's API.
When to use / When NOT to use
When to use:
- Document modeling: embed vs reference, the 16 MB cap, one-to-many/many-to-many, the
subset/extended-reference/bucket/computed/outlier patterns, taming unbounded array growth.
- Index decisions: single-field, compound (the ESR ordering rule), multikey, partial, TTL, text,
wildcard, 2dsphere; and when an index is NOT worth it.
- Any query that is slow or scans too much; reading
explain("executionStats"). - Aggregation pipelines: stage order so
$match/$sorthit an index,$lookupcost,$unwind
explosion, $group/$sort memory limits and allowDiskUse, $merge/$out, faceting.
- Multi-document transactions: sessions,
withTransactionretry semantics, read/write concern. - Operating/securing: replica set, read preference, write concern, Atlas tier choice, Atlas Search
& Vector Search, Queryable Encryption, role-based access, connection-pool knobs.
When NOT to use: