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"=>[]}
- is related to
-
MONGOID-4254 unexpected behavior using dot notation on set atomic operation
- Closed
- related to
-
MONGOID-4426 Setter on hash field failes if the original value is nil.
- Closed