Mongoid 3批量更新

时间:2012-08-01 21:24:20

标签: ruby-on-rails mongoid

升级到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)

但是,数据库中没有任何内容更新。

1 个答案:

答案 0 :(得分:0)

我认为这是因为您的查询使用类似于account_id的字符串,而不是Moped :: BSON :: ObjectId。

如果您在没有更新的情况下进行操作。你没有我想的结果。

相关问题