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

Positional operator update broken for > 10 objects

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Closed
    • Resolution: Done
    • Affects Version/s: None
    • Fix Version/s: 3.1.0
    • Component/s: None
    • Labels:
      None

      Description

       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.

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved: