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'}})
- related to
-
MONGOID-3407 Can't use dot notation with atomic updates on the document instance level
- Closed