0PricingLogin
MongoDB Academy · Lesson

The Bucket and Computed Patterns

Learners will group time series data into bucket documents to reduce index size and pre-compute aggregated values to avoid expensive real-time calculations.

Introduction to Schema Design Patterns

Expert MongoDB engineers do not design schemas by instinct — they reach for a library of proven patterns that solve recurring challenges. These patterns encode hard-won lessons about how MongoDB's storage engine, index structure, and aggregation pipeline interact with different document shapes. The Bucket Pattern and Computed Pattern are two of the most impactful for performance-sensitive applications.

The Problem: Too Many Small Documents

Consider an IoT system where each sensor reading is a separate document. A sensor producing one reading per second generates 86,400 documents per day. This means 86,400 index entries per sensor per day, enormous index sizes, and a huge number of operations when querying a day's data. Reading 24 hours of data requires fetching tens of thousands of tiny documents — very inefficient.

// Anti-pattern: one document per reading
{
  _id: ObjectId(),
  sensorId: 'sensor-42',
  timestamp: ISODate('2024-06-01T10:00:01Z'),
  temperature: 23.1
}
// 86,400 such documents per sensor per day
// 86,400 index entries per sensor per day

All lessons in this course

  1. The Bucket and Computed Patterns
  2. The Extended Reference and Subset Patterns
  3. The Polymorphic and Schema Versioning Patterns
  4. The Outlier and Tree Structure Patterns
← Back to MongoDB Academy