Add a way to determine a document's rank after a $sort

XMLWordPrintableJSON

    • Type: New Feature
    • Resolution: Duplicate
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Aggregation Framework
    • Query Optimization
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      It would be useful to be able to add a documents position in a sort to the document. For example, there could be an additional option to the $sort stage:

      {$sort: {
          order: {a: 1, b: 1},
          includeSortIndex: 'index'
      }}
      

      Which would output documents sorted by {a: 1, b: 1}, and inject an additional field 'index', containing it's position in the sort order (overwriting an existing field if applicable).

      Original Description

      Originally posted

      https://groups.google.com/d/topic/mongodb-user/PL_g1RCmPsI/discussion

      It would be very useful to be able to extract the indexed position of a document from a group statement, or a sort. e.g. consider the use case of building up a leader board / league table.

      Workaround suggestions welcome in the meantime.

              Assignee:
              [DO NOT USE] Backlog - Query Optimization
              Reporter:
              Sam Halliday
              Votes:
              8 Vote for this issue
              Watchers:
              19 Start watching this issue

                Created:
                Updated:
                Resolved: