Mongodb Aggregate Sum。

2017/11/29 mongo

Mongodb search aggregate SUM

  • find aggregate and where

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 }
         }
     }
   ]
)

Affiliate

Search

    Post Directory