MongoDB Patterns
MongoDB patterns covering schema design, embedding vs referencing, indexing, aggregation pipelines, and production best practices.
- Difficulty
- intermediate
- Read time
- 1 min read
- Version
- v1.0.0
- Confidence
- established
- Last updated
Quick Reference
MongoDB: Embed for 1:few relationships accessed together. Reference for 1:many, shared data, large/unbounded arrays. Avoid arrays >100 items. Index query patterns, not all fields. Use explain() to verify index usage. Aggregation $lookup is expensive - prefer embedding. Shard key choice is critical.
Use When
- MongoDB databases
- Document database design
- Schema flexibility needs
- Horizontal scaling requirements
Skip When
- Complex transactions required
- Heavy JOIN requirements
- Relational data models
MongoDB Patterns
MongoDB patterns covering schema design, embedding vs referencing, indexing, aggregation pipelines, and production best practices.