From aa466178a52cb1685f0dfa43e8dd54aa609c8050 Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Tue, 5 Jul 2022 10:31:14 -0400 Subject: [PATCH] fix(types): add $top and $topN aggregation operators Fix #12053 --- test/types/expressions.test.ts | 8 ++++++++ types/expressions.d.ts | 17 +++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/test/types/expressions.test.ts b/test/types/expressions.test.ts index 2ee99e2b82f..ba71d9a2fb8 100644 --- a/test/types/expressions.test.ts +++ b/test/types/expressions.test.ts @@ -78,6 +78,14 @@ const timewithOffset430DateToString: Expression = { $dateToString: { format: '%H const minutesOffsetNYDateToString: Expression = { $dateToString: { format: '%Z', date: '$date', timezone: 'America/New_York' } }; const minutesOffset430DateToString: Expression = { $dateToString: { format: '%Z', date: '$date', timezone: '+04:30' } }; +const topN: Expression.TopN = { + $topN: { + output: ['$playerId', '$score'], + sortBy: { score: 1 }, + n: 3 + } +}; + const dateSubtract1: Expression = { $dateSubtract: { diff --git a/types/expressions.d.ts b/types/expressions.d.ts index be5b5789741..865c26ff319 100644 --- a/types/expressions.d.ts +++ b/types/expressions.d.ts @@ -2316,6 +2316,21 @@ declare module 'mongoose' { $toObjectId: Expression; } + export interface Top { + $top: { + sortBy: AnyObject, + output: Expression + }; + } + + export interface TopN { + $topN: { + n: Expression, + sortBy: AnyObject, + output: Expression + }; + } + export interface ToString { /** * 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' { AccumulatorOperator | VariableExpressionOperator | WindowOperator | + Expression.Top | + Expression.TopN | any; export type NullExpression = null;