> ## Content Index
> Fetch the complete content index at: https://www.karls.io/llms.txt
> Use this file to discover other available public pages before exploring further.

# MongoDB Computed Pattern
- URL: https://www.karls.io/mongodb-computed-pattern/
- Published: 2022-08-22T14:47:36.000Z
- Updated: 2023-12-30T00:29:48.000Z
- Description: The Computed Pattern in NoSQL is utilized when we have data that needs to be computed repeatedly and optimise performance of our app, and is also used when data is reads exceeeds writes by significant amount.
- Author: Karl Scerbiakas
- Tags: MongoDB

The Computed Pattern in NoSQL is used to optimize the performance of our app by pre-calculating values that are frequently accessed. This is especially useful when the number of data reads exceeds the number of writes by a significant amount. 

 For example, if we have a list of blog posts with comments, each post has a comment count. Instead of querying the comment count for each post, we can recalculate it and store it in the blog post document. This way, we save database resources and only need to recalculate the comment count when a new comment is added or deleted. To listen for updates to the database, MongoDB offers change streams, or you can use the middleware support provided by your ODM/ORM.

 This pattern is useful for saving valuable database resources when frequently accessed calculations, such as view counts and averages, are needed.