I am working on an app which has a ratings system, where one set of users can rate a set of players on a per match basis.
I want to be able to aggregate the data from all the users on a per match basis coupled with long term averages for each player.
I am struggling to work out the best way to model this using MongoDB. I have come up with the following solution.
For the averages on a per match basis:
I would have two fields for each player sub document within a match document consisting of
totalNumberOfRatings. These would be updated each time a user submits a rating for a player using the
$inc operator with +1 for the
totalNumberOfRatings and adding the user rating that is between 1 - 10 for the
totalRatingsScore. To get the average for that match I could then simply use
Does this solution scale if in the dream scenario, thousands of people are submitting ratings, that are likely to happen at around the same time after a match finishes?
For the long term averages:
I would have a
ratings field on a Player document that would have sub documents consisting of a
totalRatingsScore that would be updated in a similar fashion to the per match basis. To get the long term average for the player would then involve calculating the average for each match and then getting the average from all the match averages.
Both scenarios would be updated using a
What do you think about this solution? How would you tackle it?