Skip to content

Commit aa46617

Browse files
committed
fix(types): add $top and $topN aggregation operators
Fix #12053
1 parent 81c410a commit aa46617

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

test/types/expressions.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ const timewithOffset430DateToString: Expression = { $dateToString: { format: '%H
7878
const minutesOffsetNYDateToString: Expression = { $dateToString: { format: '%Z', date: '$date', timezone: 'America/New_York' } };
7979
const minutesOffset430DateToString: Expression = { $dateToString: { format: '%Z', date: '$date', timezone: '+04:30' } };
8080

81+
const topN: Expression.TopN = {
82+
$topN: {
83+
output: ['$playerId', '$score'],
84+
sortBy: { score: 1 },
85+
n: 3
86+
}
87+
};
88+
8189
const dateSubtract1: Expression = {
8290
$dateSubtract:
8391
{

types/expressions.d.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2316,6 +2316,21 @@ declare module 'mongoose' {
23162316
$toObjectId: Expression;
23172317
}
23182318

2319+
export interface Top {
2320+
$top: {
2321+
sortBy: AnyObject,
2322+
output: Expression
2323+
};
2324+
}
2325+
2326+
export interface TopN {
2327+
$topN: {
2328+
n: Expression,
2329+
sortBy: AnyObject,
2330+
output: Expression
2331+
};
2332+
}
2333+
23192334
export interface ToString {
23202335
/**
23212336
* Converts a value to a string. If the value cannot be converted to a string, $toString errors. If the value is
@@ -2407,6 +2422,8 @@ declare module 'mongoose' {
24072422
AccumulatorOperator |
24082423
VariableExpressionOperator |
24092424
WindowOperator |
2425+
Expression.Top |
2426+
Expression.TopN |
24102427
any;
24112428

24122429
export type NullExpression = null;

0 commit comments

Comments
 (0)