0

I currently have a list of restaurants similar to how Yelp works that have ratings from 1-5 and a total number of ratings. When showing the restaurants to my users, I want to sort by a weighted combination of ratings and reviews so that a restaurant with 1 5 star rating doesn't outrank a restaurant with 20 5 star ratings and 10 4 star ratings.

I want to use something like this answer: https://stackoverflow.com/a/1411268/7754241, but since the mean vote changes everytime a new restaurant is added or a new review is added, I am unsure how to do this dynamically.

Is this possible to do this within a db.find().sort() MongoDB query?

Community
  • 1
  • 1
  • have you tried doing an aggregation, and in the aggregation pipeline compute weighted score as a new field and sort by that. – harinsa Mar 25 '17 at 15:34
  • No. It's not a huge number of restaurants being sorted at once, so I was hoping I could do it within the query without creating any extra fields. – Ruben Pierre-Antoine Mar 25 '17 at 19:07

0 Answers0