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

unexpected behavior using dot notation on set atomic operation

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Critical - P2 Critical - P2
    • 6.0.1
    • Affects Version/s: 5.1.0, 5.1.1
    • Component/s: None

      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'}})
      

            Assignee:
            emily.stolfo Emily Stolfo
            Reporter:
            kuadrosx Jorge Cuadrado
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: