1.mongodb统计数据时需要两列相乘并且将相乘的结果求和的功能
2.代码:
db.shopprilegerecoding.aggregate([
{$match :{$and:[{createtime:{'$gt':new Date("2017-01-01")}},{createtime:{'$lt':new Date("2017-12-31")}}]} },
{$group :
{
_id : {
year:{$year:"$createtime"},
month:{$month:"$createtime"},
},
num_tutorial : {$sum : {$multiply:["$price","$limit"]} }//此处price为单价,limit为数量
}
}
])