This is not possible directly with mongodb [ 1 ]
One solution, if you often use this query, is to increase and decrease the number of "counters" each time you change the grades array and sort in this field.
The document will look like this:
{ "_id" : ObjectId("4e84f78b26d2046d5d00b5b2"), "parent_id" : 0, "ratings" : [ "20716", "78167" ], count : 2 "text" : "test" }
and you request using
db.comments.find().sort({count: -1})
kamaradclimber
source share