Details
-
Task
-
Resolution: Unresolved
-
Minor - P4
-
None
-
None
-
Query Execution
Description
It is rather awkward that to get topN array elements, you would do $sortArray+$slice while there's topN accumulator available.
Proposing:
$topN: {input: <expression resolving to array>, n: <n expression>, sortBy: <spec>}
e.g.:
[
|
{
|
$set: {
|
topThreeOptions: {
|
$topN: {
|
input: "$options",
|
n: 3,
|
sortBy: { votes: -1 },
|
},
|
},
|
fiveWatchersAZ: {
|
$topN: {
|
input: "$watchers",
|
n: 5,
|
sortBy: 1
|
},
|
},
|
},
|
},
|
]
|
Attachments
Issue Links
- related to
-
SERVER-59149 Add $top/$bottom/$topN/$bottomN as expressions
-
- Closed
-