Skip to content
Advertisement

mongoose aggregate model based on filter

I have a model of Review which has the field product and rating

I would like to find the sum of all ratings of a specified product and find the average by dividing by 5.

JavaScript

how would I aggregate through all ratings and filter by product to find the sum?

Advertisement

Answer

I’m assuming your using nodejs , here is how I would go about doing this

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement