rails mongo 查询前一天的结果
rails mongo query to get previous day's results
我在 rails 应用程序上从我的 ruby 生成一份报告,每天早上 7 点 运行。
此报告将收集前一天的结果。
所以基本上我想查询前一天的结果到我的 Mongo collection。这是我尝试过的:
logs = Log.where(:comp => comp, :created_at => (Date.today -1))
我收到以下错误:
BSON::InvalidDocument: Date is not currently supported; use a UTC Time instance instead.
获得上述结果的最佳方法是什么:
这是我数据库中日期的格式:
"created_at" : ISODate("2015-12-02T23:12:38.076Z")
你可以在 mongoid 中做这样的事情:
logs = Log.where(:comp => comp, :created_at.gte => (Date.today -1 ).to_datetime)
Date.to_datetime
将默认为午夜,如下所示:
(Date.today - 1).to_datetime
=> Wed, 30 Mar 2016 00:00:00 +0000
我在 rails 应用程序上从我的 ruby 生成一份报告,每天早上 7 点 运行。 此报告将收集前一天的结果。
所以基本上我想查询前一天的结果到我的 Mongo collection。这是我尝试过的:
logs = Log.where(:comp => comp, :created_at => (Date.today -1))
我收到以下错误:
BSON::InvalidDocument: Date is not currently supported; use a UTC Time instance instead.
获得上述结果的最佳方法是什么:
这是我数据库中日期的格式:
"created_at" : ISODate("2015-12-02T23:12:38.076Z")
你可以在 mongoid 中做这样的事情:
logs = Log.where(:comp => comp, :created_at.gte => (Date.today -1 ).to_datetime)
Date.to_datetime
将默认为午夜,如下所示:
(Date.today - 1).to_datetime
=> Wed, 30 Mar 2016 00:00:00 +0000