Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-2240

Model.where(...).un/safely ignores where criteria

    • Type: Icon: Task Task
    • Resolution: Done
    • 2.5.0
    • 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.

            Assignee:
            Unassigned Unassigned
            Reporter:
            jonhyman Jon Hyman
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: