ruby require 'spec_helper' class Sandwich include Mongoid::Document embeds_many :slices end class Slice include Mongoid::Document field :position, default: 0 include Mongoid::Document embedded_in :sandwiches end describe "relationship" do it "inc" do sandwich = Sandwich.create! slice = Slice.new sandwich.slices << slice Moped.logger = Logger.new(STDOUT) Moped.logger.level = Logger::DEBUG slice.inc :position, 5 end end
Executes this. Note slices.0.position.
MOPED: 127.0.0.1:27017 UPDATE database=mongoid_test collection=sandwiches selector={"_id"=>"510306c33b55524b26000001", "slices._id"=>"510306c33b55524b26000002"} update={"$inc"=>{"slices.0.position"=>5}} flags=[] (0.0811ms)
Same goes for unset, set, etc., anything that calls query.update_all.