There is still no own way to calculate percentiles, but by combining several aggregated operators, you can get the same result.
db.items.aggregate([ {'$group': { '_id': { 'league': '$league', 'base': '$base', 'type': '$type' }, 'value': {'$push': '$chaosequiv'} }}, {'$unwind': '$value'}, {'$sort': {'value': 1}}, {'$group': {'_id': '$_id', 'value': {'$push': '$value'}}}, {'$project': { '_id': 1, 'value': {'$arrayElemAt': ['$value', {'$floor': {'$multiply': [0.25, {'$size': '$value'}]}}]} }} ], allowDiskUse=True)
Note. I wrote my source code in pymongo for a problem that should have been grouped into 3 fields in the first group, so this can be more complicated than needed for a single field. I would write a solution specific to this question, but I do not think that there is enough specific information.
source share