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

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

    • Type: Icon: Task Task
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 6.1.0, 5.2.0
    • Affects Version/s: None
    • Component/s: None

      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"=>[]}
      

            Assignee:
            emily.stolfo Emily Stolfo
            Reporter:
            amw Adam Wróbel
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: