From c07ccd09bcbb0009b78f5aeafb88c7c8ec67ada2 Mon Sep 17 00:00:00 2001 From: Ivan Medina Date: Fri, 3 Jul 2026 10:57:38 -0300 Subject: [PATCH 1/2] feat(mql-typescript): add MongoDB 8.3 arrayIndexAs/as/valueAs to $filter and $reduce MONGOSH-3244 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bumps the mql-specifications submodule and regenerates schema.d.ts. New optional fields (minVersion 8.3): - $filter: arrayIndexAs — exposes current element index in cond - $reduce: as, valueAs, arrayIndexAs — custom names for element, cumulative value, and element index variables NOTE: submodule points to an unmerged branch (MONGOSH-3244-array-index-args). Will be updated to the merge commit once mongodb/mql-specifications#54 merges. --- packages/mql-typescript/mql-specifications | 2 +- packages/mql-typescript/out/schema.d.ts | 24 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/packages/mql-typescript/mql-specifications b/packages/mql-typescript/mql-specifications index 060a5748..a02ba4b8 160000 --- a/packages/mql-typescript/mql-specifications +++ b/packages/mql-typescript/mql-specifications @@ -1 +1 @@ -Subproject commit 060a5748705507b9765055a762bd7c4cb14d793f +Subproject commit a02ba4b86c15d6b0f24cbb1d0ad3dd6e1cfba69d diff --git a/packages/mql-typescript/out/schema.d.ts b/packages/mql-typescript/out/schema.d.ts index 1beedfb1..b084a7b1 100644 --- a/packages/mql-typescript/out/schema.d.ts +++ b/packages/mql-typescript/out/schema.d.ts @@ -1802,6 +1802,12 @@ export namespace Aggregation.Expression { */ as?: string; + /** + * A name for the variable that represents the index of the current element in + * the input array. If specified, this variable is available within the cond expression. + */ + arrayIndexAs?: string; + /** * A number expression that restricts the number of matching array elements that $filter returns. You cannot specify a limit less than 1. The matching array elements are returned in the order they appear in the input array. * If the specified limit is greater than the number of matching array elements, $filter returns all matching array elements. If the limit is null, $filter returns all matching array elements. @@ -2856,6 +2862,24 @@ export namespace Aggregation.Expression { */ initialValue: Expression; + /** + * A name for the variable that represents each individual element of the input array. + * If no name is specified, the variable name defaults to this. + */ + as?: string; + + /** + * A name for the variable that represents the cumulative value of the expression. + * If no name is specified, the variable name defaults to value. + */ + valueAs?: string; + + /** + * A name for the variable that represents the index of the current element in + * the input array. If specified, this variable is available within the in expression. + */ + arrayIndexAs?: string; + /** * A valid expression that $reduce applies to each element in the input array in left-to-right order. Wrap the input value with $reverseArray to yield the equivalent of applying the combining expression from right-to-left. * During evaluation of the in expression, two variables will be available: From 989fb8f210ac7de69ec6368cca1d668766b27deb Mon Sep 17 00:00:00 2001 From: Ivan Medina Date: Fri, 3 Jul 2026 12:53:27 -0300 Subject: [PATCH 2/2] chore(mql-typescript): bump mql-specifications submodule to merged main MONGOSH-3244 Updates submodule from unmerged branch commit to the merged main commit (5b4e863) of mongodb/mql-specifications#54 and regenerates schema.d.ts. --- packages/mql-typescript/mql-specifications | 2 +- packages/mql-typescript/out/schema.d.ts | 58 +++++++++++----------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/packages/mql-typescript/mql-specifications b/packages/mql-typescript/mql-specifications index a02ba4b8..5b4e8630 160000 --- a/packages/mql-typescript/mql-specifications +++ b/packages/mql-typescript/mql-specifications @@ -1 +1 @@ -Subproject commit a02ba4b86c15d6b0f24cbb1d0ad3dd6e1cfba69d +Subproject commit 5b4e8630d5e8a794978b9f4004840f104377a7a9 diff --git a/packages/mql-typescript/out/schema.d.ts b/packages/mql-typescript/out/schema.d.ts index b084a7b1..c8d8ece5 100644 --- a/packages/mql-typescript/out/schema.d.ts +++ b/packages/mql-typescript/out/schema.d.ts @@ -1792,11 +1792,6 @@ export namespace Aggregation.Expression { $filter: { input: ResolvesToArray; - /** - * An expression that resolves to a boolean value used to determine if an element should be included in the output array. The expression references each element of the input array individually with the variable name specified in as. - */ - cond: ResolvesToBool; - /** * A name for the variable that represents each individual element of the input array. If no name is specified, the variable name defaults to this. */ @@ -1808,6 +1803,11 @@ export namespace Aggregation.Expression { */ arrayIndexAs?: string; + /** + * An expression that resolves to a boolean value used to determine if an element should be included in the output array. The expression references each element of the input array individually with the variable name specified in as, and the element index with the variable name specified in arrayIndexAs (MongoDB 8.3+). + */ + cond: ResolvesToBool; + /** * A number expression that restricts the number of matching array elements that $filter returns. You cannot specify a limit less than 1. The matching array elements are returned in the order they appear in the input array. * If the specified limit is greater than the number of matching array elements, $filter returns all matching array elements. If the limit is null, $filter returns all matching array elements. @@ -2862,40 +2862,22 @@ export namespace Aggregation.Expression { */ initialValue: Expression; - /** - * A name for the variable that represents each individual element of the input array. - * If no name is specified, the variable name defaults to this. - */ - as?: string; - - /** - * A name for the variable that represents the cumulative value of the expression. - * If no name is specified, the variable name defaults to value. - */ - valueAs?: string; - - /** - * A name for the variable that represents the index of the current element in - * the input array. If specified, this variable is available within the in expression. - */ - arrayIndexAs?: string; - /** * A valid expression that $reduce applies to each element in the input array in left-to-right order. Wrap the input value with $reverseArray to yield the equivalent of applying the combining expression from right-to-left. * During evaluation of the in expression, two variables will be available: - * - value is the variable that represents the cumulative value of the expression. - * - this is the variable that refers to the element being processed. + * - value is the variable that represents the cumulative value of the expression. Use valueAs (MongoDB 8.3+) to specify a custom name. + * - this is the variable that refers to the element being processed. Use as (MongoDB 8.3+) to specify a custom name. */ in: | Expression< S & { /** - * The variable that refers to the element being processed. + * The variable that refers to the element being processed. Renamed via the as argument (MongoDB 8.3+). */ $this: any; /** - * The variable that represents the cumulative value of the expression. + * The variable that represents the cumulative value of the expression. Renamed via the valueAs argument (MongoDB 8.3+). */ $value: any; } @@ -2903,16 +2885,34 @@ export namespace Aggregation.Expression { | ExpressionMap< S & { /** - * The variable that refers to the element being processed. + * The variable that refers to the element being processed. Renamed via the as argument (MongoDB 8.3+). */ $this: any; /** - * The variable that represents the cumulative value of the expression. + * The variable that represents the cumulative value of the expression. Renamed via the valueAs argument (MongoDB 8.3+). */ $value: any; } >; + + /** + * A name for the variable that represents each individual element of the input array. + * If no name is specified, the variable name defaults to this. + */ + as?: string; + + /** + * A name for the variable that represents the cumulative value of the expression. + * If no name is specified, the variable name defaults to value. + */ + valueAs?: string; + + /** + * A name for the variable that represents the index of the current element in + * the input array. If specified, this variable is available within the in expression. + */ + arrayIndexAs?: string; }; }