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

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

    Details

      Description

      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.

        Attachments

          Activity

            People

            • Votes:
              5 Vote for this issue
              Watchers:
              11 Start watching this issue

              Dates

              • Created:
                Updated: