2012-08-01 56 views
1

批量更新都不再工作,我有以下几点:Mongoid 3批量更新升级到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) 

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

回答

0

我认为这是因为你的查询使用像account_id这样的字符串,而不是Moped :: BSON :: ObjectId。

如果你做了没有更新的地方。你没有结果我想。

+0

不幸的是,我知道这不是问题。我已经运行没有更新的地方,它确实返回结果。 – Dowker 2012-08-03 12:42:37