.last overrides skip

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Fixed
    • Priority: Minor - P4
    • 9.0.7, 8.1.11
    • Affects Version/s: None
    • Component/s: None
    • None
    • None
    • Fully Compatible
    • Ruby Drivers
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?
    • None
    • None
    • None
    • None
    • None
    • None

      In mongoid 9.0.2, .last method overrides .skip

      In mongoid 7 and before the following code would return the next to last document:

      ModelName.skip(1).last

      In mongoid 9 (and 8 I believe) the above always returns the last document.

      Looking at the code in mongoid contextual : 

       

      def retrieve_nth_to_last_with_limit(n, limit)
      
         v = view.sort(inverse_sorting).{*}skip(n){*}.limit(limit || 1)
      
         v = v.skip(n) if n > 0
      
         raw_docs = v.to_a.reverse
      
         process_raw_docs(raw_docs, limit)
      
      end
      

      I believe the skip in bold should be removed, it is overriding any skip value passed in.

            Assignee:
            Jamis Buck
            Reporter:
            Nate Muller
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: