Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-82368

Match top/bottom N accumulators in SBE and Classic

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 7.2.0-rc0, 7.0.5, 6.0.13
    • Affects Version/s: None
    • Component/s: None
    • Query Execution
    • Fully Compatible
    • ALL
    • v7.0, v6.0
    • QE 2023-10-30, QE 2023-11-13
    • 130

      Currently in Classic, $bottom accumulator will compare arrays element-by-element, which is natural, but contradicts our documentation: https://www.mongodb.com/docs/manual/reference/bson-type-comparison-order/#arrays

      A less-than comparison, or an ascending sort, compares the smallest elements of the array according to the BSON type sort order.
      
      A greater-than comparison, or a descending sort, compares the largest elements of the array according to the reverse BSON type sort order. 

      SBE will follow the docs.

      This is because in Classic, accumulator wraps sort keys in array and sort key generator considers the array being nested, so it returns it fully in a sort key. SBE accepts document fully as-is, so the array is not nested, so only one element is returned as a sort key.

      Reproduction script is attached.

        1. data.js
          0.9 kB

            Assignee:
            ivan.fefer@mongodb.com Ivan Fefer
            Reporter:
            ivan.fefer@mongodb.com Ivan Fefer
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: