mongodb 聚合aggregate 乘法
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为数量
}
}
])
声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。
- 上一篇:没有了
- 下一篇:没有了