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

Can't use dot notation with atomic updates on the document instance level

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 6.1.0, 5.2.0
    • Component/s: None
    • Labels:
    • Sprint:
      Ruby Sprint 43, Ruby Sprint 45, Ruby Sprint 46

      Description

      Seems that Mongoid doesn't handle dot notation in atomic updates on a document instance level. It's completely messed up. It is working fine when using atomic updates on criteria/scope level.

      Code:

      # Setup
       
      require 'mongoid'
       
      Mongoid.configure {|c| c.connect_to "mongoid_test"}
       
      class RootDocument
        include Mongoid::Document
        field :my_hash, type: Hash
      end
      RootDocument.delete_all
       
      puts "Using Mongoid #{Mongoid::VERSION}"
       
      # Tests
       
      root = RootDocument.new
      root.my_hash = {"test" => []}
      root.save!
      puts root.as_json.inspect
       
      begin
        puts "\nTesting push \"my_hash.test\", 1"
        root.push "my_hash.test", 1
      rescue NoMethodError => e
        puts e
      end
       
      puts root.as_json.inspect
       
      puts "\nTesting set \"my_hash.test\", \"value\""
      root.set "my_hash.test", "value"
       
      puts root.as_json.inspect
      

      Output:

      Using Mongoid 3.1.5
      {"_id"=>"528d3f1f66d9f10b4d000001", "my_hash"=>{"test"=>[]}}
       
      Testing push "my_hash.test", 1
      undefined method `my_hash.test' for #<RootDocument:0x007fc170c8a170>
      {"_id"=>"528d3f1f66d9f10b4d000001", "my_hash"=>{"test"=>[]}}
       
      Testing set "my_hash.test", "value"
      {"_id"=>"528d3f1f66d9f10b4d000001", "my_hash"=>{"test"=>[]}, "my_hash.test"=>[]}
      

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved: