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

unexpected behavior using dot notation on set atomic operation

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical - P2
    • Resolution: Fixed
    • Affects Version/s: 5.1.0, 5.1.1
    • Fix Version/s: 6.0.1
    • Component/s: None
    • Labels:

      Description

      Seems the $set operation with dot notation is overwriting the Hash field and it is not how the driver or the MongoDB documentation describes it.

      if we change the following test https://github.com/mongodb/mongoid/blob/master/spec/mongoid/persistable_spec.rb#L240 the problem will be exposed

        customer.set 'address.country.name' => 'India'
        expect(customer.address).to eql({'country' => { 'name' => 'India' }})
       
        # I expect that this code is a shortcut for:
        # Customer.collection.find({_id: customer.id}).update_one({:$set => { 'address.country.state' => 'MH' }})
        # and this will produce a hash like { 'name' => 'India', 'state' => 'MH' }
        customer.set 'address.country.state' => 'MH'
        expect(customer.address).to eql({'country' => { 'name' => 'India', 'state' => 'MH'}})
      

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: