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

Using .last on .limit query returns a different record compared to calling .to_a.last

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

      I'm seeing some strange behavior when trying to get the last record from a query limited to a number of documents. I have the example query below:

      Event.where(:_id.gt => '517f2486a812fd8222002a1f').limit(1000).to_a.last._id
      => "517f248da812fd8222002eef"

      Event.where(:_id.gt => '517f2486a812fd8222002a1f').limit(1000).last._id
      => "518011c9a812fd94f7000011"

      irb(main):009:0> Event.where(:_id.gt => '517f2486a812fd8222002a1f').limit(1000)
      => #<Mongoid::Criteria
      selector: {"_id"=>{"$gt"=>"517f2486a812fd8222002a1f"}}
      options: {:limit=>1000}
      class: Event
      embedded: false>

      Mongodb 2.4
      Mongoid 3.1.2

            Assignee:
            arthurnn Arthur Nogueira Neves
            Reporter:
            MikeEmery MikeEmery [X]
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: