Ruby Mongoid DateTime.gte / lte查询不起作用

时间:2017-05-28 23:38:51

标签: ruby mongoid

我有一个mongoid类User,其DateTime字段名为last_notification_check

并非所有User个对象都有此字段,因为它仅在用户首次登录后才添加。

我需要查询以下内容:

User.where(:last_notification_check.lte => (Time.now - 60).utc)

这应该返回1个用户对象的响应,但它会不断返回nil

我应该能够拿起的mongoid对象:

{ 
    "_id" : ObjectId("590ad06f78cee4ffcd612d5e"), 
    "active" : true, 
    "first_name" : "Test", 
    "last_name" : "Person", 
    "suffix" : null, 
    "email" : "test@email.com", 
    "encrypted_password" : "s7FThz4a68nBKx6aGJ19Bw==", 
    "admin" : true, 
    "updated_at" : ISODate("2017-05-28T21:29:30.486+0000"), 
    "created_at" : ISODate("2017-05-04T06:55:42.990+0000"), 
    "title" : "Test User", 
    "last_notificaton_check" : ISODate("2017-05-28T21:29:30.485+0000")
}

我得到以下结果......不知道该怎么做......

User.where(:last_notification_check.gte => Time.now)
# nil
User.where(:last_notification_check.lte => Time.now)
# nil
User.where(:first_name => 'Test').each do |user|
    puts user.last_name
end
# "Person"

0 个答案:

没有答案