From 6fc6ffb1996f3836000a3eb9d39528fbc77c954b Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Fri, 27 Feb 2026 09:58:17 +0100 Subject: [PATCH 1/8] fix(mql-typescript): use mql-specifications repository Instead of using a draft pull request as the base for the submodule, switch to using https://github.com/mongodb/mql-specifications. --- .gitmodules | 6 +- packages/mql-typescript/mongo-php-library | 1 - packages/mql-typescript/mql-specifications | 1 + packages/mql-typescript/out/schema.d.ts | 466 ++++++++++++++---- packages/mql-typescript/package.json | 4 +- packages/mql-typescript/src/generator.ts | 5 +- packages/mql-typescript/src/metaschema.ts | 28 +- .../mql-typescript/src/schema-generator.ts | 3 + 8 files changed, 396 insertions(+), 118 deletions(-) delete mode 160000 packages/mql-typescript/mongo-php-library create mode 160000 packages/mql-typescript/mql-specifications diff --git a/.gitmodules b/.gitmodules index 5f09a786..3f7efd4c 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ -[submodule "packages/mql-typescript/mongo-php-library"] - path = packages/mql-typescript/mongo-php-library - url = https://github.com/mongodb-js/mongo-php-library +[submodule "packages/mql-typescript/mql-specifications"] + path = packages/mql-typescript/mql-specifications + url = https://github.com/mongodb/mql-specifications.git diff --git a/packages/mql-typescript/mongo-php-library b/packages/mql-typescript/mongo-php-library deleted file mode 160000 index 4a2867b1..00000000 --- a/packages/mql-typescript/mongo-php-library +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 4a2867b1267c96190ccf7e813f21a9d7a00236cc diff --git a/packages/mql-typescript/mql-specifications b/packages/mql-typescript/mql-specifications new file mode 160000 index 00000000..67983635 --- /dev/null +++ b/packages/mql-typescript/mql-specifications @@ -0,0 +1 @@ +Subproject commit 679836355dd5671b50b4a010698b659eb7e7107b diff --git a/packages/mql-typescript/out/schema.d.ts b/packages/mql-typescript/out/schema.d.ts index 9163ee0d..1335457a 100644 --- a/packages/mql-typescript/out/schema.d.ts +++ b/packages/mql-typescript/out/schema.d.ts @@ -33,7 +33,6 @@ export namespace Aggregation.Accumulator { export interface $accumulator { /** * Defines a custom accumulator function. - * New in MongoDB 4.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/accumulator/} */ $accumulator: { @@ -107,7 +106,6 @@ export namespace Aggregation.Accumulator { export interface $bottom { /** * Returns the bottom element within a group according to the specified sort order. - * New in MongoDB 5.2: Available in the $group and $setWindowFields stages. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/bottom/} */ $bottom: { @@ -130,7 +128,6 @@ export namespace Aggregation.Accumulator { export interface $bottomN { /** * Returns an aggregation of the bottom n elements within a group, according to the specified sort order. If the group contains fewer than n elements, $bottomN returns all elements in the group. - * New in MongoDB 5.2. * Available in the $group and $setWindowFields stages. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/bottomN/} */ @@ -152,6 +149,24 @@ export namespace Aggregation.Accumulator { }; } + /** + * A type describing the `$concatArrays` operator. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/concatArrays/} + */ + export interface $concatArrays { + /** + * Concatenates arrays to return the concatenated array. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/concatArrays/} + */ + $concatArrays: [ + /** + * An array of expressions that resolve to an array. + * If any argument resolves to a value of null or refers to a field that is missing, `$concatArrays` returns `null`. + */ + ...ResolvesToArray[], + ]; + } + /** * A type describing the `$count` operator. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/count-accumulator/} @@ -160,7 +175,6 @@ export namespace Aggregation.Accumulator { /** * Returns the number of documents in the group or window. * Distinct from the $count pipeline stage. - * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/count-accumulator/} */ $count: Record; @@ -173,7 +187,6 @@ export namespace Aggregation.Accumulator { export interface $covariancePop { /** * Returns the population covariance of two numeric expressions. - * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/covariancePop/} */ $covariancePop: [ @@ -189,7 +202,6 @@ export namespace Aggregation.Accumulator { export interface $covarianceSamp { /** * Returns the sample covariance of two numeric expressions. - * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/covarianceSamp/} */ $covarianceSamp: [ @@ -205,7 +217,6 @@ export namespace Aggregation.Accumulator { export interface $denseRank { /** * Returns the document position (known as the rank) relative to other documents in the $setWindowFields stage partition. There are no gaps in the ranks. Ties receive the same rank. - * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/denseRank/} */ $denseRank: Record; @@ -218,7 +229,6 @@ export namespace Aggregation.Accumulator { export interface $derivative { /** * Returns the average rate of change within the specified window. - * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/derivative/} */ $derivative: { @@ -239,7 +249,6 @@ export namespace Aggregation.Accumulator { export interface $documentNumber { /** * Returns the position of a document (known as the document number) in the $setWindowFields stage partition. Ties result in different adjacent document numbers. - * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/documentNumber/} */ $documentNumber: Record; @@ -252,7 +261,6 @@ export namespace Aggregation.Accumulator { export interface $expMovingAvg { /** * Returns the exponential moving average for the numeric expression. - * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/expMovingAvg/} */ $expMovingAvg: { @@ -317,7 +325,6 @@ export namespace Aggregation.Accumulator { export interface $integral { /** * Returns the approximation of the area under a curve. - * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/integral/} */ $integral: { @@ -359,7 +366,7 @@ export namespace Aggregation.Accumulator { /** * An expression that resolves to the array from which to return n elements. */ - input: Expression; + input: ResolvesToArray; /** * An expression that resolves to a positive integer. The integer specifies the number of array elements that $firstN returns. @@ -376,7 +383,6 @@ export namespace Aggregation.Accumulator { /** * Fills null and missing fields in a window using linear interpolation based on surrounding field values. * Available in the $setWindowFields stage. - * New in MongoDB 5.3. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/linearFill/} */ $linearFill: ResolvesToNumber; @@ -390,7 +396,6 @@ export namespace Aggregation.Accumulator { /** * Last observation carried forward. Sets values for null and missing fields in a window to the last non-null value for the field. * Available in the $setWindowFields stage. - * New in MongoDB 5.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/locf/} */ $locf: Expression; @@ -438,7 +443,6 @@ export namespace Aggregation.Accumulator { export interface $median { /** * Returns an approximation of the median, the 50th percentile, as a scalar value. - * New in MongoDB 7.0. * This operator is available as an accumulator in these stages: * $group * $setWindowFields @@ -512,7 +516,6 @@ export namespace Aggregation.Accumulator { export interface $percentile { /** * Returns an array of scalar values that correspond to specified percentile values. - * New in MongoDB 7.0. * This operator is available as an accumulator in these stages: * $group * $setWindowFields @@ -558,12 +561,28 @@ export namespace Aggregation.Accumulator { export interface $rank { /** * Returns the document position (known as the rank) relative to other documents in the $setWindowFields stage partition. - * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/rank/} */ $rank: Record; } + /** + * A type describing the `$setUnion` operator. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/setUnion/} + */ + export interface $setUnion { + /** + * Takes two or more arrays and returns an array containing the elements that appear in any input array. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/setUnion/} + */ + $setUnion: [ + /** + * An array of expressions that resolve to an array. + */ + ...ResolvesToArray[], + ]; + } + /** * A type describing the `$shift` operator. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/shift/} @@ -571,7 +590,6 @@ export namespace Aggregation.Accumulator { export interface $shift { /** * Returns the value from an expression applied to a document in a specified position relative to the current document in the $setWindowFields stage partition. - * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/shift/} */ $shift: { @@ -646,7 +664,6 @@ export namespace Aggregation.Accumulator { export interface $top { /** * Returns the top element within a group according to the specified sort order. - * New in MongoDB 5.2. * Available in the $group and $setWindowFields stages. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/top/} */ @@ -670,7 +687,6 @@ export namespace Aggregation.Accumulator { export interface $topN { /** * Returns an aggregation of the top n fields within a group, according to the specified sort order. - * New in MongoDB 5.2. * Available in the $group and $setWindowFields stages. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/topN/} */ @@ -914,7 +930,6 @@ export namespace Aggregation.Expression { export interface $bitAnd { /** * Returns the result of a bitwise and operation on an array of int or long values. - * New in MongoDB 6.3. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitAnd/} */ $bitAnd: [...(ResolvesToInt | ResolvesToLong)[]]; @@ -927,7 +942,6 @@ export namespace Aggregation.Expression { export interface $bitNot { /** * Returns the result of a bitwise not operation on a single argument or an array that contains a single int or long value. - * New in MongoDB 6.3. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitNot/} */ $bitNot: ResolvesToInt | ResolvesToLong; @@ -940,7 +954,6 @@ export namespace Aggregation.Expression { export interface $bitOr { /** * Returns the result of a bitwise or operation on an array of int or long values. - * New in MongoDB 6.3. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitOr/} */ $bitOr: [...(ResolvesToInt | ResolvesToLong)[]]; @@ -953,7 +966,6 @@ export namespace Aggregation.Expression { export interface $bitXor { /** * Returns the result of a bitwise xor (exclusive or) operation on an array of int and long values. - * New in MongoDB 6.3. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitXor/} */ $bitXor: [...(ResolvesToInt | ResolvesToLong)[]]; @@ -1060,7 +1072,6 @@ export namespace Aggregation.Expression { export interface $convert { /** * Converts a value to a specified type. - * New in MongoDB 4.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/convert/} */ $convert: { @@ -1105,6 +1116,18 @@ export namespace Aggregation.Expression { $cosh: ResolvesToNumber; } + /** + * A type describing the `$createObjectId` operator. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/createObjectId/} + */ + export interface $createObjectId { + /** + * Returns a random object ID + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/createObjectId/} + */ + $createObjectId: Record; + } + /** * A type describing the `$dateAdd` operator. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateAdd/} @@ -1621,7 +1644,6 @@ export namespace Aggregation.Expression { export interface $function { /** * Defines a custom function. - * New in MongoDB 4.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/function/} */ $function: { @@ -1646,7 +1668,6 @@ export namespace Aggregation.Expression { export interface $getField { /** * Returns the value of a specified field from a document. You can use $getField to retrieve the value of fields with names that contain periods (.) or start with dollar signs ($). - * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/getField/} */ $getField: { @@ -1868,7 +1889,6 @@ export namespace Aggregation.Expression { /** * Returns boolean true if the specified expression resolves to an integer, decimal, double, or long. * Returns boolean false if the expression resolves to any other BSON type, null, or a missing field. - * New in MongoDB 4.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/isNumber/} */ $isNumber: Expression; @@ -1954,12 +1974,12 @@ export namespace Aggregation.Expression { /** * A type describing the `$lastN` operator. - * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/lastN/#array-operator} + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/lastN-array-element/} */ export interface $lastN { /** * Returns a specified number of elements from the end of an array. - * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/lastN/#array-operator} + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/lastN-array-element/} */ $lastN: { /** @@ -1989,7 +2009,7 @@ export namespace Aggregation.Expression { * Assignment block for the variables accessible in the in expression. To assign a variable, specify a string for the variable name and assign a valid expression for the value. * The variable assignments have no meaning outside the in expression, not even within the vars block itself. */ - vars: ExpressionMap; + vars: Record; /** * The expression to evaluate. @@ -2088,7 +2108,6 @@ export namespace Aggregation.Expression { export interface $ltrim { /** * Removes whitespace or the specified characters from the beginning of a string. - * New in MongoDB 4.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/ltrim/} */ $ltrim: { @@ -2175,7 +2194,6 @@ export namespace Aggregation.Expression { export interface $median { /** * Returns an approximation of the median, the 50th percentile, as a scalar value. - * New in MongoDB 7.0. * This operator is available as an accumulator in these stages: * $group * $setWindowFields @@ -2416,7 +2434,6 @@ export namespace Aggregation.Expression { export interface $percentile { /** * Returns an array of scalar values that correspond to specified percentile values. - * New in MongoDB 7.0. * This operator is available as an accumulator in these stages: * $group * $setWindowFields @@ -2533,33 +2550,19 @@ export namespace Aggregation.Expression { * - value is the variable that represents the cumulative value of the expression. * - this is the variable that refers to the element being processed. */ - in: - | Expression< - S & { - /** - * The variable that represents the cumulative value of the expression. - */ - $this: any; - - /** - * The variable that refers to the element being processed. - */ - $value: any; - } - > - | ExpressionMap< - S & { - /** - * The variable that represents the cumulative value of the expression. - */ - $this: any; - - /** - * The variable that refers to the element being processed. - */ - $value: any; - } - >; + in: Expression< + S & { + /** + * The variable that refers to the element being processed. + */ + $this: any; + + /** + * The variable that represents the cumulative value of the expression. + */ + $value: any; + } + >; }; } @@ -2570,7 +2573,6 @@ export namespace Aggregation.Expression { export interface $regexFind { /** * Applies a regular expression (regex) to a string and returns information on the first matched substring. - * New in MongoDB 4.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/regexFind/} */ $regexFind: { @@ -2594,7 +2596,6 @@ export namespace Aggregation.Expression { export interface $regexFindAll { /** * Applies a regular expression (regex) to a string and returns information on the all matched substrings. - * New in MongoDB 4.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/regexFindAll/} */ $regexFindAll: { @@ -2618,7 +2619,6 @@ export namespace Aggregation.Expression { export interface $regexMatch { /** * Applies a regular expression (regex) to a string and returns a boolean that indicates if a match is found or not. - * New in MongoDB 4.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/regexMatch/} */ $regexMatch: { @@ -2643,7 +2643,6 @@ export namespace Aggregation.Expression { /** * Replaces all instances of a search string in an input string with a replacement string. * $replaceAll is both case-sensitive and diacritic-sensitive, and ignores any collation present on a collection. - * New in MongoDB 4.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceAll/} */ $replaceAll: { @@ -2655,7 +2654,7 @@ export namespace Aggregation.Expression { /** * The string to search for within the given input. Can be any valid expression that resolves to a string or a null. If find refers to a field that is missing, $replaceAll returns null. */ - find: ResolvesToString | ResolvesToNull; + find: ResolvesToString | ResolvesToNull | ResolvesToRegex; /** * The string to use to replace all matched instances of find in input. Can be any valid expression that resolves to a string or a null. @@ -2671,7 +2670,6 @@ export namespace Aggregation.Expression { export interface $replaceOne { /** * Replaces the first instance of a matched string in a given input. - * New in MongoDB 4.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceOne/} */ $replaceOne: { @@ -2814,7 +2812,6 @@ export namespace Aggregation.Expression { export interface $setField { /** * Adds, updates, or removes a specified field in a document. You can use $setField to add, update, or remove fields with names that contain periods (.) or start with dollar signs ($). - * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/setField/} */ $setField: { @@ -2998,7 +2995,7 @@ export namespace Aggregation.Expression { /** * The delimiter to use when splitting the string expression. delimiter can be any valid expression as long as it resolves to a string. */ - delimiter: ResolvesToString, + delimiter: ResolvesToString | ResolvesToRegex, ]; } @@ -3237,7 +3234,6 @@ export namespace Aggregation.Expression { export interface $toBool { /** * Converts value to a boolean. - * New in MongoDB 4.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/toBool/} */ $toBool: Expression; @@ -3250,7 +3246,6 @@ export namespace Aggregation.Expression { export interface $toDate { /** * Converts value to a Date. - * New in MongoDB 4.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/toDate/} */ $toDate: Expression; @@ -3263,7 +3258,6 @@ export namespace Aggregation.Expression { export interface $toDecimal { /** * Converts value to a Decimal128. - * New in MongoDB 4.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/toDecimal/} */ $toDecimal: Expression; @@ -3276,7 +3270,6 @@ export namespace Aggregation.Expression { export interface $toDouble { /** * Converts value to a double. - * New in MongoDB 4.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/toDouble/} */ $toDouble: Expression; @@ -3301,7 +3294,6 @@ export namespace Aggregation.Expression { export interface $toInt { /** * Converts value to an integer. - * New in MongoDB 4.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/toInt/} */ $toInt: Expression; @@ -3314,7 +3306,6 @@ export namespace Aggregation.Expression { export interface $toLong { /** * Converts value to a long. - * New in MongoDB 4.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/toLong/} */ $toLong: Expression; @@ -3339,7 +3330,6 @@ export namespace Aggregation.Expression { export interface $toObjectId { /** * Converts value to an ObjectId. - * New in MongoDB 4.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/toObjectId/} */ $toObjectId: Expression; @@ -3352,7 +3342,6 @@ export namespace Aggregation.Expression { export interface $toString { /** * Converts value to a string. - * New in MongoDB 4.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/toString/} */ $toString: Expression; @@ -3377,7 +3366,6 @@ export namespace Aggregation.Expression { export interface $trim { /** * Removes whitespace or the specified characters from the beginning and end of a string. - * New in MongoDB 4.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/trim/} */ $trim: { @@ -3425,7 +3413,6 @@ export namespace Aggregation.Expression { export interface $tsIncrement { /** * Returns the incrementing ordinal from a timestamp as a long. - * New in MongoDB 5.1. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/tsIncrement/} */ $tsIncrement: ResolvesToTimestamp; @@ -3438,7 +3425,6 @@ export namespace Aggregation.Expression { export interface $tsSecond { /** * Returns the seconds from a timestamp as a long. - * New in MongoDB 5.1. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/tsSecond/} */ $tsSecond: ResolvesToTimestamp; @@ -3664,6 +3650,18 @@ export namespace Aggregation.Query { $centerSphere: unknown[]; } + /** + * A type describing the `$comment` operator. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/comment/} + */ + export interface $comment { + /** + * Adds a comment to a query predicate. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/comment/} + */ + $comment: string; + } + /** * A type describing the `$elemMatch` operator. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/elemMatch/} @@ -3685,7 +3683,7 @@ export namespace Aggregation.Query { * Matches values that are equal to a specified value. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/eq/} */ - $eq: Expression; + $eq: any; } /** @@ -4499,7 +4497,6 @@ export namespace Aggregation.Stage { /** * Specifies whether to include additional change events, such as such as DDL and index operations. - * New in MongoDB 6.0. */ showExpandedEvents?: boolean; @@ -4796,7 +4793,7 @@ export namespace Aggregation.Stage { /** * The _id expression specifies the group key. If you specify an _id value of null, or any other constant value, the $group stage returns a single document that aggregates values across all of the input documents. */ - _id: Expression | ExpressionMap; + _id: Expression; }, /** * Computed using the accumulator operators. @@ -4944,7 +4941,7 @@ export namespace Aggregation.Stage { * The pipeline cannot include the $out stage or the $merge stage. Starting in v6.0, the pipeline can contain the Atlas Search $search stage as the first stage inside the pipeline. * The pipeline cannot directly access the joined document fields. Instead, define variables for the joined document fields using the let option and then reference the variables in the pipeline stages. */ - pipeline?: UntypedPipeline; + pipeline?: Pipeline; /** * Specifies the name of the new array field to add to the input documents. The new array field contains the matching documents from the from collection. If the specified name already exists in the input document, the existing field is overwritten. @@ -4972,7 +4969,6 @@ export namespace Aggregation.Stage { export interface $merge { /** * Writes the resulting documents of the aggregation pipeline to a collection. The stage can incorporate (insert new documents, merge documents, replace documents, keep existing documents, fail the operation, process documents with a custom update pipeline) the results into an output collection. To use the $merge stage, it must be the last stage in the pipeline. - * New in MongoDB 4.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/} */ $merge: { @@ -4994,7 +4990,7 @@ export namespace Aggregation.Stage { /** * The behavior of $merge if a result document and an existing document in the collection have the same value for the specified on field(s). */ - whenMatched?: WhenMatched | UntypedPipeline; + whenMatched?: WhenMatched | Pipeline; /** * The behavior of $merge if a result document does not match an existing document in the out collection. @@ -5036,9 +5032,7 @@ export namespace Aggregation.Stage { * Reshapes each document in the stream, such as by adding new fields or removing existing fields. For each input document, outputs one document. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/project/} */ - $project: {} & { - [specification: string]: Expression | ExpressionMap; - }; + $project: {} & { [specification: string]: Expression }; } /** @@ -5095,6 +5089,38 @@ export namespace Aggregation.Stage { }; } + /** + * A type describing the `$scoreFusion` operator. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/scoreFusion/} + */ + export interface $scoreFusion { + /** + * Combines multiple pipelines using relative score fusion to create hybrid search results. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/scoreFusion/} + */ + $scoreFusion: { + /** + * An object with the following required fields: + * - input.pipelines: Map from name to input pipeline. Each pipeline must be operating on the same collection. Minimum of one pipeline. + * - input.normalization: Normalizes the score to the range 0 to 1 before combining the results. Value can be none, sigmoid or minMaxScaler. + */ + input: Record; + + /** + * An object with the following optional fields: + * - combination.weights: Map from pipeline name to numbers (non-negative). If unspecified, default weight is 1 for each pipeline. + * - combination.method: Specifies method for combining scores. Value can be avg or expression. Default is avg. + * - combination.expression: This is the custom expression that is used when combination.method is set to expression. + */ + combination?: Record; + + /** + * Set to true to include detailed scoring information. + */ + scoreDetails: boolean; + }; + } + /** * A type describing the `$search` operator. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/search/} @@ -5114,7 +5140,7 @@ export namespace Aggregation.Stage { /** * Specifies the highlighting options for displaying search terms in their original context. */ - highlight?: SearchHighlight; + highlight?: Record; /** * Parallelize search across segments on dedicated search nodes. @@ -5203,7 +5229,6 @@ export namespace Aggregation.Stage { export interface $setWindowFields { /** * Groups documents into windows and applies one or more operators to the documents in each window. - * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/setWindowFields/} */ $setWindowFields: { @@ -5232,7 +5257,6 @@ export namespace Aggregation.Stage { export interface $shardedDataDistribution { /** * Provides data and size distribution information on sharded collections. - * New in MongoDB 6.0.3. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/shardedDataDistribution/} */ $shardedDataDistribution: Record; @@ -5281,7 +5305,6 @@ export namespace Aggregation.Stage { export interface $unionWith { /** * Performs a union of two collections; i.e. combines pipeline results from two collections into a single result set. - * New in MongoDB 4.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/unionWith/} */ $unionWith: { @@ -5294,7 +5317,7 @@ export namespace Aggregation.Stage { * An aggregation pipeline to apply to the specified coll. * The pipeline cannot include the $out and $merge stages. Starting in v6.0, the pipeline can contain the Atlas Search $search stage as the first stage inside the pipeline. */ - pipeline?: UntypedPipeline; + pipeline?: Pipeline; }; } @@ -5388,12 +5411,207 @@ export namespace Aggregation.Stage { }; } } +export namespace Aggregation.Update { + /** + * A type describing the `$addToSet` operator. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/update/addToSet/} + */ + export interface $addToSet { + /** + * Adds a value to an array unless the value is already present. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/update/addToSet/} + */ + $addToSet: {} & { [field: string]: any }; + } + + /** + * A type describing the `$bit` operator. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/update/bit/} + */ + export interface $bit { + /** + * Performs bitwise updates of integer values. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/update/bit/} + */ + $bit: { + /** + * Each field maps to an object containing exactly one bitwise operation: + * and, or, or xor. + */ + } & { [field: string]: BitwiseOperation }; + } + + /** + * A type describing the `$currentDate` operator. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/update/currentDate/} + */ + export interface $currentDate { + /** + * Sets the value of a field to the current date as either a Date or Timestamp. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/update/currentDate/} + */ + $currentDate: { + /** + * The value for each field can be either: + * - true, to set the field to the current date. + * - a document with $type set to "date" or "timestamp". + */ + } & { [field: string]: boolean | Record }; + } + + /** + * A type describing the `$inc` operator. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/update/inc/} + */ + export interface $inc { + /** + * Increments a field by the specified numeric amount. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/update/inc/} + */ + $inc: {} & { [field: string]: Number }; + } + + /** + * A type describing the `$max` operator. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/update/max/} + */ + export interface $max { + /** + * Updates a field only if the specified value is greater than the current field value. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/update/max/} + */ + $max: {} & { [field: string]: any }; + } + + /** + * A type describing the `$min` operator. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/update/min/} + */ + export interface $min { + /** + * Updates a field only if the specified value is less than the current field value. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/update/min/} + */ + $min: {} & { [field: string]: any }; + } + + /** + * A type describing the `$mul` operator. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/update/mul/} + */ + export interface $mul { + /** + * Multiplies the value of a field by the specified number. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/update/mul/} + */ + $mul: {} & { [field: string]: Number }; + } + + /** + * A type describing the `$pop` operator. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/update/pop/} + */ + export interface $pop { + /** + * Removes the first or last element of an array. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/update/pop/} + */ + $pop: {} & { [field: string]: Int }; + } + + /** + * A type describing the `$pull` operator. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/update/pull/} + */ + export interface $pull { + /** + * Removes all array elements that match a specified value or condition. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/update/pull/} + */ + $pull: {} & { [field: string]: any }; + } + + /** + * A type describing the `$pullAll` operator. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/update/pullAll/} + */ + export interface $pullAll { + /** + * Removes all matching values from an array. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/update/pullAll/} + */ + $pullAll: {} & { [field: string]: unknown[] }; + } + + /** + * A type describing the `$push` operator. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/update/push/} + */ + export interface $push { + /** + * Appends a specified value to an array, with optional modifiers. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/update/push/} + */ + $push: {} & { [field: string]: any }; + } + + /** + * A type describing the `$rename` operator. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/update/rename/} + */ + export interface $rename { + /** + * Renames a field. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/update/rename/} + */ + $rename: {} & { [field: string]: string }; + } + + /** + * A type describing the `$set` operator. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/update/set/} + */ + export interface $set { + /** + * Sets the value of a field. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/update/set/} + */ + $set: {} & { [field: string]: any }; + } + + /** + * A type describing the `$setOnInsert` operator. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/update/setOnInsert/} + */ + export interface $setOnInsert { + /** + * Sets the value of a field if an update with upsert creates a new document. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/update/setOnInsert/} + */ + $setOnInsert: {} & { [field: string]: any }; + } + + /** + * A type describing the `$unset` operator. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/update/unset/} + */ + export interface $unset { + /** + * Removes the specified field from a document. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/update/unset/} + */ + $unset: {} & { [field: string]: any }; + } +} -export type Int = number | bson.Int32; -export type Double = number | bson.Double; -export type Decimal = bson.Decimal128; -export type Regex = RegExp | bson.BSONRegExp; -export type Long = bigint | bson.Long; +export type Int = number | bson.Int32 | { $numberInt: string }; +export type Double = number | bson.Double | { $numberDouble: string }; +export type Decimal = bson.Decimal128 | { $numberDecimal: string }; +export type Regex = + | RegExp + | bson.BSONRegExp + | { pattern: string; options?: string }; +export type Long = bigint | bson.Long | { $numberLong: string }; export type Javascript = bson.Code | Function | string; export type Geometry = | { type: 'Point'; coordinates: number[] } @@ -5423,6 +5641,10 @@ export type SearchPath = | UnprefixedFieldPath | UnprefixedFieldPath[] | { wildcard: string }; +export type BitwiseOperation = + | { and: Int | Long } + | { or: Int | Long } + | { xor: Int | Long }; export type SearchScore = unknown; export type Granularity = string; export type FullDocument = string; @@ -5487,6 +5709,7 @@ export type Stage = | Aggregation.Stage.$replaceRoot | Aggregation.Stage.$replaceWith | Aggregation.Stage.$sample + | Aggregation.Stage.$scoreFusion | Aggregation.Stage.$search | Aggregation.Stage.$searchMeta | Aggregation.Stage.$set @@ -5505,6 +5728,7 @@ export type Query = | QueryOperator | Partial<{ [k in keyof S]: Condition }> | Aggregation.Query.$and + | Aggregation.Query.$comment | Aggregation.Query.$expr | Aggregation.Query.$jsonSchema | Aggregation.Query.$nor @@ -5518,6 +5742,7 @@ export type Accumulator = | Aggregation.Accumulator.$avg | Aggregation.Accumulator.$bottom | Aggregation.Accumulator.$bottomN + | Aggregation.Accumulator.$concatArrays | Aggregation.Accumulator.$count | Aggregation.Accumulator.$first | Aggregation.Accumulator.$firstN @@ -5531,6 +5756,7 @@ export type Accumulator = | Aggregation.Accumulator.$minN | Aggregation.Accumulator.$percentile | Aggregation.Accumulator.$push + | Aggregation.Accumulator.$setUnion | Aggregation.Accumulator.$stdDevPop | Aggregation.Accumulator.$stdDevSamp | Aggregation.Accumulator.$sum @@ -5646,6 +5872,8 @@ export type ResolvesToArray = | ResolvesToAny | ArrayFieldPath | unknown[] + | Aggregation.Accumulator.$concatArrays + | Aggregation.Accumulator.$setUnion | Aggregation.Expression.$concatArrays | Aggregation.Expression.$filter | Aggregation.Expression.$firstN @@ -5673,6 +5901,7 @@ export type ResolvesToObjectId = | ResolvesToAny | ObjectIdFieldPath | bson.ObjectId + | Aggregation.Expression.$createObjectId | Aggregation.Expression.$toObjectId; export type ResolvesToBool = | ResolvesToAny @@ -5804,6 +6033,7 @@ export type AccumulatorOperator = | Aggregation.Accumulator.$avg | Aggregation.Accumulator.$bottom | Aggregation.Accumulator.$bottomN + | Aggregation.Accumulator.$concatArrays | Aggregation.Accumulator.$count | Aggregation.Accumulator.$covariancePop | Aggregation.Accumulator.$covarianceSamp @@ -5827,6 +6057,7 @@ export type AccumulatorOperator = | Aggregation.Accumulator.$percentile | Aggregation.Accumulator.$push | Aggregation.Accumulator.$rank + | Aggregation.Accumulator.$setUnion | Aggregation.Accumulator.$shift | Aggregation.Accumulator.$stdDevPop | Aggregation.Accumulator.$stdDevSamp @@ -5838,6 +6069,7 @@ export type Window = | Aggregation.Accumulator.$avg | Aggregation.Accumulator.$bottom | Aggregation.Accumulator.$bottomN + | Aggregation.Accumulator.$concatArrays | Aggregation.Accumulator.$count | Aggregation.Accumulator.$covariancePop | Aggregation.Accumulator.$covarianceSamp @@ -5860,6 +6092,7 @@ export type Window = | Aggregation.Accumulator.$percentile | Aggregation.Accumulator.$push | Aggregation.Accumulator.$rank + | Aggregation.Accumulator.$setUnion | Aggregation.Accumulator.$shift | Aggregation.Accumulator.$stdDevPop | Aggregation.Accumulator.$stdDevSamp @@ -5895,6 +6128,7 @@ export type ExpressionOperator = | Aggregation.Expression.$convert | Aggregation.Expression.$cos | Aggregation.Expression.$cosh + | Aggregation.Expression.$createObjectId | Aggregation.Expression.$dateAdd | Aggregation.Expression.$dateDiff | Aggregation.Expression.$dateFromParts @@ -6071,6 +6305,7 @@ export type QueryOperator = | Aggregation.Query.$box | Aggregation.Query.$center | Aggregation.Query.$centerSphere + | Aggregation.Query.$comment | Aggregation.Query.$elemMatch | Aggregation.Query.$eq | Aggregation.Query.$exists @@ -6152,6 +6387,7 @@ export type StageOperator = | Aggregation.Stage.$replaceRoot | Aggregation.Stage.$replaceWith | Aggregation.Stage.$sample + | Aggregation.Stage.$scoreFusion | Aggregation.Stage.$search | Aggregation.Stage.$searchMeta | Aggregation.Stage.$set @@ -6164,3 +6400,35 @@ export type StageOperator = | Aggregation.Stage.$unset | Aggregation.Stage.$unwind | Aggregation.Stage.$vectorSearch; +export type Update = + | Aggregation.Update.$addToSet + | Aggregation.Update.$bit + | Aggregation.Update.$currentDate + | Aggregation.Update.$inc + | Aggregation.Update.$max + | Aggregation.Update.$min + | Aggregation.Update.$mul + | Aggregation.Update.$pop + | Aggregation.Update.$pull + | Aggregation.Update.$pullAll + | Aggregation.Update.$push + | Aggregation.Update.$rename + | Aggregation.Update.$set + | Aggregation.Update.$setOnInsert + | Aggregation.Update.$unset; +export type UpdateOperator = + | Aggregation.Update.$addToSet + | Aggregation.Update.$bit + | Aggregation.Update.$currentDate + | Aggregation.Update.$inc + | Aggregation.Update.$max + | Aggregation.Update.$min + | Aggregation.Update.$mul + | Aggregation.Update.$pop + | Aggregation.Update.$pull + | Aggregation.Update.$pullAll + | Aggregation.Update.$push + | Aggregation.Update.$rename + | Aggregation.Update.$set + | Aggregation.Update.$setOnInsert + | Aggregation.Update.$unset; diff --git a/packages/mql-typescript/package.json b/packages/mql-typescript/package.json index f7d55363..ae781580 100644 --- a/packages/mql-typescript/package.json +++ b/packages/mql-typescript/package.json @@ -57,7 +57,7 @@ "check-ci": "npm run check", "test": "tsc --noEmit tests/**/*.ts", "reformat": "npm run prettier -- --write .", - "extract-metaschema": "json-refs resolve mongo-php-library/generator/config/schema.json | json-schema-to-zod -n Operator -o src/metaschema.ts && npm run prettier -- --write src/metaschema.ts", + "extract-metaschema": "json-refs resolve mql-specifications/schema.json | json-schema-to-zod -n Operator -o src/metaschema.ts && npm run prettier -- --write src/metaschema.ts", "pregenerate-schema": "npm run extract-metaschema", "generate-schema": "ts-node src/cli.ts schema", "postgenerate-schema": "npm run prettier -- --write out/*", @@ -66,7 +66,7 @@ "postgenerate-tests": "npm run prettier -- --write tests/**/*.ts", "pregenerate-driver-schema": "npm run extract-metaschema", "generate-driver-schema": "ts-node src/cli.ts driver-schema", - "postgenerate-driver-schema": "yamlfix -c mongo-php-library/generator/config/.yamlfix.toml mongo-php-library/generator/config", + "postgenerate-driver-schema": "yamlfix -c mql-specifications/.yamlfix.toml mql-specifications/definitions", "format-generated-files": "npm run postgenerate-schema && npm run postgenerate-tests && npm run postgenerate-driver-schema" }, "devDependencies": { diff --git a/packages/mql-typescript/src/generator.ts b/packages/mql-typescript/src/generator.ts index a8591d3e..763cc91b 100644 --- a/packages/mql-typescript/src/generator.ts +++ b/packages/mql-typescript/src/generator.ts @@ -196,9 +196,8 @@ export abstract class GeneratorBase { protected configDir = path.join( __dirname, '..', - 'mongo-php-library', - 'generator', - 'config', + 'mql-specifications', + 'definitions', ); private async *listCategories( diff --git a/packages/mql-typescript/src/metaschema.ts b/packages/mql-typescript/src/metaschema.ts index d8b44d46..c680d316 100644 --- a/packages/mql-typescript/src/metaschema.ts +++ b/packages/mql-typescript/src/metaschema.ts @@ -3,12 +3,14 @@ import { z } from 'zod'; export const Operator = z .object({ name: z.string().regex(new RegExp('^\\$?[a-z][a-zA-Z0-9]*$')), + minVersion: z.string().regex(new RegExp('^[0-9]+\\.[0-9]+(\\.[0-9]+)?$')), link: z.string().url().regex(new RegExp('^https://')), type: z.array( z.enum([ 'accumulator', 'stage', 'query', + 'update', 'fieldQuery', 'filter', 'window', @@ -42,22 +44,22 @@ export const Operator = z z .object({ name: z.string().regex(new RegExp('^([_$]?[a-z][a-zA-Z0-9]*|N)$')), + minVersion: z + .string() + .regex(new RegExp('^[0-9]+\\.[0-9]+(\\.[0-9]+)?$')) + .optional(), type: z.array( z.enum([ 'accumulator', 'query', 'fieldQuery', 'pipeline', - 'untypedPipeline', 'window', 'expression', - 'expressionMap', 'geometry', - 'fieldPath', 'unprefixedFieldPath', 'timeUnit', 'sortSpec', - 'any', 'granularity', 'fullDocument', 'fullDocumentBeforeChange', @@ -68,6 +70,9 @@ export const Operator = z 'range', 'sortBy', 'geoPoint', + 'resolvesToAny', + 'fieldPath', + 'any', 'resolvesToNumber', 'numberFieldPath', 'number', @@ -118,8 +123,8 @@ export const Operator = z 'decimal', 'searchPath', 'searchScore', + 'bitwiseOperation', 'searchOperator', - 'searchHighlight', ]), ), description: z.string().optional(), @@ -135,7 +140,7 @@ export const Operator = z syntheticVariables: z .array( z.object({ - name: z.string().regex(new RegExp('^[$]?[a-zA-Z0-9]*$')), + name: z.string().regex(new RegExp('^[$]?[a-zA-Z0-9]+$')), description: z.string().optional(), }), ) @@ -148,12 +153,13 @@ export const Operator = z .array( z .object({ - name: z.string(), + name: z.string().optional(), link: z.string().url().regex(new RegExp('^https://')).optional(), - pipeline: z.array(z.record(z.any())), + pipeline: z.array(z.record(z.any())).optional(), + filter: z.record(z.any()).optional(), + update: z.record(z.any()).optional(), schema: z .union([ - z.string(), z.record( z.record( z @@ -206,10 +212,12 @@ export const Operator = z .strict(), ), ), + z.string(), ]) .optional(), }) - .strict(), + .strict() + .and(z.union([z.any(), z.any()])), ) .optional(), }) diff --git a/packages/mql-typescript/src/schema-generator.ts b/packages/mql-typescript/src/schema-generator.ts index aa7d129a..da008079 100644 --- a/packages/mql-typescript/src/schema-generator.ts +++ b/packages/mql-typescript/src/schema-generator.ts @@ -86,6 +86,9 @@ export class SchemaGenerator extends GeneratorBase { 'UnprefixedFieldPath[]', '{ wildcard: string }', ], + bitwiseOperation: [ + '({ and: Int | Long } | { or: Int | Long } | { xor: Int | Long })', + ], searchScore: ['unknown'], granularity: ['string'], fullDocument: ['string'], From 687eccb752eb795c887f84c0a314aa178a3d1eca Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Mon, 29 Jun 2026 17:32:28 +0100 Subject: [PATCH 2/8] fixup: bump to latest commit in repo --- packages/mql-typescript/mql-specifications | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/mql-typescript/mql-specifications b/packages/mql-typescript/mql-specifications index 67983635..87057fa7 160000 --- a/packages/mql-typescript/mql-specifications +++ b/packages/mql-typescript/mql-specifications @@ -1 +1 @@ -Subproject commit 679836355dd5671b50b4a010698b659eb7e7107b +Subproject commit 87057fa780ebf7170a7f9f6ff85ae0b76afedec6 From 714fc6fb0431bf71225f43e5ae1b3b85a4b05151 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Tue, 30 Jun 2026 13:41:33 +0100 Subject: [PATCH 3/8] fixup: have claude draw the rest of the owl --- packages/mql-typescript/.depcheckrc | 1 - packages/mql-typescript/.eslintignore | 1 + packages/mql-typescript/.prettierignore | 1 + packages/mql-typescript/out/schema.d.ts | 894 ++++++++++++++++-- packages/mql-typescript/package.json | 3 +- .../mql-typescript/src/build-metaschema.ts | 77 ++ .../src/driverSchema/docs-crawler.ts | 22 +- .../driverSchema/driver-schema-generator.ts | 21 +- .../src/driverSchema/static-schemas.ts | 82 ++ packages/mql-typescript/src/generator.ts | 9 + packages/mql-typescript/src/metaschema.ts | 554 +++++++---- .../mql-typescript/src/schema-generator.ts | 78 +- .../src/testGenerator/test-generator.ts | 30 +- .../testGenerator/unsupported-aggregations.ts | 49 + .../tests/accumulator/concatArrays.spec.ts | 13 + .../tests/accumulator/minMaxScaler.spec.ts | 27 + .../tests/accumulator/setUnion.spec.ts | 13 + .../tests/expression/avg.spec.ts | 4 +- .../tests/expression/bottom.spec.ts | 35 + .../tests/expression/bottomN.spec.ts | 36 + .../tests/expression/convert.spec.ts | 40 + .../tests/expression/createObjectId.spec.ts | 13 + .../tests/expression/deserializeEJSON.spec.ts | 110 +++ .../tests/expression/hash.spec.ts | 69 ++ .../tests/expression/hexHash.spec.ts | 34 + .../tests/expression/map.spec.ts | 28 + .../tests/expression/replaceAll.spec.ts | 29 +- .../tests/expression/replaceOne.spec.ts | 25 + .../tests/expression/serializeEJSON.spec.ts | 137 +++ .../tests/expression/sigmoid.spec.ts | 20 + .../tests/expression/similarityCosine.spec.ts | 28 + .../expression/similarityDotProduct.spec.ts | 28 + .../expression/similarityEuclidean.spec.ts | 28 + .../tests/expression/subtype.spec.ts | 19 + .../tests/expression/toArray.spec.ts | 40 + .../tests/expression/toObject.spec.ts | 20 + .../tests/expression/top.spec.ts | 35 + .../tests/expression/topN.spec.ts | 36 + .../mql-typescript/tests/query/all.spec.ts | 39 +- .../mql-typescript/tests/query/and.spec.ts | 35 +- .../tests/query/bitsAllClear.spec.ts | 32 +- .../tests/query/bitsAllSet.spec.ts | 30 +- .../tests/query/bitsAnyClear.spec.ts | 32 +- .../tests/query/bitsAnySet.spec.ts | 30 +- .../tests/query/comment.spec.ts | 13 + .../tests/query/elemMatch.spec.ts | 51 +- .../mql-typescript/tests/query/eq.spec.ts | 57 +- .../mql-typescript/tests/query/exists.spec.ts | 29 +- .../mql-typescript/tests/query/expr.spec.ts | 39 +- .../tests/query/geoIntersects.spec.ts | 66 +- .../tests/query/geoWithin.spec.ts | 66 +- .../mql-typescript/tests/query/gt.spec.ts | 13 +- .../mql-typescript/tests/query/gte.spec.ts | 13 +- .../mql-typescript/tests/query/in.spec.ts | 26 +- .../tests/query/jsonSchema.spec.ts | 34 +- .../mql-typescript/tests/query/lt.spec.ts | 13 +- .../mql-typescript/tests/query/lte.spec.ts | 13 +- .../mql-typescript/tests/query/mod.spec.ts | 22 +- .../mql-typescript/tests/query/ne.spec.ts | 15 +- .../mql-typescript/tests/query/near.spec.ts | 21 +- .../tests/query/nearSphere.spec.ts | 21 +- .../mql-typescript/tests/query/nin.spec.ts | 20 +- .../mql-typescript/tests/query/nor.spec.ts | 47 +- .../mql-typescript/tests/query/not.spec.ts | 26 +- .../mql-typescript/tests/query/or.spec.ts | 27 +- .../mql-typescript/tests/query/rand.spec.ts | 12 +- .../mql-typescript/tests/query/regex.spec.ts | 20 +- .../tests/query/sampleRate.spec.ts | 9 +- .../mql-typescript/tests/query/size.spec.ts | 12 +- .../mql-typescript/tests/query/text.spec.ts | 102 +- .../mql-typescript/tests/query/type.spec.ts | 67 +- .../mql-typescript/tests/query/where.spec.ts | 27 +- .../tests/search/autocomplete.spec.ts | 414 +------- .../tests/search/compound.spec.ts | 111 +-- .../tests/search/embeddedDocument.spec.ts | 273 +----- .../tests/search/equals.spec.ts | 162 +--- .../tests/search/exists.spec.ts | 58 +- .../mql-typescript/tests/search/facet.spec.ts | 101 +- .../tests/search/geoShape.spec.ts | 624 +----------- .../tests/search/geoWithin.spec.ts | 568 +---------- .../tests/search/hasAncestor.spec.ts | 13 + .../tests/search/hasRoot.spec.ts | 29 + .../mql-typescript/tests/search/in.spec.ts | 111 +-- .../tests/search/moreLikeThis.spec.ts | 246 +---- .../mql-typescript/tests/search/near.spec.ts | 541 +---------- .../tests/search/phrase.spec.ts | 258 +---- .../tests/search/queryString.spec.ts | 68 +- .../mql-typescript/tests/search/range.spec.ts | 332 +------ .../mql-typescript/tests/search/regex.spec.ts | 61 +- .../mql-typescript/tests/search/text.spec.ts | 543 +---------- .../tests/search/vectorSearch.spec.ts | 97 ++ .../tests/search/wildcard.spec.ts | 124 +-- .../tests/stage/addFields.spec.ts | 60 +- .../mql-typescript/tests/stage/bucket.spec.ts | 75 +- .../tests/stage/bucketAuto.spec.ts | 17 +- .../tests/stage/changeStream.spec.ts | 6 +- .../stage/changeStreamSplitLargeEvent.spec.ts | 9 +- .../tests/stage/collStats.spec.ts | 32 +- .../mql-typescript/tests/stage/count.spec.ts | 13 +- .../tests/stage/currentOp.spec.ts | 26 +- .../tests/stage/densify.spec.ts | 44 +- .../tests/stage/documents.spec.ts | 33 +- .../mql-typescript/tests/stage/facet.spec.ts | 34 +- .../mql-typescript/tests/stage/fill.spec.ts | 69 +- .../tests/stage/geoNear.spec.ts | 110 +-- .../tests/stage/graphLookup.spec.ts | 66 +- .../mql-typescript/tests/stage/group.spec.ts | 119 +-- .../tests/stage/indexStats.spec.ts | 10 +- .../mql-typescript/tests/stage/limit.spec.ts | 6 +- .../tests/stage/listLocalSessions.spec.ts | 24 +- .../tests/stage/listSampledQueries.spec.ts | 16 +- .../tests/stage/listSearchIndexes.spec.ts | 24 +- .../tests/stage/listSessions.spec.ts | 22 +- .../mql-typescript/tests/stage/lookup.spec.ts | 106 +-- .../mql-typescript/tests/stage/match.spec.ts | 27 +- .../mql-typescript/tests/stage/merge.spec.ts | 161 +--- .../mql-typescript/tests/stage/out.spec.ts | 44 +- .../tests/stage/planCacheStats.spec.ts | 27 +- .../tests/stage/project.spec.ts | 152 +-- .../tests/stage/rankFusion.spec.ts | 13 + .../mql-typescript/tests/stage/redact.spec.ts | 68 +- .../tests/stage/replaceRoot.spec.ts | 81 +- .../tests/stage/replaceWith.spec.ts | 83 +- .../mql-typescript/tests/stage/rerank.spec.ts | 13 + .../mql-typescript/tests/stage/sample.spec.ts | 11 +- .../mql-typescript/tests/stage/score.spec.ts | 19 + .../tests/stage/scoreFusion.spec.ts | 13 + .../mql-typescript/tests/stage/search.spec.ts | 657 +------------ .../tests/stage/searchMeta.spec.ts | 377 +------- .../mql-typescript/tests/stage/set.spec.ts | 72 +- .../tests/stage/setWindowFields.spec.ts | 172 +--- .../stage/shardedDataDistribution.spec.ts | 8 +- .../mql-typescript/tests/stage/skip.spec.ts | 8 +- .../mql-typescript/tests/stage/sort.spec.ts | 21 +- .../tests/stage/sortByCount.spec.ts | 15 +- .../tests/stage/unionWith.spec.ts | 34 +- .../mql-typescript/tests/stage/unset.spec.ts | 53 +- .../mql-typescript/tests/stage/unwind.spec.ts | 74 +- .../tests/stage/vectorSearch.spec.ts | 126 +-- 139 files changed, 3028 insertions(+), 8724 deletions(-) create mode 100644 packages/mql-typescript/src/build-metaschema.ts create mode 100644 packages/mql-typescript/tests/accumulator/concatArrays.spec.ts create mode 100644 packages/mql-typescript/tests/accumulator/minMaxScaler.spec.ts create mode 100644 packages/mql-typescript/tests/accumulator/setUnion.spec.ts create mode 100644 packages/mql-typescript/tests/expression/bottom.spec.ts create mode 100644 packages/mql-typescript/tests/expression/bottomN.spec.ts create mode 100644 packages/mql-typescript/tests/expression/createObjectId.spec.ts create mode 100644 packages/mql-typescript/tests/expression/deserializeEJSON.spec.ts create mode 100644 packages/mql-typescript/tests/expression/hash.spec.ts create mode 100644 packages/mql-typescript/tests/expression/hexHash.spec.ts create mode 100644 packages/mql-typescript/tests/expression/serializeEJSON.spec.ts create mode 100644 packages/mql-typescript/tests/expression/sigmoid.spec.ts create mode 100644 packages/mql-typescript/tests/expression/similarityCosine.spec.ts create mode 100644 packages/mql-typescript/tests/expression/similarityDotProduct.spec.ts create mode 100644 packages/mql-typescript/tests/expression/similarityEuclidean.spec.ts create mode 100644 packages/mql-typescript/tests/expression/subtype.spec.ts create mode 100644 packages/mql-typescript/tests/expression/toArray.spec.ts create mode 100644 packages/mql-typescript/tests/expression/toObject.spec.ts create mode 100644 packages/mql-typescript/tests/expression/top.spec.ts create mode 100644 packages/mql-typescript/tests/expression/topN.spec.ts create mode 100644 packages/mql-typescript/tests/query/comment.spec.ts create mode 100644 packages/mql-typescript/tests/search/hasAncestor.spec.ts create mode 100644 packages/mql-typescript/tests/search/hasRoot.spec.ts create mode 100644 packages/mql-typescript/tests/search/vectorSearch.spec.ts create mode 100644 packages/mql-typescript/tests/stage/rankFusion.spec.ts create mode 100644 packages/mql-typescript/tests/stage/rerank.spec.ts create mode 100644 packages/mql-typescript/tests/stage/score.spec.ts create mode 100644 packages/mql-typescript/tests/stage/scoreFusion.spec.ts diff --git a/packages/mql-typescript/.depcheckrc b/packages/mql-typescript/.depcheckrc index 1e94b37d..c06ee3cd 100644 --- a/packages/mql-typescript/.depcheckrc +++ b/packages/mql-typescript/.depcheckrc @@ -4,7 +4,6 @@ ignores: - '@types/chai' - '@types/sinon-chai' - 'sinon' - - 'json-schema-to-zod' ignore-patterns: - 'dist' - 'mongo-php-library' diff --git a/packages/mql-typescript/.eslintignore b/packages/mql-typescript/.eslintignore index 35b733e8..3cb2ffcd 100644 --- a/packages/mql-typescript/.eslintignore +++ b/packages/mql-typescript/.eslintignore @@ -1,3 +1,4 @@ .nyc-output dist mongo-php-library +mql-specifications diff --git a/packages/mql-typescript/.prettierignore b/packages/mql-typescript/.prettierignore index 4804f298..8ffeec40 100644 --- a/packages/mql-typescript/.prettierignore +++ b/packages/mql-typescript/.prettierignore @@ -2,3 +2,4 @@ dist coverage mongo-php-library +mql-specifications diff --git a/packages/mql-typescript/out/schema.d.ts b/packages/mql-typescript/out/schema.d.ts index 1335457a..05f06578 100644 --- a/packages/mql-typescript/out/schema.d.ts +++ b/packages/mql-typescript/out/schema.d.ts @@ -19,7 +19,7 @@ type RecordWithStaticFields, TValue> = T & { // TBD: Nested fields type AFieldPath = KeysOfAType & string; -type FieldExpression = { [k: string]: FieldPath }; +type FieldExpression = { [k: string]: Expression }; type MultiAnalyzerSpec = { value: KeysOfAType; @@ -487,6 +487,37 @@ export namespace Aggregation.Accumulator { $min: Expression; } + /** + * A type describing the `$minMaxScaler` operator. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/minMaxScaler/} + */ + export interface $minMaxScaler { + /** + * Normalizes a numeric expression within a window of values. By default, values can range + * between zero and one. The smallest value becomes zero, the largest value becomes one, and + * all other values scale proportionally in between. You can also specify a custom minimum + * and maximum value for the normalized output range. + * Available only in the $setWindowFields stage. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/minMaxScaler/} + */ + $minMaxScaler: { + /** + * Numeric expression containing the value that you want to normalize. + */ + input: ResolvesToNumber; + + /** + * Minimum value that you want in the output. If omitted, defaults to 0. + */ + min?: Number; + + /** + * Maximum value that you want in the output. If omitted, defaults to 1. + */ + max?: Number; + }; + } + /** * A type describing the `$minN` operator. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/minN/} @@ -971,6 +1002,66 @@ export namespace Aggregation.Expression { $bitXor: [...(ResolvesToInt | ResolvesToLong)[]]; } + /** + * A type describing the `$bottom` operator. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/bottom-array-operator/} + */ + export interface $bottom { + /** + * Returns the bottom element within an array according to the specified sort order. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/bottom-array-operator/} + */ + $bottom: { + /** + * Specifies the order of results, with syntax similar to $sort. + */ + sortBy: SortBy; + + /** + * Represents the output for each element in the input array and can be any expression. + */ + output: Expression; + + /** + * An expression that resolves to the array from which to return the bottom element. + */ + input: ResolvesToArray; + }; + } + + /** + * A type describing the `$bottomN` operator. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/bottomN-array-operator/} + */ + export interface $bottomN { + /** + * Returns an aggregation of the bottom n elements within an array, according to the specified sort order. + * If the array contains fewer than n elements, $bottomN returns all elements in the array. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/bottomN-array-operator/} + */ + $bottomN: { + /** + * An expression that resolves to a positive integer. The integer specifies the number of array elements that $bottomN returns. + */ + n: ResolvesToInt; + + /** + * Specifies the order of results, with syntax similar to $sort. + */ + sortBy: SortBy; + + /** + * Represents the output for each element in the input array and can be any expression. + */ + output: Expression; + + /** + * An expression that resolves to the array from which to return the bottom n elements. + */ + input: ResolvesToArray; + }; + } + /** * A type describing the `$bsonSize` operator. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/bsonSize/} @@ -1071,7 +1162,11 @@ export namespace Aggregation.Expression { */ export interface $convert { /** - * Converts a value to a specified type. + * Converts a value to a specified type. Any type can be converted to string. + * If the optional base argument is specified, $convert interprets the input string as a + * number in the given base and converts it to a decimal, or converts a numeric value to a + * string representation in that base. Supported bases are 2 (binary), 8 (octal), 10 + * (decimal), and 16 (hexadecimal). * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/convert/} */ $convert: { @@ -1089,6 +1184,17 @@ export namespace Aggregation.Expression { * If unspecified, $convert returns null if the input is null or missing. */ onNull?: Expression; + + /** + * The numeric base to use when converting between strings and integers. Must be one of + * 2 (binary), 8 (octal), 10 (decimal), or 16 (hexadecimal). + * When converting a string to a number, $convert interprets the string as a number in + * the given base and returns the decimal equivalent. + * When converting a number to a string, $convert returns the string representation of + * the number in the given base. + * If unspecified, $convert uses base 10. + */ + base?: ResolvesToInt; }; } @@ -1519,6 +1625,32 @@ export namespace Aggregation.Expression { $degreesToRadians: ResolvesToNumber; } + /** + * A type describing the `$deserializeEJSON` operator. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/deserializeEJSON/} + */ + export interface $deserializeEJSON { + /** + * Converts Extended JSON (EJSON) format to native BSON values. Use this expression to + * transform EJSON type wrappers into their corresponding BSON types after parsing a JSON + * string with $convert. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/deserializeEJSON/} + */ + $deserializeEJSON: { + /** + * The Extended JSON value to convert to native BSON format. This should be a BSON + * document containing EJSON type wrappers. + */ + input: ResolvesToObject; + + /** + * The value to return if the operation encounters an error during conversion. + * If unspecified, the operation throws an error and stops. + */ + onError?: Expression; + }; + } + /** * A type describing the `$divide` operator. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/divide/} @@ -1709,6 +1841,40 @@ export namespace Aggregation.Expression { $gte: [expression1: Expression, expression2: Expression]; } + /** + * A type describing the `$hash` operator. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/hash/} + */ + export interface $hash { + /** + * Generates and returns a binary hash value (BinData) from a UTF-8 string or binary data. Use $hash in an aggregation + * pipeline to compute binary hashes for storage, verification, or comparison. To get a hexadecimal string instead of + * binary data, use $hexHash. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/hash/} + */ + $hash: { + input: ResolvesToString | ResolvesToBinData | ResolvesToNull; + algorithm: string; + }; + } + + /** + * A type describing the `$hexHash` operator. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/hexHash/} + */ + export interface $hexHash { + /** + * Generates and returns an uppercase hexadecimal string representation of a hash value from a UTF-8 string or binary + * data. Use $hexHash in an aggregation pipeline to compute hex-encoded hashes for storage, verification, or comparison. + * To get binary data instead of a hexadecimal string, use $hash. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/hexHash/} + */ + $hexHash: { + input: ResolvesToString | ResolvesToBinData | ResolvesToNull; + algorithm: string; + }; + } + /** * A type describing the `$hour` operator. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/hour/} @@ -1974,12 +2140,12 @@ export namespace Aggregation.Expression { /** * A type describing the `$lastN` operator. - * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/lastN-array-element/} + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/lastN/#array-operator} */ export interface $lastN { /** * Returns a specified number of elements from the end of an array. - * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/lastN-array-element/} + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/lastN/#array-operator} */ $lastN: { /** @@ -2009,7 +2175,7 @@ export namespace Aggregation.Expression { * Assignment block for the variables accessible in the in expression. To assign a variable, specify a string for the variable name and assign a valid expression for the value. * The variable assignments have no meaning outside the in expression, not even within the vars block itself. */ - vars: Record; + vars: ExpressionMap; /** * The expression to evaluate. @@ -2143,7 +2309,13 @@ export namespace Aggregation.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?: ResolvesToString; + 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 in expression. + */ + arrayIndexAs?: string; /** * An expression that is applied to each element of the input array. The expression references each element individually with the variable name specified in as. @@ -2204,7 +2376,7 @@ export namespace Aggregation.Expression { /** * $median calculates the 50th percentile value of this data. input must be a field name or an expression that evaluates to a numeric type. If the expression cannot be converted to a numeric type, the $median calculation ignores it. */ - input: ResolvesToNumber | ResolvesToNumber[]; + input: ResolvesToNumber | unknown[]; /** * The method that mongod uses to calculate the 50th percentile value. The method must be 'approximate'. @@ -2444,7 +2616,7 @@ export namespace Aggregation.Expression { /** * $percentile calculates the percentile values of this data. input must be a field name or an expression that evaluates to a numeric type. If the expression cannot be converted to a numeric type, the $percentile calculation ignores it. */ - input: ResolvesToNumber | ResolvesToNumber[]; + input: ResolvesToNumber | unknown[]; /** * $percentile calculates a percentile value for each element in p. The elements represent percentages and must evaluate to numeric values in the range 0.0 to 1.0, inclusive. @@ -2550,19 +2722,33 @@ export namespace Aggregation.Expression { * - value is the variable that represents the cumulative value of the expression. * - this is the variable that refers to the element being processed. */ - in: Expression< - S & { - /** - * The variable that refers to the element being processed. - */ - $this: any; - - /** - * The variable that represents the cumulative value of the expression. - */ - $value: any; - } - >; + in: + | Expression< + S & { + /** + * The variable that refers to the element being processed. + */ + $this: any; + + /** + * The variable that represents the cumulative value of the expression. + */ + $value: any; + } + > + | ExpressionMap< + S & { + /** + * The variable that refers to the element being processed. + */ + $this: any; + + /** + * The variable that represents the cumulative value of the expression. + */ + $value: any; + } + >; }; } @@ -2674,17 +2860,17 @@ export namespace Aggregation.Expression { */ $replaceOne: { /** - * The string on which you wish to apply the find. Can be any valid expression that resolves to a string or a null. If input refers to a field that is missing, $replaceAll returns null. + * The string on which you wish to apply the find. Can be any valid expression that resolves to a string or a null. If input refers to a field that is missing, $replaceOne returns null. */ input: ResolvesToString | ResolvesToNull; /** - * The string to search for within the given input. Can be any valid expression that resolves to a string or a null. If find refers to a field that is missing, $replaceAll returns null. + * The string or regex to search for within the given input. Can be any valid expression that resolves to a string, a regex, or a null. If find refers to a field that is missing, $replaceOne returns null. */ - find: ResolvesToString | ResolvesToNull; + find: ResolvesToString | ResolvesToNull | ResolvesToRegex; /** - * The string to use to replace all matched instances of find in input. Can be any valid expression that resolves to a string or a null. + * The string to use to replace the first matched instance of find in input. Can be any valid expression that resolves to a string or a null. */ replacement: ResolvesToString | ResolvesToNull; }; @@ -2771,6 +2957,39 @@ export namespace Aggregation.Expression { }; } + /** + * A type describing the `$serializeEJSON` operator. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/serializeEJSON/} + */ + export interface $serializeEJSON { + /** + * Converts BSON values to Extended JSON (EJSON) format. The result is a + * BSON document with EJSON type wrappers that can then be converted to + * a JSON string using $toString. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/serializeEJSON/} + */ + $serializeEJSON: { + /** + * The BSON value to convert to Extended JSON format. + */ + input: Expression; + + /** + * Specifies whether to use Relaxed Extended JSON format. If true, numeric types + * (Int32, Int64, Double) are represented as native JSON numbers for better readability. + * If false or unspecified, uses Canonical Extended JSON format which preserves type + * information for all BSON types. Defaults to false. + */ + relaxed?: ResolvesToBool; + + /** + * The value to return if the operation encounters an error during conversion. + * If unspecified, the operation throws an error and stops. + */ + onError?: Expression; + }; + } + /** * A type describing the `$setDifference` operator. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/setDifference/} @@ -2872,6 +3091,90 @@ export namespace Aggregation.Expression { $setUnion: [...ResolvesToArray[]]; } + /** + * A type describing the `$sigmoid` operator. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/sigmoid/} + */ + export interface $sigmoid { + /** + * Returns the sigmoid of a value, defined as 1 / (1 + e^(-x)). The result is a value between 0 and 1. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/sigmoid/} + */ + $sigmoid: ResolvesToNumber; + } + + /** + * A type describing the `$similarityCosine` operator. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/similarityCosine/} + */ + export interface $similarityCosine { + /** + * Returns the cosine similarity between two vectors. If the score argument is true, the result + * is normalized to a value between 0 and 1 for use as a vector search score. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/similarityCosine/} + */ + $similarityCosine: { + /** + * An array of exactly two expressions that each resolve to an array of numbers. + * Both arrays must have the same length. + */ + vectors: ResolvesToArray; + + /** + * If true, normalizes the result to a value between 0 and 1 for use as a vector search score. Defaults to false. + */ + score?: boolean; + }; + } + + /** + * A type describing the `$similarityDotProduct` operator. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/similarityDotProduct/} + */ + export interface $similarityDotProduct { + /** + * Returns the dot product similarity between two vectors. If the score argument is true, the result + * is normalized to a value between 0 and 1 for use as a vector search score. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/similarityDotProduct/} + */ + $similarityDotProduct: { + /** + * An array of exactly two expressions that each resolve to an array of numbers. + * Both arrays must have the same length. + */ + vectors: ResolvesToArray; + + /** + * If true, normalizes the result to a value between 0 and 1 for use as a vector search score. Defaults to false. + */ + score?: boolean; + }; + } + + /** + * A type describing the `$similarityEuclidean` operator. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/similarityEuclidean/} + */ + export interface $similarityEuclidean { + /** + * Returns the Euclidean similarity between two vectors. If the score argument is true, the result + * is normalized to a value between 0 and 1 for use as a vector search score. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/similarityEuclidean/} + */ + $similarityEuclidean: { + /** + * An array of exactly two expressions that each resolve to an array of numbers. + * Both arrays must have the same length. + */ + vectors: ResolvesToArray; + + /** + * If true, normalizes the result to a value between 0 and 1 for use as a vector search score. Defaults to false. + */ + score?: boolean; + }; + } + /** * A type describing the `$sin` operator. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/sin/} @@ -2993,7 +3296,7 @@ export namespace Aggregation.Expression { string: ResolvesToString, /** - * The delimiter to use when splitting the string expression. delimiter can be any valid expression as long as it resolves to a string. + * The delimiter to use when splitting the string expression. delimiter can be any valid expression as long as it resolves to a string or a regular expression. */ delimiter: ResolvesToString | ResolvesToRegex, ]; @@ -3164,6 +3467,19 @@ export namespace Aggregation.Expression { ]; } + /** + * A type describing the `$subtype` operator. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/subtype/} + */ + export interface $subtype { + /** + * Returns the subtype of a given value as an integer. In MongoDB 8.3, the only expression + * that contains a subtype is a BinData expression. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/subtype/} + */ + $subtype: ResolvesToBinData; + } + /** * A type describing the `$sum` operator. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/sum/} @@ -3227,6 +3543,19 @@ export namespace Aggregation.Expression { $tanh: ResolvesToNumber; } + /** + * A type describing the `$toArray` operator. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/toArray/} + */ + export interface $toArray { + /** + * Converts a value to an array. If the value cannot be converted, $toArray errors. + * If the value is null or missing, $toArray returns null. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/toArray/} + */ + $toArray: Expression; + } + /** * A type describing the `$toBool` operator. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/toBool/} @@ -3323,6 +3652,19 @@ export namespace Aggregation.Expression { $toLower: ResolvesToString; } + /** + * A type describing the `$toObject` operator. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/toObject/} + */ + export interface $toObject { + /** + * Converts a string to an object. If the value cannot be converted, $toObject errors. + * If the value is null or missing, $toObject returns null. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/toObject/} + */ + $toObject: Expression; + } + /** * A type describing the `$toObjectId` operator. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/toObjectId/} @@ -3359,6 +3701,66 @@ export namespace Aggregation.Expression { $toUpper: ResolvesToString; } + /** + * A type describing the `$top` operator. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/top-array-operator/} + */ + export interface $top { + /** + * Returns the top element within an array according to the specified sort order. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/top-array-operator/} + */ + $top: { + /** + * Specifies the order of results, with syntax similar to $sort. + */ + sortBy: SortBy; + + /** + * Represents the output for each element in the input array and can be any expression. + */ + output: Expression; + + /** + * An expression that resolves to the array from which to return the top element. + */ + input: ResolvesToArray; + }; + } + + /** + * A type describing the `$topN` operator. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/topN-array-operator/} + */ + export interface $topN { + /** + * Returns an aggregation of the top n elements within an array, according to the specified sort order. + * If the array contains fewer than n elements, $topN returns all elements in the array. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/topN-array-operator/} + */ + $topN: { + /** + * An expression that resolves to a positive integer. The integer specifies the number of array elements that $topN returns. + */ + n: ResolvesToInt; + + /** + * Specifies the order of results, with syntax similar to $sort. + */ + sortBy: SortBy; + + /** + * Represents the output for each element in the input array and can be any expression. + */ + output: Expression; + + /** + * An expression that resolves to the array from which to return the top n elements. + */ + input: ResolvesToArray; + }; + } + /** * A type describing the `$trim` operator. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/trim/} @@ -3575,7 +3977,7 @@ export namespace Aggregation.Query { * Matches numeric or binary values in which a set of bit positions all have a value of 0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/bitsAllClear/} */ - $bitsAllClear: (Int | bson.Binary) | (Int | bson.Binary)[]; + $bitsAllClear: (Int | bson.Binary) | unknown[]; } /** @@ -3587,7 +3989,7 @@ export namespace Aggregation.Query { * Matches numeric or binary values in which a set of bit positions all have a value of 1. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/bitsAllSet/} */ - $bitsAllSet: (Int | bson.Binary) | (Int | bson.Binary)[]; + $bitsAllSet: (Int | bson.Binary) | unknown[]; } /** @@ -3599,7 +4001,7 @@ export namespace Aggregation.Query { * Matches numeric or binary values in which any bit from a set of bit positions has a value of 0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/bitsAnyClear/} */ - $bitsAnyClear: (Int | bson.Binary) | (Int | bson.Binary)[]; + $bitsAnyClear: (Int | bson.Binary) | unknown[]; } /** @@ -3611,7 +4013,7 @@ export namespace Aggregation.Query { * Matches numeric or binary values in which any bit from a set of bit positions has a value of 1. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/bitsAnySet/} */ - $bitsAnySet: (Int | bson.Binary) | (Int | bson.Binary)[]; + $bitsAnySet: (Int | bson.Binary) | unknown[]; } /** @@ -4114,12 +4516,13 @@ export namespace Aggregation.Search { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/compound/} */ compound: { - must?: SearchOperator | SearchOperator[]; - mustNot?: SearchOperator | SearchOperator[]; - should?: SearchOperator | SearchOperator[]; - filter?: SearchOperator | SearchOperator[]; + must?: SearchOperator | unknown[]; + mustNot?: SearchOperator | unknown[]; + should?: SearchOperator | unknown[]; + filter?: SearchOperator | unknown[]; minimumShouldMatch?: Int; score?: SearchScore; + doesNotAffect?: string | unknown[]; }; } @@ -4162,6 +4565,7 @@ export namespace Aggregation.Search { | Number | string; score?: SearchScore; + doesNotAffect?: string | unknown[]; }; } @@ -4228,6 +4632,30 @@ export namespace Aggregation.Search { }; } + /** + * A type describing the `hasAncestor` operator. + * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/operators-collectors/hasancestor/} + */ + export interface HasAncestor { + /** + * The `hasAncestor` operator queries an `embeddedDocuments` type field specified in the `ancestorPath`. The `ancestorPath` is a parent of the field specified in the `returnScope`. + * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/operators-collectors/hasancestor/} + */ + hasAncestor: { ancestorPath: SearchPath; operator: SearchOperator }; + } + + /** + * A type describing the `hasRoot` operator. + * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/operators-collectors/hasroot/} + */ + export interface HasRoot { + /** + * The `hasRoot` operator can be used to query root-level fields when you specify the `returnScope` and `returnStoredSource` options. + * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/operators-collectors/hasroot/} + */ + hasRoot: { operator: SearchOperator }; + } + /** * A type describing the `in` operator. * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/in/} @@ -4237,7 +4665,12 @@ export namespace Aggregation.Search { * The in operator performs a search for an array of BSON values in a field. * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/in/} */ - in: { path: SearchPath; value: any | any[]; score?: SearchScore }; + in: { + path: SearchPath; + value: any | unknown[]; + score?: SearchScore; + doesNotAffect?: string | unknown[]; + }; } /** @@ -4252,7 +4685,7 @@ export namespace Aggregation.Search { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/moreLikeThis/} */ moreLikeThis: { - like: Record | Record[]; + like: Record | unknown[]; score?: SearchScore; }; } @@ -4285,7 +4718,7 @@ export namespace Aggregation.Search { */ phrase: { path: SearchPath; - query: string | string[]; + query: string | unknown[]; slop?: Int; synonyms?: string; score?: SearchScore; @@ -4317,6 +4750,7 @@ export namespace Aggregation.Search { lt?: Date | Number | string | bson.ObjectId; lte?: Date | Number | string | bson.ObjectId; score?: SearchScore; + doesNotAffect?: string | unknown[]; }; } @@ -4358,6 +4792,60 @@ export namespace Aggregation.Search { }; } + /** + * A type describing the `vectorSearch` operator. + * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/vector-search/} + */ + export interface VectorSearch { + /** + * The vectorSearch operator performs an ANN or ENN search on a vector field. It can only be + * used as a top-level operator in a $search or $searchMeta query, not nested under compound + * or other operators. + * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/vector-search/} + */ + vectorSearch: { + /** + * The indexed vector field to search. + */ + path: SearchPath; + + /** + * Array of numbers or a BinData value that represents the query vector. The number type + * must match the indexed field value type. + */ + queryVector: bson.Binary | unknown[]; + + /** + * The integer number of documents to return in the results. This value cannot exceed + * numCandidates if numCandidates is specified. + */ + limit: Int; + + /** + * If false, runs an ANN search. If true, runs an ENN search. Defaults to false. + * This parameter is required if numCandidates is omitted. + */ + exact?: boolean; + + /** + * The number of nearest neighbors to use during the search. Value must be less than or + * equal to 10000 and cannot be less than limit. This field is required if exact is false + * or omitted. + */ + numCandidates?: Int; + + /** + * Any Atlas Search operator to filter documents based on metadata or specific search criteria. + */ + filter?: SearchOperator; + + /** + * Score assigned to matching search results. + */ + score?: SearchScore; + }; + } + /** * A type describing the `wildcard` operator. * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/wildcard/} @@ -4745,7 +5233,7 @@ export namespace Aggregation.Stage { /** * Expression that specifies the value of the connectFromField with which to start the recursive search. Optionally, startWith may be array of values, each of which is individually followed through the traversal process. */ - startWith: Expression | Expression[]; + startWith: Expression | unknown[]; /** * Field name whose value $graphLookup uses to recursively match against the connectToField of other documents in the collection. If the value is an array, each element is individually followed through the traversal process. @@ -4980,7 +5468,7 @@ export namespace Aggregation.Stage { /** * Field or fields that act as a unique identifier for a document. The identifier determines if a results document matches an existing document in the output collection. */ - on?: string | string[]; + on?: string | unknown[]; /** * Specifies variables for use in the whenMatched pipeline. @@ -4990,7 +5478,7 @@ export namespace Aggregation.Stage { /** * The behavior of $merge if a result document and an existing document in the collection have the same value for the specified on field(s). */ - whenMatched?: WhenMatched | Pipeline; + whenMatched?: WhenMatched | UpdatePipeline; /** * The behavior of $merge if a result document does not match an existing document in the out collection. @@ -5008,7 +5496,48 @@ export namespace Aggregation.Stage { * Writes the resulting documents of the aggregation pipeline to a collection. To use the $out stage, it must be the last stage in the pipeline. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/out/} */ - $out: string | OutCollection; + $out: { + /** + * The output collection name. + */ + coll: string; + + /** + * The output database name. If omitted, defaults to the current database. + */ + db?: string; + + /** + * Specifies the configuration to use when writing to a time series collection. + * The timeField is required. All other fields are optional. + */ + timeseries?: { + /** + * The name of the field which contains the date in each time series document. + */ + timeField: string; + + /** + * The name of the field which contains metadata in each time series document. + */ + metaField?: string; + + /** + * The granularity of time measurements. Value can be seconds, minutes, or hours. + */ + granularity?: TimeGranularity; + + /** + * The maximum time span between measurements in a bucket. + */ + bucketMaxSpanSeconds?: Int; + + /** + * The interval that determines the starting timestamp for a new bucket. + */ + bucketRoundingSeconds?: Int; + }; + }; } /** @@ -5035,6 +5564,43 @@ export namespace Aggregation.Stage { $project: {} & { [specification: string]: Expression }; } + /** + * A type describing the `$rankFusion` operator. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/rankFusion/} + */ + export interface $rankFusion { + /** + * Combines multiple pipelines using rank-based fusion to create hybrid search results. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/rankFusion/} + */ + $rankFusion: { + /** + * An object that specifies the pipelines to combine with rank fusion. + */ + input: { + /** + * Map from name to ranked input pipeline. Each pipeline must operate on the same collection. + */ + pipelines: Pipeline; + }; + + /** + * An object that specifies how to combine the ranked results. + */ + combination?: { + /** + * Map from pipeline name to weight (non-negative number). If unspecified, default weight is 1 for each pipeline. + */ + weights?: Number; + }; + + /** + * Set to true to include detailed scoring information. + */ + scoreDetails?: boolean; + }; + } + /** * A type describing the `$redact` operator. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/redact/} @@ -5072,6 +5638,43 @@ export namespace Aggregation.Stage { $replaceWith: ResolvesToObject; } + /** + * A type describing the `$rerank` operator. + * @see {@link https://www.mongodb.com/docs/vector-search/query/aggregation-stages/rerank/} + */ + export interface $rerank { + /** + * Reranks documents using a Voyage AI reranking model to improve relevance scoring. + * @see {@link https://www.mongodb.com/docs/vector-search/query/aggregation-stages/rerank/} + */ + $rerank: { + /** + * Name of the Voyage AI reranking model to use (e.g. rerank-2.5, rerank-2.5-lite). + */ + model: string; + + /** + * Query object for reranking. + */ + query: { + /** + * Query text used to score document relevance. + */ + text: string; + }; + + /** + * Field path or array of field paths to use for reranking. + */ + path: string | unknown[]; + + /** + * Maximum number of documents to send to Voyage AI for reranking. Value must be between 1 and 1000. + */ + numDocsToRerank: Int; + }; + } + /** * A type describing the `$sample` operator. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/sample/} @@ -5089,6 +5692,44 @@ export namespace Aggregation.Stage { }; } + /** + * A type describing the `$score` operator. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/score/} + */ + export interface $score { + /** + * Computes and returns a new score as metadata. It also optionally normalizes the input + * scores, by default to a range between zero and one. + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/score/} + */ + $score: { + /** + * Computes a new value from the input scores and stores the value in the $meta keyword + * score. Returns an error for non-numeric inputs. + */ + score: Expression; + + /** + * Normalizes the score to the range of 0 to 1. Value can be: + * - none: Doesn't normalize. If omitted, defaults to none. + * - sigmoid: Applies the sigmoid expression: 1 / (1 + e^-x). + * - minMaxScaler: Applies the $minMaxScaler window function. + */ + normalization?: ScoreNormalization; + + /** + * Number to multiply the score expression by after normalization. + */ + weight?: Expression; + + /** + * Specifies if $score computes and populates the $scoreDetails metadata field for each + * output document. + */ + scoreDetails?: boolean; + }; + } + /** * A type describing the `$scoreFusion` operator. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/scoreFusion/} @@ -5100,24 +5741,44 @@ export namespace Aggregation.Stage { */ $scoreFusion: { /** - * An object with the following required fields: - * - input.pipelines: Map from name to input pipeline. Each pipeline must be operating on the same collection. Minimum of one pipeline. - * - input.normalization: Normalizes the score to the range 0 to 1 before combining the results. Value can be none, sigmoid or minMaxScaler. + * An object that specifies the pipelines to combine with score fusion. */ - input: Record; + input: { + /** + * Map from name to input pipeline. Each pipeline must be operating on the same collection. + */ + pipelines: Pipeline; + + /** + * Normalizes the score to the range 0 to 1 before combining the results. Value can be none, sigmoid or minMaxScaler. + */ + normalization: string; + }; /** - * An object with the following optional fields: - * - combination.weights: Map from pipeline name to numbers (non-negative). If unspecified, default weight is 1 for each pipeline. - * - combination.method: Specifies method for combining scores. Value can be avg or expression. Default is avg. - * - combination.expression: This is the custom expression that is used when combination.method is set to expression. + * An object that specifies how to combine the scores. */ - combination?: Record; + combination?: { + /** + * Map from pipeline name to weight (non-negative number). If unspecified, default weight is 1 for each pipeline. + */ + weights?: Number; + + /** + * Specifies method for combining scores. Value can be avg or expression. Default is avg. + */ + method?: string; + + /** + * Custom expression used when combination.method is set to expression. + */ + expression?: Expression; + }; /** * Set to true to include detailed scoring information. */ - scoreDetails: boolean; + scoreDetails?: boolean; }; } @@ -5174,6 +5835,11 @@ export namespace Aggregation.Stage { */ sort?: Record; + /** + * Object that sets the context of the query to the specified embedded document field. You must also specify `returnStoredSource` and set it to `true`. + */ + returnScope?: Record; + /** * Flag that specifies whether to perform a full document lookup on the backend database or return only stored source fields directly from Atlas Search. */ @@ -5206,6 +5872,16 @@ export namespace Aggregation.Stage { * Document that specifies the count options for retrieving a count of the results. */ count?: Record; + + /** + * Object that sets the context of the query to the specified embedded document field. You must also specify `returnStoredSource` and set it to `true` if your cluster MongoDB version is less than 8.2. + */ + returnScope?: Record; + + /** + * Flag that specifies whether to perform a full document lookup on the backend database or return only stored source fields directly from Atlas Search. + */ + returnStoredSource?: boolean; }; } @@ -5389,9 +6065,10 @@ export namespace Aggregation.Stage { path: string; /** - * Array of numbers that represent the query vector. The number type must match the indexed field value type. + * Array of numbers or a BinData value that represent the query vector. The number type + * must match the indexed field value type. */ - queryVector: unknown[]; + queryVector: bson.Binary | unknown[]; /** * This is required if numCandidates is omitted. false to run ANN search. true to run ENN search. @@ -5399,7 +6076,7 @@ export namespace Aggregation.Stage { exact?: boolean; /** - * Any match query that compares an indexed field with a boolean, date, objectId, number (not decimals), string, or UUID to use as a pre-filter. + * Any match query that compares an indexed field with a boolean, date, objectId, number, string, or UUID to use as a pre-filter. */ filter?: Query; @@ -5408,6 +6085,26 @@ export namespace Aggregation.Stage { * Number of nearest neighbors to use during the search. Value must be less than or equal to (<=) 10000. You can't specify a number less than the number of documents to return (limit). */ numCandidates?: Int; + + /** + * If true, the search returns only the stored source fields configured on the index directly from the index and skips a full document lookup. If omitted, the default value is false. + */ + returnStoredSource?: boolean; + + /** + * Configure how MongoDB Vector Search scores documents that contain nested arrays. + */ + nestedOptions?: { + /** + * Specifies how to score documents that contain nested arrays. Value can be avg or max. + */ + scoreMode?: string; + }; + + /** + * Any match query that compares an indexed top-level field with a boolean, date, objectId, number, string, or UUID to use as a pre-filter. Only valid if `nestedRoot` is specified in the index definition. + */ + parentFilter?: Query; }; } } @@ -5528,7 +6225,7 @@ export namespace Aggregation.Update { * Removes all array elements that match a specified value or condition. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/update/pull/} */ - $pull: {} & { [field: string]: any }; + $pull: {} & { [field: string]: FieldQuery }; } /** @@ -5647,6 +6344,8 @@ export type BitwiseOperation = | { xor: Int | Long }; export type SearchScore = unknown; export type Granularity = string; +export type TimeGranularity = 'seconds' | 'minutes' | 'hours'; +export type ScoreNormalization = 'none' | 'sigmoid' | 'minMaxScaler'; export type FullDocument = string; export type FullDocumentBeforeChange = string; export type AccumulatorPercentile = string; @@ -5681,37 +6380,27 @@ export type Stage = | Aggregation.Stage.$addFields | Aggregation.Stage.$bucket | Aggregation.Stage.$bucketAuto - | Aggregation.Stage.$changeStream - | Aggregation.Stage.$changeStreamSplitLargeEvent - | Aggregation.Stage.$collStats | Aggregation.Stage.$count - | Aggregation.Stage.$currentOp | Aggregation.Stage.$densify - | Aggregation.Stage.$documents | Aggregation.Stage.$facet | Aggregation.Stage.$fill - | Aggregation.Stage.$geoNear | Aggregation.Stage.$graphLookup | Aggregation.Stage.$group - | Aggregation.Stage.$indexStats | Aggregation.Stage.$limit - | Aggregation.Stage.$listLocalSessions | Aggregation.Stage.$listSampledQueries | Aggregation.Stage.$listSearchIndexes - | Aggregation.Stage.$listSessions | Aggregation.Stage.$lookup | Aggregation.Stage.$match - | Aggregation.Stage.$merge - | Aggregation.Stage.$out | Aggregation.Stage.$planCacheStats | Aggregation.Stage.$project + | Aggregation.Stage.$rankFusion | Aggregation.Stage.$redact | Aggregation.Stage.$replaceRoot | Aggregation.Stage.$replaceWith + | Aggregation.Stage.$rerank | Aggregation.Stage.$sample + | Aggregation.Stage.$score | Aggregation.Stage.$scoreFusion - | Aggregation.Stage.$search - | Aggregation.Stage.$searchMeta | Aggregation.Stage.$set | Aggregation.Stage.$setWindowFields | Aggregation.Stage.$shardedDataDistribution @@ -5720,9 +6409,9 @@ export type Stage = | Aggregation.Stage.$sortByCount | Aggregation.Stage.$unionWith | Aggregation.Stage.$unset - | Aggregation.Stage.$unwind - | Aggregation.Stage.$vectorSearch; + | Aggregation.Stage.$unwind; export type Pipeline = Stage[]; +export type UpdatePipeline = UpdateStage[]; export type UntypedPipeline = Pipeline; export type Query = | QueryOperator @@ -5828,6 +6517,10 @@ export type ResolvesToDouble = | Aggregation.Expression.$radiansToDegrees | Aggregation.Expression.$rand | Aggregation.Expression.$round + | Aggregation.Expression.$sigmoid + | Aggregation.Expression.$similarityCosine + | Aggregation.Expression.$similarityDotProduct + | Aggregation.Expression.$similarityEuclidean | Aggregation.Expression.$sin | Aggregation.Expression.$sinh | Aggregation.Expression.$sqrt @@ -5844,6 +6537,7 @@ export type ResolvesToString = | string | Aggregation.Expression.$concat | Aggregation.Expression.$dateToString + | Aggregation.Expression.$hexHash | Aggregation.Expression.$ltrim | Aggregation.Expression.$replaceAll | Aggregation.Expression.$replaceOne @@ -5864,9 +6558,12 @@ export type ResolvesToObject = | Record | Aggregation.Expression.$arrayToObject | Aggregation.Expression.$dateToParts + | Aggregation.Expression.$deserializeEJSON | Aggregation.Expression.$mergeObjects | Aggregation.Expression.$regexFind + | Aggregation.Expression.$serializeEJSON | Aggregation.Expression.$setField + | Aggregation.Expression.$toObject | Aggregation.Expression.$unsetField; export type ResolvesToArray = | ResolvesToAny @@ -5874,6 +6571,7 @@ export type ResolvesToArray = | unknown[] | Aggregation.Accumulator.$concatArrays | Aggregation.Accumulator.$setUnion + | Aggregation.Expression.$bottomN | Aggregation.Expression.$concatArrays | Aggregation.Expression.$filter | Aggregation.Expression.$firstN @@ -5892,11 +6590,14 @@ export type ResolvesToArray = | Aggregation.Expression.$slice | Aggregation.Expression.$sortArray | Aggregation.Expression.$split + | Aggregation.Expression.$toArray + | Aggregation.Expression.$topN | Aggregation.Expression.$zip; export type ResolvesToBinData = | ResolvesToAny | BinDataFieldPath - | bson.Binary; + | bson.Binary + | Aggregation.Expression.$hash; export type ResolvesToObjectId = | ResolvesToAny | ObjectIdFieldPath @@ -5980,6 +6681,7 @@ export type ResolvesToInt = | Aggregation.Expression.$strLenCP | Aggregation.Expression.$strcasecmp | Aggregation.Expression.$subtract + | Aggregation.Expression.$subtype | Aggregation.Expression.$toInt | Aggregation.Expression.$week | Aggregation.Expression.$year; @@ -6053,6 +6755,7 @@ export type AccumulatorOperator = | Aggregation.Accumulator.$median | Aggregation.Accumulator.$mergeObjects | Aggregation.Accumulator.$min + | Aggregation.Accumulator.$minMaxScaler | Aggregation.Accumulator.$minN | Aggregation.Accumulator.$percentile | Aggregation.Accumulator.$push @@ -6088,6 +6791,7 @@ export type Window = | Aggregation.Accumulator.$maxN | Aggregation.Accumulator.$median | Aggregation.Accumulator.$min + | Aggregation.Accumulator.$minMaxScaler | Aggregation.Accumulator.$minN | Aggregation.Accumulator.$percentile | Aggregation.Accumulator.$push @@ -6118,6 +6822,8 @@ export type ExpressionOperator = | Aggregation.Expression.$bitNot | Aggregation.Expression.$bitOr | Aggregation.Expression.$bitXor + | Aggregation.Expression.$bottom + | Aggregation.Expression.$bottomN | Aggregation.Expression.$bsonSize | Aggregation.Expression.$case | Aggregation.Expression.$ceil @@ -6141,6 +6847,7 @@ export type ExpressionOperator = | Aggregation.Expression.$dayOfWeek | Aggregation.Expression.$dayOfYear | Aggregation.Expression.$degreesToRadians + | Aggregation.Expression.$deserializeEJSON | Aggregation.Expression.$divide | Aggregation.Expression.$eq | Aggregation.Expression.$exp @@ -6152,6 +6859,8 @@ export type ExpressionOperator = | Aggregation.Expression.$getField | Aggregation.Expression.$gt | Aggregation.Expression.$gte + | Aggregation.Expression.$hash + | Aggregation.Expression.$hexHash | Aggregation.Expression.$hour | Aggregation.Expression.$ifNull | Aggregation.Expression.$in @@ -6205,12 +6914,17 @@ export type ExpressionOperator = | Aggregation.Expression.$round | Aggregation.Expression.$rtrim | Aggregation.Expression.$second + | Aggregation.Expression.$serializeEJSON | Aggregation.Expression.$setDifference | Aggregation.Expression.$setEquals | Aggregation.Expression.$setField | Aggregation.Expression.$setIntersection | Aggregation.Expression.$setIsSubset | Aggregation.Expression.$setUnion + | Aggregation.Expression.$sigmoid + | Aggregation.Expression.$similarityCosine + | Aggregation.Expression.$similarityDotProduct + | Aggregation.Expression.$similarityEuclidean | Aggregation.Expression.$sin | Aggregation.Expression.$sinh | Aggregation.Expression.$size @@ -6227,10 +6941,12 @@ export type ExpressionOperator = | Aggregation.Expression.$substrBytes | Aggregation.Expression.$substrCP | Aggregation.Expression.$subtract + | Aggregation.Expression.$subtype | Aggregation.Expression.$sum | Aggregation.Expression.$switch | Aggregation.Expression.$tan | Aggregation.Expression.$tanh + | Aggregation.Expression.$toArray | Aggregation.Expression.$toBool | Aggregation.Expression.$toDate | Aggregation.Expression.$toDecimal @@ -6239,9 +6955,12 @@ export type ExpressionOperator = | Aggregation.Expression.$toInt | Aggregation.Expression.$toLong | Aggregation.Expression.$toLower + | Aggregation.Expression.$toObject | Aggregation.Expression.$toObjectId | Aggregation.Expression.$toString | Aggregation.Expression.$toUpper + | Aggregation.Expression.$top + | Aggregation.Expression.$topN | Aggregation.Expression.$trim | Aggregation.Expression.$trunc | Aggregation.Expression.$tsIncrement @@ -6253,6 +6972,7 @@ export type ExpressionOperator = | Aggregation.Expression.$zip; export type ResolvesToAny = | Aggregation.Expression.$arrayElemAt + | Aggregation.Expression.$bottom | Aggregation.Expression.$cond | Aggregation.Expression.$convert | Aggregation.Expression.$first @@ -6266,7 +6986,8 @@ export type ResolvesToAny = | Aggregation.Expression.$meta | Aggregation.Expression.$min | Aggregation.Expression.$reduce - | Aggregation.Expression.$switch; + | Aggregation.Expression.$switch + | Aggregation.Expression.$top; export type SwitchBranch = Aggregation.Expression.$case; export type FieldQuery = | Aggregation.Query.$all @@ -6346,6 +7067,8 @@ export type SearchOperator = | Aggregation.Search.Facet | Aggregation.Search.GeoShape | Aggregation.Search.GeoWithin + | Aggregation.Search.HasAncestor + | Aggregation.Search.HasRoot | Aggregation.Search.In | Aggregation.Search.MoreLikeThis | Aggregation.Search.Near @@ -6354,7 +7077,15 @@ export type SearchOperator = | Aggregation.Search.Range | Aggregation.Search.Regex | Aggregation.Search.Text + | Aggregation.Search.VectorSearch | Aggregation.Search.Wildcard; +export type UpdateStage = + | Aggregation.Stage.$addFields + | Aggregation.Stage.$project + | Aggregation.Stage.$replaceRoot + | Aggregation.Stage.$replaceWith + | Aggregation.Stage.$set + | Aggregation.Stage.$unset; export type StageOperator = | Aggregation.Stage.$addFields | Aggregation.Stage.$bucket @@ -6383,10 +7114,13 @@ export type StageOperator = | Aggregation.Stage.$out | Aggregation.Stage.$planCacheStats | Aggregation.Stage.$project + | Aggregation.Stage.$rankFusion | Aggregation.Stage.$redact | Aggregation.Stage.$replaceRoot | Aggregation.Stage.$replaceWith + | Aggregation.Stage.$rerank | Aggregation.Stage.$sample + | Aggregation.Stage.$score | Aggregation.Stage.$scoreFusion | Aggregation.Stage.$search | Aggregation.Stage.$searchMeta @@ -6400,6 +7134,22 @@ export type StageOperator = | Aggregation.Stage.$unset | Aggregation.Stage.$unwind | Aggregation.Stage.$vectorSearch; +export type InputStage = + | Aggregation.Stage.$changeStream + | Aggregation.Stage.$collStats + | Aggregation.Stage.$currentOp + | Aggregation.Stage.$documents + | Aggregation.Stage.$geoNear + | Aggregation.Stage.$indexStats + | Aggregation.Stage.$listLocalSessions + | Aggregation.Stage.$listSessions + | Aggregation.Stage.$search + | Aggregation.Stage.$searchMeta + | Aggregation.Stage.$vectorSearch; +export type OutputStage = + | Aggregation.Stage.$changeStreamSplitLargeEvent + | Aggregation.Stage.$merge + | Aggregation.Stage.$out; export type Update = | Aggregation.Update.$addToSet | Aggregation.Update.$bit diff --git a/packages/mql-typescript/package.json b/packages/mql-typescript/package.json index a4dc6f28..986421f6 100644 --- a/packages/mql-typescript/package.json +++ b/packages/mql-typescript/package.json @@ -57,7 +57,7 @@ "check-ci": "npm run check", "test": "tsc --noEmit tests/**/*.ts", "reformat": "npm run prettier -- --write .", - "extract-metaschema": "json-refs resolve mql-specifications/schema.json | json-schema-to-zod -n Operator -o src/metaschema.ts && npm run prettier -- --write src/metaschema.ts", + "extract-metaschema": "ts-node src/build-metaschema.ts && npm run prettier -- --write src/metaschema.ts", "pregenerate-schema": "npm run extract-metaschema", "generate-schema": "ts-node src/cli.ts schema", "postgenerate-schema": "npm run prettier -- --write out/*", @@ -83,7 +83,6 @@ "gen-esm-wrapper": "^1.1.3", "js-yaml": "^4.1.1", "jsdom": "^24.1.3", - "json-refs": "^3.0.15", "json-schema-to-zod": "^2.6.0", "prettier": "^3.8.1", "ts-node": "^10.9.2", diff --git a/packages/mql-typescript/src/build-metaschema.ts b/packages/mql-typescript/src/build-metaschema.ts new file mode 100644 index 00000000..0d74a2ee --- /dev/null +++ b/packages/mql-typescript/src/build-metaschema.ts @@ -0,0 +1,77 @@ +import * as fs from 'fs'; +import * as path from 'path'; +import { jsonSchemaToZod } from 'json-schema-to-zod'; + +/** + * Generates `src/metaschema.ts` (the zod schema used to parse the operator + * definitions) directly from the JSON metaschema shipped in the + * `mql-specifications` submodule, so the zod definitions don't have to be + * maintained by hand. + * + * `json-schema-to-zod` expects a fully dereferenced schema and emits `z.any()` + * for any `$ref` it doesn't understand, while `json-refs` cannot inline the + * recursive `Argument.arguments` reference. We therefore dereference the + * `#/definitions/*` references ourselves, breaking reference cycles by + * replacing the recursive reference with an empty schema (which becomes + * `z.any()`). + */ + +type JsonSchema = Record; + +const schemaFile = path.resolve( + __dirname, + '..', + 'mql-specifications', + 'schemas', + 'operator.json', +); +const outputFile = path.resolve(__dirname, 'metaschema.ts'); + +const root = JSON.parse(fs.readFileSync(schemaFile, 'utf8')) as { + definitions: Record; +}; +const definitions = root.definitions; + +function dereference(node: unknown, stack: readonly string[]): unknown { + if (Array.isArray(node)) { + return node.map((item) => dereference(item, stack)); + } + + if (node && typeof node === 'object') { + const ref = (node as JsonSchema).$ref; + if (typeof ref === 'string') { + const match = /^#\/definitions\/(.+)$/.exec(ref); + if (!match) { + throw new Error(`Unsupported $ref: ${ref}`); + } + const name = match[1]; + if (stack.includes(name)) { + // Break the reference cycle. An empty schema is converted to + // `z.any()`, which accepts the recursive structure at runtime. + return {}; + } + if (!definitions[name]) { + throw new Error(`Unknown definition: ${name}`); + } + return dereference(definitions[name], [...stack, name]); + } + + return Object.fromEntries( + Object.entries(node).map(([key, value]) => [ + key, + dereference(value, stack), + ]), + ); + } + + return node; +} + +const operatorSchema = dereference(definitions.Operator, ['Operator']); + +const code = jsonSchemaToZod(operatorSchema as JsonSchema, { + name: 'Operator', + module: 'esm', +}); + +fs.writeFileSync(outputFile, code, 'utf8'); diff --git a/packages/mql-typescript/src/driverSchema/docs-crawler.ts b/packages/mql-typescript/src/driverSchema/docs-crawler.ts index 2854321a..20a8f83b 100644 --- a/packages/mql-typescript/src/driverSchema/docs-crawler.ts +++ b/packages/mql-typescript/src/driverSchema/docs-crawler.ts @@ -14,6 +14,24 @@ export class DocsCrawler { private virtualConsole: VirtualConsole; + // Documentation pages are fetched once per page (ignoring the URL fragment), + // since a single operator page typically backs several tests that only differ + // by their anchor. + private static domCache = new Map>(); + + private fetchDom(): Promise { + const url = new URL(this.url); + url.hash = ''; + const cacheKey = url.toString(); + + let dom = DocsCrawler.domCache.get(cacheKey); + if (!dom) { + dom = JSDOM.fromURL(cacheKey, { virtualConsole: this.virtualConsole }); + DocsCrawler.domCache.set(cacheKey, dom); + } + return dom; + } + private fuzzyParse(json: string): unknown[] | undefined { // Sometimes the snippet will end with ellipsis instead of json json = json.replace(/\.\.\.$/g, ''); @@ -149,9 +167,7 @@ export class DocsCrawler { } try { - const dom = await JSDOM.fromURL(this.url, { - virtualConsole: this.virtualConsole, - }); + const dom = await this.fetchDom(); const exampleSection = dom.window.document .querySelector(`a[href='${fragment}']:not([target])`) ?.closest('section'); diff --git a/packages/mql-typescript/src/driverSchema/driver-schema-generator.ts b/packages/mql-typescript/src/driverSchema/driver-schema-generator.ts index fb2a753e..13df396d 100644 --- a/packages/mql-typescript/src/driverSchema/driver-schema-generator.ts +++ b/packages/mql-typescript/src/driverSchema/driver-schema-generator.ts @@ -11,11 +11,13 @@ type TestType = NonNullable[number]; export class DriverSchemaGenerator extends GeneratorBase { private async getSchemaFromDocs(test: TestType): Promise { if (!test.link) { - console.error(`No docs reference found for ${test.name}`); + console.error(`No docs reference found for ${String(test.name)}`); return '// TODO: No docs reference found'; } - if (!test.pipeline) { - console.error(`No pipeline found for ${test.name} at ${test.link}`); + if (!('pipeline' in test) || !test.pipeline) { + console.error( + `No pipeline found for ${String(test.name)} at ${test.link}`, + ); return '// TODO: No pipeline found'; } @@ -24,7 +26,7 @@ export class DriverSchemaGenerator extends GeneratorBase { if (!schema) { console.error( - `Could not extract schema for ${test.name} at ${test.link}`, + `Could not extract schema for ${String(test.name)} at ${test.link}`, ); return '// TODO: No schema found in docs'; } @@ -45,8 +47,13 @@ export class DriverSchemaGenerator extends GeneratorBase { test: TestType; rawYaml: { tests: { name: string; schema: object | string }[] }; }): Promise { + if (test.name === undefined) { + return; + } + + const testName = test.name; const yamlTest = rawYaml.tests.find( - (t: { name: string }) => t.name === test.name, + (t: { name: string }) => t.name === testName, ); if (!yamlTest) { @@ -57,7 +64,7 @@ export class DriverSchemaGenerator extends GeneratorBase { } yamlTest.schema = - getStaticSchema({ category, operator, test: test.name }) ?? + getStaticSchema({ category, operator, test: testName }) ?? (await this.getSchemaFromDocs(test)); } @@ -86,7 +93,7 @@ export class DriverSchemaGenerator extends GeneratorBase { lineWidth: -1, }); - updatedYaml = `# $schema: ../schema.json\n${updatedYaml}`; + updatedYaml = `# $schema: ../../schemas/operator.json\n${updatedYaml}`; await fs.writeFile(operator.path, updatedYaml, 'utf8'); } diff --git a/packages/mql-typescript/src/driverSchema/static-schemas.ts b/packages/mql-typescript/src/driverSchema/static-schemas.ts index e2a26163..74e210a8 100644 --- a/packages/mql-typescript/src/driverSchema/static-schemas.ts +++ b/packages/mql-typescript/src/driverSchema/static-schemas.ts @@ -92,6 +92,35 @@ const inventorySchema: SchemaInfo = { }, }; +// The docs examples for these operators live on pages with several sibling +// examples, so the crawler cannot reliably infer their collection schema. +const zipCodeSchema: SchemaInfo = { + collectionName: 'addressBook', + schema: { + _id: { types: [{ bsonType: 'Int32' }] }, + address: { types: [{ bsonType: 'String' }] }, + zipCode: { + types: [ + { bsonType: 'String' }, + { bsonType: 'Int32' }, + { bsonType: 'Double' }, + { bsonType: 'Array', types: [{ bsonType: 'String' }] }, + ], + }, + }, +}; + +const salesByDateSchema: SchemaInfo = { + collectionName: 'sales', + schema: { + _id: { types: [{ bsonType: 'Int32' }] }, + item: { types: [{ bsonType: 'String' }] }, + price: { types: [{ bsonType: 'Decimal128' }] }, + quantity: { types: [{ bsonType: 'Int32' }] }, + date: { types: [{ bsonType: 'Date' }] }, + }, +}; + const mflixMoviesSchema: SchemaInfo = { collectionName: 'movies', schema: { @@ -1415,6 +1444,34 @@ type SchemaMap = { }; const staticSchemas: SchemaMap = { + accumulator: { + concatArrays: { + ['Warehouse collection']: { + collectionName: 'warehouses', + schema: { + instock: { + types: [{ bsonType: 'Array', types: [{ bsonType: 'String' }] }], + }, + ordered: { + types: [{ bsonType: 'Array', types: [{ bsonType: 'String' }] }], + }, + }, + }, + }, + setUnion: { + ['Flowers collection']: { + collectionName: 'flowers', + schema: { + flowerFieldA: { + types: [{ bsonType: 'Array', types: [{ bsonType: 'String' }] }], + }, + flowerFieldB: { + types: [{ bsonType: 'Array', types: [{ bsonType: 'String' }] }], + }, + }, + }, + }, + }, expression: { dateFromParts: { Example: { @@ -1496,6 +1553,15 @@ const staticSchemas: SchemaMap = { }, }, exists: inventorySchema, + gt: inventorySchema, + gte: inventorySchema, + lt: inventorySchema, + lte: inventorySchema, + nin: inventorySchema, + type: { + ['Querying by Data Type']: zipCodeSchema, + ['Querying by Array Type']: zipCodeSchema, + }, geoIntersects: geoPolygonSchema, geoWithin: geoPolygonSchema, jsonSchema: { @@ -1563,6 +1629,22 @@ const staticSchemas: SchemaMap = { wildcard: mflixMoviesSchema, }, stage: { + project: { + // The docs page for this example shares its insertion code with sibling + // examples, so the crawler cannot reliably infer the {x, y} collection. + 'Project New Array Fields': { + collectionName: 'TestCollection', + schema: { + _id: { types: [{ bsonType: 'ObjectId' }] }, + x: { types: [{ bsonType: 'Int32' }] }, + y: { types: [{ bsonType: 'Int32' }] }, + }, + }, + }, + group: { + ['Calculate Count Sum and Average']: salesByDateSchema, + ['Group by null']: salesByDateSchema, + }, sort: { collectionName: 'users', schema: { diff --git a/packages/mql-typescript/src/generator.ts b/packages/mql-typescript/src/generator.ts index 763cc91b..2e8a38d1 100644 --- a/packages/mql-typescript/src/generator.ts +++ b/packages/mql-typescript/src/generator.ts @@ -200,6 +200,12 @@ export abstract class GeneratorBase { 'definitions', ); + // The `types` category describes closed-set types using a different schema + // (schemas/type.json); those types are modeled directly in the generator's + // type mappings. The `pipeline` category describes the top-level pipeline + // containers, which are also modeled directly as type mappings. + private static readonly ignoredCategories = new Set(['types', 'pipeline']); + private async *listCategories( filterRegex: RegExp | undefined, ): AsyncIterable<{ @@ -209,6 +215,9 @@ export abstract class GeneratorBase { for await (const folder of await fs.readdir(this.configDir, { withFileTypes: true, })) { + if (GeneratorBase.ignoredCategories.has(folder.name)) { + continue; + } if (folder.isDirectory() && filterRegex?.test(folder.name) !== false) { yield { category: folder.name, diff --git a/packages/mql-typescript/src/metaschema.ts b/packages/mql-typescript/src/metaschema.ts index c680d316..d4d1feeb 100644 --- a/packages/mql-typescript/src/metaschema.ts +++ b/packages/mql-typescript/src/metaschema.ts @@ -3,37 +3,82 @@ import { z } from 'zod'; export const Operator = z .object({ name: z.string().regex(new RegExp('^\\$?[a-z][a-zA-Z0-9]*$')), - minVersion: z.string().regex(new RegExp('^[0-9]+\\.[0-9]+(\\.[0-9]+)?$')), + minVersion: z + .string() + .regex(new RegExp('^[0-9]+\\.[0-9]+(\\.[1-9][0-9]*)?$')), link: z.string().url().regex(new RegExp('^https://')), + generic: z.array(z.string()).optional(), type: z.array( - z.enum([ - 'accumulator', - 'stage', - 'query', - 'update', - 'fieldQuery', - 'filter', - 'window', - 'geometry', - 'switchBranch', - 'resolvesToAny', - 'resolvesToNumber', - 'resolvesToDouble', - 'resolvesToString', - 'resolvesToObject', - 'resolvesToArray', - 'resolvesToBinData', - 'resolvesToObjectId', - 'resolvesToBool', - 'resolvesToDate', - 'resolvesToNull', - 'resolvesToRegex', - 'resolvesToJavascript', - 'resolvesToInt', - 'resolvesToTimestamp', - 'resolvesToLong', - 'resolvesToDecimal', - 'searchOperator', + z.union([ + z.enum([ + 'pipeline', + 'accumulator', + 'stage', + 'updateStage', + 'inputStage', + 'outputStage', + 'query', + 'update', + 'fieldQuery', + 'filter', + 'window', + 'geometry', + 'switchBranch', + 'resolvesToAny', + 'resolvesToNumber', + 'resolvesToDouble', + 'resolvesToString', + 'resolvesToObject', + 'resolvesToArray', + 'resolvesToBinData', + 'resolvesToObjectId', + 'resolvesToBool', + 'resolvesToDate', + 'resolvesToNull', + 'resolvesToRegex', + 'resolvesToJavascript', + 'resolvesToInt', + 'resolvesToTimestamp', + 'resolvesToLong', + 'resolvesToDecimal', + 'searchOperator', + ]), + z.object({ + name: z.enum([ + 'pipeline', + 'accumulator', + 'stage', + 'updateStage', + 'inputStage', + 'outputStage', + 'query', + 'update', + 'fieldQuery', + 'filter', + 'window', + 'geometry', + 'switchBranch', + 'resolvesToAny', + 'resolvesToNumber', + 'resolvesToDouble', + 'resolvesToString', + 'resolvesToObject', + 'resolvesToArray', + 'resolvesToBinData', + 'resolvesToObjectId', + 'resolvesToBool', + 'resolvesToDate', + 'resolvesToNull', + 'resolvesToRegex', + 'resolvesToJavascript', + 'resolvesToInt', + 'resolvesToTimestamp', + 'resolvesToLong', + 'resolvesToDecimal', + 'searchOperator', + ]), + generic: z.string().optional(), + }), ]), ), encode: z.enum(['array', 'object', 'single']), @@ -46,91 +91,193 @@ export const Operator = z name: z.string().regex(new RegExp('^([_$]?[a-z][a-zA-Z0-9]*|N)$')), minVersion: z .string() - .regex(new RegExp('^[0-9]+\\.[0-9]+(\\.[0-9]+)?$')) + .regex(new RegExp('^[0-9]+\\.[0-9]+(\\.[1-9][0-9]*)?$')) .optional(), type: z.array( - z.enum([ - 'accumulator', - 'query', - 'fieldQuery', - 'pipeline', - 'window', - 'expression', - 'geometry', - 'unprefixedFieldPath', - 'timeUnit', - 'sortSpec', - 'granularity', - 'fullDocument', - 'fullDocumentBeforeChange', - 'accumulatorPercentile', - 'whenMatched', - 'whenNotMatched', - 'outCollection', - 'range', - 'sortBy', - 'geoPoint', - 'resolvesToAny', - 'fieldPath', - 'any', - 'resolvesToNumber', - 'numberFieldPath', - 'number', - 'resolvesToDouble', - 'doubleFieldPath', - 'double', - 'resolvesToString', - 'stringFieldPath', - 'string', - 'resolvesToObject', - 'objectFieldPath', - 'object', - 'resolvesToArray', - 'arrayFieldPath', - 'array', - 'resolvesToBinData', - 'binDataFieldPath', - 'binData', - 'resolvesToObjectId', - 'objectIdFieldPath', - 'objectId', - 'resolvesToBool', - 'boolFieldPath', - 'bool', - 'resolvesToDate', - 'dateFieldPath', - 'date', - 'resolvesToNull', - 'nullFieldPath', - 'null', - 'resolvesToRegex', - 'regexFieldPath', - 'regex', - 'resolvesToJavascript', - 'javascriptFieldPath', - 'javascript', - 'resolvesToInt', - 'intFieldPath', - 'int', - 'resolvesToTimestamp', - 'timestampFieldPath', - 'timestamp', - 'resolvesToLong', - 'longFieldPath', - 'long', - 'resolvesToDecimal', - 'decimalFieldPath', - 'decimal', - 'searchPath', - 'searchScore', - 'bitwiseOperation', - 'searchOperator', + z.union([ + z.enum([ + 'stage', + 'updateStage', + 'inputStage', + 'outputStage', + 'accumulator', + 'query', + 'fieldQuery', + 'pipeline', + 'updatePipeline', + 'untypedPipeline', + 'window', + 'expression', + 'expressionMap', + 'geometry', + 'unprefixedFieldPath', + 'timeUnit', + 'sortSpec', + 'granularity', + 'timeGranularity', + 'fullDocument', + 'fullDocumentBeforeChange', + 'accumulatorPercentile', + 'whenMatched', + 'whenNotMatched', + 'scoreNormalization', + 'outCollection', + 'range', + 'sortBy', + 'geoPoint', + 'resolvesToAny', + 'fieldPath', + 'any', + 'resolvesToNumber', + 'numberFieldPath', + 'number', + 'resolvesToDouble', + 'doubleFieldPath', + 'double', + 'resolvesToString', + 'stringFieldPath', + 'string', + 'resolvesToObject', + 'objectFieldPath', + 'object', + 'resolvesToArray', + 'arrayFieldPath', + 'array', + 'resolvesToBinData', + 'binDataFieldPath', + 'binData', + 'resolvesToObjectId', + 'objectIdFieldPath', + 'objectId', + 'resolvesToBool', + 'boolFieldPath', + 'bool', + 'resolvesToDate', + 'dateFieldPath', + 'date', + 'resolvesToNull', + 'nullFieldPath', + 'null', + 'resolvesToRegex', + 'regexFieldPath', + 'regex', + 'resolvesToJavascript', + 'javascriptFieldPath', + 'javascript', + 'resolvesToInt', + 'intFieldPath', + 'int', + 'resolvesToTimestamp', + 'timestampFieldPath', + 'timestamp', + 'resolvesToLong', + 'longFieldPath', + 'long', + 'resolvesToDecimal', + 'decimalFieldPath', + 'decimal', + 'searchPath', + 'searchScore', + 'bitwiseOperation', + 'searchOperator', + ]), + z.object({ + name: z.enum([ + 'stage', + 'updateStage', + 'inputStage', + 'outputStage', + 'accumulator', + 'query', + 'fieldQuery', + 'pipeline', + 'updatePipeline', + 'untypedPipeline', + 'window', + 'expression', + 'expressionMap', + 'geometry', + 'unprefixedFieldPath', + 'timeUnit', + 'sortSpec', + 'granularity', + 'timeGranularity', + 'fullDocument', + 'fullDocumentBeforeChange', + 'accumulatorPercentile', + 'whenMatched', + 'whenNotMatched', + 'scoreNormalization', + 'outCollection', + 'range', + 'sortBy', + 'geoPoint', + 'resolvesToAny', + 'fieldPath', + 'any', + 'resolvesToNumber', + 'numberFieldPath', + 'number', + 'resolvesToDouble', + 'doubleFieldPath', + 'double', + 'resolvesToString', + 'stringFieldPath', + 'string', + 'resolvesToObject', + 'objectFieldPath', + 'object', + 'resolvesToArray', + 'arrayFieldPath', + 'array', + 'resolvesToBinData', + 'binDataFieldPath', + 'binData', + 'resolvesToObjectId', + 'objectIdFieldPath', + 'objectId', + 'resolvesToBool', + 'boolFieldPath', + 'bool', + 'resolvesToDate', + 'dateFieldPath', + 'date', + 'resolvesToNull', + 'nullFieldPath', + 'null', + 'resolvesToRegex', + 'regexFieldPath', + 'regex', + 'resolvesToJavascript', + 'javascriptFieldPath', + 'javascript', + 'resolvesToInt', + 'intFieldPath', + 'int', + 'resolvesToTimestamp', + 'timestampFieldPath', + 'timestamp', + 'resolvesToLong', + 'longFieldPath', + 'long', + 'resolvesToDecimal', + 'decimalFieldPath', + 'decimal', + 'searchPath', + 'searchScore', + 'bitwiseOperation', + 'searchOperator', + ]), + generic: z.string().optional(), + }), ]), ), description: z.string().optional(), optional: z.boolean().optional(), valueMin: z.number().optional(), valueMax: z.number().optional(), + minItems: z.number().int().gte(0).optional(), + maxItems: z.number().int().gte(0).optional(), variadic: z.enum(['array', 'object']).optional(), variadicMin: z.number().int().gte(0).optional(), default: z @@ -145,79 +292,144 @@ export const Operator = z }), ) .optional(), + arguments: z.array(z.any()).optional(), }) .strict(), ) .optional(), tests: z .array( - z - .object({ - name: z.string().optional(), - link: z.string().url().regex(new RegExp('^https://')).optional(), - pipeline: z.array(z.record(z.any())).optional(), - filter: z.record(z.any()).optional(), - update: z.record(z.any()).optional(), - schema: z - .union([ - z.record( + z.union([ + z + .object({ + name: z.string(), + link: z.string().url().regex(new RegExp('^https://')).optional(), + pipeline: z.array(z.record(z.any())), + schema: z + .union([ z.record( - z - .object({ - types: z.array( - z.union([ - z - .object({ - bsonType: z.enum([ - 'Array', - 'Binary', - 'Boolean', - 'Code', - 'CodeWScope', - 'Date', - 'Decimal128', - 'Double', - 'Int32', - 'Int64', - 'Long', - 'MaxKey', - 'MinKey', - 'Null', - 'ObjectId', - 'BSONRegExp', - 'String', - 'BSONSymbol', - 'Timestamp', - 'Undefined', - 'Document', - 'Number', - ]), - }) - .strict(), - z - .object({ - bsonType: z.literal('Array'), - types: z.array(z.record(z.any())), - }) - .strict(), - z - .object({ - bsonType: z.literal('Document'), - fields: z.record(z.record(z.any())), - }) - .strict(), - ]), - ), - }) - .strict(), + z.record( + z + .object({ + types: z.array( + z.union([ + z + .object({ + bsonType: z.enum([ + 'Array', + 'Binary', + 'Boolean', + 'Code', + 'CodeWScope', + 'Date', + 'Decimal128', + 'Double', + 'Int32', + 'Int64', + 'Long', + 'MaxKey', + 'MinKey', + 'Null', + 'ObjectId', + 'BSONRegExp', + 'String', + 'BSONSymbol', + 'Timestamp', + 'Undefined', + 'Document', + 'Number', + ]), + }) + .strict(), + z + .object({ + bsonType: z.literal('Array'), + types: z.array(z.record(z.any())), + }) + .strict(), + z + .object({ + bsonType: z.literal('Document'), + fields: z.record(z.record(z.any())), + }) + .strict(), + ]), + ), + }) + .strict(), + ), ), - ), - z.string(), - ]) - .optional(), - }) - .strict() - .and(z.union([z.any(), z.any()])), + z.string(), + ]) + .optional(), + }) + .strict(), + z + .object({ + name: z.string(), + link: z.string().url().regex(new RegExp('^https://')).optional(), + filter: z.record(z.any()), + update: z.record(z.any()), + schema: z + .union([ + z.record( + z.record( + z + .object({ + types: z.array( + z.union([ + z + .object({ + bsonType: z.enum([ + 'Array', + 'Binary', + 'Boolean', + 'Code', + 'CodeWScope', + 'Date', + 'Decimal128', + 'Double', + 'Int32', + 'Int64', + 'Long', + 'MaxKey', + 'MinKey', + 'Null', + 'ObjectId', + 'BSONRegExp', + 'String', + 'BSONSymbol', + 'Timestamp', + 'Undefined', + 'Document', + 'Number', + ]), + }) + .strict(), + z + .object({ + bsonType: z.literal('Array'), + types: z.array(z.record(z.any())), + }) + .strict(), + z + .object({ + bsonType: z.literal('Document'), + fields: z.record(z.record(z.any())), + }) + .strict(), + ]), + ), + }) + .strict(), + ), + ), + z.string(), + ]) + .optional(), + }) + .strict(), + ]), ) .optional(), }) diff --git a/packages/mql-typescript/src/schema-generator.ts b/packages/mql-typescript/src/schema-generator.ts index da008079..d2af5275 100644 --- a/packages/mql-typescript/src/schema-generator.ts +++ b/packages/mql-typescript/src/schema-generator.ts @@ -4,13 +4,24 @@ import { GeneratorBase } from './generator'; import { Operator } from './metaschema'; import { capitalize } from './utils'; -type ArgType = NonNullable< - typeof Operator._type.arguments ->[number]['type'][number]; +type ArgumentT = NonNullable[number]; -type SyntheticVariables = NonNullable< - typeof Operator._type.arguments ->[number]['syntheticVariables']; +type TypeRef = ArgumentT['type'][number]; + +// The plain (string) form of a type reference. Type references may also be +// objects carrying a `generic` type parameter, which the generator ignores. +type ArgType = Extract; + +type SyntheticVariables = ArgumentT['syntheticVariables']; + +/** + * Normalizes a type reference (which may be a plain name or an object carrying + * a generic type parameter) to its plain name. Generics are not reflected in + * the generated TypeScript definitions. + */ +function typeRefName(type: T | { name: T }): T { + return typeof type === 'string' ? type : type.name; +} export class SchemaGenerator extends GeneratorBase { private schemaOutputFile = path.resolve( @@ -91,6 +102,8 @@ export class SchemaGenerator extends GeneratorBase { ], searchScore: ['unknown'], granularity: ['string'], + timeGranularity: ['"seconds"', '"minutes"', '"hours"'], + scoreNormalization: ['"none"', '"sigmoid"', '"minMaxScaler"'], fullDocument: ['string'], fullDocumentBeforeChange: ['string'], accumulatorPercentile: ['string'], @@ -125,6 +138,7 @@ export class SchemaGenerator extends GeneratorBase { ], stage_S: [this.toTypeName('StageOperator')], pipeline_S: [this.toTypeName('stage[]')], + updatePipeline_S: [this.toTypeName('updateStage[]')], untypedPipeline: [this.toTypeName('Pipeline')], query_S: [ this.toTypeName('QueryOperator'), @@ -278,7 +292,7 @@ export class SchemaGenerator extends GeneratorBase { // TBD: Nested fields type AFieldPath = KeysOfAType & string; - type FieldExpression = { [k: string]: FieldPath }; + type FieldExpression = { [k: string]: Expression }; type MultiAnalyzerSpec = { value: KeysOfAType; @@ -316,17 +330,25 @@ export class SchemaGenerator extends GeneratorBase { return undefined; } - private emitArg( - arg: NonNullable[number], - named: boolean, - ): void { + private emitArg(arg: ArgumentT, named: boolean): void { if (named) { this.emit(`${arg.name}${arg.optional ? '?' : ''}: `); } - const allowsArrays = arg.type.includes('array'); - const argTypes = arg.type - .filter((t) => t !== 'array') + // Object-typed arguments may carry their own nested `arguments`, which + // describe a typed object structure rather than a free-form record. The + // recursive `arguments` reference is typed as `any` in the generated + // metaschema (the reference cycle is broken during extraction), so we + // restore the element type here. + if (arg.arguments) { + this.emitObjectFromArgs(arg.arguments as ArgumentT[]); + return; + } + + const types = arg.type.map(typeRefName); + const allowsArrays = types.includes('array'); + const nonArrayTypes = types.filter((t) => t !== 'array'); + const argTypes = nonArrayTypes .map((type) => { const name = this.getArgumentTypeName(type, arg.syntheticVariables); if (!name) { @@ -337,8 +359,10 @@ export class SchemaGenerator extends GeneratorBase { .join(' | '); if (allowsArrays) { - if (arg.type.length > 1) { - this.emit(`(${argTypes}) | (${argTypes})[]`); + // `array` is a top-level alternative: the argument may be a plain + // (untyped) array in addition to any of the other listed types. + if (nonArrayTypes.length > 0) { + this.emit(`(${argTypes}) | unknown[]`); } else { this.emit('unknown[]'); } @@ -347,6 +371,22 @@ export class SchemaGenerator extends GeneratorBase { } } + /** + * Emits a typed object literal from a list of (sub-)arguments. Used for + * object-typed arguments that describe a nested, typed structure. + */ + private emitObjectFromArgs(args: ArgumentT[]): void { + this.emit('{'); + for (const arg of args) { + if (arg.description) { + this.emitComment(arg.description); + } + this.emitArg(arg, true); + this.emit(';'); + } + this.emit('}'); + } + /** * This is explicitly handling the case of $slice where an argument in the middle of the array is optional. * This is not allowed by typescript, so we need to convert the array into a union of tuples. @@ -439,7 +479,7 @@ export class SchemaGenerator extends GeneratorBase { } this.emit(`${parsed.name}:`); for (const type of parsed.type) { - (this.typeMappings[`${type}_S`] ??= []).push( + (this.typeMappings[`${typeRefName(type)}_S`] ??= []).push( `${namespace}.${ifaceName}`, ); } @@ -524,7 +564,9 @@ export class SchemaGenerator extends GeneratorBase { `RecordWithStaticFields<${objectType}, ${this.toComment( arg.description, )} ${arg.type - .map((t) => this.getArgumentTypeName(t)) + .map((t) => + this.getArgumentTypeName(typeRefName(t)), + ) .join(' | ')}>`, ); } diff --git a/packages/mql-typescript/src/testGenerator/test-generator.ts b/packages/mql-typescript/src/testGenerator/test-generator.ts index 8d9ca707..96db46d5 100644 --- a/packages/mql-typescript/src/testGenerator/test-generator.ts +++ b/packages/mql-typescript/src/testGenerator/test-generator.ts @@ -58,8 +58,12 @@ export class TestGenerator extends GeneratorBase { return `undefined`; case 'Number': return 'number'; + case 'Array': + return 'unknown[]'; + case 'Document': + return 'Record'; default: - throw new Error(`Unknown BSON type: ${type}`); + throw new Error(`Unknown BSON type: ${String(type)}`); } } @@ -115,7 +119,9 @@ export class TestGenerator extends GeneratorBase { } if (stage instanceof bson.BSONRegExp) { - return `new bson.BSONRegExp('${stage.pattern}', '${stage.options}')`; + return `new bson.BSONRegExp(${JSON.stringify( + stage.pattern, + )}, ${JSON.stringify(stage.options)})`; } if ('$code' in stage && typeof stage.$code === 'string') { @@ -141,14 +147,16 @@ export class TestGenerator extends GeneratorBase { operator: string, test: TestType, ): void { - if (!test.pipeline) { - this.emit(`// TODO: No pipeline found for ${operator}.${test.name}\n`); + if (!('pipeline' in test) || !test.pipeline) { + this.emit( + `// TODO: No pipeline found for ${operator}.${String(test.name)}\n`, + ); return; } if (!test.schema || typeof test.schema === 'string') { this.emit( - `// TODO: no schema found for ${operator}.${test.name}${test.schema ? `: ${test.schema}` : ''}\n`, + `// TODO: no schema found for ${operator}.${String(test.name)}${test.schema ? `: ${test.schema}` : ''}\n`, ); return; } @@ -168,7 +176,9 @@ export class TestGenerator extends GeneratorBase { // Some pipelines project to new types, which is not supported by the static type system. // In this case, we typecast to any to suppress the type error. const unsupportedStage = - unsupportedAggregations[category]?.[operator]?.[test.name]; + test.name === undefined + ? undefined + : unsupportedAggregations[category]?.[operator]?.[test.name]; const isUnsupportedStage = unsupportedStage && i >= unsupportedStage.stage; @@ -191,6 +201,14 @@ export class TestGenerator extends GeneratorBase { protected override async generateImpl(yamlFiles: YamlFiles): Promise { for await (const file of yamlFiles) { + // Update operators describe `filter`/`update` examples rather than + // aggregation pipelines, which the test harness cannot currently render + // (there is no associated collection schema to type them against), so we + // skip generating spec files for them. + if (file.category === 'update') { + continue; + } + const namespace = `${capitalize(file.category)}Operators`; const basePath = path.resolve( diff --git a/packages/mql-typescript/src/testGenerator/unsupported-aggregations.ts b/packages/mql-typescript/src/testGenerator/unsupported-aggregations.ts index c89f0378..1def97bd 100644 --- a/packages/mql-typescript/src/testGenerator/unsupported-aggregations.ts +++ b/packages/mql-typescript/src/testGenerator/unsupported-aggregations.ts @@ -14,6 +14,18 @@ export const unsupportedAggregations: { }, }, expression: { + top: { + Example: { stage: 0, comment: nestedFieldsExplanation }, + }, + topN: { + Example: { stage: 0, comment: nestedFieldsExplanation }, + }, + bottom: { + Example: { stage: 0, comment: nestedFieldsExplanation }, + }, + bottomN: { + Example: { stage: 0, comment: nestedFieldsExplanation }, + }, arrayToObject: { ['$objectToArray and $arrayToObject Example']: { stage: 1 }, }, @@ -49,6 +61,11 @@ export const unsupportedAggregations: { comment: '$map references the variable names defined in the `as` field, which is not available statically', }, + 'Use Array Index': { + stage: 0, + comment: + '$map references the variable names defined in the `as` and `arrayIndexAs` fields, which is not available statically', + }, }, objectToArray: { '$objectToArray to Sum Nested Fields': { stage: 1 }, @@ -109,6 +126,26 @@ export const unsupportedAggregations: { }, }, search: { + hasRoot: { + 'Simple Query': { + stage: 0, + comment: nestedFieldsExplanation, + }, + 'Multi-Level Query': { + stage: 0, + comment: nestedFieldsExplanation, + }, + 'Compound Query': { + stage: 0, + comment: nestedFieldsExplanation, + }, + }, + hasAncestor: { + Example: { + stage: 0, + comment: nestedFieldsExplanation, + }, + }, embeddedDocument: { 'Query for Matching Embedded Documents Only': { stage: 2, @@ -192,6 +229,18 @@ export const unsupportedAggregations: { 'the output field of the $bucket stage generates new fields that are not available statically', }, }, + lookup: { + 'Perform an Uncorrelated Subquery with $lookup': { + stage: 0, + comment: + 'the lookup sub-pipeline references fields from the joined collection that are not available statically', + }, + 'Perform a Concise Correlated Subquery with $lookup': { + stage: 0, + comment: + 'the lookup sub-pipeline references the variables defined in the `let` field, which are not available statically', + }, + }, currentOp: { 'Inactive Sessions': { stage: 1, diff --git a/packages/mql-typescript/tests/accumulator/concatArrays.spec.ts b/packages/mql-typescript/tests/accumulator/concatArrays.spec.ts new file mode 100644 index 00000000..5219704f --- /dev/null +++ b/packages/mql-typescript/tests/accumulator/concatArrays.spec.ts @@ -0,0 +1,13 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ +/* eslint-disable filename-rules/match */ +/* eslint-disable @typescript-eslint/consistent-type-imports */ +import type * as schema from '../../out/schema'; +import * as bson from 'bson'; + +/** + * Warehouse collection + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/concatArrays/#example} + */ +function test0() { + // TODO: no schema found for concatArrays.Warehouse collection +} diff --git a/packages/mql-typescript/tests/accumulator/minMaxScaler.spec.ts b/packages/mql-typescript/tests/accumulator/minMaxScaler.spec.ts new file mode 100644 index 00000000..07e7db73 --- /dev/null +++ b/packages/mql-typescript/tests/accumulator/minMaxScaler.spec.ts @@ -0,0 +1,27 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ +/* eslint-disable filename-rules/match */ +/* eslint-disable @typescript-eslint/consistent-type-imports */ +import type * as schema from '../../out/schema'; +import * as bson from 'bson'; + +/** + * Normalize values with custom range + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/minMaxScaler/#examples} + */ +function test0() { + type example = { + a: number; + }; + + const aggregation: schema.Pipeline = [ + { + $setWindowFields: { + sortBy: { a: 1 }, + output: { + scaled: { $minMaxScaler: { input: '$a' } }, + scaledTo100: { $minMaxScaler: { input: '$a', min: 0, max: 100 } }, + }, + }, + }, + ]; +} diff --git a/packages/mql-typescript/tests/accumulator/setUnion.spec.ts b/packages/mql-typescript/tests/accumulator/setUnion.spec.ts new file mode 100644 index 00000000..c82cf373 --- /dev/null +++ b/packages/mql-typescript/tests/accumulator/setUnion.spec.ts @@ -0,0 +1,13 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ +/* eslint-disable filename-rules/match */ +/* eslint-disable @typescript-eslint/consistent-type-imports */ +import type * as schema from '../../out/schema'; +import * as bson from 'bson'; + +/** + * Flowers collection + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/setUnion/#example} + */ +function test0() { + // TODO: no schema found for setUnion.Flowers collection +} diff --git a/packages/mql-typescript/tests/expression/avg.spec.ts b/packages/mql-typescript/tests/expression/avg.spec.ts index 60f4acd0..585cc536 100644 --- a/packages/mql-typescript/tests/expression/avg.spec.ts +++ b/packages/mql-typescript/tests/expression/avg.spec.ts @@ -20,8 +20,8 @@ function test0() { const aggregation: schema.Pipeline = [ { $project: { - quizAvg: { $avg: '$quizzes' }, - labAvg: { $avg: '$labs' }, + quizAvg: { $avg: ['$quizzes'] }, + labAvg: { $avg: ['$labs'] }, examAvg: { $avg: ['$final', '$midterm'] }, }, }, diff --git a/packages/mql-typescript/tests/expression/bottom.spec.ts b/packages/mql-typescript/tests/expression/bottom.spec.ts new file mode 100644 index 00000000..c0e26dab --- /dev/null +++ b/packages/mql-typescript/tests/expression/bottom.spec.ts @@ -0,0 +1,35 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ +/* eslint-disable filename-rules/match */ +/* eslint-disable @typescript-eslint/consistent-type-imports */ +import type * as schema from '../../out/schema'; +import * as bson from 'bson'; + +/** + * Example + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/bottom-array-operator/#example} + */ +function test0() { + type games = { + results: Array<{ + playerId: string; + score: number; + }>; + }; + + const aggregation: schema.Pipeline = [ + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). + */ + { + $project: { + bottomScore: { + $bottom: { + sortBy: { score: -1 }, + output: ['$playerId', '$score'], + input: '$results', + }, + }, + }, + } as any, + ]; +} diff --git a/packages/mql-typescript/tests/expression/bottomN.spec.ts b/packages/mql-typescript/tests/expression/bottomN.spec.ts new file mode 100644 index 00000000..dee7411c --- /dev/null +++ b/packages/mql-typescript/tests/expression/bottomN.spec.ts @@ -0,0 +1,36 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ +/* eslint-disable filename-rules/match */ +/* eslint-disable @typescript-eslint/consistent-type-imports */ +import type * as schema from '../../out/schema'; +import * as bson from 'bson'; + +/** + * Example + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/bottomN-array-operator/#example} + */ +function test0() { + type games = { + results: Array<{ + playerId: string; + score: number; + }>; + }; + + const aggregation: schema.Pipeline = [ + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). + */ + { + $project: { + bottomScores: { + $bottomN: { + n: 3, + sortBy: { score: -1 }, + output: ['$playerId', '$score'], + input: '$results', + }, + }, + }, + } as any, + ]; +} diff --git a/packages/mql-typescript/tests/expression/convert.spec.ts b/packages/mql-typescript/tests/expression/convert.spec.ts index 0e111048..5f34eb13 100644 --- a/packages/mql-typescript/tests/expression/convert.spec.ts +++ b/packages/mql-typescript/tests/expression/convert.spec.ts @@ -87,3 +87,43 @@ function test0() { } as any, ]; } + +/** + * Convert Hexadecimal String to Integer + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/convert/#base-conversion} + */ +function test1() { + type data = { + _id: number; + hexString: string; + }; + + const aggregation: schema.Pipeline = [ + { + $project: { + decimalValue: { + $convert: { input: '$hexString', to: 'int', base: 16 }, + }, + }, + }, + ]; +} + +/** + * Convert Integer to Binary String + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/convert/#base-conversion} + */ +function test2() { + type data = { + _id: number; + value: bson.Int32 | number; + }; + + const aggregation: schema.Pipeline = [ + { + $project: { + binaryString: { $convert: { input: '$value', to: 'string', base: 2 } }, + }, + }, + ]; +} diff --git a/packages/mql-typescript/tests/expression/createObjectId.spec.ts b/packages/mql-typescript/tests/expression/createObjectId.spec.ts new file mode 100644 index 00000000..c347bd80 --- /dev/null +++ b/packages/mql-typescript/tests/expression/createObjectId.spec.ts @@ -0,0 +1,13 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ +/* eslint-disable filename-rules/match */ +/* eslint-disable @typescript-eslint/consistent-type-imports */ +import type * as schema from '../../out/schema'; +import * as bson from 'bson'; + +/** + * Example + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/createObjectId/#example} + */ +function test0() { + // TODO: no schema found for createObjectId.Example +} diff --git a/packages/mql-typescript/tests/expression/deserializeEJSON.spec.ts b/packages/mql-typescript/tests/expression/deserializeEJSON.spec.ts new file mode 100644 index 00000000..a8d566ee --- /dev/null +++ b/packages/mql-typescript/tests/expression/deserializeEJSON.spec.ts @@ -0,0 +1,110 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ +/* eslint-disable filename-rules/match */ +/* eslint-disable @typescript-eslint/consistent-type-imports */ +import type * as schema from '../../out/schema'; +import * as bson from 'bson'; + +/** + * Deserialize Extended JSON Document + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/deserializeEJSON/#deserialize-extended-json-document} + */ +function test0() { + type movies = { + _id: bson.ObjectId; + title: string; + year: bson.Int32 | number; + runtime: bson.Int32 | number; + released: Date; + cast: unknown[]; + genres: unknown[]; + directors: unknown[]; + }; + + const aggregation: schema.Pipeline = [ + { $match: { title: 'Inception' } }, + { + $project: { + original: '$$ROOT', + serialized: { $serializeEJSON: { input: '$$ROOT' } }, + }, + }, + { + $project: { + title: '$original.title', + deserialized: { $deserializeEJSON: { input: '$serialized' } }, + }, + }, + ]; +} + +/** + * Parse JSON String and Deserialize + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/deserializeEJSON/#parse-json-string-and-deserialize} + */ +function test1() { + // TODO: no schema found for deserializeEJSON.Parse JSON String and Deserialize +} + +/** + * Deserialize Specific Fields + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/deserializeEJSON/#deserialize-specific-fields} + */ +function test2() { + type movies = { + _id: bson.ObjectId; + title: string; + released: Date; + runtime: bson.Int32 | number; + imdb: { + rating: bson.Double | number; + }; + }; + + const aggregation: schema.Pipeline = [ + { $match: { title: 'Inception' } }, + { + $project: { + title: 1, + serializedMetadata: { + $serializeEJSON: { + input: { + releaseDate: '$released', + runtime: '$runtime', + rating: '$imdb.rating', + }, + }, + }, + }, + }, + { + $project: { + title: 1, + metadata: { $deserializeEJSON: { input: '$serializedMetadata' } }, + }, + }, + ]; +} + +/** + * Use onError for Error Handling + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/deserializeEJSON/#use-onerror-for-error-handling} + */ +function test3() { + type data = { + _id: bson.ObjectId; + ejsonField: string; + }; + + const aggregation: schema.Pipeline = [ + { + $project: { + result: { + $deserializeEJSON: { + input: '$ejsonField', + onError: { error: 'Invalid EJSON format' }, + }, + }, + }, + }, + ]; +} diff --git a/packages/mql-typescript/tests/expression/hash.spec.ts b/packages/mql-typescript/tests/expression/hash.spec.ts new file mode 100644 index 00000000..5e826e86 --- /dev/null +++ b/packages/mql-typescript/tests/expression/hash.spec.ts @@ -0,0 +1,69 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ +/* eslint-disable filename-rules/match */ +/* eslint-disable @typescript-eslint/consistent-type-imports */ +import type * as schema from '../../out/schema'; +import * as bson from 'bson'; + +/** + * Hash a Field Value + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/hash/#hash-a-field-value} + */ +function test0() { + type files = { + _id: number; + filename: string; + hash: bson.Binary; + }; + + const aggregation: schema.Pipeline = [ + { + $project: { + filename: 1, + hash: { $hash: { input: '$filename', algorithm: 'sha256' } }, + }, + }, + ]; +} + +/** + * Hash a Literal String + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/hash/#hash-a-literal-string} + */ +function test1() { + type TestCollection = { + val: string; + }; + + const aggregation: schema.Pipeline = [ + { $documents: [{ val: 'hello' }] }, + { + $project: { + _id: 0, + hash: { $hash: { input: '$val', algorithm: 'xxh64' } }, + }, + }, + ]; +} + +/** + * Hash BinData + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/hash/#hash-bindata} + */ +function test2() { + type binaries = { + _id: number; + data: bson.Binary; + }; + + const aggregation: schema.Pipeline = [ + { $project: { hash: { $hash: { input: '$data', algorithm: 'sha256' } } } }, + ]; +} + +/** + * Null or Missing Input + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/hash/#null-or-missing-input} + */ +function test3() { + // TODO: no schema found for hash.Null or Missing Input +} diff --git a/packages/mql-typescript/tests/expression/hexHash.spec.ts b/packages/mql-typescript/tests/expression/hexHash.spec.ts new file mode 100644 index 00000000..2446fae6 --- /dev/null +++ b/packages/mql-typescript/tests/expression/hexHash.spec.ts @@ -0,0 +1,34 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ +/* eslint-disable filename-rules/match */ +/* eslint-disable @typescript-eslint/consistent-type-imports */ +import type * as schema from '../../out/schema'; +import * as bson from 'bson'; + +/** + * Hash a Field Value + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/hexHash/#hash-a-field-value} + */ +function test0() { + type files = { + _id: number; + filename: string; + hexHash: string; + }; + + const aggregation: schema.Pipeline = [ + { + $project: { + filename: 1, + hexHash: { $hexHash: { input: '$filename', algorithm: 'sha256' } }, + }, + }, + ]; +} + +/** + * Null or Missing Input + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/hexHash/#null-or-missing-input} + */ +function test1() { + // TODO: no schema found for hexHash.Null or Missing Input +} diff --git a/packages/mql-typescript/tests/expression/map.spec.ts b/packages/mql-typescript/tests/expression/map.spec.ts index ffae3cd2..ac9b3f56 100644 --- a/packages/mql-typescript/tests/expression/map.spec.ts +++ b/packages/mql-typescript/tests/expression/map.spec.ts @@ -87,3 +87,31 @@ function test2() { } as any, ]; } + +/** + * Use Array Index + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/map/} + */ +function test3() { + type data = { + scores: Array; + }; + + const aggregation: schema.Pipeline = [ + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' ($map references the variable names defined in the `as` and `arrayIndexAs` fields, which is not available statically). + */ + { + $project: { + result: { + $map: { + input: '$scores', + as: 'score', + arrayIndexAs: 'idx', + in: { $add: ['$$score', '$$idx'] }, + }, + }, + }, + } as any, + ]; +} diff --git a/packages/mql-typescript/tests/expression/replaceAll.spec.ts b/packages/mql-typescript/tests/expression/replaceAll.spec.ts index e1bc4153..c8b7ff3c 100644 --- a/packages/mql-typescript/tests/expression/replaceAll.spec.ts +++ b/packages/mql-typescript/tests/expression/replaceAll.spec.ts @@ -5,8 +5,8 @@ import type * as schema from '../../out/schema'; import * as bson from 'bson'; /** - * Example - * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceAll/#example} + * Replace Using a String + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceAll/#replace-using-a-string} */ function test0() { type inventory = { @@ -28,3 +28,28 @@ function test0() { }, ]; } + +/** + * Replace Using Regex + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceAll/#replace-using-regex} + */ +function test1() { + type inventory = { + _id: number; + item: string; + }; + + const aggregation: schema.Pipeline = [ + { + $project: { + item: { + $replaceAll: { + input: '$item', + find: new bson.BSONRegExp('\\bblue paint\\b', ''), + replacement: 'red paint', + }, + }, + }, + }, + ]; +} diff --git a/packages/mql-typescript/tests/expression/replaceOne.spec.ts b/packages/mql-typescript/tests/expression/replaceOne.spec.ts index 99b1cbbe..09c91e1f 100644 --- a/packages/mql-typescript/tests/expression/replaceOne.spec.ts +++ b/packages/mql-typescript/tests/expression/replaceOne.spec.ts @@ -28,3 +28,28 @@ function test0() { }, ]; } + +/** + * Replace Using Regex + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceOne/#replace-using-regex} + */ +function test1() { + type inventory = { + _id: number; + item: string; + }; + + const aggregation: schema.Pipeline = [ + { + $project: { + item: { + $replaceOne: { + input: '$item', + find: new bson.BSONRegExp('\\bblue paint\\b', ''), + replacement: 'red paint', + }, + }, + }, + }, + ]; +} diff --git a/packages/mql-typescript/tests/expression/serializeEJSON.spec.ts b/packages/mql-typescript/tests/expression/serializeEJSON.spec.ts new file mode 100644 index 00000000..af60c119 --- /dev/null +++ b/packages/mql-typescript/tests/expression/serializeEJSON.spec.ts @@ -0,0 +1,137 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ +/* eslint-disable filename-rules/match */ +/* eslint-disable @typescript-eslint/consistent-type-imports */ +import type * as schema from '../../out/schema'; +import * as bson from 'bson'; + +/** + * Canonical Extended JSON Example + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/serializeEJSON/#canonical-extended-json-example} + */ +function test0() { + type movies = { + _id: bson.ObjectId; + title: string; + year: bson.Int32 | number; + runtime: bson.Int32 | number; + released: Date; + cast: unknown[]; + genres: unknown[]; + directors: unknown[]; + }; + + const aggregation: schema.Pipeline = [ + { $match: { title: 'Inception' } }, + { $project: { ejson: { $serializeEJSON: { input: '$$ROOT' } } } }, + ]; +} + +/** + * Relaxed Extended JSON Example + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/serializeEJSON/#relaxed-extended-json-example} + */ +function test1() { + type movies = { + _id: bson.ObjectId; + title: string; + year: bson.Int32 | number; + runtime: bson.Int32 | number; + released: Date; + cast: unknown[]; + genres: unknown[]; + directors: unknown[]; + }; + + const aggregation: schema.Pipeline = [ + { $match: { title: 'Inception' } }, + { + $project: { + ejson: { $serializeEJSON: { input: '$$ROOT', relaxed: true } }, + }, + }, + ]; +} + +/** + * Convert to JSON String + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/serializeEJSON/#convert-to-json-string} + */ +function test2() { + type movies = { + _id: bson.ObjectId; + title: string; + year: bson.Int32 | number; + released: Date; + }; + + const aggregation: schema.Pipeline = [ + { $match: { title: 'The Godfather' } }, + { + $project: { + title: 1, + jsonString: { $toString: { $serializeEJSON: { input: '$$ROOT' } } }, + }, + }, + ]; +} + +/** + * Serialize Specific Fields + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/serializeEJSON/#serialize-specific-fields} + */ +function test3() { + type movies = { + _id: bson.ObjectId; + title: string; + year: bson.Int32 | number; + released: Date; + runtime: bson.Int32 | number; + imdb: { + rating: bson.Double | number; + }; + }; + + const aggregation: schema.Pipeline = [ + { $match: { year: { $gte: 2010 } } }, + { + $project: { + title: 1, + metadataEJSON: { + $serializeEJSON: { + input: { + releaseDate: '$released', + runtime: '$runtime', + imdbRating: '$imdb.rating', + }, + }, + }, + }, + }, + ]; +} + +/** + * Use onError for Error Handling + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/serializeEJSON/#use-onerror-for-error-handling} + */ +function test4() { + type movies = { + _id: bson.ObjectId; + title: string; + customField: string; + }; + + const aggregation: schema.Pipeline = [ + { + $project: { + title: 1, + ejson: { + $serializeEJSON: { + input: '$customField', + onError: { error: 'Serialization failed' }, + }, + }, + }, + }, + ]; +} diff --git a/packages/mql-typescript/tests/expression/sigmoid.spec.ts b/packages/mql-typescript/tests/expression/sigmoid.spec.ts new file mode 100644 index 00000000..91dab8cf --- /dev/null +++ b/packages/mql-typescript/tests/expression/sigmoid.spec.ts @@ -0,0 +1,20 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ +/* eslint-disable filename-rules/match */ +/* eslint-disable @typescript-eslint/consistent-type-imports */ +import type * as schema from '../../out/schema'; +import * as bson from 'bson'; + +/** + * Example + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/sigmoid/#examples} + */ +function test0() { + type scores = { + _id: bson.ObjectId; + score: bson.Double | number; + }; + + const aggregation: schema.Pipeline = [ + { $set: { scaled: { $sigmoid: '$score' } } }, + ]; +} diff --git a/packages/mql-typescript/tests/expression/similarityCosine.spec.ts b/packages/mql-typescript/tests/expression/similarityCosine.spec.ts new file mode 100644 index 00000000..6214a409 --- /dev/null +++ b/packages/mql-typescript/tests/expression/similarityCosine.spec.ts @@ -0,0 +1,28 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ +/* eslint-disable filename-rules/match */ +/* eslint-disable @typescript-eslint/consistent-type-imports */ +import type * as schema from '../../out/schema'; +import * as bson from 'bson'; + +/** + * Example + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/similarityCosine/#example} + */ +function test0() { + type vectors = { + _id: number; + a: Array; + b: Array; + }; + + const aggregation: schema.Pipeline = [ + { + $project: { + raw: { $similarityCosine: { vectors: ['$a', '$b'] } }, + normalized: { + $similarityCosine: { vectors: ['$a', '$b'], score: true }, + }, + }, + }, + ]; +} diff --git a/packages/mql-typescript/tests/expression/similarityDotProduct.spec.ts b/packages/mql-typescript/tests/expression/similarityDotProduct.spec.ts new file mode 100644 index 00000000..a6f26032 --- /dev/null +++ b/packages/mql-typescript/tests/expression/similarityDotProduct.spec.ts @@ -0,0 +1,28 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ +/* eslint-disable filename-rules/match */ +/* eslint-disable @typescript-eslint/consistent-type-imports */ +import type * as schema from '../../out/schema'; +import * as bson from 'bson'; + +/** + * Example + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/similarityDotProduct/#example} + */ +function test0() { + type vectors = { + _id: number; + a: Array; + b: Array; + }; + + const aggregation: schema.Pipeline = [ + { + $project: { + raw: { $similarityDotProduct: { vectors: ['$a', '$b'] } }, + normalized: { + $similarityDotProduct: { vectors: ['$a', '$b'], score: true }, + }, + }, + }, + ]; +} diff --git a/packages/mql-typescript/tests/expression/similarityEuclidean.spec.ts b/packages/mql-typescript/tests/expression/similarityEuclidean.spec.ts new file mode 100644 index 00000000..8ec54850 --- /dev/null +++ b/packages/mql-typescript/tests/expression/similarityEuclidean.spec.ts @@ -0,0 +1,28 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ +/* eslint-disable filename-rules/match */ +/* eslint-disable @typescript-eslint/consistent-type-imports */ +import type * as schema from '../../out/schema'; +import * as bson from 'bson'; + +/** + * Example + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/similarityEuclidean/#example} + */ +function test0() { + type vectors = { + _id: number; + a: Array; + b: Array; + }; + + const aggregation: schema.Pipeline = [ + { + $project: { + raw: { $similarityEuclidean: { vectors: ['$a', '$b'] } }, + normalized: { + $similarityEuclidean: { vectors: ['$a', '$b'], score: true }, + }, + }, + }, + ]; +} diff --git a/packages/mql-typescript/tests/expression/subtype.spec.ts b/packages/mql-typescript/tests/expression/subtype.spec.ts new file mode 100644 index 00000000..7b69cbe0 --- /dev/null +++ b/packages/mql-typescript/tests/expression/subtype.spec.ts @@ -0,0 +1,19 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ +/* eslint-disable filename-rules/match */ +/* eslint-disable @typescript-eslint/consistent-type-imports */ +import type * as schema from '../../out/schema'; +import * as bson from 'bson'; + +/** + * Example + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/subtype/} + */ +function test0() { + type data = { + myBinDataField: bson.Binary; + }; + + const aggregation: schema.Pipeline = [ + { $project: { result: { $subtype: '$myBinDataField' } } }, + ]; +} diff --git a/packages/mql-typescript/tests/expression/toArray.spec.ts b/packages/mql-typescript/tests/expression/toArray.spec.ts new file mode 100644 index 00000000..23927237 --- /dev/null +++ b/packages/mql-typescript/tests/expression/toArray.spec.ts @@ -0,0 +1,40 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ +/* eslint-disable filename-rules/match */ +/* eslint-disable @typescript-eslint/consistent-type-imports */ +import type * as schema from '../../out/schema'; +import * as bson from 'bson'; + +/** + * Convert String to Array + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/toArray/#convert-string-to-array} + */ +function test0() { + type jsonStrings = { + _id: number; + }; + + const aggregation: schema.Pipeline = [ + { + $project: { + _id: 0, + numbers: { $toArray: '[1, 2, 3]' }, + documents: { $toArray: '[{"a": 1}, {"b": 2}]' }, + }, + }, + ]; +} + +/** + * Convert binData to Array + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/toArray/#convert-bindata-to-array} + */ +function test1() { + type t = { + _id: number; + v: bson.Binary; + }; + + const aggregation: schema.Pipeline = [ + { $project: { _id: 0, original: '$v', asArray: { $toArray: '$v' } } }, + ]; +} diff --git a/packages/mql-typescript/tests/expression/toObject.spec.ts b/packages/mql-typescript/tests/expression/toObject.spec.ts new file mode 100644 index 00000000..1cc320f8 --- /dev/null +++ b/packages/mql-typescript/tests/expression/toObject.spec.ts @@ -0,0 +1,20 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ +/* eslint-disable filename-rules/match */ +/* eslint-disable @typescript-eslint/consistent-type-imports */ +import type * as schema from '../../out/schema'; +import * as bson from 'bson'; + +/** + * Convert String to Object + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/toObject/#convert-string-to-object} + */ +function test0() { + type jsonStrings = { + _id: number; + config: string; + }; + + const aggregation: schema.Pipeline = [ + { $project: { _id: 0, parsedConfig: { $toObject: '$config' } } }, + ]; +} diff --git a/packages/mql-typescript/tests/expression/top.spec.ts b/packages/mql-typescript/tests/expression/top.spec.ts new file mode 100644 index 00000000..1d160192 --- /dev/null +++ b/packages/mql-typescript/tests/expression/top.spec.ts @@ -0,0 +1,35 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ +/* eslint-disable filename-rules/match */ +/* eslint-disable @typescript-eslint/consistent-type-imports */ +import type * as schema from '../../out/schema'; +import * as bson from 'bson'; + +/** + * Example + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/top-array-operator/#example} + */ +function test0() { + type games = { + results: Array<{ + playerId: string; + score: number; + }>; + }; + + const aggregation: schema.Pipeline = [ + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). + */ + { + $project: { + topScore: { + $top: { + sortBy: { score: -1 }, + output: ['$playerId', '$score'], + input: '$results', + }, + }, + }, + } as any, + ]; +} diff --git a/packages/mql-typescript/tests/expression/topN.spec.ts b/packages/mql-typescript/tests/expression/topN.spec.ts new file mode 100644 index 00000000..3aa12423 --- /dev/null +++ b/packages/mql-typescript/tests/expression/topN.spec.ts @@ -0,0 +1,36 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ +/* eslint-disable filename-rules/match */ +/* eslint-disable @typescript-eslint/consistent-type-imports */ +import type * as schema from '../../out/schema'; +import * as bson from 'bson'; + +/** + * Example + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/topN-array-operator/#example} + */ +function test0() { + type games = { + results: Array<{ + playerId: string; + score: number; + }>; + }; + + const aggregation: schema.Pipeline = [ + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). + */ + { + $project: { + topScores: { + $topN: { + n: 3, + sortBy: { score: -1 }, + output: ['$playerId', '$score'], + input: '$results', + }, + }, + }, + } as any, + ]; +} diff --git a/packages/mql-typescript/tests/query/all.spec.ts b/packages/mql-typescript/tests/query/all.spec.ts index 5b197a10..dc6372fe 100644 --- a/packages/mql-typescript/tests/query/all.spec.ts +++ b/packages/mql-typescript/tests/query/all.spec.ts @@ -9,20 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/all/#use--all-to-match-values} */ function test0() { - type inventory = { - _id: bson.ObjectId; - code: string; - tags: Array; - qty: Array<{ - size: string; - num: number; - color: string; - }>; - }; - - const aggregation: schema.Pipeline = [ - { $match: { tags: { $all: ['appliance', 'school', 'book'] } } }, - ]; + // TODO: no schema found for all.Use $all to Match Values } /** @@ -30,27 +17,5 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/all/#use--all-with--elemmatch} */ function test1() { - type inventory = { - _id: bson.ObjectId; - code: string; - tags: Array; - qty: Array<{ - size: string; - num: number; - color: string; - }>; - }; - - const aggregation: schema.Pipeline = [ - { - $match: { - qty: { - $all: [ - { $elemMatch: { size: 'M', num: { $gt: 50 } } }, - { $elemMatch: { num: 100, color: 'green' } }, - ], - }, - }, - }, - ]; + // TODO: no schema found for all.Use $all with $elemMatch } diff --git a/packages/mql-typescript/tests/query/and.spec.ts b/packages/mql-typescript/tests/query/and.spec.ts index ccad2394..ac3a3ce1 100644 --- a/packages/mql-typescript/tests/query/and.spec.ts +++ b/packages/mql-typescript/tests/query/and.spec.ts @@ -9,21 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/and/#and-queries-with-multiple-expressions-specifying-the-same-field} */ function test0() { - type inventory = { - price: bson.Double | number; - qty: bson.Int32 | number | undefined; - quantity: bson.Int32 | number | undefined; - sale: boolean; - tags: Array; - }; - - const aggregation: schema.Pipeline = [ - { - $match: { - $and: [{ price: { $ne: 1.99 } }, { price: { $exists: true } }], - }, - }, - ]; + // TODO: no schema found for and.AND Queries With Multiple Expressions Specifying the Same Field } /** @@ -31,22 +17,5 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/and/#and-queries-with-multiple-expressions-specifying-the-same-operator} */ function test1() { - type inventory = { - price: bson.Double | number; - qty: bson.Int32 | number | undefined; - quantity: bson.Int32 | number | undefined; - sale: boolean; - tags: Array; - }; - - const aggregation: schema.Pipeline = [ - { - $match: { - $and: [ - { $or: [{ qty: { $lt: 10 } }, { qty: { $gt: 50 } }] }, - { $or: [{ sale: true }, { price: { $lt: 5 } }] }, - ], - }, - }, - ]; + // TODO: no schema found for and.AND Queries With Multiple Expressions Specifying the Same Operator } diff --git a/packages/mql-typescript/tests/query/bitsAllClear.spec.ts b/packages/mql-typescript/tests/query/bitsAllClear.spec.ts index af9cc174..4133e43d 100644 --- a/packages/mql-typescript/tests/query/bitsAllClear.spec.ts +++ b/packages/mql-typescript/tests/query/bitsAllClear.spec.ts @@ -9,15 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/bitsAllClear/#bit-position-array} */ function test0() { - type collection = { - _id: number; - a: number | bson.Binary; - binaryValueofA: string; - }; - - const aggregation: schema.Pipeline = [ - { $match: { a: { $bitsAllClear: [1, 5] } } }, - ]; + // TODO: no schema found for bitsAllClear.Bit Position Array } /** @@ -25,15 +17,7 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/bitsAllClear/#integer-bitmask} */ function test1() { - type collection = { - _id: number; - a: number | bson.Binary; - binaryValueofA: string; - }; - - const aggregation: schema.Pipeline = [ - { $match: { a: { $bitsAllClear: 35 } } }, - ]; + // TODO: no schema found for bitsAllClear.Integer Bitmask } /** @@ -41,15 +25,5 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/bitsAllClear/#bindata-bitmask} */ function test2() { - type collection = { - _id: number; - a: number | bson.Binary; - binaryValueofA: string; - }; - - const aggregation: schema.Pipeline = [ - { - $match: { a: { $bitsAllClear: bson.Binary.createFromBase64('IA==', 0) } }, - }, - ]; + // TODO: no schema found for bitsAllClear.BinData Bitmask } diff --git a/packages/mql-typescript/tests/query/bitsAllSet.spec.ts b/packages/mql-typescript/tests/query/bitsAllSet.spec.ts index 65fb95c8..d88781d3 100644 --- a/packages/mql-typescript/tests/query/bitsAllSet.spec.ts +++ b/packages/mql-typescript/tests/query/bitsAllSet.spec.ts @@ -9,15 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/bitsAllSet/#bit-position-array} */ function test0() { - type collection = { - _id: number; - a: number | bson.Binary; - binaryValueofA: string; - }; - - const aggregation: schema.Pipeline = [ - { $match: { a: { $bitsAllSet: [1, 5] } } }, - ]; + // TODO: no schema found for bitsAllSet.Bit Position Array } /** @@ -25,15 +17,7 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/bitsAllSet/#integer-bitmask} */ function test1() { - type collection = { - _id: number; - a: number | bson.Binary; - binaryValueofA: string; - }; - - const aggregation: schema.Pipeline = [ - { $match: { a: { $bitsAllSet: 50 } } }, - ]; + // TODO: no schema found for bitsAllSet.Integer Bitmask } /** @@ -41,13 +25,5 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/bitsAllSet/#bindata-bitmask} */ function test2() { - type collection = { - _id: number; - a: number | bson.Binary; - binaryValueofA: string; - }; - - const aggregation: schema.Pipeline = [ - { $match: { a: { $bitsAllSet: bson.Binary.createFromBase64('MA==', 0) } } }, - ]; + // TODO: no schema found for bitsAllSet.BinData Bitmask } diff --git a/packages/mql-typescript/tests/query/bitsAnyClear.spec.ts b/packages/mql-typescript/tests/query/bitsAnyClear.spec.ts index ae403359..9f461faf 100644 --- a/packages/mql-typescript/tests/query/bitsAnyClear.spec.ts +++ b/packages/mql-typescript/tests/query/bitsAnyClear.spec.ts @@ -9,15 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/bitsAnyClear/#bit-position-array} */ function test0() { - type collection = { - _id: number; - a: number | bson.Binary; - binaryValueofA: string; - }; - - const aggregation: schema.Pipeline = [ - { $match: { a: { $bitsAnyClear: [1, 5] } } }, - ]; + // TODO: no schema found for bitsAnyClear.Bit Position Array } /** @@ -25,15 +17,7 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/bitsAnyClear/#integer-bitmask} */ function test1() { - type collection = { - _id: number; - a: number | bson.Binary; - binaryValueofA: string; - }; - - const aggregation: schema.Pipeline = [ - { $match: { a: { $bitsAnyClear: 35 } } }, - ]; + // TODO: no schema found for bitsAnyClear.Integer Bitmask } /** @@ -41,15 +25,5 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/bitsAnyClear/#bindata-bitmask} */ function test2() { - type collection = { - _id: number; - a: number | bson.Binary; - binaryValueofA: string; - }; - - const aggregation: schema.Pipeline = [ - { - $match: { a: { $bitsAnyClear: bson.Binary.createFromBase64('MA==', 0) } }, - }, - ]; + // TODO: no schema found for bitsAnyClear.BinData Bitmask } diff --git a/packages/mql-typescript/tests/query/bitsAnySet.spec.ts b/packages/mql-typescript/tests/query/bitsAnySet.spec.ts index cadc533a..5411d9cd 100644 --- a/packages/mql-typescript/tests/query/bitsAnySet.spec.ts +++ b/packages/mql-typescript/tests/query/bitsAnySet.spec.ts @@ -9,15 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/bitsAnySet/#bit-position-array} */ function test0() { - type collection = { - _id: number; - a: number | bson.Binary; - binaryValueofA: string; - }; - - const aggregation: schema.Pipeline = [ - { $match: { a: { $bitsAnySet: [1, 5] } } }, - ]; + // TODO: no schema found for bitsAnySet.Bit Position Array } /** @@ -25,15 +17,7 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/bitsAnySet/#integer-bitmask} */ function test1() { - type collection = { - _id: number; - a: number | bson.Binary; - binaryValueofA: string; - }; - - const aggregation: schema.Pipeline = [ - { $match: { a: { $bitsAnySet: 35 } } }, - ]; + // TODO: no schema found for bitsAnySet.Integer Bitmask } /** @@ -41,13 +25,5 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/bitsAnySet/#bindata-bitmask} */ function test2() { - type collection = { - _id: number; - a: number | bson.Binary; - binaryValueofA: string; - }; - - const aggregation: schema.Pipeline = [ - { $match: { a: { $bitsAnySet: bson.Binary.createFromBase64('MA==', 0) } } }, - ]; + // TODO: no schema found for bitsAnySet.BinData Bitmask } diff --git a/packages/mql-typescript/tests/query/comment.spec.ts b/packages/mql-typescript/tests/query/comment.spec.ts new file mode 100644 index 00000000..0f34750b --- /dev/null +++ b/packages/mql-typescript/tests/query/comment.spec.ts @@ -0,0 +1,13 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ +/* eslint-disable filename-rules/match */ +/* eslint-disable @typescript-eslint/consistent-type-imports */ +import type * as schema from '../../out/schema'; +import * as bson from 'bson'; + +/** + * Attach a Comment to an Aggregation Expression + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/comment/#attach-a-comment-to-an-aggregation-expression} + */ +function test0() { + // TODO: no schema found for comment.Attach a Comment to an Aggregation Expression +} diff --git a/packages/mql-typescript/tests/query/elemMatch.spec.ts b/packages/mql-typescript/tests/query/elemMatch.spec.ts index 4bd3ff84..9a85e122 100644 --- a/packages/mql-typescript/tests/query/elemMatch.spec.ts +++ b/packages/mql-typescript/tests/query/elemMatch.spec.ts @@ -9,14 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/elemMatch/#element-match} */ function test0() { - type TestCollection = { - _id: number; - results: Array; - }; - - const aggregation: schema.Pipeline = [ - { $match: { results: { $elemMatch: { $gte: 80, $lt: 85 } } } }, - ]; + // TODO: no schema found for elemMatch.Element Match } /** @@ -24,26 +17,7 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/elemMatch/#array-of-embedded-documents} */ function test1() { - type survey = { - _id: number; - results: - | Array<{ - product: string; - score: number; - }> - | { - product: string; - score: number; - }; - }; - - const aggregation: schema.Pipeline = [ - { - $match: { - results: { $elemMatch: { product: 'xyz', score: { $gte: 8 } } }, - }, - }, - ]; + // TODO: no schema found for elemMatch.Array of Embedded Documents } /** @@ -51,12 +25,19 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/elemMatch/#single-query-condition} */ function test2() { - type TestCollection = { - _id: number; - results: Array; - }; + // TODO: no schema found for elemMatch.Single Query Condition +} - const aggregation: schema.Pipeline = [ - { $match: { results: { $elemMatch: { product: { $ne: 'xyz' } } } } }, - ]; +/** + * Using $or with $elemMatch + */ +function test3() { + // TODO: no schema found for elemMatch.Using $or with $elemMatch +} + +/** + * Single field operator + */ +function test4() { + // TODO: no schema found for elemMatch.Single field operator } diff --git a/packages/mql-typescript/tests/query/eq.spec.ts b/packages/mql-typescript/tests/query/eq.spec.ts index a1e68caf..8f9be835 100644 --- a/packages/mql-typescript/tests/query/eq.spec.ts +++ b/packages/mql-typescript/tests/query/eq.spec.ts @@ -9,19 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/eq/#equals-a-specified-value} */ function test0() { - type inventory = { - _id: number; - item: { - name: string; - code: string; - }; - qty: number; - tags: Array>; - }; - - const aggregation: schema.Pipeline = [ - { $match: { qty: { $eq: 20 } } }, - ]; + // TODO: no schema found for eq.Equals a Specified Value } /** @@ -29,22 +17,7 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/eq/#field-in-embedded-document-equals-a-value} */ function test1() { - type inventory = { - _id: number; - item: { - name: string; - code: string; - }; - qty: number; - tags: Array>; - }; - - const aggregation: schema.Pipeline = [ - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). - */ - { $match: { 'item.name': { $eq: 'ab' } } } as any, - ]; + // TODO: no schema found for eq.Field in Embedded Document Equals a Value } /** @@ -52,19 +25,7 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/eq/#equals-an-array-value} */ function test2() { - type inventory = { - _id: number; - item: { - name: string; - code: string; - }; - qty: number; - tags: Array>; - }; - - const aggregation: schema.Pipeline = [ - { $match: { tags: { $eq: ['A', 'B'] } } }, - ]; + // TODO: no schema found for eq.Equals an Array Value } /** @@ -72,15 +33,5 @@ function test2() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/eq/#regex-match-behaviour} */ function test3() { - type companies = { - _id: bson.Int32 | number; - company: string; - }; - - const aggregation: schema.Pipeline = [ - { $match: { company: 'MongoDB' } }, - { $match: { company: { $eq: 'MongoDB' } } }, - { $match: { company: new bson.BSONRegExp('^MongoDB', '') } }, - { $match: { company: { $eq: new bson.BSONRegExp('^MongoDB', '') } } }, - ]; + // TODO: no schema found for eq.Regex Match Behaviour } diff --git a/packages/mql-typescript/tests/query/exists.spec.ts b/packages/mql-typescript/tests/query/exists.spec.ts index 8a2eeb0f..1d21b9ef 100644 --- a/packages/mql-typescript/tests/query/exists.spec.ts +++ b/packages/mql-typescript/tests/query/exists.spec.ts @@ -9,17 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/exists/#exists-and-not-equal-to} */ function test0() { - type inventory = { - price: bson.Double | number; - qty: bson.Int32 | number | undefined; - quantity: bson.Int32 | number | undefined; - sale: boolean; - tags: Array; - }; - - const aggregation: schema.Pipeline = [ - { $match: { qty: { $exists: true, $nin: [5, 15] } } }, - ]; + // TODO: no schema found for exists.Exists and Not Equal To } /** @@ -27,15 +17,12 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/exists/#null-values} */ function test1() { - type inventory = { - price: bson.Double | number; - qty: bson.Int32 | number | undefined; - quantity: bson.Int32 | number | undefined; - sale: boolean; - tags: Array; - }; + // TODO: no schema found for exists.Null Values +} - const aggregation: schema.Pipeline = [ - { $match: { qty: { $exists: true } } }, - ]; +/** + * Missing Field + */ +function test2() { + // TODO: no schema found for exists.Missing Field } diff --git a/packages/mql-typescript/tests/query/expr.spec.ts b/packages/mql-typescript/tests/query/expr.spec.ts index da3c9a40..ffaa4f85 100644 --- a/packages/mql-typescript/tests/query/expr.spec.ts +++ b/packages/mql-typescript/tests/query/expr.spec.ts @@ -9,46 +9,13 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/expr/#compare-two-fields-from-a-single-document} */ function test0() { - type monthlyBudget = { - _id: number; - category: string; - budget: number; - spent: number; - }; - - const aggregation: schema.Pipeline = [ - { $match: { $expr: { $gt: ['$spent', '$budget'] } } }, - ]; + // TODO: no schema found for expr.Compare Two Fields from A Single Document } /** * Using $expr With Conditional Statements - * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/expr/#use--expr-with-conditional-statements} + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/expr/#using--expr-with-conditional-statements} */ function test1() { - type supplies = { - _id: number; - item: string; - qty: bson.Int32 | number; - price: bson.Decimal128; - }; - - const aggregation: schema.Pipeline = [ - { - $match: { - $expr: { - $lt: [ - { - $cond: { - if: { $gte: ['$qty', 100] }, - then: { $multiply: ['$price', 0.5] }, - else: { $multiply: ['$price', 0.75] }, - }, - }, - 5, - ], - }, - }, - }, - ]; + // TODO: no schema found for expr.Using $expr With Conditional Statements } diff --git a/packages/mql-typescript/tests/query/geoIntersects.spec.ts b/packages/mql-typescript/tests/query/geoIntersects.spec.ts index b2c98a9c..d8be7197 100644 --- a/packages/mql-typescript/tests/query/geoIntersects.spec.ts +++ b/packages/mql-typescript/tests/query/geoIntersects.spec.ts @@ -9,34 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/geoIntersects/#intersects-a-polygon} */ function test0() { - type places = { - loc: { - type: string; - coordinates: Array>>; - }; - }; - - const aggregation: schema.Pipeline = [ - { - $match: { - loc: { - $geoIntersects: { - $geometry: { - type: 'Polygon', - coordinates: [ - [ - [0, 0], - [3, 6], - [6, 1], - [0, 0], - ], - ], - }, - }, - }, - }, - }, - ]; + // TODO: no schema found for geoIntersects.Intersects a Polygon } /** @@ -44,40 +17,5 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/geoIntersects/#intersects-a--big--polygon} */ function test1() { - type places = { - loc: { - type: string; - coordinates: Array>>; - }; - }; - - const aggregation: schema.Pipeline = [ - { - $match: { - loc: { - $geoIntersects: { - $geometry: { - type: 'Polygon', - coordinates: [ - [ - [-100, 60], - [-100, 0], - [-100, -60], - [100, -60], - [100, 60], - [-100, 60], - ], - ], - crs: { - type: 'name', - properties: { - name: 'urn:x-mongodb:crs:strictwinding:EPSG:4326', - }, - }, - }, - }, - }, - }, - }, - ]; + // TODO: no schema found for geoIntersects.Intersects a Big Polygon } diff --git a/packages/mql-typescript/tests/query/geoWithin.spec.ts b/packages/mql-typescript/tests/query/geoWithin.spec.ts index d7fc7bbc..bd8864b7 100644 --- a/packages/mql-typescript/tests/query/geoWithin.spec.ts +++ b/packages/mql-typescript/tests/query/geoWithin.spec.ts @@ -9,34 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/geoWithin/#within-a-polygon} */ function test0() { - type places = { - loc: { - type: string; - coordinates: Array>>; - }; - }; - - const aggregation: schema.Pipeline = [ - { - $match: { - loc: { - $geoWithin: { - $geometry: { - type: 'Polygon', - coordinates: [ - [ - [0, 0], - [3, 6], - [6, 1], - [0, 0], - ], - ], - }, - }, - }, - }, - }, - ]; + // TODO: no schema found for geoWithin.Within a Polygon } /** @@ -44,40 +17,5 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/geoWithin/#within-a--big--polygon} */ function test1() { - type places = { - loc: { - type: string; - coordinates: Array>>; - }; - }; - - const aggregation: schema.Pipeline = [ - { - $match: { - loc: { - $geoWithin: { - $geometry: { - type: 'Polygon', - coordinates: [ - [ - [-100, 60], - [-100, 0], - [-100, -60], - [100, -60], - [100, 60], - [-100, 60], - ], - ], - crs: { - type: 'name', - properties: { - name: 'urn:x-mongodb:crs:strictwinding:EPSG:4326', - }, - }, - }, - }, - }, - }, - }, - ]; + // TODO: no schema found for geoWithin.Within a Big Polygon } diff --git a/packages/mql-typescript/tests/query/gt.spec.ts b/packages/mql-typescript/tests/query/gt.spec.ts index 4b98bdea..8a7de81b 100644 --- a/packages/mql-typescript/tests/query/gt.spec.ts +++ b/packages/mql-typescript/tests/query/gt.spec.ts @@ -9,16 +9,5 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/gt/#match-document-fields} */ function test0() { - type inventory = { - item: string; - quantity: number; - carrier: { - name: string; - fee: number; - }; - }; - - const aggregation: schema.Pipeline = [ - { $match: { quantity: { $gt: 20 } } }, - ]; + // TODO: no schema found for gt.Match Document Fields } diff --git a/packages/mql-typescript/tests/query/gte.spec.ts b/packages/mql-typescript/tests/query/gte.spec.ts index 451d8586..c35a6c97 100644 --- a/packages/mql-typescript/tests/query/gte.spec.ts +++ b/packages/mql-typescript/tests/query/gte.spec.ts @@ -9,16 +9,5 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/gte/#match-document-fields} */ function test0() { - type inventory = { - item: string; - quantity: number; - carrier: { - name: string; - fee: number; - }; - }; - - const aggregation: schema.Pipeline = [ - { $match: { quantity: { $gte: 20 } } }, - ]; + // TODO: no schema found for gte.Match Document Fields } diff --git a/packages/mql-typescript/tests/query/in.spec.ts b/packages/mql-typescript/tests/query/in.spec.ts index 159ca727..1cdf5417 100644 --- a/packages/mql-typescript/tests/query/in.spec.ts +++ b/packages/mql-typescript/tests/query/in.spec.ts @@ -9,15 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/in/#use-the--in-operator-to-match-values} */ function test0() { - type inventory = { - item: string; - quantity: number; - tags: Array; - }; - - const aggregation: schema.Pipeline = [ - { $match: { tags: { $in: ['home', 'school'] } } }, - ]; + // TODO: no schema found for in.Use the $in Operator to Match Values in an Array } /** @@ -25,19 +17,5 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/in/#use-the--in-operator-with-a-regular-expression} */ function test1() { - type inventory = { - item: string; - quantity: number; - tags: Array; - }; - - const aggregation: schema.Pipeline = [ - { - $match: { - tags: { - $in: [new bson.BSONRegExp('^be', ''), new bson.BSONRegExp('^st', '')], - }, - }, - }, - ]; + // TODO: no schema found for in.Use the $in Operator with a Regular Expression } diff --git a/packages/mql-typescript/tests/query/jsonSchema.spec.ts b/packages/mql-typescript/tests/query/jsonSchema.spec.ts index 40c0f99b..89c37b89 100644 --- a/packages/mql-typescript/tests/query/jsonSchema.spec.ts +++ b/packages/mql-typescript/tests/query/jsonSchema.spec.ts @@ -9,37 +9,5 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/jsonSchema/#syntax} */ function test0() { - type TestCollection = { - name: string; - major: string; - gpa: bson.Double | number; - address: { - street: string; - zipcode: string; - }; - }; - - const aggregation: schema.Pipeline = [ - { - $match: { - $jsonSchema: { - required: ['name', 'major', 'gpa', 'address'], - properties: { - name: { - bsonType: 'string', - description: 'must be a string and is required', - }, - address: { - bsonType: 'object', - required: ['zipcode'], - properties: { - street: { bsonType: 'string' }, - zipcode: { bsonType: 'string' }, - }, - }, - }, - }, - }, - }, - ]; + // TODO: no schema found for jsonSchema.Example } diff --git a/packages/mql-typescript/tests/query/lt.spec.ts b/packages/mql-typescript/tests/query/lt.spec.ts index 64635dd6..d460dc48 100644 --- a/packages/mql-typescript/tests/query/lt.spec.ts +++ b/packages/mql-typescript/tests/query/lt.spec.ts @@ -9,16 +9,5 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/lt/#match-document-fields} */ function test0() { - type inventory = { - item: string; - quantity: number; - carrier: { - name: string; - fee: number; - }; - }; - - const aggregation: schema.Pipeline = [ - { $match: { quantity: { $lt: 20 } } }, - ]; + // TODO: no schema found for lt.Match Document Fields } diff --git a/packages/mql-typescript/tests/query/lte.spec.ts b/packages/mql-typescript/tests/query/lte.spec.ts index 9756f5dd..096d0d2f 100644 --- a/packages/mql-typescript/tests/query/lte.spec.ts +++ b/packages/mql-typescript/tests/query/lte.spec.ts @@ -9,16 +9,5 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/lte/#match-document-fields} */ function test0() { - type inventory = { - item: string; - quantity: number; - carrier: { - name: string; - fee: number; - }; - }; - - const aggregation: schema.Pipeline = [ - { $match: { quantity: { $lte: 20 } } }, - ]; + // TODO: no schema found for lte.Match Document Fields } diff --git a/packages/mql-typescript/tests/query/mod.spec.ts b/packages/mql-typescript/tests/query/mod.spec.ts index 3a56f90b..82dbde1c 100644 --- a/packages/mql-typescript/tests/query/mod.spec.ts +++ b/packages/mql-typescript/tests/query/mod.spec.ts @@ -9,15 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/mod/#use--mod-to-select-documents} */ function test0() { - type inventory = { - _id: number; - item: string; - qty: number; - }; - - const aggregation: schema.Pipeline = [ - { $match: { qty: { $mod: [4, 0] } } }, - ]; + // TODO: no schema found for mod.Use $mod to Select Documents } /** @@ -25,15 +17,5 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/mod/#floating-point-arguments} */ function test1() { - type inventory = { - _id: number; - item: string; - qty: number; - }; - - const aggregation: schema.Pipeline = [ - { $match: { qty: { $mod: [4, 0] } } }, - { $match: { qty: { $mod: [4.5, 0] } } }, - { $match: { qty: { $mod: [4.99, 0] } } }, - ]; + // TODO: no schema found for mod.Floating Point Arguments } diff --git a/packages/mql-typescript/tests/query/ne.spec.ts b/packages/mql-typescript/tests/query/ne.spec.ts index c58c2f25..06577311 100644 --- a/packages/mql-typescript/tests/query/ne.spec.ts +++ b/packages/mql-typescript/tests/query/ne.spec.ts @@ -6,19 +6,8 @@ import * as bson from 'bson'; /** * Match Document Fields - * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/ne/#match-document-fields-that-are-not-equal} + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/ne/#match-document-fields} */ function test0() { - type inventory = { - item: string; - quantity: number; - carrier: { - name: string; - fee: number; - }; - }; - - const aggregation: schema.Pipeline = [ - { $match: { quantity: { $ne: 20 } } }, - ]; + // TODO: no schema found for ne.Match Document Fields } diff --git a/packages/mql-typescript/tests/query/near.spec.ts b/packages/mql-typescript/tests/query/near.spec.ts index 4b76e949..47fd8537 100644 --- a/packages/mql-typescript/tests/query/near.spec.ts +++ b/packages/mql-typescript/tests/query/near.spec.ts @@ -9,24 +9,5 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/near/#query-on-geojson-data} */ function test0() { - type places = { - location: { - type: string; - coordinates: Array; - }; - }; - - const aggregation: schema.Pipeline = [ - { - $match: { - location: { - $near: { - $geometry: { type: 'Point', coordinates: [-73.9667, 40.78] }, - $minDistance: 1000, - $maxDistance: 5000, - }, - }, - }, - }, - ]; + // TODO: no schema found for near.Query on GeoJSON Data } diff --git a/packages/mql-typescript/tests/query/nearSphere.spec.ts b/packages/mql-typescript/tests/query/nearSphere.spec.ts index 3c9e0804..3feffba7 100644 --- a/packages/mql-typescript/tests/query/nearSphere.spec.ts +++ b/packages/mql-typescript/tests/query/nearSphere.spec.ts @@ -9,24 +9,5 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/nearSphere/#specify-center-point-using-geojson} */ function test0() { - type places = { - location: { - type: string; - coordinates: Array; - }; - }; - - const aggregation: schema.Pipeline = [ - { - $match: { - location: { - $nearSphere: { - $geometry: { type: 'Point', coordinates: [-73.9667, 40.78] }, - $minDistance: 1000, - $maxDistance: 5000, - }, - }, - }, - }, - ]; + // TODO: no schema found for nearSphere.Specify Center Point Using GeoJSON } diff --git a/packages/mql-typescript/tests/query/nin.spec.ts b/packages/mql-typescript/tests/query/nin.spec.ts index 346da259..ce445116 100644 --- a/packages/mql-typescript/tests/query/nin.spec.ts +++ b/packages/mql-typescript/tests/query/nin.spec.ts @@ -9,15 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/nin/#select-on-unmatching-documents} */ function test0() { - type inventory = { - item: string; - quantity: number; - tags: Array; - }; - - const aggregation: schema.Pipeline = [ - { $match: { quantity: { $nin: [5, 15] } } }, - ]; + // TODO: no schema found for nin.Select on Unmatching Documents } /** @@ -25,13 +17,5 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/nin/#select-on-elements-not-in-an-array} */ function test1() { - type inventory = { - item: string; - quantity: number; - tags: Array; - }; - - const aggregation: schema.Pipeline = [ - { $match: { tags: { $nin: ['school'] } } }, - ]; + // TODO: no schema found for nin.Select on Elements Not in an Array } diff --git a/packages/mql-typescript/tests/query/nor.spec.ts b/packages/mql-typescript/tests/query/nor.spec.ts index 312c772d..472ca28e 100644 --- a/packages/mql-typescript/tests/query/nor.spec.ts +++ b/packages/mql-typescript/tests/query/nor.spec.ts @@ -9,17 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/nor/#-nor-query-with-two-expressions} */ function test0() { - type inventory = { - price: bson.Double | number; - qty: bson.Int32 | number | undefined; - quantity: bson.Int32 | number | undefined; - sale: boolean; - tags: Array; - }; - - const aggregation: schema.Pipeline = [ - { $match: { $nor: [{ price: 1.99 }, { sale: true }] } }, - ]; + // TODO: no schema found for nor.Query with Two Expressions } /** @@ -27,19 +17,7 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/nor/#-nor-and-additional-comparisons} */ function test1() { - type inventory = { - price: bson.Double | number; - qty: bson.Int32 | number | undefined; - quantity: bson.Int32 | number | undefined; - sale: boolean; - tags: Array; - }; - - const aggregation: schema.Pipeline = [ - { - $match: { $nor: [{ price: 1.99 }, { qty: { $lt: 20 } }, { sale: true }] }, - }, - ]; + // TODO: no schema found for nor.Additional Comparisons } /** @@ -47,24 +25,5 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/nor/#-nor-and--exists} */ function test2() { - type inventory = { - price: bson.Double | number; - qty: bson.Int32 | number | undefined; - quantity: bson.Int32 | number | undefined; - sale: boolean; - tags: Array; - }; - - const aggregation: schema.Pipeline = [ - { - $match: { - $nor: [ - { price: 1.99 }, - { price: { $exists: false } }, - { sale: true }, - { sale: { $exists: false } }, - ], - }, - }, - ]; + // TODO: no schema found for nor.$nor and $exists } diff --git a/packages/mql-typescript/tests/query/not.spec.ts b/packages/mql-typescript/tests/query/not.spec.ts index d27cf7be..aca76b82 100644 --- a/packages/mql-typescript/tests/query/not.spec.ts +++ b/packages/mql-typescript/tests/query/not.spec.ts @@ -9,33 +9,13 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/not/#syntax} */ function test0() { - type inventory = { - price: bson.Double | number; - qty: bson.Int32 | number | undefined; - quantity: bson.Int32 | number | undefined; - sale: boolean; - tags: Array; - }; - - const aggregation: schema.Pipeline = [ - { $match: { price: { $not: { $gt: 1.99 } } } }, - ]; + // TODO: no schema found for not.Syntax } /** * Regular Expressions - * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/not/#regular-expressions} + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/not/#-not-and-regular-expressions} */ function test1() { - type inventory = { - price: bson.Double | number; - qty: bson.Int32 | number | undefined; - quantity: bson.Int32 | number | undefined; - sale: boolean; - tags: Array; - }; - - const aggregation: schema.Pipeline = [ - { $match: { price: { $not: new bson.BSONRegExp('^p.*', '') } } }, - ]; + // TODO: no schema found for not.Regular Expressions } diff --git a/packages/mql-typescript/tests/query/or.spec.ts b/packages/mql-typescript/tests/query/or.spec.ts index 598e19c3..ca909994 100644 --- a/packages/mql-typescript/tests/query/or.spec.ts +++ b/packages/mql-typescript/tests/query/or.spec.ts @@ -9,17 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/or/#-or-clauses-and-indexes} */ function test0() { - type inventory = { - price: bson.Double | number; - qty: bson.Int32 | number | undefined; - quantity: bson.Int32 | number | undefined; - sale: boolean; - tags: Array; - }; - - const aggregation: schema.Pipeline = [ - { $match: { $or: [{ quantity: { $lt: 20 } }, { price: 10 }] } }, - ]; + // TODO: no schema found for or.$or Clauses } /** @@ -27,18 +17,5 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/or/#error-handling} */ function test1() { - type example = { - x: bson.Int32 | number; - }; - - const aggregation: schema.Pipeline = [ - { - $match: { - $or: [ - { x: { $eq: 0 } }, - { $expr: { $eq: [{ $divide: [1, '$x'] }, 3] } }, - ], - }, - }, - ]; + // TODO: no schema found for or.Error Handling } diff --git a/packages/mql-typescript/tests/query/rand.spec.ts b/packages/mql-typescript/tests/query/rand.spec.ts index 72b590fe..0698736e 100644 --- a/packages/mql-typescript/tests/query/rand.spec.ts +++ b/packages/mql-typescript/tests/query/rand.spec.ts @@ -9,15 +9,5 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/rand/#select-random-items-from-a-collection} */ function test0() { - type voters = { - name: string; - voterId: number; - district: number; - registered: boolean; - }; - - const aggregation: schema.Pipeline = [ - { $match: { district: 3, $expr: { $lt: [0.5, { $rand: {} }] } } }, - { $project: { _id: 0, name: 1, registered: 1 } }, - ]; + // TODO: no schema found for rand.Select Random Items From a Collection } diff --git a/packages/mql-typescript/tests/query/regex.spec.ts b/packages/mql-typescript/tests/query/regex.spec.ts index aa0f1fcf..7c1265d6 100644 --- a/packages/mql-typescript/tests/query/regex.spec.ts +++ b/packages/mql-typescript/tests/query/regex.spec.ts @@ -9,15 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/regex/#perform-a-like-match} */ function test0() { - type products = { - _id: number; - sku: string; - description: string; - }; - - const aggregation: schema.Pipeline = [ - { $match: { sku: { $regex: new bson.BSONRegExp('789$', '') } } }, - ]; + // TODO: no schema found for regex.Perform a LIKE Match } /** @@ -25,13 +17,5 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/regex/#perform-case-insensitive-regular-expression-match} */ function test1() { - type products = { - _id: number; - sku: string; - description: string; - }; - - const aggregation: schema.Pipeline = [ - { $match: { sku: { $regex: new bson.BSONRegExp('^ABC', 'i') } } }, - ]; + // TODO: no schema found for regex.Perform Case-Insensitive Regular Expression Match } diff --git a/packages/mql-typescript/tests/query/sampleRate.spec.ts b/packages/mql-typescript/tests/query/sampleRate.spec.ts index 86ad9950..b6ed203b 100644 --- a/packages/mql-typescript/tests/query/sampleRate.spec.ts +++ b/packages/mql-typescript/tests/query/sampleRate.spec.ts @@ -9,12 +9,5 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/sampleRate/#examples} */ function test0() { - type TestCollection = { - _id: bson.ObjectId; - }; - - const aggregation: schema.Pipeline = [ - { $match: { $sampleRate: 0.33 } }, - { $count: 'numMatches' }, - ]; + // TODO: no schema found for sampleRate.Example } diff --git a/packages/mql-typescript/tests/query/size.spec.ts b/packages/mql-typescript/tests/query/size.spec.ts index f8670203..6959c4ec 100644 --- a/packages/mql-typescript/tests/query/size.spec.ts +++ b/packages/mql-typescript/tests/query/size.spec.ts @@ -9,15 +9,5 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/tutorial/query-arrays/#query-an-array-by-array-length} */ function test0() { - type inventory = { - price: bson.Double | number; - qty: bson.Int32 | number | undefined; - quantity: bson.Int32 | number | undefined; - sale: boolean; - tags: Array; - }; - - const aggregation: schema.Pipeline = [ - { $match: { tags: { $size: 3 } } }, - ]; + // TODO: no schema found for size.Query an Array by Array Length } diff --git a/packages/mql-typescript/tests/query/text.spec.ts b/packages/mql-typescript/tests/query/text.spec.ts index 88f612c0..6ba3ae50 100644 --- a/packages/mql-typescript/tests/query/text.spec.ts +++ b/packages/mql-typescript/tests/query/text.spec.ts @@ -6,110 +6,56 @@ import * as bson from 'bson'; /** * Search for a Single Word - * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/text/#-text-with-a-single-word} + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/text/#search-for-a-single-word} */ function test0() { - type articles = { - _id: number; - subject: string; - author: string; - views: number; - }; - - const aggregation: schema.Pipeline = [ - { $match: { $text: { $search: 'coffee' } } }, - ]; + // TODO: no schema found for text.Search for a Single Word } /** - * Query a Different Language - * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/text/#query-a-different-language} + * Match Any of the Search Terms + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/text/#search-for-a-single-word} */ function test1() { - type articles = { - _id: number; - subject: string; - author: string; - views: number; - }; - - const aggregation: schema.Pipeline = [ - { $match: { $text: { $search: 'leche', $language: 'es' } } }, - ]; + // TODO: no schema found for text.Match Any of the Search Terms } /** - * Case and Diacritic Insensitive Search - * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/text/#case-and-diacritic-insensitivity} + * Search a Different Language + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/text/#search-a-different-language} */ function test2() { - type articles = { - _id: number; - subject: string; - author: string; - views: number; - }; - - const aggregation: schema.Pipeline = [ - { $match: { $text: { $search: 'сы́рники CAFÉS' } } }, - ]; + // TODO: no schema found for text.Search a Different Language } /** - * Perform Case Sensitive Search - * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/text/#case-sensitivity} + * Case and Diacritic Insensitive Search + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/text/#case-and-diacritic-insensitive-search} */ function test3() { - type articles = { - _id: number; - subject: string; - author: string; - views: number; - }; - - const aggregation: schema.Pipeline = [ - { $match: { $text: { $search: 'Coffee', $caseSensitive: true } } }, - { - $match: { - $text: { $search: '\\"Café Con Leche\\"', $caseSensitive: true }, - }, - }, - ]; + // TODO: no schema found for text.Case and Diacritic Insensitive Search } /** - * Diacritic Sensitive Search - * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/text/#diacritic-sensitivity} + * Perform Case Sensitive Search + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/text/#perform-case-sensitive-search} */ function test4() { - type articles = { - _id: number; - subject: string; - author: string; - views: number; - }; - - const aggregation: schema.Pipeline = [ - { $match: { $text: { $search: 'CAFÉ', $diacriticSensitive: true } } }, - ]; + // TODO: no schema found for text.Perform Case Sensitive Search } /** - * Text Search Score Examples - * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/text/#relevance-score-examples} + * Diacritic Sensitive Search + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/text/#perform-case-sensitive-search} */ function test5() { - type articles = { - _id: number; - subject: string; - author: string; - views: number; - }; + // TODO: no schema found for text.Diacritic Sensitive Search +} - const aggregation: schema.Pipeline = [ - { $match: { $text: { $search: 'CAFÉ', $diacriticSensitive: true } } }, - { $project: { score: { $meta: 'textScore' } } }, - { $sort: { score: { $meta: 'textScore' } } }, - { $limit: 5 }, - ]; +/** + * Text Search Score Examples + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/text/#perform-case-sensitive-search} + */ +function test6() { + // TODO: no schema found for text.Text Search Score Examples } diff --git a/packages/mql-typescript/tests/query/type.spec.ts b/packages/mql-typescript/tests/query/type.spec.ts index be8ce6ec..1049ce04 100644 --- a/packages/mql-typescript/tests/query/type.spec.ts +++ b/packages/mql-typescript/tests/query/type.spec.ts @@ -9,36 +9,15 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/type/#querying-by-data-type} */ function test0() { - type addressBook = { - _id: number; - address: string; - zipCode: string | number | bson.Long | bson.Int32 | number | Array; - }; - - const aggregation: schema.Pipeline = [ - { $match: { zipCode: { $type: [2] } } }, - { $match: { zipCode: { $type: ['string'] } } }, - { $match: { zipCode: { $type: [1] } } }, - { $match: { zipCode: { $type: ['double'] } } }, - { $match: { zipCode: { $type: ['number'] } } }, - ]; + // TODO: no schema found for type.Querying by Data Type } /** * Querying by Multiple Data Type - * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/type/#querying-by-multiple-data-types} + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/type/#querying-by-multiple-data-type} */ function test1() { - type grades = { - _id: number; - name: string; - classAverage: string | number | bson.Int32 | number; - }; - - const aggregation: schema.Pipeline = [ - { $match: { classAverage: { $type: [2, 1] } } }, - { $match: { classAverage: { $type: ['string', 'double'] } } }, - ]; + // TODO: no schema found for type.Querying by Multiple Data Type } /** @@ -46,36 +25,7 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/type/#querying-by-minkey-and-maxkey} */ function test2() { - type restaurants = { - _id: number; - address: { - building: string; - coord: Array; - street: string; - zipcode: string; - }; - borough: string; - cuisine: string; - grades: Array<{ - date: Date; - grade: string | bson.MinKey; - score: number; - }>; - name: string; - restaurant_id: string; - }; - - const aggregation: schema.Pipeline = [ - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). - */ - { $match: { zipCode: { $type: ['minKey'] } } } as any, - - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). - */ - { $match: { zipCode: { $type: ['maxKey'] } } } as any, - ]; + // TODO: no schema found for type.Querying by MinKey and MaxKey } /** @@ -83,12 +33,5 @@ function test2() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/type/#querying-by-array-type} */ function test3() { - type sensorReading = { - _id: number; - readings: Array> | number; - }; - - const aggregation: schema.Pipeline = [ - { $match: { readings: { $type: ['array'] } } }, - ]; + // TODO: no schema found for type.Querying by Array Type } diff --git a/packages/mql-typescript/tests/query/where.spec.ts b/packages/mql-typescript/tests/query/where.spec.ts index e4b7bcd2..662dc3b8 100644 --- a/packages/mql-typescript/tests/query/where.spec.ts +++ b/packages/mql-typescript/tests/query/where.spec.ts @@ -9,30 +9,5 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/where/#example} */ function test0() { - type players = { - _id: number; - name: string; - username: string; - first_login: string; - }; - - const aggregation: schema.Pipeline = [ - { - $match: { - $where: - 'function() { return hex_md5(this.name) == "9b53e667f30cd329dca1ec9e6a83e994"}', - }, - }, - { - $match: { - $expr: { - $function: { - body: 'function(name) { return hex_md5(name) == "9b53e667f30cd329dca1ec9e6a83e994";}', - args: ['$name'], - lang: 'js', - }, - }, - }, - }, - ]; + // TODO: no schema found for where.Example } diff --git a/packages/mql-typescript/tests/search/autocomplete.spec.ts b/packages/mql-typescript/tests/search/autocomplete.spec.ts index 994da04c..d9a38516 100644 --- a/packages/mql-typescript/tests/search/autocomplete.spec.ts +++ b/packages/mql-typescript/tests/search/autocomplete.spec.ts @@ -9,67 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/#basic-example} */ function test0() { - type movies = { - _id: { - $oid: string; - }; - title: string; - year: { - $numberInt: string; - }; - runtime: { - $numberInt: string; - }; - released: { - $date: { - $numberLong: string; - }; - }; - poster: string; - plot: string; - fullplot: string; - lastupdated: string; - type: string; - directors: Array; - imdb: { - rating: { - $numberDouble: string; - }; - votes: { - $numberInt: string; - }; - id: { - $numberInt: string; - }; - }; - cast: Array; - countries: Array; - genres: Array; - tomatoes: { - viewer: { - rating: { - $numberDouble: string; - }; - numReviews: { - $numberInt: string; - }; - }; - lastUpdated: { - $date: { - $numberLong: string; - }; - }; - }; - num_mflix_comments: { - $numberInt: string; - }; - }; - - const aggregation: schema.Pipeline = [ - { $search: { autocomplete: { query: 'off', path: 'title' } } }, - { $limit: 10 }, - { $project: { _id: 0, title: 1 } }, - ]; + // TODO: no schema found for autocomplete.Basic } /** @@ -77,75 +17,7 @@ function test0() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/#fuzzy-example} */ function test1() { - type movies = { - _id: { - $oid: string; - }; - title: string; - year: { - $numberInt: string; - }; - runtime: { - $numberInt: string; - }; - released: { - $date: { - $numberLong: string; - }; - }; - poster: string; - plot: string; - fullplot: string; - lastupdated: string; - type: string; - directors: Array; - imdb: { - rating: { - $numberDouble: string; - }; - votes: { - $numberInt: string; - }; - id: { - $numberInt: string; - }; - }; - cast: Array; - countries: Array; - genres: Array; - tomatoes: { - viewer: { - rating: { - $numberDouble: string; - }; - numReviews: { - $numberInt: string; - }; - }; - lastUpdated: { - $date: { - $numberLong: string; - }; - }; - }; - num_mflix_comments: { - $numberInt: string; - }; - }; - - const aggregation: schema.Pipeline = [ - { - $search: { - autocomplete: { - query: 'pre', - path: 'title', - fuzzy: { maxEdits: 1, prefixLength: 1, maxExpansions: 256 }, - }, - }, - }, - { $limit: 10 }, - { $project: { _id: 0, title: 1 } }, - ]; + // TODO: no schema found for autocomplete.Fuzzy } /** @@ -153,71 +25,7 @@ function test1() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/#simple-any-example} */ function test2() { - type movies = { - _id: { - $oid: string; - }; - title: string; - year: { - $numberInt: string; - }; - runtime: { - $numberInt: string; - }; - released: { - $date: { - $numberLong: string; - }; - }; - poster: string; - plot: string; - fullplot: string; - lastupdated: string; - type: string; - directors: Array; - imdb: { - rating: { - $numberDouble: string; - }; - votes: { - $numberInt: string; - }; - id: { - $numberInt: string; - }; - }; - cast: Array; - countries: Array; - genres: Array; - tomatoes: { - viewer: { - rating: { - $numberDouble: string; - }; - numReviews: { - $numberInt: string; - }; - }; - lastUpdated: { - $date: { - $numberLong: string; - }; - }; - }; - num_mflix_comments: { - $numberInt: string; - }; - }; - - const aggregation: schema.Pipeline = [ - { - $search: { - autocomplete: { query: 'men with', path: 'title', tokenOrder: 'any' }, - }, - }, - { $limit: 4 }, - { $project: { _id: 0, title: 1 } }, - ]; + // TODO: no schema found for autocomplete.Token Order any } /** @@ -225,75 +33,7 @@ function test2() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/#simple-sequential-example} */ function test3() { - type movies = { - _id: { - $oid: string; - }; - title: string; - year: { - $numberInt: string; - }; - runtime: { - $numberInt: string; - }; - released: { - $date: { - $numberLong: string; - }; - }; - poster: string; - plot: string; - fullplot: string; - lastupdated: string; - type: string; - directors: Array; - imdb: { - rating: { - $numberDouble: string; - }; - votes: { - $numberInt: string; - }; - id: { - $numberInt: string; - }; - }; - cast: Array; - countries: Array; - genres: Array; - tomatoes: { - viewer: { - rating: { - $numberDouble: string; - }; - numReviews: { - $numberInt: string; - }; - }; - lastUpdated: { - $date: { - $numberLong: string; - }; - }; - }; - num_mflix_comments: { - $numberInt: string; - }; - }; - - const aggregation: schema.Pipeline = [ - { - $search: { - autocomplete: { - query: 'men with', - path: 'title', - tokenOrder: 'sequential', - }, - }, - }, - { $limit: 4 }, - { $project: { _id: 0, title: 1 } }, - ]; + // TODO: no schema found for autocomplete.Token Order sequential } /** @@ -301,79 +41,7 @@ function test3() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/#highlighting-example} */ function test4() { - type movies = { - _id: { - $oid: string; - }; - title: string; - year: { - $numberInt: string; - }; - runtime: { - $numberInt: string; - }; - released: { - $date: { - $numberLong: string; - }; - }; - poster: string; - plot: string; - fullplot: string; - lastupdated: string; - type: string; - directors: Array; - imdb: { - rating: { - $numberDouble: string; - }; - votes: { - $numberInt: string; - }; - id: { - $numberInt: string; - }; - }; - cast: Array; - countries: Array; - genres: Array; - tomatoes: { - viewer: { - rating: { - $numberDouble: string; - }; - numReviews: { - $numberInt: string; - }; - }; - lastUpdated: { - $date: { - $numberLong: string; - }; - }; - }; - num_mflix_comments: { - $numberInt: string; - }; - }; - - const aggregation: schema.Pipeline = [ - { - $search: { - autocomplete: { query: 'ger', path: 'title' }, - highlight: { path: 'title' }, - }, - }, - { $limit: 5 }, - { - $project: { - score: { $meta: 'searchScore' }, - _id: 0, - title: 1, - highlights: { $meta: 'searchHighlights' }, - }, - }, - ]; + // TODO: no schema found for autocomplete.Highlighting } /** @@ -381,75 +49,5 @@ function test4() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/#search-across-multiple-fields} */ function test5() { - type movies = { - _id: { - $oid: string; - }; - title: string; - year: { - $numberInt: string; - }; - runtime: { - $numberInt: string; - }; - released: { - $date: { - $numberLong: string; - }; - }; - poster: string; - plot: string; - fullplot: string; - lastupdated: string; - type: string; - directors: Array; - imdb: { - rating: { - $numberDouble: string; - }; - votes: { - $numberInt: string; - }; - id: { - $numberInt: string; - }; - }; - cast: Array; - countries: Array; - genres: Array; - tomatoes: { - viewer: { - rating: { - $numberDouble: string; - }; - numReviews: { - $numberInt: string; - }; - }; - lastUpdated: { - $date: { - $numberLong: string; - }; - }; - }; - num_mflix_comments: { - $numberInt: string; - }; - }; - - const aggregation: schema.Pipeline = [ - { - $search: { - compound: { - should: [ - { autocomplete: { query: 'inter', path: 'title' } }, - { autocomplete: { query: 'inter', path: 'plot' } }, - ], - minimumShouldMatch: 1, - }, - }, - }, - { $limit: 10 }, - { $project: { _id: 0, title: 1, plot: 1 } }, - ]; + // TODO: no schema found for autocomplete.Across Multiple Fields } diff --git a/packages/mql-typescript/tests/search/compound.spec.ts b/packages/mql-typescript/tests/search/compound.spec.ts index 0078aaf3..bc81fc20 100644 --- a/packages/mql-typescript/tests/search/compound.spec.ts +++ b/packages/mql-typescript/tests/search/compound.spec.ts @@ -9,24 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/compound/#must-and-mustnot-example} */ function test0() { - type TestCollection = { - _id: number; - type: string; - description: string; - category: string; - in_stock: boolean; - }; - - const aggregation: schema.Pipeline = [ - { - $search: { - compound: { - must: [{ text: { query: 'varieties', path: 'description' } }], - mustNot: [{ text: { query: 'apples', path: 'description' } }], - }, - }, - }, - ]; + // TODO: no schema found for compound.must and mustNot } /** @@ -34,25 +17,7 @@ function test0() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/compound/#must-and-should-example} */ function test1() { - type TestCollection = { - _id: number; - type: string; - description: string; - category: string; - in_stock: boolean; - }; - - const aggregation: schema.Pipeline = [ - { - $search: { - compound: { - must: [{ text: { query: 'varieties', path: 'description' } }], - should: [{ text: { query: 'Fuji', path: 'description' } }], - }, - }, - }, - { $project: { score: { $meta: 'searchScore' } } }, - ]; + // TODO: no schema found for compound.must and should } /** @@ -60,28 +25,7 @@ function test1() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/compound/#minimumshouldmatch-example} */ function test2() { - type TestCollection = { - _id: number; - type: string; - description: string; - category: string; - in_stock: boolean; - }; - - const aggregation: schema.Pipeline = [ - { - $search: { - compound: { - must: [{ text: { query: 'varieties', path: 'description' } }], - should: [ - { text: { query: 'Fuji', path: 'description' } }, - { text: { query: 'Golden Delicious', path: 'description' } }, - ], - minimumShouldMatch: 1, - }, - }, - }, - ]; + // TODO: no schema found for compound.minimumShouldMatch } /** @@ -89,25 +33,7 @@ function test2() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/compound/#filter-examples} */ function test3() { - type TestCollection = { - _id: number; - type: string; - description: string; - category: string; - in_stock: boolean; - }; - - const aggregation: schema.Pipeline = [ - { - $search: { - compound: { - must: [{ text: { query: 'varieties', path: 'description' } }], - should: [{ text: { query: 'banana', path: 'description' } }], - filter: [{ text: { query: 'granny', path: 'description' } }], - }, - }, - }, - ]; + // TODO: no schema found for compound.Filter } /** @@ -115,32 +41,5 @@ function test3() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/compound/#nested-example} */ function test4() { - type TestCollection = { - _id: number; - type: string; - description: string; - category: string; - in_stock: boolean; - }; - - const aggregation: schema.Pipeline = [ - { - $search: { - compound: { - should: [ - { text: { query: 'apple', path: 'type' } }, - { - compound: { - must: [ - { text: { query: 'organic', path: 'category' } }, - { equals: { value: true, path: 'in_stock' } }, - ], - }, - }, - ], - minimumShouldMatch: 1, - }, - }, - }, - ]; + // TODO: no schema found for compound.Nested } diff --git a/packages/mql-typescript/tests/search/embeddedDocument.spec.ts b/packages/mql-typescript/tests/search/embeddedDocument.spec.ts index a7bd6679..fd4b7e6b 100644 --- a/packages/mql-typescript/tests/search/embeddedDocument.spec.ts +++ b/packages/mql-typescript/tests/search/embeddedDocument.spec.ts @@ -9,76 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/embedded-document/#index-definition} */ function test0() { - type sales = { - _id: { - $oid: string; - }; - saleDate: { - $date: { - $numberLong: string; - }; - }; - items: Array<{ - name: string; - tags: Array; - price: { - $numberDecimal: string; - }; - quantity: { - $numberInt: string; - }; - }>; - storeLocation: string; - customer: { - gender: string; - age: { - $numberInt: string; - }; - email: string; - satisfaction: { - $numberInt: string; - }; - }; - couponUsed: boolean; - purchaseMethod: string; - }; - - const aggregation: schema.Pipeline = [ - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). - */ - { - $search: { - embeddedDocument: { - path: 'items', - operator: { - compound: { - must: [{ text: { path: 'items.tags', query: 'school' } }], - should: [{ text: { path: 'items.name', query: 'backpack' } }], - }, - }, - score: { embedded: { aggregate: 'mean' } }, - }, - }, - } as any, - - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). - */ - { $limit: 5 } as any, - - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). - */ - { - $project: { - _id: 0, - 'items.name': 1, - 'items.tags': 1, - score: { $meta: 'searchScore' }, - }, - } as any, - ]; + // TODO: no schema found for embeddedDocument.Basic } /** @@ -86,65 +17,7 @@ function test0() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/embedded-document/#facet-query} */ function test1() { - type sales = { - _id: { - $oid: string; - }; - saleDate: { - $date: { - $numberLong: string; - }; - }; - items: Array<{ - name: string; - tags: Array; - price: { - $numberDecimal: string; - }; - quantity: { - $numberInt: string; - }; - }>; - storeLocation: string; - customer: { - gender: string; - age: { - $numberInt: string; - }; - email: string; - satisfaction: { - $numberInt: string; - }; - }; - couponUsed: boolean; - purchaseMethod: string; - }; - - const aggregation: schema.Pipeline = [ - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). - */ - { - $searchMeta: { - facet: { - operator: { - embeddedDocument: { - path: 'items', - operator: { - compound: { - must: [{ text: { path: 'items.tags', query: 'school' } }], - should: [{ text: { path: 'items.name', query: 'backpack' } }], - }, - }, - }, - }, - facets: { - purchaseMethodFacet: { type: 'string', path: 'purchaseMethod' }, - }, - }, - }, - } as any, - ]; + // TODO: no schema found for embeddedDocument.Facet } /** @@ -152,71 +25,7 @@ function test1() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/embedded-document/#query-and-sort} */ function test2() { - type sales = { - _id: { - $oid: string; - }; - saleDate: { - $date: { - $numberLong: string; - }; - }; - items: Array<{ - name: string; - tags: Array; - price: { - $numberDecimal: string; - }; - quantity: { - $numberInt: string; - }; - }>; - storeLocation: string; - customer: { - gender: string; - age: { - $numberInt: string; - }; - email: string; - satisfaction: { - $numberInt: string; - }; - }; - couponUsed: boolean; - purchaseMethod: string; - }; - - const aggregation: schema.Pipeline = [ - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). - */ - { - $search: { - embeddedDocument: { - path: 'items', - operator: { text: { path: 'items.name', query: 'laptop' } }, - }, - sort: { 'items.tags': 1 }, - }, - } as any, - - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). - */ - { $limit: 5 } as any, - - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). - */ - { - $project: { - _id: 0, - 'items.name': 1, - 'items.tags': 1, - score: { $meta: 'searchScore' }, - }, - } as any, - ]; + // TODO: no schema found for embeddedDocument.Query and Sort } /** @@ -224,79 +33,5 @@ function test2() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/embedded-document/#query-for-matching-embedded-documents-only} */ function test3() { - type sales = { - _id: { - $oid: string; - }; - saleDate: { - $date: { - $numberLong: string; - }; - }; - items: Array<{ - name: string; - tags: Array; - price: { - $numberDecimal: string; - }; - quantity: { - $numberInt: string; - }; - }>; - storeLocation: string; - customer: { - gender: string; - age: { - $numberInt: string; - }; - email: string; - satisfaction: { - $numberInt: string; - }; - }; - couponUsed: boolean; - purchaseMethod: string; - }; - - const aggregation: schema.Pipeline = [ - { - $search: { - embeddedDocument: { - path: 'items', - operator: { - compound: { - must: [ - { range: { path: 'items.quantity', gt: 2 } }, - { exists: { path: 'items.price' } }, - { text: { path: 'items.tags', query: 'school' } }, - ], - }, - }, - }, - }, - }, - { $limit: 2 }, - - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). - */ - { - $project: { - _id: 0, - storeLocation: 1, - items: { - $filter: { - input: '$items', - cond: { - $and: [ - { $ifNull: ['$$this.price', 'false'] }, - { $gt: ['$$this.quantity', 2] }, - { $in: ['office', '$$this.tags'] }, - ], - }, - }, - }, - }, - } as any, - ]; + // TODO: no schema found for embeddedDocument.Query for Matching Embedded Documents Only } diff --git a/packages/mql-typescript/tests/search/equals.spec.ts b/packages/mql-typescript/tests/search/equals.spec.ts index 4f0c9d37..baa332d2 100644 --- a/packages/mql-typescript/tests/search/equals.spec.ts +++ b/packages/mql-typescript/tests/search/equals.spec.ts @@ -9,26 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/equals/#boolean-examples} */ function test0() { - type users = { - _id: bson.ObjectId; - name: string; - verified_user: boolean; - account: { - new_user: boolean; - active_user: boolean; - }; - teammates: Array; - region: string; - account_created: Date; - employee_number: number; - uuid: bson.Binary; - job_title: null | string; - }; - - const aggregation: schema.Pipeline = [ - { $search: { equals: { path: 'verified_user', value: true } } }, - { $project: { name: 1, _id: 0, score: { $meta: 'searchScore' } } }, - ]; + // TODO: no schema found for equals.Boolean } /** @@ -36,32 +17,7 @@ function test0() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/equals/#objectid-example} */ function test1() { - type users = { - _id: bson.ObjectId; - name: string; - verified_user: boolean; - account: { - new_user: boolean; - active_user: boolean; - }; - teammates: Array; - region: string; - account_created: Date; - employee_number: number; - uuid: bson.Binary; - job_title: null | string; - }; - - const aggregation: schema.Pipeline = [ - { - $search: { - equals: { - path: 'teammates', - value: bson.ObjectId.createFromHexString('5a9427648b0beebeb69589a1'), - }, - }, - }, - ]; + // TODO: no schema found for equals.ObjectId } /** @@ -69,32 +25,7 @@ function test1() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/equals/#date-example} */ function test2() { - type users = { - _id: bson.ObjectId; - name: string; - verified_user: boolean; - account: { - new_user: boolean; - active_user: boolean; - }; - teammates: Array; - region: string; - account_created: Date; - employee_number: number; - uuid: bson.Binary; - job_title: null | string; - }; - - const aggregation: schema.Pipeline = [ - { - $search: { - equals: { - path: 'account_created', - value: new Date('2022-05-04T05:01:08.000Z'), - }, - }, - }, - ]; + // TODO: no schema found for equals.Date } /** @@ -102,25 +33,7 @@ function test2() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/equals/#number-example} */ function test3() { - type users = { - _id: bson.ObjectId; - name: string; - verified_user: boolean; - account: { - new_user: boolean; - active_user: boolean; - }; - teammates: Array; - region: string; - account_created: Date; - employee_number: number; - uuid: bson.Binary; - job_title: null | string; - }; - - const aggregation: schema.Pipeline = [ - { $search: { equals: { path: 'employee_number', value: 259 } } }, - ]; + // TODO: no schema found for equals.Number } /** @@ -128,25 +41,7 @@ function test3() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/equals/#string-example} */ function test4() { - type users = { - _id: bson.ObjectId; - name: string; - verified_user: boolean; - account: { - new_user: boolean; - active_user: boolean; - }; - teammates: Array; - region: string; - account_created: Date; - employee_number: number; - uuid: bson.Binary; - job_title: null | string; - }; - - const aggregation: schema.Pipeline = [ - { $search: { equals: { path: 'name', value: 'jim hall' } } }, - ]; + // TODO: no schema found for equals.String } /** @@ -154,32 +49,7 @@ function test4() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/equals/#uuid-example} */ function test5() { - type users = { - _id: bson.ObjectId; - name: string; - verified_user: boolean; - account: { - new_user: boolean; - active_user: boolean; - }; - teammates: Array; - region: string; - account_created: Date; - employee_number: number; - uuid: bson.Binary; - job_title: null | string; - }; - - const aggregation: schema.Pipeline = [ - { - $search: { - equals: { - path: 'uuid', - value: bson.Binary.createFromBase64('+sMiYLURTGmEhaK+W33ang==', 4), - }, - }, - }, - ]; + // TODO: no schema found for equals.UUID } /** @@ -187,23 +57,5 @@ function test5() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/equals/#null-example} */ function test6() { - type users = { - _id: bson.ObjectId; - name: string; - verified_user: boolean; - account: { - new_user: boolean; - active_user: boolean; - }; - teammates: Array; - region: string; - account_created: Date; - employee_number: number; - uuid: bson.Binary; - job_title: null | string; - }; - - const aggregation: schema.Pipeline = [ - { $search: { equals: { path: 'job_title', value: null } } }, - ]; + // TODO: no schema found for equals.Null } diff --git a/packages/mql-typescript/tests/search/exists.spec.ts b/packages/mql-typescript/tests/search/exists.spec.ts index a316f3dd..2ada1b51 100644 --- a/packages/mql-typescript/tests/search/exists.spec.ts +++ b/packages/mql-typescript/tests/search/exists.spec.ts @@ -9,20 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/exists/#basic-example} */ function test0() { - type TestCollection = { - _id: number; - type: string; - description: string; - quantities: { - lemons: number; - oranges: number; - grapefruit: number; - }; - }; - - const aggregation: schema.Pipeline = [ - { $search: { exists: { path: 'type' } } }, - ]; + // TODO: no schema found for exists.Basic } /** @@ -30,23 +17,7 @@ function test0() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/exists/#embedded-example} */ function test1() { - type TestCollection = { - _id: number; - type: string; - description: string; - quantities: { - lemons: number; - oranges: number; - grapefruit: number; - }; - }; - - const aggregation: schema.Pipeline = [ - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). - */ - { $search: { exists: { path: 'quantities.lemons' } } } as any, - ]; + // TODO: no schema found for exists.Embedded } /** @@ -54,28 +25,5 @@ function test1() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/exists/#compound-example} */ function test2() { - type TestCollection = { - _id: number; - type: string; - description: string; - quantities: { - lemons: number; - oranges: number; - grapefruit: number; - }; - }; - - const aggregation: schema.Pipeline = [ - { - $search: { - compound: { - must: [ - { exists: { path: 'type' } }, - { text: { query: 'apple', path: 'type' } }, - ], - should: { text: { query: 'fuji', path: 'description' } }, - }, - }, - }, - ]; + // TODO: no schema found for exists.Compound } diff --git a/packages/mql-typescript/tests/search/facet.spec.ts b/packages/mql-typescript/tests/search/facet.spec.ts index 0d3fa1b2..8991cfa9 100644 --- a/packages/mql-typescript/tests/search/facet.spec.ts +++ b/packages/mql-typescript/tests/search/facet.spec.ts @@ -9,92 +9,21 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/facet/#examples} */ function test0() { - type movies = { - _id: { - $oid: string; - }; - title: string; - year: { - $numberInt: string; - }; - runtime: { - $numberInt: string; - }; - released: { - $date: { - $numberLong: string; - }; - }; - poster: string; - plot: string; - fullplot: string; - lastupdated: string; - type: string; - directors: Array; - imdb: { - rating: { - $numberDouble: string; - }; - votes: { - $numberInt: string; - }; - id: { - $numberInt: string; - }; - }; - cast: Array; - countries: Array; - genres: Array; - tomatoes: { - viewer: { - rating: { - $numberDouble: string; - }; - numReviews: { - $numberInt: string; - }; - }; - lastUpdated: { - $date: { - $numberLong: string; - }; - }; - }; - num_mflix_comments: { - $numberInt: string; - }; - }; - - const aggregation: schema.Pipeline = [ - { - $search: { - facet: { - operator: { - near: { - path: 'released', - origin: new Date('1999-07-01T00:00:00.000Z'), - pivot: 7776000000, - }, - }, - facets: { genresFacet: { type: 'string', path: 'genres' } }, - }, - }, - }, - { $limit: 2 }, + // TODO: no schema found for facet.Facet +} - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' (this uses $$SEARCH_META, which is a synthetic field not available statically). - */ - { - $facet: { - docs: [{ $project: { title: 1, released: 1 } }], - meta: [{ $replaceWith: '$$SEARCH_META' }, { $limit: 1 }], - }, - } as any, +/** + * Multi-Select Faceting Example + * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/facet/#multi-select-faceting-example} + */ +function test1() { + // TODO: no schema found for facet.Multi-Select Faceting Example +} - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' (this uses $$SEARCH_META, which is a synthetic field not available statically). - */ - { $set: { meta: { $arrayElemAt: ['$meta', 0] } } } as any, - ]; +/** + * Inter-Facet Filter Exclusion Example + * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/facet/#inter-facet-filter-exclusion-example} + */ +function test2() { + // TODO: no schema found for facet.Inter-Facet Filter Exclusion Example } diff --git a/packages/mql-typescript/tests/search/geoShape.spec.ts b/packages/mql-typescript/tests/search/geoShape.spec.ts index 71fb2fbe..31ed7b07 100644 --- a/packages/mql-typescript/tests/search/geoShape.spec.ts +++ b/packages/mql-typescript/tests/search/geoShape.spec.ts @@ -9,207 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/geoShape/#disjoint-example} */ function test0() { - type listingsAndReviews = { - _id: string; - listing_url: string; - name: string; - summary: string; - interaction: string; - house_rules: string; - property_type: string; - room_type: string; - bed_type: string; - minimum_nights: string; - maximum_nights: string; - cancellation_policy: string; - last_scraped: { - $date: { - $numberLong: string; - }; - }; - calendar_last_scraped: { - $date: { - $numberLong: string; - }; - }; - first_review: { - $date: { - $numberLong: string; - }; - }; - last_review: { - $date: { - $numberLong: string; - }; - }; - accommodates: { - $numberInt: string; - }; - bedrooms: { - $numberInt: string; - }; - beds: { - $numberInt: string; - }; - number_of_reviews: { - $numberInt: string; - }; - bathrooms: { - $numberDecimal: string; - }; - amenities: Array; - price: { - $numberDecimal: string; - }; - security_deposit: { - $numberDecimal: string; - }; - cleaning_fee: { - $numberDecimal: string; - }; - extra_people: { - $numberDecimal: string; - }; - guests_included: { - $numberDecimal: string; - }; - images: { - thumbnail_url: string; - medium_url: string; - picture_url: string; - xl_picture_url: string; - }; - host: { - host_id: string; - host_url: string; - host_name: string; - host_location: string; - host_about: string; - host_response_time: string; - host_thumbnail_url: string; - host_picture_url: string; - host_neighbourhood: string; - host_response_rate: { - $numberInt: string; - }; - host_is_superhost: boolean; - host_has_profile_pic: boolean; - host_identity_verified: boolean; - host_listings_count: { - $numberInt: string; - }; - host_total_listings_count: { - $numberInt: string; - }; - host_verifications: Array; - }; - address: { - street: string; - suburb: string; - government_area: string; - market: string; - country: string; - country_code: string; - location: { - type: string; - coordinates: Array<{ - $numberDouble: string; - }>; - is_location_exact: boolean; - }; - }; - availability: { - availability_30: { - $numberInt: string; - }; - availability_60: { - $numberInt: string; - }; - availability_90: { - $numberInt: string; - }; - availability_365: { - $numberInt: string; - }; - }; - review_scores: { - review_scores_accuracy: { - $numberInt: string; - }; - review_scores_cleanliness: { - $numberInt: string; - }; - review_scores_checkin: { - $numberInt: string; - }; - review_scores_communication: { - $numberInt: string; - }; - review_scores_location: { - $numberInt: string; - }; - review_scores_value: { - $numberInt: string; - }; - review_scores_rating: { - $numberInt: string; - }; - }; - reviews: Array<{ - _id: string; - date: { - $date: { - $numberLong: string; - }; - }; - listing_id: string; - reviewer_id: string; - reviewer_name: string; - comments: string; - }>; - }; - - const aggregation: schema.Pipeline = [ - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). - */ - { - $search: { - geoShape: { - relation: 'disjoint', - geometry: { - type: 'Polygon', - coordinates: [ - [ - [-161.323242, 22.512557], - [-152.446289, 22.065278], - [-156.09375, 17.811456], - [-161.323242, 22.512557], - ], - ], - }, - path: 'address.location', - }, - }, - } as any, - - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). - */ - { $limit: 3 } as any, - - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). - */ - { - $project: { - _id: 0, - name: 1, - address: 1, - score: { $meta: 'searchScore' }, - }, - } as any, - ]; + // TODO: no schema found for geoShape.Disjoint } /** @@ -217,221 +17,7 @@ function test0() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/geoShape/#intersects-example} */ function test1() { - type listingsAndReviews = { - _id: string; - listing_url: string; - name: string; - summary: string; - interaction: string; - house_rules: string; - property_type: string; - room_type: string; - bed_type: string; - minimum_nights: string; - maximum_nights: string; - cancellation_policy: string; - last_scraped: { - $date: { - $numberLong: string; - }; - }; - calendar_last_scraped: { - $date: { - $numberLong: string; - }; - }; - first_review: { - $date: { - $numberLong: string; - }; - }; - last_review: { - $date: { - $numberLong: string; - }; - }; - accommodates: { - $numberInt: string; - }; - bedrooms: { - $numberInt: string; - }; - beds: { - $numberInt: string; - }; - number_of_reviews: { - $numberInt: string; - }; - bathrooms: { - $numberDecimal: string; - }; - amenities: Array; - price: { - $numberDecimal: string; - }; - security_deposit: { - $numberDecimal: string; - }; - cleaning_fee: { - $numberDecimal: string; - }; - extra_people: { - $numberDecimal: string; - }; - guests_included: { - $numberDecimal: string; - }; - images: { - thumbnail_url: string; - medium_url: string; - picture_url: string; - xl_picture_url: string; - }; - host: { - host_id: string; - host_url: string; - host_name: string; - host_location: string; - host_about: string; - host_response_time: string; - host_thumbnail_url: string; - host_picture_url: string; - host_neighbourhood: string; - host_response_rate: { - $numberInt: string; - }; - host_is_superhost: boolean; - host_has_profile_pic: boolean; - host_identity_verified: boolean; - host_listings_count: { - $numberInt: string; - }; - host_total_listings_count: { - $numberInt: string; - }; - host_verifications: Array; - }; - address: { - street: string; - suburb: string; - government_area: string; - market: string; - country: string; - country_code: string; - location: { - type: string; - coordinates: Array<{ - $numberDouble: string; - }>; - is_location_exact: boolean; - }; - }; - availability: { - availability_30: { - $numberInt: string; - }; - availability_60: { - $numberInt: string; - }; - availability_90: { - $numberInt: string; - }; - availability_365: { - $numberInt: string; - }; - }; - review_scores: { - review_scores_accuracy: { - $numberInt: string; - }; - review_scores_cleanliness: { - $numberInt: string; - }; - review_scores_checkin: { - $numberInt: string; - }; - review_scores_communication: { - $numberInt: string; - }; - review_scores_location: { - $numberInt: string; - }; - review_scores_value: { - $numberInt: string; - }; - review_scores_rating: { - $numberInt: string; - }; - }; - reviews: Array<{ - _id: string; - date: { - $date: { - $numberLong: string; - }; - }; - listing_id: string; - reviewer_id: string; - reviewer_name: string; - comments: string; - }>; - }; - - const aggregation: schema.Pipeline = [ - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). - */ - { - $search: { - geoShape: { - relation: 'intersects', - geometry: { - type: 'MultiPolygon', - coordinates: [ - [ - [ - [2.16942, 41.40082], - [2.17963, 41.40087], - [2.18146, 41.39716], - [2.15533, 41.40686], - [2.14596, 41.38475], - [2.17519, 41.41035], - [2.16942, 41.40082], - ], - ], - [ - [ - [2.16365, 41.39416], - [2.16963, 41.39726], - [2.15395, 41.38005], - [2.17935, 41.43038], - [2.16365, 41.39416], - ], - ], - ], - }, - path: 'address.location', - }, - }, - } as any, - - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). - */ - { $limit: 3 } as any, - - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). - */ - { - $project: { - _id: 0, - name: 1, - address: 1, - score: { $meta: 'searchScore' }, - }, - } as any, - ]; + // TODO: no schema found for geoShape.Intersect } /** @@ -439,209 +25,5 @@ function test1() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/geoShape/#within-example} */ function test2() { - type listingsAndReviews = { - _id: string; - listing_url: string; - name: string; - summary: string; - interaction: string; - house_rules: string; - property_type: string; - room_type: string; - bed_type: string; - minimum_nights: string; - maximum_nights: string; - cancellation_policy: string; - last_scraped: { - $date: { - $numberLong: string; - }; - }; - calendar_last_scraped: { - $date: { - $numberLong: string; - }; - }; - first_review: { - $date: { - $numberLong: string; - }; - }; - last_review: { - $date: { - $numberLong: string; - }; - }; - accommodates: { - $numberInt: string; - }; - bedrooms: { - $numberInt: string; - }; - beds: { - $numberInt: string; - }; - number_of_reviews: { - $numberInt: string; - }; - bathrooms: { - $numberDecimal: string; - }; - amenities: Array; - price: { - $numberDecimal: string; - }; - security_deposit: { - $numberDecimal: string; - }; - cleaning_fee: { - $numberDecimal: string; - }; - extra_people: { - $numberDecimal: string; - }; - guests_included: { - $numberDecimal: string; - }; - images: { - thumbnail_url: string; - medium_url: string; - picture_url: string; - xl_picture_url: string; - }; - host: { - host_id: string; - host_url: string; - host_name: string; - host_location: string; - host_about: string; - host_response_time: string; - host_thumbnail_url: string; - host_picture_url: string; - host_neighbourhood: string; - host_response_rate: { - $numberInt: string; - }; - host_is_superhost: boolean; - host_has_profile_pic: boolean; - host_identity_verified: boolean; - host_listings_count: { - $numberInt: string; - }; - host_total_listings_count: { - $numberInt: string; - }; - host_verifications: Array; - }; - address: { - street: string; - suburb: string; - government_area: string; - market: string; - country: string; - country_code: string; - location: { - type: string; - coordinates: Array<{ - $numberDouble: string; - }>; - is_location_exact: boolean; - }; - }; - availability: { - availability_30: { - $numberInt: string; - }; - availability_60: { - $numberInt: string; - }; - availability_90: { - $numberInt: string; - }; - availability_365: { - $numberInt: string; - }; - }; - review_scores: { - review_scores_accuracy: { - $numberInt: string; - }; - review_scores_cleanliness: { - $numberInt: string; - }; - review_scores_checkin: { - $numberInt: string; - }; - review_scores_communication: { - $numberInt: string; - }; - review_scores_location: { - $numberInt: string; - }; - review_scores_value: { - $numberInt: string; - }; - review_scores_rating: { - $numberInt: string; - }; - }; - reviews: Array<{ - _id: string; - date: { - $date: { - $numberLong: string; - }; - }; - listing_id: string; - reviewer_id: string; - reviewer_name: string; - comments: string; - }>; - }; - - const aggregation: schema.Pipeline = [ - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). - */ - { - $search: { - geoShape: { - relation: 'within', - geometry: { - type: 'Polygon', - coordinates: [ - [ - [-74.3994140625, 40.5305017757], - [-74.7290039063, 40.5805846641], - [-74.7729492188, 40.9467136651], - [-74.0698242188, 41.1290213475], - [-73.65234375, 40.9964840144], - [-72.6416015625, 40.9467136651], - [-72.3559570313, 40.7971774152], - [-74.3994140625, 40.5305017757], - ], - ], - }, - path: 'address.location', - }, - }, - } as any, - - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). - */ - { $limit: 3 } as any, - - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). - */ - { - $project: { - _id: 0, - name: 1, - address: 1, - score: { $meta: 'searchScore' }, - }, - } as any, - ]; + // TODO: no schema found for geoShape.Within } diff --git a/packages/mql-typescript/tests/search/geoWithin.spec.ts b/packages/mql-typescript/tests/search/geoWithin.spec.ts index 50567793..c4a7034a 100644 --- a/packages/mql-typescript/tests/search/geoWithin.spec.ts +++ b/packages/mql-typescript/tests/search/geoWithin.spec.ts @@ -9,192 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/geoWithin/#box-example} */ function test0() { - type listingsAndReviews = { - _id: string; - listing_url: string; - name: string; - summary: string; - interaction: string; - house_rules: string; - property_type: string; - room_type: string; - bed_type: string; - minimum_nights: string; - maximum_nights: string; - cancellation_policy: string; - last_scraped: { - $date: { - $numberLong: string; - }; - }; - calendar_last_scraped: { - $date: { - $numberLong: string; - }; - }; - first_review: { - $date: { - $numberLong: string; - }; - }; - last_review: { - $date: { - $numberLong: string; - }; - }; - accommodates: { - $numberInt: string; - }; - bedrooms: { - $numberInt: string; - }; - beds: { - $numberInt: string; - }; - number_of_reviews: { - $numberInt: string; - }; - bathrooms: { - $numberDecimal: string; - }; - amenities: Array; - price: { - $numberDecimal: string; - }; - security_deposit: { - $numberDecimal: string; - }; - cleaning_fee: { - $numberDecimal: string; - }; - extra_people: { - $numberDecimal: string; - }; - guests_included: { - $numberDecimal: string; - }; - images: { - thumbnail_url: string; - medium_url: string; - picture_url: string; - xl_picture_url: string; - }; - host: { - host_id: string; - host_url: string; - host_name: string; - host_location: string; - host_about: string; - host_response_time: string; - host_thumbnail_url: string; - host_picture_url: string; - host_neighbourhood: string; - host_response_rate: { - $numberInt: string; - }; - host_is_superhost: boolean; - host_has_profile_pic: boolean; - host_identity_verified: boolean; - host_listings_count: { - $numberInt: string; - }; - host_total_listings_count: { - $numberInt: string; - }; - host_verifications: Array; - }; - address: { - street: string; - suburb: string; - government_area: string; - market: string; - country: string; - country_code: string; - location: { - type: string; - coordinates: Array<{ - $numberDouble: string; - }>; - is_location_exact: boolean; - }; - }; - availability: { - availability_30: { - $numberInt: string; - }; - availability_60: { - $numberInt: string; - }; - availability_90: { - $numberInt: string; - }; - availability_365: { - $numberInt: string; - }; - }; - review_scores: { - review_scores_accuracy: { - $numberInt: string; - }; - review_scores_cleanliness: { - $numberInt: string; - }; - review_scores_checkin: { - $numberInt: string; - }; - review_scores_communication: { - $numberInt: string; - }; - review_scores_location: { - $numberInt: string; - }; - review_scores_value: { - $numberInt: string; - }; - review_scores_rating: { - $numberInt: string; - }; - }; - reviews: Array<{ - _id: string; - date: { - $date: { - $numberLong: string; - }; - }; - listing_id: string; - reviewer_id: string; - reviewer_name: string; - comments: string; - }>; - }; - - const aggregation: schema.Pipeline = [ - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). - */ - { - $search: { - geoWithin: { - path: 'address.location', - box: { - bottomLeft: { type: 'Point', coordinates: [112.467, -55.05] }, - topRight: { type: 'Point', coordinates: [168, -9.133] }, - }, - }, - }, - } as any, - - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). - */ - { $limit: 3 } as any, - - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). - */ - { $project: { _id: 0, name: 1, address: 1 } } as any, - ]; + // TODO: no schema found for geoWithin.box } /** @@ -202,192 +17,7 @@ function test0() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/geoWithin/#circle-example} */ function test1() { - type listingsAndReviews = { - _id: string; - listing_url: string; - name: string; - summary: string; - interaction: string; - house_rules: string; - property_type: string; - room_type: string; - bed_type: string; - minimum_nights: string; - maximum_nights: string; - cancellation_policy: string; - last_scraped: { - $date: { - $numberLong: string; - }; - }; - calendar_last_scraped: { - $date: { - $numberLong: string; - }; - }; - first_review: { - $date: { - $numberLong: string; - }; - }; - last_review: { - $date: { - $numberLong: string; - }; - }; - accommodates: { - $numberInt: string; - }; - bedrooms: { - $numberInt: string; - }; - beds: { - $numberInt: string; - }; - number_of_reviews: { - $numberInt: string; - }; - bathrooms: { - $numberDecimal: string; - }; - amenities: Array; - price: { - $numberDecimal: string; - }; - security_deposit: { - $numberDecimal: string; - }; - cleaning_fee: { - $numberDecimal: string; - }; - extra_people: { - $numberDecimal: string; - }; - guests_included: { - $numberDecimal: string; - }; - images: { - thumbnail_url: string; - medium_url: string; - picture_url: string; - xl_picture_url: string; - }; - host: { - host_id: string; - host_url: string; - host_name: string; - host_location: string; - host_about: string; - host_response_time: string; - host_thumbnail_url: string; - host_picture_url: string; - host_neighbourhood: string; - host_response_rate: { - $numberInt: string; - }; - host_is_superhost: boolean; - host_has_profile_pic: boolean; - host_identity_verified: boolean; - host_listings_count: { - $numberInt: string; - }; - host_total_listings_count: { - $numberInt: string; - }; - host_verifications: Array; - }; - address: { - street: string; - suburb: string; - government_area: string; - market: string; - country: string; - country_code: string; - location: { - type: string; - coordinates: Array<{ - $numberDouble: string; - }>; - is_location_exact: boolean; - }; - }; - availability: { - availability_30: { - $numberInt: string; - }; - availability_60: { - $numberInt: string; - }; - availability_90: { - $numberInt: string; - }; - availability_365: { - $numberInt: string; - }; - }; - review_scores: { - review_scores_accuracy: { - $numberInt: string; - }; - review_scores_cleanliness: { - $numberInt: string; - }; - review_scores_checkin: { - $numberInt: string; - }; - review_scores_communication: { - $numberInt: string; - }; - review_scores_location: { - $numberInt: string; - }; - review_scores_value: { - $numberInt: string; - }; - review_scores_rating: { - $numberInt: string; - }; - }; - reviews: Array<{ - _id: string; - date: { - $date: { - $numberLong: string; - }; - }; - listing_id: string; - reviewer_id: string; - reviewer_name: string; - comments: string; - }>; - }; - - const aggregation: schema.Pipeline = [ - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). - */ - { - $search: { - geoWithin: { - circle: { - center: { type: 'Point', coordinates: [-73.54, 45.54] }, - radius: 1600, - }, - path: 'address.location', - }, - }, - } as any, - - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). - */ - { $limit: 3 } as any, - - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). - */ - { $project: { _id: 0, name: 1, address: 1 } } as any, - ]; + // TODO: no schema found for geoWithin.circle } /** @@ -395,197 +25,5 @@ function test1() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/geoWithin/#geometry-examples} */ function test2() { - type listingsAndReviews = { - _id: string; - listing_url: string; - name: string; - summary: string; - interaction: string; - house_rules: string; - property_type: string; - room_type: string; - bed_type: string; - minimum_nights: string; - maximum_nights: string; - cancellation_policy: string; - last_scraped: { - $date: { - $numberLong: string; - }; - }; - calendar_last_scraped: { - $date: { - $numberLong: string; - }; - }; - first_review: { - $date: { - $numberLong: string; - }; - }; - last_review: { - $date: { - $numberLong: string; - }; - }; - accommodates: { - $numberInt: string; - }; - bedrooms: { - $numberInt: string; - }; - beds: { - $numberInt: string; - }; - number_of_reviews: { - $numberInt: string; - }; - bathrooms: { - $numberDecimal: string; - }; - amenities: Array; - price: { - $numberDecimal: string; - }; - security_deposit: { - $numberDecimal: string; - }; - cleaning_fee: { - $numberDecimal: string; - }; - extra_people: { - $numberDecimal: string; - }; - guests_included: { - $numberDecimal: string; - }; - images: { - thumbnail_url: string; - medium_url: string; - picture_url: string; - xl_picture_url: string; - }; - host: { - host_id: string; - host_url: string; - host_name: string; - host_location: string; - host_about: string; - host_response_time: string; - host_thumbnail_url: string; - host_picture_url: string; - host_neighbourhood: string; - host_response_rate: { - $numberInt: string; - }; - host_is_superhost: boolean; - host_has_profile_pic: boolean; - host_identity_verified: boolean; - host_listings_count: { - $numberInt: string; - }; - host_total_listings_count: { - $numberInt: string; - }; - host_verifications: Array; - }; - address: { - street: string; - suburb: string; - government_area: string; - market: string; - country: string; - country_code: string; - location: { - type: string; - coordinates: Array<{ - $numberDouble: string; - }>; - is_location_exact: boolean; - }; - }; - availability: { - availability_30: { - $numberInt: string; - }; - availability_60: { - $numberInt: string; - }; - availability_90: { - $numberInt: string; - }; - availability_365: { - $numberInt: string; - }; - }; - review_scores: { - review_scores_accuracy: { - $numberInt: string; - }; - review_scores_cleanliness: { - $numberInt: string; - }; - review_scores_checkin: { - $numberInt: string; - }; - review_scores_communication: { - $numberInt: string; - }; - review_scores_location: { - $numberInt: string; - }; - review_scores_value: { - $numberInt: string; - }; - review_scores_rating: { - $numberInt: string; - }; - }; - reviews: Array<{ - _id: string; - date: { - $date: { - $numberLong: string; - }; - }; - listing_id: string; - reviewer_id: string; - reviewer_name: string; - comments: string; - }>; - }; - - const aggregation: schema.Pipeline = [ - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). - */ - { - $search: { - geoWithin: { - geometry: { - type: 'Polygon', - coordinates: [ - [ - [-161.323242, 22.512557], - [-152.446289, 22.065278], - [-156.09375, 17.811456], - [-161.323242, 22.512557], - ], - ], - }, - path: 'address.location', - }, - }, - } as any, - - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). - */ - { $limit: 3 } as any, - - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). - */ - { $project: { _id: 0, name: 1, address: 1 } } as any, - ]; + // TODO: no schema found for geoWithin.geometry } diff --git a/packages/mql-typescript/tests/search/hasAncestor.spec.ts b/packages/mql-typescript/tests/search/hasAncestor.spec.ts new file mode 100644 index 00000000..44c3bff2 --- /dev/null +++ b/packages/mql-typescript/tests/search/hasAncestor.spec.ts @@ -0,0 +1,13 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ +/* eslint-disable filename-rules/match */ +/* eslint-disable @typescript-eslint/consistent-type-imports */ +import type * as schema from '../../out/schema'; +import * as bson from 'bson'; + +/** + * Example + * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/operators-collectors/hasAncestor/#sample-query} + */ +function test0() { + // TODO: no schema found for hasAncestor.Example +} diff --git a/packages/mql-typescript/tests/search/hasRoot.spec.ts b/packages/mql-typescript/tests/search/hasRoot.spec.ts new file mode 100644 index 00000000..18ae7e95 --- /dev/null +++ b/packages/mql-typescript/tests/search/hasRoot.spec.ts @@ -0,0 +1,29 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ +/* eslint-disable filename-rules/match */ +/* eslint-disable @typescript-eslint/consistent-type-imports */ +import type * as schema from '../../out/schema'; +import * as bson from 'bson'; + +/** + * Simple Query + * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/operators-collectors/hasRoot/#simple-query} + */ +function test0() { + // TODO: no schema found for hasRoot.Simple Query +} + +/** + * Multi-Level Query + * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/operators-collectors/hasRoot/#multi-level-query} + */ +function test1() { + // TODO: no schema found for hasRoot.Multi-Level Query +} + +/** + * Compound Query + * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/operators-collectors/hasRoot/#compound-query} + */ +function test2() { + // TODO: no schema found for hasRoot.Compound Query +} diff --git a/packages/mql-typescript/tests/search/in.spec.ts b/packages/mql-typescript/tests/search/in.spec.ts index 58b85a32..99842858 100644 --- a/packages/mql-typescript/tests/search/in.spec.ts +++ b/packages/mql-typescript/tests/search/in.spec.ts @@ -9,41 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/in/#examples} */ function test0() { - type customers = { - _id: bson.ObjectId; - username: string; - name: string; - address: string; - birthdate: { - $date: bson.Double | number; - }; - email: string; - accounts: Array; - tier_and_details: { - b5f19cb532fa436a9be2cf1d7d1cac8a: { - tier: string; - benefits: Array; - active: boolean; - id: string; - }; - }; - }; - - const aggregation: schema.Pipeline = [ - { - $search: { - in: { - path: 'birthdate', - value: [ - new Date('1977-03-02T02:20:31.000Z'), - new Date('1977-03-01T00:00:00.000Z'), - new Date('1977-05-06T21:57:35.000Z'), - ], - }, - }, - }, - { $project: { _id: 0, name: 1, birthdate: 1 } }, - ]; + // TODO: no schema found for in.Single Value Field Match } /** @@ -51,30 +17,7 @@ function test0() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/in/#examples} */ function test1() { - type customers = { - _id: bson.ObjectId; - username: string; - name: string; - address: string; - birthdate: { - $date: bson.Double | number; - }; - email: string; - accounts: Array; - tier_and_details: { - b5f19cb532fa436a9be2cf1d7d1cac8a: { - tier: string; - benefits: Array; - active: boolean; - id: string; - }; - }; - }; - - const aggregation: schema.Pipeline = [ - { $search: { in: { path: 'accounts', value: [371138, 371139, 371140] } } }, - { $project: { _id: 0, name: 1, accounts: 1 } }, - ]; + // TODO: no schema found for in.Array Value Field Match } /** @@ -82,53 +25,5 @@ function test1() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/in/#examples} */ function test2() { - type customers = { - _id: bson.ObjectId; - username: string; - name: string; - address: string; - birthdate: { - $date: bson.Double | number; - }; - email: string; - accounts: Array; - tier_and_details: { - b5f19cb532fa436a9be2cf1d7d1cac8a: { - tier: string; - benefits: Array; - active: boolean; - id: string; - }; - }; - }; - - const aggregation: schema.Pipeline = [ - { - $search: { - compound: { - must: [ - { - in: { - path: 'name', - value: ['james sanchez', 'jennifer lawrence'], - }, - }, - ], - should: [ - { - in: { - path: '_id', - value: [ - bson.ObjectId.createFromHexString('5ca4bbcea2dd94ee58162a72'), - bson.ObjectId.createFromHexString('5ca4bbcea2dd94ee58162a91'), - ], - }, - }, - ], - }, - }, - }, - { $limit: 5 }, - { $project: { _id: 1, name: 1, score: { $meta: 'searchScore' } } }, - ]; + // TODO: no schema found for in.Compound Query Match } diff --git a/packages/mql-typescript/tests/search/moreLikeThis.spec.ts b/packages/mql-typescript/tests/search/moreLikeThis.spec.ts index afd109ab..aa1b4306 100644 --- a/packages/mql-typescript/tests/search/moreLikeThis.spec.ts +++ b/packages/mql-typescript/tests/search/moreLikeThis.spec.ts @@ -9,71 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/morelikethis/#example-1--single-document-with-multiple-fields} */ function test0() { - type movies = { - _id: { - $oid: string; - }; - title: string; - year: { - $numberInt: string; - }; - runtime: { - $numberInt: string; - }; - released: { - $date: { - $numberLong: string; - }; - }; - poster: string; - plot: string; - fullplot: string; - lastupdated: string; - type: string; - directors: Array; - imdb: { - rating: { - $numberDouble: string; - }; - votes: { - $numberInt: string; - }; - id: { - $numberInt: string; - }; - }; - cast: Array; - countries: Array; - genres: Array; - tomatoes: { - viewer: { - rating: { - $numberDouble: string; - }; - numReviews: { - $numberInt: string; - }; - }; - lastUpdated: { - $date: { - $numberLong: string; - }; - }; - }; - num_mflix_comments: { - $numberInt: string; - }; - }; - - const aggregation: schema.Pipeline = [ - { - $search: { - moreLikeThis: { like: { title: 'The Godfather', genres: 'action' } }, - }, - }, - { $limit: 5 }, - { $project: { _id: 0, title: 1, released: 1, genres: 1 } }, - ]; + // TODO: no schema found for moreLikeThis.Single Document with Multiple Fields } /** @@ -81,95 +17,7 @@ function test0() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/morelikethis/#example-2--input-document-excluded-in-results} */ function test1() { - type movies = { - _id: { - $oid: string; - }; - title: string; - year: { - $numberInt: string; - }; - runtime: { - $numberInt: string; - }; - released: { - $date: { - $numberLong: string; - }; - }; - poster: string; - plot: string; - fullplot: string; - lastupdated: string; - type: string; - directors: Array; - imdb: { - rating: { - $numberDouble: string; - }; - votes: { - $numberInt: string; - }; - id: { - $numberInt: string; - }; - }; - cast: Array; - countries: Array; - genres: Array; - tomatoes: { - viewer: { - rating: { - $numberDouble: string; - }; - numReviews: { - $numberInt: string; - }; - }; - lastUpdated: { - $date: { - $numberLong: string; - }; - }; - }; - num_mflix_comments: { - $numberInt: string; - }; - }; - - const aggregation: schema.Pipeline = [ - { - $search: { - compound: { - must: [ - { - moreLikeThis: { - like: { - _id: bson.ObjectId.createFromHexString( - '573a1396f29313caabce4a9a', - ), - genres: ['Crime', 'Drama'], - title: 'The Godfather', - }, - }, - }, - ], - mustNot: [ - { - equals: { - path: '_id', - value: bson.ObjectId.createFromHexString( - '573a1396f29313caabce4a9a', - ), - }, - }, - ], - }, - }, - }, - { $limit: 5 }, - { $project: { _id: 1, title: 1, released: 1, genres: 1 } }, - ]; + // TODO: no schema found for moreLikeThis.Input Document Excluded in Results } /** @@ -177,93 +25,5 @@ function test1() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/morelikethis/#example-3--multiple-analyzers} */ function test2() { - type movies = { - _id: { - $oid: string; - }; - title: string; - year: { - $numberInt: string; - }; - runtime: { - $numberInt: string; - }; - released: { - $date: { - $numberLong: string; - }; - }; - poster: string; - plot: string; - fullplot: string; - lastupdated: string; - type: string; - directors: Array; - imdb: { - rating: { - $numberDouble: string; - }; - votes: { - $numberInt: string; - }; - id: { - $numberInt: string; - }; - }; - cast: Array; - countries: Array; - genres: Array; - tomatoes: { - viewer: { - rating: { - $numberDouble: string; - }; - numReviews: { - $numberInt: string; - }; - }; - lastUpdated: { - $date: { - $numberLong: string; - }; - }; - }; - num_mflix_comments: { - $numberInt: string; - }; - }; - - const aggregation: schema.Pipeline = [ - { - $search: { - compound: { - should: [ - { - moreLikeThis: { - like: { - _id: bson.ObjectId.createFromHexString( - '573a1396f29313caabce4a9a', - ), - genres: ['Crime', 'Drama'], - title: 'The Godfather', - }, - }, - }, - ], - mustNot: [ - { - equals: { - path: '_id', - value: bson.ObjectId.createFromHexString( - '573a1394f29313caabcde9ef', - ), - }, - }, - ], - }, - }, - }, - { $limit: 10 }, - { $project: { title: 1, genres: 1, _id: 1 } }, - ]; + // TODO: no schema found for moreLikeThis.Multiple Analyzers } diff --git a/packages/mql-typescript/tests/search/near.spec.ts b/packages/mql-typescript/tests/search/near.spec.ts index 45d4c6a9..23018b7f 100644 --- a/packages/mql-typescript/tests/search/near.spec.ts +++ b/packages/mql-typescript/tests/search/near.spec.ts @@ -9,79 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/near/#number-example} */ function test0() { - type movies = { - _id: { - $oid: string; - }; - title: string; - year: { - $numberInt: string; - }; - runtime: { - $numberInt: string; - }; - released: { - $date: { - $numberLong: string; - }; - }; - poster: string; - plot: string; - fullplot: string; - lastupdated: string; - type: string; - directors: Array; - imdb: { - rating: { - $numberDouble: string; - }; - votes: { - $numberInt: string; - }; - id: { - $numberInt: string; - }; - }; - cast: Array; - countries: Array; - genres: Array; - tomatoes: { - viewer: { - rating: { - $numberDouble: string; - }; - numReviews: { - $numberInt: string; - }; - }; - lastUpdated: { - $date: { - $numberLong: string; - }; - }; - }; - num_mflix_comments: { - $numberInt: string; - }; - }; - - const aggregation: schema.Pipeline = [ - { - $search: { - index: 'runtimes', - near: { path: 'runtime', origin: 279, pivot: 2 }, - }, - }, - { $limit: 7 }, - { - $project: { - _id: 0, - title: 1, - runtime: 1, - score: { $meta: 'searchScore' }, - }, - }, - ]; + // TODO: no schema found for near.Number } /** @@ -89,83 +17,7 @@ function test0() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/near/#date-example} */ function test1() { - type movies = { - _id: { - $oid: string; - }; - title: string; - year: { - $numberInt: string; - }; - runtime: { - $numberInt: string; - }; - released: { - $date: { - $numberLong: string; - }; - }; - poster: string; - plot: string; - fullplot: string; - lastupdated: string; - type: string; - directors: Array; - imdb: { - rating: { - $numberDouble: string; - }; - votes: { - $numberInt: string; - }; - id: { - $numberInt: string; - }; - }; - cast: Array; - countries: Array; - genres: Array; - tomatoes: { - viewer: { - rating: { - $numberDouble: string; - }; - numReviews: { - $numberInt: string; - }; - }; - lastUpdated: { - $date: { - $numberLong: string; - }; - }; - }; - num_mflix_comments: { - $numberInt: string; - }; - }; - - const aggregation: schema.Pipeline = [ - { - $search: { - index: 'releaseddate', - near: { - path: 'released', - origin: new Date('1915-09-13T00:00:00.000Z'), - pivot: 7776000000, - }, - }, - }, - { $limit: 3 }, - { - $project: { - _id: 0, - title: 1, - released: 1, - score: { $meta: 'searchScore' }, - }, - }, - ]; + // TODO: no schema found for near.Date } /** @@ -173,197 +25,7 @@ function test1() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/near/#geojson-point-examples} */ function test2() { - type listingsAndReviews = { - _id: string; - listing_url: string; - name: string; - summary: string; - interaction: string; - house_rules: string; - property_type: string; - room_type: string; - bed_type: string; - minimum_nights: string; - maximum_nights: string; - cancellation_policy: string; - last_scraped: { - $date: { - $numberLong: string; - }; - }; - calendar_last_scraped: { - $date: { - $numberLong: string; - }; - }; - first_review: { - $date: { - $numberLong: string; - }; - }; - last_review: { - $date: { - $numberLong: string; - }; - }; - accommodates: { - $numberInt: string; - }; - bedrooms: { - $numberInt: string; - }; - beds: { - $numberInt: string; - }; - number_of_reviews: { - $numberInt: string; - }; - bathrooms: { - $numberDecimal: string; - }; - amenities: Array; - price: { - $numberDecimal: string; - }; - security_deposit: { - $numberDecimal: string; - }; - cleaning_fee: { - $numberDecimal: string; - }; - extra_people: { - $numberDecimal: string; - }; - guests_included: { - $numberDecimal: string; - }; - images: { - thumbnail_url: string; - medium_url: string; - picture_url: string; - xl_picture_url: string; - }; - host: { - host_id: string; - host_url: string; - host_name: string; - host_location: string; - host_about: string; - host_response_time: string; - host_thumbnail_url: string; - host_picture_url: string; - host_neighbourhood: string; - host_response_rate: { - $numberInt: string; - }; - host_is_superhost: boolean; - host_has_profile_pic: boolean; - host_identity_verified: boolean; - host_listings_count: { - $numberInt: string; - }; - host_total_listings_count: { - $numberInt: string; - }; - host_verifications: Array; - }; - address: { - street: string; - suburb: string; - government_area: string; - market: string; - country: string; - country_code: string; - location: { - type: string; - coordinates: Array<{ - $numberDouble: string; - }>; - is_location_exact: boolean; - }; - }; - availability: { - availability_30: { - $numberInt: string; - }; - availability_60: { - $numberInt: string; - }; - availability_90: { - $numberInt: string; - }; - availability_365: { - $numberInt: string; - }; - }; - review_scores: { - review_scores_accuracy: { - $numberInt: string; - }; - review_scores_cleanliness: { - $numberInt: string; - }; - review_scores_checkin: { - $numberInt: string; - }; - review_scores_communication: { - $numberInt: string; - }; - review_scores_location: { - $numberInt: string; - }; - review_scores_value: { - $numberInt: string; - }; - review_scores_rating: { - $numberInt: string; - }; - }; - reviews: Array<{ - _id: string; - date: { - $date: { - $numberLong: string; - }; - }; - listing_id: string; - reviewer_id: string; - reviewer_name: string; - comments: string; - }>; - }; - - const aggregation: schema.Pipeline = [ - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). - */ - { - $search: { - near: { - origin: { type: 'Point', coordinates: [-8.61308, 41.1413] }, - pivot: 1000, - path: 'address.location', - }, - }, - } as any, - - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). - */ - { $limit: 3 } as any, - - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). - */ - { - $project: { - _id: 0, - name: 1, - address: 1, - score: { $meta: 'searchScore' }, - }, - } as any, - ]; + // TODO: no schema found for near.GeoJSON Point } /** @@ -371,200 +33,5 @@ function test2() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/near/#compound-example} */ function test3() { - type listingsAndReviews = { - _id: string; - listing_url: string; - name: string; - summary: string; - interaction: string; - house_rules: string; - property_type: string; - room_type: string; - bed_type: string; - minimum_nights: string; - maximum_nights: string; - cancellation_policy: string; - last_scraped: { - $date: { - $numberLong: string; - }; - }; - calendar_last_scraped: { - $date: { - $numberLong: string; - }; - }; - first_review: { - $date: { - $numberLong: string; - }; - }; - last_review: { - $date: { - $numberLong: string; - }; - }; - accommodates: { - $numberInt: string; - }; - bedrooms: { - $numberInt: string; - }; - beds: { - $numberInt: string; - }; - number_of_reviews: { - $numberInt: string; - }; - bathrooms: { - $numberDecimal: string; - }; - amenities: Array; - price: { - $numberDecimal: string; - }; - security_deposit: { - $numberDecimal: string; - }; - cleaning_fee: { - $numberDecimal: string; - }; - extra_people: { - $numberDecimal: string; - }; - guests_included: { - $numberDecimal: string; - }; - images: { - thumbnail_url: string; - medium_url: string; - picture_url: string; - xl_picture_url: string; - }; - host: { - host_id: string; - host_url: string; - host_name: string; - host_location: string; - host_about: string; - host_response_time: string; - host_thumbnail_url: string; - host_picture_url: string; - host_neighbourhood: string; - host_response_rate: { - $numberInt: string; - }; - host_is_superhost: boolean; - host_has_profile_pic: boolean; - host_identity_verified: boolean; - host_listings_count: { - $numberInt: string; - }; - host_total_listings_count: { - $numberInt: string; - }; - host_verifications: Array; - }; - address: { - street: string; - suburb: string; - government_area: string; - market: string; - country: string; - country_code: string; - location: { - type: string; - coordinates: Array<{ - $numberDouble: string; - }>; - is_location_exact: boolean; - }; - }; - availability: { - availability_30: { - $numberInt: string; - }; - availability_60: { - $numberInt: string; - }; - availability_90: { - $numberInt: string; - }; - availability_365: { - $numberInt: string; - }; - }; - review_scores: { - review_scores_accuracy: { - $numberInt: string; - }; - review_scores_cleanliness: { - $numberInt: string; - }; - review_scores_checkin: { - $numberInt: string; - }; - review_scores_communication: { - $numberInt: string; - }; - review_scores_location: { - $numberInt: string; - }; - review_scores_value: { - $numberInt: string; - }; - review_scores_rating: { - $numberInt: string; - }; - }; - reviews: Array<{ - _id: string; - date: { - $date: { - $numberLong: string; - }; - }; - listing_id: string; - reviewer_id: string; - reviewer_name: string; - comments: string; - }>; - }; - - const aggregation: schema.Pipeline = [ - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). - */ - { - $search: { - compound: { - must: { text: { query: 'Apartment', path: 'property_type' } }, - should: { - near: { - origin: { type: 'Point', coordinates: [114.15027, 22.28158] }, - pivot: 1000, - path: 'address.location', - }, - }, - }, - }, - } as any, - - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). - */ - { $limit: 3 } as any, - - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). - */ - { - $project: { - _id: 0, - property_type: 1, - address: 1, - score: { $meta: 'searchScore' }, - }, - } as any, - ]; + // TODO: no schema found for near.Compound } diff --git a/packages/mql-typescript/tests/search/phrase.spec.ts b/packages/mql-typescript/tests/search/phrase.spec.ts index a45cd160..5dff4dde 100644 --- a/packages/mql-typescript/tests/search/phrase.spec.ts +++ b/packages/mql-typescript/tests/search/phrase.spec.ts @@ -9,67 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/phrase/#single-phrase-example} */ function test0() { - type movies = { - _id: { - $oid: string; - }; - title: string; - year: { - $numberInt: string; - }; - runtime: { - $numberInt: string; - }; - released: { - $date: { - $numberLong: string; - }; - }; - poster: string; - plot: string; - fullplot: string; - lastupdated: string; - type: string; - directors: Array; - imdb: { - rating: { - $numberDouble: string; - }; - votes: { - $numberInt: string; - }; - id: { - $numberInt: string; - }; - }; - cast: Array; - countries: Array; - genres: Array; - tomatoes: { - viewer: { - rating: { - $numberDouble: string; - }; - numReviews: { - $numberInt: string; - }; - }; - lastUpdated: { - $date: { - $numberLong: string; - }; - }; - }; - num_mflix_comments: { - $numberInt: string; - }; - }; - - const aggregation: schema.Pipeline = [ - { $search: { phrase: { path: 'title', query: 'new york' } } }, - { $limit: 10 }, - { $project: { _id: 0, title: 1, score: { $meta: 'searchScore' } } }, - ]; + // TODO: no schema found for phrase.Single Phrase } /** @@ -77,67 +17,7 @@ function test0() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/phrase/#multiple-phrases-example} */ function test1() { - type movies = { - _id: { - $oid: string; - }; - title: string; - year: { - $numberInt: string; - }; - runtime: { - $numberInt: string; - }; - released: { - $date: { - $numberLong: string; - }; - }; - poster: string; - plot: string; - fullplot: string; - lastupdated: string; - type: string; - directors: Array; - imdb: { - rating: { - $numberDouble: string; - }; - votes: { - $numberInt: string; - }; - id: { - $numberInt: string; - }; - }; - cast: Array; - countries: Array; - genres: Array; - tomatoes: { - viewer: { - rating: { - $numberDouble: string; - }; - numReviews: { - $numberInt: string; - }; - }; - lastUpdated: { - $date: { - $numberLong: string; - }; - }; - }; - num_mflix_comments: { - $numberInt: string; - }; - }; - - const aggregation: schema.Pipeline = [ - { $search: { phrase: { path: 'title', query: ['the man', 'the moon'] } } }, - { $limit: 10 }, - { $project: { _id: 0, title: 1, score: { $meta: 'searchScore' } } }, - ]; + // TODO: no schema found for phrase.Multiple Phrase } /** @@ -145,66 +25,7 @@ function test1() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/phrase/#slop-example} */ function test2() { - type movies = { - _id: { - $oid: string; - }; - title: string; - year: { - $numberInt: string; - }; - runtime: { - $numberInt: string; - }; - released: { - $date: { - $numberLong: string; - }; - }; - poster: string; - plot: string; - fullplot: string; - lastupdated: string; - type: string; - directors: Array; - imdb: { - rating: { - $numberDouble: string; - }; - votes: { - $numberInt: string; - }; - id: { - $numberInt: string; - }; - }; - cast: Array; - countries: Array; - genres: Array; - tomatoes: { - viewer: { - rating: { - $numberDouble: string; - }; - numReviews: { - $numberInt: string; - }; - }; - lastUpdated: { - $date: { - $numberLong: string; - }; - }; - }; - num_mflix_comments: { - $numberInt: string; - }; - }; - - const aggregation: schema.Pipeline = [ - { $search: { phrase: { path: 'title', query: 'men women', slop: 5 } } }, - { $project: { _id: 0, title: 1, score: { $meta: 'searchScore' } } }, - ]; + // TODO: no schema found for phrase.Phrase Slop } /** @@ -212,76 +33,5 @@ function test2() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/phrase/#synonyms-example} */ function test3() { - type movies = { - _id: { - $oid: string; - }; - title: string; - year: { - $numberInt: string; - }; - runtime: { - $numberInt: string; - }; - released: { - $date: { - $numberLong: string; - }; - }; - poster: string; - plot: string; - fullplot: string; - lastupdated: string; - type: string; - directors: Array; - imdb: { - rating: { - $numberDouble: string; - }; - votes: { - $numberInt: string; - }; - id: { - $numberInt: string; - }; - }; - cast: Array; - countries: Array; - genres: Array; - tomatoes: { - viewer: { - rating: { - $numberDouble: string; - }; - numReviews: { - $numberInt: string; - }; - }; - lastUpdated: { - $date: { - $numberLong: string; - }; - }; - }; - num_mflix_comments: { - $numberInt: string; - }; - }; - - const aggregation: schema.Pipeline = [ - { - $search: { - phrase: { - path: 'plot', - query: 'automobile race', - slop: 5, - synonyms: 'my_synonyms', - }, - }, - }, - { $limit: 5 }, - { - $project: { _id: 0, plot: 1, title: 1, score: { $meta: 'searchScore' } }, - }, - ]; + // TODO: no schema found for phrase.Phrase Synonyms } diff --git a/packages/mql-typescript/tests/search/queryString.spec.ts b/packages/mql-typescript/tests/search/queryString.spec.ts index c034d5dc..63a74478 100644 --- a/packages/mql-typescript/tests/search/queryString.spec.ts +++ b/packages/mql-typescript/tests/search/queryString.spec.ts @@ -9,71 +9,5 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/queryString/#boolean-operator-queries} */ function test0() { - type movies = { - _id: { - $oid: string; - }; - title: string; - year: { - $numberInt: string; - }; - runtime: { - $numberInt: string; - }; - released: { - $date: { - $numberLong: string; - }; - }; - poster: string; - plot: string; - fullplot: string; - lastupdated: string; - type: string; - directors: Array; - imdb: { - rating: { - $numberDouble: string; - }; - votes: { - $numberInt: string; - }; - id: { - $numberInt: string; - }; - }; - cast: Array; - countries: Array; - genres: Array; - tomatoes: { - viewer: { - rating: { - $numberDouble: string; - }; - numReviews: { - $numberInt: string; - }; - }; - lastUpdated: { - $date: { - $numberLong: string; - }; - }; - }; - num_mflix_comments: { - $numberInt: string; - }; - }; - - const aggregation: schema.Pipeline = [ - { - $search: { - queryString: { - defaultPath: 'title', - query: 'Rocky AND (IV OR 4 OR Four)', - }, - }, - }, - { $project: { _id: 0, title: 1 } }, - ]; + // TODO: no schema found for queryString.Boolean Operator Queries } diff --git a/packages/mql-typescript/tests/search/range.spec.ts b/packages/mql-typescript/tests/search/range.spec.ts index 9d4f2720..fe22d63a 100644 --- a/packages/mql-typescript/tests/search/range.spec.ts +++ b/packages/mql-typescript/tests/search/range.spec.ts @@ -9,67 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/range/#number-example} */ function test0() { - type movies = { - _id: { - $oid: string; - }; - title: string; - year: { - $numberInt: string; - }; - runtime: { - $numberInt: string; - }; - released: { - $date: { - $numberLong: string; - }; - }; - poster: string; - plot: string; - fullplot: string; - lastupdated: string; - type: string; - directors: Array; - imdb: { - rating: { - $numberDouble: string; - }; - votes: { - $numberInt: string; - }; - id: { - $numberInt: string; - }; - }; - cast: Array; - countries: Array; - genres: Array; - tomatoes: { - viewer: { - rating: { - $numberDouble: string; - }; - numReviews: { - $numberInt: string; - }; - }; - lastUpdated: { - $date: { - $numberLong: string; - }; - }; - }; - num_mflix_comments: { - $numberInt: string; - }; - }; - - const aggregation: schema.Pipeline = [ - { $search: { range: { path: 'runtime', gte: 2, lte: 3 } } }, - { $limit: 5 }, - { $project: { _id: 0, title: 1, runtime: 1 } }, - ]; + // TODO: no schema found for range.Number gte lte } /** @@ -77,74 +17,7 @@ function test0() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/range/#number-example} */ function test1() { - type movies = { - _id: { - $oid: string; - }; - title: string; - year: { - $numberInt: string; - }; - runtime: { - $numberInt: string; - }; - released: { - $date: { - $numberLong: string; - }; - }; - poster: string; - plot: string; - fullplot: string; - lastupdated: string; - type: string; - directors: Array; - imdb: { - rating: { - $numberDouble: string; - }; - votes: { - $numberInt: string; - }; - id: { - $numberInt: string; - }; - }; - cast: Array; - countries: Array; - genres: Array; - tomatoes: { - viewer: { - rating: { - $numberDouble: string; - }; - numReviews: { - $numberInt: string; - }; - }; - lastUpdated: { - $date: { - $numberLong: string; - }; - }; - }; - num_mflix_comments: { - $numberInt: string; - }; - }; - - const aggregation: schema.Pipeline = [ - { $search: { range: { path: 'runtime', lte: 2 } } }, - { $limit: 5 }, - { - $project: { - _id: 0, - title: 1, - runtime: 1, - score: { $meta: 'searchScore' }, - }, - }, - ]; + // TODO: no schema found for range.Number lte } /** @@ -152,75 +25,7 @@ function test1() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/range/#date-example} */ function test2() { - type movies = { - _id: { - $oid: string; - }; - title: string; - year: { - $numberInt: string; - }; - runtime: { - $numberInt: string; - }; - released: { - $date: { - $numberLong: string; - }; - }; - poster: string; - plot: string; - fullplot: string; - lastupdated: string; - type: string; - directors: Array; - imdb: { - rating: { - $numberDouble: string; - }; - votes: { - $numberInt: string; - }; - id: { - $numberInt: string; - }; - }; - cast: Array; - countries: Array; - genres: Array; - tomatoes: { - viewer: { - rating: { - $numberDouble: string; - }; - numReviews: { - $numberInt: string; - }; - }; - lastUpdated: { - $date: { - $numberLong: string; - }; - }; - }; - num_mflix_comments: { - $numberInt: string; - }; - }; - - const aggregation: schema.Pipeline = [ - { - $search: { - range: { - path: 'released', - gt: new Date('2010-01-01T00:00:00.000Z'), - lt: new Date('2015-01-01T00:00:00.000Z'), - }, - }, - }, - { $limit: 5 }, - { $project: { _id: 0, title: 1, released: 1 } }, - ]; + // TODO: no schema found for range.Date } /** @@ -228,74 +33,7 @@ function test2() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/range/#objectid-example} */ function test3() { - type movies = { - _id: { - $oid: string; - }; - title: string; - year: { - $numberInt: string; - }; - runtime: { - $numberInt: string; - }; - released: { - $date: { - $numberLong: string; - }; - }; - poster: string; - plot: string; - fullplot: string; - lastupdated: string; - type: string; - directors: Array; - imdb: { - rating: { - $numberDouble: string; - }; - votes: { - $numberInt: string; - }; - id: { - $numberInt: string; - }; - }; - cast: Array; - countries: Array; - genres: Array; - tomatoes: { - viewer: { - rating: { - $numberDouble: string; - }; - numReviews: { - $numberInt: string; - }; - }; - lastUpdated: { - $date: { - $numberLong: string; - }; - }; - }; - num_mflix_comments: { - $numberInt: string; - }; - }; - - const aggregation: schema.Pipeline = [ - { - $search: { - range: { - path: '_id', - gte: bson.ObjectId.createFromHexString('573a1396f29313caabce4a9a'), - lte: bson.ObjectId.createFromHexString('573a1396f29313caabce4ae7'), - }, - }, - }, - { $project: { _id: 1, title: 1, released: 1 } }, - ]; + // TODO: no schema found for range.ObjectId } /** @@ -303,65 +41,5 @@ function test3() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/range/#string-example} */ function test4() { - type movies = { - _id: { - $oid: string; - }; - title: string; - year: { - $numberInt: string; - }; - runtime: { - $numberInt: string; - }; - released: { - $date: { - $numberLong: string; - }; - }; - poster: string; - plot: string; - fullplot: string; - lastupdated: string; - type: string; - directors: Array; - imdb: { - rating: { - $numberDouble: string; - }; - votes: { - $numberInt: string; - }; - id: { - $numberInt: string; - }; - }; - cast: Array; - countries: Array; - genres: Array; - tomatoes: { - viewer: { - rating: { - $numberDouble: string; - }; - numReviews: { - $numberInt: string; - }; - }; - lastUpdated: { - $date: { - $numberLong: string; - }; - }; - }; - num_mflix_comments: { - $numberInt: string; - }; - }; - - const aggregation: schema.Pipeline = [ - { $search: { range: { path: 'title', gt: 'city', lt: 'country' } } }, - { $limit: 5 }, - { $project: { _id: 0, title: 1 } }, - ]; + // TODO: no schema found for range.String } diff --git a/packages/mql-typescript/tests/search/regex.spec.ts b/packages/mql-typescript/tests/search/regex.spec.ts index ee152631..4352d7f3 100644 --- a/packages/mql-typescript/tests/search/regex.spec.ts +++ b/packages/mql-typescript/tests/search/regex.spec.ts @@ -9,64 +9,5 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/regex/#examples} */ function test0() { - type movies = { - _id: { - $oid: string; - }; - title: string; - year: { - $numberInt: string; - }; - runtime: { - $numberInt: string; - }; - released: { - $date: { - $numberLong: string; - }; - }; - poster: string; - plot: string; - fullplot: string; - lastupdated: string; - type: string; - directors: Array; - imdb: { - rating: { - $numberDouble: string; - }; - votes: { - $numberInt: string; - }; - id: { - $numberInt: string; - }; - }; - cast: Array; - countries: Array; - genres: Array; - tomatoes: { - viewer: { - rating: { - $numberDouble: string; - }; - numReviews: { - $numberInt: string; - }; - }; - lastUpdated: { - $date: { - $numberLong: string; - }; - }; - }; - num_mflix_comments: { - $numberInt: string; - }; - }; - - const aggregation: schema.Pipeline = [ - { $search: { regex: { path: 'title', query: '[0-9]{2} (.){4}s' } } }, - { $project: { _id: 0, title: 1 } }, - ]; + // TODO: no schema found for regex.Regex } diff --git a/packages/mql-typescript/tests/search/text.spec.ts b/packages/mql-typescript/tests/search/text.spec.ts index e8ad0412..ff45f4ad 100644 --- a/packages/mql-typescript/tests/search/text.spec.ts +++ b/packages/mql-typescript/tests/search/text.spec.ts @@ -9,66 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/text/#basic-example} */ function test0() { - type movies = { - _id: { - $oid: string; - }; - title: string; - year: { - $numberInt: string; - }; - runtime: { - $numberInt: string; - }; - released: { - $date: { - $numberLong: string; - }; - }; - poster: string; - plot: string; - fullplot: string; - lastupdated: string; - type: string; - directors: Array; - imdb: { - rating: { - $numberDouble: string; - }; - votes: { - $numberInt: string; - }; - id: { - $numberInt: string; - }; - }; - cast: Array; - countries: Array; - genres: Array; - tomatoes: { - viewer: { - rating: { - $numberDouble: string; - }; - numReviews: { - $numberInt: string; - }; - }; - lastUpdated: { - $date: { - $numberLong: string; - }; - }; - }; - num_mflix_comments: { - $numberInt: string; - }; - }; - - const aggregation: schema.Pipeline = [ - { $search: { text: { path: 'title', query: 'surfer' } } }, - { $project: { _id: 0, title: 1, score: { $meta: 'searchScore' } } }, - ]; + // TODO: no schema found for text.Basic } /** @@ -76,67 +17,7 @@ function test0() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/text/#fuzzy-examples} */ function test1() { - type movies = { - _id: { - $oid: string; - }; - title: string; - year: { - $numberInt: string; - }; - runtime: { - $numberInt: string; - }; - released: { - $date: { - $numberLong: string; - }; - }; - poster: string; - plot: string; - fullplot: string; - lastupdated: string; - type: string; - directors: Array; - imdb: { - rating: { - $numberDouble: string; - }; - votes: { - $numberInt: string; - }; - id: { - $numberInt: string; - }; - }; - cast: Array; - countries: Array; - genres: Array; - tomatoes: { - viewer: { - rating: { - $numberDouble: string; - }; - numReviews: { - $numberInt: string; - }; - }; - lastUpdated: { - $date: { - $numberLong: string; - }; - }; - }; - num_mflix_comments: { - $numberInt: string; - }; - }; - - const aggregation: schema.Pipeline = [ - { $search: { text: { path: 'title', query: 'naw yark', fuzzy: {} } } }, - { $limit: 10 }, - { $project: { _id: 0, title: 1, score: { $meta: 'searchScore' } } }, - ]; + // TODO: no schema found for text.Fuzzy Default } /** @@ -144,75 +25,7 @@ function test1() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/text/#fuzzy-examples} */ function test2() { - type movies = { - _id: { - $oid: string; - }; - title: string; - year: { - $numberInt: string; - }; - runtime: { - $numberInt: string; - }; - released: { - $date: { - $numberLong: string; - }; - }; - poster: string; - plot: string; - fullplot: string; - lastupdated: string; - type: string; - directors: Array; - imdb: { - rating: { - $numberDouble: string; - }; - votes: { - $numberInt: string; - }; - id: { - $numberInt: string; - }; - }; - cast: Array; - countries: Array; - genres: Array; - tomatoes: { - viewer: { - rating: { - $numberDouble: string; - }; - numReviews: { - $numberInt: string; - }; - }; - lastUpdated: { - $date: { - $numberLong: string; - }; - }; - }; - num_mflix_comments: { - $numberInt: string; - }; - }; - - const aggregation: schema.Pipeline = [ - { - $search: { - text: { - path: 'title', - query: 'naw yark', - fuzzy: { maxEdits: 1, maxExpansions: 100 }, - }, - }, - }, - { $limit: 10 }, - { $project: { _id: 0, title: 1, score: { $meta: 'searchScore' } } }, - ]; + // TODO: no schema found for text.Fuzzy maxExpansions } /** @@ -220,75 +33,7 @@ function test2() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/text/#fuzzy-examples} */ function test3() { - type movies = { - _id: { - $oid: string; - }; - title: string; - year: { - $numberInt: string; - }; - runtime: { - $numberInt: string; - }; - released: { - $date: { - $numberLong: string; - }; - }; - poster: string; - plot: string; - fullplot: string; - lastupdated: string; - type: string; - directors: Array; - imdb: { - rating: { - $numberDouble: string; - }; - votes: { - $numberInt: string; - }; - id: { - $numberInt: string; - }; - }; - cast: Array; - countries: Array; - genres: Array; - tomatoes: { - viewer: { - rating: { - $numberDouble: string; - }; - numReviews: { - $numberInt: string; - }; - }; - lastUpdated: { - $date: { - $numberLong: string; - }; - }; - }; - num_mflix_comments: { - $numberInt: string; - }; - }; - - const aggregation: schema.Pipeline = [ - { - $search: { - text: { - path: 'title', - query: 'naw yark', - fuzzy: { maxEdits: 1, prefixLength: 2 }, - }, - }, - }, - { $limit: 8 }, - { $project: { _id: 1, title: 1, score: { $meta: 'searchScore' } } }, - ]; + // TODO: no schema found for text.Fuzzy prefixLength } /** @@ -296,78 +41,7 @@ function test3() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/text/#match-any-using-equivalent-mapping} */ function test4() { - type movies = { - _id: { - $oid: string; - }; - title: string; - year: { - $numberInt: string; - }; - runtime: { - $numberInt: string; - }; - released: { - $date: { - $numberLong: string; - }; - }; - poster: string; - plot: string; - fullplot: string; - lastupdated: string; - type: string; - directors: Array; - imdb: { - rating: { - $numberDouble: string; - }; - votes: { - $numberInt: string; - }; - id: { - $numberInt: string; - }; - }; - cast: Array; - countries: Array; - genres: Array; - tomatoes: { - viewer: { - rating: { - $numberDouble: string; - }; - numReviews: { - $numberInt: string; - }; - }; - lastUpdated: { - $date: { - $numberLong: string; - }; - }; - }; - num_mflix_comments: { - $numberInt: string; - }; - }; - - const aggregation: schema.Pipeline = [ - { - $search: { - text: { - path: 'plot', - query: 'attire', - synonyms: 'my_synonyms', - matchCriteria: 'any', - }, - }, - }, - { $limit: 5 }, - { - $project: { _id: 0, plot: 1, title: 1, score: { $meta: 'searchScore' } }, - }, - ]; + // TODO: no schema found for text.Match any Using equivalent Mapping } /** @@ -375,78 +49,7 @@ function test4() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/text/#match-any-using-explicit-mapping} */ function test5() { - type movies = { - _id: { - $oid: string; - }; - title: string; - year: { - $numberInt: string; - }; - runtime: { - $numberInt: string; - }; - released: { - $date: { - $numberLong: string; - }; - }; - poster: string; - plot: string; - fullplot: string; - lastupdated: string; - type: string; - directors: Array; - imdb: { - rating: { - $numberDouble: string; - }; - votes: { - $numberInt: string; - }; - id: { - $numberInt: string; - }; - }; - cast: Array; - countries: Array; - genres: Array; - tomatoes: { - viewer: { - rating: { - $numberDouble: string; - }; - numReviews: { - $numberInt: string; - }; - }; - lastUpdated: { - $date: { - $numberLong: string; - }; - }; - }; - num_mflix_comments: { - $numberInt: string; - }; - }; - - const aggregation: schema.Pipeline = [ - { - $search: { - text: { - path: 'plot', - query: 'boat race', - synonyms: 'my_synonyms', - matchCriteria: 'any', - }, - }, - }, - { $limit: 10 }, - { - $project: { _id: 0, plot: 1, title: 1, score: { $meta: 'searchScore' } }, - }, - ]; + // TODO: no schema found for text.Match any Using explicit Mapping } /** @@ -454,78 +57,7 @@ function test5() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/text/#match-all-using-synonyms} */ function test6() { - type movies = { - _id: { - $oid: string; - }; - title: string; - year: { - $numberInt: string; - }; - runtime: { - $numberInt: string; - }; - released: { - $date: { - $numberLong: string; - }; - }; - poster: string; - plot: string; - fullplot: string; - lastupdated: string; - type: string; - directors: Array; - imdb: { - rating: { - $numberDouble: string; - }; - votes: { - $numberInt: string; - }; - id: { - $numberInt: string; - }; - }; - cast: Array; - countries: Array; - genres: Array; - tomatoes: { - viewer: { - rating: { - $numberDouble: string; - }; - numReviews: { - $numberInt: string; - }; - }; - lastUpdated: { - $date: { - $numberLong: string; - }; - }; - }; - num_mflix_comments: { - $numberInt: string; - }; - }; - - const aggregation: schema.Pipeline = [ - { - $search: { - text: { - path: 'plot', - query: 'automobile race', - matchCriteria: 'all', - synonyms: 'my_synonyms', - }, - }, - }, - { $limit: 20 }, - { - $project: { _id: 0, plot: 1, title: 1, score: { $meta: 'searchScore' } }, - }, - ]; + // TODO: no schema found for text.Match all Using Synonyms } /** @@ -533,64 +65,5 @@ function test6() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/text/} */ function test7() { - type movies = { - _id: { - $oid: string; - }; - title: string; - year: { - $numberInt: string; - }; - runtime: { - $numberInt: string; - }; - released: { - $date: { - $numberLong: string; - }; - }; - poster: string; - plot: string; - fullplot: string; - lastupdated: string; - type: string; - directors: Array; - imdb: { - rating: { - $numberDouble: string; - }; - votes: { - $numberInt: string; - }; - id: { - $numberInt: string; - }; - }; - cast: Array; - countries: Array; - genres: Array; - tomatoes: { - viewer: { - rating: { - $numberDouble: string; - }; - numReviews: { - $numberInt: string; - }; - }; - lastUpdated: { - $date: { - $numberLong: string; - }; - }; - }; - num_mflix_comments: { - $numberInt: string; - }; - }; - - const aggregation: schema.Pipeline = [ - { $search: { text: { path: { wildcard: '*' }, query: 'surfer' } } }, - { $project: { _id: 0, title: 1, score: { $meta: 'searchScore' } } }, - ]; + // TODO: no schema found for text.Wildcard Path } diff --git a/packages/mql-typescript/tests/search/vectorSearch.spec.ts b/packages/mql-typescript/tests/search/vectorSearch.spec.ts new file mode 100644 index 00000000..2c0d8800 --- /dev/null +++ b/packages/mql-typescript/tests/search/vectorSearch.spec.ts @@ -0,0 +1,97 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ +/* eslint-disable filename-rules/match */ +/* eslint-disable @typescript-eslint/consistent-type-imports */ +import type * as schema from '../../out/schema'; +import * as bson from 'bson'; + +/** + * ANN Basic + * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/vector-search/#basic-example} + */ +function test0() { + type movies = { + plot_embedding: Array; + plot: string; + title: string; + }; + + const aggregation: schema.Pipeline = [ + { + $search: { + vectorSearch: { + path: 'plot_embedding', + queryVector: [-0.0016261312, -0.028070757, -0.011342932], + numCandidates: 150, + limit: 10, + }, + }, + }, + { + $project: { _id: 0, plot: 1, title: 1, score: { $meta: 'searchScore' } }, + }, + ]; +} + +/** + * ANN Filter + * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/vector-search/#filter-example} + */ +function test1() { + type movies = { + plot_embedding: Array; + year: bson.Int32 | number; + plot: string; + title: string; + }; + + const aggregation: schema.Pipeline = [ + { + $search: { + vectorSearch: { + path: 'plot_embedding', + queryVector: [0.02421053, -0.022372592, -0.006231137], + filter: { range: { path: 'year', lt: 1975 } }, + numCandidates: 150, + limit: 10, + }, + }, + }, + { + $project: { + _id: 0, + title: 1, + plot: 1, + year: 1, + score: { $meta: 'searchScore' }, + }, + }, + ]; +} + +/** + * ENN + * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/vector-search/#enn-example} + */ +function test2() { + type movies = { + plot_embedding: Array; + plot: string; + title: string; + }; + + const aggregation: schema.Pipeline = [ + { + $search: { + vectorSearch: { + path: 'plot_embedding', + queryVector: [-0.006954097, -0.009932499, -0.001311474], + exact: true, + limit: 10, + }, + }, + }, + { + $project: { _id: 0, plot: 1, title: 1, score: { $meta: 'searchScore' } }, + }, + ]; +} diff --git a/packages/mql-typescript/tests/search/wildcard.spec.ts b/packages/mql-typescript/tests/search/wildcard.spec.ts index 480cd105..958553d6 100644 --- a/packages/mql-typescript/tests/search/wildcard.spec.ts +++ b/packages/mql-typescript/tests/search/wildcard.spec.ts @@ -9,67 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/wildcard/#index-definition} */ function test0() { - type movies = { - _id: { - $oid: string; - }; - title: string; - year: { - $numberInt: string; - }; - runtime: { - $numberInt: string; - }; - released: { - $date: { - $numberLong: string; - }; - }; - poster: string; - plot: string; - fullplot: string; - lastupdated: string; - type: string; - directors: Array; - imdb: { - rating: { - $numberDouble: string; - }; - votes: { - $numberInt: string; - }; - id: { - $numberInt: string; - }; - }; - cast: Array; - countries: Array; - genres: Array; - tomatoes: { - viewer: { - rating: { - $numberDouble: string; - }; - numReviews: { - $numberInt: string; - }; - }; - lastUpdated: { - $date: { - $numberLong: string; - }; - }; - }; - num_mflix_comments: { - $numberInt: string; - }; - }; - - const aggregation: schema.Pipeline = [ - { $search: { wildcard: { query: 'Wom?n *', path: { wildcard: '*' } } } }, - { $limit: 5 }, - { $project: { _id: 0, title: 1 } }, - ]; + // TODO: no schema found for wildcard.Wildcard Path } /** @@ -77,65 +17,5 @@ function test0() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/wildcard/#escape-character-example} */ function test1() { - type movies = { - _id: { - $oid: string; - }; - title: string; - year: { - $numberInt: string; - }; - runtime: { - $numberInt: string; - }; - released: { - $date: { - $numberLong: string; - }; - }; - poster: string; - plot: string; - fullplot: string; - lastupdated: string; - type: string; - directors: Array; - imdb: { - rating: { - $numberDouble: string; - }; - votes: { - $numberInt: string; - }; - id: { - $numberInt: string; - }; - }; - cast: Array; - countries: Array; - genres: Array; - tomatoes: { - viewer: { - rating: { - $numberDouble: string; - }; - numReviews: { - $numberInt: string; - }; - }; - lastUpdated: { - $date: { - $numberLong: string; - }; - }; - }; - num_mflix_comments: { - $numberInt: string; - }; - }; - - const aggregation: schema.Pipeline = [ - { $search: { wildcard: { query: '*\\?', path: 'title' } } }, - { $limit: 5 }, - { $project: { _id: 0, title: 1 } }, - ]; + // TODO: no schema found for wildcard.Escape Character Example } diff --git a/packages/mql-typescript/tests/stage/addFields.spec.ts b/packages/mql-typescript/tests/stage/addFields.spec.ts index 969b5d22..e3cc878c 100644 --- a/packages/mql-typescript/tests/stage/addFields.spec.ts +++ b/packages/mql-typescript/tests/stage/addFields.spec.ts @@ -9,31 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/addFields/#using-two--addfields-stages} */ function test0() { - type scores = { - _id: number; - student: string; - homework: Array; - quiz: Array; - extraCredit: number; - }; - - const aggregation: schema.Pipeline = [ - { - $addFields: { - totalHomework: { $sum: ['$homework'] }, - totalQuiz: { $sum: ['$quiz'] }, - }, - }, - - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' (it may involve a projected field). - */ - { - $addFields: { - totalScore: { $add: ['$totalHomework', '$totalQuiz', '$extraCredit'] }, - }, - } as any, - ]; + // TODO: no schema found for addFields.Using Two $addFields Stages } /** @@ -41,18 +17,7 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/addFields/#adding-fields-to-an-embedded-document} */ function test1() { - type vehicles = { - _id: number; - type: string; - specs: { - doors: number; - wheels: number; - }; - }; - - const aggregation: schema.Pipeline = [ - { $addFields: { 'specs.fuel_type': 'unleaded' } }, - ]; + // TODO: no schema found for addFields.Adding Fields to an Embedded Document } /** @@ -60,13 +25,7 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/addFields/#overwriting-an-existing-field} */ function test2() { - type animals = { - _id: number; - dogs: number; - cats: number; - }; - - const aggregation: schema.Pipeline = [{ $addFields: { cats: 20 } }]; + // TODO: no schema found for addFields.Overwriting an existing field } /** @@ -74,16 +33,5 @@ function test2() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/addFields/#add-element-to-an-array} */ function test3() { - type scores = { - _id: number; - student: string; - homework: Array; - quiz: Array; - extraCredit: number; - }; - - const aggregation: schema.Pipeline = [ - { $match: { _id: 1 } }, - { $addFields: { homework: { $concatArrays: ['$homework', [7]] } } }, - ]; + // TODO: no schema found for addFields.Add Element to an Array } diff --git a/packages/mql-typescript/tests/stage/bucket.spec.ts b/packages/mql-typescript/tests/stage/bucket.spec.ts index 3087cdb2..b0b335f2 100644 --- a/packages/mql-typescript/tests/stage/bucket.spec.ts +++ b/packages/mql-typescript/tests/stage/bucket.spec.ts @@ -9,38 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/bucket/#bucket-by-year-and-filter-by-bucket-results} */ function test0() { - type artists = { - _id: number; - last_name: string; - first_name: string; - year_born: number; - year_died: number; - nationality: string; - }; - - const aggregation: schema.Pipeline = [ - { - $bucket: { - groupBy: '$year_born', - boundaries: [1840, 1850, 1860, 1870, 1880], - default: 'Other', - output: { - count: { $sum: 1 }, - artists: { - $push: { - name: { $concat: ['$first_name', ' ', '$last_name'] }, - year_born: '$year_born', - }, - }, - }, - }, - }, - - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' (the output field of the $bucket stage generates new fields that are not available statically). - */ - { $match: { count: { $gt: 3 } } } as any, - ]; + // TODO: no schema found for bucket.Bucket by Year and Filter by Bucket Results } /** @@ -48,45 +17,5 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/bucket/#use--bucket-with--facet-to-bucket-by-multiple-fields} */ function test1() { - type artwork = { - _id: number; - title: string; - artist: string; - year: number; - price: bson.Decimal128; - }; - - const aggregation: schema.Pipeline = [ - { - $facet: { - price: [ - { - $bucket: { - groupBy: '$price', - boundaries: [0, 200, 400], - default: 'Other', - output: { - count: { $sum: 1 }, - artwork: { $push: { title: '$title', price: '$price' } }, - averagePrice: { $avg: '$price' }, - }, - }, - }, - ], - year: [ - { - $bucket: { - groupBy: '$year', - boundaries: [1890, 1910, 1920, 1940], - default: 'Unknown', - output: { - count: { $sum: 1 }, - artwork: { $push: { title: '$title', year: '$year' } }, - }, - }, - }, - ], - }, - }, - ]; + // TODO: no schema found for bucket.Use $bucket with $facet to Bucket by Multiple Fields } diff --git a/packages/mql-typescript/tests/stage/bucketAuto.spec.ts b/packages/mql-typescript/tests/stage/bucketAuto.spec.ts index eb003ef8..ac237a1e 100644 --- a/packages/mql-typescript/tests/stage/bucketAuto.spec.ts +++ b/packages/mql-typescript/tests/stage/bucketAuto.spec.ts @@ -9,20 +9,5 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/bucketAuto/#single-facet-aggregation} */ function test0() { - type artwork = { - _id: bson.Int32 | number; - title: string; - artist: string; - year: bson.Int32 | number; - price: bson.Decimal128; - dimensions: { - height: bson.Int32 | number; - width: bson.Int32 | number; - units: string; - }; - }; - - const aggregation: schema.Pipeline = [ - { $bucketAuto: { groupBy: '$price', buckets: 4 } }, - ]; + // TODO: no schema found for bucketAuto.Single Facet Aggregation } diff --git a/packages/mql-typescript/tests/stage/changeStream.spec.ts b/packages/mql-typescript/tests/stage/changeStream.spec.ts index 1aeb4aa0..b7e209bd 100644 --- a/packages/mql-typescript/tests/stage/changeStream.spec.ts +++ b/packages/mql-typescript/tests/stage/changeStream.spec.ts @@ -9,9 +9,5 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/changeStream/#examples} */ function test0() { - type names = { - _id: bson.ObjectId; - }; - - const aggregation: schema.Pipeline = [{ $changeStream: {} }]; + // TODO: no schema found for changeStream.Example } diff --git a/packages/mql-typescript/tests/stage/changeStreamSplitLargeEvent.spec.ts b/packages/mql-typescript/tests/stage/changeStreamSplitLargeEvent.spec.ts index ea1e2fc0..57aa8c46 100644 --- a/packages/mql-typescript/tests/stage/changeStreamSplitLargeEvent.spec.ts +++ b/packages/mql-typescript/tests/stage/changeStreamSplitLargeEvent.spec.ts @@ -9,12 +9,5 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/changeStreamSplitLargeEvent/#example} */ function test0() { - type myCollection = { - _id: bson.Int32 | number; - largeField: string; - }; - - const aggregation: schema.Pipeline = [ - { $changeStreamSplitLargeEvent: {} }, - ]; + // TODO: no schema found for changeStreamSplitLargeEvent.Example } diff --git a/packages/mql-typescript/tests/stage/collStats.spec.ts b/packages/mql-typescript/tests/stage/collStats.spec.ts index 84573f94..f00ef0b6 100644 --- a/packages/mql-typescript/tests/stage/collStats.spec.ts +++ b/packages/mql-typescript/tests/stage/collStats.spec.ts @@ -9,13 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/collStats/#latencystats-document} */ function test0() { - type TestCollection = { - _id: bson.ObjectId; - }; - - const aggregation: schema.Pipeline = [ - { $collStats: { latencyStats: { histograms: true } } }, - ]; + // TODO: no schema found for collStats.latencyStats Document } /** @@ -23,13 +17,7 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/collStats/#storagestats-document} */ function test1() { - type TestCollection = { - _id: bson.ObjectId; - }; - - const aggregation: schema.Pipeline = [ - { $collStats: { storageStats: {} } }, - ]; + // TODO: no schema found for collStats.storageStats Document } /** @@ -37,13 +25,7 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/collStats/#count-field} */ function test2() { - type TestCollection = { - _id: bson.ObjectId; - }; - - const aggregation: schema.Pipeline = [ - { $collStats: { count: {} } }, - ]; + // TODO: no schema found for collStats.count Field } /** @@ -51,11 +33,5 @@ function test2() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/collStats/#queryexecstats-document} */ function test3() { - type TestCollection = { - _id: bson.ObjectId; - }; - - const aggregation: schema.Pipeline = [ - { $collStats: { queryExecStats: {} } }, - ]; + // TODO: no schema found for collStats.queryExecStats Document } diff --git a/packages/mql-typescript/tests/stage/count.spec.ts b/packages/mql-typescript/tests/stage/count.spec.ts index d5f9e9d4..10488111 100644 --- a/packages/mql-typescript/tests/stage/count.spec.ts +++ b/packages/mql-typescript/tests/stage/count.spec.ts @@ -6,17 +6,8 @@ import * as bson from 'bson'; /** * Example - * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/count/#examples} + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/count/#example} */ function test0() { - type scores = { - _id: number; - subject: string; - score: number; - }; - - const aggregation: schema.Pipeline = [ - { $match: { score: { $gt: 80 } } }, - { $count: 'passing_scores' }, - ]; + // TODO: no schema found for count.Example } diff --git a/packages/mql-typescript/tests/stage/currentOp.spec.ts b/packages/mql-typescript/tests/stage/currentOp.spec.ts index f4dd6573..d6df9ddd 100644 --- a/packages/mql-typescript/tests/stage/currentOp.spec.ts +++ b/packages/mql-typescript/tests/stage/currentOp.spec.ts @@ -9,18 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/currentOp/#inactive-sessions} */ function test0() { - type TestCollection = { - _id: bson.ObjectId; - }; - - const aggregation: schema.Pipeline = [ - { $currentOp: { allUsers: true, idleSessions: true } }, - - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' ($currentOp emits new fields that are not available statically). - */ - { $match: { active: false, transaction: { $exists: true } } } as any, - ]; + // TODO: no schema found for currentOp.Inactive Sessions } /** @@ -28,16 +17,5 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/currentOp/#sampled-queries} */ function test1() { - type TestCollection = { - _id: bson.ObjectId; - }; - - const aggregation: schema.Pipeline = [ - { $currentOp: { allUsers: true, localOps: true } }, - - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' ($currentOp emits new fields that are not available statically). - */ - { $match: { desc: 'query analyzer' } } as any, - ]; + // TODO: no schema found for currentOp.Sampled Queries } diff --git a/packages/mql-typescript/tests/stage/densify.spec.ts b/packages/mql-typescript/tests/stage/densify.spec.ts index d603a75c..12ce07dd 100644 --- a/packages/mql-typescript/tests/stage/densify.spec.ts +++ b/packages/mql-typescript/tests/stage/densify.spec.ts @@ -9,51 +9,13 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/densify/#densify-time-series-data} */ function test0() { - type weather = { - metadata: { - sensorId: number; - type: string; - }; - timestamp: Date; - temp: number; - }; - - const aggregation: schema.Pipeline = [ - { - $densify: { - field: 'timestamp', - range: { - step: 1, - unit: 'hour', - bounds: [ - new Date('2021-05-18T00:00:00.000Z'), - new Date('2021-05-18T08:00:00.000Z'), - ], - }, - }, - }, - ]; + // TODO: no schema found for densify.Densify Time Series Data } /** * Densifiction with Partitions - * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/densify/#densification-with-partitions} + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/densify/#densifiction-with-partitions} */ function test1() { - type coffee = { - altitude: number; - variety: string; - score: number; - price: number; - }; - - const aggregation: schema.Pipeline = [ - { - $densify: { - field: 'altitude', - partitionByFields: ['variety'], - range: { bounds: 'full', step: 200 }, - }, - }, - ]; + // TODO: no schema found for densify.Densifiction with Partitions } diff --git a/packages/mql-typescript/tests/stage/documents.spec.ts b/packages/mql-typescript/tests/stage/documents.spec.ts index 2c560b0e..73b4cd27 100644 --- a/packages/mql-typescript/tests/stage/documents.spec.ts +++ b/packages/mql-typescript/tests/stage/documents.spec.ts @@ -9,14 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/documents/#test-a-pipeline-stage} */ function test0() { - type TestCollection = { - x: number; - }; - - const aggregation: schema.Pipeline = [ - { $documents: [{ x: 10 }, { x: 2 }, { x: 5 }] }, - { $bucketAuto: { groupBy: '$x', buckets: 4 } }, - ]; + // TODO: no schema found for documents.Test a Pipeline Stage } /** @@ -24,27 +17,5 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/documents/#use-a--documents-stage-in-a--lookup-stage} */ function test1() { - type locations = { - zip: number; - name: string; - }; - - const aggregation: schema.Pipeline = [ - { $match: {} }, - { - $lookup: { - localField: 'zip', - foreignField: 'zip_id', - as: 'city_state', - pipeline: [ - { - $documents: [ - { zip_id: 94301, name: 'Palo Alto, CA' }, - { zip_id: 10019, name: 'New York, NY' }, - ], - }, - ], - }, - }, - ]; + // TODO: no schema found for documents.Use a $documents Stage in a $lookup Stage } diff --git a/packages/mql-typescript/tests/stage/facet.spec.ts b/packages/mql-typescript/tests/stage/facet.spec.ts index 0c6eddf8..af4a475e 100644 --- a/packages/mql-typescript/tests/stage/facet.spec.ts +++ b/packages/mql-typescript/tests/stage/facet.spec.ts @@ -9,37 +9,5 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/facet/#example} */ function test0() { - type artwork = { - _id: number; - title: string; - artist: string; - year: number; - price: bson.Decimal128; - tags: Array; - }; - - const aggregation: schema.Pipeline = [ - { - $facet: { - categorizedByTags: [ - { $unwind: { path: '$tags' } }, - { $sortByCount: '$tags' }, - ], - categorizedByPrice: [ - { $match: { price: { $exists: true } } }, - { - $bucket: { - groupBy: '$price', - boundaries: [0, 150, 200, 300, 400], - default: 'Other', - output: { count: { $sum: 1 }, titles: { $push: '$title' } }, - }, - }, - ], - 'categorizedByYears(Auto)': [ - { $bucketAuto: { groupBy: '$year', buckets: 4 } }, - ], - }, - }, - ]; + // TODO: no schema found for facet.Example } diff --git a/packages/mql-typescript/tests/stage/fill.spec.ts b/packages/mql-typescript/tests/stage/fill.spec.ts index 2a29d4e7..17b929ea 100644 --- a/packages/mql-typescript/tests/stage/fill.spec.ts +++ b/packages/mql-typescript/tests/stage/fill.spec.ts @@ -9,24 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/fill/#fill-missing-field-values-with-a-constant-value} */ function test0() { - type dailySales = { - date: Date; - bootsSold: number; - sandalsSold: number; - sneakersSold: number; - }; - - const aggregation: schema.Pipeline = [ - { - $fill: { - output: { - bootsSold: { value: 0 }, - sandalsSold: { value: 0 }, - sneakersSold: { value: 0 }, - }, - }, - }, - ]; + // TODO: no schema found for fill.Fill Missing Field Values with a Constant Value } /** @@ -34,14 +17,7 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/fill/#fill-missing-field-values-with-linear-interpolation} */ function test1() { - type stock = { - time: Date; - price: number; - }; - - const aggregation: schema.Pipeline = [ - { $fill: { sortBy: { time: 1 }, output: { price: { method: 'linear' } } } }, - ]; + // TODO: no schema found for fill.Fill Missing Field Values with Linear Interpolation } /** @@ -49,14 +25,7 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/fill/#fill-missing-field-values-based-on-the-last-observed-value} */ function test2() { - type restaurantReviews = { - date: Date; - score: number; - }; - - const aggregation: schema.Pipeline = [ - { $fill: { sortBy: { date: 1 }, output: { score: { method: 'locf' } } } }, - ]; + // TODO: no schema found for fill.Fill Missing Field Values Based on the Last Observed Value } /** @@ -64,21 +33,7 @@ function test2() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/fill/#fill-data-for-distinct-partitions} */ function test3() { - type restaurantReviewsMultiple = { - date: Date; - restaurant: string; - score: number; - }; - - const aggregation: schema.Pipeline = [ - { - $fill: { - sortBy: { date: 1 }, - partitionBy: { restaurant: '$restaurant' }, - output: { score: { method: 'locf' } }, - }, - }, - ]; + // TODO: no schema found for fill.Fill Data for Distinct Partitions } /** @@ -86,19 +41,5 @@ function test3() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/fill/#indicate-if-a-field-was-populated-using--fill} */ function test4() { - type restaurantReviews = { - date: Date; - score: number; - }; - - const aggregation: schema.Pipeline = [ - { - $set: { - valueExisted: { - $ifNull: [{ $toBool: { $toString: '$score' } }, false], - }, - }, - }, - { $fill: { sortBy: { date: 1 }, output: { score: { method: 'locf' } } } }, - ]; + // TODO: no schema found for fill.Indicate if a Field was Populated Using $fill } diff --git a/packages/mql-typescript/tests/stage/geoNear.spec.ts b/packages/mql-typescript/tests/stage/geoNear.spec.ts index 986f4470..e1c91e13 100644 --- a/packages/mql-typescript/tests/stage/geoNear.spec.ts +++ b/packages/mql-typescript/tests/stage/geoNear.spec.ts @@ -9,27 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/geoNear/#maximum-distance} */ function test0() { - type places = { - name: string; - location: { - type: string; - coordinates: Array; - }; - category: string; - }; - - const aggregation: schema.Pipeline = [ - { - $geoNear: { - near: { type: 'Point', coordinates: [-73.99279, 40.719296] }, - distanceField: 'dist.calculated', - maxDistance: 2, - query: { category: 'Parks' }, - includeLocs: 'dist.location', - spherical: true, - }, - }, - ]; + // TODO: no schema found for geoNear.Maximum Distance } /** @@ -37,27 +17,7 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/geoNear/#minimum-distance} */ function test1() { - type places = { - name: string; - location: { - type: string; - coordinates: Array; - }; - category: string; - }; - - const aggregation: schema.Pipeline = [ - { - $geoNear: { - near: { type: 'Point', coordinates: [-73.99279, 40.719296] }, - distanceField: 'dist.calculated', - minDistance: 2, - query: { category: 'Parks' }, - includeLocs: 'dist.location', - spherical: true, - }, - }, - ]; + // TODO: no schema found for geoNear.Minimum Distance } /** @@ -65,27 +25,7 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/geoNear/#-geonear-with-the-let-option} */ function test2() { - type places = { - name: string; - location: { - type: string; - coordinates: Array; - }; - category: string; - }; - - const aggregation: schema.Pipeline = [ - { - $geoNear: { - near: '$$pt', - distanceField: 'distance', - maxDistance: 2, - query: { category: 'Parks' }, - includeLocs: 'dist.location', - spherical: true, - }, - }, - ]; + // TODO: no schema found for geoNear.with the let option } /** @@ -93,26 +33,7 @@ function test2() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/geoNear/#-geonear-with-bound-let-option} */ function test3() { - type places = { - name: string; - location: { - type: string; - coordinates: Array; - }; - category: string; - }; - - const aggregation: schema.Pipeline = [ - { - $lookup: { - from: 'places', - let: { pt: '$location' }, - pipeline: [{ $geoNear: { near: '$$pt', distanceField: 'distance' } }], - as: 'joinedField', - }, - }, - { $match: { name: 'Sara D. Roosevelt Park' } }, - ]; + // TODO: no schema found for geoNear.with Bound let Option } /** @@ -120,26 +41,5 @@ function test3() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/geoNear/#specify-which-geospatial-index-to-use} */ function test4() { - type places = { - _id: number; - name: string; - location: { - type: string; - coordinates: Array; - }; - legacy: Array; - category: string; - }; - - const aggregation: schema.Pipeline = [ - { - $geoNear: { - near: { type: 'Point', coordinates: [-73.98142, 40.71782] }, - key: 'location', - distanceField: 'dist.calculated', - query: { category: 'Parks' }, - }, - }, - { $limit: 5 }, - ]; + // TODO: no schema found for geoNear.Specify Which Geospatial Index to Use } diff --git a/packages/mql-typescript/tests/stage/graphLookup.spec.ts b/packages/mql-typescript/tests/stage/graphLookup.spec.ts index 55db1c37..58570e92 100644 --- a/packages/mql-typescript/tests/stage/graphLookup.spec.ts +++ b/packages/mql-typescript/tests/stage/graphLookup.spec.ts @@ -9,23 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/graphLookup/#within-a-single-collection} */ function test0() { - type employees = { - _id: number; - name: string; - reportsTo: string; - }; - - const aggregation: schema.Pipeline = [ - { - $graphLookup: { - from: 'employees', - startWith: '$reportsTo', - connectFromField: 'reportsTo', - connectToField: 'name', - as: 'reportingHierarchy', - }, - }, - ]; + // TODO: no schema found for graphLookup.Within a Single Collection } /** @@ -33,25 +17,7 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/graphLookup/#across-multiple-collections} */ function test1() { - type airports = { - _id: number; - airport: string; - connects: Array; - }; - - const aggregation: schema.Pipeline = [ - { - $graphLookup: { - from: 'airports', - startWith: '$nearestAirport', - connectFromField: 'connects', - connectToField: 'airport', - maxDepth: 2, - depthField: 'numConnections', - as: 'destinations', - }, - }, - ]; + // TODO: no schema found for graphLookup.Across Multiple Collections } /** @@ -59,31 +25,5 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/graphLookup/#with-a-query-filter} */ function test2() { - type people = { - _id: number; - name: string; - friends: Array; - hobbies: Array; - }; - - const aggregation: schema.Pipeline = [ - { $match: { name: 'Tanya Jordan' } }, - { - $graphLookup: { - from: 'people', - startWith: '$friends', - connectFromField: 'friends', - connectToField: 'name', - as: 'golfers', - restrictSearchWithMatch: { hobbies: 'golf' }, - }, - }, - { - $project: { - name: 1, - friends: 1, - 'connections who play golf': '$golfers.name', - }, - }, - ]; + // TODO: no schema found for graphLookup.With a Query Filter } diff --git a/packages/mql-typescript/tests/stage/group.spec.ts b/packages/mql-typescript/tests/stage/group.spec.ts index 8bccbcc5..c5197f02 100644 --- a/packages/mql-typescript/tests/stage/group.spec.ts +++ b/packages/mql-typescript/tests/stage/group.spec.ts @@ -9,17 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/group/#count-the-number-of-documents-in-a-collection} */ function test0() { - type sales = { - _id: number; - item: string; - price: bson.Decimal128; - quantity: bson.Int32 | number; - date: Date; - }; - - const aggregation: schema.Pipeline = [ - { $group: { _id: null, count: { $count: {} } } }, - ]; + // TODO: no schema found for group.Count the Number of Documents in a Collection } /** @@ -27,15 +17,7 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/group/#retrieve-distinct-values} */ function test1() { - type sales = { - _id: number; - item: string; - price: bson.Decimal128; - quantity: bson.Int32 | number; - date: Date; - }; - - const aggregation: schema.Pipeline = [{ $group: { _id: '$item' } }]; + // TODO: no schema found for group.Retrieve Distinct Values } /** @@ -43,27 +25,7 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/group/#group-by-item-having} */ function test2() { - type sales = { - _id: number; - item: string; - price: bson.Decimal128; - quantity: bson.Int32 | number; - date: Date; - }; - - const aggregation: schema.Pipeline = [ - { - $group: { - _id: '$item', - totalSaleAmount: { $sum: { $multiply: ['$price', '$quantity'] } }, - }, - }, - - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' (it may involve a projected field). - */ - { $match: { totalSaleAmount: { $gte: 100 } } } as any, - ]; + // TODO: no schema found for group.Group by Item Having } /** @@ -71,33 +33,7 @@ function test2() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/group/#calculate-count--sum--and-average} */ function test3() { - type sales = { - _id: number; - item: string; - price: bson.Decimal128; - quantity: bson.Int32 | number; - date: Date; - }; - - const aggregation: schema.Pipeline = [ - { - $match: { - date: { - $gte: new Date('2014-01-01T00:00:00.000Z'), - $lt: new Date('2015-01-01T00:00:00.000Z'), - }, - }, - }, - { - $group: { - _id: { $dateToString: { format: '%Y-%m-%d', date: '$date' } }, - totalSaleAmount: { $sum: { $multiply: ['$price', '$quantity'] } }, - averageQuantity: { $avg: '$quantity' }, - count: { $sum: 1 }, - }, - }, - { $sort: { totalSaleAmount: -1 } }, - ]; + // TODO: no schema found for group.Calculate Count Sum and Average } /** @@ -105,24 +41,7 @@ function test3() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/group/#group-by-null} */ function test4() { - type sales = { - _id: number; - item: string; - price: bson.Decimal128; - quantity: bson.Int32 | number; - date: Date; - }; - - const aggregation: schema.Pipeline = [ - { - $group: { - _id: null, - totalSaleAmount: { $sum: { $multiply: ['$price', '$quantity'] } }, - averageQuantity: { $avg: '$quantity' }, - count: { $sum: 1 }, - }, - }, - ]; + // TODO: no schema found for group.Group by null } /** @@ -130,16 +49,7 @@ function test4() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/group/#pivot-data} */ function test5() { - type books = { - _id: number; - title: string; - author: string; - copies: number; - }; - - const aggregation: schema.Pipeline = [ - { $group: { _id: '$author', books: { $push: '$title' } } }, - ]; + // TODO: no schema found for group.Pivot Data } /** @@ -147,20 +57,5 @@ function test5() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/group/#group-documents-by-author} */ function test6() { - type sales = { - _id: number; - item: string; - price: bson.Decimal128; - quantity: bson.Int32 | number; - date: Date; - }; - - const aggregation: schema.Pipeline = [ - { $group: { _id: '$author', books: { $push: '$$ROOT' } } }, - - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' (it may involve a projected field). - */ - { $addFields: { totalCopies: { $sum: ['$books.copies'] } } } as any, - ]; + // TODO: no schema found for group.Group Documents by author } diff --git a/packages/mql-typescript/tests/stage/indexStats.spec.ts b/packages/mql-typescript/tests/stage/indexStats.spec.ts index c61d65c2..469b08e4 100644 --- a/packages/mql-typescript/tests/stage/indexStats.spec.ts +++ b/packages/mql-typescript/tests/stage/indexStats.spec.ts @@ -9,13 +9,5 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/indexStats/#example} */ function test0() { - type orders = { - _id: number; - item: string; - price: number; - quantity: number; - type: string; - }; - - const aggregation: schema.Pipeline = [{ $indexStats: {} }]; + // TODO: no schema found for indexStats.Example } diff --git a/packages/mql-typescript/tests/stage/limit.spec.ts b/packages/mql-typescript/tests/stage/limit.spec.ts index 91c1f15f..c538181b 100644 --- a/packages/mql-typescript/tests/stage/limit.spec.ts +++ b/packages/mql-typescript/tests/stage/limit.spec.ts @@ -9,9 +9,5 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/limit/#example} */ function test0() { - type TestCollection = { - _id: bson.ObjectId; - }; - - const aggregation: schema.Pipeline = [{ $limit: 5 }]; + // TODO: no schema found for limit.Example } diff --git a/packages/mql-typescript/tests/stage/listLocalSessions.spec.ts b/packages/mql-typescript/tests/stage/listLocalSessions.spec.ts index cd4c9736..cfa29d2d 100644 --- a/packages/mql-typescript/tests/stage/listLocalSessions.spec.ts +++ b/packages/mql-typescript/tests/stage/listLocalSessions.spec.ts @@ -9,13 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/listLocalSessions/#list-all-local-sessions} */ function test0() { - type TestCollection = { - _id: bson.ObjectId; - }; - - const aggregation: schema.Pipeline = [ - { $listLocalSessions: { allUsers: true } }, - ]; + // TODO: no schema found for listLocalSessions.List All Local Sessions } /** @@ -23,13 +17,7 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/listLocalSessions/#list-all-local-sessions-for-the-specified-users} */ function test1() { - type TestCollection = { - _id: bson.ObjectId; - }; - - const aggregation: schema.Pipeline = [ - { $listLocalSessions: { users: [{ user: 'myAppReader', db: 'test' }] } }, - ]; + // TODO: no schema found for listLocalSessions.List All Local Sessions for the Specified Users } /** @@ -37,11 +25,5 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/listLocalSessions/#list-all-local-sessions-for-the-current-user} */ function test2() { - type TestCollection = { - _id: bson.ObjectId; - }; - - const aggregation: schema.Pipeline = [ - { $listLocalSessions: {} }, - ]; + // TODO: no schema found for listLocalSessions.List All Local Sessions for the Current User } diff --git a/packages/mql-typescript/tests/stage/listSampledQueries.spec.ts b/packages/mql-typescript/tests/stage/listSampledQueries.spec.ts index da8ddda6..75099972 100644 --- a/packages/mql-typescript/tests/stage/listSampledQueries.spec.ts +++ b/packages/mql-typescript/tests/stage/listSampledQueries.spec.ts @@ -9,13 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSampledQueries/#list-sampled-queries-for-all-collections} */ function test0() { - type TestCollection = { - _id: bson.ObjectId; - }; - - const aggregation: schema.Pipeline = [ - { $listSampledQueries: {} }, - ]; + // TODO: no schema found for listSampledQueries.List Sampled Queries for All Collections } /** @@ -23,11 +17,5 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSampledQueries/#list-sampled-queries-for-a-specific-collection} */ function test1() { - type TestCollection = { - _id: bson.ObjectId; - }; - - const aggregation: schema.Pipeline = [ - { $listSampledQueries: { namespace: 'social.post' } }, - ]; + // TODO: no schema found for listSampledQueries.List Sampled Queries for A Specific Collection } diff --git a/packages/mql-typescript/tests/stage/listSearchIndexes.spec.ts b/packages/mql-typescript/tests/stage/listSearchIndexes.spec.ts index 535fc125..c9200bf7 100644 --- a/packages/mql-typescript/tests/stage/listSearchIndexes.spec.ts +++ b/packages/mql-typescript/tests/stage/listSearchIndexes.spec.ts @@ -9,13 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSearchIndexes/#return-all-search-indexes} */ function test0() { - type TestCollection = { - _id: bson.ObjectId; - }; - - const aggregation: schema.Pipeline = [ - { $listSearchIndexes: {} }, - ]; + // TODO: no schema found for listSearchIndexes.Return All Search Indexes } /** @@ -23,13 +17,7 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSearchIndexes/#return-a-single-search-index-by-name} */ function test1() { - type TestCollection = { - _id: bson.ObjectId; - }; - - const aggregation: schema.Pipeline = [ - { $listSearchIndexes: { name: 'synonym-mappings' } }, - ]; + // TODO: no schema found for listSearchIndexes.Return a Single Search Index by Name } /** @@ -37,11 +25,5 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSearchIndexes/#return-a-single-search-index-by-id} */ function test2() { - type TestCollection = { - _id: bson.ObjectId; - }; - - const aggregation: schema.Pipeline = [ - { $listSearchIndexes: { id: '6524096020da840844a4c4a7' } }, - ]; + // TODO: no schema found for listSearchIndexes.Return a Single Search Index by id } diff --git a/packages/mql-typescript/tests/stage/listSessions.spec.ts b/packages/mql-typescript/tests/stage/listSessions.spec.ts index dd14b8f2..cebdaa6e 100644 --- a/packages/mql-typescript/tests/stage/listSessions.spec.ts +++ b/packages/mql-typescript/tests/stage/listSessions.spec.ts @@ -9,13 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSessions/#list-all-sessions} */ function test0() { - type TestCollection = { - _id: bson.ObjectId; - }; - - const aggregation: schema.Pipeline = [ - { $listSessions: { allUsers: true } }, - ]; + // TODO: no schema found for listSessions.List All Sessions } /** @@ -23,13 +17,7 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSessions/#list-all-sessions-for-the-specified-users} */ function test1() { - type TestCollection = { - _id: bson.ObjectId; - }; - - const aggregation: schema.Pipeline = [ - { $listSessions: { users: [{ user: 'myAppReader', db: 'test' }] } }, - ]; + // TODO: no schema found for listSessions.List All Sessions for the Specified Users } /** @@ -37,9 +25,5 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSessions/#list-all-sessions-for-the-current-user} */ function test2() { - type TestCollection = { - _id: bson.ObjectId; - }; - - const aggregation: schema.Pipeline = [{ $listSessions: {} }]; + // TODO: no schema found for listSessions.List All Sessions for the Current User } diff --git a/packages/mql-typescript/tests/stage/lookup.spec.ts b/packages/mql-typescript/tests/stage/lookup.spec.ts index 580ce1d2..341ead26 100644 --- a/packages/mql-typescript/tests/stage/lookup.spec.ts +++ b/packages/mql-typescript/tests/stage/lookup.spec.ts @@ -9,23 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/lookup/#perform-a-single-equality-join-with--lookup} */ function test0() { - type orders = { - _id: number; - item: string; - price: number; - quantity: number; - }; - - const aggregation: schema.Pipeline = [ - { - $lookup: { - from: 'inventory', - localField: 'item', - foreignField: 'sku', - as: 'inventory_docs', - }, - }, - ]; + // TODO: no schema found for lookup.Perform a Single Equality Join with $lookup } /** @@ -33,23 +17,7 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/lookup/#use--lookup-with-an-array} */ function test1() { - type classes = { - _id: number; - title: string; - enrollmentlist: Array; - days: Array; - }; - - const aggregation: schema.Pipeline = [ - { - $lookup: { - from: 'members', - localField: 'enrollmentlist', - foreignField: 'name', - as: 'enrollee_info', - }, - }, - ]; + // TODO: no schema found for lookup.Use $lookup with an Array } /** @@ -57,31 +25,7 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/lookup/#use--lookup-with--mergeobjects} */ function test2() { - type orders = { - _id: number; - item: string; - price: number; - quantity: number; - }; - - const aggregation: schema.Pipeline = [ - { - $lookup: { - from: 'items', - localField: 'item', - foreignField: 'item', - as: 'fromItems', - }, - }, - { - $replaceRoot: { - newRoot: { - $mergeObjects: [{ $arrayElemAt: ['$fromItems', 0] }, '$$ROOT'], - }, - }, - }, - { $project: { fromItems: 0 } }, - ]; + // TODO: no schema found for lookup.Use $lookup with $mergeObjects } /** @@ -89,7 +33,7 @@ function test2() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/lookup/#perform-multiple-joins-and-a-correlated-subquery-with--lookup} */ function test3() { - // TODO: no schema found for lookup.Perform Multiple Joins and a Correlated Subquery with $lookup: // TODO: No schema found in docs + // TODO: no schema found for lookup.Perform Multiple Joins and a Correlated Subquery with $lookup } /** @@ -97,25 +41,7 @@ function test3() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/lookup/#perform-an-uncorrelated-subquery-with--lookup} */ function test4() { - type absences = { - _id: number; - student: string; - sickdays: Array; - }; - - const aggregation: schema.Pipeline = [ - { - $lookup: { - from: 'holidays', - pipeline: [ - { $match: { year: 2018 } }, - { $project: { _id: 0, date: { name: '$name', date: '$date' } } }, - { $replaceRoot: { newRoot: '$date' } }, - ], - as: 'holidays', - }, - }, - ]; + // TODO: no schema found for lookup.Perform an Uncorrelated Subquery with $lookup } /** @@ -123,25 +49,5 @@ function test4() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/lookup/#perform-a-concise-correlated-subquery-with--lookup} */ function test5() { - type restaurants = { - _id: number; - name: string; - food: Array; - beverages: Array; - }; - - const aggregation: schema.Pipeline = [ - { - $lookup: { - from: 'restaurants', - localField: 'restaurant_name', - foreignField: 'name', - let: { orders_drink: '$drink' }, - pipeline: [ - { $match: { $expr: { $in: ['$$orders_drink', '$beverages'] } } }, - ], - as: 'matches', - }, - }, - ]; + // TODO: no schema found for lookup.Perform a Concise Correlated Subquery with $lookup } diff --git a/packages/mql-typescript/tests/stage/match.spec.ts b/packages/mql-typescript/tests/stage/match.spec.ts index 040f9ad4..29a079dc 100644 --- a/packages/mql-typescript/tests/stage/match.spec.ts +++ b/packages/mql-typescript/tests/stage/match.spec.ts @@ -9,16 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/match/#equality-match} */ function test0() { - type TestCollection = { - _id: bson.ObjectId; - author: string; - score: number; - views: number; - }; - - const aggregation: schema.Pipeline = [ - { $match: { author: 'dave' } }, - ]; + // TODO: no schema found for match.Equality Match } /** @@ -26,19 +17,5 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/match/#perform-a-count} */ function test1() { - type TestCollection = { - _id: bson.ObjectId; - author: string; - score: number; - views: number; - }; - - const aggregation: schema.Pipeline = [ - { - $match: { - $or: [{ score: { $gt: 70, $lt: 90 } }, { views: { $gte: 1000 } }], - }, - }, - { $group: { _id: null, count: { $sum: 1 } } }, - ]; + // TODO: no schema found for match.Perform a Count } diff --git a/packages/mql-typescript/tests/stage/merge.spec.ts b/packages/mql-typescript/tests/stage/merge.spec.ts index 4f2cea30..31829993 100644 --- a/packages/mql-typescript/tests/stage/merge.spec.ts +++ b/packages/mql-typescript/tests/stage/merge.spec.ts @@ -9,30 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/#on-demand-materialized-view--initial-creation} */ function test0() { - type salaries = { - _id: number; - employee: string; - dept: string; - salary: number; - fiscal_year: number; - }; - - const aggregation: schema.Pipeline = [ - { - $group: { - _id: { fiscal_year: '$fiscal_year', dept: '$dept' }, - salaries: { $sum: '$salary' }, - }, - }, - { - $merge: { - into: { db: 'reporting', coll: 'budgets' }, - on: '_id', - whenMatched: 'replace', - whenNotMatched: 'insert', - }, - }, - ]; + // TODO: no schema found for merge.On-Demand Materialized View Initial Creation } /** @@ -40,31 +17,7 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/#on-demand-materialized-view--update-replace-data} */ function test1() { - type salaries = { - _id: number; - employee: string; - dept: string; - salary: number; - fiscal_year: number; - }; - - const aggregation: schema.Pipeline = [ - { $match: { fiscal_year: { $gte: 2019 } } }, - { - $group: { - _id: { fiscal_year: '$fiscal_year', dept: '$dept' }, - salaries: { $sum: '$salary' }, - }, - }, - { - $merge: { - into: { db: 'reporting', coll: 'budgets' }, - on: '_id', - whenMatched: 'replace', - whenNotMatched: 'insert', - }, - }, - ]; + // TODO: no schema found for merge.On-Demand Materialized View Update Replace Data } /** @@ -72,38 +25,7 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/#only-insert-new-data} */ function test2() { - type salaries = { - _id: number; - employee: string; - dept: string; - salary: number; - fiscal_year: number; - }; - - const aggregation: schema.Pipeline = [ - { $match: { fiscal_year: 2019 } }, - { - $group: { - _id: { fiscal_year: '$fiscal_year', dept: '$dept' }, - employees: { $push: '$employee' }, - }, - }, - { - $project: { - _id: 0, - dept: '$_id.dept', - fiscal_year: '$_id.fiscal_year', - employees: 1, - }, - }, - { - $merge: { - into: { db: 'reporting', coll: 'orgArchive' }, - on: ['dept', 'fiscal_year'], - whenMatched: 'fail', - }, - }, - ]; + // TODO: no schema found for merge.Only Insert New Data } /** @@ -111,25 +33,7 @@ function test2() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/#merge-results-from-multiple-collections} */ function test3() { - type purchaseorders = { - _id: number; - quarter: string; - region: string; - qty: number; - reportDate: Date; - }; - - const aggregation: schema.Pipeline = [ - { $group: { _id: '$quarter', purchased: { $sum: '$qty' } } }, - { - $merge: { - into: 'quarterlyreport', - on: '_id', - whenMatched: 'merge', - whenNotMatched: 'insert', - }, - }, - ]; + // TODO: no schema found for merge.Merge Results from Multiple Collections } /** @@ -137,44 +41,7 @@ function test3() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/#use-the-pipeline-to-customize-the-merge} */ function test4() { - type votes = { - date: Date; - thumbsup: number; - thumbsdown: number; - }; - - const aggregation: schema.Pipeline = [ - { - $match: { - date: { - $gte: new Date('2019-05-07T00:00:00.000Z'), - $lt: new Date('2019-05-08T00:00:00.000Z'), - }, - }, - }, - { - $project: { - _id: { $dateToString: { format: '%Y-%m', date: '$date' } }, - thumbsup: 1, - thumbsdown: 1, - }, - }, - { - $merge: { - into: 'monthlytotals', - on: '_id', - whenMatched: [ - { - $addFields: { - thumbsup: { $add: ['$thumbsup', '$$new.thumbsup'] }, - thumbsdown: { $add: ['$thumbsdown', '$$new.thumbsdown'] }, - }, - }, - ], - whenNotMatched: 'insert', - }, - }, - ]; + // TODO: no schema found for merge.Use the Pipeline to Customize the Merge } /** @@ -182,21 +49,5 @@ function test4() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/#use-variables-to-customize-the-merge} */ function test5() { - type salaries = { - _id: number; - employee: string; - dept: string; - salary: number; - fiscal_year: number; - }; - - const aggregation: schema.Pipeline = [ - { - $merge: { - into: 'cakeSales', - let: { year: '2020' }, - whenMatched: [{ $addFields: { salesYear: '$$year' } }], - }, - }, - ]; + // TODO: no schema found for merge.Use Variables to Customize the Merge } diff --git a/packages/mql-typescript/tests/stage/out.spec.ts b/packages/mql-typescript/tests/stage/out.spec.ts index 842dac45..a8886710 100644 --- a/packages/mql-typescript/tests/stage/out.spec.ts +++ b/packages/mql-typescript/tests/stage/out.spec.ts @@ -9,17 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/out/#output-to-same-database} */ function test0() { - type books = { - _id: number; - title: string; - author: string; - copies: number; - }; - - const aggregation: schema.Pipeline = [ - { $group: { _id: '$author', books: { $push: '$title' } } }, - { $out: 'authors' }, - ]; + // TODO: no schema found for out.Output to Same Database } /** @@ -27,15 +17,31 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/out/#output-to-a-different-database} */ function test1() { - type books = { - _id: number; - title: string; - author: string; - copies: number; + // TODO: no schema found for out.Output to a Different Database +} + +/** + * Output to a Time Series Collection + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/out/#output-to-a-time-series-collection} + */ +function test2() { + type sensors = { + timestamp: Date; + sensorId: string; + temperature: number; }; - const aggregation: schema.Pipeline = [ - { $group: { _id: '$author', books: { $push: '$title' } } }, - { $out: { db: 'reporting', coll: 'authors' } }, + const aggregation: schema.Pipeline = [ + { + $out: { + db: 'reporting', + coll: 'sensorData', + timeseries: { + timeField: 'timestamp', + metaField: 'sensorId', + granularity: 'hours', + }, + }, + }, ]; } diff --git a/packages/mql-typescript/tests/stage/planCacheStats.spec.ts b/packages/mql-typescript/tests/stage/planCacheStats.spec.ts index 65a247c4..3173e5ae 100644 --- a/packages/mql-typescript/tests/stage/planCacheStats.spec.ts +++ b/packages/mql-typescript/tests/stage/planCacheStats.spec.ts @@ -9,15 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/planCacheStats/#return-information-for-all-entries-in-the-query-cache} */ function test0() { - type orders = { - _id: number; - item: string; - price: bson.Decimal128; - quantity: number; - type: string; - }; - - const aggregation: schema.Pipeline = [{ $planCacheStats: {} }]; + // TODO: no schema found for planCacheStats.Return Information for All Entries in the Query Cache } /** @@ -25,20 +17,5 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/planCacheStats/#find-cache-entry-details-for-a-query-hash} */ function test1() { - type orders = { - _id: number; - item: string; - price: bson.Decimal128; - quantity: number; - type: string; - }; - - const aggregation: schema.Pipeline = [ - { $planCacheStats: {} }, - - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' ($planCacheStats emits new fields that are not available statically). - */ - { $match: { planCacheKey: 'B1435201' } } as any, - ]; + // TODO: no schema found for planCacheStats.Find Cache Entry Details for a Query Hash } diff --git a/packages/mql-typescript/tests/stage/project.spec.ts b/packages/mql-typescript/tests/stage/project.spec.ts index 4ca4b905..9122990c 100644 --- a/packages/mql-typescript/tests/stage/project.spec.ts +++ b/packages/mql-typescript/tests/stage/project.spec.ts @@ -9,20 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/project/#include-specific-fields-in-output-documents} */ function test0() { - type books = { - _id: number; - title: string; - isbn: string; - author: { - last: string; - first: string; - }; - copies: number; - }; - - const aggregation: schema.Pipeline = [ - { $project: { title: 1, author: 1 } }, - ]; + // TODO: no schema found for project.Include Specific Fields in Output Documents } /** @@ -30,20 +17,7 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/project/#suppress-_id-field-in-the-output-documents} */ function test1() { - type books = { - _id: number; - title: string; - isbn: string; - author: { - last: string; - first: string; - }; - copies: number; - }; - - const aggregation: schema.Pipeline = [ - { $project: { _id: 0, title: 1, author: 1 } }, - ]; + // TODO: no schema found for project.Suppress id Field in the Output Documents } /** @@ -51,21 +25,7 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/project/#exclude-fields-from-output-documents} */ function test2() { - type books = { - _id: number; - title: string; - isbn: string; - author: { - last: string; - first: string; - }; - copies: number; - lastModified: string; - }; - - const aggregation: schema.Pipeline = [ - { $project: { lastModified: 0 } }, - ]; + // TODO: no schema found for project.Exclude Fields from Output Documents } /** @@ -73,22 +33,7 @@ function test2() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/project/#exclude-fields-from-embedded-documents} */ function test3() { - type books = { - _id: number; - title: string; - isbn: string; - author: { - last: string; - first: string; - }; - copies: number; - lastModified: string; - }; - - const aggregation: schema.Pipeline = [ - { $project: { 'author.first': 0, lastModified: 0 } }, - { $project: { author: { first: 0 }, lastModified: 0 } }, - ]; + // TODO: no schema found for project.Exclude Fields from Embedded Documents } /** @@ -96,35 +41,7 @@ function test3() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/project/#conditionally-exclude-fields} */ function test4() { - type books = { - _id: number; - title: string; - isbn: string; - author: { - last: string; - first: string; - middle: string; - }; - copies: number; - lastModified: string; - }; - - const aggregation: schema.Pipeline = [ - { - $project: { - title: 1, - 'author.first': 1, - 'author.last': 1, - 'author.middle': { - $cond: { - if: { $eq: ['', '$author.middle'] }, - then: '$$REMOVE', - else: '$author.middle', - }, - }, - }, - }, - ]; + // TODO: no schema found for project.Conditionally Exclude Fields } /** @@ -132,26 +49,7 @@ function test4() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/project/#include-specific-fields-from-embedded-documents} */ function test5() { - type bookmarks = { - _id: number; - user: string; - stop: - | { - title: string; - author: string; - page: number; - } - | Array<{ - title: string; - author: string; - page: number; - }>; - }; - - const aggregation: schema.Pipeline = [ - { $project: { 'stop.title': 1 } }, - { $project: { stop: { title: 1 } } }, - ]; + // TODO: no schema found for project.Include Specific Fields from Embedded Documents } /** @@ -159,33 +57,7 @@ function test5() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/project/#include-computed-fields} */ function test6() { - type books = { - _id: number; - title: string; - isbn: string; - author: { - last: string; - first: string; - }; - copies: number; - }; - - const aggregation: schema.Pipeline = [ - { - $project: { - title: 1, - isbn: { - prefix: { $substr: ['$isbn', 0, 3] }, - group: { $substr: ['$isbn', 3, 2] }, - publisher: { $substr: ['$isbn', 5, 4] }, - title: { $substr: ['$isbn', 9, 3] }, - checkDigit: { $substr: ['$isbn', 12, 1] }, - }, - lastName: '$author.last', - copiesSold: '$copies', - }, - }, - ]; + // TODO: no schema found for project.Include Computed Fields } /** @@ -193,13 +65,5 @@ function test6() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/project/#project-new-array-fields} */ function test7() { - type TestCollection = { - _id: bson.ObjectId; - x: number; - y: number; - }; - - const aggregation: schema.Pipeline = [ - { $project: { myArray: ['$x', '$y'] } }, - ]; + // TODO: no schema found for project.Project New Array Fields } diff --git a/packages/mql-typescript/tests/stage/rankFusion.spec.ts b/packages/mql-typescript/tests/stage/rankFusion.spec.ts new file mode 100644 index 00000000..7b8b64ea --- /dev/null +++ b/packages/mql-typescript/tests/stage/rankFusion.spec.ts @@ -0,0 +1,13 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ +/* eslint-disable filename-rules/match */ +/* eslint-disable @typescript-eslint/consistent-type-imports */ +import type * as schema from '../../out/schema'; +import * as bson from 'bson'; + +/** + * Example + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/rankFusion/#examples} + */ +function test0() { + // TODO: no schema found for rankFusion.Example +} diff --git a/packages/mql-typescript/tests/stage/redact.spec.ts b/packages/mql-typescript/tests/stage/redact.spec.ts index 9f98954a..e13a9dde 100644 --- a/packages/mql-typescript/tests/stage/redact.spec.ts +++ b/packages/mql-typescript/tests/stage/redact.spec.ts @@ -9,37 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/redact/#evaluate-access-at-every-document-level} */ function test0() { - type forecasts = { - _id: number; - title: string; - tags: Array; - year: number; - subsections: Array<{ - subtitle: string; - tags: Array; - content: - | string - | { - text: string; - tags: Array; - }; - }>; - }; - - const aggregation: schema.Pipeline = [ - { $match: { year: 2014 } }, - { - $redact: { - $cond: { - if: { - $gt: [{ $size: { $setIntersection: ['$tags', ['STLW', 'G']] } }, 0], - }, - then: '$$DESCEND', - else: '$$PRUNE', - }, - }, - }, - ]; + // TODO: no schema found for redact.Evaluate Access at Every Document Level } /** @@ -47,39 +17,5 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/redact/#exclude-all-fields-at-a-given-level} */ function test1() { - type accounts = { - _id: number; - level: number; - acct_id: string; - cc: { - level: number; - type: string; - num: number; - exp_date: Date; - billing_addr: { - level: number; - addr1: string; - city: string; - }; - shipping_addr: Array<{ - level: number; - addr1: string; - city: string; - }>; - }; - status: string; - }; - - const aggregation: schema.Pipeline = [ - { $match: { status: 'A' } }, - { - $redact: { - $cond: { - if: { $eq: ['$level', 5] }, - then: '$$PRUNE', - else: '$$DESCEND', - }, - }, - }, - ]; + // TODO: no schema found for redact.Exclude All Fields at a Given Level } diff --git a/packages/mql-typescript/tests/stage/replaceRoot.spec.ts b/packages/mql-typescript/tests/stage/replaceRoot.spec.ts index e4d1308e..75808db3 100644 --- a/packages/mql-typescript/tests/stage/replaceRoot.spec.ts +++ b/packages/mql-typescript/tests/stage/replaceRoot.spec.ts @@ -9,26 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceRoot/#-replaceroot-with-an-embedded-document-field} */ function test0() { - type TestCollection = { - _id: number; - name: string; - age: number; - pets: { - dogs: number; - cats: number; - fish: number; - }; - }; - - const aggregation: schema.Pipeline = [ - { - $replaceRoot: { - newRoot: { - $mergeObjects: [{ dogs: 0, cats: 0, birds: 0, fish: 0 }, '$pets'], - }, - }, - }, - ]; + // TODO: no schema found for replaceRoot.with an Embedded Document Field } /** @@ -36,29 +17,7 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceRoot/#-replaceroot-with-a-document-nested-in-an-array} */ function test1() { - type students = { - _id: number; - grades: Array<{ - test: number; - grade: number; - mean: number; - std: number; - }>; - }; - - const aggregation: schema.Pipeline = [ - { $unwind: { path: '$grades' } }, - - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). - */ - { $match: { 'grades.grade': { $gte: 90 } } } as any, - - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). - */ - { $replaceRoot: { newRoot: '$grades' } } as any, - ]; + // TODO: no schema found for replaceRoot.with a Document Nested in an Array } /** @@ -66,20 +25,7 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceRoot/#-replaceroot-with-a-newly-created-document} */ function test2() { - type TestCollection = { - _id: number; - first_name: string; - last_name: string; - city: string; - }; - - const aggregation: schema.Pipeline = [ - { - $replaceRoot: { - newRoot: { full_name: { $concat: ['$first_name', ' ', '$last_name'] } }, - }, - }, - ]; + // TODO: no schema found for replaceRoot.with a newly created document } /** @@ -87,24 +33,5 @@ function test2() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceRoot/#-replaceroot-with-a-new-document-created-from---root-and-a-default-document} */ function test3() { - type contacts = { - _id: number; - name: string; - email: string; - cell: string; - home: string; - }; - - const aggregation: schema.Pipeline = [ - { - $replaceRoot: { - newRoot: { - $mergeObjects: [ - { _id: '', name: '', email: '', cell: '', home: '' }, - '$$ROOT', - ], - }, - }, - }, - ]; + // TODO: no schema found for replaceRoot.with a New Document Created from $$ROOT and a Default Document } diff --git a/packages/mql-typescript/tests/stage/replaceWith.spec.ts b/packages/mql-typescript/tests/stage/replaceWith.spec.ts index 6da06f72..93f00270 100644 --- a/packages/mql-typescript/tests/stage/replaceWith.spec.ts +++ b/packages/mql-typescript/tests/stage/replaceWith.spec.ts @@ -9,24 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceWith/#-replacewith-an-embedded-document-field} */ function test0() { - type people = { - _id: number; - name: string; - age: number; - pets: { - dogs: number; - cats: number; - fish: number; - }; - }; - - const aggregation: schema.Pipeline = [ - { - $replaceWith: { - $mergeObjects: [{ dogs: 0, cats: 0, birds: 0, fish: 0 }, '$pets'], - }, - }, - ]; + // TODO: no schema found for replaceWith.an Embedded Document Field } /** @@ -34,29 +17,7 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceWith/#-replacewith-a-document-nested-in-an-array} */ function test1() { - type students = { - _id: number; - grades: Array<{ - test: number; - grade: number; - mean: number; - std: number; - }>; - }; - - const aggregation: schema.Pipeline = [ - { $unwind: { path: '$grades' } }, - - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). - */ - { $match: { 'grades.grade': { $gte: 90 } } } as any, - - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). - */ - { $replaceWith: '$grades' } as any, - ]; + // TODO: no schema found for replaceWith.a Document Nested in an Array } /** @@ -64,27 +25,7 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceWith/#-replacewith-a-newly-created-document} */ function test2() { - type sales = { - _id: number; - item: string; - price: number; - quantity: number; - date: Date; - status: string; - }; - - const aggregation: schema.Pipeline = [ - { $match: { status: 'C' } }, - { - $replaceWith: { - _id: '$_id', - item: '$item', - amount: { $multiply: ['$price', '$quantity'] }, - status: 'Complete', - asofDate: '$$NOW', - }, - }, - ]; + // TODO: no schema found for replaceWith.a Newly Created Document } /** @@ -92,21 +33,5 @@ function test2() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceWith/#-replacewith-a-new-document-created-from---root-and-a-default-document} */ function test3() { - type contacts = { - _id: number; - name: string; - email: string; - cell: string; - }; - - const aggregation: schema.Pipeline = [ - { - $replaceWith: { - $mergeObjects: [ - { _id: '', name: '', email: '', cell: '', home: '' }, - '$$ROOT', - ], - }, - }, - ]; + // TODO: no schema found for replaceWith.a New Document Created from $$ROOT and a Default Document } diff --git a/packages/mql-typescript/tests/stage/rerank.spec.ts b/packages/mql-typescript/tests/stage/rerank.spec.ts new file mode 100644 index 00000000..84aad1c7 --- /dev/null +++ b/packages/mql-typescript/tests/stage/rerank.spec.ts @@ -0,0 +1,13 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ +/* eslint-disable filename-rules/match */ +/* eslint-disable @typescript-eslint/consistent-type-imports */ +import type * as schema from '../../out/schema'; +import * as bson from 'bson'; + +/** + * Example + * @see {@link https://www.mongodb.com/docs/vector-search/query/aggregation-stages/rerank/#examples} + */ +function test0() { + // TODO: no schema found for rerank.Example +} diff --git a/packages/mql-typescript/tests/stage/sample.spec.ts b/packages/mql-typescript/tests/stage/sample.spec.ts index bfe00b5a..f9f2c19b 100644 --- a/packages/mql-typescript/tests/stage/sample.spec.ts +++ b/packages/mql-typescript/tests/stage/sample.spec.ts @@ -6,15 +6,8 @@ import * as bson from 'bson'; /** * Example - * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/sample/#examples} + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/sample/#example} */ function test0() { - type users = { - _id: number; - name: string; - q1: boolean; - q2: boolean; - }; - - const aggregation: schema.Pipeline = [{ $sample: { size: 3 } }]; + // TODO: no schema found for sample.Example } diff --git a/packages/mql-typescript/tests/stage/score.spec.ts b/packages/mql-typescript/tests/stage/score.spec.ts new file mode 100644 index 00000000..cf64c514 --- /dev/null +++ b/packages/mql-typescript/tests/stage/score.spec.ts @@ -0,0 +1,19 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ +/* eslint-disable filename-rules/match */ +/* eslint-disable @typescript-eslint/consistent-type-imports */ +import type * as schema from '../../out/schema'; +import * as bson from 'bson'; + +/** + * Example + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/score/} + */ +function test0() { + type movies = { + plot_embedding: Array; + }; + + const aggregation: schema.Pipeline = [ + { $score: { score: { $meta: 'vectorSearchScore' } } }, + ]; +} diff --git a/packages/mql-typescript/tests/stage/scoreFusion.spec.ts b/packages/mql-typescript/tests/stage/scoreFusion.spec.ts new file mode 100644 index 00000000..e25c9951 --- /dev/null +++ b/packages/mql-typescript/tests/stage/scoreFusion.spec.ts @@ -0,0 +1,13 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ +/* eslint-disable filename-rules/match */ +/* eslint-disable @typescript-eslint/consistent-type-imports */ +import type * as schema from '../../out/schema'; +import * as bson from 'bson'; + +/** + * Example + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/scoreFusion/#examples} + */ +function test0() { + // TODO: no schema found for scoreFusion.Example +} diff --git a/packages/mql-typescript/tests/stage/search.spec.ts b/packages/mql-typescript/tests/stage/search.spec.ts index 000b14b4..114208f4 100644 --- a/packages/mql-typescript/tests/stage/search.spec.ts +++ b/packages/mql-typescript/tests/stage/search.spec.ts @@ -6,88 +6,10 @@ import * as bson from 'bson'; /** * Example - * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/aggregation-stages/search/#aggregation-variable} + * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/query-syntax/#aggregation-variable} */ function test0() { - type movies = { - _id: { - $oid: string; - }; - title: string; - year: { - $numberInt: string; - }; - runtime: { - $numberInt: string; - }; - released: { - $date: { - $numberLong: string; - }; - }; - poster: string; - plot: string; - fullplot: string; - lastupdated: string; - type: string; - directors: Array; - imdb: { - rating: { - $numberDouble: string; - }; - votes: { - $numberInt: string; - }; - id: { - $numberInt: string; - }; - }; - cast: Array; - countries: Array; - genres: Array; - tomatoes: { - viewer: { - rating: { - $numberDouble: string; - }; - numReviews: { - $numberInt: string; - }; - }; - lastUpdated: { - $date: { - $numberLong: string; - }; - }; - }; - num_mflix_comments: { - $numberInt: string; - }; - }; - - const aggregation: schema.Pipeline = [ - { - $search: { - near: { - path: 'released', - origin: new Date('2011-09-01T00:00:00.000Z'), - pivot: 7776000000, - }, - }, - }, - { $project: { _id: 0, title: 1, released: 1 } }, - { $limit: 5 }, - - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' ($search emits new fields that are not available statically, such as $$SEARCH_META). - */ - { - $facet: { - docs: [], - meta: [{ $replaceWith: '$$SEARCH_META' }, { $limit: 1 }], - }, - } as any, - ]; + // TODO: no schema found for search.Example } /** @@ -95,76 +17,7 @@ function test0() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/sort/#date-search-and-sort} */ function test1() { - type movies = { - _id: { - $oid: string; - }; - title: string; - year: { - $numberInt: string; - }; - runtime: { - $numberInt: string; - }; - released: { - $date: { - $numberLong: string; - }; - }; - poster: string; - plot: string; - fullplot: string; - lastupdated: string; - type: string; - directors: Array; - imdb: { - rating: { - $numberDouble: string; - }; - votes: { - $numberInt: string; - }; - id: { - $numberInt: string; - }; - }; - cast: Array; - countries: Array; - genres: Array; - tomatoes: { - viewer: { - rating: { - $numberDouble: string; - }; - numReviews: { - $numberInt: string; - }; - }; - lastUpdated: { - $date: { - $numberLong: string; - }; - }; - }; - num_mflix_comments: { - $numberInt: string; - }; - }; - - const aggregation: schema.Pipeline = [ - { - $search: { - range: { - path: 'released', - gt: new Date('2010-01-01T00:00:00.000Z'), - lt: new Date('2015-01-01T00:00:00.000Z'), - }, - sort: { released: -1 }, - }, - }, - { $limit: 5 }, - { $project: { _id: 0, title: 1, released: 1 } }, - ]; + // TODO: no schema found for search.Date Search and Sort } /** @@ -172,83 +25,7 @@ function test1() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/sort/#number-search-and-sort} */ function test2() { - type movies = { - _id: { - $oid: string; - }; - title: string; - year: { - $numberInt: string; - }; - runtime: { - $numberInt: string; - }; - released: { - $date: { - $numberLong: string; - }; - }; - poster: string; - plot: string; - fullplot: string; - lastupdated: string; - type: string; - directors: Array; - imdb: { - rating: { - $numberDouble: string; - }; - votes: { - $numberInt: string; - }; - id: { - $numberInt: string; - }; - }; - cast: Array; - countries: Array; - genres: Array; - tomatoes: { - viewer: { - rating: { - $numberDouble: string; - }; - numReviews: { - $numberInt: string; - }; - }; - lastUpdated: { - $date: { - $numberLong: string; - }; - }; - }; - num_mflix_comments: { - $numberInt: string; - }; - }; - - const aggregation: schema.Pipeline = [ - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). - */ - { - $search: { - range: { path: 'awards.wins', gt: 3 }, - sort: { 'awards.wins': -1 }, - }, - } as any, - - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). - */ - { $limit: 5 } as any, - - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). - */ - { $project: { _id: 0, title: 1, 'awards.wins': 1 } } as any, - ]; + // TODO: no schema found for search.Number Search and Sort } /** @@ -256,72 +33,7 @@ function test2() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/sort/#sort-by-score} */ function test3() { - type movies = { - _id: { - $oid: string; - }; - title: string; - year: { - $numberInt: string; - }; - runtime: { - $numberInt: string; - }; - released: { - $date: { - $numberLong: string; - }; - }; - poster: string; - plot: string; - fullplot: string; - lastupdated: string; - type: string; - directors: Array; - imdb: { - rating: { - $numberDouble: string; - }; - votes: { - $numberInt: string; - }; - id: { - $numberInt: string; - }; - }; - cast: Array; - countries: Array; - genres: Array; - tomatoes: { - viewer: { - rating: { - $numberDouble: string; - }; - numReviews: { - $numberInt: string; - }; - }; - lastUpdated: { - $date: { - $numberLong: string; - }; - }; - }; - num_mflix_comments: { - $numberInt: string; - }; - }; - - const aggregation: schema.Pipeline = [ - { - $search: { - text: { path: 'title', query: 'story' }, - sort: { score: { $meta: 'searchScore', order: 1 } }, - }, - }, - { $limit: 5 }, - { $project: { _id: 0, title: 1, score: { $meta: 'searchScore' } } }, - ]; + // TODO: no schema found for search.Sort by score } /** @@ -329,71 +41,7 @@ function test3() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/paginate-results/#search-after-the-reference-point} */ function test4() { - type movies = { - _id: { - $oid: string; - }; - title: string; - year: { - $numberInt: string; - }; - runtime: { - $numberInt: string; - }; - released: { - $date: { - $numberLong: string; - }; - }; - poster: string; - plot: string; - fullplot: string; - lastupdated: string; - type: string; - directors: Array; - imdb: { - rating: { - $numberDouble: string; - }; - votes: { - $numberInt: string; - }; - id: { - $numberInt: string; - }; - }; - cast: Array; - countries: Array; - genres: Array; - tomatoes: { - viewer: { - rating: { - $numberDouble: string; - }; - numReviews: { - $numberInt: string; - }; - }; - lastUpdated: { - $date: { - $numberLong: string; - }; - }; - }; - num_mflix_comments: { - $numberInt: string; - }; - }; - - const aggregation: schema.Pipeline = [ - { - $search: { - text: { path: 'title', query: 'war' }, - sort: { score: { $meta: 'searchScore' }, released: 1 }, - searchAfter: 'CMtJGgYQuq+ngwgaCSkAjBYH7AAAAA==', - }, - }, - ]; + // TODO: no schema found for search.Paginate results after a token } /** @@ -401,71 +49,7 @@ function test4() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/paginate-results/#search-before-the-reference-point} */ function test5() { - type movies = { - _id: { - $oid: string; - }; - title: string; - year: { - $numberInt: string; - }; - runtime: { - $numberInt: string; - }; - released: { - $date: { - $numberLong: string; - }; - }; - poster: string; - plot: string; - fullplot: string; - lastupdated: string; - type: string; - directors: Array; - imdb: { - rating: { - $numberDouble: string; - }; - votes: { - $numberInt: string; - }; - id: { - $numberInt: string; - }; - }; - cast: Array; - countries: Array; - genres: Array; - tomatoes: { - viewer: { - rating: { - $numberDouble: string; - }; - numReviews: { - $numberInt: string; - }; - }; - lastUpdated: { - $date: { - $numberLong: string; - }; - }; - }; - num_mflix_comments: { - $numberInt: string; - }; - }; - - const aggregation: schema.Pipeline = [ - { - $search: { - text: { path: 'title', query: 'war' }, - sort: { score: { $meta: 'searchScore' }, released: 1 }, - searchBefore: 'CJ6kARoGELqvp4MIGgkpACDA3U8BAAA=', - }, - }, - ]; + // TODO: no schema found for search.Paginate results before a token } /** @@ -473,76 +57,7 @@ function test5() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/counting/#count-results} */ function test6() { - type movies = { - _id: { - $oid: string; - }; - title: string; - year: { - $numberInt: string; - }; - runtime: { - $numberInt: string; - }; - released: { - $date: { - $numberLong: string; - }; - }; - poster: string; - plot: string; - fullplot: string; - lastupdated: string; - type: string; - directors: Array; - imdb: { - rating: { - $numberDouble: string; - }; - votes: { - $numberInt: string; - }; - id: { - $numberInt: string; - }; - }; - cast: Array; - countries: Array; - genres: Array; - tomatoes: { - viewer: { - rating: { - $numberDouble: string; - }; - numReviews: { - $numberInt: string; - }; - }; - lastUpdated: { - $date: { - $numberLong: string; - }; - }; - }; - num_mflix_comments: { - $numberInt: string; - }; - }; - - const aggregation: schema.Pipeline = [ - { - $search: { - near: { - path: 'released', - origin: new Date('2011-09-01T00:00:00.000Z'), - pivot: 7776000000, - }, - count: { type: 'total' }, - }, - }, - { $project: { meta: '$$SEARCH_META', title: 1, released: 1 } }, - { $limit: 2 }, - ]; + // TODO: no schema found for search.Count results } /** @@ -550,72 +65,7 @@ function test6() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/tracking/#examples} */ function test7() { - type movies = { - _id: { - $oid: string; - }; - title: string; - year: { - $numberInt: string; - }; - runtime: { - $numberInt: string; - }; - released: { - $date: { - $numberLong: string; - }; - }; - poster: string; - plot: string; - fullplot: string; - lastupdated: string; - type: string; - directors: Array; - imdb: { - rating: { - $numberDouble: string; - }; - votes: { - $numberInt: string; - }; - id: { - $numberInt: string; - }; - }; - cast: Array; - countries: Array; - genres: Array; - tomatoes: { - viewer: { - rating: { - $numberDouble: string; - }; - numReviews: { - $numberInt: string; - }; - }; - lastUpdated: { - $date: { - $numberLong: string; - }; - }; - }; - num_mflix_comments: { - $numberInt: string; - }; - }; - - const aggregation: schema.Pipeline = [ - { - $search: { - text: { query: 'summer', path: 'title' }, - tracking: { searchTerms: 'summer' }, - }, - }, - { $limit: 5 }, - { $project: { _id: 0, title: 1 } }, - ]; + // TODO: no schema found for search.Track Search terms } /** @@ -623,92 +73,5 @@ function test7() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/return-stored-source/#examples} */ function test8() { - type movies = { - _id: { - $oid: string; - }; - title: string; - year: { - $numberInt: string; - }; - runtime: { - $numberInt: string; - }; - released: { - $date: { - $numberLong: string; - }; - }; - poster: string; - plot: string; - fullplot: string; - lastupdated: string; - type: string; - directors: Array; - imdb: { - rating: { - $numberDouble: string; - }; - votes: { - $numberInt: string; - }; - id: { - $numberInt: string; - }; - }; - cast: Array; - countries: Array; - genres: Array; - tomatoes: { - viewer: { - rating: { - $numberDouble: string; - }; - numReviews: { - $numberInt: string; - }; - }; - lastUpdated: { - $date: { - $numberLong: string; - }; - }; - }; - num_mflix_comments: { - $numberInt: string; - }; - }; - - const aggregation: schema.Pipeline = [ - { - $search: { - text: { query: 'baseball', path: 'title' }, - returnStoredSource: true, - }, - }, - - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). - */ - { - $match: { - $or: [ - { 'imdb.rating': { $gt: 8.2 } }, - { 'imdb.votes': { $gte: 4500 } }, - ], - }, - } as any, - - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). - */ - { - $lookup: { - from: 'movies', - localField: '_id', - foreignField: '_id', - as: 'document', - }, - } as any, - ]; + // TODO: no schema found for search.Return Stored Source Fields } diff --git a/packages/mql-typescript/tests/stage/searchMeta.spec.ts b/packages/mql-typescript/tests/stage/searchMeta.spec.ts index cc3e598d..239e6c82 100644 --- a/packages/mql-typescript/tests/stage/searchMeta.spec.ts +++ b/packages/mql-typescript/tests/stage/searchMeta.spec.ts @@ -6,73 +6,10 @@ import * as bson from 'bson'; /** * Example - * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/aggregation-stages/searchMeta/#example} + * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/query-syntax/#example} */ function test0() { - type movies = { - _id: { - $oid: string; - }; - title: string; - year: { - $numberInt: string; - }; - runtime: { - $numberInt: string; - }; - released: { - $date: { - $numberLong: string; - }; - }; - poster: string; - plot: string; - fullplot: string; - lastupdated: string; - type: string; - directors: Array; - imdb: { - rating: { - $numberDouble: string; - }; - votes: { - $numberInt: string; - }; - id: { - $numberInt: string; - }; - }; - cast: Array; - countries: Array; - genres: Array; - tomatoes: { - viewer: { - rating: { - $numberDouble: string; - }; - numReviews: { - $numberInt: string; - }; - }; - lastUpdated: { - $date: { - $numberLong: string; - }; - }; - }; - num_mflix_comments: { - $numberInt: string; - }; - }; - - const aggregation: schema.Pipeline = [ - { - $searchMeta: { - range: { path: 'year', gte: 1998, lt: 1999 }, - count: { type: 'total' }, - }, - }, - ]; + // TODO: no schema found for searchMeta.Example } /** @@ -80,79 +17,7 @@ function test0() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/facet/#example-1} */ function test1() { - type movies = { - _id: { - $oid: string; - }; - title: string; - year: { - $numberInt: string; - }; - runtime: { - $numberInt: string; - }; - released: { - $date: { - $numberLong: string; - }; - }; - poster: string; - plot: string; - fullplot: string; - lastupdated: string; - type: string; - directors: Array; - imdb: { - rating: { - $numberDouble: string; - }; - votes: { - $numberInt: string; - }; - id: { - $numberInt: string; - }; - }; - cast: Array; - countries: Array; - genres: Array; - tomatoes: { - viewer: { - rating: { - $numberDouble: string; - }; - numReviews: { - $numberInt: string; - }; - }; - lastUpdated: { - $date: { - $numberLong: string; - }; - }; - }; - num_mflix_comments: { - $numberInt: string; - }; - }; - - const aggregation: schema.Pipeline = [ - { - $searchMeta: { - facet: { - operator: { range: { path: 'year', gte: 1980, lte: 2000 } }, - facets: { - yearFacet: { - type: 'number', - path: 'year', - boundaries: [1980, 1990, 2000], - default: 'other', - }, - }, - }, - }, - }, - ]; + // TODO: no schema found for searchMeta.Year Facet } /** @@ -160,90 +25,7 @@ function test1() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/facet/#example-2} */ function test2() { - type movies = { - _id: { - $oid: string; - }; - title: string; - year: { - $numberInt: string; - }; - runtime: { - $numberInt: string; - }; - released: { - $date: { - $numberLong: string; - }; - }; - poster: string; - plot: string; - fullplot: string; - lastupdated: string; - type: string; - directors: Array; - imdb: { - rating: { - $numberDouble: string; - }; - votes: { - $numberInt: string; - }; - id: { - $numberInt: string; - }; - }; - cast: Array; - countries: Array; - genres: Array; - tomatoes: { - viewer: { - rating: { - $numberDouble: string; - }; - numReviews: { - $numberInt: string; - }; - }; - lastUpdated: { - $date: { - $numberLong: string; - }; - }; - }; - num_mflix_comments: { - $numberInt: string; - }; - }; - - const aggregation: schema.Pipeline = [ - { - $searchMeta: { - facet: { - operator: { - range: { - path: 'released', - gte: new Date('2000-01-01T00:00:00.000Z'), - lte: new Date('2015-01-31T00:00:00.000Z'), - }, - }, - facets: { - yearFacet: { - type: 'date', - path: 'released', - boundaries: [ - new Date('2000-01-01T00:00:00.000Z'), - new Date('2005-01-01T00:00:00.000Z'), - new Date('2010-01-01T00:00:00.000Z'), - new Date('2015-01-01T00:00:00.000Z'), - ], - default: 'other', - }, - }, - }, - }, - }, - ]; + // TODO: no schema found for searchMeta.Date Facet } /** @@ -251,89 +33,7 @@ function test2() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/facet/#examples} */ function test3() { - type movies = { - _id: { - $oid: string; - }; - title: string; - year: { - $numberInt: string; - }; - runtime: { - $numberInt: string; - }; - released: { - $date: { - $numberLong: string; - }; - }; - poster: string; - plot: string; - fullplot: string; - lastupdated: string; - type: string; - directors: Array; - imdb: { - rating: { - $numberDouble: string; - }; - votes: { - $numberInt: string; - }; - id: { - $numberInt: string; - }; - }; - cast: Array; - countries: Array; - genres: Array; - tomatoes: { - viewer: { - rating: { - $numberDouble: string; - }; - numReviews: { - $numberInt: string; - }; - }; - lastUpdated: { - $date: { - $numberLong: string; - }; - }; - }; - num_mflix_comments: { - $numberInt: string; - }; - }; - - const aggregation: schema.Pipeline = [ - { - $searchMeta: { - facet: { - operator: { - range: { - path: 'released', - gte: new Date('2000-01-01T00:00:00.000Z'), - lte: new Date('2015-01-31T00:00:00.000Z'), - }, - }, - facets: { - directorsFacet: { - type: 'string', - path: 'directors', - numBuckets: 7, - }, - yearFacet: { - type: 'number', - path: 'year', - boundaries: [2000, 2005, 2010, 2015], - }, - }, - }, - }, - }, - ]; + // TODO: no schema found for searchMeta.Metadata Results } /** @@ -341,70 +41,5 @@ function test3() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/#bucket-results-through-facet-queries} */ function test4() { - type movies = { - _id: { - $oid: string; - }; - title: string; - year: { - $numberInt: string; - }; - runtime: { - $numberInt: string; - }; - released: { - $date: { - $numberLong: string; - }; - }; - poster: string; - plot: string; - fullplot: string; - lastupdated: string; - type: string; - directors: Array; - imdb: { - rating: { - $numberDouble: string; - }; - votes: { - $numberInt: string; - }; - id: { - $numberInt: string; - }; - }; - cast: Array; - countries: Array; - genres: Array; - tomatoes: { - viewer: { - rating: { - $numberDouble: string; - }; - numReviews: { - $numberInt: string; - }; - }; - lastUpdated: { - $date: { - $numberLong: string; - }; - }; - }; - num_mflix_comments: { - $numberInt: string; - }; - }; - - const aggregation: schema.Pipeline = [ - { - $searchMeta: { - facet: { - operator: { autocomplete: { path: 'title', query: 'Gravity' } }, - facets: { titleFacet: { type: 'string', path: 'title' } }, - }, - }, - }, - ]; + // TODO: no schema found for searchMeta.Autocomplete Bucket Results through Facet Queries } diff --git a/packages/mql-typescript/tests/stage/set.spec.ts b/packages/mql-typescript/tests/stage/set.spec.ts index 2f56605d..bf0f0564 100644 --- a/packages/mql-typescript/tests/stage/set.spec.ts +++ b/packages/mql-typescript/tests/stage/set.spec.ts @@ -9,31 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/set/#using-two--set-stages} */ function test0() { - type scores = { - _id: number; - student: string; - homework: Array; - quiz: Array; - extraCredit: number; - }; - - const aggregation: schema.Pipeline = [ - { - $set: { - totalHomework: { $sum: ['$homework'] }, - totalQuiz: { $sum: ['$quiz'] }, - }, - }, - - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' (second $set stage references fields created in the first). - */ - { - $set: { - totalScore: { $add: ['$totalHomework', '$totalQuiz', '$extraCredit'] }, - }, - } as any, - ]; + // TODO: no schema found for set.Using Two $set Stages } /** @@ -41,18 +17,7 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/set/#adding-fields-to-an-embedded-document} */ function test1() { - type vehicles = { - _id: number; - type: string; - specs: { - doors: number; - wheels: number; - }; - }; - - const aggregation: schema.Pipeline = [ - { $set: { 'specs.fuel_type': 'unleaded' } }, - ]; + // TODO: no schema found for set.Adding Fields to an Embedded Document } /** @@ -60,13 +25,7 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/set/#overwriting-an-existing-field} */ function test2() { - type animals = { - _id: number; - dogs: number; - cats: number; - }; - - const aggregation: schema.Pipeline = [{ $set: { cats: 20 } }]; + // TODO: no schema found for set.Overwriting an existing field } /** @@ -74,18 +33,7 @@ function test2() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/set/#add-element-to-an-array} */ function test3() { - type scores = { - _id: number; - student: string; - homework: Array; - quiz: Array; - extraCredit: number; - }; - - const aggregation: schema.Pipeline = [ - { $match: { _id: 1 } }, - { $set: { homework: { $concatArrays: ['$homework', [7]] } } }, - ]; + // TODO: no schema found for set.Add Element to an Array } /** @@ -93,15 +41,5 @@ function test3() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/set/#creating-a-new-field-with-existing-fields} */ function test4() { - type scores = { - _id: number; - student: string; - homework: Array; - quiz: Array; - extraCredit: number; - }; - - const aggregation: schema.Pipeline = [ - { $set: { quizAverage: { $avg: '$quiz' } } }, - ]; + // TODO: no schema found for set.Creating a New Field with Existing Fields } diff --git a/packages/mql-typescript/tests/stage/setWindowFields.spec.ts b/packages/mql-typescript/tests/stage/setWindowFields.spec.ts index 13584fc6..4ebfae73 100644 --- a/packages/mql-typescript/tests/stage/setWindowFields.spec.ts +++ b/packages/mql-typescript/tests/stage/setWindowFields.spec.ts @@ -9,29 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/setWindowFields/#use-documents-window-to-obtain-cumulative-quantity-for-each-state} */ function test0() { - type cakeSales = { - _id: number; - type: string; - orderDate: Date; - state: string; - price: number; - quantity: number; - }; - - const aggregation: schema.Pipeline = [ - { - $setWindowFields: { - partitionBy: '$state', - sortBy: { orderDate: 1 }, - output: { - cumulativeQuantityForState: { - $sum: '$quantity', - window: { documents: ['unbounded', 'current'] }, - }, - }, - }, - }, - ]; + // TODO: no schema found for setWindowFields.Use Documents Window to Obtain Cumulative Quantity for Each State } /** @@ -39,29 +17,7 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/setWindowFields/#use-documents-window-to-obtain-cumulative-quantity-for-each-year} */ function test1() { - type cakeSales = { - _id: number; - type: string; - orderDate: Date; - state: string; - price: number; - quantity: number; - }; - - const aggregation: schema.Pipeline = [ - { - $setWindowFields: { - partitionBy: { $year: { date: '$orderDate' } }, - sortBy: { orderDate: 1 }, - output: { - cumulativeQuantityForYear: { - $sum: '$quantity', - window: { documents: ['unbounded', 'current'] }, - }, - }, - }, - }, - ]; + // TODO: no schema found for setWindowFields.Use Documents Window to Obtain Cumulative Quantity for Each Year } /** @@ -69,29 +25,7 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/setWindowFields/#use-documents-window-to-obtain-moving-average-quantity-for-each-year} */ function test2() { - type cakeSales = { - _id: number; - type: string; - orderDate: Date; - state: string; - price: number; - quantity: number; - }; - - const aggregation: schema.Pipeline = [ - { - $setWindowFields: { - partitionBy: { $year: { date: '$orderDate' } }, - sortBy: { orderDate: 1 }, - output: { - averageQuantity: { - $avg: '$quantity', - window: { documents: [-1, 0] }, - }, - }, - }, - }, - ]; + // TODO: no schema found for setWindowFields.Use Documents Window to Obtain Moving Average Quantity for Each Year } /** @@ -99,33 +33,7 @@ function test2() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/setWindowFields/#use-documents-window-to-obtain-cumulative-and-maximum-quantity-for-each-year} */ function test3() { - type cakeSales = { - _id: number; - type: string; - orderDate: Date; - state: string; - price: number; - quantity: number; - }; - - const aggregation: schema.Pipeline = [ - { - $setWindowFields: { - partitionBy: { $year: { date: '$orderDate' } }, - sortBy: { orderDate: 1 }, - output: { - cumulativeQuantityForYear: { - $sum: '$quantity', - window: { documents: ['unbounded', 'current'] }, - }, - maximumQuantityForYear: { - $max: '$quantity', - window: { documents: ['unbounded', 'unbounded'] }, - }, - }, - }, - }, - ]; + // TODO: no schema found for setWindowFields.Use Documents Window to Obtain Cumulative and Maximum Quantity for Each Year } /** @@ -133,29 +41,7 @@ function test3() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/setWindowFields/#range-window-example} */ function test4() { - type cakeSales = { - _id: number; - type: string; - orderDate: Date; - state: string; - price: number; - quantity: number; - }; - - const aggregation: schema.Pipeline = [ - { - $setWindowFields: { - partitionBy: '$state', - sortBy: { price: 1 }, - output: { - quantityFromSimilarOrders: { - $sum: '$quantity', - window: { range: [-10, 10] }, - }, - }, - }, - }, - ]; + // TODO: no schema found for setWindowFields.Range Window Example } /** @@ -163,29 +49,7 @@ function test4() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/setWindowFields/#use-a-time-range-window-with-a-positive-upper-bound} */ function test5() { - type cakeSales = { - _id: number; - type: string; - orderDate: Date; - state: string; - price: number; - quantity: number; - }; - - const aggregation: schema.Pipeline = [ - { - $setWindowFields: { - partitionBy: '$state', - sortBy: { orderDate: 1 }, - output: { - recentOrders: { - $push: '$orderDate', - window: { range: ['unbounded', 10], unit: 'month' }, - }, - }, - }, - }, - ]; + // TODO: no schema found for setWindowFields.Use a Time Range Window with a Positive Upper Bound } /** @@ -193,27 +57,5 @@ function test5() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/setWindowFields/#use-a-time-range-window-with-a-negative-upper-bound} */ function test6() { - type cakeSales = { - _id: number; - type: string; - orderDate: Date; - state: string; - price: number; - quantity: number; - }; - - const aggregation: schema.Pipeline = [ - { - $setWindowFields: { - partitionBy: '$state', - sortBy: { orderDate: 1 }, - output: { - recentOrders: { - $push: '$orderDate', - window: { range: ['unbounded', -10], unit: 'month' }, - }, - }, - }, - }, - ]; + // TODO: no schema found for setWindowFields.Use a Time Range Window with a Negative Upper Bound } diff --git a/packages/mql-typescript/tests/stage/shardedDataDistribution.spec.ts b/packages/mql-typescript/tests/stage/shardedDataDistribution.spec.ts index 7f4d66ed..961d6f13 100644 --- a/packages/mql-typescript/tests/stage/shardedDataDistribution.spec.ts +++ b/packages/mql-typescript/tests/stage/shardedDataDistribution.spec.ts @@ -9,11 +9,5 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/shardedDataDistribution/#examples} */ function test0() { - type TestCollection = { - _id: bson.ObjectId; - }; - - const aggregation: schema.Pipeline = [ - { $shardedDataDistribution: {} }, - ]; + // TODO: no schema found for shardedDataDistribution.Example } diff --git a/packages/mql-typescript/tests/stage/skip.spec.ts b/packages/mql-typescript/tests/stage/skip.spec.ts index 12e7e5b5..939efc50 100644 --- a/packages/mql-typescript/tests/stage/skip.spec.ts +++ b/packages/mql-typescript/tests/stage/skip.spec.ts @@ -6,12 +6,8 @@ import * as bson from 'bson'; /** * Example - * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/skip/#examples} + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/skip/#example} */ function test0() { - type TestCollection = { - _id: bson.ObjectId; - }; - - const aggregation: schema.Pipeline = [{ $skip: 5 }]; + // TODO: no schema found for skip.Example } diff --git a/packages/mql-typescript/tests/stage/sort.spec.ts b/packages/mql-typescript/tests/stage/sort.spec.ts index 0744771d..6ca78ac9 100644 --- a/packages/mql-typescript/tests/stage/sort.spec.ts +++ b/packages/mql-typescript/tests/stage/sort.spec.ts @@ -9,15 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/sort/#ascending-descending-sort} */ function test0() { - type users = { - age: bson.Int32 | number; - posts: bson.Int32 | number; - name: string; - }; - - const aggregation: schema.Pipeline = [ - { $sort: { age: -1, posts: 1 } }, - ]; + // TODO: no schema found for sort.Ascending Descending Sort } /** @@ -25,14 +17,5 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/sort/#text-score-metadata-sort} */ function test1() { - type users = { - age: bson.Int32 | number; - posts: bson.Int32 | number; - name: string; - }; - - const aggregation: schema.Pipeline = [ - { $match: { $text: { $search: 'operating' } } }, - { $sort: { score: { $meta: 'textScore' }, posts: -1 } }, - ]; + // TODO: no schema found for sort.Text Score Metadata Sort } diff --git a/packages/mql-typescript/tests/stage/sortByCount.spec.ts b/packages/mql-typescript/tests/stage/sortByCount.spec.ts index d8fe9ac8..612c91e3 100644 --- a/packages/mql-typescript/tests/stage/sortByCount.spec.ts +++ b/packages/mql-typescript/tests/stage/sortByCount.spec.ts @@ -6,19 +6,8 @@ import * as bson from 'bson'; /** * Example - * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/sortByCount/#examples} + * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/sortByCount/#example} */ function test0() { - type exhibits = { - _id: number; - title: string; - artist: string; - year: number; - tags: Array; - }; - - const aggregation: schema.Pipeline = [ - { $unwind: { path: '$tags' } }, - { $sortByCount: '$tags' }, - ]; + // TODO: no schema found for sortByCount.Example } diff --git a/packages/mql-typescript/tests/stage/unionWith.spec.ts b/packages/mql-typescript/tests/stage/unionWith.spec.ts index 1a661717..204b7551 100644 --- a/packages/mql-typescript/tests/stage/unionWith.spec.ts +++ b/packages/mql-typescript/tests/stage/unionWith.spec.ts @@ -9,25 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/unionWith/#report-1--all-sales-by-year-and-stores-and-items} */ function test0() { - type sales_2017 = { - store: string; - item: string; - quantity: number; - }; - - const aggregation: schema.Pipeline = [ - { $set: { _id: '2017' } }, - { - $unionWith: { coll: 'sales_2018', pipeline: [{ $set: { _id: '2018' } }] }, - }, - { - $unionWith: { coll: 'sales_2019', pipeline: [{ $set: { _id: '2019' } }] }, - }, - { - $unionWith: { coll: 'sales_2020', pipeline: [{ $set: { _id: '2020' } }] }, - }, - { $sort: { _id: 1, store: 1, item: 1 } }, - ]; + // TODO: no schema found for unionWith.Report 1 All Sales by Year and Stores and Items } /** @@ -35,17 +17,5 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/unionWith/#report-2--aggregated-sales-by-items} */ function test1() { - type sales_2017 = { - store: string; - item: string; - quantity: number; - }; - - const aggregation: schema.Pipeline = [ - { $unionWith: { coll: 'sales_2018' } }, - { $unionWith: { coll: 'sales_2019' } }, - { $unionWith: { coll: 'sales_2020' } }, - { $group: { _id: '$item', total: { $sum: '$quantity' } } }, - { $sort: { total: -1 } }, - ]; + // TODO: no schema found for unionWith.Report 2 Aggregated Sales by Items } diff --git a/packages/mql-typescript/tests/stage/unset.spec.ts b/packages/mql-typescript/tests/stage/unset.spec.ts index 2ef5b245..cec47ee8 100644 --- a/packages/mql-typescript/tests/stage/unset.spec.ts +++ b/packages/mql-typescript/tests/stage/unset.spec.ts @@ -9,21 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/unset/#remove-a-single-field} */ function test0() { - type books = { - _id: number; - title: string; - isbn: string; - author: { - last: string; - first: string; - }; - copies: Array<{ - warehouse: string; - qty: number; - }>; - }; - - const aggregation: schema.Pipeline = [{ $unset: ['copies'] }]; + // TODO: no schema found for unset.Remove a Single Field } /** @@ -31,21 +17,7 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/unset/#remove-top-level-fields} */ function test1() { - type books = { - _id: number; - title: string; - isbn: string; - author: { - last: string; - first: string; - }; - copies: Array<{ - warehouse: string; - qty: number; - }>; - }; - - const aggregation: schema.Pipeline = [{ $unset: ['isbn', 'copies'] }]; + // TODO: no schema found for unset.Remove Top-Level Fields } /** @@ -53,24 +25,5 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/unset/#remove-embedded-fields} */ function test2() { - type books = { - _id: number; - title: string; - isbn: string; - author: { - last: string; - first: string; - }; - copies: Array<{ - warehouse: string; - qty: number; - }>; - }; - - const aggregation: schema.Pipeline = [ - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). - */ - { $unset: ['isbn', 'author.first', 'copies.warehouse'] } as any, - ]; + // TODO: no schema found for unset.Remove Embedded Fields } diff --git a/packages/mql-typescript/tests/stage/unwind.spec.ts b/packages/mql-typescript/tests/stage/unwind.spec.ts index b9781c68..9381ad21 100644 --- a/packages/mql-typescript/tests/stage/unwind.spec.ts +++ b/packages/mql-typescript/tests/stage/unwind.spec.ts @@ -9,15 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/unwind/#unwind-array} */ function test0() { - type inventory = { - _id: number; - item: string; - sizes: Array; - }; - - const aggregation: schema.Pipeline = [ - { $unwind: { path: '$sizes' } }, - ]; + // TODO: no schema found for unwind.Unwind Array } /** @@ -25,15 +17,7 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/unwind/#preservenullandemptyarrays} */ function test1() { - type inventory = { - _id: number; - item: string; - sizes: Array; - }; - - const aggregation: schema.Pipeline = [ - { $unwind: { path: '$sizes', preserveNullAndEmptyArrays: true } }, - ]; + // TODO: no schema found for unwind.preserveNullAndEmptyArrays } /** @@ -41,15 +25,7 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/unwind/#includearrayindex} */ function test2() { - type inventory = { - _id: number; - item: string; - sizes: Array; - }; - - const aggregation: schema.Pipeline = [ - { $unwind: { path: '$sizes', includeArrayIndex: 'arrayIndex' } }, - ]; + // TODO: no schema found for unwind.includeArrayIndex } /** @@ -57,18 +33,7 @@ function test2() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/unwind/#group-by-unwound-values} */ function test3() { - type inventory2 = { - _id: number; - item: string; - price: bson.Decimal128; - sizes: Array | string | null; - }; - - const aggregation: schema.Pipeline = [ - { $unwind: { path: '$sizes', preserveNullAndEmptyArrays: true } }, - { $group: { _id: '$sizes', averagePrice: { $avg: '$price' } } }, - { $sort: { averagePrice: -1 } }, - ]; + // TODO: no schema found for unwind.Group by Unwound Values } /** @@ -76,34 +41,5 @@ function test3() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/unwind/#unwind-embedded-arrays} */ function test4() { - type sales = { - _id: string; - items: Array<{ - name: string; - tags: Array; - price: bson.Decimal128; - quantity: bson.Int32 | number; - }>; - }; - - const aggregation: schema.Pipeline = [ - { $unwind: { path: '$items' } }, - - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). - */ - { $unwind: { path: '$items.tags' } } as any, - - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). - */ - { - $group: { - _id: '$items.tags', - totalSalesAmount: { - $sum: { $multiply: ['$items.price', '$items.quantity'] }, - }, - }, - } as any, - ]; + // TODO: no schema found for unwind.Unwind Embedded Arrays } diff --git a/packages/mql-typescript/tests/stage/vectorSearch.spec.ts b/packages/mql-typescript/tests/stage/vectorSearch.spec.ts index 1234c90c..c3119a7d 100644 --- a/packages/mql-typescript/tests/stage/vectorSearch.spec.ts +++ b/packages/mql-typescript/tests/stage/vectorSearch.spec.ts @@ -6,16 +6,16 @@ import * as bson from 'bson'; /** * ANN Basic - * @see {@link https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-stage/#ann-examples} + * @see {@link https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-stage/#examples} */ function test0() { - type TestCollection = { + type movies = { + plot_embedding: Array; plot: string; title: string; - score: number; }; - const aggregation: schema.Pipeline = [ + const aggregation: schema.Pipeline = [ { $vectorSearch: { index: 'vector_index', @@ -38,63 +38,14 @@ function test0() { /** * ANN Filter - * @see {@link https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-stage/#ann-examples} + * @see {@link https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-stage/#examples} */ function test1() { type movies = { - _id: { - $oid: string; - }; - title: string; - year: { - $numberInt: string; - }; - runtime: { - $numberInt: string; - }; - released: { - $date: { - $numberLong: string; - }; - }; - poster: string; + plot_embedding: Array; + year: bson.Int32 | number; plot: string; - fullplot: string; - lastupdated: string; - type: string; - directors: Array; - imdb: { - rating: { - $numberDouble: string; - }; - votes: { - $numberInt: string; - }; - id: { - $numberInt: string; - }; - }; - cast: Array; - countries: Array; - genres: Array; - tomatoes: { - viewer: { - rating: { - $numberDouble: string; - }; - numReviews: { - $numberInt: string; - }; - }; - lastUpdated: { - $date: { - $numberLong: string; - }; - }; - }; - num_mflix_comments: { - $numberInt: string; - }; + title: string; }; const aggregation: schema.Pipeline = [ @@ -122,16 +73,16 @@ function test1() { /** * ENN - * @see {@link https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-stage/#enn-example} + * @see {@link https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-stage/#examples} */ function test2() { - type TestCollection = { + type movies = { + plot_embedding: Array; plot: string; title: string; - score: number; }; - const aggregation: schema.Pipeline = [ + const aggregation: schema.Pipeline = [ { $vectorSearch: { index: 'vector_index', @@ -151,3 +102,56 @@ function test2() { }, ]; } + +/** + * Stored Source + * @see {@link https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-stage/#examples} + */ +function test3() { + type movies = { + plot_embedding: Array; + year: bson.Int32 | number; + genres: Array; + plot: string; + title: string; + }; + + const aggregation: schema.Pipeline = [ + { + $vectorSearch: { + index: 'vector_index', + path: 'plot_embedding', + queryVector: [ + -0.03994801267981529, -0.016522614285349846, -0.008775344118475914, + ], + filter: { + $and: [ + { year: { $gt: 1970 } }, + { year: { $lt: 2020 } }, + { genres: { $in: ['Action', 'Drama', 'Comedy'] } }, + ], + }, + limit: 10, + numCandidates: 1000, + returnStoredSource: true, + }, + }, + { + $project: { + _id: 0, + plot: 1, + title: 1, + genres: 1, + score: { $meta: 'vectorSearchScore' }, + }, + }, + ]; +} + +/** + * Nested field + * @see {@link https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-stage/#examples} + */ +function test4() { + // TODO: no schema found for vectorSearch.Nested field +} From 7fc28686674e944e70b4f6c07021255142a30eb9 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Tue, 30 Jun 2026 14:09:26 +0100 Subject: [PATCH 4/8] update tests using our script, avoid OOM --- packages/mql-typescript/mql-specifications | 2 +- .../src/driverSchema/docs-crawler.ts | 22 +- .../tests/accumulator/concatArrays.spec.ts | 9 +- .../tests/accumulator/minMaxScaler.spec.ts | 5 +- .../tests/accumulator/setUnion.spec.ts | 16 +- .../tests/expression/bottom.spec.ts | 24 +- .../tests/expression/bottomN.spec.ts | 25 +- .../tests/expression/concatArrays.spec.ts | 13 +- .../tests/expression/cond.spec.ts | 17 +- .../tests/expression/convert.spec.ts | 106 +-- .../tests/expression/createObjectId.spec.ts | 2 +- .../tests/expression/deserializeEJSON.spec.ts | 72 +- .../tests/expression/getField.spec.ts | 2 +- .../tests/expression/hash.spec.ts | 10 +- .../tests/expression/hexHash.spec.ts | 14 +- .../tests/expression/ifNull.spec.ts | 20 +- .../tests/expression/map.spec.ts | 59 +- .../tests/expression/max.spec.ts | 4 +- .../tests/expression/min.spec.ts | 4 +- .../tests/expression/replaceOne.spec.ts | 19 +- .../tests/expression/serializeEJSON.spec.ts | 144 +++- .../tests/expression/setField.spec.ts | 4 +- .../tests/expression/setUnion.spec.ts | 13 +- .../tests/expression/sigmoid.spec.ts | 9 +- .../tests/expression/subtype.spec.ts | 8 +- .../tests/expression/sum.spec.ts | 4 +- .../tests/expression/toArray.spec.ts | 1 - .../tests/expression/top.spec.ts | 24 +- .../tests/expression/topN.spec.ts | 25 +- .../tests/expression/type.spec.ts | 7 +- .../tests/expression/unsetField.spec.ts | 2 +- .../mql-typescript/tests/query/all.spec.ts | 39 +- .../mql-typescript/tests/query/and.spec.ts | 35 +- .../tests/query/bitsAllClear.spec.ts | 32 +- .../tests/query/bitsAllSet.spec.ts | 30 +- .../tests/query/bitsAnyClear.spec.ts | 32 +- .../tests/query/bitsAnySet.spec.ts | 30 +- .../tests/query/comment.spec.ts | 2 +- .../tests/query/elemMatch.spec.ts | 43 +- .../mql-typescript/tests/query/eq.spec.ts | 57 +- .../mql-typescript/tests/query/exists.spec.ts | 36 +- .../mql-typescript/tests/query/expr.spec.ts | 15 +- .../tests/query/geoIntersects.spec.ts | 66 +- .../tests/query/geoWithin.spec.ts | 66 +- .../mql-typescript/tests/query/gt.spec.ts | 12 +- .../mql-typescript/tests/query/gte.spec.ts | 12 +- .../mql-typescript/tests/query/in.spec.ts | 4 +- .../tests/query/jsonSchema.spec.ts | 34 +- .../mql-typescript/tests/query/lt.spec.ts | 12 +- .../mql-typescript/tests/query/lte.spec.ts | 12 +- .../mql-typescript/tests/query/mod.spec.ts | 22 +- .../mql-typescript/tests/query/ne.spec.ts | 2 +- .../mql-typescript/tests/query/near.spec.ts | 21 +- .../tests/query/nearSphere.spec.ts | 21 +- .../mql-typescript/tests/query/nin.spec.ts | 24 +- .../mql-typescript/tests/query/nor.spec.ts | 47 +- .../mql-typescript/tests/query/not.spec.ts | 24 +- .../mql-typescript/tests/query/or.spec.ts | 27 +- .../mql-typescript/tests/query/rand.spec.ts | 2 +- .../mql-typescript/tests/query/regex.spec.ts | 20 +- .../tests/query/sampleRate.spec.ts | 9 +- .../mql-typescript/tests/query/size.spec.ts | 12 +- .../mql-typescript/tests/query/text.spec.ts | 14 +- .../mql-typescript/tests/query/type.spec.ts | 69 +- .../mql-typescript/tests/query/where.spec.ts | 27 +- .../tests/search/autocomplete.spec.ts | 414 ++++++++++- .../tests/search/compound.spec.ts | 111 ++- .../tests/search/embeddedDocument.spec.ts | 273 +++++++- .../tests/search/equals.spec.ts | 162 ++++- .../tests/search/exists.spec.ts | 58 +- .../mql-typescript/tests/search/facet.spec.ts | 265 ++++++- .../tests/search/geoShape.spec.ts | 624 ++++++++++++++++- .../tests/search/geoWithin.spec.ts | 568 ++++++++++++++- .../tests/search/hasAncestor.spec.ts | 39 +- .../tests/search/hasRoot.spec.ts | 156 ++++- .../mql-typescript/tests/search/in.spec.ts | 111 ++- .../tests/search/moreLikeThis.spec.ts | 246 ++++++- .../mql-typescript/tests/search/near.spec.ts | 541 ++++++++++++++- .../tests/search/phrase.spec.ts | 258 ++++++- .../tests/search/queryString.spec.ts | 68 +- .../mql-typescript/tests/search/range.spec.ts | 332 ++++++++- .../mql-typescript/tests/search/regex.spec.ts | 61 +- .../mql-typescript/tests/search/text.spec.ts | 543 ++++++++++++++- .../tests/search/vectorSearch.spec.ts | 74 +- .../tests/search/wildcard.spec.ts | 124 +++- .../tests/stage/addFields.spec.ts | 8 +- .../mql-typescript/tests/stage/bucket.spec.ts | 75 +- .../tests/stage/bucketAuto.spec.ts | 17 +- .../tests/stage/changeStream.spec.ts | 6 +- .../stage/changeStreamSplitLargeEvent.spec.ts | 9 +- .../tests/stage/collStats.spec.ts | 32 +- .../mql-typescript/tests/stage/count.spec.ts | 2 +- .../tests/stage/currentOp.spec.ts | 26 +- .../tests/stage/densify.spec.ts | 27 +- .../tests/stage/documents.spec.ts | 33 +- .../mql-typescript/tests/stage/facet.spec.ts | 2 +- .../mql-typescript/tests/stage/fill.spec.ts | 69 +- .../tests/stage/geoNear.spec.ts | 110 ++- .../tests/stage/graphLookup.spec.ts | 66 +- .../mql-typescript/tests/stage/group.spec.ts | 78 ++- .../tests/stage/indexStats.spec.ts | 2 +- .../mql-typescript/tests/stage/limit.spec.ts | 6 +- .../tests/stage/listLocalSessions.spec.ts | 24 +- .../tests/stage/listSampledQueries.spec.ts | 16 +- .../tests/stage/listSearchIndexes.spec.ts | 24 +- .../tests/stage/listSessions.spec.ts | 22 +- .../mql-typescript/tests/stage/lookup.spec.ts | 128 +++- .../mql-typescript/tests/stage/match.spec.ts | 4 +- .../mql-typescript/tests/stage/merge.spec.ts | 12 +- .../mql-typescript/tests/stage/out.spec.ts | 44 +- .../tests/stage/planCacheStats.spec.ts | 27 +- .../tests/stage/project.spec.ts | 108 ++- .../tests/stage/rankFusion.spec.ts | 2 +- .../mql-typescript/tests/stage/redact.spec.ts | 68 +- .../tests/stage/replaceRoot.spec.ts | 81 ++- .../tests/stage/replaceWith.spec.ts | 83 ++- .../mql-typescript/tests/stage/rerank.spec.ts | 2 +- .../mql-typescript/tests/stage/sample.spec.ts | 2 +- .../mql-typescript/tests/stage/score.spec.ts | 8 +- .../tests/stage/scoreFusion.spec.ts | 2 +- .../mql-typescript/tests/stage/search.spec.ts | 655 +++++++++++++++++- .../tests/stage/searchMeta.spec.ts | 375 +++++++++- .../mql-typescript/tests/stage/set.spec.ts | 72 +- .../tests/stage/setWindowFields.spec.ts | 172 ++++- .../stage/shardedDataDistribution.spec.ts | 8 +- .../mql-typescript/tests/stage/skip.spec.ts | 6 +- .../mql-typescript/tests/stage/sort.spec.ts | 21 +- .../tests/stage/sortByCount.spec.ts | 2 +- .../tests/stage/unionWith.spec.ts | 34 +- .../mql-typescript/tests/stage/unset.spec.ts | 53 +- .../mql-typescript/tests/stage/unwind.spec.ts | 74 +- .../tests/stage/vectorSearch.spec.ts | 148 ++-- 132 files changed, 8592 insertions(+), 877 deletions(-) diff --git a/packages/mql-typescript/mql-specifications b/packages/mql-typescript/mql-specifications index 87057fa7..5b99b699 160000 --- a/packages/mql-typescript/mql-specifications +++ b/packages/mql-typescript/mql-specifications @@ -1 +1 @@ -Subproject commit 87057fa780ebf7170a7f9f6ff85ae0b76afedec6 +Subproject commit 5b99b6999de36e4b50ece576708426f4e762e36b diff --git a/packages/mql-typescript/src/driverSchema/docs-crawler.ts b/packages/mql-typescript/src/driverSchema/docs-crawler.ts index 20a8f83b..2854321a 100644 --- a/packages/mql-typescript/src/driverSchema/docs-crawler.ts +++ b/packages/mql-typescript/src/driverSchema/docs-crawler.ts @@ -14,24 +14,6 @@ export class DocsCrawler { private virtualConsole: VirtualConsole; - // Documentation pages are fetched once per page (ignoring the URL fragment), - // since a single operator page typically backs several tests that only differ - // by their anchor. - private static domCache = new Map>(); - - private fetchDom(): Promise { - const url = new URL(this.url); - url.hash = ''; - const cacheKey = url.toString(); - - let dom = DocsCrawler.domCache.get(cacheKey); - if (!dom) { - dom = JSDOM.fromURL(cacheKey, { virtualConsole: this.virtualConsole }); - DocsCrawler.domCache.set(cacheKey, dom); - } - return dom; - } - private fuzzyParse(json: string): unknown[] | undefined { // Sometimes the snippet will end with ellipsis instead of json json = json.replace(/\.\.\.$/g, ''); @@ -167,7 +149,9 @@ export class DocsCrawler { } try { - const dom = await this.fetchDom(); + const dom = await JSDOM.fromURL(this.url, { + virtualConsole: this.virtualConsole, + }); const exampleSection = dom.window.document .querySelector(`a[href='${fragment}']:not([target])`) ?.closest('section'); diff --git a/packages/mql-typescript/tests/accumulator/concatArrays.spec.ts b/packages/mql-typescript/tests/accumulator/concatArrays.spec.ts index 5219704f..09836d33 100644 --- a/packages/mql-typescript/tests/accumulator/concatArrays.spec.ts +++ b/packages/mql-typescript/tests/accumulator/concatArrays.spec.ts @@ -9,5 +9,12 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/concatArrays/#example} */ function test0() { - // TODO: no schema found for concatArrays.Warehouse collection + type warehouses = { + instock: Array; + ordered: Array; + }; + + const aggregation: schema.Pipeline = [ + { $project: { items: { $concatArrays: ['$instock', '$ordered'] } } }, + ]; } diff --git a/packages/mql-typescript/tests/accumulator/minMaxScaler.spec.ts b/packages/mql-typescript/tests/accumulator/minMaxScaler.spec.ts index 07e7db73..4dbedb3b 100644 --- a/packages/mql-typescript/tests/accumulator/minMaxScaler.spec.ts +++ b/packages/mql-typescript/tests/accumulator/minMaxScaler.spec.ts @@ -9,11 +9,12 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/minMaxScaler/#examples} */ function test0() { - type example = { + type TestCollection = { + _id: number; a: number; }; - const aggregation: schema.Pipeline = [ + const aggregation: schema.Pipeline = [ { $setWindowFields: { sortBy: { a: 1 }, diff --git a/packages/mql-typescript/tests/accumulator/setUnion.spec.ts b/packages/mql-typescript/tests/accumulator/setUnion.spec.ts index c82cf373..e1025460 100644 --- a/packages/mql-typescript/tests/accumulator/setUnion.spec.ts +++ b/packages/mql-typescript/tests/accumulator/setUnion.spec.ts @@ -9,5 +9,19 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/setUnion/#example} */ function test0() { - // TODO: no schema found for setUnion.Flowers collection + type flowers = { + flowerFieldA: Array; + flowerFieldB: Array; + }; + + const aggregation: schema.Pipeline = [ + { + $project: { + flowerFieldA: 1, + flowerFieldB: 1, + allValues: { $setUnion: ['$flowerFieldA', '$flowerFieldB'] }, + _id: 0, + }, + }, + ]; } diff --git a/packages/mql-typescript/tests/expression/bottom.spec.ts b/packages/mql-typescript/tests/expression/bottom.spec.ts index c0e26dab..1666daab 100644 --- a/packages/mql-typescript/tests/expression/bottom.spec.ts +++ b/packages/mql-typescript/tests/expression/bottom.spec.ts @@ -9,27 +9,5 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/bottom-array-operator/#example} */ function test0() { - type games = { - results: Array<{ - playerId: string; - score: number; - }>; - }; - - const aggregation: schema.Pipeline = [ - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). - */ - { - $project: { - bottomScore: { - $bottom: { - sortBy: { score: -1 }, - output: ['$playerId', '$score'], - input: '$results', - }, - }, - }, - } as any, - ]; + // TODO: no schema found for bottom.Example: // TODO: No schema found in docs } diff --git a/packages/mql-typescript/tests/expression/bottomN.spec.ts b/packages/mql-typescript/tests/expression/bottomN.spec.ts index dee7411c..13d6b90c 100644 --- a/packages/mql-typescript/tests/expression/bottomN.spec.ts +++ b/packages/mql-typescript/tests/expression/bottomN.spec.ts @@ -9,28 +9,5 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/bottomN-array-operator/#example} */ function test0() { - type games = { - results: Array<{ - playerId: string; - score: number; - }>; - }; - - const aggregation: schema.Pipeline = [ - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). - */ - { - $project: { - bottomScores: { - $bottomN: { - n: 3, - sortBy: { score: -1 }, - output: ['$playerId', '$score'], - input: '$results', - }, - }, - }, - } as any, - ]; + // TODO: no schema found for bottomN.Example: // TODO: No schema found in docs } diff --git a/packages/mql-typescript/tests/expression/concatArrays.spec.ts b/packages/mql-typescript/tests/expression/concatArrays.spec.ts index e812f009..c064f7f4 100644 --- a/packages/mql-typescript/tests/expression/concatArrays.spec.ts +++ b/packages/mql-typescript/tests/expression/concatArrays.spec.ts @@ -9,13 +9,18 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/concatArrays/#example} */ function test0() { - type warehouses = { + type sales = { _id: number; - instock: Array; - ordered: Array; + items: Array< + | string + | { + accessories: Array; + } + >; + location: string; }; - const aggregation: schema.Pipeline = [ + const aggregation: schema.Pipeline = [ { $project: { items: { $concatArrays: ['$instock', '$ordered'] } } }, ]; } diff --git a/packages/mql-typescript/tests/expression/cond.spec.ts b/packages/mql-typescript/tests/expression/cond.spec.ts index 95298d28..4f07b44f 100644 --- a/packages/mql-typescript/tests/expression/cond.spec.ts +++ b/packages/mql-typescript/tests/expression/cond.spec.ts @@ -9,20 +9,5 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/cond/#example} */ function test0() { - type inventory = { - _id: number; - item: string; - qty: number; - }; - - const aggregation: schema.Pipeline = [ - { - $project: { - item: 1, - discount: { - $cond: { if: { $gte: ['$qty', 250] }, then: 30, else: 20 }, - }, - }, - }, - ]; + // TODO: no schema found for cond.Example: // TODO: No schema found in docs } diff --git a/packages/mql-typescript/tests/expression/convert.spec.ts b/packages/mql-typescript/tests/expression/convert.spec.ts index 5f34eb13..ec7c323c 100644 --- a/packages/mql-typescript/tests/expression/convert.spec.ts +++ b/packages/mql-typescript/tests/expression/convert.spec.ts @@ -9,83 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/convert/#example} */ function test0() { - type orders = { - _id: number; - item: string; - qty: number; - price: bson.Decimal128 | number | string; - }; - - const aggregation: schema.Pipeline = [ - { - $addFields: { - convertedPrice: { - $convert: { - input: '$price', - to: 'decimal', - onError: 'Error', - onNull: { - bytes: { - '0': 0, - '1': 0, - '2': 0, - '3': 0, - '4': 0, - '5': 0, - '6': 0, - '7': 0, - '8': 0, - '9': 0, - '10': 0, - '11': 0, - '12': 0, - '13': 0, - '14': 64, - '15': 48, - }, - }, - }, - }, - convertedQty: { - $convert: { - input: '$qty', - to: 'int', - onError: { - $concat: [ - 'Could not convert ', - { $toString: '$qty' }, - ' to type integer.', - ], - }, - onNull: 0, - }, - }, - }, - }, - - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' (it may involve a projected field). - */ - { - $project: { - totalPrice: { - $switch: { - branches: [ - { - case: { $eq: [{ $type: '$convertedPrice' }, 'string'] }, - then: 'NaN', - }, - { - case: { $eq: [{ $type: '$convertedQty' }, 'string'] }, - then: 'NaN', - }, - ], - default: { $multiply: ['$convertedPrice', '$convertedQty'] }, - }, - }, - }, - } as any, - ]; + // TODO: no schema found for convert.Example: // TODO: No schema found in docs } /** @@ -93,20 +17,7 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/convert/#base-conversion} */ function test1() { - type data = { - _id: number; - hexString: string; - }; - - const aggregation: schema.Pipeline = [ - { - $project: { - decimalValue: { - $convert: { input: '$hexString', to: 'int', base: 16 }, - }, - }, - }, - ]; + // TODO: no schema found for convert.Convert Hexadecimal String to Integer: // TODO: No schema found in docs } /** @@ -114,16 +25,5 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/convert/#base-conversion} */ function test2() { - type data = { - _id: number; - value: bson.Int32 | number; - }; - - const aggregation: schema.Pipeline = [ - { - $project: { - binaryString: { $convert: { input: '$value', to: 'string', base: 2 } }, - }, - }, - ]; + // TODO: no schema found for convert.Convert Integer to Binary String: // TODO: No schema found in docs } diff --git a/packages/mql-typescript/tests/expression/createObjectId.spec.ts b/packages/mql-typescript/tests/expression/createObjectId.spec.ts index c347bd80..acf16460 100644 --- a/packages/mql-typescript/tests/expression/createObjectId.spec.ts +++ b/packages/mql-typescript/tests/expression/createObjectId.spec.ts @@ -9,5 +9,5 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/createObjectId/#example} */ function test0() { - // TODO: no schema found for createObjectId.Example + // TODO: no schema found for createObjectId.Example: // TODO: No schema found in docs } diff --git a/packages/mql-typescript/tests/expression/deserializeEJSON.spec.ts b/packages/mql-typescript/tests/expression/deserializeEJSON.spec.ts index a8d566ee..cdd976d7 100644 --- a/packages/mql-typescript/tests/expression/deserializeEJSON.spec.ts +++ b/packages/mql-typescript/tests/expression/deserializeEJSON.spec.ts @@ -9,18 +9,22 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/deserializeEJSON/#deserialize-extended-json-document} */ function test0() { - type movies = { + type TestCollection = { _id: bson.ObjectId; title: string; - year: bson.Int32 | number; - runtime: bson.Int32 | number; - released: Date; - cast: unknown[]; - genres: unknown[]; - directors: unknown[]; + deserialized: { + _id: bson.ObjectId; + title: string; + year: number; + runtime: number; + released: Date; + cast: Array; + genres: Array; + directors: Array; + }; }; - const aggregation: schema.Pipeline = [ + const aggregation: schema.Pipeline = [ { $match: { title: 'Inception' } }, { $project: { @@ -42,7 +46,24 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/deserializeEJSON/#parse-json-string-and-deserialize} */ function test1() { - // TODO: no schema found for deserializeEJSON.Parse JSON String and Deserialize + type TestCollection = { + jsonData: string; + }; + + const aggregation: schema.Pipeline = [ + { + $documents: [ + { + jsonData: + '{"_id":{"$oid":"507f1f77bcf86cd799439011"},"title":"The Matrix","year":{"$numberInt":"1999"},"rating":{"$numberDouble":"8.7"}}', + }, + ], + }, + { + $project: { parsed: { $convert: { input: '$jsonData', to: 'object' } } }, + }, + { $project: { movie: { $deserializeEJSON: { input: '$parsed' } } } }, + ]; } /** @@ -50,17 +71,22 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/deserializeEJSON/#deserialize-specific-fields} */ function test2() { - type movies = { + type TestCollection = { _id: bson.ObjectId; title: string; - released: Date; - runtime: bson.Int32 | number; - imdb: { - rating: bson.Double | number; + deserialized: { + _id: bson.ObjectId; + title: string; + year: number; + runtime: number; + released: Date; + cast: Array; + genres: Array; + directors: Array; }; }; - const aggregation: schema.Pipeline = [ + const aggregation: schema.Pipeline = [ { $match: { title: 'Inception' } }, { $project: { @@ -90,12 +116,22 @@ function test2() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/deserializeEJSON/#use-onerror-for-error-handling} */ function test3() { - type data = { + type TestCollection = { _id: bson.ObjectId; - ejsonField: string; + title: string; + deserialized: { + _id: bson.ObjectId; + title: string; + year: number; + runtime: number; + released: Date; + cast: Array; + genres: Array; + directors: Array; + }; }; - const aggregation: schema.Pipeline = [ + const aggregation: schema.Pipeline = [ { $project: { result: { diff --git a/packages/mql-typescript/tests/expression/getField.spec.ts b/packages/mql-typescript/tests/expression/getField.spec.ts index f85709f5..25f9e77e 100644 --- a/packages/mql-typescript/tests/expression/getField.spec.ts +++ b/packages/mql-typescript/tests/expression/getField.spec.ts @@ -31,7 +31,7 @@ function test1() { type inventory = { _id: number; item: string; - $price: number; + 'price.usd': number; qty: number; }; diff --git a/packages/mql-typescript/tests/expression/hash.spec.ts b/packages/mql-typescript/tests/expression/hash.spec.ts index 5e826e86..c94327af 100644 --- a/packages/mql-typescript/tests/expression/hash.spec.ts +++ b/packages/mql-typescript/tests/expression/hash.spec.ts @@ -12,7 +12,6 @@ function test0() { type files = { _id: number; filename: string; - hash: bson.Binary; }; const aggregation: schema.Pipeline = [ @@ -65,5 +64,12 @@ function test2() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/hash/#null-or-missing-input} */ function test3() { - // TODO: no schema found for hash.Null or Missing Input + type TestCollection = { + val: null; + }; + + const aggregation: schema.Pipeline = [ + { $documents: [{ val: null }, {}] }, + { $project: { hash: { $hash: { input: '$val', algorithm: 'sha256' } } } }, + ]; } diff --git a/packages/mql-typescript/tests/expression/hexHash.spec.ts b/packages/mql-typescript/tests/expression/hexHash.spec.ts index 2446fae6..bc9ca6da 100644 --- a/packages/mql-typescript/tests/expression/hexHash.spec.ts +++ b/packages/mql-typescript/tests/expression/hexHash.spec.ts @@ -12,7 +12,6 @@ function test0() { type files = { _id: number; filename: string; - hexHash: string; }; const aggregation: schema.Pipeline = [ @@ -30,5 +29,16 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/hexHash/#null-or-missing-input} */ function test1() { - // TODO: no schema found for hexHash.Null or Missing Input + type TestCollection = { + val: null; + }; + + const aggregation: schema.Pipeline = [ + { $documents: [{ val: null }, {}] }, + { + $project: { + hexHash: { $hexHash: { input: '$val', algorithm: 'sha256' } }, + }, + }, + ]; } diff --git a/packages/mql-typescript/tests/expression/ifNull.spec.ts b/packages/mql-typescript/tests/expression/ifNull.spec.ts index aee239c1..1052b6be 100644 --- a/packages/mql-typescript/tests/expression/ifNull.spec.ts +++ b/packages/mql-typescript/tests/expression/ifNull.spec.ts @@ -9,14 +9,12 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/ifNull/#single-input-expression} */ function test0() { - type inventory = { - _id: number; - item: string; - description: string | null; - quantity: number; + type TestCollection = { + title: string; + rated: string; }; - const aggregation: schema.Pipeline = [ + const aggregation: schema.Pipeline = [ { $project: { item: 1, @@ -31,14 +29,12 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/ifNull/#multiple-input-expressions} */ function test1() { - type inventory = { - _id: number; - item: string; - description: string | null; - quantity: number; + type TestCollection = { + title: string; + rated: string; }; - const aggregation: schema.Pipeline = [ + const aggregation: schema.Pipeline = [ { $project: { item: 1, diff --git a/packages/mql-typescript/tests/expression/map.spec.ts b/packages/mql-typescript/tests/expression/map.spec.ts index ac9b3f56..beb4ee52 100644 --- a/packages/mql-typescript/tests/expression/map.spec.ts +++ b/packages/mql-typescript/tests/expression/map.spec.ts @@ -9,11 +9,12 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/map/#add-to-each-element-of-an-array} */ function test0() { - type grades = { - quizzes: Array; + type TestCollection = { + theaterId: number; + adjustedCoordinates: Array; }; - const aggregation: schema.Pipeline = [ + const aggregation: schema.Pipeline = [ /** * This stage is unsupported by the static type system, so we're casting it to 'any' ($map references the variable names defined in the `as` field, which is not available statically). */ @@ -36,12 +37,12 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/map/#truncate-each-array-element} */ function test1() { - type deliveries = { - city: string; - distances: Array; + type TestCollection = { + theaterId: number; + adjustedCoordinates: Array; }; - const aggregation: schema.Pipeline = [ + const aggregation: schema.Pipeline = [ /** * This stage is unsupported by the static type system, so we're casting it to 'any' ($map references the variable names defined in the `as` field, which is not available statically). */ @@ -65,27 +66,7 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/map/#convert-celsius-temperatures-to-fahrenheit} */ function test2() { - type temperatures = { - date: Date; - tempsC: Array; - }; - - const aggregation: schema.Pipeline = [ - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' ($map references the variable names defined in the `as` field, which is not available statically). - */ - { - $addFields: { - tempsF: { - $map: { - input: '$tempsC', - as: 'tempInCelsius', - in: { $add: [{ $multiply: ['$$tempInCelsius', 1.8] }, 32] }, - }, - }, - }, - } as any, - ]; + // TODO: no schema found for map.Convert Celsius Temperatures to Fahrenheit: // TODO: No schema found in docs } /** @@ -93,25 +74,5 @@ function test2() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/map/} */ function test3() { - type data = { - scores: Array; - }; - - const aggregation: schema.Pipeline = [ - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' ($map references the variable names defined in the `as` and `arrayIndexAs` fields, which is not available statically). - */ - { - $project: { - result: { - $map: { - input: '$scores', - as: 'score', - arrayIndexAs: 'idx', - in: { $add: ['$$score', '$$idx'] }, - }, - }, - }, - } as any, - ]; + // TODO: no schema found for map.Use Array Index: // TODO: No schema found in docs } diff --git a/packages/mql-typescript/tests/expression/max.spec.ts b/packages/mql-typescript/tests/expression/max.spec.ts index 48cf3572..4495bdc5 100644 --- a/packages/mql-typescript/tests/expression/max.spec.ts +++ b/packages/mql-typescript/tests/expression/max.spec.ts @@ -9,7 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/max/#use-in--project-stage} */ function test0() { - type TestCollection = { + type students = { _id: number; quizzes: Array; labs: Array; @@ -17,7 +17,7 @@ function test0() { midterm: number; }; - const aggregation: schema.Pipeline = [ + const aggregation: schema.Pipeline = [ { $project: { quizMax: { $max: ['$quizzes'] }, diff --git a/packages/mql-typescript/tests/expression/min.spec.ts b/packages/mql-typescript/tests/expression/min.spec.ts index a7bb280a..39cf7b0a 100644 --- a/packages/mql-typescript/tests/expression/min.spec.ts +++ b/packages/mql-typescript/tests/expression/min.spec.ts @@ -9,7 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/min/#use-in--project-stage} */ function test0() { - type TestCollection = { + type students = { _id: number; quizzes: Array; labs: Array; @@ -17,7 +17,7 @@ function test0() { midterm: number; }; - const aggregation: schema.Pipeline = [ + const aggregation: schema.Pipeline = [ { $project: { quizMin: { $min: ['$quizzes'] }, diff --git a/packages/mql-typescript/tests/expression/replaceOne.spec.ts b/packages/mql-typescript/tests/expression/replaceOne.spec.ts index 09c91e1f..2a368196 100644 --- a/packages/mql-typescript/tests/expression/replaceOne.spec.ts +++ b/packages/mql-typescript/tests/expression/replaceOne.spec.ts @@ -9,24 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceOne/#example} */ function test0() { - type inventory = { - _id: number; - item: string; - }; - - const aggregation: schema.Pipeline = [ - { - $project: { - item: { - $replaceOne: { - input: '$item', - find: 'blue paint', - replacement: 'red paint', - }, - }, - }, - }, - ]; + // TODO: no schema found for replaceOne.Example: // TODO: No schema found in docs } /** diff --git a/packages/mql-typescript/tests/expression/serializeEJSON.spec.ts b/packages/mql-typescript/tests/expression/serializeEJSON.spec.ts index af60c119..87f759b1 100644 --- a/packages/mql-typescript/tests/expression/serializeEJSON.spec.ts +++ b/packages/mql-typescript/tests/expression/serializeEJSON.spec.ts @@ -9,18 +9,31 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/serializeEJSON/#canonical-extended-json-example} */ function test0() { - type movies = { + type TestCollection = { _id: bson.ObjectId; - title: string; - year: bson.Int32 | number; - runtime: bson.Int32 | number; - released: Date; - cast: unknown[]; - genres: unknown[]; - directors: unknown[]; + ejson: { + _id: { + $oid: string; + }; + title: string; + year: { + $numberInt: string; + }; + runtime: { + $numberInt: string; + }; + released: { + $date: { + $numberLong: string; + }; + }; + cast: Array; + genres: Array; + directors: Array; + }; }; - const aggregation: schema.Pipeline = [ + const aggregation: schema.Pipeline = [ { $match: { title: 'Inception' } }, { $project: { ejson: { $serializeEJSON: { input: '$$ROOT' } } } }, ]; @@ -31,18 +44,31 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/serializeEJSON/#relaxed-extended-json-example} */ function test1() { - type movies = { + type TestCollection = { _id: bson.ObjectId; - title: string; - year: bson.Int32 | number; - runtime: bson.Int32 | number; - released: Date; - cast: unknown[]; - genres: unknown[]; - directors: unknown[]; + ejson: { + _id: { + $oid: string; + }; + title: string; + year: { + $numberInt: string; + }; + runtime: { + $numberInt: string; + }; + released: { + $date: { + $numberLong: string; + }; + }; + cast: Array; + genres: Array; + directors: Array; + }; }; - const aggregation: schema.Pipeline = [ + const aggregation: schema.Pipeline = [ { $match: { title: 'Inception' } }, { $project: { @@ -57,14 +83,31 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/serializeEJSON/#convert-to-json-string} */ function test2() { - type movies = { + type TestCollection = { _id: bson.ObjectId; - title: string; - year: bson.Int32 | number; - released: Date; + ejson: { + _id: { + $oid: string; + }; + title: string; + year: { + $numberInt: string; + }; + runtime: { + $numberInt: string; + }; + released: { + $date: { + $numberLong: string; + }; + }; + cast: Array; + genres: Array; + directors: Array; + }; }; - const aggregation: schema.Pipeline = [ + const aggregation: schema.Pipeline = [ { $match: { title: 'The Godfather' } }, { $project: { @@ -80,18 +123,31 @@ function test2() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/serializeEJSON/#serialize-specific-fields} */ function test3() { - type movies = { + type TestCollection = { _id: bson.ObjectId; - title: string; - year: bson.Int32 | number; - released: Date; - runtime: bson.Int32 | number; - imdb: { - rating: bson.Double | number; + ejson: { + _id: { + $oid: string; + }; + title: string; + year: { + $numberInt: string; + }; + runtime: { + $numberInt: string; + }; + released: { + $date: { + $numberLong: string; + }; + }; + cast: Array; + genres: Array; + directors: Array; }; }; - const aggregation: schema.Pipeline = [ + const aggregation: schema.Pipeline = [ { $match: { year: { $gte: 2010 } } }, { $project: { @@ -115,13 +171,31 @@ function test3() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/serializeEJSON/#use-onerror-for-error-handling} */ function test4() { - type movies = { + type TestCollection = { _id: bson.ObjectId; - title: string; - customField: string; + ejson: { + _id: { + $oid: string; + }; + title: string; + year: { + $numberInt: string; + }; + runtime: { + $numberInt: string; + }; + released: { + $date: { + $numberLong: string; + }; + }; + cast: Array; + genres: Array; + directors: Array; + }; }; - const aggregation: schema.Pipeline = [ + const aggregation: schema.Pipeline = [ { $project: { title: 1, diff --git a/packages/mql-typescript/tests/expression/setField.spec.ts b/packages/mql-typescript/tests/expression/setField.spec.ts index ea0b138f..36de0ca7 100644 --- a/packages/mql-typescript/tests/expression/setField.spec.ts +++ b/packages/mql-typescript/tests/expression/setField.spec.ts @@ -82,8 +82,8 @@ function test3() { type inventory = { _id: number; item: string; + price: number; qty: number; - $price: number; }; const aggregation: schema.Pipeline = [ @@ -129,8 +129,8 @@ function test5() { type inventory = { _id: number; item: string; + price: number; qty: number; - $price: number; }; const aggregation: schema.Pipeline = [ diff --git a/packages/mql-typescript/tests/expression/setUnion.spec.ts b/packages/mql-typescript/tests/expression/setUnion.spec.ts index d209d755..90a07640 100644 --- a/packages/mql-typescript/tests/expression/setUnion.spec.ts +++ b/packages/mql-typescript/tests/expression/setUnion.spec.ts @@ -9,13 +9,18 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/setUnion/#example} */ function test0() { - type flowers = { + type sales = { _id: number; - flowerFieldA: Array; - flowerFieldB: Array>; + items: Array< + | string + | { + accessories: Array; + } + >; + location: string; }; - const aggregation: schema.Pipeline = [ + const aggregation: schema.Pipeline = [ { $project: { flowerFieldA: 1, diff --git a/packages/mql-typescript/tests/expression/sigmoid.spec.ts b/packages/mql-typescript/tests/expression/sigmoid.spec.ts index 91dab8cf..ff1a36d0 100644 --- a/packages/mql-typescript/tests/expression/sigmoid.spec.ts +++ b/packages/mql-typescript/tests/expression/sigmoid.spec.ts @@ -9,12 +9,5 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/sigmoid/#examples} */ function test0() { - type scores = { - _id: bson.ObjectId; - score: bson.Double | number; - }; - - const aggregation: schema.Pipeline = [ - { $set: { scaled: { $sigmoid: '$score' } } }, - ]; + // TODO: no schema found for sigmoid.Example: // TODO: No schema found in docs } diff --git a/packages/mql-typescript/tests/expression/subtype.spec.ts b/packages/mql-typescript/tests/expression/subtype.spec.ts index 7b69cbe0..c732cfef 100644 --- a/packages/mql-typescript/tests/expression/subtype.spec.ts +++ b/packages/mql-typescript/tests/expression/subtype.spec.ts @@ -9,11 +9,5 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/subtype/} */ function test0() { - type data = { - myBinDataField: bson.Binary; - }; - - const aggregation: schema.Pipeline = [ - { $project: { result: { $subtype: '$myBinDataField' } } }, - ]; + // TODO: no schema found for subtype.Example: // TODO: No schema found in docs } diff --git a/packages/mql-typescript/tests/expression/sum.spec.ts b/packages/mql-typescript/tests/expression/sum.spec.ts index 34aa8557..3be6fa74 100644 --- a/packages/mql-typescript/tests/expression/sum.spec.ts +++ b/packages/mql-typescript/tests/expression/sum.spec.ts @@ -9,7 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/sum/#use-in--project-stage} */ function test0() { - type students = { + type TestCollection = { _id: number; quizzes: Array; labs: Array; @@ -17,7 +17,7 @@ function test0() { midterm: number; }; - const aggregation: schema.Pipeline = [ + const aggregation: schema.Pipeline = [ { $project: { quizTotal: { $sum: ['$quizzes'] }, diff --git a/packages/mql-typescript/tests/expression/toArray.spec.ts b/packages/mql-typescript/tests/expression/toArray.spec.ts index 23927237..dd5dfab6 100644 --- a/packages/mql-typescript/tests/expression/toArray.spec.ts +++ b/packages/mql-typescript/tests/expression/toArray.spec.ts @@ -30,7 +30,6 @@ function test0() { */ function test1() { type t = { - _id: number; v: bson.Binary; }; diff --git a/packages/mql-typescript/tests/expression/top.spec.ts b/packages/mql-typescript/tests/expression/top.spec.ts index 1d160192..4614cfd6 100644 --- a/packages/mql-typescript/tests/expression/top.spec.ts +++ b/packages/mql-typescript/tests/expression/top.spec.ts @@ -9,27 +9,5 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/top-array-operator/#example} */ function test0() { - type games = { - results: Array<{ - playerId: string; - score: number; - }>; - }; - - const aggregation: schema.Pipeline = [ - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). - */ - { - $project: { - topScore: { - $top: { - sortBy: { score: -1 }, - output: ['$playerId', '$score'], - input: '$results', - }, - }, - }, - } as any, - ]; + // TODO: no schema found for top.Example: // TODO: No schema found in docs } diff --git a/packages/mql-typescript/tests/expression/topN.spec.ts b/packages/mql-typescript/tests/expression/topN.spec.ts index 3aa12423..1fb78cd4 100644 --- a/packages/mql-typescript/tests/expression/topN.spec.ts +++ b/packages/mql-typescript/tests/expression/topN.spec.ts @@ -9,28 +9,5 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/topN-array-operator/#example} */ function test0() { - type games = { - results: Array<{ - playerId: string; - score: number; - }>; - }; - - const aggregation: schema.Pipeline = [ - /** - * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). - */ - { - $project: { - topScores: { - $topN: { - n: 3, - sortBy: { score: -1 }, - output: ['$playerId', '$score'], - input: '$results', - }, - }, - }, - } as any, - ]; + // TODO: no schema found for topN.Example: // TODO: No schema found in docs } diff --git a/packages/mql-typescript/tests/expression/type.spec.ts b/packages/mql-typescript/tests/expression/type.spec.ts index c9ff9196..a98f53ea 100644 --- a/packages/mql-typescript/tests/expression/type.spec.ts +++ b/packages/mql-typescript/tests/expression/type.spec.ts @@ -9,7 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/type/#example} */ function test0() { - type TestCollection = { + type coll = { _id: number; a: | number @@ -20,10 +20,11 @@ function test0() { c: string; } | string - | bson.Long; + | bson.Long + | null; }; - const aggregation: schema.Pipeline = [ + const aggregation: schema.Pipeline = [ { $project: { a: { $type: '$a' } } }, ]; } diff --git a/packages/mql-typescript/tests/expression/unsetField.spec.ts b/packages/mql-typescript/tests/expression/unsetField.spec.ts index 77a56bd9..34427e33 100644 --- a/packages/mql-typescript/tests/expression/unsetField.spec.ts +++ b/packages/mql-typescript/tests/expression/unsetField.spec.ts @@ -30,7 +30,7 @@ function test1() { _id: number; item: string; qty: number; - $price: number; + 'price.usd': number; }; const aggregation: schema.Pipeline = [ diff --git a/packages/mql-typescript/tests/query/all.spec.ts b/packages/mql-typescript/tests/query/all.spec.ts index dc6372fe..5b197a10 100644 --- a/packages/mql-typescript/tests/query/all.spec.ts +++ b/packages/mql-typescript/tests/query/all.spec.ts @@ -9,7 +9,20 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/all/#use--all-to-match-values} */ function test0() { - // TODO: no schema found for all.Use $all to Match Values + type inventory = { + _id: bson.ObjectId; + code: string; + tags: Array; + qty: Array<{ + size: string; + num: number; + color: string; + }>; + }; + + const aggregation: schema.Pipeline = [ + { $match: { tags: { $all: ['appliance', 'school', 'book'] } } }, + ]; } /** @@ -17,5 +30,27 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/all/#use--all-with--elemmatch} */ function test1() { - // TODO: no schema found for all.Use $all with $elemMatch + type inventory = { + _id: bson.ObjectId; + code: string; + tags: Array; + qty: Array<{ + size: string; + num: number; + color: string; + }>; + }; + + const aggregation: schema.Pipeline = [ + { + $match: { + qty: { + $all: [ + { $elemMatch: { size: 'M', num: { $gt: 50 } } }, + { $elemMatch: { num: 100, color: 'green' } }, + ], + }, + }, + }, + ]; } diff --git a/packages/mql-typescript/tests/query/and.spec.ts b/packages/mql-typescript/tests/query/and.spec.ts index ac3a3ce1..ccad2394 100644 --- a/packages/mql-typescript/tests/query/and.spec.ts +++ b/packages/mql-typescript/tests/query/and.spec.ts @@ -9,7 +9,21 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/and/#and-queries-with-multiple-expressions-specifying-the-same-field} */ function test0() { - // TODO: no schema found for and.AND Queries With Multiple Expressions Specifying the Same Field + type inventory = { + price: bson.Double | number; + qty: bson.Int32 | number | undefined; + quantity: bson.Int32 | number | undefined; + sale: boolean; + tags: Array; + }; + + const aggregation: schema.Pipeline = [ + { + $match: { + $and: [{ price: { $ne: 1.99 } }, { price: { $exists: true } }], + }, + }, + ]; } /** @@ -17,5 +31,22 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/and/#and-queries-with-multiple-expressions-specifying-the-same-operator} */ function test1() { - // TODO: no schema found for and.AND Queries With Multiple Expressions Specifying the Same Operator + type inventory = { + price: bson.Double | number; + qty: bson.Int32 | number | undefined; + quantity: bson.Int32 | number | undefined; + sale: boolean; + tags: Array; + }; + + const aggregation: schema.Pipeline = [ + { + $match: { + $and: [ + { $or: [{ qty: { $lt: 10 } }, { qty: { $gt: 50 } }] }, + { $or: [{ sale: true }, { price: { $lt: 5 } }] }, + ], + }, + }, + ]; } diff --git a/packages/mql-typescript/tests/query/bitsAllClear.spec.ts b/packages/mql-typescript/tests/query/bitsAllClear.spec.ts index 4133e43d..af9cc174 100644 --- a/packages/mql-typescript/tests/query/bitsAllClear.spec.ts +++ b/packages/mql-typescript/tests/query/bitsAllClear.spec.ts @@ -9,7 +9,15 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/bitsAllClear/#bit-position-array} */ function test0() { - // TODO: no schema found for bitsAllClear.Bit Position Array + type collection = { + _id: number; + a: number | bson.Binary; + binaryValueofA: string; + }; + + const aggregation: schema.Pipeline = [ + { $match: { a: { $bitsAllClear: [1, 5] } } }, + ]; } /** @@ -17,7 +25,15 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/bitsAllClear/#integer-bitmask} */ function test1() { - // TODO: no schema found for bitsAllClear.Integer Bitmask + type collection = { + _id: number; + a: number | bson.Binary; + binaryValueofA: string; + }; + + const aggregation: schema.Pipeline = [ + { $match: { a: { $bitsAllClear: 35 } } }, + ]; } /** @@ -25,5 +41,15 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/bitsAllClear/#bindata-bitmask} */ function test2() { - // TODO: no schema found for bitsAllClear.BinData Bitmask + type collection = { + _id: number; + a: number | bson.Binary; + binaryValueofA: string; + }; + + const aggregation: schema.Pipeline = [ + { + $match: { a: { $bitsAllClear: bson.Binary.createFromBase64('IA==', 0) } }, + }, + ]; } diff --git a/packages/mql-typescript/tests/query/bitsAllSet.spec.ts b/packages/mql-typescript/tests/query/bitsAllSet.spec.ts index d88781d3..65fb95c8 100644 --- a/packages/mql-typescript/tests/query/bitsAllSet.spec.ts +++ b/packages/mql-typescript/tests/query/bitsAllSet.spec.ts @@ -9,7 +9,15 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/bitsAllSet/#bit-position-array} */ function test0() { - // TODO: no schema found for bitsAllSet.Bit Position Array + type collection = { + _id: number; + a: number | bson.Binary; + binaryValueofA: string; + }; + + const aggregation: schema.Pipeline = [ + { $match: { a: { $bitsAllSet: [1, 5] } } }, + ]; } /** @@ -17,7 +25,15 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/bitsAllSet/#integer-bitmask} */ function test1() { - // TODO: no schema found for bitsAllSet.Integer Bitmask + type collection = { + _id: number; + a: number | bson.Binary; + binaryValueofA: string; + }; + + const aggregation: schema.Pipeline = [ + { $match: { a: { $bitsAllSet: 50 } } }, + ]; } /** @@ -25,5 +41,13 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/bitsAllSet/#bindata-bitmask} */ function test2() { - // TODO: no schema found for bitsAllSet.BinData Bitmask + type collection = { + _id: number; + a: number | bson.Binary; + binaryValueofA: string; + }; + + const aggregation: schema.Pipeline = [ + { $match: { a: { $bitsAllSet: bson.Binary.createFromBase64('MA==', 0) } } }, + ]; } diff --git a/packages/mql-typescript/tests/query/bitsAnyClear.spec.ts b/packages/mql-typescript/tests/query/bitsAnyClear.spec.ts index 9f461faf..ae403359 100644 --- a/packages/mql-typescript/tests/query/bitsAnyClear.spec.ts +++ b/packages/mql-typescript/tests/query/bitsAnyClear.spec.ts @@ -9,7 +9,15 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/bitsAnyClear/#bit-position-array} */ function test0() { - // TODO: no schema found for bitsAnyClear.Bit Position Array + type collection = { + _id: number; + a: number | bson.Binary; + binaryValueofA: string; + }; + + const aggregation: schema.Pipeline = [ + { $match: { a: { $bitsAnyClear: [1, 5] } } }, + ]; } /** @@ -17,7 +25,15 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/bitsAnyClear/#integer-bitmask} */ function test1() { - // TODO: no schema found for bitsAnyClear.Integer Bitmask + type collection = { + _id: number; + a: number | bson.Binary; + binaryValueofA: string; + }; + + const aggregation: schema.Pipeline = [ + { $match: { a: { $bitsAnyClear: 35 } } }, + ]; } /** @@ -25,5 +41,15 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/bitsAnyClear/#bindata-bitmask} */ function test2() { - // TODO: no schema found for bitsAnyClear.BinData Bitmask + type collection = { + _id: number; + a: number | bson.Binary; + binaryValueofA: string; + }; + + const aggregation: schema.Pipeline = [ + { + $match: { a: { $bitsAnyClear: bson.Binary.createFromBase64('MA==', 0) } }, + }, + ]; } diff --git a/packages/mql-typescript/tests/query/bitsAnySet.spec.ts b/packages/mql-typescript/tests/query/bitsAnySet.spec.ts index 5411d9cd..cadc533a 100644 --- a/packages/mql-typescript/tests/query/bitsAnySet.spec.ts +++ b/packages/mql-typescript/tests/query/bitsAnySet.spec.ts @@ -9,7 +9,15 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/bitsAnySet/#bit-position-array} */ function test0() { - // TODO: no schema found for bitsAnySet.Bit Position Array + type collection = { + _id: number; + a: number | bson.Binary; + binaryValueofA: string; + }; + + const aggregation: schema.Pipeline = [ + { $match: { a: { $bitsAnySet: [1, 5] } } }, + ]; } /** @@ -17,7 +25,15 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/bitsAnySet/#integer-bitmask} */ function test1() { - // TODO: no schema found for bitsAnySet.Integer Bitmask + type collection = { + _id: number; + a: number | bson.Binary; + binaryValueofA: string; + }; + + const aggregation: schema.Pipeline = [ + { $match: { a: { $bitsAnySet: 35 } } }, + ]; } /** @@ -25,5 +41,13 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/bitsAnySet/#bindata-bitmask} */ function test2() { - // TODO: no schema found for bitsAnySet.BinData Bitmask + type collection = { + _id: number; + a: number | bson.Binary; + binaryValueofA: string; + }; + + const aggregation: schema.Pipeline = [ + { $match: { a: { $bitsAnySet: bson.Binary.createFromBase64('MA==', 0) } } }, + ]; } diff --git a/packages/mql-typescript/tests/query/comment.spec.ts b/packages/mql-typescript/tests/query/comment.spec.ts index 0f34750b..02409ab6 100644 --- a/packages/mql-typescript/tests/query/comment.spec.ts +++ b/packages/mql-typescript/tests/query/comment.spec.ts @@ -9,5 +9,5 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/comment/#attach-a-comment-to-an-aggregation-expression} */ function test0() { - // TODO: no schema found for comment.Attach a Comment to an Aggregation Expression + // TODO: no schema found for comment.Attach a Comment to an Aggregation Expression: // TODO: No schema found in docs } diff --git a/packages/mql-typescript/tests/query/elemMatch.spec.ts b/packages/mql-typescript/tests/query/elemMatch.spec.ts index 9a85e122..4bb8a098 100644 --- a/packages/mql-typescript/tests/query/elemMatch.spec.ts +++ b/packages/mql-typescript/tests/query/elemMatch.spec.ts @@ -9,7 +9,14 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/elemMatch/#element-match} */ function test0() { - // TODO: no schema found for elemMatch.Element Match + type TestCollection = { + _id: number; + results: Array; + }; + + const aggregation: schema.Pipeline = [ + { $match: { results: { $elemMatch: { $gte: 80, $lt: 85 } } } }, + ]; } /** @@ -17,7 +24,26 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/elemMatch/#array-of-embedded-documents} */ function test1() { - // TODO: no schema found for elemMatch.Array of Embedded Documents + type survey = { + _id: number; + results: + | Array<{ + product: string; + score: number; + }> + | { + product: string; + score: number; + }; + }; + + const aggregation: schema.Pipeline = [ + { + $match: { + results: { $elemMatch: { product: 'xyz', score: { $gte: 8 } } }, + }, + }, + ]; } /** @@ -25,19 +51,26 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/elemMatch/#single-query-condition} */ function test2() { - // TODO: no schema found for elemMatch.Single Query Condition + type TestCollection = { + _id: number; + results: Array; + }; + + const aggregation: schema.Pipeline = [ + { $match: { results: { $elemMatch: { product: { $ne: 'xyz' } } } } }, + ]; } /** * Using $or with $elemMatch */ function test3() { - // TODO: no schema found for elemMatch.Using $or with $elemMatch + // TODO: no schema found for elemMatch.Using $or with $elemMatch: // TODO: No docs reference found } /** * Single field operator */ function test4() { - // TODO: no schema found for elemMatch.Single field operator + // TODO: no schema found for elemMatch.Single field operator: // TODO: No docs reference found } diff --git a/packages/mql-typescript/tests/query/eq.spec.ts b/packages/mql-typescript/tests/query/eq.spec.ts index 8f9be835..a1e68caf 100644 --- a/packages/mql-typescript/tests/query/eq.spec.ts +++ b/packages/mql-typescript/tests/query/eq.spec.ts @@ -9,7 +9,19 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/eq/#equals-a-specified-value} */ function test0() { - // TODO: no schema found for eq.Equals a Specified Value + type inventory = { + _id: number; + item: { + name: string; + code: string; + }; + qty: number; + tags: Array>; + }; + + const aggregation: schema.Pipeline = [ + { $match: { qty: { $eq: 20 } } }, + ]; } /** @@ -17,7 +29,22 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/eq/#field-in-embedded-document-equals-a-value} */ function test1() { - // TODO: no schema found for eq.Field in Embedded Document Equals a Value + type inventory = { + _id: number; + item: { + name: string; + code: string; + }; + qty: number; + tags: Array>; + }; + + const aggregation: schema.Pipeline = [ + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). + */ + { $match: { 'item.name': { $eq: 'ab' } } } as any, + ]; } /** @@ -25,7 +52,19 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/eq/#equals-an-array-value} */ function test2() { - // TODO: no schema found for eq.Equals an Array Value + type inventory = { + _id: number; + item: { + name: string; + code: string; + }; + qty: number; + tags: Array>; + }; + + const aggregation: schema.Pipeline = [ + { $match: { tags: { $eq: ['A', 'B'] } } }, + ]; } /** @@ -33,5 +72,15 @@ function test2() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/eq/#regex-match-behaviour} */ function test3() { - // TODO: no schema found for eq.Regex Match Behaviour + type companies = { + _id: bson.Int32 | number; + company: string; + }; + + const aggregation: schema.Pipeline = [ + { $match: { company: 'MongoDB' } }, + { $match: { company: { $eq: 'MongoDB' } } }, + { $match: { company: new bson.BSONRegExp('^MongoDB', '') } }, + { $match: { company: { $eq: new bson.BSONRegExp('^MongoDB', '') } } }, + ]; } diff --git a/packages/mql-typescript/tests/query/exists.spec.ts b/packages/mql-typescript/tests/query/exists.spec.ts index 1d21b9ef..b8afd20c 100644 --- a/packages/mql-typescript/tests/query/exists.spec.ts +++ b/packages/mql-typescript/tests/query/exists.spec.ts @@ -9,7 +9,17 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/exists/#exists-and-not-equal-to} */ function test0() { - // TODO: no schema found for exists.Exists and Not Equal To + type inventory = { + price: bson.Double | number; + qty: bson.Int32 | number | undefined; + quantity: bson.Int32 | number | undefined; + sale: boolean; + tags: Array; + }; + + const aggregation: schema.Pipeline = [ + { $match: { qty: { $exists: true, $nin: [5, 15] } } }, + ]; } /** @@ -17,12 +27,32 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/exists/#null-values} */ function test1() { - // TODO: no schema found for exists.Null Values + type inventory = { + price: bson.Double | number; + qty: bson.Int32 | number | undefined; + quantity: bson.Int32 | number | undefined; + sale: boolean; + tags: Array; + }; + + const aggregation: schema.Pipeline = [ + { $match: { qty: { $exists: true } } }, + ]; } /** * Missing Field */ function test2() { - // TODO: no schema found for exists.Missing Field + type inventory = { + price: bson.Double | number; + qty: bson.Int32 | number | undefined; + quantity: bson.Int32 | number | undefined; + sale: boolean; + tags: Array; + }; + + const aggregation: schema.Pipeline = [ + { $match: { qty: { $exists: false } } }, + ]; } diff --git a/packages/mql-typescript/tests/query/expr.spec.ts b/packages/mql-typescript/tests/query/expr.spec.ts index ffaa4f85..9097767e 100644 --- a/packages/mql-typescript/tests/query/expr.spec.ts +++ b/packages/mql-typescript/tests/query/expr.spec.ts @@ -9,7 +9,18 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/expr/#compare-two-fields-from-a-single-document} */ function test0() { - // TODO: no schema found for expr.Compare Two Fields from A Single Document + type TestCollection = { + title: string; + tomatoes: { + viewer: { + rating: number; + }; + }; + }; + + const aggregation: schema.Pipeline = [ + { $match: { $expr: { $gt: ['$spent', '$budget'] } } }, + ]; } /** @@ -17,5 +28,5 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/expr/#using--expr-with-conditional-statements} */ function test1() { - // TODO: no schema found for expr.Using $expr With Conditional Statements + // TODO: no schema found for expr.Using $expr With Conditional Statements: // TODO: No schema found in docs } diff --git a/packages/mql-typescript/tests/query/geoIntersects.spec.ts b/packages/mql-typescript/tests/query/geoIntersects.spec.ts index d8be7197..b2c98a9c 100644 --- a/packages/mql-typescript/tests/query/geoIntersects.spec.ts +++ b/packages/mql-typescript/tests/query/geoIntersects.spec.ts @@ -9,7 +9,34 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/geoIntersects/#intersects-a-polygon} */ function test0() { - // TODO: no schema found for geoIntersects.Intersects a Polygon + type places = { + loc: { + type: string; + coordinates: Array>>; + }; + }; + + const aggregation: schema.Pipeline = [ + { + $match: { + loc: { + $geoIntersects: { + $geometry: { + type: 'Polygon', + coordinates: [ + [ + [0, 0], + [3, 6], + [6, 1], + [0, 0], + ], + ], + }, + }, + }, + }, + }, + ]; } /** @@ -17,5 +44,40 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/geoIntersects/#intersects-a--big--polygon} */ function test1() { - // TODO: no schema found for geoIntersects.Intersects a Big Polygon + type places = { + loc: { + type: string; + coordinates: Array>>; + }; + }; + + const aggregation: schema.Pipeline = [ + { + $match: { + loc: { + $geoIntersects: { + $geometry: { + type: 'Polygon', + coordinates: [ + [ + [-100, 60], + [-100, 0], + [-100, -60], + [100, -60], + [100, 60], + [-100, 60], + ], + ], + crs: { + type: 'name', + properties: { + name: 'urn:x-mongodb:crs:strictwinding:EPSG:4326', + }, + }, + }, + }, + }, + }, + }, + ]; } diff --git a/packages/mql-typescript/tests/query/geoWithin.spec.ts b/packages/mql-typescript/tests/query/geoWithin.spec.ts index bd8864b7..d7fc7bbc 100644 --- a/packages/mql-typescript/tests/query/geoWithin.spec.ts +++ b/packages/mql-typescript/tests/query/geoWithin.spec.ts @@ -9,7 +9,34 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/geoWithin/#within-a-polygon} */ function test0() { - // TODO: no schema found for geoWithin.Within a Polygon + type places = { + loc: { + type: string; + coordinates: Array>>; + }; + }; + + const aggregation: schema.Pipeline = [ + { + $match: { + loc: { + $geoWithin: { + $geometry: { + type: 'Polygon', + coordinates: [ + [ + [0, 0], + [3, 6], + [6, 1], + [0, 0], + ], + ], + }, + }, + }, + }, + }, + ]; } /** @@ -17,5 +44,40 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/geoWithin/#within-a--big--polygon} */ function test1() { - // TODO: no schema found for geoWithin.Within a Big Polygon + type places = { + loc: { + type: string; + coordinates: Array>>; + }; + }; + + const aggregation: schema.Pipeline = [ + { + $match: { + loc: { + $geoWithin: { + $geometry: { + type: 'Polygon', + coordinates: [ + [ + [-100, 60], + [-100, 0], + [-100, -60], + [100, -60], + [100, 60], + [-100, 60], + ], + ], + crs: { + type: 'name', + properties: { + name: 'urn:x-mongodb:crs:strictwinding:EPSG:4326', + }, + }, + }, + }, + }, + }, + }, + ]; } diff --git a/packages/mql-typescript/tests/query/gt.spec.ts b/packages/mql-typescript/tests/query/gt.spec.ts index 8a7de81b..4b03c166 100644 --- a/packages/mql-typescript/tests/query/gt.spec.ts +++ b/packages/mql-typescript/tests/query/gt.spec.ts @@ -9,5 +9,15 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/gt/#match-document-fields} */ function test0() { - // TODO: no schema found for gt.Match Document Fields + type inventory = { + price: bson.Double | number; + qty: bson.Int32 | number | undefined; + quantity: bson.Int32 | number | undefined; + sale: boolean; + tags: Array; + }; + + const aggregation: schema.Pipeline = [ + { $match: { qty: { $gt: 20 } } }, + ]; } diff --git a/packages/mql-typescript/tests/query/gte.spec.ts b/packages/mql-typescript/tests/query/gte.spec.ts index c35a6c97..15369829 100644 --- a/packages/mql-typescript/tests/query/gte.spec.ts +++ b/packages/mql-typescript/tests/query/gte.spec.ts @@ -9,5 +9,15 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/gte/#match-document-fields} */ function test0() { - // TODO: no schema found for gte.Match Document Fields + type inventory = { + price: bson.Double | number; + qty: bson.Int32 | number | undefined; + quantity: bson.Int32 | number | undefined; + sale: boolean; + tags: Array; + }; + + const aggregation: schema.Pipeline = [ + { $match: { qty: { $gte: 20 } } }, + ]; } diff --git a/packages/mql-typescript/tests/query/in.spec.ts b/packages/mql-typescript/tests/query/in.spec.ts index 1cdf5417..608e0e86 100644 --- a/packages/mql-typescript/tests/query/in.spec.ts +++ b/packages/mql-typescript/tests/query/in.spec.ts @@ -9,7 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/in/#use-the--in-operator-to-match-values} */ function test0() { - // TODO: no schema found for in.Use the $in Operator to Match Values in an Array + // TODO: no schema found for in.Use the $in Operator to Match Values in an Array: // TODO: No schema found in docs } /** @@ -17,5 +17,5 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/in/#use-the--in-operator-with-a-regular-expression} */ function test1() { - // TODO: no schema found for in.Use the $in Operator with a Regular Expression + // TODO: no schema found for in.Use the $in Operator with a Regular Expression: // TODO: No schema found in docs } diff --git a/packages/mql-typescript/tests/query/jsonSchema.spec.ts b/packages/mql-typescript/tests/query/jsonSchema.spec.ts index 89c37b89..40c0f99b 100644 --- a/packages/mql-typescript/tests/query/jsonSchema.spec.ts +++ b/packages/mql-typescript/tests/query/jsonSchema.spec.ts @@ -9,5 +9,37 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/jsonSchema/#syntax} */ function test0() { - // TODO: no schema found for jsonSchema.Example + type TestCollection = { + name: string; + major: string; + gpa: bson.Double | number; + address: { + street: string; + zipcode: string; + }; + }; + + const aggregation: schema.Pipeline = [ + { + $match: { + $jsonSchema: { + required: ['name', 'major', 'gpa', 'address'], + properties: { + name: { + bsonType: 'string', + description: 'must be a string and is required', + }, + address: { + bsonType: 'object', + required: ['zipcode'], + properties: { + street: { bsonType: 'string' }, + zipcode: { bsonType: 'string' }, + }, + }, + }, + }, + }, + }, + ]; } diff --git a/packages/mql-typescript/tests/query/lt.spec.ts b/packages/mql-typescript/tests/query/lt.spec.ts index d460dc48..112f5502 100644 --- a/packages/mql-typescript/tests/query/lt.spec.ts +++ b/packages/mql-typescript/tests/query/lt.spec.ts @@ -9,5 +9,15 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/lt/#match-document-fields} */ function test0() { - // TODO: no schema found for lt.Match Document Fields + type inventory = { + price: bson.Double | number; + qty: bson.Int32 | number | undefined; + quantity: bson.Int32 | number | undefined; + sale: boolean; + tags: Array; + }; + + const aggregation: schema.Pipeline = [ + { $match: { qty: { $lt: 20 } } }, + ]; } diff --git a/packages/mql-typescript/tests/query/lte.spec.ts b/packages/mql-typescript/tests/query/lte.spec.ts index 096d0d2f..88f05277 100644 --- a/packages/mql-typescript/tests/query/lte.spec.ts +++ b/packages/mql-typescript/tests/query/lte.spec.ts @@ -9,5 +9,15 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/lte/#match-document-fields} */ function test0() { - // TODO: no schema found for lte.Match Document Fields + type inventory = { + price: bson.Double | number; + qty: bson.Int32 | number | undefined; + quantity: bson.Int32 | number | undefined; + sale: boolean; + tags: Array; + }; + + const aggregation: schema.Pipeline = [ + { $match: { qty: { $lte: 20 } } }, + ]; } diff --git a/packages/mql-typescript/tests/query/mod.spec.ts b/packages/mql-typescript/tests/query/mod.spec.ts index 82dbde1c..3a56f90b 100644 --- a/packages/mql-typescript/tests/query/mod.spec.ts +++ b/packages/mql-typescript/tests/query/mod.spec.ts @@ -9,7 +9,15 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/mod/#use--mod-to-select-documents} */ function test0() { - // TODO: no schema found for mod.Use $mod to Select Documents + type inventory = { + _id: number; + item: string; + qty: number; + }; + + const aggregation: schema.Pipeline = [ + { $match: { qty: { $mod: [4, 0] } } }, + ]; } /** @@ -17,5 +25,15 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/mod/#floating-point-arguments} */ function test1() { - // TODO: no schema found for mod.Floating Point Arguments + type inventory = { + _id: number; + item: string; + qty: number; + }; + + const aggregation: schema.Pipeline = [ + { $match: { qty: { $mod: [4, 0] } } }, + { $match: { qty: { $mod: [4.5, 0] } } }, + { $match: { qty: { $mod: [4.99, 0] } } }, + ]; } diff --git a/packages/mql-typescript/tests/query/ne.spec.ts b/packages/mql-typescript/tests/query/ne.spec.ts index 06577311..755a939f 100644 --- a/packages/mql-typescript/tests/query/ne.spec.ts +++ b/packages/mql-typescript/tests/query/ne.spec.ts @@ -9,5 +9,5 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/ne/#match-document-fields} */ function test0() { - // TODO: no schema found for ne.Match Document Fields + // TODO: no schema found for ne.Match Document Fields: // TODO: No schema found in docs } diff --git a/packages/mql-typescript/tests/query/near.spec.ts b/packages/mql-typescript/tests/query/near.spec.ts index 47fd8537..4b76e949 100644 --- a/packages/mql-typescript/tests/query/near.spec.ts +++ b/packages/mql-typescript/tests/query/near.spec.ts @@ -9,5 +9,24 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/near/#query-on-geojson-data} */ function test0() { - // TODO: no schema found for near.Query on GeoJSON Data + type places = { + location: { + type: string; + coordinates: Array; + }; + }; + + const aggregation: schema.Pipeline = [ + { + $match: { + location: { + $near: { + $geometry: { type: 'Point', coordinates: [-73.9667, 40.78] }, + $minDistance: 1000, + $maxDistance: 5000, + }, + }, + }, + }, + ]; } diff --git a/packages/mql-typescript/tests/query/nearSphere.spec.ts b/packages/mql-typescript/tests/query/nearSphere.spec.ts index 3feffba7..3c9e0804 100644 --- a/packages/mql-typescript/tests/query/nearSphere.spec.ts +++ b/packages/mql-typescript/tests/query/nearSphere.spec.ts @@ -9,5 +9,24 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/nearSphere/#specify-center-point-using-geojson} */ function test0() { - // TODO: no schema found for nearSphere.Specify Center Point Using GeoJSON + type places = { + location: { + type: string; + coordinates: Array; + }; + }; + + const aggregation: schema.Pipeline = [ + { + $match: { + location: { + $nearSphere: { + $geometry: { type: 'Point', coordinates: [-73.9667, 40.78] }, + $minDistance: 1000, + $maxDistance: 5000, + }, + }, + }, + }, + ]; } diff --git a/packages/mql-typescript/tests/query/nin.spec.ts b/packages/mql-typescript/tests/query/nin.spec.ts index ce445116..bb590c7b 100644 --- a/packages/mql-typescript/tests/query/nin.spec.ts +++ b/packages/mql-typescript/tests/query/nin.spec.ts @@ -9,7 +9,17 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/nin/#select-on-unmatching-documents} */ function test0() { - // TODO: no schema found for nin.Select on Unmatching Documents + type inventory = { + price: bson.Double | number; + qty: bson.Int32 | number | undefined; + quantity: bson.Int32 | number | undefined; + sale: boolean; + tags: Array; + }; + + const aggregation: schema.Pipeline = [ + { $match: { quantity: { $nin: [5, 15] } } }, + ]; } /** @@ -17,5 +27,15 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/nin/#select-on-elements-not-in-an-array} */ function test1() { - // TODO: no schema found for nin.Select on Elements Not in an Array + type inventory = { + price: bson.Double | number; + qty: bson.Int32 | number | undefined; + quantity: bson.Int32 | number | undefined; + sale: boolean; + tags: Array; + }; + + const aggregation: schema.Pipeline = [ + { $match: { tags: { $nin: ['school'] } } }, + ]; } diff --git a/packages/mql-typescript/tests/query/nor.spec.ts b/packages/mql-typescript/tests/query/nor.spec.ts index 472ca28e..312c772d 100644 --- a/packages/mql-typescript/tests/query/nor.spec.ts +++ b/packages/mql-typescript/tests/query/nor.spec.ts @@ -9,7 +9,17 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/nor/#-nor-query-with-two-expressions} */ function test0() { - // TODO: no schema found for nor.Query with Two Expressions + type inventory = { + price: bson.Double | number; + qty: bson.Int32 | number | undefined; + quantity: bson.Int32 | number | undefined; + sale: boolean; + tags: Array; + }; + + const aggregation: schema.Pipeline = [ + { $match: { $nor: [{ price: 1.99 }, { sale: true }] } }, + ]; } /** @@ -17,7 +27,19 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/nor/#-nor-and-additional-comparisons} */ function test1() { - // TODO: no schema found for nor.Additional Comparisons + type inventory = { + price: bson.Double | number; + qty: bson.Int32 | number | undefined; + quantity: bson.Int32 | number | undefined; + sale: boolean; + tags: Array; + }; + + const aggregation: schema.Pipeline = [ + { + $match: { $nor: [{ price: 1.99 }, { qty: { $lt: 20 } }, { sale: true }] }, + }, + ]; } /** @@ -25,5 +47,24 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/nor/#-nor-and--exists} */ function test2() { - // TODO: no schema found for nor.$nor and $exists + type inventory = { + price: bson.Double | number; + qty: bson.Int32 | number | undefined; + quantity: bson.Int32 | number | undefined; + sale: boolean; + tags: Array; + }; + + const aggregation: schema.Pipeline = [ + { + $match: { + $nor: [ + { price: 1.99 }, + { price: { $exists: false } }, + { sale: true }, + { sale: { $exists: false } }, + ], + }, + }, + ]; } diff --git a/packages/mql-typescript/tests/query/not.spec.ts b/packages/mql-typescript/tests/query/not.spec.ts index aca76b82..83ac674f 100644 --- a/packages/mql-typescript/tests/query/not.spec.ts +++ b/packages/mql-typescript/tests/query/not.spec.ts @@ -9,7 +9,17 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/not/#syntax} */ function test0() { - // TODO: no schema found for not.Syntax + type inventory = { + price: bson.Double | number; + qty: bson.Int32 | number | undefined; + quantity: bson.Int32 | number | undefined; + sale: boolean; + tags: Array; + }; + + const aggregation: schema.Pipeline = [ + { $match: { price: { $not: { $gt: 1.99 } } } }, + ]; } /** @@ -17,5 +27,15 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/not/#-not-and-regular-expressions} */ function test1() { - // TODO: no schema found for not.Regular Expressions + type inventory = { + price: bson.Double | number; + qty: bson.Int32 | number | undefined; + quantity: bson.Int32 | number | undefined; + sale: boolean; + tags: Array; + }; + + const aggregation: schema.Pipeline = [ + { $match: { price: { $not: new bson.BSONRegExp('^p.*', '') } } }, + ]; } diff --git a/packages/mql-typescript/tests/query/or.spec.ts b/packages/mql-typescript/tests/query/or.spec.ts index ca909994..598e19c3 100644 --- a/packages/mql-typescript/tests/query/or.spec.ts +++ b/packages/mql-typescript/tests/query/or.spec.ts @@ -9,7 +9,17 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/or/#-or-clauses-and-indexes} */ function test0() { - // TODO: no schema found for or.$or Clauses + type inventory = { + price: bson.Double | number; + qty: bson.Int32 | number | undefined; + quantity: bson.Int32 | number | undefined; + sale: boolean; + tags: Array; + }; + + const aggregation: schema.Pipeline = [ + { $match: { $or: [{ quantity: { $lt: 20 } }, { price: 10 }] } }, + ]; } /** @@ -17,5 +27,18 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/or/#error-handling} */ function test1() { - // TODO: no schema found for or.Error Handling + type example = { + x: bson.Int32 | number; + }; + + const aggregation: schema.Pipeline = [ + { + $match: { + $or: [ + { x: { $eq: 0 } }, + { $expr: { $eq: [{ $divide: [1, '$x'] }, 3] } }, + ], + }, + }, + ]; } diff --git a/packages/mql-typescript/tests/query/rand.spec.ts b/packages/mql-typescript/tests/query/rand.spec.ts index 0698736e..56f9edf3 100644 --- a/packages/mql-typescript/tests/query/rand.spec.ts +++ b/packages/mql-typescript/tests/query/rand.spec.ts @@ -9,5 +9,5 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/rand/#select-random-items-from-a-collection} */ function test0() { - // TODO: no schema found for rand.Select Random Items From a Collection + // TODO: no schema found for rand.Select Random Items From a Collection: // TODO: No schema found in docs } diff --git a/packages/mql-typescript/tests/query/regex.spec.ts b/packages/mql-typescript/tests/query/regex.spec.ts index 7c1265d6..aa0f1fcf 100644 --- a/packages/mql-typescript/tests/query/regex.spec.ts +++ b/packages/mql-typescript/tests/query/regex.spec.ts @@ -9,7 +9,15 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/regex/#perform-a-like-match} */ function test0() { - // TODO: no schema found for regex.Perform a LIKE Match + type products = { + _id: number; + sku: string; + description: string; + }; + + const aggregation: schema.Pipeline = [ + { $match: { sku: { $regex: new bson.BSONRegExp('789$', '') } } }, + ]; } /** @@ -17,5 +25,13 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/regex/#perform-case-insensitive-regular-expression-match} */ function test1() { - // TODO: no schema found for regex.Perform Case-Insensitive Regular Expression Match + type products = { + _id: number; + sku: string; + description: string; + }; + + const aggregation: schema.Pipeline = [ + { $match: { sku: { $regex: new bson.BSONRegExp('^ABC', 'i') } } }, + ]; } diff --git a/packages/mql-typescript/tests/query/sampleRate.spec.ts b/packages/mql-typescript/tests/query/sampleRate.spec.ts index b6ed203b..86ad9950 100644 --- a/packages/mql-typescript/tests/query/sampleRate.spec.ts +++ b/packages/mql-typescript/tests/query/sampleRate.spec.ts @@ -9,5 +9,12 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/sampleRate/#examples} */ function test0() { - // TODO: no schema found for sampleRate.Example + type TestCollection = { + _id: bson.ObjectId; + }; + + const aggregation: schema.Pipeline = [ + { $match: { $sampleRate: 0.33 } }, + { $count: 'numMatches' }, + ]; } diff --git a/packages/mql-typescript/tests/query/size.spec.ts b/packages/mql-typescript/tests/query/size.spec.ts index 6959c4ec..f8670203 100644 --- a/packages/mql-typescript/tests/query/size.spec.ts +++ b/packages/mql-typescript/tests/query/size.spec.ts @@ -9,5 +9,15 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/tutorial/query-arrays/#query-an-array-by-array-length} */ function test0() { - // TODO: no schema found for size.Query an Array by Array Length + type inventory = { + price: bson.Double | number; + qty: bson.Int32 | number | undefined; + quantity: bson.Int32 | number | undefined; + sale: boolean; + tags: Array; + }; + + const aggregation: schema.Pipeline = [ + { $match: { tags: { $size: 3 } } }, + ]; } diff --git a/packages/mql-typescript/tests/query/text.spec.ts b/packages/mql-typescript/tests/query/text.spec.ts index 6ba3ae50..b2e5cd28 100644 --- a/packages/mql-typescript/tests/query/text.spec.ts +++ b/packages/mql-typescript/tests/query/text.spec.ts @@ -9,7 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/text/#search-for-a-single-word} */ function test0() { - // TODO: no schema found for text.Search for a Single Word + // TODO: no schema found for text.Search for a Single Word: // TODO: No schema found in docs } /** @@ -17,7 +17,7 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/text/#search-for-a-single-word} */ function test1() { - // TODO: no schema found for text.Match Any of the Search Terms + // TODO: no schema found for text.Match Any of the Search Terms: // TODO: No schema found in docs } /** @@ -25,7 +25,7 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/text/#search-a-different-language} */ function test2() { - // TODO: no schema found for text.Search a Different Language + // TODO: no schema found for text.Search a Different Language: // TODO: No schema found in docs } /** @@ -33,7 +33,7 @@ function test2() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/text/#case-and-diacritic-insensitive-search} */ function test3() { - // TODO: no schema found for text.Case and Diacritic Insensitive Search + // TODO: no schema found for text.Case and Diacritic Insensitive Search: // TODO: No schema found in docs } /** @@ -41,7 +41,7 @@ function test3() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/text/#perform-case-sensitive-search} */ function test4() { - // TODO: no schema found for text.Perform Case Sensitive Search + // TODO: no schema found for text.Perform Case Sensitive Search: // TODO: No schema found in docs } /** @@ -49,7 +49,7 @@ function test4() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/text/#perform-case-sensitive-search} */ function test5() { - // TODO: no schema found for text.Diacritic Sensitive Search + // TODO: no schema found for text.Diacritic Sensitive Search: // TODO: No schema found in docs } /** @@ -57,5 +57,5 @@ function test5() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/text/#perform-case-sensitive-search} */ function test6() { - // TODO: no schema found for text.Text Search Score Examples + // TODO: no schema found for text.Text Search Score Examples: // TODO: No schema found in docs } diff --git a/packages/mql-typescript/tests/query/type.spec.ts b/packages/mql-typescript/tests/query/type.spec.ts index 1049ce04..91c08d80 100644 --- a/packages/mql-typescript/tests/query/type.spec.ts +++ b/packages/mql-typescript/tests/query/type.spec.ts @@ -9,7 +9,25 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/type/#querying-by-data-type} */ function test0() { - // TODO: no schema found for type.Querying by Data Type + type addressBook = { + _id: bson.Int32 | number; + address: string; + zipCode: + | string + | bson.Int32 + | number + | bson.Double + | number + | Array; + }; + + const aggregation: schema.Pipeline = [ + { $match: { zipCode: { $type: [2] } } }, + { $match: { zipCode: { $type: ['string'] } } }, + { $match: { zipCode: { $type: [1] } } }, + { $match: { zipCode: { $type: ['double'] } } }, + { $match: { zipCode: { $type: ['number'] } } }, + ]; } /** @@ -17,7 +35,7 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/type/#querying-by-multiple-data-type} */ function test1() { - // TODO: no schema found for type.Querying by Multiple Data Type + // TODO: no schema found for type.Querying by Multiple Data Type: // TODO: No schema found in docs } /** @@ -25,7 +43,36 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/type/#querying-by-minkey-and-maxkey} */ function test2() { - // TODO: no schema found for type.Querying by MinKey and MaxKey + type restaurants = { + _id: number; + address: { + building: string; + coord: Array; + street: string; + zipcode: string; + }; + borough: string; + cuisine: string; + grades: Array<{ + date: Date; + grade: string | bson.MinKey; + score: number; + }>; + name: string; + restaurant_id: string; + }; + + const aggregation: schema.Pipeline = [ + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). + */ + { $match: { zipCode: { $type: ['minKey'] } } } as any, + + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). + */ + { $match: { zipCode: { $type: ['maxKey'] } } } as any, + ]; } /** @@ -33,5 +80,19 @@ function test2() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/type/#querying-by-array-type} */ function test3() { - // TODO: no schema found for type.Querying by Array Type + type addressBook = { + _id: bson.Int32 | number; + address: string; + zipCode: + | string + | bson.Int32 + | number + | bson.Double + | number + | Array; + }; + + const aggregation: schema.Pipeline = [ + { $match: { zipCode: { $type: ['array'] } } }, + ]; } diff --git a/packages/mql-typescript/tests/query/where.spec.ts b/packages/mql-typescript/tests/query/where.spec.ts index 662dc3b8..e4b7bcd2 100644 --- a/packages/mql-typescript/tests/query/where.spec.ts +++ b/packages/mql-typescript/tests/query/where.spec.ts @@ -9,5 +9,30 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/where/#example} */ function test0() { - // TODO: no schema found for where.Example + type players = { + _id: number; + name: string; + username: string; + first_login: string; + }; + + const aggregation: schema.Pipeline = [ + { + $match: { + $where: + 'function() { return hex_md5(this.name) == "9b53e667f30cd329dca1ec9e6a83e994"}', + }, + }, + { + $match: { + $expr: { + $function: { + body: 'function(name) { return hex_md5(name) == "9b53e667f30cd329dca1ec9e6a83e994";}', + args: ['$name'], + lang: 'js', + }, + }, + }, + }, + ]; } diff --git a/packages/mql-typescript/tests/search/autocomplete.spec.ts b/packages/mql-typescript/tests/search/autocomplete.spec.ts index d9a38516..994da04c 100644 --- a/packages/mql-typescript/tests/search/autocomplete.spec.ts +++ b/packages/mql-typescript/tests/search/autocomplete.spec.ts @@ -9,7 +9,67 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/#basic-example} */ function test0() { - // TODO: no schema found for autocomplete.Basic + type movies = { + _id: { + $oid: string; + }; + title: string; + year: { + $numberInt: string; + }; + runtime: { + $numberInt: string; + }; + released: { + $date: { + $numberLong: string; + }; + }; + poster: string; + plot: string; + fullplot: string; + lastupdated: string; + type: string; + directors: Array; + imdb: { + rating: { + $numberDouble: string; + }; + votes: { + $numberInt: string; + }; + id: { + $numberInt: string; + }; + }; + cast: Array; + countries: Array; + genres: Array; + tomatoes: { + viewer: { + rating: { + $numberDouble: string; + }; + numReviews: { + $numberInt: string; + }; + }; + lastUpdated: { + $date: { + $numberLong: string; + }; + }; + }; + num_mflix_comments: { + $numberInt: string; + }; + }; + + const aggregation: schema.Pipeline = [ + { $search: { autocomplete: { query: 'off', path: 'title' } } }, + { $limit: 10 }, + { $project: { _id: 0, title: 1 } }, + ]; } /** @@ -17,7 +77,75 @@ function test0() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/#fuzzy-example} */ function test1() { - // TODO: no schema found for autocomplete.Fuzzy + type movies = { + _id: { + $oid: string; + }; + title: string; + year: { + $numberInt: string; + }; + runtime: { + $numberInt: string; + }; + released: { + $date: { + $numberLong: string; + }; + }; + poster: string; + plot: string; + fullplot: string; + lastupdated: string; + type: string; + directors: Array; + imdb: { + rating: { + $numberDouble: string; + }; + votes: { + $numberInt: string; + }; + id: { + $numberInt: string; + }; + }; + cast: Array; + countries: Array; + genres: Array; + tomatoes: { + viewer: { + rating: { + $numberDouble: string; + }; + numReviews: { + $numberInt: string; + }; + }; + lastUpdated: { + $date: { + $numberLong: string; + }; + }; + }; + num_mflix_comments: { + $numberInt: string; + }; + }; + + const aggregation: schema.Pipeline = [ + { + $search: { + autocomplete: { + query: 'pre', + path: 'title', + fuzzy: { maxEdits: 1, prefixLength: 1, maxExpansions: 256 }, + }, + }, + }, + { $limit: 10 }, + { $project: { _id: 0, title: 1 } }, + ]; } /** @@ -25,7 +153,71 @@ function test1() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/#simple-any-example} */ function test2() { - // TODO: no schema found for autocomplete.Token Order any + type movies = { + _id: { + $oid: string; + }; + title: string; + year: { + $numberInt: string; + }; + runtime: { + $numberInt: string; + }; + released: { + $date: { + $numberLong: string; + }; + }; + poster: string; + plot: string; + fullplot: string; + lastupdated: string; + type: string; + directors: Array; + imdb: { + rating: { + $numberDouble: string; + }; + votes: { + $numberInt: string; + }; + id: { + $numberInt: string; + }; + }; + cast: Array; + countries: Array; + genres: Array; + tomatoes: { + viewer: { + rating: { + $numberDouble: string; + }; + numReviews: { + $numberInt: string; + }; + }; + lastUpdated: { + $date: { + $numberLong: string; + }; + }; + }; + num_mflix_comments: { + $numberInt: string; + }; + }; + + const aggregation: schema.Pipeline = [ + { + $search: { + autocomplete: { query: 'men with', path: 'title', tokenOrder: 'any' }, + }, + }, + { $limit: 4 }, + { $project: { _id: 0, title: 1 } }, + ]; } /** @@ -33,7 +225,75 @@ function test2() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/#simple-sequential-example} */ function test3() { - // TODO: no schema found for autocomplete.Token Order sequential + type movies = { + _id: { + $oid: string; + }; + title: string; + year: { + $numberInt: string; + }; + runtime: { + $numberInt: string; + }; + released: { + $date: { + $numberLong: string; + }; + }; + poster: string; + plot: string; + fullplot: string; + lastupdated: string; + type: string; + directors: Array; + imdb: { + rating: { + $numberDouble: string; + }; + votes: { + $numberInt: string; + }; + id: { + $numberInt: string; + }; + }; + cast: Array; + countries: Array; + genres: Array; + tomatoes: { + viewer: { + rating: { + $numberDouble: string; + }; + numReviews: { + $numberInt: string; + }; + }; + lastUpdated: { + $date: { + $numberLong: string; + }; + }; + }; + num_mflix_comments: { + $numberInt: string; + }; + }; + + const aggregation: schema.Pipeline = [ + { + $search: { + autocomplete: { + query: 'men with', + path: 'title', + tokenOrder: 'sequential', + }, + }, + }, + { $limit: 4 }, + { $project: { _id: 0, title: 1 } }, + ]; } /** @@ -41,7 +301,79 @@ function test3() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/#highlighting-example} */ function test4() { - // TODO: no schema found for autocomplete.Highlighting + type movies = { + _id: { + $oid: string; + }; + title: string; + year: { + $numberInt: string; + }; + runtime: { + $numberInt: string; + }; + released: { + $date: { + $numberLong: string; + }; + }; + poster: string; + plot: string; + fullplot: string; + lastupdated: string; + type: string; + directors: Array; + imdb: { + rating: { + $numberDouble: string; + }; + votes: { + $numberInt: string; + }; + id: { + $numberInt: string; + }; + }; + cast: Array; + countries: Array; + genres: Array; + tomatoes: { + viewer: { + rating: { + $numberDouble: string; + }; + numReviews: { + $numberInt: string; + }; + }; + lastUpdated: { + $date: { + $numberLong: string; + }; + }; + }; + num_mflix_comments: { + $numberInt: string; + }; + }; + + const aggregation: schema.Pipeline = [ + { + $search: { + autocomplete: { query: 'ger', path: 'title' }, + highlight: { path: 'title' }, + }, + }, + { $limit: 5 }, + { + $project: { + score: { $meta: 'searchScore' }, + _id: 0, + title: 1, + highlights: { $meta: 'searchHighlights' }, + }, + }, + ]; } /** @@ -49,5 +381,75 @@ function test4() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/#search-across-multiple-fields} */ function test5() { - // TODO: no schema found for autocomplete.Across Multiple Fields + type movies = { + _id: { + $oid: string; + }; + title: string; + year: { + $numberInt: string; + }; + runtime: { + $numberInt: string; + }; + released: { + $date: { + $numberLong: string; + }; + }; + poster: string; + plot: string; + fullplot: string; + lastupdated: string; + type: string; + directors: Array; + imdb: { + rating: { + $numberDouble: string; + }; + votes: { + $numberInt: string; + }; + id: { + $numberInt: string; + }; + }; + cast: Array; + countries: Array; + genres: Array; + tomatoes: { + viewer: { + rating: { + $numberDouble: string; + }; + numReviews: { + $numberInt: string; + }; + }; + lastUpdated: { + $date: { + $numberLong: string; + }; + }; + }; + num_mflix_comments: { + $numberInt: string; + }; + }; + + const aggregation: schema.Pipeline = [ + { + $search: { + compound: { + should: [ + { autocomplete: { query: 'inter', path: 'title' } }, + { autocomplete: { query: 'inter', path: 'plot' } }, + ], + minimumShouldMatch: 1, + }, + }, + }, + { $limit: 10 }, + { $project: { _id: 0, title: 1, plot: 1 } }, + ]; } diff --git a/packages/mql-typescript/tests/search/compound.spec.ts b/packages/mql-typescript/tests/search/compound.spec.ts index bc81fc20..0078aaf3 100644 --- a/packages/mql-typescript/tests/search/compound.spec.ts +++ b/packages/mql-typescript/tests/search/compound.spec.ts @@ -9,7 +9,24 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/compound/#must-and-mustnot-example} */ function test0() { - // TODO: no schema found for compound.must and mustNot + type TestCollection = { + _id: number; + type: string; + description: string; + category: string; + in_stock: boolean; + }; + + const aggregation: schema.Pipeline = [ + { + $search: { + compound: { + must: [{ text: { query: 'varieties', path: 'description' } }], + mustNot: [{ text: { query: 'apples', path: 'description' } }], + }, + }, + }, + ]; } /** @@ -17,7 +34,25 @@ function test0() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/compound/#must-and-should-example} */ function test1() { - // TODO: no schema found for compound.must and should + type TestCollection = { + _id: number; + type: string; + description: string; + category: string; + in_stock: boolean; + }; + + const aggregation: schema.Pipeline = [ + { + $search: { + compound: { + must: [{ text: { query: 'varieties', path: 'description' } }], + should: [{ text: { query: 'Fuji', path: 'description' } }], + }, + }, + }, + { $project: { score: { $meta: 'searchScore' } } }, + ]; } /** @@ -25,7 +60,28 @@ function test1() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/compound/#minimumshouldmatch-example} */ function test2() { - // TODO: no schema found for compound.minimumShouldMatch + type TestCollection = { + _id: number; + type: string; + description: string; + category: string; + in_stock: boolean; + }; + + const aggregation: schema.Pipeline = [ + { + $search: { + compound: { + must: [{ text: { query: 'varieties', path: 'description' } }], + should: [ + { text: { query: 'Fuji', path: 'description' } }, + { text: { query: 'Golden Delicious', path: 'description' } }, + ], + minimumShouldMatch: 1, + }, + }, + }, + ]; } /** @@ -33,7 +89,25 @@ function test2() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/compound/#filter-examples} */ function test3() { - // TODO: no schema found for compound.Filter + type TestCollection = { + _id: number; + type: string; + description: string; + category: string; + in_stock: boolean; + }; + + const aggregation: schema.Pipeline = [ + { + $search: { + compound: { + must: [{ text: { query: 'varieties', path: 'description' } }], + should: [{ text: { query: 'banana', path: 'description' } }], + filter: [{ text: { query: 'granny', path: 'description' } }], + }, + }, + }, + ]; } /** @@ -41,5 +115,32 @@ function test3() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/compound/#nested-example} */ function test4() { - // TODO: no schema found for compound.Nested + type TestCollection = { + _id: number; + type: string; + description: string; + category: string; + in_stock: boolean; + }; + + const aggregation: schema.Pipeline = [ + { + $search: { + compound: { + should: [ + { text: { query: 'apple', path: 'type' } }, + { + compound: { + must: [ + { text: { query: 'organic', path: 'category' } }, + { equals: { value: true, path: 'in_stock' } }, + ], + }, + }, + ], + minimumShouldMatch: 1, + }, + }, + }, + ]; } diff --git a/packages/mql-typescript/tests/search/embeddedDocument.spec.ts b/packages/mql-typescript/tests/search/embeddedDocument.spec.ts index fd4b7e6b..a7bd6679 100644 --- a/packages/mql-typescript/tests/search/embeddedDocument.spec.ts +++ b/packages/mql-typescript/tests/search/embeddedDocument.spec.ts @@ -9,7 +9,76 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/embedded-document/#index-definition} */ function test0() { - // TODO: no schema found for embeddedDocument.Basic + type sales = { + _id: { + $oid: string; + }; + saleDate: { + $date: { + $numberLong: string; + }; + }; + items: Array<{ + name: string; + tags: Array; + price: { + $numberDecimal: string; + }; + quantity: { + $numberInt: string; + }; + }>; + storeLocation: string; + customer: { + gender: string; + age: { + $numberInt: string; + }; + email: string; + satisfaction: { + $numberInt: string; + }; + }; + couponUsed: boolean; + purchaseMethod: string; + }; + + const aggregation: schema.Pipeline = [ + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). + */ + { + $search: { + embeddedDocument: { + path: 'items', + operator: { + compound: { + must: [{ text: { path: 'items.tags', query: 'school' } }], + should: [{ text: { path: 'items.name', query: 'backpack' } }], + }, + }, + score: { embedded: { aggregate: 'mean' } }, + }, + }, + } as any, + + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). + */ + { $limit: 5 } as any, + + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). + */ + { + $project: { + _id: 0, + 'items.name': 1, + 'items.tags': 1, + score: { $meta: 'searchScore' }, + }, + } as any, + ]; } /** @@ -17,7 +86,65 @@ function test0() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/embedded-document/#facet-query} */ function test1() { - // TODO: no schema found for embeddedDocument.Facet + type sales = { + _id: { + $oid: string; + }; + saleDate: { + $date: { + $numberLong: string; + }; + }; + items: Array<{ + name: string; + tags: Array; + price: { + $numberDecimal: string; + }; + quantity: { + $numberInt: string; + }; + }>; + storeLocation: string; + customer: { + gender: string; + age: { + $numberInt: string; + }; + email: string; + satisfaction: { + $numberInt: string; + }; + }; + couponUsed: boolean; + purchaseMethod: string; + }; + + const aggregation: schema.Pipeline = [ + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). + */ + { + $searchMeta: { + facet: { + operator: { + embeddedDocument: { + path: 'items', + operator: { + compound: { + must: [{ text: { path: 'items.tags', query: 'school' } }], + should: [{ text: { path: 'items.name', query: 'backpack' } }], + }, + }, + }, + }, + facets: { + purchaseMethodFacet: { type: 'string', path: 'purchaseMethod' }, + }, + }, + }, + } as any, + ]; } /** @@ -25,7 +152,71 @@ function test1() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/embedded-document/#query-and-sort} */ function test2() { - // TODO: no schema found for embeddedDocument.Query and Sort + type sales = { + _id: { + $oid: string; + }; + saleDate: { + $date: { + $numberLong: string; + }; + }; + items: Array<{ + name: string; + tags: Array; + price: { + $numberDecimal: string; + }; + quantity: { + $numberInt: string; + }; + }>; + storeLocation: string; + customer: { + gender: string; + age: { + $numberInt: string; + }; + email: string; + satisfaction: { + $numberInt: string; + }; + }; + couponUsed: boolean; + purchaseMethod: string; + }; + + const aggregation: schema.Pipeline = [ + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). + */ + { + $search: { + embeddedDocument: { + path: 'items', + operator: { text: { path: 'items.name', query: 'laptop' } }, + }, + sort: { 'items.tags': 1 }, + }, + } as any, + + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). + */ + { $limit: 5 } as any, + + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). + */ + { + $project: { + _id: 0, + 'items.name': 1, + 'items.tags': 1, + score: { $meta: 'searchScore' }, + }, + } as any, + ]; } /** @@ -33,5 +224,79 @@ function test2() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/embedded-document/#query-for-matching-embedded-documents-only} */ function test3() { - // TODO: no schema found for embeddedDocument.Query for Matching Embedded Documents Only + type sales = { + _id: { + $oid: string; + }; + saleDate: { + $date: { + $numberLong: string; + }; + }; + items: Array<{ + name: string; + tags: Array; + price: { + $numberDecimal: string; + }; + quantity: { + $numberInt: string; + }; + }>; + storeLocation: string; + customer: { + gender: string; + age: { + $numberInt: string; + }; + email: string; + satisfaction: { + $numberInt: string; + }; + }; + couponUsed: boolean; + purchaseMethod: string; + }; + + const aggregation: schema.Pipeline = [ + { + $search: { + embeddedDocument: { + path: 'items', + operator: { + compound: { + must: [ + { range: { path: 'items.quantity', gt: 2 } }, + { exists: { path: 'items.price' } }, + { text: { path: 'items.tags', query: 'school' } }, + ], + }, + }, + }, + }, + }, + { $limit: 2 }, + + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). + */ + { + $project: { + _id: 0, + storeLocation: 1, + items: { + $filter: { + input: '$items', + cond: { + $and: [ + { $ifNull: ['$$this.price', 'false'] }, + { $gt: ['$$this.quantity', 2] }, + { $in: ['office', '$$this.tags'] }, + ], + }, + }, + }, + }, + } as any, + ]; } diff --git a/packages/mql-typescript/tests/search/equals.spec.ts b/packages/mql-typescript/tests/search/equals.spec.ts index baa332d2..4f0c9d37 100644 --- a/packages/mql-typescript/tests/search/equals.spec.ts +++ b/packages/mql-typescript/tests/search/equals.spec.ts @@ -9,7 +9,26 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/equals/#boolean-examples} */ function test0() { - // TODO: no schema found for equals.Boolean + type users = { + _id: bson.ObjectId; + name: string; + verified_user: boolean; + account: { + new_user: boolean; + active_user: boolean; + }; + teammates: Array; + region: string; + account_created: Date; + employee_number: number; + uuid: bson.Binary; + job_title: null | string; + }; + + const aggregation: schema.Pipeline = [ + { $search: { equals: { path: 'verified_user', value: true } } }, + { $project: { name: 1, _id: 0, score: { $meta: 'searchScore' } } }, + ]; } /** @@ -17,7 +36,32 @@ function test0() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/equals/#objectid-example} */ function test1() { - // TODO: no schema found for equals.ObjectId + type users = { + _id: bson.ObjectId; + name: string; + verified_user: boolean; + account: { + new_user: boolean; + active_user: boolean; + }; + teammates: Array; + region: string; + account_created: Date; + employee_number: number; + uuid: bson.Binary; + job_title: null | string; + }; + + const aggregation: schema.Pipeline = [ + { + $search: { + equals: { + path: 'teammates', + value: bson.ObjectId.createFromHexString('5a9427648b0beebeb69589a1'), + }, + }, + }, + ]; } /** @@ -25,7 +69,32 @@ function test1() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/equals/#date-example} */ function test2() { - // TODO: no schema found for equals.Date + type users = { + _id: bson.ObjectId; + name: string; + verified_user: boolean; + account: { + new_user: boolean; + active_user: boolean; + }; + teammates: Array; + region: string; + account_created: Date; + employee_number: number; + uuid: bson.Binary; + job_title: null | string; + }; + + const aggregation: schema.Pipeline = [ + { + $search: { + equals: { + path: 'account_created', + value: new Date('2022-05-04T05:01:08.000Z'), + }, + }, + }, + ]; } /** @@ -33,7 +102,25 @@ function test2() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/equals/#number-example} */ function test3() { - // TODO: no schema found for equals.Number + type users = { + _id: bson.ObjectId; + name: string; + verified_user: boolean; + account: { + new_user: boolean; + active_user: boolean; + }; + teammates: Array; + region: string; + account_created: Date; + employee_number: number; + uuid: bson.Binary; + job_title: null | string; + }; + + const aggregation: schema.Pipeline = [ + { $search: { equals: { path: 'employee_number', value: 259 } } }, + ]; } /** @@ -41,7 +128,25 @@ function test3() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/equals/#string-example} */ function test4() { - // TODO: no schema found for equals.String + type users = { + _id: bson.ObjectId; + name: string; + verified_user: boolean; + account: { + new_user: boolean; + active_user: boolean; + }; + teammates: Array; + region: string; + account_created: Date; + employee_number: number; + uuid: bson.Binary; + job_title: null | string; + }; + + const aggregation: schema.Pipeline = [ + { $search: { equals: { path: 'name', value: 'jim hall' } } }, + ]; } /** @@ -49,7 +154,32 @@ function test4() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/equals/#uuid-example} */ function test5() { - // TODO: no schema found for equals.UUID + type users = { + _id: bson.ObjectId; + name: string; + verified_user: boolean; + account: { + new_user: boolean; + active_user: boolean; + }; + teammates: Array; + region: string; + account_created: Date; + employee_number: number; + uuid: bson.Binary; + job_title: null | string; + }; + + const aggregation: schema.Pipeline = [ + { + $search: { + equals: { + path: 'uuid', + value: bson.Binary.createFromBase64('+sMiYLURTGmEhaK+W33ang==', 4), + }, + }, + }, + ]; } /** @@ -57,5 +187,23 @@ function test5() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/equals/#null-example} */ function test6() { - // TODO: no schema found for equals.Null + type users = { + _id: bson.ObjectId; + name: string; + verified_user: boolean; + account: { + new_user: boolean; + active_user: boolean; + }; + teammates: Array; + region: string; + account_created: Date; + employee_number: number; + uuid: bson.Binary; + job_title: null | string; + }; + + const aggregation: schema.Pipeline = [ + { $search: { equals: { path: 'job_title', value: null } } }, + ]; } diff --git a/packages/mql-typescript/tests/search/exists.spec.ts b/packages/mql-typescript/tests/search/exists.spec.ts index 2ada1b51..a316f3dd 100644 --- a/packages/mql-typescript/tests/search/exists.spec.ts +++ b/packages/mql-typescript/tests/search/exists.spec.ts @@ -9,7 +9,20 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/exists/#basic-example} */ function test0() { - // TODO: no schema found for exists.Basic + type TestCollection = { + _id: number; + type: string; + description: string; + quantities: { + lemons: number; + oranges: number; + grapefruit: number; + }; + }; + + const aggregation: schema.Pipeline = [ + { $search: { exists: { path: 'type' } } }, + ]; } /** @@ -17,7 +30,23 @@ function test0() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/exists/#embedded-example} */ function test1() { - // TODO: no schema found for exists.Embedded + type TestCollection = { + _id: number; + type: string; + description: string; + quantities: { + lemons: number; + oranges: number; + grapefruit: number; + }; + }; + + const aggregation: schema.Pipeline = [ + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). + */ + { $search: { exists: { path: 'quantities.lemons' } } } as any, + ]; } /** @@ -25,5 +54,28 @@ function test1() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/exists/#compound-example} */ function test2() { - // TODO: no schema found for exists.Compound + type TestCollection = { + _id: number; + type: string; + description: string; + quantities: { + lemons: number; + oranges: number; + grapefruit: number; + }; + }; + + const aggregation: schema.Pipeline = [ + { + $search: { + compound: { + must: [ + { exists: { path: 'type' } }, + { text: { query: 'apple', path: 'type' } }, + ], + should: { text: { query: 'fuji', path: 'description' } }, + }, + }, + }, + ]; } diff --git a/packages/mql-typescript/tests/search/facet.spec.ts b/packages/mql-typescript/tests/search/facet.spec.ts index 8991cfa9..48a9087e 100644 --- a/packages/mql-typescript/tests/search/facet.spec.ts +++ b/packages/mql-typescript/tests/search/facet.spec.ts @@ -9,7 +9,94 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/facet/#examples} */ function test0() { - // TODO: no schema found for facet.Facet + type movies = { + _id: { + $oid: string; + }; + title: string; + year: { + $numberInt: string; + }; + runtime: { + $numberInt: string; + }; + released: { + $date: { + $numberLong: string; + }; + }; + poster: string; + plot: string; + fullplot: string; + lastupdated: string; + type: string; + directors: Array; + imdb: { + rating: { + $numberDouble: string; + }; + votes: { + $numberInt: string; + }; + id: { + $numberInt: string; + }; + }; + cast: Array; + countries: Array; + genres: Array; + tomatoes: { + viewer: { + rating: { + $numberDouble: string; + }; + numReviews: { + $numberInt: string; + }; + }; + lastUpdated: { + $date: { + $numberLong: string; + }; + }; + }; + num_mflix_comments: { + $numberInt: string; + }; + }; + + const aggregation: schema.Pipeline = [ + { + $search: { + facet: { + operator: { + near: { + path: 'released', + origin: new Date('1999-07-01T00:00:00.000Z'), + pivot: 7776000000, + }, + }, + facets: { genresFacet: { type: 'string', path: 'genres' } }, + }, + }, + }, + { $limit: 2 }, + + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (this uses $$SEARCH_META, which is a synthetic field not available statically). + */ + { + $facet: { + docs: [{ $project: { title: 1, released: 1 } }], + meta: [{ $replaceWith: '$$SEARCH_META' }, { $limit: 1 }], + }, + } as any, + + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (this uses $$SEARCH_META, which is a synthetic field not available statically). + */ + { $set: { meta: { $arrayElemAt: ['$meta', 0] } } } as any, + ]; } /** @@ -17,7 +104,93 @@ function test0() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/facet/#multi-select-faceting-example} */ function test1() { - // TODO: no schema found for facet.Multi-Select Faceting Example + type movies = { + _id: { + $oid: string; + }; + title: string; + year: { + $numberInt: string; + }; + runtime: { + $numberInt: string; + }; + released: { + $date: { + $numberLong: string; + }; + }; + poster: string; + plot: string; + fullplot: string; + lastupdated: string; + type: string; + directors: Array; + imdb: { + rating: { + $numberDouble: string; + }; + votes: { + $numberInt: string; + }; + id: { + $numberInt: string; + }; + }; + cast: Array; + countries: Array; + genres: Array; + tomatoes: { + viewer: { + rating: { + $numberDouble: string; + }; + numReviews: { + $numberInt: string; + }; + }; + lastUpdated: { + $date: { + $numberLong: string; + }; + }; + }; + num_mflix_comments: { + $numberInt: string; + }; + }; + + const aggregation: schema.Pipeline = [ + { + $searchMeta: { + facet: { + operator: { + compound: { + must: [{ text: { path: 'description', query: 'new york city' } }], + filter: [ + { + equals: { + path: 'cancellation_policy', + value: 'moderate', + doesNotAffect: 'cancellationFacet', + }, + }, + ], + }, + }, + facets: { + accommodatesFacet: { + path: 'accommodates', + type: 'number', + boundaries: [1, 2, 4, 8], + }, + cancellationFacet: { path: 'cancellation_policy', type: 'string' }, + roomTypeFacet: { path: 'room_type', type: 'string' }, + }, + }, + }, + }, + ]; } /** @@ -25,5 +198,91 @@ function test1() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/facet/#inter-facet-filter-exclusion-example} */ function test2() { - // TODO: no schema found for facet.Inter-Facet Filter Exclusion Example + type movies = { + _id: { + $oid: string; + }; + title: string; + year: { + $numberInt: string; + }; + runtime: { + $numberInt: string; + }; + released: { + $date: { + $numberLong: string; + }; + }; + poster: string; + plot: string; + fullplot: string; + lastupdated: string; + type: string; + directors: Array; + imdb: { + rating: { + $numberDouble: string; + }; + votes: { + $numberInt: string; + }; + id: { + $numberInt: string; + }; + }; + cast: Array; + countries: Array; + genres: Array; + tomatoes: { + viewer: { + rating: { + $numberDouble: string; + }; + numReviews: { + $numberInt: string; + }; + }; + lastUpdated: { + $date: { + $numberLong: string; + }; + }; + }; + num_mflix_comments: { + $numberInt: string; + }; + }; + + const aggregation: schema.Pipeline = [ + { + $searchMeta: { + facet: { + operator: { + compound: { + must: [{ text: { path: 'description', query: 'new york city' } }], + filter: [ + { + equals: { + path: 'cancellation_policy', + value: 'moderate', + doesNotAffect: 'accommodatesFacet', + }, + }, + ], + }, + }, + facets: { + accommodatesFacet: { + path: 'accommodates', + type: 'number', + boundaries: [1, 2, 4, 8], + }, + cancellationFacet: { path: 'cancellation_policy', type: 'string' }, + roomTypeFacet: { path: 'room_type', type: 'string' }, + }, + }, + }, + }, + ]; } diff --git a/packages/mql-typescript/tests/search/geoShape.spec.ts b/packages/mql-typescript/tests/search/geoShape.spec.ts index 31ed7b07..71fb2fbe 100644 --- a/packages/mql-typescript/tests/search/geoShape.spec.ts +++ b/packages/mql-typescript/tests/search/geoShape.spec.ts @@ -9,7 +9,207 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/geoShape/#disjoint-example} */ function test0() { - // TODO: no schema found for geoShape.Disjoint + type listingsAndReviews = { + _id: string; + listing_url: string; + name: string; + summary: string; + interaction: string; + house_rules: string; + property_type: string; + room_type: string; + bed_type: string; + minimum_nights: string; + maximum_nights: string; + cancellation_policy: string; + last_scraped: { + $date: { + $numberLong: string; + }; + }; + calendar_last_scraped: { + $date: { + $numberLong: string; + }; + }; + first_review: { + $date: { + $numberLong: string; + }; + }; + last_review: { + $date: { + $numberLong: string; + }; + }; + accommodates: { + $numberInt: string; + }; + bedrooms: { + $numberInt: string; + }; + beds: { + $numberInt: string; + }; + number_of_reviews: { + $numberInt: string; + }; + bathrooms: { + $numberDecimal: string; + }; + amenities: Array; + price: { + $numberDecimal: string; + }; + security_deposit: { + $numberDecimal: string; + }; + cleaning_fee: { + $numberDecimal: string; + }; + extra_people: { + $numberDecimal: string; + }; + guests_included: { + $numberDecimal: string; + }; + images: { + thumbnail_url: string; + medium_url: string; + picture_url: string; + xl_picture_url: string; + }; + host: { + host_id: string; + host_url: string; + host_name: string; + host_location: string; + host_about: string; + host_response_time: string; + host_thumbnail_url: string; + host_picture_url: string; + host_neighbourhood: string; + host_response_rate: { + $numberInt: string; + }; + host_is_superhost: boolean; + host_has_profile_pic: boolean; + host_identity_verified: boolean; + host_listings_count: { + $numberInt: string; + }; + host_total_listings_count: { + $numberInt: string; + }; + host_verifications: Array; + }; + address: { + street: string; + suburb: string; + government_area: string; + market: string; + country: string; + country_code: string; + location: { + type: string; + coordinates: Array<{ + $numberDouble: string; + }>; + is_location_exact: boolean; + }; + }; + availability: { + availability_30: { + $numberInt: string; + }; + availability_60: { + $numberInt: string; + }; + availability_90: { + $numberInt: string; + }; + availability_365: { + $numberInt: string; + }; + }; + review_scores: { + review_scores_accuracy: { + $numberInt: string; + }; + review_scores_cleanliness: { + $numberInt: string; + }; + review_scores_checkin: { + $numberInt: string; + }; + review_scores_communication: { + $numberInt: string; + }; + review_scores_location: { + $numberInt: string; + }; + review_scores_value: { + $numberInt: string; + }; + review_scores_rating: { + $numberInt: string; + }; + }; + reviews: Array<{ + _id: string; + date: { + $date: { + $numberLong: string; + }; + }; + listing_id: string; + reviewer_id: string; + reviewer_name: string; + comments: string; + }>; + }; + + const aggregation: schema.Pipeline = [ + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). + */ + { + $search: { + geoShape: { + relation: 'disjoint', + geometry: { + type: 'Polygon', + coordinates: [ + [ + [-161.323242, 22.512557], + [-152.446289, 22.065278], + [-156.09375, 17.811456], + [-161.323242, 22.512557], + ], + ], + }, + path: 'address.location', + }, + }, + } as any, + + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). + */ + { $limit: 3 } as any, + + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). + */ + { + $project: { + _id: 0, + name: 1, + address: 1, + score: { $meta: 'searchScore' }, + }, + } as any, + ]; } /** @@ -17,7 +217,221 @@ function test0() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/geoShape/#intersects-example} */ function test1() { - // TODO: no schema found for geoShape.Intersect + type listingsAndReviews = { + _id: string; + listing_url: string; + name: string; + summary: string; + interaction: string; + house_rules: string; + property_type: string; + room_type: string; + bed_type: string; + minimum_nights: string; + maximum_nights: string; + cancellation_policy: string; + last_scraped: { + $date: { + $numberLong: string; + }; + }; + calendar_last_scraped: { + $date: { + $numberLong: string; + }; + }; + first_review: { + $date: { + $numberLong: string; + }; + }; + last_review: { + $date: { + $numberLong: string; + }; + }; + accommodates: { + $numberInt: string; + }; + bedrooms: { + $numberInt: string; + }; + beds: { + $numberInt: string; + }; + number_of_reviews: { + $numberInt: string; + }; + bathrooms: { + $numberDecimal: string; + }; + amenities: Array; + price: { + $numberDecimal: string; + }; + security_deposit: { + $numberDecimal: string; + }; + cleaning_fee: { + $numberDecimal: string; + }; + extra_people: { + $numberDecimal: string; + }; + guests_included: { + $numberDecimal: string; + }; + images: { + thumbnail_url: string; + medium_url: string; + picture_url: string; + xl_picture_url: string; + }; + host: { + host_id: string; + host_url: string; + host_name: string; + host_location: string; + host_about: string; + host_response_time: string; + host_thumbnail_url: string; + host_picture_url: string; + host_neighbourhood: string; + host_response_rate: { + $numberInt: string; + }; + host_is_superhost: boolean; + host_has_profile_pic: boolean; + host_identity_verified: boolean; + host_listings_count: { + $numberInt: string; + }; + host_total_listings_count: { + $numberInt: string; + }; + host_verifications: Array; + }; + address: { + street: string; + suburb: string; + government_area: string; + market: string; + country: string; + country_code: string; + location: { + type: string; + coordinates: Array<{ + $numberDouble: string; + }>; + is_location_exact: boolean; + }; + }; + availability: { + availability_30: { + $numberInt: string; + }; + availability_60: { + $numberInt: string; + }; + availability_90: { + $numberInt: string; + }; + availability_365: { + $numberInt: string; + }; + }; + review_scores: { + review_scores_accuracy: { + $numberInt: string; + }; + review_scores_cleanliness: { + $numberInt: string; + }; + review_scores_checkin: { + $numberInt: string; + }; + review_scores_communication: { + $numberInt: string; + }; + review_scores_location: { + $numberInt: string; + }; + review_scores_value: { + $numberInt: string; + }; + review_scores_rating: { + $numberInt: string; + }; + }; + reviews: Array<{ + _id: string; + date: { + $date: { + $numberLong: string; + }; + }; + listing_id: string; + reviewer_id: string; + reviewer_name: string; + comments: string; + }>; + }; + + const aggregation: schema.Pipeline = [ + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). + */ + { + $search: { + geoShape: { + relation: 'intersects', + geometry: { + type: 'MultiPolygon', + coordinates: [ + [ + [ + [2.16942, 41.40082], + [2.17963, 41.40087], + [2.18146, 41.39716], + [2.15533, 41.40686], + [2.14596, 41.38475], + [2.17519, 41.41035], + [2.16942, 41.40082], + ], + ], + [ + [ + [2.16365, 41.39416], + [2.16963, 41.39726], + [2.15395, 41.38005], + [2.17935, 41.43038], + [2.16365, 41.39416], + ], + ], + ], + }, + path: 'address.location', + }, + }, + } as any, + + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). + */ + { $limit: 3 } as any, + + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). + */ + { + $project: { + _id: 0, + name: 1, + address: 1, + score: { $meta: 'searchScore' }, + }, + } as any, + ]; } /** @@ -25,5 +439,209 @@ function test1() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/geoShape/#within-example} */ function test2() { - // TODO: no schema found for geoShape.Within + type listingsAndReviews = { + _id: string; + listing_url: string; + name: string; + summary: string; + interaction: string; + house_rules: string; + property_type: string; + room_type: string; + bed_type: string; + minimum_nights: string; + maximum_nights: string; + cancellation_policy: string; + last_scraped: { + $date: { + $numberLong: string; + }; + }; + calendar_last_scraped: { + $date: { + $numberLong: string; + }; + }; + first_review: { + $date: { + $numberLong: string; + }; + }; + last_review: { + $date: { + $numberLong: string; + }; + }; + accommodates: { + $numberInt: string; + }; + bedrooms: { + $numberInt: string; + }; + beds: { + $numberInt: string; + }; + number_of_reviews: { + $numberInt: string; + }; + bathrooms: { + $numberDecimal: string; + }; + amenities: Array; + price: { + $numberDecimal: string; + }; + security_deposit: { + $numberDecimal: string; + }; + cleaning_fee: { + $numberDecimal: string; + }; + extra_people: { + $numberDecimal: string; + }; + guests_included: { + $numberDecimal: string; + }; + images: { + thumbnail_url: string; + medium_url: string; + picture_url: string; + xl_picture_url: string; + }; + host: { + host_id: string; + host_url: string; + host_name: string; + host_location: string; + host_about: string; + host_response_time: string; + host_thumbnail_url: string; + host_picture_url: string; + host_neighbourhood: string; + host_response_rate: { + $numberInt: string; + }; + host_is_superhost: boolean; + host_has_profile_pic: boolean; + host_identity_verified: boolean; + host_listings_count: { + $numberInt: string; + }; + host_total_listings_count: { + $numberInt: string; + }; + host_verifications: Array; + }; + address: { + street: string; + suburb: string; + government_area: string; + market: string; + country: string; + country_code: string; + location: { + type: string; + coordinates: Array<{ + $numberDouble: string; + }>; + is_location_exact: boolean; + }; + }; + availability: { + availability_30: { + $numberInt: string; + }; + availability_60: { + $numberInt: string; + }; + availability_90: { + $numberInt: string; + }; + availability_365: { + $numberInt: string; + }; + }; + review_scores: { + review_scores_accuracy: { + $numberInt: string; + }; + review_scores_cleanliness: { + $numberInt: string; + }; + review_scores_checkin: { + $numberInt: string; + }; + review_scores_communication: { + $numberInt: string; + }; + review_scores_location: { + $numberInt: string; + }; + review_scores_value: { + $numberInt: string; + }; + review_scores_rating: { + $numberInt: string; + }; + }; + reviews: Array<{ + _id: string; + date: { + $date: { + $numberLong: string; + }; + }; + listing_id: string; + reviewer_id: string; + reviewer_name: string; + comments: string; + }>; + }; + + const aggregation: schema.Pipeline = [ + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). + */ + { + $search: { + geoShape: { + relation: 'within', + geometry: { + type: 'Polygon', + coordinates: [ + [ + [-74.3994140625, 40.5305017757], + [-74.7290039063, 40.5805846641], + [-74.7729492188, 40.9467136651], + [-74.0698242188, 41.1290213475], + [-73.65234375, 40.9964840144], + [-72.6416015625, 40.9467136651], + [-72.3559570313, 40.7971774152], + [-74.3994140625, 40.5305017757], + ], + ], + }, + path: 'address.location', + }, + }, + } as any, + + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). + */ + { $limit: 3 } as any, + + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). + */ + { + $project: { + _id: 0, + name: 1, + address: 1, + score: { $meta: 'searchScore' }, + }, + } as any, + ]; } diff --git a/packages/mql-typescript/tests/search/geoWithin.spec.ts b/packages/mql-typescript/tests/search/geoWithin.spec.ts index c4a7034a..50567793 100644 --- a/packages/mql-typescript/tests/search/geoWithin.spec.ts +++ b/packages/mql-typescript/tests/search/geoWithin.spec.ts @@ -9,7 +9,192 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/geoWithin/#box-example} */ function test0() { - // TODO: no schema found for geoWithin.box + type listingsAndReviews = { + _id: string; + listing_url: string; + name: string; + summary: string; + interaction: string; + house_rules: string; + property_type: string; + room_type: string; + bed_type: string; + minimum_nights: string; + maximum_nights: string; + cancellation_policy: string; + last_scraped: { + $date: { + $numberLong: string; + }; + }; + calendar_last_scraped: { + $date: { + $numberLong: string; + }; + }; + first_review: { + $date: { + $numberLong: string; + }; + }; + last_review: { + $date: { + $numberLong: string; + }; + }; + accommodates: { + $numberInt: string; + }; + bedrooms: { + $numberInt: string; + }; + beds: { + $numberInt: string; + }; + number_of_reviews: { + $numberInt: string; + }; + bathrooms: { + $numberDecimal: string; + }; + amenities: Array; + price: { + $numberDecimal: string; + }; + security_deposit: { + $numberDecimal: string; + }; + cleaning_fee: { + $numberDecimal: string; + }; + extra_people: { + $numberDecimal: string; + }; + guests_included: { + $numberDecimal: string; + }; + images: { + thumbnail_url: string; + medium_url: string; + picture_url: string; + xl_picture_url: string; + }; + host: { + host_id: string; + host_url: string; + host_name: string; + host_location: string; + host_about: string; + host_response_time: string; + host_thumbnail_url: string; + host_picture_url: string; + host_neighbourhood: string; + host_response_rate: { + $numberInt: string; + }; + host_is_superhost: boolean; + host_has_profile_pic: boolean; + host_identity_verified: boolean; + host_listings_count: { + $numberInt: string; + }; + host_total_listings_count: { + $numberInt: string; + }; + host_verifications: Array; + }; + address: { + street: string; + suburb: string; + government_area: string; + market: string; + country: string; + country_code: string; + location: { + type: string; + coordinates: Array<{ + $numberDouble: string; + }>; + is_location_exact: boolean; + }; + }; + availability: { + availability_30: { + $numberInt: string; + }; + availability_60: { + $numberInt: string; + }; + availability_90: { + $numberInt: string; + }; + availability_365: { + $numberInt: string; + }; + }; + review_scores: { + review_scores_accuracy: { + $numberInt: string; + }; + review_scores_cleanliness: { + $numberInt: string; + }; + review_scores_checkin: { + $numberInt: string; + }; + review_scores_communication: { + $numberInt: string; + }; + review_scores_location: { + $numberInt: string; + }; + review_scores_value: { + $numberInt: string; + }; + review_scores_rating: { + $numberInt: string; + }; + }; + reviews: Array<{ + _id: string; + date: { + $date: { + $numberLong: string; + }; + }; + listing_id: string; + reviewer_id: string; + reviewer_name: string; + comments: string; + }>; + }; + + const aggregation: schema.Pipeline = [ + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). + */ + { + $search: { + geoWithin: { + path: 'address.location', + box: { + bottomLeft: { type: 'Point', coordinates: [112.467, -55.05] }, + topRight: { type: 'Point', coordinates: [168, -9.133] }, + }, + }, + }, + } as any, + + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). + */ + { $limit: 3 } as any, + + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). + */ + { $project: { _id: 0, name: 1, address: 1 } } as any, + ]; } /** @@ -17,7 +202,192 @@ function test0() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/geoWithin/#circle-example} */ function test1() { - // TODO: no schema found for geoWithin.circle + type listingsAndReviews = { + _id: string; + listing_url: string; + name: string; + summary: string; + interaction: string; + house_rules: string; + property_type: string; + room_type: string; + bed_type: string; + minimum_nights: string; + maximum_nights: string; + cancellation_policy: string; + last_scraped: { + $date: { + $numberLong: string; + }; + }; + calendar_last_scraped: { + $date: { + $numberLong: string; + }; + }; + first_review: { + $date: { + $numberLong: string; + }; + }; + last_review: { + $date: { + $numberLong: string; + }; + }; + accommodates: { + $numberInt: string; + }; + bedrooms: { + $numberInt: string; + }; + beds: { + $numberInt: string; + }; + number_of_reviews: { + $numberInt: string; + }; + bathrooms: { + $numberDecimal: string; + }; + amenities: Array; + price: { + $numberDecimal: string; + }; + security_deposit: { + $numberDecimal: string; + }; + cleaning_fee: { + $numberDecimal: string; + }; + extra_people: { + $numberDecimal: string; + }; + guests_included: { + $numberDecimal: string; + }; + images: { + thumbnail_url: string; + medium_url: string; + picture_url: string; + xl_picture_url: string; + }; + host: { + host_id: string; + host_url: string; + host_name: string; + host_location: string; + host_about: string; + host_response_time: string; + host_thumbnail_url: string; + host_picture_url: string; + host_neighbourhood: string; + host_response_rate: { + $numberInt: string; + }; + host_is_superhost: boolean; + host_has_profile_pic: boolean; + host_identity_verified: boolean; + host_listings_count: { + $numberInt: string; + }; + host_total_listings_count: { + $numberInt: string; + }; + host_verifications: Array; + }; + address: { + street: string; + suburb: string; + government_area: string; + market: string; + country: string; + country_code: string; + location: { + type: string; + coordinates: Array<{ + $numberDouble: string; + }>; + is_location_exact: boolean; + }; + }; + availability: { + availability_30: { + $numberInt: string; + }; + availability_60: { + $numberInt: string; + }; + availability_90: { + $numberInt: string; + }; + availability_365: { + $numberInt: string; + }; + }; + review_scores: { + review_scores_accuracy: { + $numberInt: string; + }; + review_scores_cleanliness: { + $numberInt: string; + }; + review_scores_checkin: { + $numberInt: string; + }; + review_scores_communication: { + $numberInt: string; + }; + review_scores_location: { + $numberInt: string; + }; + review_scores_value: { + $numberInt: string; + }; + review_scores_rating: { + $numberInt: string; + }; + }; + reviews: Array<{ + _id: string; + date: { + $date: { + $numberLong: string; + }; + }; + listing_id: string; + reviewer_id: string; + reviewer_name: string; + comments: string; + }>; + }; + + const aggregation: schema.Pipeline = [ + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). + */ + { + $search: { + geoWithin: { + circle: { + center: { type: 'Point', coordinates: [-73.54, 45.54] }, + radius: 1600, + }, + path: 'address.location', + }, + }, + } as any, + + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). + */ + { $limit: 3 } as any, + + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). + */ + { $project: { _id: 0, name: 1, address: 1 } } as any, + ]; } /** @@ -25,5 +395,197 @@ function test1() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/geoWithin/#geometry-examples} */ function test2() { - // TODO: no schema found for geoWithin.geometry + type listingsAndReviews = { + _id: string; + listing_url: string; + name: string; + summary: string; + interaction: string; + house_rules: string; + property_type: string; + room_type: string; + bed_type: string; + minimum_nights: string; + maximum_nights: string; + cancellation_policy: string; + last_scraped: { + $date: { + $numberLong: string; + }; + }; + calendar_last_scraped: { + $date: { + $numberLong: string; + }; + }; + first_review: { + $date: { + $numberLong: string; + }; + }; + last_review: { + $date: { + $numberLong: string; + }; + }; + accommodates: { + $numberInt: string; + }; + bedrooms: { + $numberInt: string; + }; + beds: { + $numberInt: string; + }; + number_of_reviews: { + $numberInt: string; + }; + bathrooms: { + $numberDecimal: string; + }; + amenities: Array; + price: { + $numberDecimal: string; + }; + security_deposit: { + $numberDecimal: string; + }; + cleaning_fee: { + $numberDecimal: string; + }; + extra_people: { + $numberDecimal: string; + }; + guests_included: { + $numberDecimal: string; + }; + images: { + thumbnail_url: string; + medium_url: string; + picture_url: string; + xl_picture_url: string; + }; + host: { + host_id: string; + host_url: string; + host_name: string; + host_location: string; + host_about: string; + host_response_time: string; + host_thumbnail_url: string; + host_picture_url: string; + host_neighbourhood: string; + host_response_rate: { + $numberInt: string; + }; + host_is_superhost: boolean; + host_has_profile_pic: boolean; + host_identity_verified: boolean; + host_listings_count: { + $numberInt: string; + }; + host_total_listings_count: { + $numberInt: string; + }; + host_verifications: Array; + }; + address: { + street: string; + suburb: string; + government_area: string; + market: string; + country: string; + country_code: string; + location: { + type: string; + coordinates: Array<{ + $numberDouble: string; + }>; + is_location_exact: boolean; + }; + }; + availability: { + availability_30: { + $numberInt: string; + }; + availability_60: { + $numberInt: string; + }; + availability_90: { + $numberInt: string; + }; + availability_365: { + $numberInt: string; + }; + }; + review_scores: { + review_scores_accuracy: { + $numberInt: string; + }; + review_scores_cleanliness: { + $numberInt: string; + }; + review_scores_checkin: { + $numberInt: string; + }; + review_scores_communication: { + $numberInt: string; + }; + review_scores_location: { + $numberInt: string; + }; + review_scores_value: { + $numberInt: string; + }; + review_scores_rating: { + $numberInt: string; + }; + }; + reviews: Array<{ + _id: string; + date: { + $date: { + $numberLong: string; + }; + }; + listing_id: string; + reviewer_id: string; + reviewer_name: string; + comments: string; + }>; + }; + + const aggregation: schema.Pipeline = [ + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). + */ + { + $search: { + geoWithin: { + geometry: { + type: 'Polygon', + coordinates: [ + [ + [-161.323242, 22.512557], + [-152.446289, 22.065278], + [-156.09375, 17.811456], + [-161.323242, 22.512557], + ], + ], + }, + path: 'address.location', + }, + }, + } as any, + + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). + */ + { $limit: 3 } as any, + + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). + */ + { $project: { _id: 0, name: 1, address: 1 } } as any, + ]; } diff --git a/packages/mql-typescript/tests/search/hasAncestor.spec.ts b/packages/mql-typescript/tests/search/hasAncestor.spec.ts index 44c3bff2..af9cbb21 100644 --- a/packages/mql-typescript/tests/search/hasAncestor.spec.ts +++ b/packages/mql-typescript/tests/search/hasAncestor.spec.ts @@ -9,5 +9,42 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/operators-collectors/hasAncestor/#sample-query} */ function test0() { - // TODO: no schema found for hasAncestor.Example + type TestCollection = { + mappings: { + dynamic: boolean; + fields: { + funding_rounds: { + dynamic: boolean; + fields: { + investments: Array<{ + dynamic: boolean; + storedSource: { + include: Array; + }; + type: string; + }>; + }; + type: string; + }; + }; + }; + }; + + const aggregation: schema.Pipeline = [ + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). + */ + { + $search: { + returnStoredSource: true, + returnScope: { path: 'funding_rounds.investments' }, + hasAncestor: { + ancestorPath: 'funding_rounds', + operator: { + equals: { path: 'funding_rounds.funded_year', value: 2005 }, + }, + }, + }, + } as any, + ]; } diff --git a/packages/mql-typescript/tests/search/hasRoot.spec.ts b/packages/mql-typescript/tests/search/hasRoot.spec.ts index 18ae7e95..60e74330 100644 --- a/packages/mql-typescript/tests/search/hasRoot.spec.ts +++ b/packages/mql-typescript/tests/search/hasRoot.spec.ts @@ -9,7 +9,48 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/operators-collectors/hasRoot/#simple-query} */ function test0() { - // TODO: no schema found for hasRoot.Simple Query + type TestCollection = { + mappings: { + dynamic: boolean; + fields: { + funding_rounds: { + dynamic: boolean; + fields: { + investments: Array<{ + dynamic: boolean; + type: string; + }>; + }; + storedSource: { + include: Array; + }; + type: string; + }; + products: { + dynamic: boolean; + storedSource: { + include: Array; + }; + type: string; + }; + }; + }; + }; + + const aggregation: schema.Pipeline = [ + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). + */ + { + $search: { + returnStoredSource: true, + returnScope: { path: 'products' }, + hasRoot: { + operator: { range: { path: 'founded_year', gte: 2005, lte: 2010 } }, + }, + }, + } as any, + ]; } /** @@ -17,7 +58,46 @@ function test0() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/operators-collectors/hasRoot/#multi-level-query} */ function test1() { - // TODO: no schema found for hasRoot.Multi-Level Query + type TestCollection = { + mappings: { + dynamic: boolean; + fields: { + funding_rounds: { + dynamic: boolean; + fields: { + investments: Array<{ + dynamic: boolean; + type: string; + }>; + }; + storedSource: { + include: Array; + }; + type: string; + }; + products: { + dynamic: boolean; + storedSource: { + include: Array; + }; + type: string; + }; + }; + }; + }; + + const aggregation: schema.Pipeline = [ + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). + */ + { + $search: { + returnStoredSource: true, + returnScope: { path: 'funding_rounds' }, + hasRoot: { operator: { text: { path: 'name', query: 'Facebook' } } }, + }, + } as any, + ]; } /** @@ -25,5 +105,75 @@ function test1() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/operators-collectors/hasRoot/#compound-query} */ function test2() { - // TODO: no schema found for hasRoot.Compound Query + type TestCollection = { + mappings: { + dynamic: boolean; + fields: { + funding_rounds: { + dynamic: boolean; + fields: { + investments: Array<{ + dynamic: boolean; + type: string; + }>; + }; + storedSource: { + include: Array; + }; + type: string; + }; + products: { + dynamic: boolean; + storedSource: { + include: Array; + }; + type: string; + }; + }; + }; + }; + + const aggregation: schema.Pipeline = [ + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). + */ + { + $search: { + compound: { + should: [ + { + embeddedDocument: { + path: 'funding_rounds.investments', + operator: { + wildcard: { + path: 'funding_rounds.investments.financial_org.name', + query: '*Ventures*', + allowAnalyzedField: true, + }, + }, + }, + }, + { + hasRoot: { + operator: { + wildcard: { + path: 'description', + query: '*network*', + allowAnalyzedField: true, + }, + }, + }, + }, + ], + }, + returnScope: { path: 'funding_rounds' }, + returnStoredSource: true, + }, + } as any, + + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). + */ + { $limit: 5 } as any, + ]; } diff --git a/packages/mql-typescript/tests/search/in.spec.ts b/packages/mql-typescript/tests/search/in.spec.ts index 99842858..58b85a32 100644 --- a/packages/mql-typescript/tests/search/in.spec.ts +++ b/packages/mql-typescript/tests/search/in.spec.ts @@ -9,7 +9,41 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/in/#examples} */ function test0() { - // TODO: no schema found for in.Single Value Field Match + type customers = { + _id: bson.ObjectId; + username: string; + name: string; + address: string; + birthdate: { + $date: bson.Double | number; + }; + email: string; + accounts: Array; + tier_and_details: { + b5f19cb532fa436a9be2cf1d7d1cac8a: { + tier: string; + benefits: Array; + active: boolean; + id: string; + }; + }; + }; + + const aggregation: schema.Pipeline = [ + { + $search: { + in: { + path: 'birthdate', + value: [ + new Date('1977-03-02T02:20:31.000Z'), + new Date('1977-03-01T00:00:00.000Z'), + new Date('1977-05-06T21:57:35.000Z'), + ], + }, + }, + }, + { $project: { _id: 0, name: 1, birthdate: 1 } }, + ]; } /** @@ -17,7 +51,30 @@ function test0() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/in/#examples} */ function test1() { - // TODO: no schema found for in.Array Value Field Match + type customers = { + _id: bson.ObjectId; + username: string; + name: string; + address: string; + birthdate: { + $date: bson.Double | number; + }; + email: string; + accounts: Array; + tier_and_details: { + b5f19cb532fa436a9be2cf1d7d1cac8a: { + tier: string; + benefits: Array; + active: boolean; + id: string; + }; + }; + }; + + const aggregation: schema.Pipeline = [ + { $search: { in: { path: 'accounts', value: [371138, 371139, 371140] } } }, + { $project: { _id: 0, name: 1, accounts: 1 } }, + ]; } /** @@ -25,5 +82,53 @@ function test1() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/in/#examples} */ function test2() { - // TODO: no schema found for in.Compound Query Match + type customers = { + _id: bson.ObjectId; + username: string; + name: string; + address: string; + birthdate: { + $date: bson.Double | number; + }; + email: string; + accounts: Array; + tier_and_details: { + b5f19cb532fa436a9be2cf1d7d1cac8a: { + tier: string; + benefits: Array; + active: boolean; + id: string; + }; + }; + }; + + const aggregation: schema.Pipeline = [ + { + $search: { + compound: { + must: [ + { + in: { + path: 'name', + value: ['james sanchez', 'jennifer lawrence'], + }, + }, + ], + should: [ + { + in: { + path: '_id', + value: [ + bson.ObjectId.createFromHexString('5ca4bbcea2dd94ee58162a72'), + bson.ObjectId.createFromHexString('5ca4bbcea2dd94ee58162a91'), + ], + }, + }, + ], + }, + }, + }, + { $limit: 5 }, + { $project: { _id: 1, name: 1, score: { $meta: 'searchScore' } } }, + ]; } diff --git a/packages/mql-typescript/tests/search/moreLikeThis.spec.ts b/packages/mql-typescript/tests/search/moreLikeThis.spec.ts index aa1b4306..afd109ab 100644 --- a/packages/mql-typescript/tests/search/moreLikeThis.spec.ts +++ b/packages/mql-typescript/tests/search/moreLikeThis.spec.ts @@ -9,7 +9,71 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/morelikethis/#example-1--single-document-with-multiple-fields} */ function test0() { - // TODO: no schema found for moreLikeThis.Single Document with Multiple Fields + type movies = { + _id: { + $oid: string; + }; + title: string; + year: { + $numberInt: string; + }; + runtime: { + $numberInt: string; + }; + released: { + $date: { + $numberLong: string; + }; + }; + poster: string; + plot: string; + fullplot: string; + lastupdated: string; + type: string; + directors: Array; + imdb: { + rating: { + $numberDouble: string; + }; + votes: { + $numberInt: string; + }; + id: { + $numberInt: string; + }; + }; + cast: Array; + countries: Array; + genres: Array; + tomatoes: { + viewer: { + rating: { + $numberDouble: string; + }; + numReviews: { + $numberInt: string; + }; + }; + lastUpdated: { + $date: { + $numberLong: string; + }; + }; + }; + num_mflix_comments: { + $numberInt: string; + }; + }; + + const aggregation: schema.Pipeline = [ + { + $search: { + moreLikeThis: { like: { title: 'The Godfather', genres: 'action' } }, + }, + }, + { $limit: 5 }, + { $project: { _id: 0, title: 1, released: 1, genres: 1 } }, + ]; } /** @@ -17,7 +81,95 @@ function test0() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/morelikethis/#example-2--input-document-excluded-in-results} */ function test1() { - // TODO: no schema found for moreLikeThis.Input Document Excluded in Results + type movies = { + _id: { + $oid: string; + }; + title: string; + year: { + $numberInt: string; + }; + runtime: { + $numberInt: string; + }; + released: { + $date: { + $numberLong: string; + }; + }; + poster: string; + plot: string; + fullplot: string; + lastupdated: string; + type: string; + directors: Array; + imdb: { + rating: { + $numberDouble: string; + }; + votes: { + $numberInt: string; + }; + id: { + $numberInt: string; + }; + }; + cast: Array; + countries: Array; + genres: Array; + tomatoes: { + viewer: { + rating: { + $numberDouble: string; + }; + numReviews: { + $numberInt: string; + }; + }; + lastUpdated: { + $date: { + $numberLong: string; + }; + }; + }; + num_mflix_comments: { + $numberInt: string; + }; + }; + + const aggregation: schema.Pipeline = [ + { + $search: { + compound: { + must: [ + { + moreLikeThis: { + like: { + _id: bson.ObjectId.createFromHexString( + '573a1396f29313caabce4a9a', + ), + genres: ['Crime', 'Drama'], + title: 'The Godfather', + }, + }, + }, + ], + mustNot: [ + { + equals: { + path: '_id', + value: bson.ObjectId.createFromHexString( + '573a1396f29313caabce4a9a', + ), + }, + }, + ], + }, + }, + }, + { $limit: 5 }, + { $project: { _id: 1, title: 1, released: 1, genres: 1 } }, + ]; } /** @@ -25,5 +177,93 @@ function test1() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/morelikethis/#example-3--multiple-analyzers} */ function test2() { - // TODO: no schema found for moreLikeThis.Multiple Analyzers + type movies = { + _id: { + $oid: string; + }; + title: string; + year: { + $numberInt: string; + }; + runtime: { + $numberInt: string; + }; + released: { + $date: { + $numberLong: string; + }; + }; + poster: string; + plot: string; + fullplot: string; + lastupdated: string; + type: string; + directors: Array; + imdb: { + rating: { + $numberDouble: string; + }; + votes: { + $numberInt: string; + }; + id: { + $numberInt: string; + }; + }; + cast: Array; + countries: Array; + genres: Array; + tomatoes: { + viewer: { + rating: { + $numberDouble: string; + }; + numReviews: { + $numberInt: string; + }; + }; + lastUpdated: { + $date: { + $numberLong: string; + }; + }; + }; + num_mflix_comments: { + $numberInt: string; + }; + }; + + const aggregation: schema.Pipeline = [ + { + $search: { + compound: { + should: [ + { + moreLikeThis: { + like: { + _id: bson.ObjectId.createFromHexString( + '573a1396f29313caabce4a9a', + ), + genres: ['Crime', 'Drama'], + title: 'The Godfather', + }, + }, + }, + ], + mustNot: [ + { + equals: { + path: '_id', + value: bson.ObjectId.createFromHexString( + '573a1394f29313caabcde9ef', + ), + }, + }, + ], + }, + }, + }, + { $limit: 10 }, + { $project: { title: 1, genres: 1, _id: 1 } }, + ]; } diff --git a/packages/mql-typescript/tests/search/near.spec.ts b/packages/mql-typescript/tests/search/near.spec.ts index 23018b7f..45d4c6a9 100644 --- a/packages/mql-typescript/tests/search/near.spec.ts +++ b/packages/mql-typescript/tests/search/near.spec.ts @@ -9,7 +9,79 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/near/#number-example} */ function test0() { - // TODO: no schema found for near.Number + type movies = { + _id: { + $oid: string; + }; + title: string; + year: { + $numberInt: string; + }; + runtime: { + $numberInt: string; + }; + released: { + $date: { + $numberLong: string; + }; + }; + poster: string; + plot: string; + fullplot: string; + lastupdated: string; + type: string; + directors: Array; + imdb: { + rating: { + $numberDouble: string; + }; + votes: { + $numberInt: string; + }; + id: { + $numberInt: string; + }; + }; + cast: Array; + countries: Array; + genres: Array; + tomatoes: { + viewer: { + rating: { + $numberDouble: string; + }; + numReviews: { + $numberInt: string; + }; + }; + lastUpdated: { + $date: { + $numberLong: string; + }; + }; + }; + num_mflix_comments: { + $numberInt: string; + }; + }; + + const aggregation: schema.Pipeline = [ + { + $search: { + index: 'runtimes', + near: { path: 'runtime', origin: 279, pivot: 2 }, + }, + }, + { $limit: 7 }, + { + $project: { + _id: 0, + title: 1, + runtime: 1, + score: { $meta: 'searchScore' }, + }, + }, + ]; } /** @@ -17,7 +89,83 @@ function test0() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/near/#date-example} */ function test1() { - // TODO: no schema found for near.Date + type movies = { + _id: { + $oid: string; + }; + title: string; + year: { + $numberInt: string; + }; + runtime: { + $numberInt: string; + }; + released: { + $date: { + $numberLong: string; + }; + }; + poster: string; + plot: string; + fullplot: string; + lastupdated: string; + type: string; + directors: Array; + imdb: { + rating: { + $numberDouble: string; + }; + votes: { + $numberInt: string; + }; + id: { + $numberInt: string; + }; + }; + cast: Array; + countries: Array; + genres: Array; + tomatoes: { + viewer: { + rating: { + $numberDouble: string; + }; + numReviews: { + $numberInt: string; + }; + }; + lastUpdated: { + $date: { + $numberLong: string; + }; + }; + }; + num_mflix_comments: { + $numberInt: string; + }; + }; + + const aggregation: schema.Pipeline = [ + { + $search: { + index: 'releaseddate', + near: { + path: 'released', + origin: new Date('1915-09-13T00:00:00.000Z'), + pivot: 7776000000, + }, + }, + }, + { $limit: 3 }, + { + $project: { + _id: 0, + title: 1, + released: 1, + score: { $meta: 'searchScore' }, + }, + }, + ]; } /** @@ -25,7 +173,197 @@ function test1() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/near/#geojson-point-examples} */ function test2() { - // TODO: no schema found for near.GeoJSON Point + type listingsAndReviews = { + _id: string; + listing_url: string; + name: string; + summary: string; + interaction: string; + house_rules: string; + property_type: string; + room_type: string; + bed_type: string; + minimum_nights: string; + maximum_nights: string; + cancellation_policy: string; + last_scraped: { + $date: { + $numberLong: string; + }; + }; + calendar_last_scraped: { + $date: { + $numberLong: string; + }; + }; + first_review: { + $date: { + $numberLong: string; + }; + }; + last_review: { + $date: { + $numberLong: string; + }; + }; + accommodates: { + $numberInt: string; + }; + bedrooms: { + $numberInt: string; + }; + beds: { + $numberInt: string; + }; + number_of_reviews: { + $numberInt: string; + }; + bathrooms: { + $numberDecimal: string; + }; + amenities: Array; + price: { + $numberDecimal: string; + }; + security_deposit: { + $numberDecimal: string; + }; + cleaning_fee: { + $numberDecimal: string; + }; + extra_people: { + $numberDecimal: string; + }; + guests_included: { + $numberDecimal: string; + }; + images: { + thumbnail_url: string; + medium_url: string; + picture_url: string; + xl_picture_url: string; + }; + host: { + host_id: string; + host_url: string; + host_name: string; + host_location: string; + host_about: string; + host_response_time: string; + host_thumbnail_url: string; + host_picture_url: string; + host_neighbourhood: string; + host_response_rate: { + $numberInt: string; + }; + host_is_superhost: boolean; + host_has_profile_pic: boolean; + host_identity_verified: boolean; + host_listings_count: { + $numberInt: string; + }; + host_total_listings_count: { + $numberInt: string; + }; + host_verifications: Array; + }; + address: { + street: string; + suburb: string; + government_area: string; + market: string; + country: string; + country_code: string; + location: { + type: string; + coordinates: Array<{ + $numberDouble: string; + }>; + is_location_exact: boolean; + }; + }; + availability: { + availability_30: { + $numberInt: string; + }; + availability_60: { + $numberInt: string; + }; + availability_90: { + $numberInt: string; + }; + availability_365: { + $numberInt: string; + }; + }; + review_scores: { + review_scores_accuracy: { + $numberInt: string; + }; + review_scores_cleanliness: { + $numberInt: string; + }; + review_scores_checkin: { + $numberInt: string; + }; + review_scores_communication: { + $numberInt: string; + }; + review_scores_location: { + $numberInt: string; + }; + review_scores_value: { + $numberInt: string; + }; + review_scores_rating: { + $numberInt: string; + }; + }; + reviews: Array<{ + _id: string; + date: { + $date: { + $numberLong: string; + }; + }; + listing_id: string; + reviewer_id: string; + reviewer_name: string; + comments: string; + }>; + }; + + const aggregation: schema.Pipeline = [ + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). + */ + { + $search: { + near: { + origin: { type: 'Point', coordinates: [-8.61308, 41.1413] }, + pivot: 1000, + path: 'address.location', + }, + }, + } as any, + + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). + */ + { $limit: 3 } as any, + + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). + */ + { + $project: { + _id: 0, + name: 1, + address: 1, + score: { $meta: 'searchScore' }, + }, + } as any, + ]; } /** @@ -33,5 +371,200 @@ function test2() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/near/#compound-example} */ function test3() { - // TODO: no schema found for near.Compound + type listingsAndReviews = { + _id: string; + listing_url: string; + name: string; + summary: string; + interaction: string; + house_rules: string; + property_type: string; + room_type: string; + bed_type: string; + minimum_nights: string; + maximum_nights: string; + cancellation_policy: string; + last_scraped: { + $date: { + $numberLong: string; + }; + }; + calendar_last_scraped: { + $date: { + $numberLong: string; + }; + }; + first_review: { + $date: { + $numberLong: string; + }; + }; + last_review: { + $date: { + $numberLong: string; + }; + }; + accommodates: { + $numberInt: string; + }; + bedrooms: { + $numberInt: string; + }; + beds: { + $numberInt: string; + }; + number_of_reviews: { + $numberInt: string; + }; + bathrooms: { + $numberDecimal: string; + }; + amenities: Array; + price: { + $numberDecimal: string; + }; + security_deposit: { + $numberDecimal: string; + }; + cleaning_fee: { + $numberDecimal: string; + }; + extra_people: { + $numberDecimal: string; + }; + guests_included: { + $numberDecimal: string; + }; + images: { + thumbnail_url: string; + medium_url: string; + picture_url: string; + xl_picture_url: string; + }; + host: { + host_id: string; + host_url: string; + host_name: string; + host_location: string; + host_about: string; + host_response_time: string; + host_thumbnail_url: string; + host_picture_url: string; + host_neighbourhood: string; + host_response_rate: { + $numberInt: string; + }; + host_is_superhost: boolean; + host_has_profile_pic: boolean; + host_identity_verified: boolean; + host_listings_count: { + $numberInt: string; + }; + host_total_listings_count: { + $numberInt: string; + }; + host_verifications: Array; + }; + address: { + street: string; + suburb: string; + government_area: string; + market: string; + country: string; + country_code: string; + location: { + type: string; + coordinates: Array<{ + $numberDouble: string; + }>; + is_location_exact: boolean; + }; + }; + availability: { + availability_30: { + $numberInt: string; + }; + availability_60: { + $numberInt: string; + }; + availability_90: { + $numberInt: string; + }; + availability_365: { + $numberInt: string; + }; + }; + review_scores: { + review_scores_accuracy: { + $numberInt: string; + }; + review_scores_cleanliness: { + $numberInt: string; + }; + review_scores_checkin: { + $numberInt: string; + }; + review_scores_communication: { + $numberInt: string; + }; + review_scores_location: { + $numberInt: string; + }; + review_scores_value: { + $numberInt: string; + }; + review_scores_rating: { + $numberInt: string; + }; + }; + reviews: Array<{ + _id: string; + date: { + $date: { + $numberLong: string; + }; + }; + listing_id: string; + reviewer_id: string; + reviewer_name: string; + comments: string; + }>; + }; + + const aggregation: schema.Pipeline = [ + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). + */ + { + $search: { + compound: { + must: { text: { query: 'Apartment', path: 'property_type' } }, + should: { + near: { + origin: { type: 'Point', coordinates: [114.15027, 22.28158] }, + pivot: 1000, + path: 'address.location', + }, + }, + }, + }, + } as any, + + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). + */ + { $limit: 3 } as any, + + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). + */ + { + $project: { + _id: 0, + property_type: 1, + address: 1, + score: { $meta: 'searchScore' }, + }, + } as any, + ]; } diff --git a/packages/mql-typescript/tests/search/phrase.spec.ts b/packages/mql-typescript/tests/search/phrase.spec.ts index 5dff4dde..a45cd160 100644 --- a/packages/mql-typescript/tests/search/phrase.spec.ts +++ b/packages/mql-typescript/tests/search/phrase.spec.ts @@ -9,7 +9,67 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/phrase/#single-phrase-example} */ function test0() { - // TODO: no schema found for phrase.Single Phrase + type movies = { + _id: { + $oid: string; + }; + title: string; + year: { + $numberInt: string; + }; + runtime: { + $numberInt: string; + }; + released: { + $date: { + $numberLong: string; + }; + }; + poster: string; + plot: string; + fullplot: string; + lastupdated: string; + type: string; + directors: Array; + imdb: { + rating: { + $numberDouble: string; + }; + votes: { + $numberInt: string; + }; + id: { + $numberInt: string; + }; + }; + cast: Array; + countries: Array; + genres: Array; + tomatoes: { + viewer: { + rating: { + $numberDouble: string; + }; + numReviews: { + $numberInt: string; + }; + }; + lastUpdated: { + $date: { + $numberLong: string; + }; + }; + }; + num_mflix_comments: { + $numberInt: string; + }; + }; + + const aggregation: schema.Pipeline = [ + { $search: { phrase: { path: 'title', query: 'new york' } } }, + { $limit: 10 }, + { $project: { _id: 0, title: 1, score: { $meta: 'searchScore' } } }, + ]; } /** @@ -17,7 +77,67 @@ function test0() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/phrase/#multiple-phrases-example} */ function test1() { - // TODO: no schema found for phrase.Multiple Phrase + type movies = { + _id: { + $oid: string; + }; + title: string; + year: { + $numberInt: string; + }; + runtime: { + $numberInt: string; + }; + released: { + $date: { + $numberLong: string; + }; + }; + poster: string; + plot: string; + fullplot: string; + lastupdated: string; + type: string; + directors: Array; + imdb: { + rating: { + $numberDouble: string; + }; + votes: { + $numberInt: string; + }; + id: { + $numberInt: string; + }; + }; + cast: Array; + countries: Array; + genres: Array; + tomatoes: { + viewer: { + rating: { + $numberDouble: string; + }; + numReviews: { + $numberInt: string; + }; + }; + lastUpdated: { + $date: { + $numberLong: string; + }; + }; + }; + num_mflix_comments: { + $numberInt: string; + }; + }; + + const aggregation: schema.Pipeline = [ + { $search: { phrase: { path: 'title', query: ['the man', 'the moon'] } } }, + { $limit: 10 }, + { $project: { _id: 0, title: 1, score: { $meta: 'searchScore' } } }, + ]; } /** @@ -25,7 +145,66 @@ function test1() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/phrase/#slop-example} */ function test2() { - // TODO: no schema found for phrase.Phrase Slop + type movies = { + _id: { + $oid: string; + }; + title: string; + year: { + $numberInt: string; + }; + runtime: { + $numberInt: string; + }; + released: { + $date: { + $numberLong: string; + }; + }; + poster: string; + plot: string; + fullplot: string; + lastupdated: string; + type: string; + directors: Array; + imdb: { + rating: { + $numberDouble: string; + }; + votes: { + $numberInt: string; + }; + id: { + $numberInt: string; + }; + }; + cast: Array; + countries: Array; + genres: Array; + tomatoes: { + viewer: { + rating: { + $numberDouble: string; + }; + numReviews: { + $numberInt: string; + }; + }; + lastUpdated: { + $date: { + $numberLong: string; + }; + }; + }; + num_mflix_comments: { + $numberInt: string; + }; + }; + + const aggregation: schema.Pipeline = [ + { $search: { phrase: { path: 'title', query: 'men women', slop: 5 } } }, + { $project: { _id: 0, title: 1, score: { $meta: 'searchScore' } } }, + ]; } /** @@ -33,5 +212,76 @@ function test2() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/phrase/#synonyms-example} */ function test3() { - // TODO: no schema found for phrase.Phrase Synonyms + type movies = { + _id: { + $oid: string; + }; + title: string; + year: { + $numberInt: string; + }; + runtime: { + $numberInt: string; + }; + released: { + $date: { + $numberLong: string; + }; + }; + poster: string; + plot: string; + fullplot: string; + lastupdated: string; + type: string; + directors: Array; + imdb: { + rating: { + $numberDouble: string; + }; + votes: { + $numberInt: string; + }; + id: { + $numberInt: string; + }; + }; + cast: Array; + countries: Array; + genres: Array; + tomatoes: { + viewer: { + rating: { + $numberDouble: string; + }; + numReviews: { + $numberInt: string; + }; + }; + lastUpdated: { + $date: { + $numberLong: string; + }; + }; + }; + num_mflix_comments: { + $numberInt: string; + }; + }; + + const aggregation: schema.Pipeline = [ + { + $search: { + phrase: { + path: 'plot', + query: 'automobile race', + slop: 5, + synonyms: 'my_synonyms', + }, + }, + }, + { $limit: 5 }, + { + $project: { _id: 0, plot: 1, title: 1, score: { $meta: 'searchScore' } }, + }, + ]; } diff --git a/packages/mql-typescript/tests/search/queryString.spec.ts b/packages/mql-typescript/tests/search/queryString.spec.ts index 63a74478..c034d5dc 100644 --- a/packages/mql-typescript/tests/search/queryString.spec.ts +++ b/packages/mql-typescript/tests/search/queryString.spec.ts @@ -9,5 +9,71 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/queryString/#boolean-operator-queries} */ function test0() { - // TODO: no schema found for queryString.Boolean Operator Queries + type movies = { + _id: { + $oid: string; + }; + title: string; + year: { + $numberInt: string; + }; + runtime: { + $numberInt: string; + }; + released: { + $date: { + $numberLong: string; + }; + }; + poster: string; + plot: string; + fullplot: string; + lastupdated: string; + type: string; + directors: Array; + imdb: { + rating: { + $numberDouble: string; + }; + votes: { + $numberInt: string; + }; + id: { + $numberInt: string; + }; + }; + cast: Array; + countries: Array; + genres: Array; + tomatoes: { + viewer: { + rating: { + $numberDouble: string; + }; + numReviews: { + $numberInt: string; + }; + }; + lastUpdated: { + $date: { + $numberLong: string; + }; + }; + }; + num_mflix_comments: { + $numberInt: string; + }; + }; + + const aggregation: schema.Pipeline = [ + { + $search: { + queryString: { + defaultPath: 'title', + query: 'Rocky AND (IV OR 4 OR Four)', + }, + }, + }, + { $project: { _id: 0, title: 1 } }, + ]; } diff --git a/packages/mql-typescript/tests/search/range.spec.ts b/packages/mql-typescript/tests/search/range.spec.ts index fe22d63a..9d4f2720 100644 --- a/packages/mql-typescript/tests/search/range.spec.ts +++ b/packages/mql-typescript/tests/search/range.spec.ts @@ -9,7 +9,67 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/range/#number-example} */ function test0() { - // TODO: no schema found for range.Number gte lte + type movies = { + _id: { + $oid: string; + }; + title: string; + year: { + $numberInt: string; + }; + runtime: { + $numberInt: string; + }; + released: { + $date: { + $numberLong: string; + }; + }; + poster: string; + plot: string; + fullplot: string; + lastupdated: string; + type: string; + directors: Array; + imdb: { + rating: { + $numberDouble: string; + }; + votes: { + $numberInt: string; + }; + id: { + $numberInt: string; + }; + }; + cast: Array; + countries: Array; + genres: Array; + tomatoes: { + viewer: { + rating: { + $numberDouble: string; + }; + numReviews: { + $numberInt: string; + }; + }; + lastUpdated: { + $date: { + $numberLong: string; + }; + }; + }; + num_mflix_comments: { + $numberInt: string; + }; + }; + + const aggregation: schema.Pipeline = [ + { $search: { range: { path: 'runtime', gte: 2, lte: 3 } } }, + { $limit: 5 }, + { $project: { _id: 0, title: 1, runtime: 1 } }, + ]; } /** @@ -17,7 +77,74 @@ function test0() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/range/#number-example} */ function test1() { - // TODO: no schema found for range.Number lte + type movies = { + _id: { + $oid: string; + }; + title: string; + year: { + $numberInt: string; + }; + runtime: { + $numberInt: string; + }; + released: { + $date: { + $numberLong: string; + }; + }; + poster: string; + plot: string; + fullplot: string; + lastupdated: string; + type: string; + directors: Array; + imdb: { + rating: { + $numberDouble: string; + }; + votes: { + $numberInt: string; + }; + id: { + $numberInt: string; + }; + }; + cast: Array; + countries: Array; + genres: Array; + tomatoes: { + viewer: { + rating: { + $numberDouble: string; + }; + numReviews: { + $numberInt: string; + }; + }; + lastUpdated: { + $date: { + $numberLong: string; + }; + }; + }; + num_mflix_comments: { + $numberInt: string; + }; + }; + + const aggregation: schema.Pipeline = [ + { $search: { range: { path: 'runtime', lte: 2 } } }, + { $limit: 5 }, + { + $project: { + _id: 0, + title: 1, + runtime: 1, + score: { $meta: 'searchScore' }, + }, + }, + ]; } /** @@ -25,7 +152,75 @@ function test1() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/range/#date-example} */ function test2() { - // TODO: no schema found for range.Date + type movies = { + _id: { + $oid: string; + }; + title: string; + year: { + $numberInt: string; + }; + runtime: { + $numberInt: string; + }; + released: { + $date: { + $numberLong: string; + }; + }; + poster: string; + plot: string; + fullplot: string; + lastupdated: string; + type: string; + directors: Array; + imdb: { + rating: { + $numberDouble: string; + }; + votes: { + $numberInt: string; + }; + id: { + $numberInt: string; + }; + }; + cast: Array; + countries: Array; + genres: Array; + tomatoes: { + viewer: { + rating: { + $numberDouble: string; + }; + numReviews: { + $numberInt: string; + }; + }; + lastUpdated: { + $date: { + $numberLong: string; + }; + }; + }; + num_mflix_comments: { + $numberInt: string; + }; + }; + + const aggregation: schema.Pipeline = [ + { + $search: { + range: { + path: 'released', + gt: new Date('2010-01-01T00:00:00.000Z'), + lt: new Date('2015-01-01T00:00:00.000Z'), + }, + }, + }, + { $limit: 5 }, + { $project: { _id: 0, title: 1, released: 1 } }, + ]; } /** @@ -33,7 +228,74 @@ function test2() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/range/#objectid-example} */ function test3() { - // TODO: no schema found for range.ObjectId + type movies = { + _id: { + $oid: string; + }; + title: string; + year: { + $numberInt: string; + }; + runtime: { + $numberInt: string; + }; + released: { + $date: { + $numberLong: string; + }; + }; + poster: string; + plot: string; + fullplot: string; + lastupdated: string; + type: string; + directors: Array; + imdb: { + rating: { + $numberDouble: string; + }; + votes: { + $numberInt: string; + }; + id: { + $numberInt: string; + }; + }; + cast: Array; + countries: Array; + genres: Array; + tomatoes: { + viewer: { + rating: { + $numberDouble: string; + }; + numReviews: { + $numberInt: string; + }; + }; + lastUpdated: { + $date: { + $numberLong: string; + }; + }; + }; + num_mflix_comments: { + $numberInt: string; + }; + }; + + const aggregation: schema.Pipeline = [ + { + $search: { + range: { + path: '_id', + gte: bson.ObjectId.createFromHexString('573a1396f29313caabce4a9a'), + lte: bson.ObjectId.createFromHexString('573a1396f29313caabce4ae7'), + }, + }, + }, + { $project: { _id: 1, title: 1, released: 1 } }, + ]; } /** @@ -41,5 +303,65 @@ function test3() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/range/#string-example} */ function test4() { - // TODO: no schema found for range.String + type movies = { + _id: { + $oid: string; + }; + title: string; + year: { + $numberInt: string; + }; + runtime: { + $numberInt: string; + }; + released: { + $date: { + $numberLong: string; + }; + }; + poster: string; + plot: string; + fullplot: string; + lastupdated: string; + type: string; + directors: Array; + imdb: { + rating: { + $numberDouble: string; + }; + votes: { + $numberInt: string; + }; + id: { + $numberInt: string; + }; + }; + cast: Array; + countries: Array; + genres: Array; + tomatoes: { + viewer: { + rating: { + $numberDouble: string; + }; + numReviews: { + $numberInt: string; + }; + }; + lastUpdated: { + $date: { + $numberLong: string; + }; + }; + }; + num_mflix_comments: { + $numberInt: string; + }; + }; + + const aggregation: schema.Pipeline = [ + { $search: { range: { path: 'title', gt: 'city', lt: 'country' } } }, + { $limit: 5 }, + { $project: { _id: 0, title: 1 } }, + ]; } diff --git a/packages/mql-typescript/tests/search/regex.spec.ts b/packages/mql-typescript/tests/search/regex.spec.ts index 4352d7f3..ee152631 100644 --- a/packages/mql-typescript/tests/search/regex.spec.ts +++ b/packages/mql-typescript/tests/search/regex.spec.ts @@ -9,5 +9,64 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/regex/#examples} */ function test0() { - // TODO: no schema found for regex.Regex + type movies = { + _id: { + $oid: string; + }; + title: string; + year: { + $numberInt: string; + }; + runtime: { + $numberInt: string; + }; + released: { + $date: { + $numberLong: string; + }; + }; + poster: string; + plot: string; + fullplot: string; + lastupdated: string; + type: string; + directors: Array; + imdb: { + rating: { + $numberDouble: string; + }; + votes: { + $numberInt: string; + }; + id: { + $numberInt: string; + }; + }; + cast: Array; + countries: Array; + genres: Array; + tomatoes: { + viewer: { + rating: { + $numberDouble: string; + }; + numReviews: { + $numberInt: string; + }; + }; + lastUpdated: { + $date: { + $numberLong: string; + }; + }; + }; + num_mflix_comments: { + $numberInt: string; + }; + }; + + const aggregation: schema.Pipeline = [ + { $search: { regex: { path: 'title', query: '[0-9]{2} (.){4}s' } } }, + { $project: { _id: 0, title: 1 } }, + ]; } diff --git a/packages/mql-typescript/tests/search/text.spec.ts b/packages/mql-typescript/tests/search/text.spec.ts index ff45f4ad..e8ad0412 100644 --- a/packages/mql-typescript/tests/search/text.spec.ts +++ b/packages/mql-typescript/tests/search/text.spec.ts @@ -9,7 +9,66 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/text/#basic-example} */ function test0() { - // TODO: no schema found for text.Basic + type movies = { + _id: { + $oid: string; + }; + title: string; + year: { + $numberInt: string; + }; + runtime: { + $numberInt: string; + }; + released: { + $date: { + $numberLong: string; + }; + }; + poster: string; + plot: string; + fullplot: string; + lastupdated: string; + type: string; + directors: Array; + imdb: { + rating: { + $numberDouble: string; + }; + votes: { + $numberInt: string; + }; + id: { + $numberInt: string; + }; + }; + cast: Array; + countries: Array; + genres: Array; + tomatoes: { + viewer: { + rating: { + $numberDouble: string; + }; + numReviews: { + $numberInt: string; + }; + }; + lastUpdated: { + $date: { + $numberLong: string; + }; + }; + }; + num_mflix_comments: { + $numberInt: string; + }; + }; + + const aggregation: schema.Pipeline = [ + { $search: { text: { path: 'title', query: 'surfer' } } }, + { $project: { _id: 0, title: 1, score: { $meta: 'searchScore' } } }, + ]; } /** @@ -17,7 +76,67 @@ function test0() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/text/#fuzzy-examples} */ function test1() { - // TODO: no schema found for text.Fuzzy Default + type movies = { + _id: { + $oid: string; + }; + title: string; + year: { + $numberInt: string; + }; + runtime: { + $numberInt: string; + }; + released: { + $date: { + $numberLong: string; + }; + }; + poster: string; + plot: string; + fullplot: string; + lastupdated: string; + type: string; + directors: Array; + imdb: { + rating: { + $numberDouble: string; + }; + votes: { + $numberInt: string; + }; + id: { + $numberInt: string; + }; + }; + cast: Array; + countries: Array; + genres: Array; + tomatoes: { + viewer: { + rating: { + $numberDouble: string; + }; + numReviews: { + $numberInt: string; + }; + }; + lastUpdated: { + $date: { + $numberLong: string; + }; + }; + }; + num_mflix_comments: { + $numberInt: string; + }; + }; + + const aggregation: schema.Pipeline = [ + { $search: { text: { path: 'title', query: 'naw yark', fuzzy: {} } } }, + { $limit: 10 }, + { $project: { _id: 0, title: 1, score: { $meta: 'searchScore' } } }, + ]; } /** @@ -25,7 +144,75 @@ function test1() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/text/#fuzzy-examples} */ function test2() { - // TODO: no schema found for text.Fuzzy maxExpansions + type movies = { + _id: { + $oid: string; + }; + title: string; + year: { + $numberInt: string; + }; + runtime: { + $numberInt: string; + }; + released: { + $date: { + $numberLong: string; + }; + }; + poster: string; + plot: string; + fullplot: string; + lastupdated: string; + type: string; + directors: Array; + imdb: { + rating: { + $numberDouble: string; + }; + votes: { + $numberInt: string; + }; + id: { + $numberInt: string; + }; + }; + cast: Array; + countries: Array; + genres: Array; + tomatoes: { + viewer: { + rating: { + $numberDouble: string; + }; + numReviews: { + $numberInt: string; + }; + }; + lastUpdated: { + $date: { + $numberLong: string; + }; + }; + }; + num_mflix_comments: { + $numberInt: string; + }; + }; + + const aggregation: schema.Pipeline = [ + { + $search: { + text: { + path: 'title', + query: 'naw yark', + fuzzy: { maxEdits: 1, maxExpansions: 100 }, + }, + }, + }, + { $limit: 10 }, + { $project: { _id: 0, title: 1, score: { $meta: 'searchScore' } } }, + ]; } /** @@ -33,7 +220,75 @@ function test2() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/text/#fuzzy-examples} */ function test3() { - // TODO: no schema found for text.Fuzzy prefixLength + type movies = { + _id: { + $oid: string; + }; + title: string; + year: { + $numberInt: string; + }; + runtime: { + $numberInt: string; + }; + released: { + $date: { + $numberLong: string; + }; + }; + poster: string; + plot: string; + fullplot: string; + lastupdated: string; + type: string; + directors: Array; + imdb: { + rating: { + $numberDouble: string; + }; + votes: { + $numberInt: string; + }; + id: { + $numberInt: string; + }; + }; + cast: Array; + countries: Array; + genres: Array; + tomatoes: { + viewer: { + rating: { + $numberDouble: string; + }; + numReviews: { + $numberInt: string; + }; + }; + lastUpdated: { + $date: { + $numberLong: string; + }; + }; + }; + num_mflix_comments: { + $numberInt: string; + }; + }; + + const aggregation: schema.Pipeline = [ + { + $search: { + text: { + path: 'title', + query: 'naw yark', + fuzzy: { maxEdits: 1, prefixLength: 2 }, + }, + }, + }, + { $limit: 8 }, + { $project: { _id: 1, title: 1, score: { $meta: 'searchScore' } } }, + ]; } /** @@ -41,7 +296,78 @@ function test3() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/text/#match-any-using-equivalent-mapping} */ function test4() { - // TODO: no schema found for text.Match any Using equivalent Mapping + type movies = { + _id: { + $oid: string; + }; + title: string; + year: { + $numberInt: string; + }; + runtime: { + $numberInt: string; + }; + released: { + $date: { + $numberLong: string; + }; + }; + poster: string; + plot: string; + fullplot: string; + lastupdated: string; + type: string; + directors: Array; + imdb: { + rating: { + $numberDouble: string; + }; + votes: { + $numberInt: string; + }; + id: { + $numberInt: string; + }; + }; + cast: Array; + countries: Array; + genres: Array; + tomatoes: { + viewer: { + rating: { + $numberDouble: string; + }; + numReviews: { + $numberInt: string; + }; + }; + lastUpdated: { + $date: { + $numberLong: string; + }; + }; + }; + num_mflix_comments: { + $numberInt: string; + }; + }; + + const aggregation: schema.Pipeline = [ + { + $search: { + text: { + path: 'plot', + query: 'attire', + synonyms: 'my_synonyms', + matchCriteria: 'any', + }, + }, + }, + { $limit: 5 }, + { + $project: { _id: 0, plot: 1, title: 1, score: { $meta: 'searchScore' } }, + }, + ]; } /** @@ -49,7 +375,78 @@ function test4() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/text/#match-any-using-explicit-mapping} */ function test5() { - // TODO: no schema found for text.Match any Using explicit Mapping + type movies = { + _id: { + $oid: string; + }; + title: string; + year: { + $numberInt: string; + }; + runtime: { + $numberInt: string; + }; + released: { + $date: { + $numberLong: string; + }; + }; + poster: string; + plot: string; + fullplot: string; + lastupdated: string; + type: string; + directors: Array; + imdb: { + rating: { + $numberDouble: string; + }; + votes: { + $numberInt: string; + }; + id: { + $numberInt: string; + }; + }; + cast: Array; + countries: Array; + genres: Array; + tomatoes: { + viewer: { + rating: { + $numberDouble: string; + }; + numReviews: { + $numberInt: string; + }; + }; + lastUpdated: { + $date: { + $numberLong: string; + }; + }; + }; + num_mflix_comments: { + $numberInt: string; + }; + }; + + const aggregation: schema.Pipeline = [ + { + $search: { + text: { + path: 'plot', + query: 'boat race', + synonyms: 'my_synonyms', + matchCriteria: 'any', + }, + }, + }, + { $limit: 10 }, + { + $project: { _id: 0, plot: 1, title: 1, score: { $meta: 'searchScore' } }, + }, + ]; } /** @@ -57,7 +454,78 @@ function test5() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/text/#match-all-using-synonyms} */ function test6() { - // TODO: no schema found for text.Match all Using Synonyms + type movies = { + _id: { + $oid: string; + }; + title: string; + year: { + $numberInt: string; + }; + runtime: { + $numberInt: string; + }; + released: { + $date: { + $numberLong: string; + }; + }; + poster: string; + plot: string; + fullplot: string; + lastupdated: string; + type: string; + directors: Array; + imdb: { + rating: { + $numberDouble: string; + }; + votes: { + $numberInt: string; + }; + id: { + $numberInt: string; + }; + }; + cast: Array; + countries: Array; + genres: Array; + tomatoes: { + viewer: { + rating: { + $numberDouble: string; + }; + numReviews: { + $numberInt: string; + }; + }; + lastUpdated: { + $date: { + $numberLong: string; + }; + }; + }; + num_mflix_comments: { + $numberInt: string; + }; + }; + + const aggregation: schema.Pipeline = [ + { + $search: { + text: { + path: 'plot', + query: 'automobile race', + matchCriteria: 'all', + synonyms: 'my_synonyms', + }, + }, + }, + { $limit: 20 }, + { + $project: { _id: 0, plot: 1, title: 1, score: { $meta: 'searchScore' } }, + }, + ]; } /** @@ -65,5 +533,64 @@ function test6() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/text/} */ function test7() { - // TODO: no schema found for text.Wildcard Path + type movies = { + _id: { + $oid: string; + }; + title: string; + year: { + $numberInt: string; + }; + runtime: { + $numberInt: string; + }; + released: { + $date: { + $numberLong: string; + }; + }; + poster: string; + plot: string; + fullplot: string; + lastupdated: string; + type: string; + directors: Array; + imdb: { + rating: { + $numberDouble: string; + }; + votes: { + $numberInt: string; + }; + id: { + $numberInt: string; + }; + }; + cast: Array; + countries: Array; + genres: Array; + tomatoes: { + viewer: { + rating: { + $numberDouble: string; + }; + numReviews: { + $numberInt: string; + }; + }; + lastUpdated: { + $date: { + $numberLong: string; + }; + }; + }; + num_mflix_comments: { + $numberInt: string; + }; + }; + + const aggregation: schema.Pipeline = [ + { $search: { text: { path: { wildcard: '*' }, query: 'surfer' } } }, + { $project: { _id: 0, title: 1, score: { $meta: 'searchScore' } } }, + ]; } diff --git a/packages/mql-typescript/tests/search/vectorSearch.spec.ts b/packages/mql-typescript/tests/search/vectorSearch.spec.ts index 2c0d8800..7ea6f00a 100644 --- a/packages/mql-typescript/tests/search/vectorSearch.spec.ts +++ b/packages/mql-typescript/tests/search/vectorSearch.spec.ts @@ -9,27 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/vector-search/#basic-example} */ function test0() { - type movies = { - plot_embedding: Array; - plot: string; - title: string; - }; - - const aggregation: schema.Pipeline = [ - { - $search: { - vectorSearch: { - path: 'plot_embedding', - queryVector: [-0.0016261312, -0.028070757, -0.011342932], - numCandidates: 150, - limit: 10, - }, - }, - }, - { - $project: { _id: 0, plot: 1, title: 1, score: { $meta: 'searchScore' } }, - }, - ]; + // TODO: no schema found for vectorSearch.ANN Basic: // TODO: No schema found in docs } /** @@ -37,35 +17,7 @@ function test0() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/vector-search/#filter-example} */ function test1() { - type movies = { - plot_embedding: Array; - year: bson.Int32 | number; - plot: string; - title: string; - }; - - const aggregation: schema.Pipeline = [ - { - $search: { - vectorSearch: { - path: 'plot_embedding', - queryVector: [0.02421053, -0.022372592, -0.006231137], - filter: { range: { path: 'year', lt: 1975 } }, - numCandidates: 150, - limit: 10, - }, - }, - }, - { - $project: { - _id: 0, - title: 1, - plot: 1, - year: 1, - score: { $meta: 'searchScore' }, - }, - }, - ]; + // TODO: no schema found for vectorSearch.ANN Filter: // TODO: No schema found in docs } /** @@ -73,25 +25,5 @@ function test1() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/vector-search/#enn-example} */ function test2() { - type movies = { - plot_embedding: Array; - plot: string; - title: string; - }; - - const aggregation: schema.Pipeline = [ - { - $search: { - vectorSearch: { - path: 'plot_embedding', - queryVector: [-0.006954097, -0.009932499, -0.001311474], - exact: true, - limit: 10, - }, - }, - }, - { - $project: { _id: 0, plot: 1, title: 1, score: { $meta: 'searchScore' } }, - }, - ]; + // TODO: no schema found for vectorSearch.ENN: // TODO: No schema found in docs } diff --git a/packages/mql-typescript/tests/search/wildcard.spec.ts b/packages/mql-typescript/tests/search/wildcard.spec.ts index 958553d6..480cd105 100644 --- a/packages/mql-typescript/tests/search/wildcard.spec.ts +++ b/packages/mql-typescript/tests/search/wildcard.spec.ts @@ -9,7 +9,67 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/wildcard/#index-definition} */ function test0() { - // TODO: no schema found for wildcard.Wildcard Path + type movies = { + _id: { + $oid: string; + }; + title: string; + year: { + $numberInt: string; + }; + runtime: { + $numberInt: string; + }; + released: { + $date: { + $numberLong: string; + }; + }; + poster: string; + plot: string; + fullplot: string; + lastupdated: string; + type: string; + directors: Array; + imdb: { + rating: { + $numberDouble: string; + }; + votes: { + $numberInt: string; + }; + id: { + $numberInt: string; + }; + }; + cast: Array; + countries: Array; + genres: Array; + tomatoes: { + viewer: { + rating: { + $numberDouble: string; + }; + numReviews: { + $numberInt: string; + }; + }; + lastUpdated: { + $date: { + $numberLong: string; + }; + }; + }; + num_mflix_comments: { + $numberInt: string; + }; + }; + + const aggregation: schema.Pipeline = [ + { $search: { wildcard: { query: 'Wom?n *', path: { wildcard: '*' } } } }, + { $limit: 5 }, + { $project: { _id: 0, title: 1 } }, + ]; } /** @@ -17,5 +77,65 @@ function test0() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/wildcard/#escape-character-example} */ function test1() { - // TODO: no schema found for wildcard.Escape Character Example + type movies = { + _id: { + $oid: string; + }; + title: string; + year: { + $numberInt: string; + }; + runtime: { + $numberInt: string; + }; + released: { + $date: { + $numberLong: string; + }; + }; + poster: string; + plot: string; + fullplot: string; + lastupdated: string; + type: string; + directors: Array; + imdb: { + rating: { + $numberDouble: string; + }; + votes: { + $numberInt: string; + }; + id: { + $numberInt: string; + }; + }; + cast: Array; + countries: Array; + genres: Array; + tomatoes: { + viewer: { + rating: { + $numberDouble: string; + }; + numReviews: { + $numberInt: string; + }; + }; + lastUpdated: { + $date: { + $numberLong: string; + }; + }; + }; + num_mflix_comments: { + $numberInt: string; + }; + }; + + const aggregation: schema.Pipeline = [ + { $search: { wildcard: { query: '*\\?', path: 'title' } } }, + { $limit: 5 }, + { $project: { _id: 0, title: 1 } }, + ]; } diff --git a/packages/mql-typescript/tests/stage/addFields.spec.ts b/packages/mql-typescript/tests/stage/addFields.spec.ts index e3cc878c..fef5b3c2 100644 --- a/packages/mql-typescript/tests/stage/addFields.spec.ts +++ b/packages/mql-typescript/tests/stage/addFields.spec.ts @@ -9,7 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/addFields/#using-two--addfields-stages} */ function test0() { - // TODO: no schema found for addFields.Using Two $addFields Stages + // TODO: no schema found for addFields.Using Two $addFields Stages: // TODO: No schema found in docs } /** @@ -17,7 +17,7 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/addFields/#adding-fields-to-an-embedded-document} */ function test1() { - // TODO: no schema found for addFields.Adding Fields to an Embedded Document + // TODO: no schema found for addFields.Adding Fields to an Embedded Document: // TODO: No schema found in docs } /** @@ -25,7 +25,7 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/addFields/#overwriting-an-existing-field} */ function test2() { - // TODO: no schema found for addFields.Overwriting an existing field + // TODO: no schema found for addFields.Overwriting an existing field: // TODO: No schema found in docs } /** @@ -33,5 +33,5 @@ function test2() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/addFields/#add-element-to-an-array} */ function test3() { - // TODO: no schema found for addFields.Add Element to an Array + // TODO: no schema found for addFields.Add Element to an Array: // TODO: No schema found in docs } diff --git a/packages/mql-typescript/tests/stage/bucket.spec.ts b/packages/mql-typescript/tests/stage/bucket.spec.ts index b0b335f2..3087cdb2 100644 --- a/packages/mql-typescript/tests/stage/bucket.spec.ts +++ b/packages/mql-typescript/tests/stage/bucket.spec.ts @@ -9,7 +9,38 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/bucket/#bucket-by-year-and-filter-by-bucket-results} */ function test0() { - // TODO: no schema found for bucket.Bucket by Year and Filter by Bucket Results + type artists = { + _id: number; + last_name: string; + first_name: string; + year_born: number; + year_died: number; + nationality: string; + }; + + const aggregation: schema.Pipeline = [ + { + $bucket: { + groupBy: '$year_born', + boundaries: [1840, 1850, 1860, 1870, 1880], + default: 'Other', + output: { + count: { $sum: 1 }, + artists: { + $push: { + name: { $concat: ['$first_name', ' ', '$last_name'] }, + year_born: '$year_born', + }, + }, + }, + }, + }, + + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (the output field of the $bucket stage generates new fields that are not available statically). + */ + { $match: { count: { $gt: 3 } } } as any, + ]; } /** @@ -17,5 +48,45 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/bucket/#use--bucket-with--facet-to-bucket-by-multiple-fields} */ function test1() { - // TODO: no schema found for bucket.Use $bucket with $facet to Bucket by Multiple Fields + type artwork = { + _id: number; + title: string; + artist: string; + year: number; + price: bson.Decimal128; + }; + + const aggregation: schema.Pipeline = [ + { + $facet: { + price: [ + { + $bucket: { + groupBy: '$price', + boundaries: [0, 200, 400], + default: 'Other', + output: { + count: { $sum: 1 }, + artwork: { $push: { title: '$title', price: '$price' } }, + averagePrice: { $avg: '$price' }, + }, + }, + }, + ], + year: [ + { + $bucket: { + groupBy: '$year', + boundaries: [1890, 1910, 1920, 1940], + default: 'Unknown', + output: { + count: { $sum: 1 }, + artwork: { $push: { title: '$title', year: '$year' } }, + }, + }, + }, + ], + }, + }, + ]; } diff --git a/packages/mql-typescript/tests/stage/bucketAuto.spec.ts b/packages/mql-typescript/tests/stage/bucketAuto.spec.ts index ac237a1e..eb003ef8 100644 --- a/packages/mql-typescript/tests/stage/bucketAuto.spec.ts +++ b/packages/mql-typescript/tests/stage/bucketAuto.spec.ts @@ -9,5 +9,20 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/bucketAuto/#single-facet-aggregation} */ function test0() { - // TODO: no schema found for bucketAuto.Single Facet Aggregation + type artwork = { + _id: bson.Int32 | number; + title: string; + artist: string; + year: bson.Int32 | number; + price: bson.Decimal128; + dimensions: { + height: bson.Int32 | number; + width: bson.Int32 | number; + units: string; + }; + }; + + const aggregation: schema.Pipeline = [ + { $bucketAuto: { groupBy: '$price', buckets: 4 } }, + ]; } diff --git a/packages/mql-typescript/tests/stage/changeStream.spec.ts b/packages/mql-typescript/tests/stage/changeStream.spec.ts index b7e209bd..1aeb4aa0 100644 --- a/packages/mql-typescript/tests/stage/changeStream.spec.ts +++ b/packages/mql-typescript/tests/stage/changeStream.spec.ts @@ -9,5 +9,9 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/changeStream/#examples} */ function test0() { - // TODO: no schema found for changeStream.Example + type names = { + _id: bson.ObjectId; + }; + + const aggregation: schema.Pipeline = [{ $changeStream: {} }]; } diff --git a/packages/mql-typescript/tests/stage/changeStreamSplitLargeEvent.spec.ts b/packages/mql-typescript/tests/stage/changeStreamSplitLargeEvent.spec.ts index 57aa8c46..ea1e2fc0 100644 --- a/packages/mql-typescript/tests/stage/changeStreamSplitLargeEvent.spec.ts +++ b/packages/mql-typescript/tests/stage/changeStreamSplitLargeEvent.spec.ts @@ -9,5 +9,12 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/changeStreamSplitLargeEvent/#example} */ function test0() { - // TODO: no schema found for changeStreamSplitLargeEvent.Example + type myCollection = { + _id: bson.Int32 | number; + largeField: string; + }; + + const aggregation: schema.Pipeline = [ + { $changeStreamSplitLargeEvent: {} }, + ]; } diff --git a/packages/mql-typescript/tests/stage/collStats.spec.ts b/packages/mql-typescript/tests/stage/collStats.spec.ts index f00ef0b6..84573f94 100644 --- a/packages/mql-typescript/tests/stage/collStats.spec.ts +++ b/packages/mql-typescript/tests/stage/collStats.spec.ts @@ -9,7 +9,13 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/collStats/#latencystats-document} */ function test0() { - // TODO: no schema found for collStats.latencyStats Document + type TestCollection = { + _id: bson.ObjectId; + }; + + const aggregation: schema.Pipeline = [ + { $collStats: { latencyStats: { histograms: true } } }, + ]; } /** @@ -17,7 +23,13 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/collStats/#storagestats-document} */ function test1() { - // TODO: no schema found for collStats.storageStats Document + type TestCollection = { + _id: bson.ObjectId; + }; + + const aggregation: schema.Pipeline = [ + { $collStats: { storageStats: {} } }, + ]; } /** @@ -25,7 +37,13 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/collStats/#count-field} */ function test2() { - // TODO: no schema found for collStats.count Field + type TestCollection = { + _id: bson.ObjectId; + }; + + const aggregation: schema.Pipeline = [ + { $collStats: { count: {} } }, + ]; } /** @@ -33,5 +51,11 @@ function test2() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/collStats/#queryexecstats-document} */ function test3() { - // TODO: no schema found for collStats.queryExecStats Document + type TestCollection = { + _id: bson.ObjectId; + }; + + const aggregation: schema.Pipeline = [ + { $collStats: { queryExecStats: {} } }, + ]; } diff --git a/packages/mql-typescript/tests/stage/count.spec.ts b/packages/mql-typescript/tests/stage/count.spec.ts index 10488111..45c44cae 100644 --- a/packages/mql-typescript/tests/stage/count.spec.ts +++ b/packages/mql-typescript/tests/stage/count.spec.ts @@ -9,5 +9,5 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/count/#example} */ function test0() { - // TODO: no schema found for count.Example + // TODO: no schema found for count.Example: // TODO: No schema found in docs } diff --git a/packages/mql-typescript/tests/stage/currentOp.spec.ts b/packages/mql-typescript/tests/stage/currentOp.spec.ts index d6df9ddd..f4dd6573 100644 --- a/packages/mql-typescript/tests/stage/currentOp.spec.ts +++ b/packages/mql-typescript/tests/stage/currentOp.spec.ts @@ -9,7 +9,18 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/currentOp/#inactive-sessions} */ function test0() { - // TODO: no schema found for currentOp.Inactive Sessions + type TestCollection = { + _id: bson.ObjectId; + }; + + const aggregation: schema.Pipeline = [ + { $currentOp: { allUsers: true, idleSessions: true } }, + + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' ($currentOp emits new fields that are not available statically). + */ + { $match: { active: false, transaction: { $exists: true } } } as any, + ]; } /** @@ -17,5 +28,16 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/currentOp/#sampled-queries} */ function test1() { - // TODO: no schema found for currentOp.Sampled Queries + type TestCollection = { + _id: bson.ObjectId; + }; + + const aggregation: schema.Pipeline = [ + { $currentOp: { allUsers: true, localOps: true } }, + + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' ($currentOp emits new fields that are not available statically). + */ + { $match: { desc: 'query analyzer' } } as any, + ]; } diff --git a/packages/mql-typescript/tests/stage/densify.spec.ts b/packages/mql-typescript/tests/stage/densify.spec.ts index 12ce07dd..1b104a05 100644 --- a/packages/mql-typescript/tests/stage/densify.spec.ts +++ b/packages/mql-typescript/tests/stage/densify.spec.ts @@ -9,7 +9,30 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/densify/#densify-time-series-data} */ function test0() { - // TODO: no schema found for densify.Densify Time Series Data + type weather = { + metadata: { + sensorId: number; + type: string; + }; + timestamp: Date; + temp: number; + }; + + const aggregation: schema.Pipeline = [ + { + $densify: { + field: 'timestamp', + range: { + step: 1, + unit: 'hour', + bounds: [ + new Date('2021-05-18T00:00:00.000Z'), + new Date('2021-05-18T08:00:00.000Z'), + ], + }, + }, + }, + ]; } /** @@ -17,5 +40,5 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/densify/#densifiction-with-partitions} */ function test1() { - // TODO: no schema found for densify.Densifiction with Partitions + // TODO: no schema found for densify.Densifiction with Partitions: // TODO: No schema found in docs } diff --git a/packages/mql-typescript/tests/stage/documents.spec.ts b/packages/mql-typescript/tests/stage/documents.spec.ts index 73b4cd27..2c560b0e 100644 --- a/packages/mql-typescript/tests/stage/documents.spec.ts +++ b/packages/mql-typescript/tests/stage/documents.spec.ts @@ -9,7 +9,14 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/documents/#test-a-pipeline-stage} */ function test0() { - // TODO: no schema found for documents.Test a Pipeline Stage + type TestCollection = { + x: number; + }; + + const aggregation: schema.Pipeline = [ + { $documents: [{ x: 10 }, { x: 2 }, { x: 5 }] }, + { $bucketAuto: { groupBy: '$x', buckets: 4 } }, + ]; } /** @@ -17,5 +24,27 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/documents/#use-a--documents-stage-in-a--lookup-stage} */ function test1() { - // TODO: no schema found for documents.Use a $documents Stage in a $lookup Stage + type locations = { + zip: number; + name: string; + }; + + const aggregation: schema.Pipeline = [ + { $match: {} }, + { + $lookup: { + localField: 'zip', + foreignField: 'zip_id', + as: 'city_state', + pipeline: [ + { + $documents: [ + { zip_id: 94301, name: 'Palo Alto, CA' }, + { zip_id: 10019, name: 'New York, NY' }, + ], + }, + ], + }, + }, + ]; } diff --git a/packages/mql-typescript/tests/stage/facet.spec.ts b/packages/mql-typescript/tests/stage/facet.spec.ts index af4a475e..4c21e897 100644 --- a/packages/mql-typescript/tests/stage/facet.spec.ts +++ b/packages/mql-typescript/tests/stage/facet.spec.ts @@ -9,5 +9,5 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/facet/#example} */ function test0() { - // TODO: no schema found for facet.Example + // TODO: no schema found for facet.Example: // TODO: No schema found in docs } diff --git a/packages/mql-typescript/tests/stage/fill.spec.ts b/packages/mql-typescript/tests/stage/fill.spec.ts index 17b929ea..2a29d4e7 100644 --- a/packages/mql-typescript/tests/stage/fill.spec.ts +++ b/packages/mql-typescript/tests/stage/fill.spec.ts @@ -9,7 +9,24 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/fill/#fill-missing-field-values-with-a-constant-value} */ function test0() { - // TODO: no schema found for fill.Fill Missing Field Values with a Constant Value + type dailySales = { + date: Date; + bootsSold: number; + sandalsSold: number; + sneakersSold: number; + }; + + const aggregation: schema.Pipeline = [ + { + $fill: { + output: { + bootsSold: { value: 0 }, + sandalsSold: { value: 0 }, + sneakersSold: { value: 0 }, + }, + }, + }, + ]; } /** @@ -17,7 +34,14 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/fill/#fill-missing-field-values-with-linear-interpolation} */ function test1() { - // TODO: no schema found for fill.Fill Missing Field Values with Linear Interpolation + type stock = { + time: Date; + price: number; + }; + + const aggregation: schema.Pipeline = [ + { $fill: { sortBy: { time: 1 }, output: { price: { method: 'linear' } } } }, + ]; } /** @@ -25,7 +49,14 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/fill/#fill-missing-field-values-based-on-the-last-observed-value} */ function test2() { - // TODO: no schema found for fill.Fill Missing Field Values Based on the Last Observed Value + type restaurantReviews = { + date: Date; + score: number; + }; + + const aggregation: schema.Pipeline = [ + { $fill: { sortBy: { date: 1 }, output: { score: { method: 'locf' } } } }, + ]; } /** @@ -33,7 +64,21 @@ function test2() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/fill/#fill-data-for-distinct-partitions} */ function test3() { - // TODO: no schema found for fill.Fill Data for Distinct Partitions + type restaurantReviewsMultiple = { + date: Date; + restaurant: string; + score: number; + }; + + const aggregation: schema.Pipeline = [ + { + $fill: { + sortBy: { date: 1 }, + partitionBy: { restaurant: '$restaurant' }, + output: { score: { method: 'locf' } }, + }, + }, + ]; } /** @@ -41,5 +86,19 @@ function test3() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/fill/#indicate-if-a-field-was-populated-using--fill} */ function test4() { - // TODO: no schema found for fill.Indicate if a Field was Populated Using $fill + type restaurantReviews = { + date: Date; + score: number; + }; + + const aggregation: schema.Pipeline = [ + { + $set: { + valueExisted: { + $ifNull: [{ $toBool: { $toString: '$score' } }, false], + }, + }, + }, + { $fill: { sortBy: { date: 1 }, output: { score: { method: 'locf' } } } }, + ]; } diff --git a/packages/mql-typescript/tests/stage/geoNear.spec.ts b/packages/mql-typescript/tests/stage/geoNear.spec.ts index e1c91e13..986f4470 100644 --- a/packages/mql-typescript/tests/stage/geoNear.spec.ts +++ b/packages/mql-typescript/tests/stage/geoNear.spec.ts @@ -9,7 +9,27 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/geoNear/#maximum-distance} */ function test0() { - // TODO: no schema found for geoNear.Maximum Distance + type places = { + name: string; + location: { + type: string; + coordinates: Array; + }; + category: string; + }; + + const aggregation: schema.Pipeline = [ + { + $geoNear: { + near: { type: 'Point', coordinates: [-73.99279, 40.719296] }, + distanceField: 'dist.calculated', + maxDistance: 2, + query: { category: 'Parks' }, + includeLocs: 'dist.location', + spherical: true, + }, + }, + ]; } /** @@ -17,7 +37,27 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/geoNear/#minimum-distance} */ function test1() { - // TODO: no schema found for geoNear.Minimum Distance + type places = { + name: string; + location: { + type: string; + coordinates: Array; + }; + category: string; + }; + + const aggregation: schema.Pipeline = [ + { + $geoNear: { + near: { type: 'Point', coordinates: [-73.99279, 40.719296] }, + distanceField: 'dist.calculated', + minDistance: 2, + query: { category: 'Parks' }, + includeLocs: 'dist.location', + spherical: true, + }, + }, + ]; } /** @@ -25,7 +65,27 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/geoNear/#-geonear-with-the-let-option} */ function test2() { - // TODO: no schema found for geoNear.with the let option + type places = { + name: string; + location: { + type: string; + coordinates: Array; + }; + category: string; + }; + + const aggregation: schema.Pipeline = [ + { + $geoNear: { + near: '$$pt', + distanceField: 'distance', + maxDistance: 2, + query: { category: 'Parks' }, + includeLocs: 'dist.location', + spherical: true, + }, + }, + ]; } /** @@ -33,7 +93,26 @@ function test2() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/geoNear/#-geonear-with-bound-let-option} */ function test3() { - // TODO: no schema found for geoNear.with Bound let Option + type places = { + name: string; + location: { + type: string; + coordinates: Array; + }; + category: string; + }; + + const aggregation: schema.Pipeline = [ + { + $lookup: { + from: 'places', + let: { pt: '$location' }, + pipeline: [{ $geoNear: { near: '$$pt', distanceField: 'distance' } }], + as: 'joinedField', + }, + }, + { $match: { name: 'Sara D. Roosevelt Park' } }, + ]; } /** @@ -41,5 +120,26 @@ function test3() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/geoNear/#specify-which-geospatial-index-to-use} */ function test4() { - // TODO: no schema found for geoNear.Specify Which Geospatial Index to Use + type places = { + _id: number; + name: string; + location: { + type: string; + coordinates: Array; + }; + legacy: Array; + category: string; + }; + + const aggregation: schema.Pipeline = [ + { + $geoNear: { + near: { type: 'Point', coordinates: [-73.98142, 40.71782] }, + key: 'location', + distanceField: 'dist.calculated', + query: { category: 'Parks' }, + }, + }, + { $limit: 5 }, + ]; } diff --git a/packages/mql-typescript/tests/stage/graphLookup.spec.ts b/packages/mql-typescript/tests/stage/graphLookup.spec.ts index 58570e92..55db1c37 100644 --- a/packages/mql-typescript/tests/stage/graphLookup.spec.ts +++ b/packages/mql-typescript/tests/stage/graphLookup.spec.ts @@ -9,7 +9,23 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/graphLookup/#within-a-single-collection} */ function test0() { - // TODO: no schema found for graphLookup.Within a Single Collection + type employees = { + _id: number; + name: string; + reportsTo: string; + }; + + const aggregation: schema.Pipeline = [ + { + $graphLookup: { + from: 'employees', + startWith: '$reportsTo', + connectFromField: 'reportsTo', + connectToField: 'name', + as: 'reportingHierarchy', + }, + }, + ]; } /** @@ -17,7 +33,25 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/graphLookup/#across-multiple-collections} */ function test1() { - // TODO: no schema found for graphLookup.Across Multiple Collections + type airports = { + _id: number; + airport: string; + connects: Array; + }; + + const aggregation: schema.Pipeline = [ + { + $graphLookup: { + from: 'airports', + startWith: '$nearestAirport', + connectFromField: 'connects', + connectToField: 'airport', + maxDepth: 2, + depthField: 'numConnections', + as: 'destinations', + }, + }, + ]; } /** @@ -25,5 +59,31 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/graphLookup/#with-a-query-filter} */ function test2() { - // TODO: no schema found for graphLookup.With a Query Filter + type people = { + _id: number; + name: string; + friends: Array; + hobbies: Array; + }; + + const aggregation: schema.Pipeline = [ + { $match: { name: 'Tanya Jordan' } }, + { + $graphLookup: { + from: 'people', + startWith: '$friends', + connectFromField: 'friends', + connectToField: 'name', + as: 'golfers', + restrictSearchWithMatch: { hobbies: 'golf' }, + }, + }, + { + $project: { + name: 1, + friends: 1, + 'connections who play golf': '$golfers.name', + }, + }, + ]; } diff --git a/packages/mql-typescript/tests/stage/group.spec.ts b/packages/mql-typescript/tests/stage/group.spec.ts index c5197f02..9770eca0 100644 --- a/packages/mql-typescript/tests/stage/group.spec.ts +++ b/packages/mql-typescript/tests/stage/group.spec.ts @@ -9,7 +9,14 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/group/#count-the-number-of-documents-in-a-collection} */ function test0() { - // TODO: no schema found for group.Count the Number of Documents in a Collection + type TestCollection = { + _id: null; + count: number; + }; + + const aggregation: schema.Pipeline = [ + { $group: { _id: null, count: { $count: {} } } }, + ]; } /** @@ -17,7 +24,14 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/group/#retrieve-distinct-values} */ function test1() { - // TODO: no schema found for group.Retrieve Distinct Values + type TestCollection = { + _id: null; + count: number; + }; + + const aggregation: schema.Pipeline = [ + { $group: { _id: '$item' } }, + ]; } /** @@ -25,7 +39,7 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/group/#group-by-item-having} */ function test2() { - // TODO: no schema found for group.Group by Item Having + // TODO: no schema found for group.Group by Item Having: // TODO: No schema found in docs } /** @@ -33,7 +47,33 @@ function test2() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/group/#calculate-count--sum--and-average} */ function test3() { - // TODO: no schema found for group.Calculate Count Sum and Average + type sales = { + _id: bson.Int32 | number; + item: string; + price: bson.Decimal128; + quantity: bson.Int32 | number; + date: Date; + }; + + const aggregation: schema.Pipeline = [ + { + $match: { + date: { + $gte: new Date('2014-01-01T00:00:00.000Z'), + $lt: new Date('2015-01-01T00:00:00.000Z'), + }, + }, + }, + { + $group: { + _id: { $dateToString: { format: '%Y-%m-%d', date: '$date' } }, + totalSaleAmount: { $sum: { $multiply: ['$price', '$quantity'] } }, + averageQuantity: { $avg: '$quantity' }, + count: { $sum: 1 }, + }, + }, + { $sort: { totalSaleAmount: -1 } }, + ]; } /** @@ -41,7 +81,24 @@ function test3() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/group/#group-by-null} */ function test4() { - // TODO: no schema found for group.Group by null + type sales = { + _id: bson.Int32 | number; + item: string; + price: bson.Decimal128; + quantity: bson.Int32 | number; + date: Date; + }; + + const aggregation: schema.Pipeline = [ + { + $group: { + _id: null, + totalSaleAmount: { $sum: { $multiply: ['$price', '$quantity'] } }, + averageQuantity: { $avg: '$quantity' }, + count: { $sum: 1 }, + }, + }, + ]; } /** @@ -49,7 +106,14 @@ function test4() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/group/#pivot-data} */ function test5() { - // TODO: no schema found for group.Pivot Data + type TestCollection = { + _id: null; + count: number; + }; + + const aggregation: schema.Pipeline = [ + { $group: { _id: '$author', books: { $push: '$title' } } }, + ]; } /** @@ -57,5 +121,5 @@ function test5() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/group/#group-documents-by-author} */ function test6() { - // TODO: no schema found for group.Group Documents by author + // TODO: no schema found for group.Group Documents by author: // TODO: No schema found in docs } diff --git a/packages/mql-typescript/tests/stage/indexStats.spec.ts b/packages/mql-typescript/tests/stage/indexStats.spec.ts index 469b08e4..5b78f315 100644 --- a/packages/mql-typescript/tests/stage/indexStats.spec.ts +++ b/packages/mql-typescript/tests/stage/indexStats.spec.ts @@ -9,5 +9,5 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/indexStats/#example} */ function test0() { - // TODO: no schema found for indexStats.Example + // TODO: no schema found for indexStats.Example: // TODO: No schema found in docs } diff --git a/packages/mql-typescript/tests/stage/limit.spec.ts b/packages/mql-typescript/tests/stage/limit.spec.ts index c538181b..91c1f15f 100644 --- a/packages/mql-typescript/tests/stage/limit.spec.ts +++ b/packages/mql-typescript/tests/stage/limit.spec.ts @@ -9,5 +9,9 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/limit/#example} */ function test0() { - // TODO: no schema found for limit.Example + type TestCollection = { + _id: bson.ObjectId; + }; + + const aggregation: schema.Pipeline = [{ $limit: 5 }]; } diff --git a/packages/mql-typescript/tests/stage/listLocalSessions.spec.ts b/packages/mql-typescript/tests/stage/listLocalSessions.spec.ts index cfa29d2d..cd4c9736 100644 --- a/packages/mql-typescript/tests/stage/listLocalSessions.spec.ts +++ b/packages/mql-typescript/tests/stage/listLocalSessions.spec.ts @@ -9,7 +9,13 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/listLocalSessions/#list-all-local-sessions} */ function test0() { - // TODO: no schema found for listLocalSessions.List All Local Sessions + type TestCollection = { + _id: bson.ObjectId; + }; + + const aggregation: schema.Pipeline = [ + { $listLocalSessions: { allUsers: true } }, + ]; } /** @@ -17,7 +23,13 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/listLocalSessions/#list-all-local-sessions-for-the-specified-users} */ function test1() { - // TODO: no schema found for listLocalSessions.List All Local Sessions for the Specified Users + type TestCollection = { + _id: bson.ObjectId; + }; + + const aggregation: schema.Pipeline = [ + { $listLocalSessions: { users: [{ user: 'myAppReader', db: 'test' }] } }, + ]; } /** @@ -25,5 +37,11 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/listLocalSessions/#list-all-local-sessions-for-the-current-user} */ function test2() { - // TODO: no schema found for listLocalSessions.List All Local Sessions for the Current User + type TestCollection = { + _id: bson.ObjectId; + }; + + const aggregation: schema.Pipeline = [ + { $listLocalSessions: {} }, + ]; } diff --git a/packages/mql-typescript/tests/stage/listSampledQueries.spec.ts b/packages/mql-typescript/tests/stage/listSampledQueries.spec.ts index 75099972..da8ddda6 100644 --- a/packages/mql-typescript/tests/stage/listSampledQueries.spec.ts +++ b/packages/mql-typescript/tests/stage/listSampledQueries.spec.ts @@ -9,7 +9,13 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSampledQueries/#list-sampled-queries-for-all-collections} */ function test0() { - // TODO: no schema found for listSampledQueries.List Sampled Queries for All Collections + type TestCollection = { + _id: bson.ObjectId; + }; + + const aggregation: schema.Pipeline = [ + { $listSampledQueries: {} }, + ]; } /** @@ -17,5 +23,11 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSampledQueries/#list-sampled-queries-for-a-specific-collection} */ function test1() { - // TODO: no schema found for listSampledQueries.List Sampled Queries for A Specific Collection + type TestCollection = { + _id: bson.ObjectId; + }; + + const aggregation: schema.Pipeline = [ + { $listSampledQueries: { namespace: 'social.post' } }, + ]; } diff --git a/packages/mql-typescript/tests/stage/listSearchIndexes.spec.ts b/packages/mql-typescript/tests/stage/listSearchIndexes.spec.ts index c9200bf7..535fc125 100644 --- a/packages/mql-typescript/tests/stage/listSearchIndexes.spec.ts +++ b/packages/mql-typescript/tests/stage/listSearchIndexes.spec.ts @@ -9,7 +9,13 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSearchIndexes/#return-all-search-indexes} */ function test0() { - // TODO: no schema found for listSearchIndexes.Return All Search Indexes + type TestCollection = { + _id: bson.ObjectId; + }; + + const aggregation: schema.Pipeline = [ + { $listSearchIndexes: {} }, + ]; } /** @@ -17,7 +23,13 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSearchIndexes/#return-a-single-search-index-by-name} */ function test1() { - // TODO: no schema found for listSearchIndexes.Return a Single Search Index by Name + type TestCollection = { + _id: bson.ObjectId; + }; + + const aggregation: schema.Pipeline = [ + { $listSearchIndexes: { name: 'synonym-mappings' } }, + ]; } /** @@ -25,5 +37,11 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSearchIndexes/#return-a-single-search-index-by-id} */ function test2() { - // TODO: no schema found for listSearchIndexes.Return a Single Search Index by id + type TestCollection = { + _id: bson.ObjectId; + }; + + const aggregation: schema.Pipeline = [ + { $listSearchIndexes: { id: '6524096020da840844a4c4a7' } }, + ]; } diff --git a/packages/mql-typescript/tests/stage/listSessions.spec.ts b/packages/mql-typescript/tests/stage/listSessions.spec.ts index cebdaa6e..dd14b8f2 100644 --- a/packages/mql-typescript/tests/stage/listSessions.spec.ts +++ b/packages/mql-typescript/tests/stage/listSessions.spec.ts @@ -9,7 +9,13 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSessions/#list-all-sessions} */ function test0() { - // TODO: no schema found for listSessions.List All Sessions + type TestCollection = { + _id: bson.ObjectId; + }; + + const aggregation: schema.Pipeline = [ + { $listSessions: { allUsers: true } }, + ]; } /** @@ -17,7 +23,13 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSessions/#list-all-sessions-for-the-specified-users} */ function test1() { - // TODO: no schema found for listSessions.List All Sessions for the Specified Users + type TestCollection = { + _id: bson.ObjectId; + }; + + const aggregation: schema.Pipeline = [ + { $listSessions: { users: [{ user: 'myAppReader', db: 'test' }] } }, + ]; } /** @@ -25,5 +37,9 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSessions/#list-all-sessions-for-the-current-user} */ function test2() { - // TODO: no schema found for listSessions.List All Sessions for the Current User + type TestCollection = { + _id: bson.ObjectId; + }; + + const aggregation: schema.Pipeline = [{ $listSessions: {} }]; } diff --git a/packages/mql-typescript/tests/stage/lookup.spec.ts b/packages/mql-typescript/tests/stage/lookup.spec.ts index 341ead26..0198eb0d 100644 --- a/packages/mql-typescript/tests/stage/lookup.spec.ts +++ b/packages/mql-typescript/tests/stage/lookup.spec.ts @@ -9,7 +9,26 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/lookup/#perform-a-single-equality-join-with--lookup} */ function test0() { - // TODO: no schema found for lookup.Perform a Single Equality Join with $lookup + type TestCollection = { + title: string; + year: number; + movie_comments: Array<{ + name: string; + text: string; + date: Date; + }>; + }; + + const aggregation: schema.Pipeline = [ + { + $lookup: { + from: 'inventory', + localField: 'item', + foreignField: 'sku', + as: 'inventory_docs', + }, + }, + ]; } /** @@ -17,7 +36,26 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/lookup/#use--lookup-with-an-array} */ function test1() { - // TODO: no schema found for lookup.Use $lookup with an Array + type TestCollection = { + title: string; + year: number; + movie_comments: Array<{ + name: string; + text: string; + date: Date; + }>; + }; + + const aggregation: schema.Pipeline = [ + { + $lookup: { + from: 'members', + localField: 'enrollmentlist', + foreignField: 'name', + as: 'enrollee_info', + }, + }, + ]; } /** @@ -25,7 +63,34 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/lookup/#use--lookup-with--mergeobjects} */ function test2() { - // TODO: no schema found for lookup.Use $lookup with $mergeObjects + type TestCollection = { + title: string; + year: number; + movie_comments: Array<{ + name: string; + text: string; + date: Date; + }>; + }; + + const aggregation: schema.Pipeline = [ + { + $lookup: { + from: 'items', + localField: 'item', + foreignField: 'item', + as: 'fromItems', + }, + }, + { + $replaceRoot: { + newRoot: { + $mergeObjects: [{ $arrayElemAt: ['$fromItems', 0] }, '$$ROOT'], + }, + }, + }, + { $project: { fromItems: 0 } }, + ]; } /** @@ -33,7 +98,7 @@ function test2() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/lookup/#perform-multiple-joins-and-a-correlated-subquery-with--lookup} */ function test3() { - // TODO: no schema found for lookup.Perform Multiple Joins and a Correlated Subquery with $lookup + // TODO: no schema found for lookup.Perform Multiple Joins and a Correlated Subquery with $lookup: // TODO: No schema found in docs } /** @@ -41,7 +106,32 @@ function test3() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/lookup/#perform-an-uncorrelated-subquery-with--lookup} */ function test4() { - // TODO: no schema found for lookup.Perform an Uncorrelated Subquery with $lookup + type TestCollection = { + title: string; + year: number; + movie_comments: Array<{ + name: string; + text: string; + date: Date; + }>; + }; + + const aggregation: schema.Pipeline = [ + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (the lookup sub-pipeline references fields from the joined collection that are not available statically). + */ + { + $lookup: { + from: 'holidays', + pipeline: [ + { $match: { year: 2018 } }, + { $project: { _id: 0, date: { name: '$name', date: '$date' } } }, + { $replaceRoot: { newRoot: '$date' } }, + ], + as: 'holidays', + }, + } as any, + ]; } /** @@ -49,5 +139,31 @@ function test4() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/lookup/#perform-a-concise-correlated-subquery-with--lookup} */ function test5() { - // TODO: no schema found for lookup.Perform a Concise Correlated Subquery with $lookup + type TestCollection = { + title: string; + year: number; + movie_comments: Array<{ + name: string; + text: string; + date: Date; + }>; + }; + + const aggregation: schema.Pipeline = [ + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (the lookup sub-pipeline references the variables defined in the `let` field, which are not available statically). + */ + { + $lookup: { + from: 'restaurants', + localField: 'restaurant_name', + foreignField: 'name', + let: { orders_drink: '$drink' }, + pipeline: [ + { $match: { $expr: { $in: ['$$orders_drink', '$beverages'] } } }, + ], + as: 'matches', + }, + } as any, + ]; } diff --git a/packages/mql-typescript/tests/stage/match.spec.ts b/packages/mql-typescript/tests/stage/match.spec.ts index 29a079dc..8a042a41 100644 --- a/packages/mql-typescript/tests/stage/match.spec.ts +++ b/packages/mql-typescript/tests/stage/match.spec.ts @@ -9,7 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/match/#equality-match} */ function test0() { - // TODO: no schema found for match.Equality Match + // TODO: no schema found for match.Equality Match: // TODO: No schema found in docs } /** @@ -17,5 +17,5 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/match/#perform-a-count} */ function test1() { - // TODO: no schema found for match.Perform a Count + // TODO: no schema found for match.Perform a Count: // TODO: No schema found in docs } diff --git a/packages/mql-typescript/tests/stage/merge.spec.ts b/packages/mql-typescript/tests/stage/merge.spec.ts index 31829993..2f69ac13 100644 --- a/packages/mql-typescript/tests/stage/merge.spec.ts +++ b/packages/mql-typescript/tests/stage/merge.spec.ts @@ -9,7 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/#on-demand-materialized-view--initial-creation} */ function test0() { - // TODO: no schema found for merge.On-Demand Materialized View Initial Creation + // TODO: no schema found for merge.On-Demand Materialized View Initial Creation: // TODO: No schema found in docs } /** @@ -17,7 +17,7 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/#on-demand-materialized-view--update-replace-data} */ function test1() { - // TODO: no schema found for merge.On-Demand Materialized View Update Replace Data + // TODO: no schema found for merge.On-Demand Materialized View Update Replace Data: // TODO: No schema found in docs } /** @@ -25,7 +25,7 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/#only-insert-new-data} */ function test2() { - // TODO: no schema found for merge.Only Insert New Data + // TODO: no schema found for merge.Only Insert New Data: // TODO: No schema found in docs } /** @@ -33,7 +33,7 @@ function test2() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/#merge-results-from-multiple-collections} */ function test3() { - // TODO: no schema found for merge.Merge Results from Multiple Collections + // TODO: no schema found for merge.Merge Results from Multiple Collections: // TODO: No schema found in docs } /** @@ -41,7 +41,7 @@ function test3() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/#use-the-pipeline-to-customize-the-merge} */ function test4() { - // TODO: no schema found for merge.Use the Pipeline to Customize the Merge + // TODO: no schema found for merge.Use the Pipeline to Customize the Merge: // TODO: No schema found in docs } /** @@ -49,5 +49,5 @@ function test4() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/#use-variables-to-customize-the-merge} */ function test5() { - // TODO: no schema found for merge.Use Variables to Customize the Merge + // TODO: no schema found for merge.Use Variables to Customize the Merge: // TODO: No schema found in docs } diff --git a/packages/mql-typescript/tests/stage/out.spec.ts b/packages/mql-typescript/tests/stage/out.spec.ts index a8886710..114c9c1a 100644 --- a/packages/mql-typescript/tests/stage/out.spec.ts +++ b/packages/mql-typescript/tests/stage/out.spec.ts @@ -9,7 +9,17 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/out/#output-to-same-database} */ function test0() { - // TODO: no schema found for out.Output to Same Database + type books = { + _id: number; + title: string; + author: string; + copies: number; + }; + + const aggregation: schema.Pipeline = [ + { $group: { _id: '$author', books: { $push: '$title' } } }, + { $out: { coll: 'authors' } }, + ]; } /** @@ -17,7 +27,17 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/out/#output-to-a-different-database} */ function test1() { - // TODO: no schema found for out.Output to a Different Database + type books = { + _id: number; + title: string; + author: string; + copies: number; + }; + + const aggregation: schema.Pipeline = [ + { $group: { _id: '$author', books: { $push: '$title' } } }, + { $out: { db: 'reporting', coll: 'authors' } }, + ]; } /** @@ -25,23 +45,5 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/out/#output-to-a-time-series-collection} */ function test2() { - type sensors = { - timestamp: Date; - sensorId: string; - temperature: number; - }; - - const aggregation: schema.Pipeline = [ - { - $out: { - db: 'reporting', - coll: 'sensorData', - timeseries: { - timeField: 'timestamp', - metaField: 'sensorId', - granularity: 'hours', - }, - }, - }, - ]; + // TODO: no schema found for out.Output to a Time Series Collection: // TODO: No schema found in docs } diff --git a/packages/mql-typescript/tests/stage/planCacheStats.spec.ts b/packages/mql-typescript/tests/stage/planCacheStats.spec.ts index 3173e5ae..65a247c4 100644 --- a/packages/mql-typescript/tests/stage/planCacheStats.spec.ts +++ b/packages/mql-typescript/tests/stage/planCacheStats.spec.ts @@ -9,7 +9,15 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/planCacheStats/#return-information-for-all-entries-in-the-query-cache} */ function test0() { - // TODO: no schema found for planCacheStats.Return Information for All Entries in the Query Cache + type orders = { + _id: number; + item: string; + price: bson.Decimal128; + quantity: number; + type: string; + }; + + const aggregation: schema.Pipeline = [{ $planCacheStats: {} }]; } /** @@ -17,5 +25,20 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/planCacheStats/#find-cache-entry-details-for-a-query-hash} */ function test1() { - // TODO: no schema found for planCacheStats.Find Cache Entry Details for a Query Hash + type orders = { + _id: number; + item: string; + price: bson.Decimal128; + quantity: number; + type: string; + }; + + const aggregation: schema.Pipeline = [ + { $planCacheStats: {} }, + + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' ($planCacheStats emits new fields that are not available statically). + */ + { $match: { planCacheKey: 'B1435201' } } as any, + ]; } diff --git a/packages/mql-typescript/tests/stage/project.spec.ts b/packages/mql-typescript/tests/stage/project.spec.ts index 9122990c..cd22e771 100644 --- a/packages/mql-typescript/tests/stage/project.spec.ts +++ b/packages/mql-typescript/tests/stage/project.spec.ts @@ -9,7 +9,15 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/project/#include-specific-fields-in-output-documents} */ function test0() { - // TODO: no schema found for project.Include Specific Fields in Output Documents + type TestCollection = { + _id: bson.ObjectId; + title: string; + rated: string; + }; + + const aggregation: schema.Pipeline = [ + { $project: { title: 1, author: 1 } }, + ]; } /** @@ -17,7 +25,15 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/project/#suppress-_id-field-in-the-output-documents} */ function test1() { - // TODO: no schema found for project.Suppress id Field in the Output Documents + type TestCollection = { + _id: bson.ObjectId; + title: string; + rated: string; + }; + + const aggregation: schema.Pipeline = [ + { $project: { _id: 0, title: 1, author: 1 } }, + ]; } /** @@ -25,7 +41,15 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/project/#exclude-fields-from-output-documents} */ function test2() { - // TODO: no schema found for project.Exclude Fields from Output Documents + type TestCollection = { + _id: bson.ObjectId; + title: string; + rated: string; + }; + + const aggregation: schema.Pipeline = [ + { $project: { lastModified: 0 } }, + ]; } /** @@ -33,7 +57,16 @@ function test2() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/project/#exclude-fields-from-embedded-documents} */ function test3() { - // TODO: no schema found for project.Exclude Fields from Embedded Documents + type TestCollection = { + _id: bson.ObjectId; + title: string; + rated: string; + }; + + const aggregation: schema.Pipeline = [ + { $project: { 'author.first': 0, lastModified: 0 } }, + { $project: { author: { first: 0 }, lastModified: 0 } }, + ]; } /** @@ -41,7 +74,28 @@ function test3() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/project/#conditionally-exclude-fields} */ function test4() { - // TODO: no schema found for project.Conditionally Exclude Fields + type TestCollection = { + _id: bson.ObjectId; + title: string; + rated: string; + }; + + const aggregation: schema.Pipeline = [ + { + $project: { + title: 1, + 'author.first': 1, + 'author.last': 1, + 'author.middle': { + $cond: { + if: { $eq: ['', '$author.middle'] }, + then: '$$REMOVE', + else: '$author.middle', + }, + }, + }, + }, + ]; } /** @@ -49,7 +103,16 @@ function test4() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/project/#include-specific-fields-from-embedded-documents} */ function test5() { - // TODO: no schema found for project.Include Specific Fields from Embedded Documents + type TestCollection = { + _id: bson.ObjectId; + title: string; + rated: string; + }; + + const aggregation: schema.Pipeline = [ + { $project: { 'stop.title': 1 } }, + { $project: { stop: { title: 1 } } }, + ]; } /** @@ -57,7 +120,28 @@ function test5() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/project/#include-computed-fields} */ function test6() { - // TODO: no schema found for project.Include Computed Fields + type TestCollection = { + _id: bson.ObjectId; + title: string; + rated: string; + }; + + const aggregation: schema.Pipeline = [ + { + $project: { + title: 1, + isbn: { + prefix: { $substr: ['$isbn', 0, 3] }, + group: { $substr: ['$isbn', 3, 2] }, + publisher: { $substr: ['$isbn', 5, 4] }, + title: { $substr: ['$isbn', 9, 3] }, + checkDigit: { $substr: ['$isbn', 12, 1] }, + }, + lastName: '$author.last', + copiesSold: '$copies', + }, + }, + ]; } /** @@ -65,5 +149,13 @@ function test6() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/project/#project-new-array-fields} */ function test7() { - // TODO: no schema found for project.Project New Array Fields + type TestCollection = { + _id: bson.ObjectId; + x: bson.Int32 | number; + y: bson.Int32 | number; + }; + + const aggregation: schema.Pipeline = [ + { $project: { myArray: ['$x', '$y'] } }, + ]; } diff --git a/packages/mql-typescript/tests/stage/rankFusion.spec.ts b/packages/mql-typescript/tests/stage/rankFusion.spec.ts index 7b8b64ea..972ab776 100644 --- a/packages/mql-typescript/tests/stage/rankFusion.spec.ts +++ b/packages/mql-typescript/tests/stage/rankFusion.spec.ts @@ -9,5 +9,5 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/rankFusion/#examples} */ function test0() { - // TODO: no schema found for rankFusion.Example + // TODO: no schema found for rankFusion.Example: // TODO: No schema found in docs } diff --git a/packages/mql-typescript/tests/stage/redact.spec.ts b/packages/mql-typescript/tests/stage/redact.spec.ts index e13a9dde..9f98954a 100644 --- a/packages/mql-typescript/tests/stage/redact.spec.ts +++ b/packages/mql-typescript/tests/stage/redact.spec.ts @@ -9,7 +9,37 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/redact/#evaluate-access-at-every-document-level} */ function test0() { - // TODO: no schema found for redact.Evaluate Access at Every Document Level + type forecasts = { + _id: number; + title: string; + tags: Array; + year: number; + subsections: Array<{ + subtitle: string; + tags: Array; + content: + | string + | { + text: string; + tags: Array; + }; + }>; + }; + + const aggregation: schema.Pipeline = [ + { $match: { year: 2014 } }, + { + $redact: { + $cond: { + if: { + $gt: [{ $size: { $setIntersection: ['$tags', ['STLW', 'G']] } }, 0], + }, + then: '$$DESCEND', + else: '$$PRUNE', + }, + }, + }, + ]; } /** @@ -17,5 +47,39 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/redact/#exclude-all-fields-at-a-given-level} */ function test1() { - // TODO: no schema found for redact.Exclude All Fields at a Given Level + type accounts = { + _id: number; + level: number; + acct_id: string; + cc: { + level: number; + type: string; + num: number; + exp_date: Date; + billing_addr: { + level: number; + addr1: string; + city: string; + }; + shipping_addr: Array<{ + level: number; + addr1: string; + city: string; + }>; + }; + status: string; + }; + + const aggregation: schema.Pipeline = [ + { $match: { status: 'A' } }, + { + $redact: { + $cond: { + if: { $eq: ['$level', 5] }, + then: '$$PRUNE', + else: '$$DESCEND', + }, + }, + }, + ]; } diff --git a/packages/mql-typescript/tests/stage/replaceRoot.spec.ts b/packages/mql-typescript/tests/stage/replaceRoot.spec.ts index 75808db3..e4d1308e 100644 --- a/packages/mql-typescript/tests/stage/replaceRoot.spec.ts +++ b/packages/mql-typescript/tests/stage/replaceRoot.spec.ts @@ -9,7 +9,26 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceRoot/#-replaceroot-with-an-embedded-document-field} */ function test0() { - // TODO: no schema found for replaceRoot.with an Embedded Document Field + type TestCollection = { + _id: number; + name: string; + age: number; + pets: { + dogs: number; + cats: number; + fish: number; + }; + }; + + const aggregation: schema.Pipeline = [ + { + $replaceRoot: { + newRoot: { + $mergeObjects: [{ dogs: 0, cats: 0, birds: 0, fish: 0 }, '$pets'], + }, + }, + }, + ]; } /** @@ -17,7 +36,29 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceRoot/#-replaceroot-with-a-document-nested-in-an-array} */ function test1() { - // TODO: no schema found for replaceRoot.with a Document Nested in an Array + type students = { + _id: number; + grades: Array<{ + test: number; + grade: number; + mean: number; + std: number; + }>; + }; + + const aggregation: schema.Pipeline = [ + { $unwind: { path: '$grades' } }, + + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). + */ + { $match: { 'grades.grade': { $gte: 90 } } } as any, + + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). + */ + { $replaceRoot: { newRoot: '$grades' } } as any, + ]; } /** @@ -25,7 +66,20 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceRoot/#-replaceroot-with-a-newly-created-document} */ function test2() { - // TODO: no schema found for replaceRoot.with a newly created document + type TestCollection = { + _id: number; + first_name: string; + last_name: string; + city: string; + }; + + const aggregation: schema.Pipeline = [ + { + $replaceRoot: { + newRoot: { full_name: { $concat: ['$first_name', ' ', '$last_name'] } }, + }, + }, + ]; } /** @@ -33,5 +87,24 @@ function test2() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceRoot/#-replaceroot-with-a-new-document-created-from---root-and-a-default-document} */ function test3() { - // TODO: no schema found for replaceRoot.with a New Document Created from $$ROOT and a Default Document + type contacts = { + _id: number; + name: string; + email: string; + cell: string; + home: string; + }; + + const aggregation: schema.Pipeline = [ + { + $replaceRoot: { + newRoot: { + $mergeObjects: [ + { _id: '', name: '', email: '', cell: '', home: '' }, + '$$ROOT', + ], + }, + }, + }, + ]; } diff --git a/packages/mql-typescript/tests/stage/replaceWith.spec.ts b/packages/mql-typescript/tests/stage/replaceWith.spec.ts index 93f00270..6da06f72 100644 --- a/packages/mql-typescript/tests/stage/replaceWith.spec.ts +++ b/packages/mql-typescript/tests/stage/replaceWith.spec.ts @@ -9,7 +9,24 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceWith/#-replacewith-an-embedded-document-field} */ function test0() { - // TODO: no schema found for replaceWith.an Embedded Document Field + type people = { + _id: number; + name: string; + age: number; + pets: { + dogs: number; + cats: number; + fish: number; + }; + }; + + const aggregation: schema.Pipeline = [ + { + $replaceWith: { + $mergeObjects: [{ dogs: 0, cats: 0, birds: 0, fish: 0 }, '$pets'], + }, + }, + ]; } /** @@ -17,7 +34,29 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceWith/#-replacewith-a-document-nested-in-an-array} */ function test1() { - // TODO: no schema found for replaceWith.a Document Nested in an Array + type students = { + _id: number; + grades: Array<{ + test: number; + grade: number; + mean: number; + std: number; + }>; + }; + + const aggregation: schema.Pipeline = [ + { $unwind: { path: '$grades' } }, + + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). + */ + { $match: { 'grades.grade': { $gte: 90 } } } as any, + + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). + */ + { $replaceWith: '$grades' } as any, + ]; } /** @@ -25,7 +64,27 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceWith/#-replacewith-a-newly-created-document} */ function test2() { - // TODO: no schema found for replaceWith.a Newly Created Document + type sales = { + _id: number; + item: string; + price: number; + quantity: number; + date: Date; + status: string; + }; + + const aggregation: schema.Pipeline = [ + { $match: { status: 'C' } }, + { + $replaceWith: { + _id: '$_id', + item: '$item', + amount: { $multiply: ['$price', '$quantity'] }, + status: 'Complete', + asofDate: '$$NOW', + }, + }, + ]; } /** @@ -33,5 +92,21 @@ function test2() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceWith/#-replacewith-a-new-document-created-from---root-and-a-default-document} */ function test3() { - // TODO: no schema found for replaceWith.a New Document Created from $$ROOT and a Default Document + type contacts = { + _id: number; + name: string; + email: string; + cell: string; + }; + + const aggregation: schema.Pipeline = [ + { + $replaceWith: { + $mergeObjects: [ + { _id: '', name: '', email: '', cell: '', home: '' }, + '$$ROOT', + ], + }, + }, + ]; } diff --git a/packages/mql-typescript/tests/stage/rerank.spec.ts b/packages/mql-typescript/tests/stage/rerank.spec.ts index 84aad1c7..6a6ae7ba 100644 --- a/packages/mql-typescript/tests/stage/rerank.spec.ts +++ b/packages/mql-typescript/tests/stage/rerank.spec.ts @@ -9,5 +9,5 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/vector-search/query/aggregation-stages/rerank/#examples} */ function test0() { - // TODO: no schema found for rerank.Example + // TODO: no schema found for rerank.Example: // TODO: No schema found in docs } diff --git a/packages/mql-typescript/tests/stage/sample.spec.ts b/packages/mql-typescript/tests/stage/sample.spec.ts index f9f2c19b..bfabfe62 100644 --- a/packages/mql-typescript/tests/stage/sample.spec.ts +++ b/packages/mql-typescript/tests/stage/sample.spec.ts @@ -9,5 +9,5 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/sample/#example} */ function test0() { - // TODO: no schema found for sample.Example + // TODO: no schema found for sample.Example: // TODO: No schema found in docs } diff --git a/packages/mql-typescript/tests/stage/score.spec.ts b/packages/mql-typescript/tests/stage/score.spec.ts index cf64c514..a7e89b4c 100644 --- a/packages/mql-typescript/tests/stage/score.spec.ts +++ b/packages/mql-typescript/tests/stage/score.spec.ts @@ -9,11 +9,5 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/score/} */ function test0() { - type movies = { - plot_embedding: Array; - }; - - const aggregation: schema.Pipeline = [ - { $score: { score: { $meta: 'vectorSearchScore' } } }, - ]; + // TODO: no schema found for score.Example: // TODO: No schema found in docs } diff --git a/packages/mql-typescript/tests/stage/scoreFusion.spec.ts b/packages/mql-typescript/tests/stage/scoreFusion.spec.ts index e25c9951..3c2c99fc 100644 --- a/packages/mql-typescript/tests/stage/scoreFusion.spec.ts +++ b/packages/mql-typescript/tests/stage/scoreFusion.spec.ts @@ -9,5 +9,5 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/scoreFusion/#examples} */ function test0() { - // TODO: no schema found for scoreFusion.Example + // TODO: no schema found for scoreFusion.Example: // TODO: No schema found in docs } diff --git a/packages/mql-typescript/tests/stage/search.spec.ts b/packages/mql-typescript/tests/stage/search.spec.ts index 114208f4..c2e11bcc 100644 --- a/packages/mql-typescript/tests/stage/search.spec.ts +++ b/packages/mql-typescript/tests/stage/search.spec.ts @@ -9,7 +9,85 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/query-syntax/#aggregation-variable} */ function test0() { - // TODO: no schema found for search.Example + type movies = { + _id: { + $oid: string; + }; + title: string; + year: { + $numberInt: string; + }; + runtime: { + $numberInt: string; + }; + released: { + $date: { + $numberLong: string; + }; + }; + poster: string; + plot: string; + fullplot: string; + lastupdated: string; + type: string; + directors: Array; + imdb: { + rating: { + $numberDouble: string; + }; + votes: { + $numberInt: string; + }; + id: { + $numberInt: string; + }; + }; + cast: Array; + countries: Array; + genres: Array; + tomatoes: { + viewer: { + rating: { + $numberDouble: string; + }; + numReviews: { + $numberInt: string; + }; + }; + lastUpdated: { + $date: { + $numberLong: string; + }; + }; + }; + num_mflix_comments: { + $numberInt: string; + }; + }; + + const aggregation: schema.Pipeline = [ + { + $search: { + near: { + path: 'released', + origin: new Date('2011-09-01T00:00:00.000Z'), + pivot: 7776000000, + }, + }, + }, + { $project: { _id: 0, title: 1, released: 1 } }, + { $limit: 5 }, + + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' ($search emits new fields that are not available statically, such as $$SEARCH_META). + */ + { + $facet: { + docs: [], + meta: [{ $replaceWith: '$$SEARCH_META' }, { $limit: 1 }], + }, + } as any, + ]; } /** @@ -17,7 +95,76 @@ function test0() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/sort/#date-search-and-sort} */ function test1() { - // TODO: no schema found for search.Date Search and Sort + type movies = { + _id: { + $oid: string; + }; + title: string; + year: { + $numberInt: string; + }; + runtime: { + $numberInt: string; + }; + released: { + $date: { + $numberLong: string; + }; + }; + poster: string; + plot: string; + fullplot: string; + lastupdated: string; + type: string; + directors: Array; + imdb: { + rating: { + $numberDouble: string; + }; + votes: { + $numberInt: string; + }; + id: { + $numberInt: string; + }; + }; + cast: Array; + countries: Array; + genres: Array; + tomatoes: { + viewer: { + rating: { + $numberDouble: string; + }; + numReviews: { + $numberInt: string; + }; + }; + lastUpdated: { + $date: { + $numberLong: string; + }; + }; + }; + num_mflix_comments: { + $numberInt: string; + }; + }; + + const aggregation: schema.Pipeline = [ + { + $search: { + range: { + path: 'released', + gt: new Date('2010-01-01T00:00:00.000Z'), + lt: new Date('2015-01-01T00:00:00.000Z'), + }, + sort: { released: -1 }, + }, + }, + { $limit: 5 }, + { $project: { _id: 0, title: 1, released: 1 } }, + ]; } /** @@ -25,7 +172,83 @@ function test1() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/sort/#number-search-and-sort} */ function test2() { - // TODO: no schema found for search.Number Search and Sort + type movies = { + _id: { + $oid: string; + }; + title: string; + year: { + $numberInt: string; + }; + runtime: { + $numberInt: string; + }; + released: { + $date: { + $numberLong: string; + }; + }; + poster: string; + plot: string; + fullplot: string; + lastupdated: string; + type: string; + directors: Array; + imdb: { + rating: { + $numberDouble: string; + }; + votes: { + $numberInt: string; + }; + id: { + $numberInt: string; + }; + }; + cast: Array; + countries: Array; + genres: Array; + tomatoes: { + viewer: { + rating: { + $numberDouble: string; + }; + numReviews: { + $numberInt: string; + }; + }; + lastUpdated: { + $date: { + $numberLong: string; + }; + }; + }; + num_mflix_comments: { + $numberInt: string; + }; + }; + + const aggregation: schema.Pipeline = [ + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). + */ + { + $search: { + range: { path: 'awards.wins', gt: 3 }, + sort: { 'awards.wins': -1 }, + }, + } as any, + + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). + */ + { $limit: 5 } as any, + + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). + */ + { $project: { _id: 0, title: 1, 'awards.wins': 1 } } as any, + ]; } /** @@ -33,7 +256,72 @@ function test2() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/sort/#sort-by-score} */ function test3() { - // TODO: no schema found for search.Sort by score + type movies = { + _id: { + $oid: string; + }; + title: string; + year: { + $numberInt: string; + }; + runtime: { + $numberInt: string; + }; + released: { + $date: { + $numberLong: string; + }; + }; + poster: string; + plot: string; + fullplot: string; + lastupdated: string; + type: string; + directors: Array; + imdb: { + rating: { + $numberDouble: string; + }; + votes: { + $numberInt: string; + }; + id: { + $numberInt: string; + }; + }; + cast: Array; + countries: Array; + genres: Array; + tomatoes: { + viewer: { + rating: { + $numberDouble: string; + }; + numReviews: { + $numberInt: string; + }; + }; + lastUpdated: { + $date: { + $numberLong: string; + }; + }; + }; + num_mflix_comments: { + $numberInt: string; + }; + }; + + const aggregation: schema.Pipeline = [ + { + $search: { + text: { path: 'title', query: 'story' }, + sort: { score: { $meta: 'searchScore', order: 1 } }, + }, + }, + { $limit: 5 }, + { $project: { _id: 0, title: 1, score: { $meta: 'searchScore' } } }, + ]; } /** @@ -41,7 +329,71 @@ function test3() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/paginate-results/#search-after-the-reference-point} */ function test4() { - // TODO: no schema found for search.Paginate results after a token + type movies = { + _id: { + $oid: string; + }; + title: string; + year: { + $numberInt: string; + }; + runtime: { + $numberInt: string; + }; + released: { + $date: { + $numberLong: string; + }; + }; + poster: string; + plot: string; + fullplot: string; + lastupdated: string; + type: string; + directors: Array; + imdb: { + rating: { + $numberDouble: string; + }; + votes: { + $numberInt: string; + }; + id: { + $numberInt: string; + }; + }; + cast: Array; + countries: Array; + genres: Array; + tomatoes: { + viewer: { + rating: { + $numberDouble: string; + }; + numReviews: { + $numberInt: string; + }; + }; + lastUpdated: { + $date: { + $numberLong: string; + }; + }; + }; + num_mflix_comments: { + $numberInt: string; + }; + }; + + const aggregation: schema.Pipeline = [ + { + $search: { + text: { path: 'title', query: 'war' }, + sort: { score: { $meta: 'searchScore' }, released: 1 }, + searchAfter: 'CMtJGgYQuq+ngwgaCSkAjBYH7AAAAA==', + }, + }, + ]; } /** @@ -49,7 +401,71 @@ function test4() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/paginate-results/#search-before-the-reference-point} */ function test5() { - // TODO: no schema found for search.Paginate results before a token + type movies = { + _id: { + $oid: string; + }; + title: string; + year: { + $numberInt: string; + }; + runtime: { + $numberInt: string; + }; + released: { + $date: { + $numberLong: string; + }; + }; + poster: string; + plot: string; + fullplot: string; + lastupdated: string; + type: string; + directors: Array; + imdb: { + rating: { + $numberDouble: string; + }; + votes: { + $numberInt: string; + }; + id: { + $numberInt: string; + }; + }; + cast: Array; + countries: Array; + genres: Array; + tomatoes: { + viewer: { + rating: { + $numberDouble: string; + }; + numReviews: { + $numberInt: string; + }; + }; + lastUpdated: { + $date: { + $numberLong: string; + }; + }; + }; + num_mflix_comments: { + $numberInt: string; + }; + }; + + const aggregation: schema.Pipeline = [ + { + $search: { + text: { path: 'title', query: 'war' }, + sort: { score: { $meta: 'searchScore' }, released: 1 }, + searchBefore: 'CJ6kARoGELqvp4MIGgkpACDA3U8BAAA=', + }, + }, + ]; } /** @@ -57,7 +473,76 @@ function test5() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/counting/#count-results} */ function test6() { - // TODO: no schema found for search.Count results + type movies = { + _id: { + $oid: string; + }; + title: string; + year: { + $numberInt: string; + }; + runtime: { + $numberInt: string; + }; + released: { + $date: { + $numberLong: string; + }; + }; + poster: string; + plot: string; + fullplot: string; + lastupdated: string; + type: string; + directors: Array; + imdb: { + rating: { + $numberDouble: string; + }; + votes: { + $numberInt: string; + }; + id: { + $numberInt: string; + }; + }; + cast: Array; + countries: Array; + genres: Array; + tomatoes: { + viewer: { + rating: { + $numberDouble: string; + }; + numReviews: { + $numberInt: string; + }; + }; + lastUpdated: { + $date: { + $numberLong: string; + }; + }; + }; + num_mflix_comments: { + $numberInt: string; + }; + }; + + const aggregation: schema.Pipeline = [ + { + $search: { + near: { + path: 'released', + origin: new Date('2011-09-01T00:00:00.000Z'), + pivot: 7776000000, + }, + count: { type: 'total' }, + }, + }, + { $project: { meta: '$$SEARCH_META', title: 1, released: 1 } }, + { $limit: 2 }, + ]; } /** @@ -65,7 +550,72 @@ function test6() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/tracking/#examples} */ function test7() { - // TODO: no schema found for search.Track Search terms + type movies = { + _id: { + $oid: string; + }; + title: string; + year: { + $numberInt: string; + }; + runtime: { + $numberInt: string; + }; + released: { + $date: { + $numberLong: string; + }; + }; + poster: string; + plot: string; + fullplot: string; + lastupdated: string; + type: string; + directors: Array; + imdb: { + rating: { + $numberDouble: string; + }; + votes: { + $numberInt: string; + }; + id: { + $numberInt: string; + }; + }; + cast: Array; + countries: Array; + genres: Array; + tomatoes: { + viewer: { + rating: { + $numberDouble: string; + }; + numReviews: { + $numberInt: string; + }; + }; + lastUpdated: { + $date: { + $numberLong: string; + }; + }; + }; + num_mflix_comments: { + $numberInt: string; + }; + }; + + const aggregation: schema.Pipeline = [ + { + $search: { + text: { query: 'summer', path: 'title' }, + tracking: { searchTerms: 'summer' }, + }, + }, + { $limit: 5 }, + { $project: { _id: 0, title: 1 } }, + ]; } /** @@ -73,5 +623,92 @@ function test7() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/return-stored-source/#examples} */ function test8() { - // TODO: no schema found for search.Return Stored Source Fields + type movies = { + _id: { + $oid: string; + }; + title: string; + year: { + $numberInt: string; + }; + runtime: { + $numberInt: string; + }; + released: { + $date: { + $numberLong: string; + }; + }; + poster: string; + plot: string; + fullplot: string; + lastupdated: string; + type: string; + directors: Array; + imdb: { + rating: { + $numberDouble: string; + }; + votes: { + $numberInt: string; + }; + id: { + $numberInt: string; + }; + }; + cast: Array; + countries: Array; + genres: Array; + tomatoes: { + viewer: { + rating: { + $numberDouble: string; + }; + numReviews: { + $numberInt: string; + }; + }; + lastUpdated: { + $date: { + $numberLong: string; + }; + }; + }; + num_mflix_comments: { + $numberInt: string; + }; + }; + + const aggregation: schema.Pipeline = [ + { + $search: { + text: { query: 'baseball', path: 'title' }, + returnStoredSource: true, + }, + }, + + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). + */ + { + $match: { + $or: [ + { 'imdb.rating': { $gt: 8.2 } }, + { 'imdb.votes': { $gte: 4500 } }, + ], + }, + } as any, + + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). + */ + { + $lookup: { + from: 'movies', + localField: '_id', + foreignField: '_id', + as: 'document', + }, + } as any, + ]; } diff --git a/packages/mql-typescript/tests/stage/searchMeta.spec.ts b/packages/mql-typescript/tests/stage/searchMeta.spec.ts index 239e6c82..cb0a44a5 100644 --- a/packages/mql-typescript/tests/stage/searchMeta.spec.ts +++ b/packages/mql-typescript/tests/stage/searchMeta.spec.ts @@ -9,7 +9,70 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/query-syntax/#example} */ function test0() { - // TODO: no schema found for searchMeta.Example + type movies = { + _id: { + $oid: string; + }; + title: string; + year: { + $numberInt: string; + }; + runtime: { + $numberInt: string; + }; + released: { + $date: { + $numberLong: string; + }; + }; + poster: string; + plot: string; + fullplot: string; + lastupdated: string; + type: string; + directors: Array; + imdb: { + rating: { + $numberDouble: string; + }; + votes: { + $numberInt: string; + }; + id: { + $numberInt: string; + }; + }; + cast: Array; + countries: Array; + genres: Array; + tomatoes: { + viewer: { + rating: { + $numberDouble: string; + }; + numReviews: { + $numberInt: string; + }; + }; + lastUpdated: { + $date: { + $numberLong: string; + }; + }; + }; + num_mflix_comments: { + $numberInt: string; + }; + }; + + const aggregation: schema.Pipeline = [ + { + $searchMeta: { + range: { path: 'year', gte: 1998, lt: 1999 }, + count: { type: 'total' }, + }, + }, + ]; } /** @@ -17,7 +80,79 @@ function test0() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/facet/#example-1} */ function test1() { - // TODO: no schema found for searchMeta.Year Facet + type movies = { + _id: { + $oid: string; + }; + title: string; + year: { + $numberInt: string; + }; + runtime: { + $numberInt: string; + }; + released: { + $date: { + $numberLong: string; + }; + }; + poster: string; + plot: string; + fullplot: string; + lastupdated: string; + type: string; + directors: Array; + imdb: { + rating: { + $numberDouble: string; + }; + votes: { + $numberInt: string; + }; + id: { + $numberInt: string; + }; + }; + cast: Array; + countries: Array; + genres: Array; + tomatoes: { + viewer: { + rating: { + $numberDouble: string; + }; + numReviews: { + $numberInt: string; + }; + }; + lastUpdated: { + $date: { + $numberLong: string; + }; + }; + }; + num_mflix_comments: { + $numberInt: string; + }; + }; + + const aggregation: schema.Pipeline = [ + { + $searchMeta: { + facet: { + operator: { range: { path: 'year', gte: 1980, lte: 2000 } }, + facets: { + yearFacet: { + type: 'number', + path: 'year', + boundaries: [1980, 1990, 2000], + default: 'other', + }, + }, + }, + }, + }, + ]; } /** @@ -25,7 +160,90 @@ function test1() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/facet/#example-2} */ function test2() { - // TODO: no schema found for searchMeta.Date Facet + type movies = { + _id: { + $oid: string; + }; + title: string; + year: { + $numberInt: string; + }; + runtime: { + $numberInt: string; + }; + released: { + $date: { + $numberLong: string; + }; + }; + poster: string; + plot: string; + fullplot: string; + lastupdated: string; + type: string; + directors: Array; + imdb: { + rating: { + $numberDouble: string; + }; + votes: { + $numberInt: string; + }; + id: { + $numberInt: string; + }; + }; + cast: Array; + countries: Array; + genres: Array; + tomatoes: { + viewer: { + rating: { + $numberDouble: string; + }; + numReviews: { + $numberInt: string; + }; + }; + lastUpdated: { + $date: { + $numberLong: string; + }; + }; + }; + num_mflix_comments: { + $numberInt: string; + }; + }; + + const aggregation: schema.Pipeline = [ + { + $searchMeta: { + facet: { + operator: { + range: { + path: 'released', + gte: new Date('2000-01-01T00:00:00.000Z'), + lte: new Date('2015-01-31T00:00:00.000Z'), + }, + }, + facets: { + yearFacet: { + type: 'date', + path: 'released', + boundaries: [ + new Date('2000-01-01T00:00:00.000Z'), + new Date('2005-01-01T00:00:00.000Z'), + new Date('2010-01-01T00:00:00.000Z'), + new Date('2015-01-01T00:00:00.000Z'), + ], + default: 'other', + }, + }, + }, + }, + }, + ]; } /** @@ -33,7 +251,89 @@ function test2() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/facet/#examples} */ function test3() { - // TODO: no schema found for searchMeta.Metadata Results + type movies = { + _id: { + $oid: string; + }; + title: string; + year: { + $numberInt: string; + }; + runtime: { + $numberInt: string; + }; + released: { + $date: { + $numberLong: string; + }; + }; + poster: string; + plot: string; + fullplot: string; + lastupdated: string; + type: string; + directors: Array; + imdb: { + rating: { + $numberDouble: string; + }; + votes: { + $numberInt: string; + }; + id: { + $numberInt: string; + }; + }; + cast: Array; + countries: Array; + genres: Array; + tomatoes: { + viewer: { + rating: { + $numberDouble: string; + }; + numReviews: { + $numberInt: string; + }; + }; + lastUpdated: { + $date: { + $numberLong: string; + }; + }; + }; + num_mflix_comments: { + $numberInt: string; + }; + }; + + const aggregation: schema.Pipeline = [ + { + $searchMeta: { + facet: { + operator: { + range: { + path: 'released', + gte: new Date('2000-01-01T00:00:00.000Z'), + lte: new Date('2015-01-31T00:00:00.000Z'), + }, + }, + facets: { + directorsFacet: { + type: 'string', + path: 'directors', + numBuckets: 7, + }, + yearFacet: { + type: 'number', + path: 'year', + boundaries: [2000, 2005, 2010, 2015], + }, + }, + }, + }, + }, + ]; } /** @@ -41,5 +341,70 @@ function test3() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/#bucket-results-through-facet-queries} */ function test4() { - // TODO: no schema found for searchMeta.Autocomplete Bucket Results through Facet Queries + type movies = { + _id: { + $oid: string; + }; + title: string; + year: { + $numberInt: string; + }; + runtime: { + $numberInt: string; + }; + released: { + $date: { + $numberLong: string; + }; + }; + poster: string; + plot: string; + fullplot: string; + lastupdated: string; + type: string; + directors: Array; + imdb: { + rating: { + $numberDouble: string; + }; + votes: { + $numberInt: string; + }; + id: { + $numberInt: string; + }; + }; + cast: Array; + countries: Array; + genres: Array; + tomatoes: { + viewer: { + rating: { + $numberDouble: string; + }; + numReviews: { + $numberInt: string; + }; + }; + lastUpdated: { + $date: { + $numberLong: string; + }; + }; + }; + num_mflix_comments: { + $numberInt: string; + }; + }; + + const aggregation: schema.Pipeline = [ + { + $searchMeta: { + facet: { + operator: { autocomplete: { path: 'title', query: 'Gravity' } }, + facets: { titleFacet: { type: 'string', path: 'title' } }, + }, + }, + }, + ]; } diff --git a/packages/mql-typescript/tests/stage/set.spec.ts b/packages/mql-typescript/tests/stage/set.spec.ts index bf0f0564..a45b9c34 100644 --- a/packages/mql-typescript/tests/stage/set.spec.ts +++ b/packages/mql-typescript/tests/stage/set.spec.ts @@ -9,7 +9,31 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/set/#using-two--set-stages} */ function test0() { - // TODO: no schema found for set.Using Two $set Stages + type scores = { + _id: number; + student: string; + homework: Array; + quiz: Array; + extraCredit: number; + }; + + const aggregation: schema.Pipeline = [ + { + $set: { + totalHomework: { $sum: ['$homework'] }, + totalQuiz: { $sum: ['$quiz'] }, + }, + }, + + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (second $set stage references fields created in the first). + */ + { + $set: { + totalScore: { $add: ['$totalHomework', '$totalQuiz', '$extraCredit'] }, + }, + } as any, + ]; } /** @@ -17,7 +41,18 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/set/#adding-fields-to-an-embedded-document} */ function test1() { - // TODO: no schema found for set.Adding Fields to an Embedded Document + type vehicles = { + _id: number; + type: string; + specs: { + doors: number; + wheels: number; + }; + }; + + const aggregation: schema.Pipeline = [ + { $set: { 'specs.fuel_type': 'unleaded' } }, + ]; } /** @@ -25,7 +60,13 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/set/#overwriting-an-existing-field} */ function test2() { - // TODO: no schema found for set.Overwriting an existing field + type animals = { + _id: number; + dogs: number; + cats: number; + }; + + const aggregation: schema.Pipeline = [{ $set: { cats: 20 } }]; } /** @@ -33,7 +74,18 @@ function test2() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/set/#add-element-to-an-array} */ function test3() { - // TODO: no schema found for set.Add Element to an Array + type scores = { + _id: number; + student: string; + homework: Array; + quiz: Array; + extraCredit: number; + }; + + const aggregation: schema.Pipeline = [ + { $match: { _id: 1 } }, + { $set: { homework: { $concatArrays: ['$homework', [7]] } } }, + ]; } /** @@ -41,5 +93,15 @@ function test3() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/set/#creating-a-new-field-with-existing-fields} */ function test4() { - // TODO: no schema found for set.Creating a New Field with Existing Fields + type scores = { + _id: number; + student: string; + homework: Array; + quiz: Array; + extraCredit: number; + }; + + const aggregation: schema.Pipeline = [ + { $set: { quizAverage: { $avg: ['$quiz'] } } }, + ]; } diff --git a/packages/mql-typescript/tests/stage/setWindowFields.spec.ts b/packages/mql-typescript/tests/stage/setWindowFields.spec.ts index 4ebfae73..13584fc6 100644 --- a/packages/mql-typescript/tests/stage/setWindowFields.spec.ts +++ b/packages/mql-typescript/tests/stage/setWindowFields.spec.ts @@ -9,7 +9,29 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/setWindowFields/#use-documents-window-to-obtain-cumulative-quantity-for-each-state} */ function test0() { - // TODO: no schema found for setWindowFields.Use Documents Window to Obtain Cumulative Quantity for Each State + type cakeSales = { + _id: number; + type: string; + orderDate: Date; + state: string; + price: number; + quantity: number; + }; + + const aggregation: schema.Pipeline = [ + { + $setWindowFields: { + partitionBy: '$state', + sortBy: { orderDate: 1 }, + output: { + cumulativeQuantityForState: { + $sum: '$quantity', + window: { documents: ['unbounded', 'current'] }, + }, + }, + }, + }, + ]; } /** @@ -17,7 +39,29 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/setWindowFields/#use-documents-window-to-obtain-cumulative-quantity-for-each-year} */ function test1() { - // TODO: no schema found for setWindowFields.Use Documents Window to Obtain Cumulative Quantity for Each Year + type cakeSales = { + _id: number; + type: string; + orderDate: Date; + state: string; + price: number; + quantity: number; + }; + + const aggregation: schema.Pipeline = [ + { + $setWindowFields: { + partitionBy: { $year: { date: '$orderDate' } }, + sortBy: { orderDate: 1 }, + output: { + cumulativeQuantityForYear: { + $sum: '$quantity', + window: { documents: ['unbounded', 'current'] }, + }, + }, + }, + }, + ]; } /** @@ -25,7 +69,29 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/setWindowFields/#use-documents-window-to-obtain-moving-average-quantity-for-each-year} */ function test2() { - // TODO: no schema found for setWindowFields.Use Documents Window to Obtain Moving Average Quantity for Each Year + type cakeSales = { + _id: number; + type: string; + orderDate: Date; + state: string; + price: number; + quantity: number; + }; + + const aggregation: schema.Pipeline = [ + { + $setWindowFields: { + partitionBy: { $year: { date: '$orderDate' } }, + sortBy: { orderDate: 1 }, + output: { + averageQuantity: { + $avg: '$quantity', + window: { documents: [-1, 0] }, + }, + }, + }, + }, + ]; } /** @@ -33,7 +99,33 @@ function test2() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/setWindowFields/#use-documents-window-to-obtain-cumulative-and-maximum-quantity-for-each-year} */ function test3() { - // TODO: no schema found for setWindowFields.Use Documents Window to Obtain Cumulative and Maximum Quantity for Each Year + type cakeSales = { + _id: number; + type: string; + orderDate: Date; + state: string; + price: number; + quantity: number; + }; + + const aggregation: schema.Pipeline = [ + { + $setWindowFields: { + partitionBy: { $year: { date: '$orderDate' } }, + sortBy: { orderDate: 1 }, + output: { + cumulativeQuantityForYear: { + $sum: '$quantity', + window: { documents: ['unbounded', 'current'] }, + }, + maximumQuantityForYear: { + $max: '$quantity', + window: { documents: ['unbounded', 'unbounded'] }, + }, + }, + }, + }, + ]; } /** @@ -41,7 +133,29 @@ function test3() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/setWindowFields/#range-window-example} */ function test4() { - // TODO: no schema found for setWindowFields.Range Window Example + type cakeSales = { + _id: number; + type: string; + orderDate: Date; + state: string; + price: number; + quantity: number; + }; + + const aggregation: schema.Pipeline = [ + { + $setWindowFields: { + partitionBy: '$state', + sortBy: { price: 1 }, + output: { + quantityFromSimilarOrders: { + $sum: '$quantity', + window: { range: [-10, 10] }, + }, + }, + }, + }, + ]; } /** @@ -49,7 +163,29 @@ function test4() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/setWindowFields/#use-a-time-range-window-with-a-positive-upper-bound} */ function test5() { - // TODO: no schema found for setWindowFields.Use a Time Range Window with a Positive Upper Bound + type cakeSales = { + _id: number; + type: string; + orderDate: Date; + state: string; + price: number; + quantity: number; + }; + + const aggregation: schema.Pipeline = [ + { + $setWindowFields: { + partitionBy: '$state', + sortBy: { orderDate: 1 }, + output: { + recentOrders: { + $push: '$orderDate', + window: { range: ['unbounded', 10], unit: 'month' }, + }, + }, + }, + }, + ]; } /** @@ -57,5 +193,27 @@ function test5() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/setWindowFields/#use-a-time-range-window-with-a-negative-upper-bound} */ function test6() { - // TODO: no schema found for setWindowFields.Use a Time Range Window with a Negative Upper Bound + type cakeSales = { + _id: number; + type: string; + orderDate: Date; + state: string; + price: number; + quantity: number; + }; + + const aggregation: schema.Pipeline = [ + { + $setWindowFields: { + partitionBy: '$state', + sortBy: { orderDate: 1 }, + output: { + recentOrders: { + $push: '$orderDate', + window: { range: ['unbounded', -10], unit: 'month' }, + }, + }, + }, + }, + ]; } diff --git a/packages/mql-typescript/tests/stage/shardedDataDistribution.spec.ts b/packages/mql-typescript/tests/stage/shardedDataDistribution.spec.ts index 961d6f13..7f4d66ed 100644 --- a/packages/mql-typescript/tests/stage/shardedDataDistribution.spec.ts +++ b/packages/mql-typescript/tests/stage/shardedDataDistribution.spec.ts @@ -9,5 +9,11 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/shardedDataDistribution/#examples} */ function test0() { - // TODO: no schema found for shardedDataDistribution.Example + type TestCollection = { + _id: bson.ObjectId; + }; + + const aggregation: schema.Pipeline = [ + { $shardedDataDistribution: {} }, + ]; } diff --git a/packages/mql-typescript/tests/stage/skip.spec.ts b/packages/mql-typescript/tests/stage/skip.spec.ts index 939efc50..fd3291eb 100644 --- a/packages/mql-typescript/tests/stage/skip.spec.ts +++ b/packages/mql-typescript/tests/stage/skip.spec.ts @@ -9,5 +9,9 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/skip/#example} */ function test0() { - // TODO: no schema found for skip.Example + type TestCollection = { + _id: bson.ObjectId; + }; + + const aggregation: schema.Pipeline = [{ $skip: 5 }]; } diff --git a/packages/mql-typescript/tests/stage/sort.spec.ts b/packages/mql-typescript/tests/stage/sort.spec.ts index 6ca78ac9..0744771d 100644 --- a/packages/mql-typescript/tests/stage/sort.spec.ts +++ b/packages/mql-typescript/tests/stage/sort.spec.ts @@ -9,7 +9,15 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/sort/#ascending-descending-sort} */ function test0() { - // TODO: no schema found for sort.Ascending Descending Sort + type users = { + age: bson.Int32 | number; + posts: bson.Int32 | number; + name: string; + }; + + const aggregation: schema.Pipeline = [ + { $sort: { age: -1, posts: 1 } }, + ]; } /** @@ -17,5 +25,14 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/sort/#text-score-metadata-sort} */ function test1() { - // TODO: no schema found for sort.Text Score Metadata Sort + type users = { + age: bson.Int32 | number; + posts: bson.Int32 | number; + name: string; + }; + + const aggregation: schema.Pipeline = [ + { $match: { $text: { $search: 'operating' } } }, + { $sort: { score: { $meta: 'textScore' }, posts: -1 } }, + ]; } diff --git a/packages/mql-typescript/tests/stage/sortByCount.spec.ts b/packages/mql-typescript/tests/stage/sortByCount.spec.ts index 612c91e3..564d227e 100644 --- a/packages/mql-typescript/tests/stage/sortByCount.spec.ts +++ b/packages/mql-typescript/tests/stage/sortByCount.spec.ts @@ -9,5 +9,5 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/sortByCount/#example} */ function test0() { - // TODO: no schema found for sortByCount.Example + // TODO: no schema found for sortByCount.Example: // TODO: No schema found in docs } diff --git a/packages/mql-typescript/tests/stage/unionWith.spec.ts b/packages/mql-typescript/tests/stage/unionWith.spec.ts index 204b7551..1a661717 100644 --- a/packages/mql-typescript/tests/stage/unionWith.spec.ts +++ b/packages/mql-typescript/tests/stage/unionWith.spec.ts @@ -9,7 +9,25 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/unionWith/#report-1--all-sales-by-year-and-stores-and-items} */ function test0() { - // TODO: no schema found for unionWith.Report 1 All Sales by Year and Stores and Items + type sales_2017 = { + store: string; + item: string; + quantity: number; + }; + + const aggregation: schema.Pipeline = [ + { $set: { _id: '2017' } }, + { + $unionWith: { coll: 'sales_2018', pipeline: [{ $set: { _id: '2018' } }] }, + }, + { + $unionWith: { coll: 'sales_2019', pipeline: [{ $set: { _id: '2019' } }] }, + }, + { + $unionWith: { coll: 'sales_2020', pipeline: [{ $set: { _id: '2020' } }] }, + }, + { $sort: { _id: 1, store: 1, item: 1 } }, + ]; } /** @@ -17,5 +35,17 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/unionWith/#report-2--aggregated-sales-by-items} */ function test1() { - // TODO: no schema found for unionWith.Report 2 Aggregated Sales by Items + type sales_2017 = { + store: string; + item: string; + quantity: number; + }; + + const aggregation: schema.Pipeline = [ + { $unionWith: { coll: 'sales_2018' } }, + { $unionWith: { coll: 'sales_2019' } }, + { $unionWith: { coll: 'sales_2020' } }, + { $group: { _id: '$item', total: { $sum: '$quantity' } } }, + { $sort: { total: -1 } }, + ]; } diff --git a/packages/mql-typescript/tests/stage/unset.spec.ts b/packages/mql-typescript/tests/stage/unset.spec.ts index cec47ee8..2ef5b245 100644 --- a/packages/mql-typescript/tests/stage/unset.spec.ts +++ b/packages/mql-typescript/tests/stage/unset.spec.ts @@ -9,7 +9,21 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/unset/#remove-a-single-field} */ function test0() { - // TODO: no schema found for unset.Remove a Single Field + type books = { + _id: number; + title: string; + isbn: string; + author: { + last: string; + first: string; + }; + copies: Array<{ + warehouse: string; + qty: number; + }>; + }; + + const aggregation: schema.Pipeline = [{ $unset: ['copies'] }]; } /** @@ -17,7 +31,21 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/unset/#remove-top-level-fields} */ function test1() { - // TODO: no schema found for unset.Remove Top-Level Fields + type books = { + _id: number; + title: string; + isbn: string; + author: { + last: string; + first: string; + }; + copies: Array<{ + warehouse: string; + qty: number; + }>; + }; + + const aggregation: schema.Pipeline = [{ $unset: ['isbn', 'copies'] }]; } /** @@ -25,5 +53,24 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/unset/#remove-embedded-fields} */ function test2() { - // TODO: no schema found for unset.Remove Embedded Fields + type books = { + _id: number; + title: string; + isbn: string; + author: { + last: string; + first: string; + }; + copies: Array<{ + warehouse: string; + qty: number; + }>; + }; + + const aggregation: schema.Pipeline = [ + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). + */ + { $unset: ['isbn', 'author.first', 'copies.warehouse'] } as any, + ]; } diff --git a/packages/mql-typescript/tests/stage/unwind.spec.ts b/packages/mql-typescript/tests/stage/unwind.spec.ts index 9381ad21..b9781c68 100644 --- a/packages/mql-typescript/tests/stage/unwind.spec.ts +++ b/packages/mql-typescript/tests/stage/unwind.spec.ts @@ -9,7 +9,15 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/unwind/#unwind-array} */ function test0() { - // TODO: no schema found for unwind.Unwind Array + type inventory = { + _id: number; + item: string; + sizes: Array; + }; + + const aggregation: schema.Pipeline = [ + { $unwind: { path: '$sizes' } }, + ]; } /** @@ -17,7 +25,15 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/unwind/#preservenullandemptyarrays} */ function test1() { - // TODO: no schema found for unwind.preserveNullAndEmptyArrays + type inventory = { + _id: number; + item: string; + sizes: Array; + }; + + const aggregation: schema.Pipeline = [ + { $unwind: { path: '$sizes', preserveNullAndEmptyArrays: true } }, + ]; } /** @@ -25,7 +41,15 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/unwind/#includearrayindex} */ function test2() { - // TODO: no schema found for unwind.includeArrayIndex + type inventory = { + _id: number; + item: string; + sizes: Array; + }; + + const aggregation: schema.Pipeline = [ + { $unwind: { path: '$sizes', includeArrayIndex: 'arrayIndex' } }, + ]; } /** @@ -33,7 +57,18 @@ function test2() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/unwind/#group-by-unwound-values} */ function test3() { - // TODO: no schema found for unwind.Group by Unwound Values + type inventory2 = { + _id: number; + item: string; + price: bson.Decimal128; + sizes: Array | string | null; + }; + + const aggregation: schema.Pipeline = [ + { $unwind: { path: '$sizes', preserveNullAndEmptyArrays: true } }, + { $group: { _id: '$sizes', averagePrice: { $avg: '$price' } } }, + { $sort: { averagePrice: -1 } }, + ]; } /** @@ -41,5 +76,34 @@ function test3() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/unwind/#unwind-embedded-arrays} */ function test4() { - // TODO: no schema found for unwind.Unwind Embedded Arrays + type sales = { + _id: string; + items: Array<{ + name: string; + tags: Array; + price: bson.Decimal128; + quantity: bson.Int32 | number; + }>; + }; + + const aggregation: schema.Pipeline = [ + { $unwind: { path: '$items' } }, + + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). + */ + { $unwind: { path: '$items.tags' } } as any, + + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). + */ + { + $group: { + _id: '$items.tags', + totalSalesAmount: { + $sum: { $multiply: ['$items.price', '$items.quantity'] }, + }, + }, + } as any, + ]; } diff --git a/packages/mql-typescript/tests/stage/vectorSearch.spec.ts b/packages/mql-typescript/tests/stage/vectorSearch.spec.ts index c3119a7d..0ffb3f50 100644 --- a/packages/mql-typescript/tests/stage/vectorSearch.spec.ts +++ b/packages/mql-typescript/tests/stage/vectorSearch.spec.ts @@ -9,31 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-stage/#examples} */ function test0() { - type movies = { - plot_embedding: Array; - plot: string; - title: string; - }; - - const aggregation: schema.Pipeline = [ - { - $vectorSearch: { - index: 'vector_index', - path: 'plot_embedding', - queryVector: [-0.0016261312, -0.028070757, -0.011342932], - numCandidates: 150, - limit: 10, - }, - }, - { - $project: { - _id: 0, - plot: 1, - title: 1, - score: { $meta: 'vectorSearchScore' }, - }, - }, - ]; + // TODO: no schema found for vectorSearch.ANN Basic: // TODO: No schema found in docs } /** @@ -42,10 +18,59 @@ function test0() { */ function test1() { type movies = { - plot_embedding: Array; - year: bson.Int32 | number; - plot: string; + _id: { + $oid: string; + }; title: string; + year: { + $numberInt: string; + }; + runtime: { + $numberInt: string; + }; + released: { + $date: { + $numberLong: string; + }; + }; + poster: string; + plot: string; + fullplot: string; + lastupdated: string; + type: string; + directors: Array; + imdb: { + rating: { + $numberDouble: string; + }; + votes: { + $numberInt: string; + }; + id: { + $numberInt: string; + }; + }; + cast: Array; + countries: Array; + genres: Array; + tomatoes: { + viewer: { + rating: { + $numberDouble: string; + }; + numReviews: { + $numberInt: string; + }; + }; + lastUpdated: { + $date: { + $numberLong: string; + }; + }; + }; + num_mflix_comments: { + $numberInt: string; + }; }; const aggregation: schema.Pipeline = [ @@ -76,31 +101,7 @@ function test1() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-stage/#examples} */ function test2() { - type movies = { - plot_embedding: Array; - plot: string; - title: string; - }; - - const aggregation: schema.Pipeline = [ - { - $vectorSearch: { - index: 'vector_index', - path: 'plot_embedding', - queryVector: [-0.006954097, -0.009932499, -0.001311474], - exact: true, - limit: 10, - }, - }, - { - $project: { - _id: 0, - plot: 1, - title: 1, - score: { $meta: 'vectorSearchScore' }, - }, - }, - ]; + // TODO: no schema found for vectorSearch.ENN: // TODO: No schema found in docs } /** @@ -108,44 +109,7 @@ function test2() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-stage/#examples} */ function test3() { - type movies = { - plot_embedding: Array; - year: bson.Int32 | number; - genres: Array; - plot: string; - title: string; - }; - - const aggregation: schema.Pipeline = [ - { - $vectorSearch: { - index: 'vector_index', - path: 'plot_embedding', - queryVector: [ - -0.03994801267981529, -0.016522614285349846, -0.008775344118475914, - ], - filter: { - $and: [ - { year: { $gt: 1970 } }, - { year: { $lt: 2020 } }, - { genres: { $in: ['Action', 'Drama', 'Comedy'] } }, - ], - }, - limit: 10, - numCandidates: 1000, - returnStoredSource: true, - }, - }, - { - $project: { - _id: 0, - plot: 1, - title: 1, - genres: 1, - score: { $meta: 'vectorSearchScore' }, - }, - }, - ]; + // TODO: no schema found for vectorSearch.Stored Source: // TODO: No schema found in docs } /** @@ -153,5 +117,5 @@ function test3() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-stage/#examples} */ function test4() { - // TODO: no schema found for vectorSearch.Nested field + // TODO: no schema found for vectorSearch.Nested field: // TODO: No schema found in docs } From 2accdcc372db1250cc8c23d6a96f95d49305c036 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Tue, 30 Jun 2026 14:33:08 +0100 Subject: [PATCH 5/8] fixup: bring back minVersion tags --- packages/mql-typescript/out/schema.d.ts | 296 +++++++++++++++++ packages/mql-typescript/src/cli.ts | 29 +- .../src/driverSchema/static-schemas.ts | 27 ++ .../mql-typescript/src/schema-generator.ts | 10 +- .../tests/expression/concatArrays.spec.ts | 14 +- .../tests/expression/serializeEJSON.spec.ts | 300 ++++++++++++++---- .../tests/expression/setUnion.spec.ts | 14 +- 7 files changed, 586 insertions(+), 104 deletions(-) diff --git a/packages/mql-typescript/out/schema.d.ts b/packages/mql-typescript/out/schema.d.ts index 05f06578..1beedfb1 100644 --- a/packages/mql-typescript/out/schema.d.ts +++ b/packages/mql-typescript/out/schema.d.ts @@ -33,6 +33,7 @@ export namespace Aggregation.Accumulator { export interface $accumulator { /** * Defines a custom accumulator function. + * New in MongoDB 4.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/accumulator/} */ $accumulator: { @@ -81,6 +82,7 @@ export namespace Aggregation.Accumulator { /** * Returns an array of unique expression values for each group. Order of the array elements is undefined. * Changed in MongoDB 5.0: Available in the $setWindowFields stage. + * New in MongoDB 2.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/addToSet/} */ $addToSet: Expression; @@ -94,6 +96,7 @@ export namespace Aggregation.Accumulator { /** * Returns an average of numerical values. Ignores non-numeric values. * Changed in MongoDB 5.0: Available in the $setWindowFields stage. + * New in MongoDB 2.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/avg/} */ $avg: ResolvesToNumber; @@ -106,6 +109,7 @@ export namespace Aggregation.Accumulator { export interface $bottom { /** * Returns the bottom element within a group according to the specified sort order. + * New in MongoDB 5.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/bottom/} */ $bottom: { @@ -129,6 +133,7 @@ export namespace Aggregation.Accumulator { /** * Returns an aggregation of the bottom n elements within a group, according to the specified sort order. If the group contains fewer than n elements, $bottomN returns all elements in the group. * Available in the $group and $setWindowFields stages. + * New in MongoDB 5.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/bottomN/} */ $bottomN: { @@ -156,6 +161,7 @@ export namespace Aggregation.Accumulator { export interface $concatArrays { /** * Concatenates arrays to return the concatenated array. + * New in MongoDB 4.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/concatArrays/} */ $concatArrays: [ @@ -175,6 +181,7 @@ export namespace Aggregation.Accumulator { /** * Returns the number of documents in the group or window. * Distinct from the $count pipeline stage. + * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/count-accumulator/} */ $count: Record; @@ -187,6 +194,7 @@ export namespace Aggregation.Accumulator { export interface $covariancePop { /** * Returns the population covariance of two numeric expressions. + * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/covariancePop/} */ $covariancePop: [ @@ -202,6 +210,7 @@ export namespace Aggregation.Accumulator { export interface $covarianceSamp { /** * Returns the sample covariance of two numeric expressions. + * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/covarianceSamp/} */ $covarianceSamp: [ @@ -217,6 +226,7 @@ export namespace Aggregation.Accumulator { export interface $denseRank { /** * Returns the document position (known as the rank) relative to other documents in the $setWindowFields stage partition. There are no gaps in the ranks. Ties receive the same rank. + * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/denseRank/} */ $denseRank: Record; @@ -229,6 +239,7 @@ export namespace Aggregation.Accumulator { export interface $derivative { /** * Returns the average rate of change within the specified window. + * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/derivative/} */ $derivative: { @@ -249,6 +260,7 @@ export namespace Aggregation.Accumulator { export interface $documentNumber { /** * Returns the position of a document (known as the document number) in the $setWindowFields stage partition. Ties result in different adjacent document numbers. + * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/documentNumber/} */ $documentNumber: Record; @@ -261,6 +273,7 @@ export namespace Aggregation.Accumulator { export interface $expMovingAvg { /** * Returns the exponential moving average for the numeric expression. + * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/expMovingAvg/} */ $expMovingAvg: { @@ -289,6 +302,7 @@ export namespace Aggregation.Accumulator { /** * Returns the result of an expression for the first document in a group or window. * Changed in MongoDB 5.0: Available in the $setWindowFields stage. + * New in MongoDB 2.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/first/} */ $first: Expression; @@ -303,6 +317,7 @@ export namespace Aggregation.Accumulator { * Returns an aggregation of the first n elements within a group. * The elements returned are meaningful only if in a specified sort order. * If the group contains fewer than n elements, $firstN returns all elements in the group. + * New in MongoDB 5.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/firstN/} */ $firstN: { @@ -325,6 +340,7 @@ export namespace Aggregation.Accumulator { export interface $integral { /** * Returns the approximation of the area under a curve. + * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/integral/} */ $integral: { @@ -346,6 +362,7 @@ export namespace Aggregation.Accumulator { /** * Returns the result of an expression for the last document in a group or window. * Changed in MongoDB 5.0: Available in the $setWindowFields stage. + * New in MongoDB 2.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/last/} */ $last: Expression; @@ -360,6 +377,7 @@ export namespace Aggregation.Accumulator { * Returns an aggregation of the last n elements within a group. * The elements returned are meaningful only if in a specified sort order. * If the group contains fewer than n elements, $lastN returns all elements in the group. + * New in MongoDB 5.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/lastN/} */ $lastN: { @@ -383,6 +401,7 @@ export namespace Aggregation.Accumulator { /** * Fills null and missing fields in a window using linear interpolation based on surrounding field values. * Available in the $setWindowFields stage. + * New in MongoDB 5.3. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/linearFill/} */ $linearFill: ResolvesToNumber; @@ -396,6 +415,7 @@ export namespace Aggregation.Accumulator { /** * Last observation carried forward. Sets values for null and missing fields in a window to the last non-null value for the field. * Available in the $setWindowFields stage. + * New in MongoDB 5.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/locf/} */ $locf: Expression; @@ -409,6 +429,7 @@ export namespace Aggregation.Accumulator { /** * Returns the maximum value that results from applying an expression to each document. * Changed in MongoDB 5.0: Available in the $setWindowFields stage. + * New in MongoDB 2.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/max/} */ $max: Expression; @@ -421,6 +442,7 @@ export namespace Aggregation.Accumulator { export interface $maxN { /** * Returns the n largest values in an array. Distinct from the $maxN accumulator. + * New in MongoDB 5.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/maxN/} */ $maxN: { @@ -447,6 +469,7 @@ export namespace Aggregation.Accumulator { * $group * $setWindowFields * It is also available as an aggregation expression. + * New in MongoDB 7.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/median/} */ $median: { @@ -469,6 +492,7 @@ export namespace Aggregation.Accumulator { export interface $mergeObjects { /** * Combines multiple documents into a single document. + * New in MongoDB 3.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/mergeObjects/} */ $mergeObjects: ResolvesToObject; @@ -482,6 +506,7 @@ export namespace Aggregation.Accumulator { /** * Returns the minimum value that results from applying an expression to each document. * Changed in MongoDB 5.0: Available in the $setWindowFields stage. + * New in MongoDB 2.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/min/} */ $min: Expression; @@ -498,6 +523,7 @@ export namespace Aggregation.Accumulator { * all other values scale proportionally in between. You can also specify a custom minimum * and maximum value for the normalized output range. * Available only in the $setWindowFields stage. + * New in MongoDB 8.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/minMaxScaler/} */ $minMaxScaler: { @@ -525,6 +551,7 @@ export namespace Aggregation.Accumulator { export interface $minN { /** * Returns the n smallest values in an array. Distinct from the $minN accumulator. + * New in MongoDB 5.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/minN/} */ $minN: { @@ -551,6 +578,7 @@ export namespace Aggregation.Accumulator { * $group * $setWindowFields * It is also available as an aggregation expression. + * New in MongoDB 7.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/percentile/} */ $percentile: { @@ -580,6 +608,7 @@ export namespace Aggregation.Accumulator { /** * Returns an array of values that result from applying an expression to each document. * Changed in MongoDB 5.0: Available in the $setWindowFields stage. + * New in MongoDB 2.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/push/} */ $push: Expression; @@ -592,6 +621,7 @@ export namespace Aggregation.Accumulator { export interface $rank { /** * Returns the document position (known as the rank) relative to other documents in the $setWindowFields stage partition. + * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/rank/} */ $rank: Record; @@ -604,6 +634,7 @@ export namespace Aggregation.Accumulator { export interface $setUnion { /** * Takes two or more arrays and returns an array containing the elements that appear in any input array. + * New in MongoDB 4.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/setUnion/} */ $setUnion: [ @@ -621,6 +652,7 @@ export namespace Aggregation.Accumulator { export interface $shift { /** * Returns the value from an expression applied to a document in a specified position relative to the current document in the $setWindowFields stage partition. + * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/shift/} */ $shift: { @@ -656,6 +688,7 @@ export namespace Aggregation.Accumulator { * Calculates the population standard deviation of the input values. Use if the values encompass the entire population of data you want to represent and do not wish to generalize about a larger population. $stdDevPop ignores non-numeric values. * If the values represent only a sample of a population of data from which to generalize about the population, use $stdDevSamp instead. * Changed in MongoDB 5.0: Available in the $setWindowFields stage. + * New in MongoDB 3.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/stdDevPop/} */ $stdDevPop: ResolvesToNumber; @@ -670,6 +703,7 @@ export namespace Aggregation.Accumulator { * Calculates the sample standard deviation of the input values. Use if the values encompass a sample of a population of data from which to generalize about the population. $stdDevSamp ignores non-numeric values. * If the values represent the entire population of data or you do not wish to generalize about a larger population, use $stdDevPop instead. * Changed in MongoDB 5.0: Available in the $setWindowFields stage. + * New in MongoDB 3.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/stdDevSamp/} */ $stdDevSamp: ResolvesToNumber; @@ -683,6 +717,7 @@ export namespace Aggregation.Accumulator { /** * Returns a sum of numerical values. Ignores non-numeric values. * Changed in MongoDB 5.0: Available in the $setWindowFields stage. + * New in MongoDB 2.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/sum/} */ $sum: ResolvesToNumber; @@ -696,6 +731,7 @@ export namespace Aggregation.Accumulator { /** * Returns the top element within a group according to the specified sort order. * Available in the $group and $setWindowFields stages. + * New in MongoDB 5.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/top/} */ $top: { @@ -719,6 +755,7 @@ export namespace Aggregation.Accumulator { /** * Returns an aggregation of the top n fields within a group, according to the specified sort order. * Available in the $group and $setWindowFields stages. + * New in MongoDB 5.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/topN/} */ $topN: { @@ -747,6 +784,7 @@ export namespace Aggregation.Expression { export interface $abs { /** * Returns the absolute value of a number. + * New in MongoDB 3.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/abs/} */ $abs: ResolvesToNumber; @@ -759,6 +797,7 @@ export namespace Aggregation.Expression { export interface $acos { /** * Returns the inverse cosine (arc cosine) of a value in radians. + * New in MongoDB 4.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/acos/} */ $acos: ResolvesToNumber; @@ -771,6 +810,7 @@ export namespace Aggregation.Expression { export interface $acosh { /** * Returns the inverse hyperbolic cosine (hyperbolic arc cosine) of a value in radians. + * New in MongoDB 4.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/acosh/} */ $acosh: ResolvesToNumber; @@ -783,6 +823,7 @@ export namespace Aggregation.Expression { export interface $add { /** * Adds numbers to return the sum, or adds numbers and a date to return a new date. If adding numbers and a date, treats the numbers as milliseconds. Accepts any number of argument expressions, but at most, one expression can resolve to a date. + * New in MongoDB 2.6. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/add/} */ $add: [ @@ -800,6 +841,7 @@ export namespace Aggregation.Expression { export interface $allElementsTrue { /** * Returns true if no element of a set evaluates to false, otherwise, returns false. Accepts a single argument expression. + * New in MongoDB 3.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/allElementsTrue/} */ $allElementsTrue: [expression: ResolvesToArray]; @@ -812,6 +854,7 @@ export namespace Aggregation.Expression { export interface $and { /** * Returns true only when all its expressions evaluate to true. Accepts any number of argument expressions. + * New in MongoDB 2.6. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/and/} */ $and: [ @@ -832,6 +875,7 @@ export namespace Aggregation.Expression { export interface $anyElementTrue { /** * Returns true if any elements of a set evaluate to true; otherwise, returns false. Accepts a single argument expression. + * New in MongoDB 3.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/anyElementTrue/} */ $anyElementTrue: [expression: ResolvesToArray]; @@ -844,6 +888,7 @@ export namespace Aggregation.Expression { export interface $arrayElemAt { /** * Returns the element at the specified array index. + * New in MongoDB 3.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/arrayElemAt/} */ $arrayElemAt: [array: ResolvesToArray, idx: ResolvesToInt]; @@ -856,6 +901,7 @@ export namespace Aggregation.Expression { export interface $arrayToObject { /** * Converts an array of key value pairs to a document. + * New in MongoDB 3.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/arrayToObject/} */ $arrayToObject: [array: ResolvesToArray]; @@ -868,6 +914,7 @@ export namespace Aggregation.Expression { export interface $asin { /** * Returns the inverse sin (arc sine) of a value in radians. + * New in MongoDB 4.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/asin/} */ $asin: ResolvesToNumber; @@ -880,6 +927,7 @@ export namespace Aggregation.Expression { export interface $asinh { /** * Returns the inverse hyperbolic sine (hyperbolic arc sine) of a value in radians. + * New in MongoDB 4.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/asinh/} */ $asinh: ResolvesToNumber; @@ -892,6 +940,7 @@ export namespace Aggregation.Expression { export interface $atan { /** * Returns the inverse tangent (arc tangent) of a value in radians. + * New in MongoDB 4.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/atan/} */ $atan: ResolvesToNumber; @@ -904,6 +953,7 @@ export namespace Aggregation.Expression { export interface $atan2 { /** * Returns the inverse tangent (arc tangent) of y / x in radians, where y and x are the first and second values passed to the expression respectively. + * New in MongoDB 4.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/atan2/} */ $atan2: [ @@ -924,6 +974,7 @@ export namespace Aggregation.Expression { export interface $atanh { /** * Returns the inverse hyperbolic tangent (hyperbolic arc tangent) of a value in radians. + * New in MongoDB 4.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/atanh/} */ $atanh: ResolvesToNumber; @@ -937,6 +988,7 @@ export namespace Aggregation.Expression { /** * Returns an average of numerical values. Ignores non-numeric values. * Changed in MongoDB 5.0: Available in the $setWindowFields stage. + * New in MongoDB 3.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/avg/} */ $avg: [...ResolvesToNumber[]]; @@ -949,6 +1001,7 @@ export namespace Aggregation.Expression { export interface $binarySize { /** * Returns the size of a given string or binary data value's content in bytes. + * New in MongoDB 4.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/binarySize/} */ $binarySize: ResolvesToString | ResolvesToBinData | ResolvesToNull; @@ -961,6 +1014,7 @@ export namespace Aggregation.Expression { export interface $bitAnd { /** * Returns the result of a bitwise and operation on an array of int or long values. + * New in MongoDB 6.3. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitAnd/} */ $bitAnd: [...(ResolvesToInt | ResolvesToLong)[]]; @@ -973,6 +1027,7 @@ export namespace Aggregation.Expression { export interface $bitNot { /** * Returns the result of a bitwise not operation on a single argument or an array that contains a single int or long value. + * New in MongoDB 6.3. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitNot/} */ $bitNot: ResolvesToInt | ResolvesToLong; @@ -985,6 +1040,7 @@ export namespace Aggregation.Expression { export interface $bitOr { /** * Returns the result of a bitwise or operation on an array of int or long values. + * New in MongoDB 6.3. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitOr/} */ $bitOr: [...(ResolvesToInt | ResolvesToLong)[]]; @@ -997,6 +1053,7 @@ export namespace Aggregation.Expression { export interface $bitXor { /** * Returns the result of a bitwise xor (exclusive or) operation on an array of int and long values. + * New in MongoDB 6.3. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitXor/} */ $bitXor: [...(ResolvesToInt | ResolvesToLong)[]]; @@ -1009,6 +1066,7 @@ export namespace Aggregation.Expression { export interface $bottom { /** * Returns the bottom element within an array according to the specified sort order. + * New in MongoDB 7.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/bottom-array-operator/} */ $bottom: { @@ -1037,6 +1095,7 @@ export namespace Aggregation.Expression { /** * Returns an aggregation of the bottom n elements within an array, according to the specified sort order. * If the array contains fewer than n elements, $bottomN returns all elements in the array. + * New in MongoDB 7.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/bottomN-array-operator/} */ $bottomN: { @@ -1069,6 +1128,7 @@ export namespace Aggregation.Expression { export interface $bsonSize { /** * Returns the size in bytes of a given document (i.e. BSON type Object) when encoded as BSON. + * New in MongoDB 4.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/bsonSize/} */ $bsonSize: ResolvesToObject | ResolvesToNull; @@ -1081,6 +1141,7 @@ export namespace Aggregation.Expression { export interface $case { /** * Represents a single case in a $switch expression + * New in MongoDB 3.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/switch/} */ $case: { @@ -1103,6 +1164,7 @@ export namespace Aggregation.Expression { export interface $ceil { /** * Returns the smallest integer greater than or equal to the specified number. + * New in MongoDB 3.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/ceil/} */ $ceil: ResolvesToNumber; @@ -1115,6 +1177,7 @@ export namespace Aggregation.Expression { export interface $cmp { /** * Returns 0 if the two values are equivalent, 1 if the first value is greater than the second, and -1 if the first value is less than the second. + * New in MongoDB 3.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/cmp/} */ $cmp: [expression1: Expression, expression2: Expression]; @@ -1127,6 +1190,7 @@ export namespace Aggregation.Expression { export interface $concat { /** * Concatenates any number of strings. + * New in MongoDB 3.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/concat/} */ $concat: [...ResolvesToString[]]; @@ -1139,6 +1203,7 @@ export namespace Aggregation.Expression { export interface $concatArrays { /** * Concatenates arrays to return the concatenated array. + * New in MongoDB 3.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/concatArrays/} */ $concatArrays: [...ResolvesToArray[]]; @@ -1151,6 +1216,7 @@ export namespace Aggregation.Expression { export interface $cond { /** * A ternary operator that evaluates one expression, and depending on the result, returns the value of one of the other two expressions. Accepts either three expressions in an ordered list or three named parameters. + * New in MongoDB 3.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/cond/} */ $cond: { if: ResolvesToBool; then: Expression; else: Expression }; @@ -1167,6 +1233,7 @@ export namespace Aggregation.Expression { * number in the given base and converts it to a decimal, or converts a numeric value to a * string representation in that base. Supported bases are 2 (binary), 8 (octal), 10 * (decimal), and 16 (hexadecimal). + * New in MongoDB 4.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/convert/} */ $convert: { @@ -1205,6 +1272,7 @@ export namespace Aggregation.Expression { export interface $cos { /** * Returns the cosine of a value that is measured in radians. + * New in MongoDB 4.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/cos/} */ $cos: ResolvesToNumber; @@ -1217,6 +1285,7 @@ export namespace Aggregation.Expression { export interface $cosh { /** * Returns the hyperbolic cosine of a value that is measured in radians. + * New in MongoDB 4.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/cosh/} */ $cosh: ResolvesToNumber; @@ -1229,6 +1298,7 @@ export namespace Aggregation.Expression { export interface $createObjectId { /** * Returns a random object ID + * New in MongoDB 4.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/createObjectId/} */ $createObjectId: Record; @@ -1241,6 +1311,7 @@ export namespace Aggregation.Expression { export interface $dateAdd { /** * Adds a number of time units to a date object. + * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateAdd/} */ $dateAdd: { @@ -1272,6 +1343,7 @@ export namespace Aggregation.Expression { export interface $dateDiff { /** * Returns the difference between two dates. + * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateDiff/} */ $dateDiff: { @@ -1315,6 +1387,7 @@ export namespace Aggregation.Expression { export interface $dateFromParts { /** * Constructs a BSON Date object given the date's constituent parts. + * New in MongoDB 3.6. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateFromParts/} */ $dateFromParts: { @@ -1382,6 +1455,7 @@ export namespace Aggregation.Expression { export interface $dateFromString { /** * Converts a date/time string to a date object. + * New in MongoDB 3.6. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateFromString/} */ $dateFromString: { @@ -1422,6 +1496,7 @@ export namespace Aggregation.Expression { export interface $dateSubtract { /** * Subtracts a number of time units from a date object. + * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateSubtract/} */ $dateSubtract: { @@ -1453,6 +1528,7 @@ export namespace Aggregation.Expression { export interface $dateToParts { /** * Returns a document containing the constituent parts of a date. + * New in MongoDB 3.6. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateToParts/} */ $dateToParts: { @@ -1480,6 +1556,7 @@ export namespace Aggregation.Expression { export interface $dateToString { /** * Returns the date as a formatted string. + * New in MongoDB 3.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateToString/} */ $dateToString: { @@ -1514,6 +1591,7 @@ export namespace Aggregation.Expression { export interface $dateTrunc { /** * Truncates a date. + * New in MongoDB 5.1. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateTrunc/} */ $dateTrunc: { @@ -1554,6 +1632,7 @@ export namespace Aggregation.Expression { export interface $dayOfMonth { /** * Returns the day of the month for a date as a number between 1 and 31. + * New in MongoDB 2.6. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/dayOfMonth/} */ $dayOfMonth: { @@ -1576,6 +1655,7 @@ export namespace Aggregation.Expression { export interface $dayOfWeek { /** * Returns the day of the week for a date as a number between 1 (Sunday) and 7 (Saturday). + * New in MongoDB 2.6. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/dayOfWeek/} */ $dayOfWeek: { @@ -1598,6 +1678,7 @@ export namespace Aggregation.Expression { export interface $dayOfYear { /** * Returns the day of the year for a date as a number between 1 and 366 (leap year). + * New in MongoDB 2.6. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/dayOfYear/} */ $dayOfYear: { @@ -1620,6 +1701,7 @@ export namespace Aggregation.Expression { export interface $degreesToRadians { /** * Converts a value from degrees to radians. + * New in MongoDB 4.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/degreesToRadians/} */ $degreesToRadians: ResolvesToNumber; @@ -1634,6 +1716,7 @@ export namespace Aggregation.Expression { * Converts Extended JSON (EJSON) format to native BSON values. Use this expression to * transform EJSON type wrappers into their corresponding BSON types after parsing a JSON * string with $convert. + * New in MongoDB 8.3. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/deserializeEJSON/} */ $deserializeEJSON: { @@ -1658,6 +1741,7 @@ export namespace Aggregation.Expression { export interface $divide { /** * Returns the result of dividing the first number by the second. Accepts two argument expressions. + * New in MongoDB 3.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/divide/} */ $divide: [ @@ -1676,6 +1760,7 @@ export namespace Aggregation.Expression { export interface $eq { /** * Returns true if the values are equivalent. + * New in MongoDB 2.6. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/eq/} */ $eq: [expression1: Expression, expression2: Expression]; @@ -1688,6 +1773,7 @@ export namespace Aggregation.Expression { export interface $exp { /** * Raises e to the specified exponent. + * New in MongoDB 4.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/exp/} */ $exp: ResolvesToNumber; @@ -1700,6 +1786,7 @@ export namespace Aggregation.Expression { export interface $filter { /** * Selects a subset of the array to return an array with only the elements that match the filter condition. + * New in MongoDB 3.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/filter/} */ $filter: { @@ -1730,6 +1817,7 @@ export namespace Aggregation.Expression { export interface $first { /** * Returns the result of an expression for the first document in an array. + * New in MongoDB 4.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/first/} */ $first: ResolvesToArray; @@ -1742,6 +1830,7 @@ export namespace Aggregation.Expression { export interface $firstN { /** * Returns a specified number of elements from the beginning of an array. + * New in MongoDB 5.1. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/firstN-array-element/} */ $firstN: { @@ -1764,6 +1853,7 @@ export namespace Aggregation.Expression { export interface $floor { /** * Returns the largest integer less than or equal to the specified number. + * New in MongoDB 3.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/floor/} */ $floor: ResolvesToNumber; @@ -1776,6 +1866,7 @@ export namespace Aggregation.Expression { export interface $function { /** * Defines a custom function. + * New in MongoDB 4.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/function/} */ $function: { @@ -1800,6 +1891,7 @@ export namespace Aggregation.Expression { export interface $getField { /** * Returns the value of a specified field from a document. You can use $getField to retrieve the value of fields with names that contain periods (.) or start with dollar signs ($). + * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/getField/} */ $getField: { @@ -1824,6 +1916,7 @@ export namespace Aggregation.Expression { export interface $gt { /** * Returns true if the first value is greater than the second. + * New in MongoDB 2.6. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/gt/} */ $gt: [expression1: Expression, expression2: Expression]; @@ -1836,6 +1929,7 @@ export namespace Aggregation.Expression { export interface $gte { /** * Returns true if the first value is greater than or equal to the second. + * New in MongoDB 2.6. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/gte/} */ $gte: [expression1: Expression, expression2: Expression]; @@ -1850,6 +1944,7 @@ export namespace Aggregation.Expression { * Generates and returns a binary hash value (BinData) from a UTF-8 string or binary data. Use $hash in an aggregation * pipeline to compute binary hashes for storage, verification, or comparison. To get a hexadecimal string instead of * binary data, use $hexHash. + * New in MongoDB 8.3. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/hash/} */ $hash: { @@ -1867,6 +1962,7 @@ export namespace Aggregation.Expression { * Generates and returns an uppercase hexadecimal string representation of a hash value from a UTF-8 string or binary * data. Use $hexHash in an aggregation pipeline to compute hex-encoded hashes for storage, verification, or comparison. * To get binary data instead of a hexadecimal string, use $hash. + * New in MongoDB 8.3. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/hexHash/} */ $hexHash: { @@ -1882,6 +1978,7 @@ export namespace Aggregation.Expression { export interface $hour { /** * Returns the hour for a date as a number between 0 and 23. + * New in MongoDB 2.6. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/hour/} */ $hour: { @@ -1904,6 +2001,7 @@ export namespace Aggregation.Expression { export interface $ifNull { /** * Returns either the non-null result of the first expression or the result of the second expression if the first expression results in a null result. Null result encompasses instances of undefined values or missing fields. Accepts two expressions as arguments. The result of the second expression can be null. + * New in MongoDB 3.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/ifNull/} */ $ifNull: [...Expression[]]; @@ -1916,6 +2014,7 @@ export namespace Aggregation.Expression { export interface $in { /** * Returns a boolean indicating whether a specified value is in an array. + * New in MongoDB 3.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/in/} */ $in: [ @@ -1938,6 +2037,7 @@ export namespace Aggregation.Expression { export interface $indexOfArray { /** * Searches an array for an occurrence of a specified value and returns the array index of the first occurrence. Array indexes start at zero. + * New in MongoDB 3.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/indexOfArray/} */ $indexOfArray: [ @@ -1970,6 +2070,7 @@ export namespace Aggregation.Expression { export interface $indexOfBytes { /** * Searches a string for an occurrence of a substring and returns the UTF-8 byte index of the first occurrence. If the substring is not found, returns -1. + * New in MongoDB 3.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/indexOfBytes/} */ $indexOfBytes: [ @@ -2006,6 +2107,7 @@ export namespace Aggregation.Expression { export interface $indexOfCP { /** * Searches a string for an occurrence of a substring and returns the UTF-8 code point index of the first occurrence. If the substring is not found, returns -1 + * New in MongoDB 3.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/indexOfCP/} */ $indexOfCP: [ @@ -2042,6 +2144,7 @@ export namespace Aggregation.Expression { export interface $isArray { /** * Determines if the operand is an array. Returns a boolean. + * New in MongoDB 4.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/isArray/} */ $isArray: [expression: Expression]; @@ -2055,6 +2158,7 @@ export namespace Aggregation.Expression { /** * Returns boolean true if the specified expression resolves to an integer, decimal, double, or long. * Returns boolean false if the expression resolves to any other BSON type, null, or a missing field. + * New in MongoDB 4.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/isNumber/} */ $isNumber: Expression; @@ -2067,6 +2171,7 @@ export namespace Aggregation.Expression { export interface $isoDayOfWeek { /** * Returns the weekday number in ISO 8601 format, ranging from 1 (for Monday) to 7 (for Sunday). + * New in MongoDB 3.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/isoDayOfWeek/} */ $isoDayOfWeek: { @@ -2089,6 +2194,7 @@ export namespace Aggregation.Expression { export interface $isoWeek { /** * Returns the week number in ISO 8601 format, ranging from 1 to 53. Week numbers start at 1 with the week (Monday through Sunday) that contains the year's first Thursday. + * New in MongoDB 3.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/isoWeek/} */ $isoWeek: { @@ -2111,6 +2217,7 @@ export namespace Aggregation.Expression { export interface $isoWeekYear { /** * Returns the year number in ISO 8601 format. The year starts with the Monday of week 1 (ISO 8601) and ends with the Sunday of the last week (ISO 8601). + * New in MongoDB 3.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/isoWeekYear/} */ $isoWeekYear: { @@ -2133,6 +2240,7 @@ export namespace Aggregation.Expression { export interface $last { /** * Returns the result of an expression for the last document in an array. + * New in MongoDB 4.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/last/} */ $last: ResolvesToArray; @@ -2145,6 +2253,7 @@ export namespace Aggregation.Expression { export interface $lastN { /** * Returns a specified number of elements from the end of an array. + * New in MongoDB 5.1. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/lastN/#array-operator} */ $lastN: { @@ -2168,6 +2277,7 @@ export namespace Aggregation.Expression { /** * Defines variables for use within the scope of a subexpression and returns the result of the subexpression. Accepts named parameters. * Accepts any number of argument expressions. + * New in MongoDB 3.6. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/let/} */ $let: { @@ -2191,6 +2301,7 @@ export namespace Aggregation.Expression { export interface $literal { /** * Return a value without parsing. Use for values that the aggregation pipeline may interpret as an expression. For example, use a $literal expression to a string that starts with a dollar sign ($) to avoid parsing as a field path. + * New in MongoDB 3.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/literal/} */ $literal: any; @@ -2204,6 +2315,7 @@ export namespace Aggregation.Expression { /** * Calculates the natural log of a number. * $ln is equivalent to $log: [ , Math.E ] expression, where Math.E is a JavaScript representation for Euler's number e. + * New in MongoDB 4.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/ln/} */ $ln: ResolvesToNumber; @@ -2216,6 +2328,7 @@ export namespace Aggregation.Expression { export interface $log { /** * Calculates the log of a number in the specified base. + * New in MongoDB 4.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/log/} */ $log: [ @@ -2238,6 +2351,7 @@ export namespace Aggregation.Expression { export interface $log10 { /** * Calculates the log base 10 of a number. + * New in MongoDB 4.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/log10/} */ $log10: ResolvesToNumber; @@ -2250,6 +2364,7 @@ export namespace Aggregation.Expression { export interface $lt { /** * Returns true if the first value is less than the second. + * New in MongoDB 2.6. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/lt/} */ $lt: [expression1: Expression, expression2: Expression]; @@ -2262,6 +2377,7 @@ export namespace Aggregation.Expression { export interface $lte { /** * Returns true if the first value is less than or equal to the second. + * New in MongoDB 2.6. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/lte/} */ $lte: [expression1: Expression, expression2: Expression]; @@ -2274,6 +2390,7 @@ export namespace Aggregation.Expression { export interface $ltrim { /** * Removes whitespace or the specified characters from the beginning of a string. + * New in MongoDB 4.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/ltrim/} */ $ltrim: { @@ -2298,6 +2415,7 @@ export namespace Aggregation.Expression { export interface $map { /** * Applies a subexpression to each element of an array and returns the array of resulting values in order. Accepts named parameters. + * New in MongoDB 3.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/map/} */ $map: { @@ -2332,6 +2450,7 @@ export namespace Aggregation.Expression { /** * Returns the maximum value that results from applying an expression to each document. * Changed in MongoDB 5.0: Available in the $setWindowFields stage. + * New in MongoDB 3.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/max/} */ $max: [...Expression[]]; @@ -2344,6 +2463,7 @@ export namespace Aggregation.Expression { export interface $maxN { /** * Returns the n largest values in an array. Distinct from the $maxN accumulator. + * New in MongoDB 5.1. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/maxN-array-element/} */ $maxN: { @@ -2370,6 +2490,7 @@ export namespace Aggregation.Expression { * $group * $setWindowFields * It is also available as an aggregation expression. + * New in MongoDB 7.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/median/} */ $median: { @@ -2392,6 +2513,7 @@ export namespace Aggregation.Expression { export interface $mergeObjects { /** * Combines multiple documents into a single document. + * New in MongoDB 3.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/mergeObjects/} */ $mergeObjects: [ @@ -2409,6 +2531,7 @@ export namespace Aggregation.Expression { export interface $meta { /** * Access available per-document metadata related to the aggregation operation. + * New in MongoDB 4.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/meta/} */ $meta: string; @@ -2421,6 +2544,7 @@ export namespace Aggregation.Expression { export interface $millisecond { /** * Returns the milliseconds of a date as a number between 0 and 999. + * New in MongoDB 2.6. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/millisecond/} */ $millisecond: { @@ -2444,6 +2568,7 @@ export namespace Aggregation.Expression { /** * Returns the minimum value that results from applying an expression to each document. * Changed in MongoDB 5.0: Available in the $setWindowFields stage. + * New in MongoDB 3.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/min/} */ $min: [...Expression[]]; @@ -2456,6 +2581,7 @@ export namespace Aggregation.Expression { export interface $minN { /** * Returns the n smallest values in an array. Distinct from the $minN accumulator. + * New in MongoDB 5.1. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/minN-array-element/} */ $minN: { @@ -2478,6 +2604,7 @@ export namespace Aggregation.Expression { export interface $minute { /** * Returns the minute for a date as a number between 0 and 59. + * New in MongoDB 2.6. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/minute/} */ $minute: { @@ -2500,6 +2627,7 @@ export namespace Aggregation.Expression { export interface $mod { /** * Returns the remainder of the first number divided by the second. Accepts two argument expressions. + * New in MongoDB 3.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/mod/} */ $mod: [ @@ -2518,6 +2646,7 @@ export namespace Aggregation.Expression { export interface $month { /** * Returns the month for a date as a number between 1 (January) and 12 (December). + * New in MongoDB 2.6. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/month/} */ $month: { @@ -2540,6 +2669,7 @@ export namespace Aggregation.Expression { export interface $multiply { /** * Multiplies numbers to return the product. Accepts any number of argument expressions. + * New in MongoDB 3.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/multiply/} */ $multiply: [ @@ -2558,6 +2688,7 @@ export namespace Aggregation.Expression { export interface $ne { /** * Returns true if the values are not equivalent. + * New in MongoDB 2.6. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/ne/} */ $ne: [expression1: Expression, expression2: Expression]; @@ -2570,6 +2701,7 @@ export namespace Aggregation.Expression { export interface $not { /** * Returns the boolean value that is the opposite of its argument expression. Accepts a single argument expression. + * New in MongoDB 2.6. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/not/} */ $not: [expression: Expression | ResolvesToBool]; @@ -2582,6 +2714,7 @@ export namespace Aggregation.Expression { export interface $objectToArray { /** * Converts a document to an array of documents representing key-value pairs. + * New in MongoDB 3.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/objectToArray/} */ $objectToArray: ResolvesToObject; @@ -2594,6 +2727,7 @@ export namespace Aggregation.Expression { export interface $or { /** * Returns true when any of its expressions evaluates to true. Accepts any number of argument expressions. + * New in MongoDB 2.6. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/or/} */ $or: [...(Expression | ResolvesToBool)[]]; @@ -2610,6 +2744,7 @@ export namespace Aggregation.Expression { * $group * $setWindowFields * It is also available as an aggregation expression. + * New in MongoDB 7.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/percentile/} */ $percentile: { @@ -2638,6 +2773,7 @@ export namespace Aggregation.Expression { export interface $pow { /** * Raises a number to the specified exponent. + * New in MongoDB 3.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/pow/} */ $pow: [number: ResolvesToNumber, exponent: ResolvesToNumber]; @@ -2650,6 +2786,7 @@ export namespace Aggregation.Expression { export interface $radiansToDegrees { /** * Converts a value from radians to degrees. + * New in MongoDB 4.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/radiansToDegrees/} */ $radiansToDegrees: ResolvesToNumber; @@ -2662,6 +2799,7 @@ export namespace Aggregation.Expression { export interface $rand { /** * Returns a random float between 0 and 1 + * New in MongoDB 4.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/rand/} */ $rand: Record; @@ -2674,6 +2812,7 @@ export namespace Aggregation.Expression { export interface $range { /** * Outputs an array containing a sequence of integers according to user-defined inputs. + * New in MongoDB 3.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/range/} */ $range: [ @@ -2701,6 +2840,7 @@ export namespace Aggregation.Expression { export interface $reduce { /** * Applies an expression to each element in an array and combines them into a single value. + * New in MongoDB 3.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/reduce/} */ $reduce: { @@ -2759,6 +2899,7 @@ export namespace Aggregation.Expression { export interface $regexFind { /** * Applies a regular expression (regex) to a string and returns information on the first matched substring. + * New in MongoDB 4.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/regexFind/} */ $regexFind: { @@ -2782,6 +2923,7 @@ export namespace Aggregation.Expression { export interface $regexFindAll { /** * Applies a regular expression (regex) to a string and returns information on the all matched substrings. + * New in MongoDB 4.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/regexFindAll/} */ $regexFindAll: { @@ -2805,6 +2947,7 @@ export namespace Aggregation.Expression { export interface $regexMatch { /** * Applies a regular expression (regex) to a string and returns a boolean that indicates if a match is found or not. + * New in MongoDB 4.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/regexMatch/} */ $regexMatch: { @@ -2829,6 +2972,7 @@ export namespace Aggregation.Expression { /** * Replaces all instances of a search string in an input string with a replacement string. * $replaceAll is both case-sensitive and diacritic-sensitive, and ignores any collation present on a collection. + * New in MongoDB 4.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceAll/} */ $replaceAll: { @@ -2856,6 +3000,7 @@ export namespace Aggregation.Expression { export interface $replaceOne { /** * Replaces the first instance of a matched string in a given input. + * New in MongoDB 4.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceOne/} */ $replaceOne: { @@ -2883,6 +3028,7 @@ export namespace Aggregation.Expression { export interface $reverseArray { /** * Returns an array with the elements in reverse order. + * New in MongoDB 3.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/reverseArray/} */ $reverseArray: ResolvesToArray; @@ -2895,6 +3041,7 @@ export namespace Aggregation.Expression { export interface $round { /** * Rounds a number to a whole integer or to a specified decimal place. + * New in MongoDB 3.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/round/} */ $round: [ @@ -2918,6 +3065,7 @@ export namespace Aggregation.Expression { export interface $rtrim { /** * Removes whitespace characters, including null, or the specified characters from the end of a string. + * New in MongoDB 4.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/rtrim/} */ $rtrim: { @@ -2942,6 +3090,7 @@ export namespace Aggregation.Expression { export interface $second { /** * Returns the seconds for a date as a number between 0 and 60 (leap seconds). + * New in MongoDB 2.6. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/second/} */ $second: { @@ -2966,6 +3115,7 @@ export namespace Aggregation.Expression { * Converts BSON values to Extended JSON (EJSON) format. The result is a * BSON document with EJSON type wrappers that can then be converted to * a JSON string using $toString. + * New in MongoDB 8.3. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/serializeEJSON/} */ $serializeEJSON: { @@ -2997,6 +3147,7 @@ export namespace Aggregation.Expression { export interface $setDifference { /** * Returns a set with elements that appear in the first set but not in the second set; i.e. performs a relative complement of the second set relative to the first. Accepts exactly two argument expressions. + * New in MongoDB 3.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/setDifference/} */ $setDifference: [ @@ -3019,6 +3170,7 @@ export namespace Aggregation.Expression { export interface $setEquals { /** * Returns true if the input sets have the same distinct elements. Accepts two or more argument expressions. + * New in MongoDB 3.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/setEquals/} */ $setEquals: [...ResolvesToArray[]]; @@ -3031,6 +3183,7 @@ export namespace Aggregation.Expression { export interface $setField { /** * Adds, updates, or removes a specified field in a document. You can use $setField to add, update, or remove fields with names that contain periods (.) or start with dollar signs ($). + * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/setField/} */ $setField: { @@ -3059,6 +3212,7 @@ export namespace Aggregation.Expression { export interface $setIntersection { /** * Returns a set with elements that appear in all of the input sets. Accepts any number of argument expressions. + * New in MongoDB 3.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/setIntersection/} */ $setIntersection: [...ResolvesToArray[]]; @@ -3071,6 +3225,7 @@ export namespace Aggregation.Expression { export interface $setIsSubset { /** * Returns true if all elements of the first set appear in the second set, including when the first set equals the second set; i.e. not a strict subset. Accepts exactly two argument expressions. + * New in MongoDB 3.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/setIsSubset/} */ $setIsSubset: [ @@ -3086,6 +3241,7 @@ export namespace Aggregation.Expression { export interface $setUnion { /** * Returns a set with elements that appear in any of the input sets. + * New in MongoDB 3.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/setUnion/} */ $setUnion: [...ResolvesToArray[]]; @@ -3098,6 +3254,7 @@ export namespace Aggregation.Expression { export interface $sigmoid { /** * Returns the sigmoid of a value, defined as 1 / (1 + e^(-x)). The result is a value between 0 and 1. + * New in MongoDB 8.1. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/sigmoid/} */ $sigmoid: ResolvesToNumber; @@ -3111,6 +3268,7 @@ export namespace Aggregation.Expression { /** * Returns the cosine similarity between two vectors. If the score argument is true, the result * is normalized to a value between 0 and 1 for use as a vector search score. + * New in MongoDB 8.3. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/similarityCosine/} */ $similarityCosine: { @@ -3135,6 +3293,7 @@ export namespace Aggregation.Expression { /** * Returns the dot product similarity between two vectors. If the score argument is true, the result * is normalized to a value between 0 and 1 for use as a vector search score. + * New in MongoDB 8.3. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/similarityDotProduct/} */ $similarityDotProduct: { @@ -3159,6 +3318,7 @@ export namespace Aggregation.Expression { /** * Returns the Euclidean similarity between two vectors. If the score argument is true, the result * is normalized to a value between 0 and 1 for use as a vector search score. + * New in MongoDB 8.3. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/similarityEuclidean/} */ $similarityEuclidean: { @@ -3182,6 +3342,7 @@ export namespace Aggregation.Expression { export interface $sin { /** * Returns the sine of a value that is measured in radians. + * New in MongoDB 4.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/sin/} */ $sin: ResolvesToNumber; @@ -3194,6 +3355,7 @@ export namespace Aggregation.Expression { export interface $sinh { /** * Returns the hyperbolic sine of a value that is measured in radians. + * New in MongoDB 4.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/sinh/} */ $sinh: ResolvesToNumber; @@ -3206,6 +3368,7 @@ export namespace Aggregation.Expression { export interface $size { /** * Returns the number of elements in the array. Accepts a single expression as argument. + * New in MongoDB 3.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/size/} */ $size: ResolvesToArray; @@ -3218,6 +3381,7 @@ export namespace Aggregation.Expression { export interface $slice { /** * Returns a subset of an array. + * New in MongoDB 3.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/slice/} */ $slice: @@ -3263,6 +3427,7 @@ export namespace Aggregation.Expression { export interface $sortArray { /** * Sorts the elements of an array. + * New in MongoDB 5.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/sortArray/} */ $sortArray: { @@ -3287,6 +3452,7 @@ export namespace Aggregation.Expression { export interface $split { /** * Splits a string into substrings based on a delimiter. Returns an array of substrings. If the delimiter is not found within the string, returns an array containing the original string. + * New in MongoDB 3.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/split/} */ $split: [ @@ -3309,6 +3475,7 @@ export namespace Aggregation.Expression { export interface $sqrt { /** * Calculates the square root. + * New in MongoDB 3.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/sqrt/} */ $sqrt: ResolvesToNumber; @@ -3323,6 +3490,7 @@ export namespace Aggregation.Expression { * Calculates the population standard deviation of the input values. Use if the values encompass the entire population of data you want to represent and do not wish to generalize about a larger population. $stdDevPop ignores non-numeric values. * If the values represent only a sample of a population of data from which to generalize about the population, use $stdDevSamp instead. * Changed in MongoDB 5.0: Available in the $setWindowFields stage. + * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/stdDevPop/} */ $stdDevPop: [...ResolvesToNumber[]]; @@ -3336,6 +3504,7 @@ export namespace Aggregation.Expression { /** * Calculates the sample standard deviation of the input values. Use if the values encompass a sample of a population of data from which to generalize about the population. $stdDevSamp ignores non-numeric values. * If the values represent the entire population of data or you do not wish to generalize about a larger population, use $stdDevPop instead. + * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/stdDevSamp/} */ $stdDevSamp: [...ResolvesToNumber[]]; @@ -3348,6 +3517,7 @@ export namespace Aggregation.Expression { export interface $strLenBytes { /** * Returns the number of UTF-8 encoded bytes in a string. + * New in MongoDB 3.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/strLenBytes/} */ $strLenBytes: ResolvesToString; @@ -3360,6 +3530,7 @@ export namespace Aggregation.Expression { export interface $strLenCP { /** * Returns the number of UTF-8 code points in a string. + * New in MongoDB 3.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/strLenCP/} */ $strLenCP: ResolvesToString; @@ -3372,6 +3543,7 @@ export namespace Aggregation.Expression { export interface $strcasecmp { /** * Performs case-insensitive string comparison and returns: 0 if two strings are equivalent, 1 if the first string is greater than the second, and -1 if the first string is less than the second. + * New in MongoDB 3.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/strcasecmp/} */ $strcasecmp: [ @@ -3387,6 +3559,7 @@ export namespace Aggregation.Expression { export interface $substr { /** * Deprecated. Use $substrBytes or $substrCP. + * New in MongoDB 3.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/substr/} */ $substr: [ @@ -3411,6 +3584,7 @@ export namespace Aggregation.Expression { export interface $substrBytes { /** * Returns the substring of a string. Starts with the character at the specified UTF-8 byte index (zero-based) in the string and continues for the specified number of bytes. + * New in MongoDB 3.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/substrBytes/} */ $substrBytes: [ @@ -3435,6 +3609,7 @@ export namespace Aggregation.Expression { export interface $substrCP { /** * Returns the substring of a string. Starts with the character at the specified UTF-8 code point (CP) index (zero-based) in the string and continues for the number of code points specified. + * New in MongoDB 3.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/substrCP/} */ $substrCP: [ @@ -3459,6 +3634,7 @@ export namespace Aggregation.Expression { export interface $subtract { /** * Returns the result of subtracting the second value from the first. If the two values are numbers, return the difference. If the two values are dates, return the difference in milliseconds. If the two values are a date and a number in milliseconds, return the resulting date. Accepts two argument expressions. If the two values are a date and a number, specify the date argument first as it is not meaningful to subtract a date from a number. + * New in MongoDB 2.6. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/subtract/} */ $subtract: [ @@ -3475,6 +3651,7 @@ export namespace Aggregation.Expression { /** * Returns the subtype of a given value as an integer. In MongoDB 8.3, the only expression * that contains a subtype is a BinData expression. + * New in MongoDB 8.3. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/subtype/} */ $subtype: ResolvesToBinData; @@ -3488,6 +3665,7 @@ export namespace Aggregation.Expression { /** * Returns a sum of numerical values. Ignores non-numeric values. * Changed in MongoDB 5.0: Available in the $setWindowFields stage. + * New in MongoDB 3.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/sum/} */ $sum: [...(ResolvesToNumber | ResolvesToArray)[]]; @@ -3500,6 +3678,7 @@ export namespace Aggregation.Expression { export interface $switch { /** * Evaluates a series of case expressions. When it finds an expression which evaluates to true, $switch executes a specified expression and breaks out of the control flow. + * New in MongoDB 4.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/switch/} */ $switch: { @@ -3526,6 +3705,7 @@ export namespace Aggregation.Expression { export interface $tan { /** * Returns the tangent of a value that is measured in radians. + * New in MongoDB 4.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/tan/} */ $tan: ResolvesToNumber; @@ -3538,6 +3718,7 @@ export namespace Aggregation.Expression { export interface $tanh { /** * Returns the hyperbolic tangent of a value that is measured in radians. + * New in MongoDB 4.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/tanh/} */ $tanh: ResolvesToNumber; @@ -3551,6 +3732,7 @@ export namespace Aggregation.Expression { /** * Converts a value to an array. If the value cannot be converted, $toArray errors. * If the value is null or missing, $toArray returns null. + * New in MongoDB 8.3. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/toArray/} */ $toArray: Expression; @@ -3563,6 +3745,7 @@ export namespace Aggregation.Expression { export interface $toBool { /** * Converts value to a boolean. + * New in MongoDB 4.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/toBool/} */ $toBool: Expression; @@ -3575,6 +3758,7 @@ export namespace Aggregation.Expression { export interface $toDate { /** * Converts value to a Date. + * New in MongoDB 4.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/toDate/} */ $toDate: Expression; @@ -3587,6 +3771,7 @@ export namespace Aggregation.Expression { export interface $toDecimal { /** * Converts value to a Decimal128. + * New in MongoDB 4.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/toDecimal/} */ $toDecimal: Expression; @@ -3599,6 +3784,7 @@ export namespace Aggregation.Expression { export interface $toDouble { /** * Converts value to a double. + * New in MongoDB 4.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/toDouble/} */ $toDouble: Expression; @@ -3611,6 +3797,7 @@ export namespace Aggregation.Expression { export interface $toHashedIndexKey { /** * Computes and returns the hash value of the input expression using the same hash function that MongoDB uses to create a hashed index. A hash function maps a key or string to a fixed-size numeric value. + * New in MongoDB 4.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/toHashedIndexKey/} */ $toHashedIndexKey: Expression; @@ -3623,6 +3810,7 @@ export namespace Aggregation.Expression { export interface $toInt { /** * Converts value to an integer. + * New in MongoDB 4.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/toInt/} */ $toInt: Expression; @@ -3635,6 +3823,7 @@ export namespace Aggregation.Expression { export interface $toLong { /** * Converts value to a long. + * New in MongoDB 4.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/toLong/} */ $toLong: Expression; @@ -3647,6 +3836,7 @@ export namespace Aggregation.Expression { export interface $toLower { /** * Converts a string to lowercase. Accepts a single argument expression. + * New in MongoDB 3.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/toLower/} */ $toLower: ResolvesToString; @@ -3660,6 +3850,7 @@ export namespace Aggregation.Expression { /** * Converts a string to an object. If the value cannot be converted, $toObject errors. * If the value is null or missing, $toObject returns null. + * New in MongoDB 8.3. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/toObject/} */ $toObject: Expression; @@ -3672,6 +3863,7 @@ export namespace Aggregation.Expression { export interface $toObjectId { /** * Converts value to an ObjectId. + * New in MongoDB 4.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/toObjectId/} */ $toObjectId: Expression; @@ -3684,6 +3876,7 @@ export namespace Aggregation.Expression { export interface $toString { /** * Converts value to a string. + * New in MongoDB 4.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/toString/} */ $toString: Expression; @@ -3696,6 +3889,7 @@ export namespace Aggregation.Expression { export interface $toUpper { /** * Converts a string to uppercase. Accepts a single argument expression. + * New in MongoDB 3.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/toUpper/} */ $toUpper: ResolvesToString; @@ -3708,6 +3902,7 @@ export namespace Aggregation.Expression { export interface $top { /** * Returns the top element within an array according to the specified sort order. + * New in MongoDB 7.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/top-array-operator/} */ $top: { @@ -3736,6 +3931,7 @@ export namespace Aggregation.Expression { /** * Returns an aggregation of the top n elements within an array, according to the specified sort order. * If the array contains fewer than n elements, $topN returns all elements in the array. + * New in MongoDB 7.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/topN-array-operator/} */ $topN: { @@ -3768,6 +3964,7 @@ export namespace Aggregation.Expression { export interface $trim { /** * Removes whitespace or the specified characters from the beginning and end of a string. + * New in MongoDB 4.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/trim/} */ $trim: { @@ -3792,6 +3989,7 @@ export namespace Aggregation.Expression { export interface $trunc { /** * Truncates a number to a whole integer or to a specified decimal place. + * New in MongoDB 3.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/trunc/} */ $trunc: [ @@ -3815,6 +4013,7 @@ export namespace Aggregation.Expression { export interface $tsIncrement { /** * Returns the incrementing ordinal from a timestamp as a long. + * New in MongoDB 5.1. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/tsIncrement/} */ $tsIncrement: ResolvesToTimestamp; @@ -3827,6 +4026,7 @@ export namespace Aggregation.Expression { export interface $tsSecond { /** * Returns the seconds from a timestamp as a long. + * New in MongoDB 5.1. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/tsSecond/} */ $tsSecond: ResolvesToTimestamp; @@ -3839,6 +4039,7 @@ export namespace Aggregation.Expression { export interface $type { /** * Return the BSON data type of the field. + * New in MongoDB 3.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/type/} */ $type: Expression; @@ -3852,6 +4053,7 @@ export namespace Aggregation.Expression { /** * You can use $unsetField to remove fields with names that contain periods (.) or that start with dollar signs ($). * $unsetField is an alias for $setField using $$REMOVE to remove fields. + * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/unsetField/} */ $unsetField: { @@ -3874,6 +4076,7 @@ export namespace Aggregation.Expression { export interface $week { /** * Returns the week number for a date as a number between 0 (the partial week that precedes the first Sunday of the year) and 53 (leap year). + * New in MongoDB 2.6. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/week/} */ $week: { @@ -3896,6 +4099,7 @@ export namespace Aggregation.Expression { export interface $year { /** * Returns the year for a date as a number (e.g. 2014). + * New in MongoDB 2.6. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/year/} */ $year: { @@ -3918,6 +4122,7 @@ export namespace Aggregation.Expression { export interface $zip { /** * Merge two arrays together. + * New in MongoDB 3.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/zip/} */ $zip: { @@ -3951,6 +4156,7 @@ export namespace Aggregation.Query { export interface $all { /** * Matches arrays that contain all elements specified in the query. + * New in MongoDB 2.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/all/} */ $all: [...FieldQuery[]]; @@ -3975,6 +4181,7 @@ export namespace Aggregation.Query { export interface $bitsAllClear { /** * Matches numeric or binary values in which a set of bit positions all have a value of 0. + * New in MongoDB 3.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/bitsAllClear/} */ $bitsAllClear: (Int | bson.Binary) | unknown[]; @@ -3987,6 +4194,7 @@ export namespace Aggregation.Query { export interface $bitsAllSet { /** * Matches numeric or binary values in which a set of bit positions all have a value of 1. + * New in MongoDB 3.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/bitsAllSet/} */ $bitsAllSet: (Int | bson.Binary) | unknown[]; @@ -3999,6 +4207,7 @@ export namespace Aggregation.Query { export interface $bitsAnyClear { /** * Matches numeric or binary values in which any bit from a set of bit positions has a value of 0. + * New in MongoDB 3.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/bitsAnyClear/} */ $bitsAnyClear: (Int | bson.Binary) | unknown[]; @@ -4011,6 +4220,7 @@ export namespace Aggregation.Query { export interface $bitsAnySet { /** * Matches numeric or binary values in which any bit from a set of bit positions has a value of 1. + * New in MongoDB 3.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/bitsAnySet/} */ $bitsAnySet: (Int | bson.Binary) | unknown[]; @@ -4023,6 +4233,7 @@ export namespace Aggregation.Query { export interface $box { /** * Specifies a rectangular box using legacy coordinate pairs for $geoWithin queries. The 2d index supports $box. + * New in MongoDB 2.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/box/} */ $box: unknown[]; @@ -4035,6 +4246,7 @@ export namespace Aggregation.Query { export interface $center { /** * Specifies a circle using legacy coordinate pairs to $geoWithin queries when using planar geometry. The 2d index supports $center. + * New in MongoDB 2.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/center/} */ $center: unknown[]; @@ -4047,6 +4259,7 @@ export namespace Aggregation.Query { export interface $centerSphere { /** * Specifies a circle using either legacy coordinate pairs or GeoJSON format for $geoWithin queries when using spherical geometry. The 2dsphere and 2d indexes support $centerSphere. + * New in MongoDB 2.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/centerSphere/} */ $centerSphere: unknown[]; @@ -4059,6 +4272,7 @@ export namespace Aggregation.Query { export interface $comment { /** * Adds a comment to a query predicate. + * New in MongoDB 2.6. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/comment/} */ $comment: string; @@ -4071,6 +4285,7 @@ export namespace Aggregation.Query { export interface $elemMatch { /** * The $elemMatch operator matches documents that contain an array field with at least one element that matches all the specified query criteria. + * New in MongoDB 2.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/elemMatch/} */ $elemMatch: Query | FieldQuery; @@ -4083,6 +4298,7 @@ export namespace Aggregation.Query { export interface $eq { /** * Matches values that are equal to a specified value. + * New in MongoDB 3.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/eq/} */ $eq: any; @@ -4107,6 +4323,7 @@ export namespace Aggregation.Query { export interface $expr { /** * Allows use of aggregation expressions within the query language. + * New in MongoDB 3.6. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/expr/} */ $expr: Expression; @@ -4119,6 +4336,7 @@ export namespace Aggregation.Query { export interface $geoIntersects { /** * Selects geometries that intersect with a GeoJSON geometry. The 2dsphere index supports $geoIntersects. + * New in MongoDB 2.6. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/geoIntersects/} */ $geoIntersects: Geometry & {}; @@ -4131,6 +4349,7 @@ export namespace Aggregation.Query { export interface $geoWithin { /** * Selects geometries within a bounding GeoJSON geometry. The 2dsphere and 2d indexes support $geoWithin. + * New in MongoDB 2.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/geoWithin/} */ $geoWithin: Geometry & {}; @@ -4143,6 +4362,7 @@ export namespace Aggregation.Query { export interface $geometry { /** * Specifies a geometry in GeoJSON format to geospatial query operators. + * New in MongoDB 2.6. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/geometry/} */ $geometry: { @@ -4195,6 +4415,7 @@ export namespace Aggregation.Query { export interface $jsonSchema { /** * Validate documents against the given JSON Schema. + * New in MongoDB 3.6. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/jsonSchema/} */ $jsonSchema: Record; @@ -4231,6 +4452,7 @@ export namespace Aggregation.Query { export interface $maxDistance { /** * Specifies a maximum distance to limit the results of $near and $nearSphere queries. The 2dsphere and 2d indexes support $maxDistance. + * New in MongoDB 2.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/maxDistance/} */ $maxDistance: Number; @@ -4243,6 +4465,7 @@ export namespace Aggregation.Query { export interface $minDistance { /** * Specifies a minimum distance to limit the results of $near and $nearSphere queries. For use with 2dsphere index only. + * New in MongoDB 2.6. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/minDistance/} */ $minDistance: Int | Double; @@ -4279,6 +4502,7 @@ export namespace Aggregation.Query { export interface $near { /** * Returns geospatial objects in proximity to a point. Requires a geospatial index. The 2dsphere and 2d indexes support $near. + * New in MongoDB 2.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/near/} */ $near: Geometry & { @@ -4301,6 +4525,7 @@ export namespace Aggregation.Query { export interface $nearSphere { /** * Returns geospatial objects in proximity to a point on a sphere. Requires a geospatial index. The 2dsphere and 2d indexes support $nearSphere. + * New in MongoDB 2.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/nearSphere/} */ $nearSphere: Geometry & { @@ -4371,6 +4596,7 @@ export namespace Aggregation.Query { export interface $polygon { /** * Specifies a polygon to using legacy coordinate pairs for $geoWithin queries. The 2d index supports $center. + * New in MongoDB 2.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/polygon/} */ $polygon: unknown[]; @@ -4383,6 +4609,7 @@ export namespace Aggregation.Query { export interface $rand { /** * Generates a random float between 0 and 1. + * New in MongoDB 4.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/rand/} */ $rand: Record; @@ -4407,6 +4634,7 @@ export namespace Aggregation.Query { export interface $sampleRate { /** * Randomly select documents at a given rate. Although the exact number of documents selected varies on each run, the quantity chosen approximates the sample rate expressed as a percentage of the total number of documents. + * New in MongoDB 5.3. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/sampleRate/} */ $sampleRate: ResolvesToDouble; @@ -4431,6 +4659,7 @@ export namespace Aggregation.Query { export interface $text { /** * Performs text search. + * New in MongoDB 2.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/text/} */ $text: { @@ -4465,6 +4694,7 @@ export namespace Aggregation.Query { export interface $type { /** * Selects documents if a field is of the specified type. + * New in MongoDB 3.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/type/} */ $type: [...(Int | string)[]]; @@ -4493,6 +4723,7 @@ export namespace Aggregation.Search { * contains a sequence of characters from an incomplete input string. The * fields that you intend to query with the autocomplete operator must be * indexed with the autocomplete data type in the collection's index definition. + * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/} */ autocomplete: { @@ -4513,6 +4744,7 @@ export namespace Aggregation.Search { * The compound operator combines two or more operators into a single query. * Each element of a compound query is called a clause, and each clause * consists of one or more sub-queries. + * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/compound/} */ compound: { @@ -4536,6 +4768,7 @@ export namespace Aggregation.Search { * It constrains multiple query predicates to be satisfied from a single * element of an array of embedded documents. embeddedDocument can be used only * for queries over fields of the embeddedDocuments + * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/embedded-document/} */ embeddedDocument: { @@ -4552,6 +4785,7 @@ export namespace Aggregation.Search { export interface Equals { /** * The equals operator checks whether a field matches a value you specify. + * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/equals/} */ equals: { @@ -4576,6 +4810,7 @@ export namespace Aggregation.Search { export interface Exists { /** * The exists operator tests if a path to a specified indexed field name exists in a document. + * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/exists/} */ exists: { path: SearchPath; score?: SearchScore }; @@ -4589,6 +4824,7 @@ export namespace Aggregation.Search { /** * The facet collector groups results by values or ranges in the specified * faceted fields and returns the count for each of those groups. + * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/facet/} */ facet: { facets: Record; operator?: SearchOperator }; @@ -4602,6 +4838,7 @@ export namespace Aggregation.Search { /** * The geoShape operator supports querying shapes with a relation to a given * geometry if indexShapes is set to true in the index definition. + * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/geoShape/} */ geoShape: { @@ -4621,6 +4858,7 @@ export namespace Aggregation.Search { * The geoWithin operator supports querying geographic points within a given * geometry. Only points are returned, even if indexShapes value is true in * the index definition. + * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/geoWithin/} */ geoWithin: { @@ -4639,6 +4877,7 @@ export namespace Aggregation.Search { export interface HasAncestor { /** * The `hasAncestor` operator queries an `embeddedDocuments` type field specified in the `ancestorPath`. The `ancestorPath` is a parent of the field specified in the `returnScope`. + * New in MongoDB 8.2. * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/operators-collectors/hasancestor/} */ hasAncestor: { ancestorPath: SearchPath; operator: SearchOperator }; @@ -4651,6 +4890,7 @@ export namespace Aggregation.Search { export interface HasRoot { /** * The `hasRoot` operator can be used to query root-level fields when you specify the `returnScope` and `returnStoredSource` options. + * New in MongoDB 8.2. * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/operators-collectors/hasroot/} */ hasRoot: { operator: SearchOperator }; @@ -4663,6 +4903,7 @@ export namespace Aggregation.Search { export interface In { /** * The in operator performs a search for an array of BSON values in a field. + * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/in/} */ in: { @@ -4682,6 +4923,7 @@ export namespace Aggregation.Search { * The moreLikeThis operator returns documents similar to input documents. * The moreLikeThis operator allows you to build features for your applications * that display similar or alternative results based on one or more given documents. + * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/moreLikeThis/} */ moreLikeThis: { @@ -4697,6 +4939,7 @@ export namespace Aggregation.Search { export interface Near { /** * The near operator supports querying and scoring numeric, date, and GeoJSON point values. + * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/near/} */ near: { @@ -4714,6 +4957,7 @@ export namespace Aggregation.Search { export interface Phrase { /** * The phrase operator performs search for documents containing an ordered sequence of terms using the analyzer specified in the index configuration. + * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/phrase/} */ phrase: { @@ -4741,6 +4985,7 @@ export namespace Aggregation.Search { /** * The range operator supports querying and scoring numeric, date, and string values. * You can use this operator to find results that are within a given numeric, date, objectId, or letter (from the English alphabet) range. + * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/range/} */ range: { @@ -4762,6 +5007,7 @@ export namespace Aggregation.Search { /** * regex interprets the query field as a regular expression. * regex is a term-level operator, meaning that the query field isn't analyzed. + * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/regex/} */ regex: { @@ -4780,6 +5026,7 @@ export namespace Aggregation.Search { /** * The text operator performs a full-text search using the analyzer that you specify in the index configuration. * If you omit an analyzer, the text operator uses the default standard analyzer. + * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/text/} */ text: { @@ -4801,6 +5048,7 @@ export namespace Aggregation.Search { * The vectorSearch operator performs an ANN or ENN search on a vector field. It can only be * used as a top-level operator in a $search or $searchMeta query, not nested under compound * or other operators. + * New in MongoDB 6.0. * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/vector-search/} */ vectorSearch: { @@ -4853,6 +5101,7 @@ export namespace Aggregation.Search { export interface Wildcard { /** * The wildcard operator enables queries which use special characters in the search string that can match any character. + * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/wildcard/} */ wildcard: { @@ -4871,6 +5120,7 @@ export namespace Aggregation.Stage { export interface $addFields { /** * Adds new fields to documents. Outputs documents that contain all existing fields from the input documents and newly added fields. + * New in MongoDB 3.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/addFields/} */ $addFields: { @@ -4887,6 +5137,7 @@ export namespace Aggregation.Stage { export interface $bucket { /** * Categorizes incoming documents into groups, called buckets, based on a specified expression and bucket boundaries. + * New in MongoDB 3.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/bucket/} */ $bucket: { @@ -4926,6 +5177,7 @@ export namespace Aggregation.Stage { export interface $bucketAuto { /** * Categorizes incoming documents into a specific number of groups, called buckets, based on a specified expression. Bucket boundaries are automatically determined in an attempt to evenly distribute the documents into the specified number of buckets. + * New in MongoDB 3.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/bucketAuto/} */ $bucketAuto: { @@ -4960,6 +5212,7 @@ export namespace Aggregation.Stage { export interface $changeStream { /** * Returns a Change Stream cursor for the collection or database. This stage can only occur once in an aggregation pipeline and it must occur as the first stage. + * New in MongoDB 3.6. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/changeStream/} */ $changeStream: { @@ -5008,6 +5261,7 @@ export namespace Aggregation.Stage { /** * Splits large change stream events that exceed 16 MB into smaller fragments returned in a change stream cursor. * You can only use $changeStreamSplitLargeEvent in a $changeStream pipeline and it must be the final stage in the pipeline. + * New in MongoDB 6.1. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/changeStreamSplitLargeEvent/} */ $changeStreamSplitLargeEvent: Record; @@ -5020,6 +5274,7 @@ export namespace Aggregation.Stage { export interface $collStats { /** * Returns statistics regarding a collection or view. + * New in MongoDB 3.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/collStats/} */ $collStats: { @@ -5038,6 +5293,7 @@ export namespace Aggregation.Stage { /** * Returns a count of the number of documents at this stage of the aggregation pipeline. * Distinct from the $count aggregation accumulator. + * New in MongoDB 3.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/count/} */ $count: string; @@ -5050,6 +5306,7 @@ export namespace Aggregation.Stage { export interface $currentOp { /** * Returns information on active and/or dormant operations for the MongoDB deployment. To run, use the db.aggregate() method. + * New in MongoDB 3.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/currentOp/} */ $currentOp: { @@ -5068,6 +5325,7 @@ export namespace Aggregation.Stage { export interface $densify { /** * Creates new documents in a sequence of documents where certain values in a field are missing. + * New in MongoDB 5.1. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/densify/} */ $densify: { @@ -5097,6 +5355,7 @@ export namespace Aggregation.Stage { export interface $documents { /** * Returns literal documents from input values. + * New in MongoDB 5.1. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/documents/} */ $documents: ResolvesToArray; @@ -5109,6 +5368,7 @@ export namespace Aggregation.Stage { export interface $facet { /** * Processes multiple aggregation pipelines within a single stage on the same set of input documents. Enables the creation of multi-faceted aggregations capable of characterizing data across multiple dimensions, or facets, in a single stage. + * New in MongoDB 3.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/facet/} */ $facet: {} & { [facet: string]: Pipeline }; @@ -5121,6 +5381,7 @@ export namespace Aggregation.Stage { export interface $fill { /** * Populates null and missing field values within documents. + * New in MongoDB 5.3. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/fill/} */ $fill: { @@ -5158,6 +5419,7 @@ export namespace Aggregation.Stage { export interface $geoNear { /** * Returns an ordered stream of documents based on the proximity to a geospatial point. Incorporates the functionality of $match, $sort, and $limit for geospatial data. The output documents include an additional distance field and can include a location identifier field. + * New in MongoDB 2.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/geoNear/} */ $geoNear: { @@ -5221,6 +5483,7 @@ export namespace Aggregation.Stage { export interface $graphLookup { /** * Performs a recursive search on a collection. To each output document, adds a new array field that contains the traversal results of the recursive search for that document. + * New in MongoDB 3.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/graphLookup/} */ $graphLookup: { @@ -5274,6 +5537,7 @@ export namespace Aggregation.Stage { export interface $group { /** * Groups input documents by a specified identifier expression and applies the accumulator expression(s), if specified, to each group. Consumes all input documents and outputs one document per each distinct group. The output documents only contain the identifier field and, if specified, accumulated fields. + * New in MongoDB 2.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/group/} */ $group: RecordWithStaticFields< @@ -5297,6 +5561,7 @@ export namespace Aggregation.Stage { export interface $indexStats { /** * Returns statistics regarding the use of each index for the collection. + * New in MongoDB 3.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/indexStats/} */ $indexStats: Record; @@ -5309,6 +5574,7 @@ export namespace Aggregation.Stage { export interface $limit { /** * Passes the first n documents unmodified to the pipeline where n is the specified limit. For each input document, outputs either one document (for the first n documents) or zero documents (after the first n documents). + * New in MongoDB 2.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/limit/} */ $limit: Int; @@ -5321,6 +5587,7 @@ export namespace Aggregation.Stage { export interface $listLocalSessions { /** * Lists all active sessions recently in use on the currently connected mongos or mongod instance. These sessions may have not yet propagated to the system.sessions collection. + * New in MongoDB 3.6. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/listLocalSessions/} */ $listLocalSessions: { @@ -5343,6 +5610,7 @@ export namespace Aggregation.Stage { export interface $listSampledQueries { /** * Lists sampled queries for all collections or a specific collection. + * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSampledQueries/} */ $listSampledQueries: { namespace?: string }; @@ -5355,6 +5623,7 @@ export namespace Aggregation.Stage { export interface $listSearchIndexes { /** * Returns information about existing Atlas Search indexes on a specified collection. + * New in MongoDB 7.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSearchIndexes/} */ $listSearchIndexes: { @@ -5377,6 +5646,7 @@ export namespace Aggregation.Stage { export interface $listSessions { /** * Lists all sessions that have been active long enough to propagate to the system.sessions collection. + * New in MongoDB 3.6. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSessions/} */ $listSessions: { @@ -5399,6 +5669,7 @@ export namespace Aggregation.Stage { export interface $lookup { /** * Performs a left outer join to another collection in the same database to filter in documents from the "joined" collection for processing. + * New in MongoDB 3.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/lookup/} */ $lookup: { @@ -5445,6 +5716,7 @@ export namespace Aggregation.Stage { export interface $match { /** * Filters the document stream to allow only matching documents to pass unmodified into the next pipeline stage. $match uses standard MongoDB queries. For each input document, outputs either one document (a match) or zero documents (no match). + * New in MongoDB 2.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/match/} */ $match: Query; @@ -5457,6 +5729,7 @@ export namespace Aggregation.Stage { export interface $merge { /** * Writes the resulting documents of the aggregation pipeline to a collection. The stage can incorporate (insert new documents, merge documents, replace documents, keep existing documents, fail the operation, process documents with a custom update pipeline) the results into an output collection. To use the $merge stage, it must be the last stage in the pipeline. + * New in MongoDB 4.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/} */ $merge: { @@ -5494,6 +5767,7 @@ export namespace Aggregation.Stage { export interface $out { /** * Writes the resulting documents of the aggregation pipeline to a collection. To use the $out stage, it must be the last stage in the pipeline. + * New in MongoDB 2.6. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/out/} */ $out: { @@ -5547,6 +5821,7 @@ export namespace Aggregation.Stage { export interface $planCacheStats { /** * Returns plan cache information for a collection. + * New in MongoDB 4.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/planCacheStats/} */ $planCacheStats: Record; @@ -5559,6 +5834,7 @@ export namespace Aggregation.Stage { export interface $project { /** * Reshapes each document in the stream, such as by adding new fields or removing existing fields. For each input document, outputs one document. + * New in MongoDB 2.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/project/} */ $project: {} & { [specification: string]: Expression }; @@ -5571,6 +5847,7 @@ export namespace Aggregation.Stage { export interface $rankFusion { /** * Combines multiple pipelines using rank-based fusion to create hybrid search results. + * New in MongoDB 8.1. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/rankFusion/} */ $rankFusion: { @@ -5608,6 +5885,7 @@ export namespace Aggregation.Stage { export interface $redact { /** * Reshapes each document in the stream by restricting the content for each document based on information stored in the documents themselves. Incorporates the functionality of $project and $match. Can be used to implement field level redaction. For each input document, outputs either one or zero documents. + * New in MongoDB 2.6. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/redact/} */ $redact: Expression; @@ -5620,6 +5898,7 @@ export namespace Aggregation.Stage { export interface $replaceRoot { /** * Replaces a document with the specified embedded document. The operation replaces all existing fields in the input document, including the _id field. Specify a document embedded in the input document to promote the embedded document to the top level. + * New in MongoDB 3.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceRoot/} */ $replaceRoot: { newRoot: ResolvesToObject }; @@ -5633,6 +5912,7 @@ export namespace Aggregation.Stage { /** * Replaces a document with the specified embedded document. The operation replaces all existing fields in the input document, including the _id field. Specify a document embedded in the input document to promote the embedded document to the top level. * Alias for $replaceRoot. + * New in MongoDB 4.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceWith/} */ $replaceWith: ResolvesToObject; @@ -5645,6 +5925,7 @@ export namespace Aggregation.Stage { export interface $rerank { /** * Reranks documents using a Voyage AI reranking model to improve relevance scoring. + * New in MongoDB 8.3. * @see {@link https://www.mongodb.com/docs/vector-search/query/aggregation-stages/rerank/} */ $rerank: { @@ -5682,6 +5963,7 @@ export namespace Aggregation.Stage { export interface $sample { /** * Randomly selects the specified number of documents from its input. + * New in MongoDB 3.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/sample/} */ $sample: { @@ -5700,6 +5982,7 @@ export namespace Aggregation.Stage { /** * Computes and returns a new score as metadata. It also optionally normalizes the input * scores, by default to a range between zero and one. + * New in MongoDB 8.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/score/} */ $score: { @@ -5737,6 +6020,7 @@ export namespace Aggregation.Stage { export interface $scoreFusion { /** * Combines multiple pipelines using relative score fusion to create hybrid search results. + * New in MongoDB 8.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/scoreFusion/} */ $scoreFusion: { @@ -5790,6 +6074,7 @@ export namespace Aggregation.Stage { /** * Performs a full-text search of the field or fields in an Atlas collection. * NOTE: $search is only available for MongoDB Atlas clusters, and is not available for self-managed deployments. + * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/search/} */ $search: SearchOperator & { @@ -5860,6 +6145,7 @@ export namespace Aggregation.Stage { /** * Returns different types of metadata result documents for the Atlas Search query against an Atlas collection. * NOTE: $searchMeta is only available for MongoDB Atlas clusters running MongoDB v4.4.9 or higher, and is not available for self-managed deployments. + * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/searchMeta/} */ $searchMeta: SearchOperator & { @@ -5893,6 +6179,7 @@ export namespace Aggregation.Stage { /** * Adds new fields to documents. Outputs documents that contain all existing fields from the input documents and newly added fields. * Alias for $addFields. + * New in MongoDB 4.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/set/} */ $set: {} & { [field: string]: Expression }; @@ -5905,6 +6192,7 @@ export namespace Aggregation.Stage { export interface $setWindowFields { /** * Groups documents into windows and applies one or more operators to the documents in each window. + * New in MongoDB 5.0. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/setWindowFields/} */ $setWindowFields: { @@ -5933,6 +6221,7 @@ export namespace Aggregation.Stage { export interface $shardedDataDistribution { /** * Provides data and size distribution information on sharded collections. + * New in MongoDB 6.0.3. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/shardedDataDistribution/} */ $shardedDataDistribution: Record; @@ -5945,6 +6234,7 @@ export namespace Aggregation.Stage { export interface $skip { /** * Skips the first n documents where n is the specified skip number and passes the remaining documents unmodified to the pipeline. For each input document, outputs either zero documents (for the first n documents) or one document (if after the first n documents). + * New in MongoDB 2.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/skip/} */ $skip: Int; @@ -5957,6 +6247,7 @@ export namespace Aggregation.Stage { export interface $sort { /** * Reorders the document stream by a specified sort key. Only the order changes; the documents remain unmodified. For each input document, outputs one document. + * New in MongoDB 2.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/sort/} */ $sort: {} & { [sort: string]: Expression | SortSpec }; @@ -5969,6 +6260,7 @@ export namespace Aggregation.Stage { export interface $sortByCount { /** * Groups incoming documents based on the value of a specified expression, then computes the count of documents in each distinct group. + * New in MongoDB 3.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/sortByCount/} */ $sortByCount: Expression; @@ -5981,6 +6273,7 @@ export namespace Aggregation.Stage { export interface $unionWith { /** * Performs a union of two collections; i.e. combines pipeline results from two collections into a single result set. + * New in MongoDB 4.4. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/unionWith/} */ $unionWith: { @@ -6005,6 +6298,7 @@ export namespace Aggregation.Stage { /** * Removes or excludes fields from documents. * Alias for $project stage that removes or excludes fields. + * New in MongoDB 4.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/unset/} */ $unset: [...UnprefixedFieldPath[]]; @@ -6017,6 +6311,7 @@ export namespace Aggregation.Stage { export interface $unwind { /** * Deconstructs an array field from the input documents to output a document for each element. Each output document replaces the array with an element value. For each input document, outputs n documents where n is the number of array elements and can be zero for an empty array. + * New in MongoDB 2.2. * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/unwind/} */ $unwind: { @@ -6046,6 +6341,7 @@ export namespace Aggregation.Stage { export interface $vectorSearch { /** * The $vectorSearch stage performs an ANN or ENN search on a vector in the specified field. + * New in MongoDB 6.0. * @see {@link https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-stage/} */ $vectorSearch: { diff --git a/packages/mql-typescript/src/cli.ts b/packages/mql-typescript/src/cli.ts index c09366c6..f409fc17 100644 --- a/packages/mql-typescript/src/cli.ts +++ b/packages/mql-typescript/src/cli.ts @@ -6,28 +6,31 @@ import { DriverSchemaGenerator } from './driverSchema/driver-schema-generator'; import type { GeneratorBase } from './generator'; async function main() { + const filterOptions = { + category: { + type: 'string', + choices: ['accumulator', 'expression', 'query', 'search', 'stage'], + description: + 'The category of the operator to generate. If not provided, all categories will be used.', + }, + operator: { + type: 'string', + description: + 'The operator to generate. If not provided, all operators will be used.', + }, + } as const; + const argv = await yargs(hideBin(process.argv)) .command('schema', 'Generates schema from the php driver definitions') .command( 'tests', 'Generates tests from the php driver definitions and the docs examples', + filterOptions, ) .command( 'driver-schema', 'Updates the php driver definitions with the schema for the tests', - { - category: { - type: 'string', - choices: ['accumulator', 'expression', 'query', 'search', 'stage'], - description: - 'The category of the operator to update. If not provided, all categories will be updated.', - }, - operator: { - type: 'string', - description: - 'The operator to update the schema for. If not provided, all operators will be updated.', - }, - }, + filterOptions, ) .demandCommand(1, 'A command must be provided') .help().argv; diff --git a/packages/mql-typescript/src/driverSchema/static-schemas.ts b/packages/mql-typescript/src/driverSchema/static-schemas.ts index 74e210a8..9452aeed 100644 --- a/packages/mql-typescript/src/driverSchema/static-schemas.ts +++ b/packages/mql-typescript/src/driverSchema/static-schemas.ts @@ -1473,6 +1473,33 @@ const staticSchemas: SchemaMap = { }, }, expression: { + concatArrays: { + Example: { + collectionName: 'warehouses', + schema: { + instock: { + types: [{ bsonType: 'Array', types: [{ bsonType: 'String' }] }], + }, + ordered: { + types: [{ bsonType: 'Array', types: [{ bsonType: 'String' }] }], + }, + }, + }, + }, + setUnion: { + Example: { + collectionName: 'flowers', + schema: { + flowerFieldA: { + types: [{ bsonType: 'Array', types: [{ bsonType: 'String' }] }], + }, + flowerFieldB: { + types: [{ bsonType: 'Array', types: [{ bsonType: 'String' }] }], + }, + }, + }, + }, + serializeEJSON: mflixMoviesSchema, dateFromParts: { Example: { collectionName: 'sales', diff --git a/packages/mql-typescript/src/schema-generator.ts b/packages/mql-typescript/src/schema-generator.ts index d2af5275..7de97838 100644 --- a/packages/mql-typescript/src/schema-generator.ts +++ b/packages/mql-typescript/src/schema-generator.ts @@ -475,7 +475,15 @@ export class SchemaGenerator extends GeneratorBase { ); this.emit(`export interface ${ifaceName} {`); if (parsed.description) { - this.emitComment(parsed.description, parsed.link); + // Append a "New in MongoDB" note derived from the operator's + // `minVersion`, matching how the documentation annotates operators. + // `1.0` denotes the initial release (i.e. the operator has always + // existed), so we omit the note in that case. + const versionNote = + parsed.minVersion === '1.0' + ? '' + : `\nNew in MongoDB ${parsed.minVersion}.`; + this.emitComment(`${parsed.description}${versionNote}`, parsed.link); } this.emit(`${parsed.name}:`); for (const type of parsed.type) { diff --git a/packages/mql-typescript/tests/expression/concatArrays.spec.ts b/packages/mql-typescript/tests/expression/concatArrays.spec.ts index c064f7f4..8ca9ab47 100644 --- a/packages/mql-typescript/tests/expression/concatArrays.spec.ts +++ b/packages/mql-typescript/tests/expression/concatArrays.spec.ts @@ -9,18 +9,12 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/concatArrays/#example} */ function test0() { - type sales = { - _id: number; - items: Array< - | string - | { - accessories: Array; - } - >; - location: string; + type warehouses = { + instock: Array; + ordered: Array; }; - const aggregation: schema.Pipeline = [ + const aggregation: schema.Pipeline = [ { $project: { items: { $concatArrays: ['$instock', '$ordered'] } } }, ]; } diff --git a/packages/mql-typescript/tests/expression/serializeEJSON.spec.ts b/packages/mql-typescript/tests/expression/serializeEJSON.spec.ts index 87f759b1..8a532259 100644 --- a/packages/mql-typescript/tests/expression/serializeEJSON.spec.ts +++ b/packages/mql-typescript/tests/expression/serializeEJSON.spec.ts @@ -9,31 +9,63 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/serializeEJSON/#canonical-extended-json-example} */ function test0() { - type TestCollection = { - _id: bson.ObjectId; - ejson: { - _id: { - $oid: string; - }; - title: string; - year: { + type movies = { + _id: { + $oid: string; + }; + title: string; + year: { + $numberInt: string; + }; + runtime: { + $numberInt: string; + }; + released: { + $date: { + $numberLong: string; + }; + }; + poster: string; + plot: string; + fullplot: string; + lastupdated: string; + type: string; + directors: Array; + imdb: { + rating: { + $numberDouble: string; + }; + votes: { $numberInt: string; }; - runtime: { + id: { $numberInt: string; }; - released: { + }; + cast: Array; + countries: Array; + genres: Array; + tomatoes: { + viewer: { + rating: { + $numberDouble: string; + }; + numReviews: { + $numberInt: string; + }; + }; + lastUpdated: { $date: { $numberLong: string; }; }; - cast: Array; - genres: Array; - directors: Array; + }; + num_mflix_comments: { + $numberInt: string; }; }; - const aggregation: schema.Pipeline = [ + const aggregation: schema.Pipeline = [ { $match: { title: 'Inception' } }, { $project: { ejson: { $serializeEJSON: { input: '$$ROOT' } } } }, ]; @@ -44,31 +76,63 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/serializeEJSON/#relaxed-extended-json-example} */ function test1() { - type TestCollection = { - _id: bson.ObjectId; - ejson: { - _id: { - $oid: string; - }; - title: string; - year: { + type movies = { + _id: { + $oid: string; + }; + title: string; + year: { + $numberInt: string; + }; + runtime: { + $numberInt: string; + }; + released: { + $date: { + $numberLong: string; + }; + }; + poster: string; + plot: string; + fullplot: string; + lastupdated: string; + type: string; + directors: Array; + imdb: { + rating: { + $numberDouble: string; + }; + votes: { $numberInt: string; }; - runtime: { + id: { $numberInt: string; }; - released: { + }; + cast: Array; + countries: Array; + genres: Array; + tomatoes: { + viewer: { + rating: { + $numberDouble: string; + }; + numReviews: { + $numberInt: string; + }; + }; + lastUpdated: { $date: { $numberLong: string; }; }; - cast: Array; - genres: Array; - directors: Array; + }; + num_mflix_comments: { + $numberInt: string; }; }; - const aggregation: schema.Pipeline = [ + const aggregation: schema.Pipeline = [ { $match: { title: 'Inception' } }, { $project: { @@ -83,31 +147,63 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/serializeEJSON/#convert-to-json-string} */ function test2() { - type TestCollection = { - _id: bson.ObjectId; - ejson: { - _id: { - $oid: string; - }; - title: string; - year: { + type movies = { + _id: { + $oid: string; + }; + title: string; + year: { + $numberInt: string; + }; + runtime: { + $numberInt: string; + }; + released: { + $date: { + $numberLong: string; + }; + }; + poster: string; + plot: string; + fullplot: string; + lastupdated: string; + type: string; + directors: Array; + imdb: { + rating: { + $numberDouble: string; + }; + votes: { $numberInt: string; }; - runtime: { + id: { $numberInt: string; }; - released: { + }; + cast: Array; + countries: Array; + genres: Array; + tomatoes: { + viewer: { + rating: { + $numberDouble: string; + }; + numReviews: { + $numberInt: string; + }; + }; + lastUpdated: { $date: { $numberLong: string; }; }; - cast: Array; - genres: Array; - directors: Array; + }; + num_mflix_comments: { + $numberInt: string; }; }; - const aggregation: schema.Pipeline = [ + const aggregation: schema.Pipeline = [ { $match: { title: 'The Godfather' } }, { $project: { @@ -123,31 +219,63 @@ function test2() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/serializeEJSON/#serialize-specific-fields} */ function test3() { - type TestCollection = { - _id: bson.ObjectId; - ejson: { - _id: { - $oid: string; - }; - title: string; - year: { + type movies = { + _id: { + $oid: string; + }; + title: string; + year: { + $numberInt: string; + }; + runtime: { + $numberInt: string; + }; + released: { + $date: { + $numberLong: string; + }; + }; + poster: string; + plot: string; + fullplot: string; + lastupdated: string; + type: string; + directors: Array; + imdb: { + rating: { + $numberDouble: string; + }; + votes: { $numberInt: string; }; - runtime: { + id: { $numberInt: string; }; - released: { + }; + cast: Array; + countries: Array; + genres: Array; + tomatoes: { + viewer: { + rating: { + $numberDouble: string; + }; + numReviews: { + $numberInt: string; + }; + }; + lastUpdated: { $date: { $numberLong: string; }; }; - cast: Array; - genres: Array; - directors: Array; + }; + num_mflix_comments: { + $numberInt: string; }; }; - const aggregation: schema.Pipeline = [ + const aggregation: schema.Pipeline = [ { $match: { year: { $gte: 2010 } } }, { $project: { @@ -171,31 +299,63 @@ function test3() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/serializeEJSON/#use-onerror-for-error-handling} */ function test4() { - type TestCollection = { - _id: bson.ObjectId; - ejson: { - _id: { - $oid: string; - }; - title: string; - year: { + type movies = { + _id: { + $oid: string; + }; + title: string; + year: { + $numberInt: string; + }; + runtime: { + $numberInt: string; + }; + released: { + $date: { + $numberLong: string; + }; + }; + poster: string; + plot: string; + fullplot: string; + lastupdated: string; + type: string; + directors: Array; + imdb: { + rating: { + $numberDouble: string; + }; + votes: { $numberInt: string; }; - runtime: { + id: { $numberInt: string; }; - released: { + }; + cast: Array; + countries: Array; + genres: Array; + tomatoes: { + viewer: { + rating: { + $numberDouble: string; + }; + numReviews: { + $numberInt: string; + }; + }; + lastUpdated: { $date: { $numberLong: string; }; }; - cast: Array; - genres: Array; - directors: Array; + }; + num_mflix_comments: { + $numberInt: string; }; }; - const aggregation: schema.Pipeline = [ + const aggregation: schema.Pipeline = [ { $project: { title: 1, diff --git a/packages/mql-typescript/tests/expression/setUnion.spec.ts b/packages/mql-typescript/tests/expression/setUnion.spec.ts index 90a07640..682abfd9 100644 --- a/packages/mql-typescript/tests/expression/setUnion.spec.ts +++ b/packages/mql-typescript/tests/expression/setUnion.spec.ts @@ -9,18 +9,12 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/setUnion/#example} */ function test0() { - type sales = { - _id: number; - items: Array< - | string - | { - accessories: Array; - } - >; - location: string; + type flowers = { + flowerFieldA: Array; + flowerFieldB: Array; }; - const aggregation: schema.Pipeline = [ + const aggregation: schema.Pipeline = [ { $project: { flowerFieldA: 1, From b38bde4ead36cca262237aee9f93836ecbfea60d Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Tue, 30 Jun 2026 15:00:43 +0100 Subject: [PATCH 6/8] Add back tests --- packages/mql-typescript/mql-specifications | 2 +- .../tests/accumulator/minMaxScaler.spec.ts | 5 +- .../tests/expression/bottom.spec.ts | 24 +- .../tests/expression/bottomN.spec.ts | 25 +- .../tests/expression/concatArrays.spec.ts | 1 + .../tests/expression/cond.spec.ts | 17 +- .../tests/expression/convert.spec.ts | 106 ++++++- .../tests/expression/createObjectId.spec.ts | 2 +- .../tests/expression/deserializeEJSON.spec.ts | 53 ++-- .../tests/expression/getField.spec.ts | 2 +- .../tests/expression/hash.spec.ts | 1 + .../tests/expression/hexHash.spec.ts | 1 + .../tests/expression/ifNull.spec.ts | 20 +- .../tests/expression/map.spec.ts | 59 +++- .../tests/expression/max.spec.ts | 4 +- .../tests/expression/min.spec.ts | 4 +- .../tests/expression/replaceOne.spec.ts | 19 +- .../tests/expression/serializeEJSON.spec.ts | 282 ++---------------- .../tests/expression/setField.spec.ts | 4 +- .../tests/expression/setUnion.spec.ts | 3 +- .../tests/expression/sigmoid.spec.ts | 9 +- .../tests/expression/subtype.spec.ts | 8 +- .../tests/expression/sum.spec.ts | 4 +- .../tests/expression/toArray.spec.ts | 1 + .../tests/expression/top.spec.ts | 24 +- .../tests/expression/topN.spec.ts | 25 +- .../tests/expression/type.spec.ts | 7 +- .../tests/expression/unsetField.spec.ts | 2 +- .../tests/query/comment.spec.ts | 2 +- .../mql-typescript/tests/query/in.spec.ts | 4 +- .../mql-typescript/tests/query/ne.spec.ts | 2 +- .../mql-typescript/tests/query/rand.spec.ts | 2 +- .../mql-typescript/tests/query/text.spec.ts | 14 +- .../tests/search/vectorSearch.spec.ts | 74 ++++- .../tests/stage/addFields.spec.ts | 8 +- .../mql-typescript/tests/stage/count.spec.ts | 2 +- .../mql-typescript/tests/stage/facet.spec.ts | 2 +- .../tests/stage/indexStats.spec.ts | 2 +- .../mql-typescript/tests/stage/match.spec.ts | 4 +- .../mql-typescript/tests/stage/merge.spec.ts | 12 +- .../mql-typescript/tests/stage/out.spec.ts | 20 +- .../tests/stage/rankFusion.spec.ts | 2 +- .../mql-typescript/tests/stage/rerank.spec.ts | 2 +- .../mql-typescript/tests/stage/sample.spec.ts | 2 +- .../mql-typescript/tests/stage/score.spec.ts | 8 +- .../tests/stage/scoreFusion.spec.ts | 2 +- .../tests/stage/sortByCount.spec.ts | 2 +- .../tests/stage/vectorSearch.spec.ts | 148 +++++---- 48 files changed, 592 insertions(+), 436 deletions(-) diff --git a/packages/mql-typescript/mql-specifications b/packages/mql-typescript/mql-specifications index 5b99b699..1fe529bf 160000 --- a/packages/mql-typescript/mql-specifications +++ b/packages/mql-typescript/mql-specifications @@ -1 +1 @@ -Subproject commit 5b99b6999de36e4b50ece576708426f4e762e36b +Subproject commit 1fe529bf7830ee717392d408646d39b5934a319a diff --git a/packages/mql-typescript/tests/accumulator/minMaxScaler.spec.ts b/packages/mql-typescript/tests/accumulator/minMaxScaler.spec.ts index 4dbedb3b..07e7db73 100644 --- a/packages/mql-typescript/tests/accumulator/minMaxScaler.spec.ts +++ b/packages/mql-typescript/tests/accumulator/minMaxScaler.spec.ts @@ -9,12 +9,11 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/minMaxScaler/#examples} */ function test0() { - type TestCollection = { - _id: number; + type example = { a: number; }; - const aggregation: schema.Pipeline = [ + const aggregation: schema.Pipeline = [ { $setWindowFields: { sortBy: { a: 1 }, diff --git a/packages/mql-typescript/tests/expression/bottom.spec.ts b/packages/mql-typescript/tests/expression/bottom.spec.ts index 1666daab..c0e26dab 100644 --- a/packages/mql-typescript/tests/expression/bottom.spec.ts +++ b/packages/mql-typescript/tests/expression/bottom.spec.ts @@ -9,5 +9,27 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/bottom-array-operator/#example} */ function test0() { - // TODO: no schema found for bottom.Example: // TODO: No schema found in docs + type games = { + results: Array<{ + playerId: string; + score: number; + }>; + }; + + const aggregation: schema.Pipeline = [ + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). + */ + { + $project: { + bottomScore: { + $bottom: { + sortBy: { score: -1 }, + output: ['$playerId', '$score'], + input: '$results', + }, + }, + }, + } as any, + ]; } diff --git a/packages/mql-typescript/tests/expression/bottomN.spec.ts b/packages/mql-typescript/tests/expression/bottomN.spec.ts index 13d6b90c..dee7411c 100644 --- a/packages/mql-typescript/tests/expression/bottomN.spec.ts +++ b/packages/mql-typescript/tests/expression/bottomN.spec.ts @@ -9,5 +9,28 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/bottomN-array-operator/#example} */ function test0() { - // TODO: no schema found for bottomN.Example: // TODO: No schema found in docs + type games = { + results: Array<{ + playerId: string; + score: number; + }>; + }; + + const aggregation: schema.Pipeline = [ + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). + */ + { + $project: { + bottomScores: { + $bottomN: { + n: 3, + sortBy: { score: -1 }, + output: ['$playerId', '$score'], + input: '$results', + }, + }, + }, + } as any, + ]; } diff --git a/packages/mql-typescript/tests/expression/concatArrays.spec.ts b/packages/mql-typescript/tests/expression/concatArrays.spec.ts index 8ca9ab47..e812f009 100644 --- a/packages/mql-typescript/tests/expression/concatArrays.spec.ts +++ b/packages/mql-typescript/tests/expression/concatArrays.spec.ts @@ -10,6 +10,7 @@ import * as bson from 'bson'; */ function test0() { type warehouses = { + _id: number; instock: Array; ordered: Array; }; diff --git a/packages/mql-typescript/tests/expression/cond.spec.ts b/packages/mql-typescript/tests/expression/cond.spec.ts index 4f07b44f..95298d28 100644 --- a/packages/mql-typescript/tests/expression/cond.spec.ts +++ b/packages/mql-typescript/tests/expression/cond.spec.ts @@ -9,5 +9,20 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/cond/#example} */ function test0() { - // TODO: no schema found for cond.Example: // TODO: No schema found in docs + type inventory = { + _id: number; + item: string; + qty: number; + }; + + const aggregation: schema.Pipeline = [ + { + $project: { + item: 1, + discount: { + $cond: { if: { $gte: ['$qty', 250] }, then: 30, else: 20 }, + }, + }, + }, + ]; } diff --git a/packages/mql-typescript/tests/expression/convert.spec.ts b/packages/mql-typescript/tests/expression/convert.spec.ts index ec7c323c..5f34eb13 100644 --- a/packages/mql-typescript/tests/expression/convert.spec.ts +++ b/packages/mql-typescript/tests/expression/convert.spec.ts @@ -9,7 +9,83 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/convert/#example} */ function test0() { - // TODO: no schema found for convert.Example: // TODO: No schema found in docs + type orders = { + _id: number; + item: string; + qty: number; + price: bson.Decimal128 | number | string; + }; + + const aggregation: schema.Pipeline = [ + { + $addFields: { + convertedPrice: { + $convert: { + input: '$price', + to: 'decimal', + onError: 'Error', + onNull: { + bytes: { + '0': 0, + '1': 0, + '2': 0, + '3': 0, + '4': 0, + '5': 0, + '6': 0, + '7': 0, + '8': 0, + '9': 0, + '10': 0, + '11': 0, + '12': 0, + '13': 0, + '14': 64, + '15': 48, + }, + }, + }, + }, + convertedQty: { + $convert: { + input: '$qty', + to: 'int', + onError: { + $concat: [ + 'Could not convert ', + { $toString: '$qty' }, + ' to type integer.', + ], + }, + onNull: 0, + }, + }, + }, + }, + + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (it may involve a projected field). + */ + { + $project: { + totalPrice: { + $switch: { + branches: [ + { + case: { $eq: [{ $type: '$convertedPrice' }, 'string'] }, + then: 'NaN', + }, + { + case: { $eq: [{ $type: '$convertedQty' }, 'string'] }, + then: 'NaN', + }, + ], + default: { $multiply: ['$convertedPrice', '$convertedQty'] }, + }, + }, + }, + } as any, + ]; } /** @@ -17,7 +93,20 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/convert/#base-conversion} */ function test1() { - // TODO: no schema found for convert.Convert Hexadecimal String to Integer: // TODO: No schema found in docs + type data = { + _id: number; + hexString: string; + }; + + const aggregation: schema.Pipeline = [ + { + $project: { + decimalValue: { + $convert: { input: '$hexString', to: 'int', base: 16 }, + }, + }, + }, + ]; } /** @@ -25,5 +114,16 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/convert/#base-conversion} */ function test2() { - // TODO: no schema found for convert.Convert Integer to Binary String: // TODO: No schema found in docs + type data = { + _id: number; + value: bson.Int32 | number; + }; + + const aggregation: schema.Pipeline = [ + { + $project: { + binaryString: { $convert: { input: '$value', to: 'string', base: 2 } }, + }, + }, + ]; } diff --git a/packages/mql-typescript/tests/expression/createObjectId.spec.ts b/packages/mql-typescript/tests/expression/createObjectId.spec.ts index acf16460..c347bd80 100644 --- a/packages/mql-typescript/tests/expression/createObjectId.spec.ts +++ b/packages/mql-typescript/tests/expression/createObjectId.spec.ts @@ -9,5 +9,5 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/createObjectId/#example} */ function test0() { - // TODO: no schema found for createObjectId.Example: // TODO: No schema found in docs + // TODO: no schema found for createObjectId.Example } diff --git a/packages/mql-typescript/tests/expression/deserializeEJSON.spec.ts b/packages/mql-typescript/tests/expression/deserializeEJSON.spec.ts index cdd976d7..9d37118e 100644 --- a/packages/mql-typescript/tests/expression/deserializeEJSON.spec.ts +++ b/packages/mql-typescript/tests/expression/deserializeEJSON.spec.ts @@ -9,22 +9,18 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/deserializeEJSON/#deserialize-extended-json-document} */ function test0() { - type TestCollection = { + type movies = { _id: bson.ObjectId; title: string; - deserialized: { - _id: bson.ObjectId; - title: string; - year: number; - runtime: number; - released: Date; - cast: Array; - genres: Array; - directors: Array; - }; + year: bson.Int32 | number; + runtime: bson.Int32 | number; + released: Date; + cast: unknown[]; + genres: unknown[]; + directors: unknown[]; }; - const aggregation: schema.Pipeline = [ + const aggregation: schema.Pipeline = [ { $match: { title: 'Inception' } }, { $project: { @@ -71,22 +67,17 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/deserializeEJSON/#deserialize-specific-fields} */ function test2() { - type TestCollection = { + type movies = { _id: bson.ObjectId; title: string; - deserialized: { - _id: bson.ObjectId; - title: string; - year: number; - runtime: number; - released: Date; - cast: Array; - genres: Array; - directors: Array; + released: Date; + runtime: bson.Int32 | number; + imdb: { + rating: bson.Double | number; }; }; - const aggregation: schema.Pipeline = [ + const aggregation: schema.Pipeline = [ { $match: { title: 'Inception' } }, { $project: { @@ -116,22 +107,12 @@ function test2() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/deserializeEJSON/#use-onerror-for-error-handling} */ function test3() { - type TestCollection = { + type data = { _id: bson.ObjectId; - title: string; - deserialized: { - _id: bson.ObjectId; - title: string; - year: number; - runtime: number; - released: Date; - cast: Array; - genres: Array; - directors: Array; - }; + ejsonField: string; }; - const aggregation: schema.Pipeline = [ + const aggregation: schema.Pipeline = [ { $project: { result: { diff --git a/packages/mql-typescript/tests/expression/getField.spec.ts b/packages/mql-typescript/tests/expression/getField.spec.ts index 25f9e77e..f85709f5 100644 --- a/packages/mql-typescript/tests/expression/getField.spec.ts +++ b/packages/mql-typescript/tests/expression/getField.spec.ts @@ -31,7 +31,7 @@ function test1() { type inventory = { _id: number; item: string; - 'price.usd': number; + $price: number; qty: number; }; diff --git a/packages/mql-typescript/tests/expression/hash.spec.ts b/packages/mql-typescript/tests/expression/hash.spec.ts index c94327af..ca4dd21f 100644 --- a/packages/mql-typescript/tests/expression/hash.spec.ts +++ b/packages/mql-typescript/tests/expression/hash.spec.ts @@ -12,6 +12,7 @@ function test0() { type files = { _id: number; filename: string; + hash: bson.Binary; }; const aggregation: schema.Pipeline = [ diff --git a/packages/mql-typescript/tests/expression/hexHash.spec.ts b/packages/mql-typescript/tests/expression/hexHash.spec.ts index bc9ca6da..cc9c5477 100644 --- a/packages/mql-typescript/tests/expression/hexHash.spec.ts +++ b/packages/mql-typescript/tests/expression/hexHash.spec.ts @@ -12,6 +12,7 @@ function test0() { type files = { _id: number; filename: string; + hexHash: string; }; const aggregation: schema.Pipeline = [ diff --git a/packages/mql-typescript/tests/expression/ifNull.spec.ts b/packages/mql-typescript/tests/expression/ifNull.spec.ts index 1052b6be..aee239c1 100644 --- a/packages/mql-typescript/tests/expression/ifNull.spec.ts +++ b/packages/mql-typescript/tests/expression/ifNull.spec.ts @@ -9,12 +9,14 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/ifNull/#single-input-expression} */ function test0() { - type TestCollection = { - title: string; - rated: string; + type inventory = { + _id: number; + item: string; + description: string | null; + quantity: number; }; - const aggregation: schema.Pipeline = [ + const aggregation: schema.Pipeline = [ { $project: { item: 1, @@ -29,12 +31,14 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/ifNull/#multiple-input-expressions} */ function test1() { - type TestCollection = { - title: string; - rated: string; + type inventory = { + _id: number; + item: string; + description: string | null; + quantity: number; }; - const aggregation: schema.Pipeline = [ + const aggregation: schema.Pipeline = [ { $project: { item: 1, diff --git a/packages/mql-typescript/tests/expression/map.spec.ts b/packages/mql-typescript/tests/expression/map.spec.ts index beb4ee52..ac9b3f56 100644 --- a/packages/mql-typescript/tests/expression/map.spec.ts +++ b/packages/mql-typescript/tests/expression/map.spec.ts @@ -9,12 +9,11 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/map/#add-to-each-element-of-an-array} */ function test0() { - type TestCollection = { - theaterId: number; - adjustedCoordinates: Array; + type grades = { + quizzes: Array; }; - const aggregation: schema.Pipeline = [ + const aggregation: schema.Pipeline = [ /** * This stage is unsupported by the static type system, so we're casting it to 'any' ($map references the variable names defined in the `as` field, which is not available statically). */ @@ -37,12 +36,12 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/map/#truncate-each-array-element} */ function test1() { - type TestCollection = { - theaterId: number; - adjustedCoordinates: Array; + type deliveries = { + city: string; + distances: Array; }; - const aggregation: schema.Pipeline = [ + const aggregation: schema.Pipeline = [ /** * This stage is unsupported by the static type system, so we're casting it to 'any' ($map references the variable names defined in the `as` field, which is not available statically). */ @@ -66,7 +65,27 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/map/#convert-celsius-temperatures-to-fahrenheit} */ function test2() { - // TODO: no schema found for map.Convert Celsius Temperatures to Fahrenheit: // TODO: No schema found in docs + type temperatures = { + date: Date; + tempsC: Array; + }; + + const aggregation: schema.Pipeline = [ + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' ($map references the variable names defined in the `as` field, which is not available statically). + */ + { + $addFields: { + tempsF: { + $map: { + input: '$tempsC', + as: 'tempInCelsius', + in: { $add: [{ $multiply: ['$$tempInCelsius', 1.8] }, 32] }, + }, + }, + }, + } as any, + ]; } /** @@ -74,5 +93,25 @@ function test2() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/map/} */ function test3() { - // TODO: no schema found for map.Use Array Index: // TODO: No schema found in docs + type data = { + scores: Array; + }; + + const aggregation: schema.Pipeline = [ + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' ($map references the variable names defined in the `as` and `arrayIndexAs` fields, which is not available statically). + */ + { + $project: { + result: { + $map: { + input: '$scores', + as: 'score', + arrayIndexAs: 'idx', + in: { $add: ['$$score', '$$idx'] }, + }, + }, + }, + } as any, + ]; } diff --git a/packages/mql-typescript/tests/expression/max.spec.ts b/packages/mql-typescript/tests/expression/max.spec.ts index 4495bdc5..48cf3572 100644 --- a/packages/mql-typescript/tests/expression/max.spec.ts +++ b/packages/mql-typescript/tests/expression/max.spec.ts @@ -9,7 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/max/#use-in--project-stage} */ function test0() { - type students = { + type TestCollection = { _id: number; quizzes: Array; labs: Array; @@ -17,7 +17,7 @@ function test0() { midterm: number; }; - const aggregation: schema.Pipeline = [ + const aggregation: schema.Pipeline = [ { $project: { quizMax: { $max: ['$quizzes'] }, diff --git a/packages/mql-typescript/tests/expression/min.spec.ts b/packages/mql-typescript/tests/expression/min.spec.ts index 39cf7b0a..a7bb280a 100644 --- a/packages/mql-typescript/tests/expression/min.spec.ts +++ b/packages/mql-typescript/tests/expression/min.spec.ts @@ -9,7 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/min/#use-in--project-stage} */ function test0() { - type students = { + type TestCollection = { _id: number; quizzes: Array; labs: Array; @@ -17,7 +17,7 @@ function test0() { midterm: number; }; - const aggregation: schema.Pipeline = [ + const aggregation: schema.Pipeline = [ { $project: { quizMin: { $min: ['$quizzes'] }, diff --git a/packages/mql-typescript/tests/expression/replaceOne.spec.ts b/packages/mql-typescript/tests/expression/replaceOne.spec.ts index 2a368196..09c91e1f 100644 --- a/packages/mql-typescript/tests/expression/replaceOne.spec.ts +++ b/packages/mql-typescript/tests/expression/replaceOne.spec.ts @@ -9,7 +9,24 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceOne/#example} */ function test0() { - // TODO: no schema found for replaceOne.Example: // TODO: No schema found in docs + type inventory = { + _id: number; + item: string; + }; + + const aggregation: schema.Pipeline = [ + { + $project: { + item: { + $replaceOne: { + input: '$item', + find: 'blue paint', + replacement: 'red paint', + }, + }, + }, + }, + ]; } /** diff --git a/packages/mql-typescript/tests/expression/serializeEJSON.spec.ts b/packages/mql-typescript/tests/expression/serializeEJSON.spec.ts index 8a532259..af60c119 100644 --- a/packages/mql-typescript/tests/expression/serializeEJSON.spec.ts +++ b/packages/mql-typescript/tests/expression/serializeEJSON.spec.ts @@ -10,59 +10,14 @@ import * as bson from 'bson'; */ function test0() { type movies = { - _id: { - $oid: string; - }; + _id: bson.ObjectId; title: string; - year: { - $numberInt: string; - }; - runtime: { - $numberInt: string; - }; - released: { - $date: { - $numberLong: string; - }; - }; - poster: string; - plot: string; - fullplot: string; - lastupdated: string; - type: string; - directors: Array; - imdb: { - rating: { - $numberDouble: string; - }; - votes: { - $numberInt: string; - }; - id: { - $numberInt: string; - }; - }; - cast: Array; - countries: Array; - genres: Array; - tomatoes: { - viewer: { - rating: { - $numberDouble: string; - }; - numReviews: { - $numberInt: string; - }; - }; - lastUpdated: { - $date: { - $numberLong: string; - }; - }; - }; - num_mflix_comments: { - $numberInt: string; - }; + year: bson.Int32 | number; + runtime: bson.Int32 | number; + released: Date; + cast: unknown[]; + genres: unknown[]; + directors: unknown[]; }; const aggregation: schema.Pipeline = [ @@ -77,59 +32,14 @@ function test0() { */ function test1() { type movies = { - _id: { - $oid: string; - }; + _id: bson.ObjectId; title: string; - year: { - $numberInt: string; - }; - runtime: { - $numberInt: string; - }; - released: { - $date: { - $numberLong: string; - }; - }; - poster: string; - plot: string; - fullplot: string; - lastupdated: string; - type: string; - directors: Array; - imdb: { - rating: { - $numberDouble: string; - }; - votes: { - $numberInt: string; - }; - id: { - $numberInt: string; - }; - }; - cast: Array; - countries: Array; - genres: Array; - tomatoes: { - viewer: { - rating: { - $numberDouble: string; - }; - numReviews: { - $numberInt: string; - }; - }; - lastUpdated: { - $date: { - $numberLong: string; - }; - }; - }; - num_mflix_comments: { - $numberInt: string; - }; + year: bson.Int32 | number; + runtime: bson.Int32 | number; + released: Date; + cast: unknown[]; + genres: unknown[]; + directors: unknown[]; }; const aggregation: schema.Pipeline = [ @@ -148,59 +58,10 @@ function test1() { */ function test2() { type movies = { - _id: { - $oid: string; - }; + _id: bson.ObjectId; title: string; - year: { - $numberInt: string; - }; - runtime: { - $numberInt: string; - }; - released: { - $date: { - $numberLong: string; - }; - }; - poster: string; - plot: string; - fullplot: string; - lastupdated: string; - type: string; - directors: Array; - imdb: { - rating: { - $numberDouble: string; - }; - votes: { - $numberInt: string; - }; - id: { - $numberInt: string; - }; - }; - cast: Array; - countries: Array; - genres: Array; - tomatoes: { - viewer: { - rating: { - $numberDouble: string; - }; - numReviews: { - $numberInt: string; - }; - }; - lastUpdated: { - $date: { - $numberLong: string; - }; - }; - }; - num_mflix_comments: { - $numberInt: string; - }; + year: bson.Int32 | number; + released: Date; }; const aggregation: schema.Pipeline = [ @@ -220,58 +81,13 @@ function test2() { */ function test3() { type movies = { - _id: { - $oid: string; - }; + _id: bson.ObjectId; title: string; - year: { - $numberInt: string; - }; - runtime: { - $numberInt: string; - }; - released: { - $date: { - $numberLong: string; - }; - }; - poster: string; - plot: string; - fullplot: string; - lastupdated: string; - type: string; - directors: Array; + year: bson.Int32 | number; + released: Date; + runtime: bson.Int32 | number; imdb: { - rating: { - $numberDouble: string; - }; - votes: { - $numberInt: string; - }; - id: { - $numberInt: string; - }; - }; - cast: Array; - countries: Array; - genres: Array; - tomatoes: { - viewer: { - rating: { - $numberDouble: string; - }; - numReviews: { - $numberInt: string; - }; - }; - lastUpdated: { - $date: { - $numberLong: string; - }; - }; - }; - num_mflix_comments: { - $numberInt: string; + rating: bson.Double | number; }; }; @@ -300,59 +116,9 @@ function test3() { */ function test4() { type movies = { - _id: { - $oid: string; - }; + _id: bson.ObjectId; title: string; - year: { - $numberInt: string; - }; - runtime: { - $numberInt: string; - }; - released: { - $date: { - $numberLong: string; - }; - }; - poster: string; - plot: string; - fullplot: string; - lastupdated: string; - type: string; - directors: Array; - imdb: { - rating: { - $numberDouble: string; - }; - votes: { - $numberInt: string; - }; - id: { - $numberInt: string; - }; - }; - cast: Array; - countries: Array; - genres: Array; - tomatoes: { - viewer: { - rating: { - $numberDouble: string; - }; - numReviews: { - $numberInt: string; - }; - }; - lastUpdated: { - $date: { - $numberLong: string; - }; - }; - }; - num_mflix_comments: { - $numberInt: string; - }; + customField: string; }; const aggregation: schema.Pipeline = [ diff --git a/packages/mql-typescript/tests/expression/setField.spec.ts b/packages/mql-typescript/tests/expression/setField.spec.ts index 36de0ca7..ea0b138f 100644 --- a/packages/mql-typescript/tests/expression/setField.spec.ts +++ b/packages/mql-typescript/tests/expression/setField.spec.ts @@ -82,8 +82,8 @@ function test3() { type inventory = { _id: number; item: string; - price: number; qty: number; + $price: number; }; const aggregation: schema.Pipeline = [ @@ -129,8 +129,8 @@ function test5() { type inventory = { _id: number; item: string; - price: number; qty: number; + $price: number; }; const aggregation: schema.Pipeline = [ diff --git a/packages/mql-typescript/tests/expression/setUnion.spec.ts b/packages/mql-typescript/tests/expression/setUnion.spec.ts index 682abfd9..d209d755 100644 --- a/packages/mql-typescript/tests/expression/setUnion.spec.ts +++ b/packages/mql-typescript/tests/expression/setUnion.spec.ts @@ -10,8 +10,9 @@ import * as bson from 'bson'; */ function test0() { type flowers = { + _id: number; flowerFieldA: Array; - flowerFieldB: Array; + flowerFieldB: Array>; }; const aggregation: schema.Pipeline = [ diff --git a/packages/mql-typescript/tests/expression/sigmoid.spec.ts b/packages/mql-typescript/tests/expression/sigmoid.spec.ts index ff1a36d0..91dab8cf 100644 --- a/packages/mql-typescript/tests/expression/sigmoid.spec.ts +++ b/packages/mql-typescript/tests/expression/sigmoid.spec.ts @@ -9,5 +9,12 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/sigmoid/#examples} */ function test0() { - // TODO: no schema found for sigmoid.Example: // TODO: No schema found in docs + type scores = { + _id: bson.ObjectId; + score: bson.Double | number; + }; + + const aggregation: schema.Pipeline = [ + { $set: { scaled: { $sigmoid: '$score' } } }, + ]; } diff --git a/packages/mql-typescript/tests/expression/subtype.spec.ts b/packages/mql-typescript/tests/expression/subtype.spec.ts index c732cfef..7b69cbe0 100644 --- a/packages/mql-typescript/tests/expression/subtype.spec.ts +++ b/packages/mql-typescript/tests/expression/subtype.spec.ts @@ -9,5 +9,11 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/subtype/} */ function test0() { - // TODO: no schema found for subtype.Example: // TODO: No schema found in docs + type data = { + myBinDataField: bson.Binary; + }; + + const aggregation: schema.Pipeline = [ + { $project: { result: { $subtype: '$myBinDataField' } } }, + ]; } diff --git a/packages/mql-typescript/tests/expression/sum.spec.ts b/packages/mql-typescript/tests/expression/sum.spec.ts index 3be6fa74..34aa8557 100644 --- a/packages/mql-typescript/tests/expression/sum.spec.ts +++ b/packages/mql-typescript/tests/expression/sum.spec.ts @@ -9,7 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/sum/#use-in--project-stage} */ function test0() { - type TestCollection = { + type students = { _id: number; quizzes: Array; labs: Array; @@ -17,7 +17,7 @@ function test0() { midterm: number; }; - const aggregation: schema.Pipeline = [ + const aggregation: schema.Pipeline = [ { $project: { quizTotal: { $sum: ['$quizzes'] }, diff --git a/packages/mql-typescript/tests/expression/toArray.spec.ts b/packages/mql-typescript/tests/expression/toArray.spec.ts index dd5dfab6..23927237 100644 --- a/packages/mql-typescript/tests/expression/toArray.spec.ts +++ b/packages/mql-typescript/tests/expression/toArray.spec.ts @@ -30,6 +30,7 @@ function test0() { */ function test1() { type t = { + _id: number; v: bson.Binary; }; diff --git a/packages/mql-typescript/tests/expression/top.spec.ts b/packages/mql-typescript/tests/expression/top.spec.ts index 4614cfd6..1d160192 100644 --- a/packages/mql-typescript/tests/expression/top.spec.ts +++ b/packages/mql-typescript/tests/expression/top.spec.ts @@ -9,5 +9,27 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/top-array-operator/#example} */ function test0() { - // TODO: no schema found for top.Example: // TODO: No schema found in docs + type games = { + results: Array<{ + playerId: string; + score: number; + }>; + }; + + const aggregation: schema.Pipeline = [ + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). + */ + { + $project: { + topScore: { + $top: { + sortBy: { score: -1 }, + output: ['$playerId', '$score'], + input: '$results', + }, + }, + }, + } as any, + ]; } diff --git a/packages/mql-typescript/tests/expression/topN.spec.ts b/packages/mql-typescript/tests/expression/topN.spec.ts index 1fb78cd4..3aa12423 100644 --- a/packages/mql-typescript/tests/expression/topN.spec.ts +++ b/packages/mql-typescript/tests/expression/topN.spec.ts @@ -9,5 +9,28 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/topN-array-operator/#example} */ function test0() { - // TODO: no schema found for topN.Example: // TODO: No schema found in docs + type games = { + results: Array<{ + playerId: string; + score: number; + }>; + }; + + const aggregation: schema.Pipeline = [ + /** + * This stage is unsupported by the static type system, so we're casting it to 'any' (this test accesses nested fields, which is not currently supported). + */ + { + $project: { + topScores: { + $topN: { + n: 3, + sortBy: { score: -1 }, + output: ['$playerId', '$score'], + input: '$results', + }, + }, + }, + } as any, + ]; } diff --git a/packages/mql-typescript/tests/expression/type.spec.ts b/packages/mql-typescript/tests/expression/type.spec.ts index a98f53ea..c9ff9196 100644 --- a/packages/mql-typescript/tests/expression/type.spec.ts +++ b/packages/mql-typescript/tests/expression/type.spec.ts @@ -9,7 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/type/#example} */ function test0() { - type coll = { + type TestCollection = { _id: number; a: | number @@ -20,11 +20,10 @@ function test0() { c: string; } | string - | bson.Long - | null; + | bson.Long; }; - const aggregation: schema.Pipeline = [ + const aggregation: schema.Pipeline = [ { $project: { a: { $type: '$a' } } }, ]; } diff --git a/packages/mql-typescript/tests/expression/unsetField.spec.ts b/packages/mql-typescript/tests/expression/unsetField.spec.ts index 34427e33..77a56bd9 100644 --- a/packages/mql-typescript/tests/expression/unsetField.spec.ts +++ b/packages/mql-typescript/tests/expression/unsetField.spec.ts @@ -30,7 +30,7 @@ function test1() { _id: number; item: string; qty: number; - 'price.usd': number; + $price: number; }; const aggregation: schema.Pipeline = [ diff --git a/packages/mql-typescript/tests/query/comment.spec.ts b/packages/mql-typescript/tests/query/comment.spec.ts index 02409ab6..0f34750b 100644 --- a/packages/mql-typescript/tests/query/comment.spec.ts +++ b/packages/mql-typescript/tests/query/comment.spec.ts @@ -9,5 +9,5 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/comment/#attach-a-comment-to-an-aggregation-expression} */ function test0() { - // TODO: no schema found for comment.Attach a Comment to an Aggregation Expression: // TODO: No schema found in docs + // TODO: no schema found for comment.Attach a Comment to an Aggregation Expression } diff --git a/packages/mql-typescript/tests/query/in.spec.ts b/packages/mql-typescript/tests/query/in.spec.ts index 608e0e86..1cdf5417 100644 --- a/packages/mql-typescript/tests/query/in.spec.ts +++ b/packages/mql-typescript/tests/query/in.spec.ts @@ -9,7 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/in/#use-the--in-operator-to-match-values} */ function test0() { - // TODO: no schema found for in.Use the $in Operator to Match Values in an Array: // TODO: No schema found in docs + // TODO: no schema found for in.Use the $in Operator to Match Values in an Array } /** @@ -17,5 +17,5 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/in/#use-the--in-operator-with-a-regular-expression} */ function test1() { - // TODO: no schema found for in.Use the $in Operator with a Regular Expression: // TODO: No schema found in docs + // TODO: no schema found for in.Use the $in Operator with a Regular Expression } diff --git a/packages/mql-typescript/tests/query/ne.spec.ts b/packages/mql-typescript/tests/query/ne.spec.ts index 755a939f..06577311 100644 --- a/packages/mql-typescript/tests/query/ne.spec.ts +++ b/packages/mql-typescript/tests/query/ne.spec.ts @@ -9,5 +9,5 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/ne/#match-document-fields} */ function test0() { - // TODO: no schema found for ne.Match Document Fields: // TODO: No schema found in docs + // TODO: no schema found for ne.Match Document Fields } diff --git a/packages/mql-typescript/tests/query/rand.spec.ts b/packages/mql-typescript/tests/query/rand.spec.ts index 56f9edf3..0698736e 100644 --- a/packages/mql-typescript/tests/query/rand.spec.ts +++ b/packages/mql-typescript/tests/query/rand.spec.ts @@ -9,5 +9,5 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/rand/#select-random-items-from-a-collection} */ function test0() { - // TODO: no schema found for rand.Select Random Items From a Collection: // TODO: No schema found in docs + // TODO: no schema found for rand.Select Random Items From a Collection } diff --git a/packages/mql-typescript/tests/query/text.spec.ts b/packages/mql-typescript/tests/query/text.spec.ts index b2e5cd28..6ba3ae50 100644 --- a/packages/mql-typescript/tests/query/text.spec.ts +++ b/packages/mql-typescript/tests/query/text.spec.ts @@ -9,7 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/text/#search-for-a-single-word} */ function test0() { - // TODO: no schema found for text.Search for a Single Word: // TODO: No schema found in docs + // TODO: no schema found for text.Search for a Single Word } /** @@ -17,7 +17,7 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/text/#search-for-a-single-word} */ function test1() { - // TODO: no schema found for text.Match Any of the Search Terms: // TODO: No schema found in docs + // TODO: no schema found for text.Match Any of the Search Terms } /** @@ -25,7 +25,7 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/text/#search-a-different-language} */ function test2() { - // TODO: no schema found for text.Search a Different Language: // TODO: No schema found in docs + // TODO: no schema found for text.Search a Different Language } /** @@ -33,7 +33,7 @@ function test2() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/text/#case-and-diacritic-insensitive-search} */ function test3() { - // TODO: no schema found for text.Case and Diacritic Insensitive Search: // TODO: No schema found in docs + // TODO: no schema found for text.Case and Diacritic Insensitive Search } /** @@ -41,7 +41,7 @@ function test3() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/text/#perform-case-sensitive-search} */ function test4() { - // TODO: no schema found for text.Perform Case Sensitive Search: // TODO: No schema found in docs + // TODO: no schema found for text.Perform Case Sensitive Search } /** @@ -49,7 +49,7 @@ function test4() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/text/#perform-case-sensitive-search} */ function test5() { - // TODO: no schema found for text.Diacritic Sensitive Search: // TODO: No schema found in docs + // TODO: no schema found for text.Diacritic Sensitive Search } /** @@ -57,5 +57,5 @@ function test5() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/query/text/#perform-case-sensitive-search} */ function test6() { - // TODO: no schema found for text.Text Search Score Examples: // TODO: No schema found in docs + // TODO: no schema found for text.Text Search Score Examples } diff --git a/packages/mql-typescript/tests/search/vectorSearch.spec.ts b/packages/mql-typescript/tests/search/vectorSearch.spec.ts index 7ea6f00a..2c0d8800 100644 --- a/packages/mql-typescript/tests/search/vectorSearch.spec.ts +++ b/packages/mql-typescript/tests/search/vectorSearch.spec.ts @@ -9,7 +9,27 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/vector-search/#basic-example} */ function test0() { - // TODO: no schema found for vectorSearch.ANN Basic: // TODO: No schema found in docs + type movies = { + plot_embedding: Array; + plot: string; + title: string; + }; + + const aggregation: schema.Pipeline = [ + { + $search: { + vectorSearch: { + path: 'plot_embedding', + queryVector: [-0.0016261312, -0.028070757, -0.011342932], + numCandidates: 150, + limit: 10, + }, + }, + }, + { + $project: { _id: 0, plot: 1, title: 1, score: { $meta: 'searchScore' } }, + }, + ]; } /** @@ -17,7 +37,35 @@ function test0() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/vector-search/#filter-example} */ function test1() { - // TODO: no schema found for vectorSearch.ANN Filter: // TODO: No schema found in docs + type movies = { + plot_embedding: Array; + year: bson.Int32 | number; + plot: string; + title: string; + }; + + const aggregation: schema.Pipeline = [ + { + $search: { + vectorSearch: { + path: 'plot_embedding', + queryVector: [0.02421053, -0.022372592, -0.006231137], + filter: { range: { path: 'year', lt: 1975 } }, + numCandidates: 150, + limit: 10, + }, + }, + }, + { + $project: { + _id: 0, + title: 1, + plot: 1, + year: 1, + score: { $meta: 'searchScore' }, + }, + }, + ]; } /** @@ -25,5 +73,25 @@ function test1() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-search/vector-search/#enn-example} */ function test2() { - // TODO: no schema found for vectorSearch.ENN: // TODO: No schema found in docs + type movies = { + plot_embedding: Array; + plot: string; + title: string; + }; + + const aggregation: schema.Pipeline = [ + { + $search: { + vectorSearch: { + path: 'plot_embedding', + queryVector: [-0.006954097, -0.009932499, -0.001311474], + exact: true, + limit: 10, + }, + }, + }, + { + $project: { _id: 0, plot: 1, title: 1, score: { $meta: 'searchScore' } }, + }, + ]; } diff --git a/packages/mql-typescript/tests/stage/addFields.spec.ts b/packages/mql-typescript/tests/stage/addFields.spec.ts index fef5b3c2..e3cc878c 100644 --- a/packages/mql-typescript/tests/stage/addFields.spec.ts +++ b/packages/mql-typescript/tests/stage/addFields.spec.ts @@ -9,7 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/addFields/#using-two--addfields-stages} */ function test0() { - // TODO: no schema found for addFields.Using Two $addFields Stages: // TODO: No schema found in docs + // TODO: no schema found for addFields.Using Two $addFields Stages } /** @@ -17,7 +17,7 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/addFields/#adding-fields-to-an-embedded-document} */ function test1() { - // TODO: no schema found for addFields.Adding Fields to an Embedded Document: // TODO: No schema found in docs + // TODO: no schema found for addFields.Adding Fields to an Embedded Document } /** @@ -25,7 +25,7 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/addFields/#overwriting-an-existing-field} */ function test2() { - // TODO: no schema found for addFields.Overwriting an existing field: // TODO: No schema found in docs + // TODO: no schema found for addFields.Overwriting an existing field } /** @@ -33,5 +33,5 @@ function test2() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/addFields/#add-element-to-an-array} */ function test3() { - // TODO: no schema found for addFields.Add Element to an Array: // TODO: No schema found in docs + // TODO: no schema found for addFields.Add Element to an Array } diff --git a/packages/mql-typescript/tests/stage/count.spec.ts b/packages/mql-typescript/tests/stage/count.spec.ts index 45c44cae..10488111 100644 --- a/packages/mql-typescript/tests/stage/count.spec.ts +++ b/packages/mql-typescript/tests/stage/count.spec.ts @@ -9,5 +9,5 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/count/#example} */ function test0() { - // TODO: no schema found for count.Example: // TODO: No schema found in docs + // TODO: no schema found for count.Example } diff --git a/packages/mql-typescript/tests/stage/facet.spec.ts b/packages/mql-typescript/tests/stage/facet.spec.ts index 4c21e897..af4a475e 100644 --- a/packages/mql-typescript/tests/stage/facet.spec.ts +++ b/packages/mql-typescript/tests/stage/facet.spec.ts @@ -9,5 +9,5 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/facet/#example} */ function test0() { - // TODO: no schema found for facet.Example: // TODO: No schema found in docs + // TODO: no schema found for facet.Example } diff --git a/packages/mql-typescript/tests/stage/indexStats.spec.ts b/packages/mql-typescript/tests/stage/indexStats.spec.ts index 5b78f315..469b08e4 100644 --- a/packages/mql-typescript/tests/stage/indexStats.spec.ts +++ b/packages/mql-typescript/tests/stage/indexStats.spec.ts @@ -9,5 +9,5 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/indexStats/#example} */ function test0() { - // TODO: no schema found for indexStats.Example: // TODO: No schema found in docs + // TODO: no schema found for indexStats.Example } diff --git a/packages/mql-typescript/tests/stage/match.spec.ts b/packages/mql-typescript/tests/stage/match.spec.ts index 8a042a41..29a079dc 100644 --- a/packages/mql-typescript/tests/stage/match.spec.ts +++ b/packages/mql-typescript/tests/stage/match.spec.ts @@ -9,7 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/match/#equality-match} */ function test0() { - // TODO: no schema found for match.Equality Match: // TODO: No schema found in docs + // TODO: no schema found for match.Equality Match } /** @@ -17,5 +17,5 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/match/#perform-a-count} */ function test1() { - // TODO: no schema found for match.Perform a Count: // TODO: No schema found in docs + // TODO: no schema found for match.Perform a Count } diff --git a/packages/mql-typescript/tests/stage/merge.spec.ts b/packages/mql-typescript/tests/stage/merge.spec.ts index 2f69ac13..31829993 100644 --- a/packages/mql-typescript/tests/stage/merge.spec.ts +++ b/packages/mql-typescript/tests/stage/merge.spec.ts @@ -9,7 +9,7 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/#on-demand-materialized-view--initial-creation} */ function test0() { - // TODO: no schema found for merge.On-Demand Materialized View Initial Creation: // TODO: No schema found in docs + // TODO: no schema found for merge.On-Demand Materialized View Initial Creation } /** @@ -17,7 +17,7 @@ function test0() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/#on-demand-materialized-view--update-replace-data} */ function test1() { - // TODO: no schema found for merge.On-Demand Materialized View Update Replace Data: // TODO: No schema found in docs + // TODO: no schema found for merge.On-Demand Materialized View Update Replace Data } /** @@ -25,7 +25,7 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/#only-insert-new-data} */ function test2() { - // TODO: no schema found for merge.Only Insert New Data: // TODO: No schema found in docs + // TODO: no schema found for merge.Only Insert New Data } /** @@ -33,7 +33,7 @@ function test2() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/#merge-results-from-multiple-collections} */ function test3() { - // TODO: no schema found for merge.Merge Results from Multiple Collections: // TODO: No schema found in docs + // TODO: no schema found for merge.Merge Results from Multiple Collections } /** @@ -41,7 +41,7 @@ function test3() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/#use-the-pipeline-to-customize-the-merge} */ function test4() { - // TODO: no schema found for merge.Use the Pipeline to Customize the Merge: // TODO: No schema found in docs + // TODO: no schema found for merge.Use the Pipeline to Customize the Merge } /** @@ -49,5 +49,5 @@ function test4() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/#use-variables-to-customize-the-merge} */ function test5() { - // TODO: no schema found for merge.Use Variables to Customize the Merge: // TODO: No schema found in docs + // TODO: no schema found for merge.Use Variables to Customize the Merge } diff --git a/packages/mql-typescript/tests/stage/out.spec.ts b/packages/mql-typescript/tests/stage/out.spec.ts index 114c9c1a..1c37201e 100644 --- a/packages/mql-typescript/tests/stage/out.spec.ts +++ b/packages/mql-typescript/tests/stage/out.spec.ts @@ -45,5 +45,23 @@ function test1() { * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/out/#output-to-a-time-series-collection} */ function test2() { - // TODO: no schema found for out.Output to a Time Series Collection: // TODO: No schema found in docs + type sensors = { + timestamp: Date; + sensorId: string; + temperature: number; + }; + + const aggregation: schema.Pipeline = [ + { + $out: { + db: 'reporting', + coll: 'sensorData', + timeseries: { + timeField: 'timestamp', + metaField: 'sensorId', + granularity: 'hours', + }, + }, + }, + ]; } diff --git a/packages/mql-typescript/tests/stage/rankFusion.spec.ts b/packages/mql-typescript/tests/stage/rankFusion.spec.ts index 972ab776..7b8b64ea 100644 --- a/packages/mql-typescript/tests/stage/rankFusion.spec.ts +++ b/packages/mql-typescript/tests/stage/rankFusion.spec.ts @@ -9,5 +9,5 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/rankFusion/#examples} */ function test0() { - // TODO: no schema found for rankFusion.Example: // TODO: No schema found in docs + // TODO: no schema found for rankFusion.Example } diff --git a/packages/mql-typescript/tests/stage/rerank.spec.ts b/packages/mql-typescript/tests/stage/rerank.spec.ts index 6a6ae7ba..84aad1c7 100644 --- a/packages/mql-typescript/tests/stage/rerank.spec.ts +++ b/packages/mql-typescript/tests/stage/rerank.spec.ts @@ -9,5 +9,5 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/vector-search/query/aggregation-stages/rerank/#examples} */ function test0() { - // TODO: no schema found for rerank.Example: // TODO: No schema found in docs + // TODO: no schema found for rerank.Example } diff --git a/packages/mql-typescript/tests/stage/sample.spec.ts b/packages/mql-typescript/tests/stage/sample.spec.ts index bfabfe62..f9f2c19b 100644 --- a/packages/mql-typescript/tests/stage/sample.spec.ts +++ b/packages/mql-typescript/tests/stage/sample.spec.ts @@ -9,5 +9,5 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/sample/#example} */ function test0() { - // TODO: no schema found for sample.Example: // TODO: No schema found in docs + // TODO: no schema found for sample.Example } diff --git a/packages/mql-typescript/tests/stage/score.spec.ts b/packages/mql-typescript/tests/stage/score.spec.ts index a7e89b4c..cf64c514 100644 --- a/packages/mql-typescript/tests/stage/score.spec.ts +++ b/packages/mql-typescript/tests/stage/score.spec.ts @@ -9,5 +9,11 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/score/} */ function test0() { - // TODO: no schema found for score.Example: // TODO: No schema found in docs + type movies = { + plot_embedding: Array; + }; + + const aggregation: schema.Pipeline = [ + { $score: { score: { $meta: 'vectorSearchScore' } } }, + ]; } diff --git a/packages/mql-typescript/tests/stage/scoreFusion.spec.ts b/packages/mql-typescript/tests/stage/scoreFusion.spec.ts index 3c2c99fc..e25c9951 100644 --- a/packages/mql-typescript/tests/stage/scoreFusion.spec.ts +++ b/packages/mql-typescript/tests/stage/scoreFusion.spec.ts @@ -9,5 +9,5 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/scoreFusion/#examples} */ function test0() { - // TODO: no schema found for scoreFusion.Example: // TODO: No schema found in docs + // TODO: no schema found for scoreFusion.Example } diff --git a/packages/mql-typescript/tests/stage/sortByCount.spec.ts b/packages/mql-typescript/tests/stage/sortByCount.spec.ts index 564d227e..612c91e3 100644 --- a/packages/mql-typescript/tests/stage/sortByCount.spec.ts +++ b/packages/mql-typescript/tests/stage/sortByCount.spec.ts @@ -9,5 +9,5 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/manual/reference/operator/aggregation/sortByCount/#example} */ function test0() { - // TODO: no schema found for sortByCount.Example: // TODO: No schema found in docs + // TODO: no schema found for sortByCount.Example } diff --git a/packages/mql-typescript/tests/stage/vectorSearch.spec.ts b/packages/mql-typescript/tests/stage/vectorSearch.spec.ts index 0ffb3f50..c3119a7d 100644 --- a/packages/mql-typescript/tests/stage/vectorSearch.spec.ts +++ b/packages/mql-typescript/tests/stage/vectorSearch.spec.ts @@ -9,7 +9,31 @@ import * as bson from 'bson'; * @see {@link https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-stage/#examples} */ function test0() { - // TODO: no schema found for vectorSearch.ANN Basic: // TODO: No schema found in docs + type movies = { + plot_embedding: Array; + plot: string; + title: string; + }; + + const aggregation: schema.Pipeline = [ + { + $vectorSearch: { + index: 'vector_index', + path: 'plot_embedding', + queryVector: [-0.0016261312, -0.028070757, -0.011342932], + numCandidates: 150, + limit: 10, + }, + }, + { + $project: { + _id: 0, + plot: 1, + title: 1, + score: { $meta: 'vectorSearchScore' }, + }, + }, + ]; } /** @@ -18,59 +42,10 @@ function test0() { */ function test1() { type movies = { - _id: { - $oid: string; - }; - title: string; - year: { - $numberInt: string; - }; - runtime: { - $numberInt: string; - }; - released: { - $date: { - $numberLong: string; - }; - }; - poster: string; + plot_embedding: Array; + year: bson.Int32 | number; plot: string; - fullplot: string; - lastupdated: string; - type: string; - directors: Array; - imdb: { - rating: { - $numberDouble: string; - }; - votes: { - $numberInt: string; - }; - id: { - $numberInt: string; - }; - }; - cast: Array; - countries: Array; - genres: Array; - tomatoes: { - viewer: { - rating: { - $numberDouble: string; - }; - numReviews: { - $numberInt: string; - }; - }; - lastUpdated: { - $date: { - $numberLong: string; - }; - }; - }; - num_mflix_comments: { - $numberInt: string; - }; + title: string; }; const aggregation: schema.Pipeline = [ @@ -101,7 +76,31 @@ function test1() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-stage/#examples} */ function test2() { - // TODO: no schema found for vectorSearch.ENN: // TODO: No schema found in docs + type movies = { + plot_embedding: Array; + plot: string; + title: string; + }; + + const aggregation: schema.Pipeline = [ + { + $vectorSearch: { + index: 'vector_index', + path: 'plot_embedding', + queryVector: [-0.006954097, -0.009932499, -0.001311474], + exact: true, + limit: 10, + }, + }, + { + $project: { + _id: 0, + plot: 1, + title: 1, + score: { $meta: 'vectorSearchScore' }, + }, + }, + ]; } /** @@ -109,7 +108,44 @@ function test2() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-stage/#examples} */ function test3() { - // TODO: no schema found for vectorSearch.Stored Source: // TODO: No schema found in docs + type movies = { + plot_embedding: Array; + year: bson.Int32 | number; + genres: Array; + plot: string; + title: string; + }; + + const aggregation: schema.Pipeline = [ + { + $vectorSearch: { + index: 'vector_index', + path: 'plot_embedding', + queryVector: [ + -0.03994801267981529, -0.016522614285349846, -0.008775344118475914, + ], + filter: { + $and: [ + { year: { $gt: 1970 } }, + { year: { $lt: 2020 } }, + { genres: { $in: ['Action', 'Drama', 'Comedy'] } }, + ], + }, + limit: 10, + numCandidates: 1000, + returnStoredSource: true, + }, + }, + { + $project: { + _id: 0, + plot: 1, + title: 1, + genres: 1, + score: { $meta: 'vectorSearchScore' }, + }, + }, + ]; } /** @@ -117,5 +153,5 @@ function test3() { * @see {@link https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-stage/#examples} */ function test4() { - // TODO: no schema found for vectorSearch.Nested field: // TODO: No schema found in docs + // TODO: no schema found for vectorSearch.Nested field } From ea7820cf9d75c52e5b0859e748be5d11396add46 Mon Sep 17 00:00:00 2001 From: Ivan Medina Date: Thu, 2 Jul 2026 10:11:32 -0300 Subject: [PATCH 7/8] chore(mql-typescript): update mql-specifications submodule to merged main PR #53 (Add missing test schemas) has been merged into mql-specifications main. Update the submodule pointer from the pre-merge branch commit to the merged main commit (060a574). --- packages/mql-typescript/mql-specifications | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/mql-typescript/mql-specifications b/packages/mql-typescript/mql-specifications index 1fe529bf..060a5748 160000 --- a/packages/mql-typescript/mql-specifications +++ b/packages/mql-typescript/mql-specifications @@ -1 +1 @@ -Subproject commit 1fe529bf7830ee717392d408646d39b5934a319a +Subproject commit 060a5748705507b9765055a762bd7c4cb14d793f From 810fb201c1700f07a0273f301da08912f5930cfd Mon Sep 17 00:00:00 2001 From: Ivan Medina Date: Fri, 3 Jul 2026 10:48:27 -0300 Subject: [PATCH 8/8] 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 to include new 8.3 argument definitions 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 currently points to an unmerged branch (MONGOSH-3244-array-index-args). Will be updated to the merge commit once mongodb/mql-specifications#54 is merged. --- 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: