Skip to content

Commit

Permalink
Merge pull request #12087 from Automattic/ts-aggregation-let
Browse files Browse the repository at this point in the history
fix(types): add $let as a possible expression to $addFields
  • Loading branch information
vkarpov15 committed Jul 15, 2022
2 parents 3e5fa8c + 0897fea commit c48461a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
23 changes: 23 additions & 0 deletions test/types/PipelineStage.test.ts
Expand Up @@ -392,3 +392,26 @@ const stages3: PipelineStage[] = [
}
}
];

const stages4: PipelineStage[] = [
{
$addFields: {
usersCount: {
$let: {
vars: {
users: { $push: '$user' }
},
in: {
$reduce: {
input: '$users',
initialValue: 0,
in: {
$cond: { if: { $isArray: '$$this' }, then: { $size: '$$this' }, else: '$$this' }
}
}
}
}
}
}
}
];
3 changes: 2 additions & 1 deletion types/expressions.d.ts
Expand Up @@ -2448,7 +2448,8 @@ declare module 'mongoose' {
BinaryExpression |
FunctionExpression |
ObjectIdExpression |
ConditionalExpressionOperator;
ConditionalExpressionOperator |
Expression.Let;

export type ObjectIdExpression =
TypeExpressionOperatorReturningObjectId;
Expand Down

0 comments on commit c48461a

Please sign in to comment.