-
Type:
Investigation
-
Resolution: Unresolved
-
Priority:
Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
-
None
-
Developer Tools
Original Downstream Change Summary
New expressions for getting top/bottom part of an array
Description of Linked Ticket
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
},
},
},
},
]
- depends on
-
SERVER-72121 Add $top/$bottom/$topN/$bottomN as expressions
-
- Closed
-