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

atomically destroys document data if no atomic operations are performed by the block

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 7.0.0
    • Affects Version/s: 5.2.1, 6.2.1
    • Component/s: None
    • Labels:
      None

      When using the `atomically` method to combine multiple atomic operations into a single mongo operation, if zero atomic operations are created by the block, then mongoid issues an incorrect update operation with an empty document `{}`.
      This completely erases the underlying document.

      Expected Behaviour: There should be no update, and no loss of data.

      Example:

      SomeModel.rb
      class SomeModel
         include Mongoid::Document
      
        def perform_some_updates
           atomically do
              set(:foo, 'bar') if some_condition
              set(:baz: 'quux') if other_condition
              # etc
          end
      end
      

      If both of the conditionals in the example evaluate to false, then models data is unexpectedly lost.

            Assignee:
            emily.stolfo Emily Stolfo
            Reporter:
            gingerhendrix Gareth Andrew
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: