Question

Let's say I have two collections: "Movies" and "Reviews." Users write reviews about movies and assign each movie a review score from 0 to 10. I want to make a list of the top 20 movies, based on each movie's average review score. Does anyone know how to set up the publish/subscription code? It's giving me the blues now. Everything I've read suggests this is a weak area for Meteor, and I can't seem to find a comparable example.

Was it helpful?

Solution

The solution is to store the average review score directly in the Movies collection and update it when a new review is added. This can be achieved by storing the total review score and number of reviews, which lets you update the average without having to retrieve all of the other reviews.

OTHER TIPS

Update the average for a movie each time a review is posted and store that average in the movie document. It is more work at the time of creating the review, but querying the top 20 movies becomes trivial after that.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top