黄舟2017-04-17 15:59:15
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
大家讲道理2017-04-17 15:59:15
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
.