From 38c53b82c8c34d5582cc6405bb48b55e97d8dd8b Mon Sep 17 00:00:00 2001 From: Hafez Date: Mon, 11 Jul 2022 14:38:22 +0200 Subject: [PATCH 1/2] test(types): test $let as a possible expression to $addFields --- test/types/PipelineStage.test.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/types/PipelineStage.test.ts b/test/types/PipelineStage.test.ts index 5c97a53fd41..37968a3b366 100644 --- a/test/types/PipelineStage.test.ts +++ b/test/types/PipelineStage.test.ts @@ -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' } + } + } + } + } + } + } + } +]; From 0897fea89af993c7adef63e1bea589db6c7256ed Mon Sep 17 00:00:00 2001 From: Hafez Date: Mon, 11 Jul 2022 14:46:54 +0200 Subject: [PATCH 2/2] fix(types): add $let as a possible expression to $addFields --- types/expressions.d.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/types/expressions.d.ts b/types/expressions.d.ts index 10ee0bf1559..988b0357568 100644 --- a/types/expressions.d.ts +++ b/types/expressions.d.ts @@ -2448,7 +2448,8 @@ declare module 'mongoose' { BinaryExpression | FunctionExpression | ObjectIdExpression | - ConditionalExpressionOperator; + ConditionalExpressionOperator | + Expression.Let; export type ObjectIdExpression = TypeExpressionOperatorReturningObjectId;