search

Home  >  Q&A  >  body text

node.js - mongodb根据一个字段的范围进行数量统计

PHP中文网PHP中文网2770 days ago348

reply all(2)I'll reply

  • 黄舟

    黄舟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

    reply
    0
  • 大家讲道理

    大家讲道理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.

    reply
    0
  • Cancelreply