M320: Chapter 4: Patterns Part 2

MongoDB Data Modeling: Patterns Part 2

Computed Pattern

Use this pattern if you need to compute similar computations many times.

  • Math operations
  • Fan out operations
  • Roll-up operations

Roll Up Ops

Which one of the following scenarios is best suited for the application of the Computed Pattern?

We need to calculate a value that is displayed 100 times a minute and is based on a field which updates once a minute.

Lab: Apply the Computed Pattern

Result

{
  "_id": ObjectId("5c9414f25e6aff2b8870a2d0"),
  "zone": 13,
  "date": ISODate("2019-03-21T00:00:00.000Z"),
  "kW per day": {
    "consumption": 9756,
    "self-produced": 2059,
    "city-supplemented": 7700
  }
}

Bucket Pattern(used in IoT)

Which one of the following requirements in our system is the best candidate to use the Bucket Pattern?

Schema Versioning Pattern

Avoid downtime while performing schema upgrades.

Tree Patterns

  • Company Organization Chars
  • Books Subjects
  • Categories of a Shop

Model Tree Structures

  • Parent References
  • Child References
  • Array of Ancestors
  • Materialized Paths

Ancestor Array + Parent Model

Polymorphic Pattern

Single View solution

Which one of the following scenarios is best suited for the use of the Polymorphic Pattern? The organization acquired different companies over the years, serving the same markets with the same customers and there is a requirement to merge all systems into one.

Other Patterns

  • Approximation Pattern
    • avoiding performing an operation too often
  • Outlier Pattern
    • keeping the focus on the most frequent use cases

This can be used for track page views

Summary of Patterns