-
Type: New Feature
-
Resolution: Duplicate
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: Aggregation Framework
-
Query Optimization
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.
- depends on
-
SERVER-56572 Allow ranking-style window functions over a compound set of sortBy fields
- Backlog
- duplicates
-
SERVER-56572 Allow ranking-style window functions over a compound set of sortBy fields
- Backlog