node.js - mongodb根据一个字段的范围进行数量统计
PHP中文网
PHP中文网 2017-04-17 15:57:15
0
2
342
PHP中文网
PHP中文网

认证0级讲师

reply all(2)
黄舟

Do you count the total number of data for each day? , is the timestamp stored in mongodb int32 or int64? To meet the above conditions, you can do the following

db.find("timeStamp":{"$lt":456,"$gte":123}).count()

count() is a type of aggregation

大家讲道理

What kind of data? If it is time series data, the historical situation will not change. It is recommended to count it once a day and save the results for direct access later. Do not perform unnecessary calculations every time.
aggregate是推荐的取代map/reduce的聚合框架。如果以上假设成立,楼上的办法也可以达成。但是要注意count在分片集中给出的是不精确结果,想要精确结果还是请用aggregate.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template