Node.js MongoDb按总查询筛选
我有一个这样的样品Node.js MongoDb按总查询筛选,node.js,mongodb,express,Node.js,Mongodb,Express,我有一个这样的样品 _id counts createdAt 58adc57a1f84e37c19df0ccb [600, 100, 400, 500, 700, 200, 300] 2017-02-07T13:23:38.320Z . other document rows . other document rows . other document rows ... 样
_id counts createdAt
58adc57a1f84e37c19df0ccb [600, 100, 400, 500, 700, 200, 300] 2017-02-07T13:23:38.320Z
. other document rows
. other document rows
. other document rows
...
样本:
我的文档行是这样的
_id counts createdAt
58adc57a1f84e37c19df0ccb [600, 100, 400, 500, 700, 200, 300] 2017-02-07T13:23:38.320Z
. other document rows
. other document rows
. other document rows
...
我想问一问
总价格在20到30之间
及
“2016-01-26”、“2018-02-02”之间的工资时间
如何编写查询
谢谢你的帮助 你可以试试这个
db.getCollection('test').aggregate(
[
{"$addFields": { "total_counts": { "$sum": "$counts" } } },
{"$match": {
"total_counts": { "$gt": 2700 , "$lt": 3000 },
"createdAt": { "$gt": ISODate('2016-01-26'), "$lt": ISODate('2018-02-02') }
} }
]
)