What are common design patterns in MongoDB schema architecture?
Specialized schema patterns address specific performance and scaling needs in MongoDB:
• Subset Pattern: Embeds the top 5-10 most frequent items (e.g. recent reviews) in the main document to satisfy 90% of views, while storing the full history in a secondary collection. • Bucket Pattern: Groups time-series or sensor data into aggregated document chunks rather than creating one document per millisecond reading. • Computed Pattern: Pre-computes rollups (e.g., total sales, average rating) on write, avoiding expensive runtime aggregation on read.
// Subset Pattern: Main movie document holds top 3 recent reviews
{
"_id": ObjectId("..."),
"title": "Inception",
"director": "Christopher Nolan",
"recentReviews": [
{ "user": "Mark", "rating": 5, "comment": "Brilliant movie!" },
{ "user": "Sarah", "rating": 4, "comment": "Mind bending." }
],
"totalReviewsCount": 15420
}The Subset pattern drastically reduces network transfer size by serving the first page of reviews immediately from the parent document without extra queries.
Ready for Atlas & Cloud Basics?
Take a quick test to evaluate yourself, or move straight to the next module.