mongodb aggregation $size code example
Example 1: query document array size greater than 1
// Find all docs that have at least two name array elements.
db.accommodations.find({'name.1': {$exists: true}})
Example 2: aggregation with size and sort mongodb
> db.demo33.aggregate({$unwind:"$ListOfStudent"}, { $group : {_id:'$_id', ct:{$sum:1}}}, { $sort :{ ct: -1}} );