For example I have user documents with `badges` field:
User
{ _id: "someone@example.com", password: "..." badges: ["b1", "b2", "b3"] }
The `badges` field is updated by $addToSet so there won't be duplicate.
Then I want to list users and sort by the number of badges they have. Currently I am using aggregation which can give me the result. however the $unwind step seems to be overkilled... as I understand it creates N documents on the fly if the user has N badges.
It would be easier to make the query like:
db.users.find({}, {$sort: {badges.$size: -1}})
- duplicates
-
SERVER-478 Advanced $size quering
- Closed