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