-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
I just totally messed up my staging environment with something like code. Using Mongoid 2.4.12.
User.where(:favorite_color => "blue").unsafely.update_all(:favorite_color => "red")
Mongo logs:
# Not using unsafely User.where(:favorite_color => "blue").update_all(:favorite_color => "red") # > Tue Jul 24 18:32:24 [conn2] update development.users query: { favorite_color: "blue" } update: { $set: { favorite_color: "red" } } 0ms # Using unsafely User.where(:favorite_color => "blue").unsafely.update_all(:favorite_color => "red") # > Tue Jul 24 18:32:57 [conn2] update development.users update: { $set: { favorite_color: "red" } } 0ms
.safely has the same effect on the mongo logs.
It seems like unsafely/safely needs to be called first; you should probably error then if it is called on a Mongoid::Criteria if that is the intended purpose.