1.The six patterns, worked in detail
Subset keeps only a needed slice of a large sub-document embedded. Bucket groups many small readings into fewer per-interval documents. Extended reference copies a few fields to skip a $lookup. Computed stores a value instead of recalculating it. Attribute turns sparse fields into a queryable array. Outlier handles the rare oversized document separately.
Key features
- Subset: embed only the N most-needed sub-items (e.g. 10 latest reviews), reference the rest
- Bucket: group readings by interval (e.g. one document per sensor per hour) instead of one document per reading
- Extended reference: copy a few stable, frequently-needed fields onto the referencing document
- Computed: store a derived value and update it incrementally, instead of recalculating on every read
- Attribute: move sparse or varying fields into a { k, v } array so one index covers all of them
- Outlier: detect and handle the rare huge document (a celebrity account, a viral post) as a special case
Pattern → symptom it targets → what changes
- measured symptom — e.g. slow read, huge working set
- matching pattern — one of the six
- targeted fix — not a general rewrite
Command
// Each pattern is applied to the specific collection/field showing the symptom — not adopted project-wideSubset, bucket, extended reference, computed, attribute, outlier — six patterns, each targeting one specific, measurable symptom. Apply one at a time, against a measured cost, not speculatively.