Answers for "mongodb count array size"

1

mongodb count array size

db.inventory.aggregate([
   {
      $project: {
         item: 1,
         numberOfColors: { $cond: { if: { $isArray: "$colors" }, then: { $size: "$colors" }, else: "NA"} }
      }
   }
] )
Posted by: Guest on May-07-2020

Browse Popular Code Answers by Language