Details
-
New Feature
-
Resolution: Duplicate
-
Major - P3
-
None
-
None
-
None
Description
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"} |
}
|
},
|
...
|
]
|
Attachments
Issue Links
- duplicates
-
SERVER-29425 Add an expression to sort an array
-
- Closed
-