Answer the question
In order to leave comments, you need to log in
(MVC) Should the sum be stored in the model?
In a Mongo database (JSON storage), the document contains an array of objects:
{
myArray: [{a: 1}, {a: 2}, {a: 3}, {a: 4}]
}
{
myArray: [{a: 1}, {a: 2}, {a: 3}, {a: 4}],
sum_a: 10
}
Answer the question
In order to leave comments, you need to log in
There is such a generally correct opinion that any task should be started with SQL and 3rd normal form, and only then, based on the load profile, carefully introduce denormalization and data duplication.
Since you already have Mongo, the advice is generally late, but still applicable here.
And if a lot of documents are retrieved, isn't it expensive to count the same thing every time?No one except you can measure this in a live project on a live task and compare it with the cost of updating while saving.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question