-
Type: New Feature
-
Resolution: Duplicate
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: Aggregation Framework
-
None
Here's the use case.
I need a sorted array of elements within a document:
[ ... { $group: { "_id": "$athing", "anArray": {$push :"$aVal"} } }, { $addFields : { "sortedArr" : { $sort :"$anArray" } } }, //something like this ... ]
Now, I could sort before the grouping, but that'll only work if the data set is small. If I have a much smalled subset of the data, sorting it would be much faster.
... [ ... { $sort : { "aVal" : -1 } }, //Does not work for very large data sets { $group: { "_id": "$athing", "sortedArr": {$push :"$aVal"} } }, ... ]
- duplicates
-
SERVER-29425 Add an expression to sort an array
- Closed