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

Atomic set operation on a Hash field's key writes the entire hash

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 7.0.3
    • Component/s: Persistence
    • Labels:
      None
    • Environment:
      OS X 10.14 and Ubuntu 18.04 LTS

      When attempting to set a specific key within Hash field using the atomic

      set

      method, the entire Hash is written rather than just the specified key.

      Given a class:

      class Lead
        include Mongoid::Document
      
        field :additional_info, type: Hash
      end
      

      Running the following:

      2.6.2 :001 > lde = Lead.first
      2.6.2 :002 > lde.additional_info
       => {"x"=>1, "y"=>2, "z"=>3} 
      2.6.2 :003 > lde.set("additional_info.x" => 0)
      

      Produces this query:

      {"update"=>"leads", "ordered"=>true, "lsid"=>{"id"=><BSON::Binary:0x70205608300400 type=uuid data=0xc5e017742a694cd8...>}, "updates"=>[{"q"=>{"_id"=>"lde_12Vwbb66NgkdCL"}, "u"=>{"$set"=>{"additional_info"=>{"x"=>0, "y"=>2, "z"=>3}}}, "multi"=>false, "...
      

      You can see from the query that the entire Hash is being written.

            Assignee:
            Unassigned Unassigned
            Reporter:
            mauricio@whoisblackops.com Mauricio Gomes
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: