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

Applying a sort order appears to not properly reset cursor on .first and .last

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

      Without a sort order .first and .last work as expected each time:

      irb(main):081:0> a = StagingBlekkoBacklink.where(presence_id: 486)
      => #<Mongoid::Criteria
         selector: {"presence_id"=>486},
         options:  {},
         class:    StagingBlekkoBacklink,
         embedded: false>
      
      irb(main):082:0> a.first
      => #<StagingBlekkoBacklink _id: 509da58bebad640c3c000001, _type: nil, presence_id: 486, competitor_id: 878, date_range_id: 1, to_url: "http://www.hud-son.com/all_new_mill.htm", from_url: "https://www.grit.com/blogs/blog.aspx?blogmonth=2&blogyear=2012&blogid=184", anchor_text: "hud-son hfe 21 bandsaw mill", anchor_has_image: false, title: "The Daily Commute", exclude: false, follow: false, popularity: 0.000157, geo: "{}", is_new: false, is_removed: false>
      irb(main):083:0> a.last
      => #<StagingBlekkoBacklink _id: 509da58bebad640c3c000e7f, _type: nil, presence_id: 486, web_page_id: 3746, web_site_id: 507, date_range_id: 3, to_url: "http://www.norwoodsawmills.com/band-blades", from_url: "https://plus.google.com/105265266632264874631/posts", anchor_text: nil, anchor_has_image: false, title: "Norwood Portable Sawmills - Google+", exclude: false, follow: false, popularity: 1.12591201989172, geo: "{}", is_new: true, is_removed: false>
      irb(main):084:0> a.first
      => #<StagingBlekkoBacklink _id: 509da58bebad640c3c000001, _type: nil, presence_id: 486, competitor_id: 878, date_range_id: 1, to_url: "http://www.hud-son.com/all_new_mill.htm", from_url: "https://www.grit.com/blogs/blog.aspx?blogmonth=2&blogyear=2012&blogid=184", anchor_text: "hud-son hfe 21 bandsaw mill", anchor_has_image: false, title: "The Daily Commute", exclude: false, follow: false, popularity: 0.000157, geo: "{}", is_new: false, is_removed: false>
      irb(main):085:0> a.last
      => #<StagingBlekkoBacklink _id: 509da58bebad640c3c000e7f, _type: nil, presence_id: 486, web_page_id: 3746, web_site_id: 507, date_range_id: 3, to_url: "http://www.norwoodsawmills.com/band-blades", from_url: "https://plus.google.com/105265266632264874631/posts", anchor_text: nil, anchor_has_image: false, title: "Norwood Portable Sawmills - Google+", exclude: false, follow: false, popularity: 1.12591201989172, geo: "{}", is_new: true, is_removed: false>
      

      However when you apply a sort order the cursor does not reset after running last:

      irb(main):086:0> a = StagingBlekkoBacklink.where(presence_id: 486).asc(:date_range_id)
      => #<Mongoid::Criteria
         selector: {"presence_id"=>486},
         options:  {:sort=>{"date_range_id"=>1}},
         class:    StagingBlekkoBacklink,
         embedded: false>
      
      irb(main):087:0> a.first
      => #<StagingBlekkoBacklink _id: 509da58bebad640c3c00015f, _type: nil, presence_id: 486, competitor_id: 880, date_range_id: 1, to_url: "http://www.timberking.com/", from_url: "http://www.precallpro.com/blog/bid/35800/Curing-The-Sales-Bloviator-Shut-up-and-Sell-More", anchor_text: nil, anchor_has_image: false, title: "Curing The Sales Bloviator - Shut-up and Sell More", exclude: true, follow: true, popularity: 0.100111, geo: "{\"city\":\"Lake Forest\",\"country_code\":\"US\",\"isp_org\":\"Rackspace Hosting\",\"latitude\":\"33.6451\",\"longitude\":\"-117.6786\",\"state\":\"CA\",\"zip\":\"92630\"}", is_new: true, is_removed: false>
      irb(main):088:0> a.last
      => #<StagingBlekkoBacklink _id: 509da58bebad640c3c000e7f, _type: nil, presence_id: 486, web_page_id: 3746, web_site_id: 507, date_range_id: 3, to_url: "http://www.norwoodsawmills.com/band-blades", from_url: "https://plus.google.com/105265266632264874631/posts", anchor_text: nil, anchor_has_image: false, title: "Norwood Portable Sawmills - Google+", exclude: false, follow: false, popularity: 1.12591201989172, geo: "{}", is_new: true, is_removed: false>
      irb(main):089:0> a.first
      => #<StagingBlekkoBacklink _id: 509da58bebad640c3c000e7f, _type: nil, presence_id: 486, web_page_id: 3746, web_site_id: 507, date_range_id: 3, to_url: "http://www.norwoodsawmills.com/band-blades", from_url: "https://plus.google.com/105265266632264874631/posts", anchor_text: nil, anchor_has_image: false, title: "Norwood Portable Sawmills - Google+", exclude: false, follow: false, popularity: 1.12591201989172, geo: "{}", is_new: true, is_removed: false>
      irb(main):090:0> a.last
      => #<StagingBlekkoBacklink _id: 509da58bebad640c3c000e7f, _type: nil, presence_id: 486, web_page_id: 3746, web_site_id: 507, date_range_id: 3, to_url: "http://www.norwoodsawmills.com/band-blades", from_url: "https://plus.google.com/105265266632264874631/posts", anchor_text: nil, anchor_has_image: false, title: "Norwood Portable Sawmills - Google+", exclude: false, follow: false, popularity: 1.12591201989172, geo: "{}", is_new: true, is_removed: false>
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            gshiftlabs-dbuttineau gshiftlabs-dbuttineau
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: