how to get length of arrayin mongo aggregation code example
Example 1: mongo count elements in array
{ $size: <expression> }
Example 2: mongodb count array size
db.inventory.aggregate([
{
$project: {
item: 1,
numberOfColors: { $cond: { if: { $isArray: "$colors" }, then: { $size: "$colors" }, else: "NA"} }
}
}
] )