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
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.
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
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
.