如何使用 Mongoid 和 Ruby 查询日期范围(比如从现在开始的最后 30 天)?
我需要得到一个数组或哈希,如下所示:
{
15 => 300,
14 => 23,
13 => 23
...
30 => 20 # Goes over into previous month
28 => 2
}
我目前正在使用 DateTime 实例以及 unix timestamp Integer 字段存储每个文档。
上述哈希中的键是天数,值是那些天所有销售额的总和。
有什么想法吗?
最佳答案
有一个更简单的方法:
Sale.where(created_at: (30.days.ago..Time.now))
调整时间范围以适应。
关于ruby - 使用 Mongoid 和 Ruby 查询最近 30 天的日期范围?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7778464/