db.collection.aggregate([ { $unwind: "$items" },
db.collection.aggregate([
{ $unwind: "$items" },
{
"$group": {
"_id": "$_id",
collected:{
$addToSet: "$items.results.collected"
},
}
},
{ $unwind: "$collected" },
{
$project: {
totalcoletado: {
$size: "$collected"
}
}
},
{$sort: { totalcoletado: -1 } },
{$limit: 5}
])
])