升级到 Mongoid 3 后,批量更新不再有效。在 Mongoid 2 中,我有以下内容:
Shift.where(
:account_id => current_account.id,
:location => self.department.location.name,
:department => self.department.name,
:position => self.name_was,
:color => self.color_was,
:date.gte => Date.current
).update_all(position: self.name, color: self.color)
我知道标准正在返回结果,但它不再更新文档。这是 Mongoid 3 中的声明:
Shift.where(
:account_id => current_account.id,
:location => self.department.location.name,
:department => self.department.name,
:position => self.name_was,
:color => self.color_was,
:date.gte => Date.current
).update(position: self.name, color: self.color)
我正在运行 Rails 3.2.7 和 Mongoid 3.0.3。有什么我不知道的变化吗?这也是日志中的条目:
MOPED: 127.0.0.1:27017 UPDATE database=development collection=shifts selector={"$query"=>{"account_id"=>"5017e8774f4e481fe3000001", "location"=>"Downtown", "department"=>"Cashes", "position"=>"Cash 1", "date"=>{"$gte"=>2012-08-01 00:00:00 UTC}}, "$orderby"=>{"start_at"=>1}} update={"$set"=>{:position=>"Cash A", :color=>"#42ed23"}} flags=[:multi] (0.2141ms)
但是,数据库中没有任何内容得到更新。