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

Positional operator update broken for > 10 objects

    • Type: Icon: Task Task
    • Resolution: Done
    • 3.1.0
    • Affects Version/s: None
    • Component/s: None
    • None

       ruby
      require 'spec_helper'
      
      class Collection
        include Mongoid::Document
        embeds_many :things
      end
      
      class Thing
        include Mongoid::Document
        field :index
        field :name
        embedded_in :collection  
      end
      
      describe Mongoid do
        it "inserts null records" do
          c = Collection.create!
          11.times do |i|
            c.things << Thing.new(index: i, name: "t#{i}")\
          end
          c.things.where({ :index.gt => 9 }).each do |thing|
            thing.update_attributes!({ index: thing.index - 1 })
          end
          c.reload.things.count.should == 11
        end
      end
      

      Uh oh.

        1) Mongoid inserts null records
           Failure/Error: c.reload.things.count.should == 11
             expected: 11
                  got: 101 (using ==)
      

      It's making queries with a positional operator $0, then $1, above 10.

            Assignee:
            Unassigned Unassigned
            Reporter:
            dblock Daniel Doubrovkine
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: