Title: Mongodb Aggregate Sum。

Categories: mongo

Description: Mongodb sum 查询聚合

Keywords: mongo, sum

Mongodb search aggregate SUM

db.cabinet.aggregate(
   [
     {
       $group:
         {
           _id: { },
           totalAmount: { $sum: "$cabinetBoxTotal" },
           count: { $sum: 1 }
         }
     }
   ]
)

db.cabinet.aggregate(
   [
       { $match : { cabinetName : "中国农业大学西校区2号柜"} },

     {
       $group:
         {
           _id: {},
           totalAmount: { $sum: "$cabinetBoxTotal" },
           count: { $sum: 1 }
         }
     }
   ]
)