Assigning a real-time ranking/order/index to a sorted list using the MongoDB Aggregation framework
Dan Delaney

This is very interesting!

I have recently implemented a rank function less elegantly:

  1. Count number of users with lower score
  2. Query users with same score, fetch, and loop through array until the desired user is found, remember index.
  3. Add the count of1 to the index of 2 and add 1.

However, I wonder whether your aggregation approach goes through all the documents in the collection or stops when it reaches the user — given an index on the PLR field.

I also wonder whether it is useful to instead regularly go through all documents and update a rank attribute.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.