Uploaded image for project: 'Documentation'
  1. Documentation
  2. DOCS-9994

Unique field must be included to ensure sort order stability across multiple queries

    XMLWordPrintableJSON

Details

    Description

      There are number of reasons that the ordering of results with the same sort key might not be stable:

      1. The query execution stages for performing blocking sort operations in find/aggregation do not use a stable sort algorithm.
      2. Unpredictability of network latency and getMore ordering for queries on sharded clusters may result in different orders. This is similar to the behavior described in SERVER-27716, which was closed as Works as Designed.
      3. Changes to the underlying storage. For example, document moves on the MMAPv1 storage engine can result in repeated COLLSCANs returning the data in different orders. Therefore, even if the blocking sort query execution algorithm was stable, this still wouldn't be sufficient to guarantee consistent ordering of equal-keyed results.

      Therefore, we should clarify that users who require a stable sort order across queries (eg pagination) add a unique field to their sort.

      Attachments

        Activity

          People

            andrew.feierabend@mongodb.com Andrew Feierabend (Inactive)
            kelsey.schubert@mongodb.com Kelsey Schubert
            Votes:
            0 Vote for this issue
            Watchers:
            11 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              3 years, 8 weeks, 2 days ago