📅  最后修改于: 2022-03-11 14:57:45.853000             🧑  作者: Mango
db.inventory.aggregate([
{
$project: {
item: 1,
numberOfColors: { $cond: { if: { $isArray: "$colors" }, then: { $size: "$colors" }, else: "NA"} }
}
}
] )