how to find array length in mongodb code example
Example 1: mongodb filter empty array
db.collection.find({arrayElementName : {$exists:true, $size:0}})
Example 2: mongodb count array size
db.inventory.aggregate([
{
$project: {
item: 1,
numberOfColors: { $cond: { if: { $isArray: "$colors" }, then: { $size: "$colors" }, else: "NA"} }
}
}
] )