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.

有帮助吗?

解决方案

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.

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top