Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js MongoDb按总查询筛选_Node.js_Mongodb_Express - Fatal编程技术网

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