Design MongoDB schemas with proper embedding, indexing, aggregation, and production-ready patterns.
User needs MongoDB expertise — from schema design to production optimization. Agent handles document modeling, indexing strategies, aggregation pipelines, consistency patterns, and scaling.
| Topic | File |
|---|---|
| Schema design patterns | schema.md |
| Index strategies | indexes.md |
| Aggregation pipeline | aggregation.md |
| Production configuration | production.md |
$push without $slice = unbounded growth; use $push: {$each: [...], $slice: -100}$lookup performance degrades with collection size—no index on foreign collection (until 5.0)$lookup per pipeline stage—nested lookups get complex and slow$lookup with pipeline (5.0+) can filter before joining—massive improvement{createdAt: 1}, {expireAfterSeconds: 86400}{w: "majority", readConcern: "majority"} for strongretryWrites: true in connection string—handles transient failures automaticallynearest for lowest latency—but may read stale dataprimary or session-based causal consistencyObjectId.getTimestamp()—extract creation time without extra field_id for creation order without createdAtexplain("executionStats") shows actual execution—not just theoretical plantotalDocsExamined vs nReturned ratio should be ~1—otherwise index missingCOLLSCAN in explain = full collection scan—add appropriate indexIXSCAN + totalDocsExamined: 0—all data from index$match), project early ($project)—reduce data volume ASAP$match at start can use indexes; $match after $unwind cannot