Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(types): add $let as a possible expression to $addFields #12087

Merged
merged 2 commits into from Jul 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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