Conclusion / Learn

Video Transcript (English)

Congratulations! You have now completed the third and final phase of our data modeling methodology: applying schema design patterns.

In this phase, you used knowledge gained from identifying the workload and relationships in the bookstore app.

You then examined foundational schema design patterns and learned how to apply them.

We started with an introduction to the inheritance pattern, which allows us to store data that has common fields and substantial differences in the same collection, much like the different types of books in the book collection.

To apply the inheritance pattern, we created a product_type field which identified the book type of each document in the books collection.

Next, we discussed the computed pattern, which allows us to perform computations efficiently, by running operations when data changes and storing results for quick read access.

We saw how this pattern enabled us to accurately calculate the average star rating of a book and how it could help create roll ups with business information for our internal stakeholders.

While the computed pattern allows us to avoid performing repeated computations, the approximation pattern enables us to find numbers that are statistically valid but not exact when working with big data.

We found this would be appropriate to apply when generating an average star rating for a book with a large number of reviews.

This leads to huge performance gains and reduced resource usage.

Next, the extended reference pattern showed us how to embed data from other documents into the main document to minimize joins or lookup operations.

In this case, we embedded book and user information into review documents.

When using this pattern, remember that it's best to bring only the fields you need and to use fields that do not change often.

We should also have a strategy for updating extended references when the source data changes.

Here’s a hint: MongoDB Change Streams and MongoDB Atlas Triggers.

And finally, you learned about the schema versioning pattern, which enables you to modify your schema without application downtime.

In our example, we updated the schema of the users collection and discussed a migration plan.

These foundational schema design patterns will provide a common language for you and your teams.

They’ll also allow you to model your data in MongoDB and improve the performance of your applications.

If you'd like to learn more, you can review MongoDB’s documentation and check out the other seven foundational patterns in the MongoDB blog series “Building with Patterns: A Summary”.

Until next time. Keep building.