我有一个 Ruby 关联类,如下所示:
class Association
include Mongoid::Document
field :issued, type: Integer
field :lifetime, type: Integer
end
我想删除我的集合中的所有文档 where doc.issued + doc.lifetime > Time.now
. 我在网上找到了以下语法:
Association.delete_all(["issued + lifetime > ?", Time.now.to_i])
我无法让它工作,我收到以下错误:
TypeError: can't convert Symbol into Integer
from /var/lib/gems/1.9.1/gems/mongoid-3.1.0/lib/mongoid/persistence.rb:298:in `[]'
from /var/lib/gems/1.9.1/gems/mongoid-3.1.0/lib/mongoid/persistence.rb:298:in `delete_all'
from (irb):77
from /usr/bin/irb:12:in `<main>'
有人能告诉我这种语法有什么问题或建议不同的语法吗?