MongoDB 实现按列累加统计

Mongodb 如何计算多条数据的总和

MySQL:

select date, sum(total) from test_table where date>="2018-02-26 00:00:00" and date<'2018-02-27 00:00:00' and my_id = 0;

MongoDB 聚合查询:

db.getCollection('test_table').aggregate( [ { $match: { "my_id":0, "now_date":{"$gte":ISODate("2018-02-26T00:00:00.000Z"), "$lt": ISODate("2018-02-27T00:00:00.000Z")} } }, { $group: { _id: null, total: { $sum: "$total" } } } ] )

你可能感兴趣的:(MongoDB,sum,mongodb,统计,按列)