A query for user points, and then a query to count users with points above.
Points.findOne({userId: userId}, (err, doc) => { Points.count({points: {$gt: doc.points}}, (err, count) => { // do something with count... }); });
For scalable performance, you need to index userId and points separately. In your circuit:
userId: {type: ObjectId, index: true}, points: {type: Number, index: true}, ...
It should be faster than any solution to reduce the map.
source share