1> db.mycollection.insert({'foo':[1,2,3,4]})
2> db.mycollection.insert({'foo':[5,6,7]})
3
4> db.mycollection.aggregate([{$project: { count: { $size:"$foo" }}}])
5{ "_id" : ObjectId("5314b5c360477752b449eedf"), "count" : 4 }
6{ "_id" : ObjectId("5314b5c860477752b449eee0"), "count" : 3 }
7
1db.inventory.aggregate([
2 {
3 $project: {
4 item: 1,
5 numberOfColors: { $cond: { if: { $isArray: "$colors" }, then: { $size: "$colors" }, else: "NA"} }
6 }
7 }
8] )
9