Skip to content

Commit

Permalink
fix(types): add $top and $topN aggregation operators
Browse files Browse the repository at this point in the history
Fix #12053
  • Loading branch information
vkarpov15 committed Jul 5, 2022
1 parent 81c410a commit aa46617
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
8 changes: 8 additions & 0 deletions test/types/expressions.test.ts
Expand Up @@ -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:
{
Expand Down
17 changes: 17 additions & 0 deletions types/expressions.d.ts
Expand Up @@ -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
Expand Down Expand Up @@ -2407,6 +2422,8 @@ declare module 'mongoose' {
AccumulatorOperator |
VariableExpressionOperator |
WindowOperator |
Expression.Top |
Expression.TopN |
any;

export type NullExpression = null;
Expand Down

0 comments on commit aa46617

Please sign in to comment.