Couchbase pdf example stores reviews avg in one document

Hello,

I seen the PDF from couchbase “DATABASE DESIGN FOR RETAIL AND INVENTORY”

and saw there was a book document and instead to calculate the avg reviews in the reviews table they store it in the book document but how they do it to calculate ? So then I have everytime make a transaction for this book document when a review was inserted is this not bad ?

rat

It depends. If you compute the average when a review is being added, and it is read only once, then the average has been computed 100 times more than necessary. But a more normal case would be like an product on Amazon - for 100 reviews to be added, and the average being read thousands of times as users are browsing.

I only would do this for fastet query results because when you have10k Reviews only on one product and you want to Show 150 Products and count all Reviews and Compute the average it is of Course Slower then or what you Think ?

The example has the average computed and stored whenever the reviews are modified because it makes for faster queries. If you wish to compute the average review every time, then you can do that instead.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.