diff --git a/generator/config/.yamlfix.toml b/generator/config/.yamlfix.toml new file mode 100644 index 000000000..e4b1e02bb --- /dev/null +++ b/generator/config/.yamlfix.toml @@ -0,0 +1,8 @@ +allow_duplicate_keys = false +comments_min_spaces_from_content = 1 +sequence_style = "block_style" +indent_mapping = 4 +indent_offset = 4 +indent_sequence = 6 +none_representation = "~" +explicit_start = false diff --git a/generator/config/accumulator/accumulator.yaml b/generator/config/accumulator/accumulator.yaml index 9cfdb6b53..8ea0ddad1 100644 --- a/generator/config/accumulator/accumulator.yaml +++ b/generator/config/accumulator/accumulator.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $accumulator -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/accumulator/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/accumulator/ type: - accumulator encode: object @@ -8,125 +8,142 @@ description: | Defines a custom accumulator function. New in MongoDB 4.4. arguments: - - - name: init - type: - - javascript - description: | - Function used to initialize the state. The init function receives its arguments from the initArgs array expression. You can specify the function definition as either BSON type Code or String. - - - name: initArgs - type: - - resolvesToArray - optional: true - description: | - Arguments passed to the init function. - - - name: accumulate - type: - - javascript - description: | - Function used to accumulate documents. The accumulate function receives its arguments from the current state and accumulateArgs array expression. The result of the accumulate function becomes the new state. You can specify the function definition as either BSON type Code or String. - - - name: accumulateArgs - type: - - resolvesToArray - description: | - Arguments passed to the accumulate function. You can use accumulateArgs to specify what field value(s) to pass to the accumulate function. - - - name: merge - type: - - javascript - description: | - Function used to merge two internal states. merge must be either a String or Code BSON type. merge returns the combined result of the two merged states. For information on when the merge function is called, see Merge Two States with $merge. - - - name: finalize - type: - - javascript - optional: true - description: | - Function used to update the result of the accumulation. - - - name: lang - type: - - string - description: | - The language used in the $accumulator code. - + - name: init + type: + - javascript + description: | + Function used to initialize the state. The init function receives its arguments from the initArgs array expression. You can specify the function definition as either BSON type Code or String. + - name: initArgs + type: + - resolvesToArray + optional: true + description: | + Arguments passed to the init function. + - name: accumulate + type: + - javascript + description: | + Function used to accumulate documents. The accumulate function receives its arguments from the current state and accumulateArgs array expression. The result of the accumulate function becomes the new state. You can specify the function definition as either BSON type Code or String. + - name: accumulateArgs + type: + - resolvesToArray + description: | + Arguments passed to the accumulate function. You can use accumulateArgs to specify what field value(s) to pass to the accumulate function. + - name: merge + type: + - javascript + description: | + Function used to merge two internal states. merge must be either a String or Code BSON type. merge returns the combined result of the two merged states. For information on when the merge function is called, see Merge Two States with $merge. + - name: finalize + type: + - javascript + optional: true + description: | + Function used to update the result of the accumulation. + - name: lang + type: + - string + description: | + The language used in the $accumulator code. tests: - - - name: 'Use $accumulator to Implement the $avg Operator' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/accumulator/#use--accumulator-to-implement-the--avg-operator' - pipeline: - - - $group: - _id: '$author' - avgCopies: - $accumulator: - init: - $code: |- - function() { - return { count: 0, sum: 0 } + - name: Use $accumulator to Implement the $avg Operator + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/accumulator/#use--accumulator-to-implement-the--avg-operator + pipeline: + - $group: + _id: $author + avgCopies: + $accumulator: + init: + $code: |- + function() { + return { count: 0, sum: 0 } + } + accumulate: + $code: |- + function(state, numCopies) { + return { count: state.count + 1, sum: state.sum + numCopies } + } + accumulateArgs: + - $copies + merge: + $code: |- + function(state1, state2) { + return { + count: state1.count + state2.count, + sum: state1.sum + state2.sum } - accumulate: - $code: |- - function(state, numCopies) { - return { count: state.count + 1, sum: state.sum + numCopies } + } + finalize: + $code: |- + function(state) { + return (state.sum / state.count) + } + lang: js + schema: + books: + _id: + types: + - bsonType: Number + title: + types: + - bsonType: String + author: + types: + - bsonType: String + copies: + types: + - bsonType: Number + - name: Use initArgs to Vary the Initial State by Group + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/accumulator/#use-initargs-to-vary-the-initial-state-by-group + pipeline: + - $group: + _id: + city: $city + restaurants: + $accumulator: + init: + $code: |- + function(city, userProfileCity) { + return { max: city === userProfileCity ? 3 : 1, restaurants: [] } + } + initArgs: + - $city + - Bettles + accumulate: + $code: |- + function(state, restaurantName) { + if (state.restaurants.length < state.max) { + state.restaurants.push(restaurantName); } - accumulateArgs: [ "$copies" ] - merge: - $code: |- - function(state1, state2) { - return { - count: state1.count + state2.count, - sum: state1.sum + state2.sum - } + return state; + } + accumulateArgs: + - $name + merge: + $code: |- + function(state1, state2) { + return { + max: state1.max, + restaurants: state1.restaurants.concat(state2.restaurants).slice(0, state1.max) } - finalize: - $code: |- - function(state) { - return (state.sum / state.count) - } - lang: 'js' - - - - name: 'Use initArgs to Vary the Initial State by Group' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/accumulator/#use-initargs-to-vary-the-initial-state-by-group' - pipeline: - - - $group: - _id: - city: '$city' - restaurants: - $accumulator: - init: - $code: |- - function(city, userProfileCity) { - return { max: city === userProfileCity ? 3 : 1, restaurants: [] } - } - initArgs: - - '$city' - - 'Bettles' - accumulate: - $code: |- - function(state, restaurantName) { - if (state.restaurants.length < state.max) { - state.restaurants.push(restaurantName); - } - return state; - } - accumulateArgs: ['$name'] - merge: - $code: |- - function(state1, state2) { - return { - max: state1.max, - restaurants: state1.restaurants.concat(state2.restaurants).slice(0, state1.max) - } - } - finalize: - $code: |- - function(state) { - return state.restaurants - } - lang: 'js' + } + finalize: + $code: |- + function(state) { + return state.restaurants + } + lang: js + schema: + restaurants: + _id: + types: + - bsonType: Number + name: + types: + - bsonType: String + city: + types: + - bsonType: String + cuisine: + types: + - bsonType: String diff --git a/generator/config/accumulator/addToSet.yaml b/generator/config/accumulator/addToSet.yaml index 9566899eb..c230972e6 100644 --- a/generator/config/accumulator/addToSet.yaml +++ b/generator/config/accumulator/addToSet.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $addToSet -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/addToSet/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/addToSet/ type: - accumulator - window @@ -9,39 +9,71 @@ description: | 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. arguments: - - - name: expression - type: - - expression - + - name: expression + type: + - expression tests: - - - name: 'Use in $group Stage' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/addToSet/#use-in--group-stage' - pipeline: - - $group: + - name: Use in $group Stage + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/addToSet/#use-in--group-stage + pipeline: + - $group: _id: day: $dayOfYear: - date: '$date' + date: $date year: $year: - date: '$date' + date: $date itemsSold: - $addToSet: '$item' - - - name: 'Use in $setWindowFields Stage' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/addToSet/#use-in--setwindowfields-stage' - pipeline: - - - $setWindowFields: - partitionBy: '$state' - sortBy: - orderDate: 1 - output: - cakeTypesForState: - $addToSet: '$type' - window: - documents: - - 'unbounded' - - 'current' + $addToSet: $item + schema: + sales: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + price: + types: + - bsonType: Number + quantity: + types: + - bsonType: Number + date: + types: + - bsonType: Date + - name: Use in $setWindowFields Stage + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/addToSet/#use-in--setwindowfields-stage + pipeline: + - $setWindowFields: + partitionBy: $state + sortBy: + orderDate: 1 + output: + cakeTypesForState: + $addToSet: $type + window: + documents: + - unbounded + - current + schema: + cakeSales: + _id: + types: + - bsonType: Number + type: + types: + - bsonType: String + orderDate: + types: + - bsonType: Date + state: + types: + - bsonType: String + price: + types: + - bsonType: Number + quantity: + types: + - bsonType: Number diff --git a/generator/config/accumulator/avg.yaml b/generator/config/accumulator/avg.yaml index 3777bbf98..ed6b2ef11 100644 --- a/generator/config/accumulator/avg.yaml +++ b/generator/config/accumulator/avg.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $avg -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/avg/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/avg/ type: - accumulator - window @@ -9,37 +9,70 @@ description: | Returns an average of numerical values. Ignores non-numeric values. Changed in MongoDB 5.0: Available in the $setWindowFields stage. arguments: - - - name: expression - type: - - resolvesToNumber + - name: expression + type: + - resolvesToNumber tests: - - - name: 'Use in $group Stage' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/avg/#use-in--group-stage' - pipeline: - - $group: - _id: '$item' - avgAmount: - $avg: - $multiply: - - '$price' - - '$quantity' - avgQuantity: - $avg: '$quantity' - - - name: 'Use in $setWindowFields Stage' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/avg/#use-in--setwindowfields-stage' - pipeline: - - - $setWindowFields: - partitionBy: '$state' - sortBy: - orderDate: 1 - output: - averageQuantityForState: - $avg: '$quantity' - window: - documents: - - 'unbounded' - - 'current' + - name: Use in $group Stage + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/avg/#use-in--group-stage + pipeline: + - $group: + _id: $item + avgAmount: + $avg: + $multiply: + - $price + - $quantity + avgQuantity: + $avg: $quantity + schema: + sales: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + price: + types: + - bsonType: Number + quantity: + types: + - bsonType: Number + date: + types: + - bsonType: Date + - name: Use in $setWindowFields Stage + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/avg/#use-in--setwindowfields-stage + pipeline: + - $setWindowFields: + partitionBy: $state + sortBy: + orderDate: 1 + output: + averageQuantityForState: + $avg: $quantity + window: + documents: + - unbounded + - current + schema: + cakeSales: + _id: + types: + - bsonType: Number + type: + types: + - bsonType: String + orderDate: + types: + - bsonType: Date + state: + types: + - bsonType: String + price: + types: + - bsonType: Number + quantity: + types: + - bsonType: Number diff --git a/generator/config/accumulator/bottom.yaml b/generator/config/accumulator/bottom.yaml index 1e363d193..994ffd83b 100644 --- a/generator/config/accumulator/bottom.yaml +++ b/generator/config/accumulator/bottom.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $bottom -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/bottom/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/bottom/ type: - accumulator - window @@ -9,47 +9,62 @@ description: | 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. arguments: - - - name: sortBy - type: - - sortBy - description: | - Specifies the order of results, with syntax similar to $sort. - - - name: output - type: - - expression - description: | - Represents the output for each element in the group and can be any expression. + - name: sortBy + type: + - sortBy + description: | + Specifies the order of results, with syntax similar to $sort. + - name: output + type: + - expression + description: | + Represents the output for each element in the group and can be any expression. tests: - - - name: 'Find the Bottom Score' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/bottom/#find-the-bottom-score' - pipeline: - - - $match: - gameId: 'G1' - - - $group: - _id: '$gameId' - playerId: - $bottom: - output: - - '$playerId' - - '$score' - sortBy: - score: -1 - - - name: 'Finding the Bottom Score Across Multiple Games' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/bottom/#finding-the-bottom-score-across-multiple-games' - pipeline: - - - $group: - _id: '$gameId' - playerId: - $bottom: - output: - - '$playerId' - - '$score' - sortBy: - score: -1 + - name: Find the Bottom Score + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/bottom/#find-the-bottom-score + pipeline: + - $match: + gameId: G1 + - $group: + _id: $gameId + playerId: + $bottom: + output: + - $playerId + - $score + sortBy: + score: -1 + schema: + gamescores: + playerId: + types: + - bsonType: String + gameId: + types: + - bsonType: String + score: + types: + - bsonType: Number + - name: Finding the Bottom Score Across Multiple Games + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/bottom/#finding-the-bottom-score-across-multiple-games + pipeline: + - $group: + _id: $gameId + playerId: + $bottom: + output: + - $playerId + - $score + sortBy: + score: -1 + schema: + gamescores: + playerId: + types: + - bsonType: String + gameId: + types: + - bsonType: String + score: + types: + - bsonType: Number diff --git a/generator/config/accumulator/bottomN.yaml b/generator/config/accumulator/bottomN.yaml index 355d8e09a..9ad82267a 100644 --- a/generator/config/accumulator/bottomN.yaml +++ b/generator/config/accumulator/bottomN.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $bottomN -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/bottomN/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/bottomN/ type: - accumulator - window @@ -10,76 +10,99 @@ description: | New in MongoDB 5.2. Available in the $group and $setWindowFields stages. arguments: - - - name: 'n' - type: - - resolvesToInt - description: | - Limits the number of results per group and has to be a positive integral expression that is either a constant or depends on the _id value for $group. - - - name: sortBy - type: - - sortBy - description: | - Specifies the order of results, with syntax similar to $sort. - - - name: output - type: - - expression - description: | - Represents the output for each element in the group and can be any expression. + - name: n + type: + - resolvesToInt + description: | + Limits the number of results per group and has to be a positive integral expression that is either a constant or depends on the _id value for $group. + - name: sortBy + type: + - sortBy + description: | + Specifies the order of results, with syntax similar to $sort. + - name: output + type: + - expression + description: | + Represents the output for each element in the group and can be any expression. tests: - - - name: 'Find the Three Lowest Scores' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/bottomN/#find-the-three-lowest-scores' - pipeline: - - - $match: - gameId: 'G1' - - - $group: - _id: '$gameId' - playerId: - $bottomN: - output: - - '$playerId' - - '$score' - sortBy: - score: -1 - n: 3 - - - name: 'Finding the Three Lowest Score Documents Across Multiple Games' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/bottomN/#finding-the-three-lowest-score-documents-across-multiple-games' - pipeline: - - - $group: - _id: '$gameId' - playerId: - $bottomN: - output: - - '$playerId' - - '$score' - sortBy: - score: -1 - n: 3 - - - name: 'Computing n Based on the Group Key for $group' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/bottomN/#computing-n-based-on-the-group-key-for--group' - pipeline: - - - $group: - _id: - gameId: '$gameId' - gamescores: - $bottomN: - output: '$score' - n: - $cond: - if: - $eq: - - '$gameId' - - 'G2' - then: 1 - else: 3 - sortBy: - score: -1 + - name: Find the Three Lowest Scores + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/bottomN/#find-the-three-lowest-scores + pipeline: + - $match: + gameId: G1 + - $group: + _id: $gameId + playerId: + $bottomN: + output: + - $playerId + - $score + sortBy: + score: -1 + n: 3 + schema: + gamescores: + playerId: + types: + - bsonType: String + gameId: + types: + - bsonType: String + score: + types: + - bsonType: Number + - name: Finding the Three Lowest Score Documents Across Multiple Games + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/bottomN/#finding-the-three-lowest-score-documents-across-multiple-games + pipeline: + - $group: + _id: $gameId + playerId: + $bottomN: + output: + - $playerId + - $score + sortBy: + score: -1 + n: 3 + schema: + gamescores: + playerId: + types: + - bsonType: String + gameId: + types: + - bsonType: String + score: + types: + - bsonType: Number + - name: Computing n Based on the Group Key for $group + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/bottomN/#computing-n-based-on-the-group-key-for--group + pipeline: + - $group: + _id: + gameId: $gameId + gamescores: + $bottomN: + output: $score + n: + $cond: + if: + $eq: + - $gameId + - G2 + then: 1 + else: 3 + sortBy: + score: -1 + schema: + gamescores: + playerId: + types: + - bsonType: String + gameId: + types: + - bsonType: String + score: + types: + - bsonType: Number diff --git a/generator/config/accumulator/count.yaml b/generator/config/accumulator/count.yaml index d9819056d..5e4f137a1 100644 --- a/generator/config/accumulator/count.yaml +++ b/generator/config/accumulator/count.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $count -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/count-accumulator/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/count-accumulator/ type: - accumulator - window @@ -10,28 +10,64 @@ description: | Distinct from the $count pipeline stage. New in MongoDB 5.0. tests: - - - name: 'Use in $group Stage' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/count-accumulator/#use-in--group-stage' - pipeline: - - - $group: - _id: '$state' + - name: Use in $group Stage + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/count-accumulator/#use-in--group-stage + pipeline: + - $group: + _id: $state + countNumberOfDocumentsForState: + $count: {} + schema: + cakeSales: + _id: + types: + - bsonType: Number + type: + types: + - bsonType: String + orderDate: + types: + - bsonType: Date + state: + types: + - bsonType: String + price: + types: + - bsonType: Number + quantity: + types: + - bsonType: Number + - name: Use in $setWindowFields Stage + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/count-accumulator/#use-in--setwindowfields-stage + pipeline: + - $setWindowFields: + partitionBy: $state + sortBy: + orderDate: 1 + output: countNumberOfDocumentsForState: $count: {} - - - name: 'Use in $setWindowFields Stage' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/count-accumulator/#use-in--setwindowfields-stage' - pipeline: - - - $setWindowFields: - partitionBy: '$state' - sortBy: - orderDate: 1 - output: - countNumberOfDocumentsForState: - $count: {} - window: - documents: - - 'unbounded' - - 'current' + window: + documents: + - unbounded + - current + schema: + cakeSales: + _id: + types: + - bsonType: Number + type: + types: + - bsonType: String + orderDate: + types: + - bsonType: Date + state: + types: + - bsonType: String + price: + types: + - bsonType: Number + quantity: + types: + - bsonType: Number diff --git a/generator/config/accumulator/covariancePop.yaml b/generator/config/accumulator/covariancePop.yaml index b43a24022..bbe350042 100644 --- a/generator/config/accumulator/covariancePop.yaml +++ b/generator/config/accumulator/covariancePop.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $covariancePop -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/covariancePop/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/covariancePop/ type: - window encode: array @@ -8,34 +8,47 @@ description: | Returns the population covariance of two numeric expressions. New in MongoDB 5.0. arguments: - - - name: expression1 - type: - - resolvesToNumber - - - name: expression2 - type: - - resolvesToNumber + - name: expression1 + type: + - resolvesToNumber + - name: expression2 + type: + - resolvesToNumber tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/covariancePop/#example' - pipeline: - - - $setWindowFields: - partitionBy: '$state' - sortBy: - orderDate: 1 - output: - covariancePopForState: - $covariancePop: - - - # Example uses the short form, the builder always generates the verbose form - # $year: '$orderDate' - $year: - date: '$orderDate' - - '$quantity' - window: - documents: - - 'unbounded' - - 'current' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/covariancePop/#example + pipeline: + - $setWindowFields: + partitionBy: $state + sortBy: + orderDate: 1 + output: + covariancePopForState: + $covariancePop: + - $year: + date: $orderDate + - $quantity + window: + documents: + - unbounded + - current + schema: + cakeSales: + _id: + types: + - bsonType: Number + type: + types: + - bsonType: String + orderDate: + types: + - bsonType: Date + state: + types: + - bsonType: String + price: + types: + - bsonType: Number + quantity: + types: + - bsonType: Number diff --git a/generator/config/accumulator/covarianceSamp.yaml b/generator/config/accumulator/covarianceSamp.yaml index b6cc529af..c08b95ce3 100644 --- a/generator/config/accumulator/covarianceSamp.yaml +++ b/generator/config/accumulator/covarianceSamp.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $covarianceSamp -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/covarianceSamp/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/covarianceSamp/ type: - window encode: array @@ -8,34 +8,47 @@ description: | Returns the sample covariance of two numeric expressions. New in MongoDB 5.0. arguments: - - - name: expression1 - type: - - resolvesToNumber - - - name: expression2 - type: - - resolvesToNumber + - name: expression1 + type: + - resolvesToNumber + - name: expression2 + type: + - resolvesToNumber tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/covarianceSamp/#example' - pipeline: - - - $setWindowFields: - partitionBy: '$state' - sortBy: - orderDate: 1 - output: - covarianceSampForState: - $covarianceSamp: - - - # Example uses the short form, the builder always generates the verbose form - # $year: '$orderDate' - $year: - date: '$orderDate' - - '$quantity' - window: - documents: - - 'unbounded' - - 'current' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/covarianceSamp/#example + pipeline: + - $setWindowFields: + partitionBy: $state + sortBy: + orderDate: 1 + output: + covarianceSampForState: + $covarianceSamp: + - $year: + date: $orderDate + - $quantity + window: + documents: + - unbounded + - current + schema: + cakeSales: + _id: + types: + - bsonType: Number + type: + types: + - bsonType: String + orderDate: + types: + - bsonType: Date + state: + types: + - bsonType: String + price: + types: + - bsonType: Number + quantity: + types: + - bsonType: Number diff --git a/generator/config/accumulator/denseRank.yaml b/generator/config/accumulator/denseRank.yaml index 0c50dd901..ad4fdf953 100644 --- a/generator/config/accumulator/denseRank.yaml +++ b/generator/config/accumulator/denseRank.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $denseRank -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/denseRank/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/denseRank/ type: - window encode: object @@ -8,27 +8,63 @@ description: | 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. tests: - - - name: 'Dense Rank Partitions by an Integer Field' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/denseRank/#dense-rank-partitions-by-an-integer-field' - pipeline: - - - $setWindowFields: - partitionBy: '$state' - sortBy: - quantity: -1 - output: - denseRankQuantityForState: - $denseRank: {} - - - name: 'Dense Rank Partitions by a Date Field' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/denseRank/#dense-rank-partitions-by-a-date-field' - pipeline: - - - $setWindowFields: - partitionBy: '$state' - sortBy: - orderDate: 1 - output: - denseRankOrderDateForState: - $denseRank: {} + - name: Dense Rank Partitions by an Integer Field + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/denseRank/#dense-rank-partitions-by-an-integer-field + pipeline: + - $setWindowFields: + partitionBy: $state + sortBy: + quantity: -1 + output: + denseRankQuantityForState: + $denseRank: {} + schema: + cakeSales: + _id: + types: + - bsonType: Number + type: + types: + - bsonType: String + orderDate: + types: + - bsonType: Date + state: + types: + - bsonType: String + price: + types: + - bsonType: Number + quantity: + types: + - bsonType: Number + - name: Dense Rank Partitions by a Date Field + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/denseRank/#dense-rank-partitions-by-a-date-field + pipeline: + - $setWindowFields: + partitionBy: $state + sortBy: + orderDate: 1 + output: + denseRankOrderDateForState: + $denseRank: {} + schema: + cakeSales: + _id: + types: + - bsonType: Number + type: + types: + - bsonType: String + orderDate: + types: + - bsonType: Date + state: + types: + - bsonType: String + price: + types: + - bsonType: Number + quantity: + types: + - bsonType: Number diff --git a/generator/config/accumulator/derivative.yaml b/generator/config/accumulator/derivative.yaml index 5745e9380..2e07cd0cf 100644 --- a/generator/config/accumulator/derivative.yaml +++ b/generator/config/accumulator/derivative.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $derivative -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/derivative/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/derivative/ type: - window encode: object @@ -8,40 +8,46 @@ description: | Returns the average rate of change within the specified window. New in MongoDB 5.0. arguments: - - - name: input - type: - - resolvesToNumber - - resolvesToDate - - - name: unit - type: - - timeUnit - optional: true - description: | - A string that specifies the time unit. Use one of these strings: "week", "day","hour", "minute", "second", "millisecond". - If the sortBy field is not a date, you must omit a unit. If you specify a unit, you must specify a date in the sortBy field. + - name: input + type: + - resolvesToNumber + - resolvesToDate + - name: unit + type: + - timeUnit + optional: true + description: | + A string that specifies the time unit. Use one of these strings: "week", "day","hour", "minute", "second", "millisecond". + If the sortBy field is not a date, you must omit a unit. If you specify a unit, you must specify a date in the sortBy field. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/derivative/#example' - pipeline: - - - $setWindowFields: - partitionBy: '$truckID' - sortBy: - timeStamp: 1 - output: - truckAverageSpeed: - $derivative: - input: '$miles' - unit: 'hour' - window: - range: - - -30 - - 0 - unit: 'second' - - - $match: + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/derivative/#example + pipeline: + - $setWindowFields: + partitionBy: $truckID + sortBy: + timeStamp: 1 + output: truckAverageSpeed: - $gt: 50 + $derivative: + input: $miles + unit: hour + window: + range: + - -30 + - 0 + unit: second + - $match: + truckAverageSpeed: + $gt: 50 + schema: + deliveryFleet: + truckID: + types: + - bsonType: String + timeStamp: + types: + - bsonType: Date + miles: + types: + - bsonType: Number diff --git a/generator/config/accumulator/documentNumber.yaml b/generator/config/accumulator/documentNumber.yaml index b810ccd44..d185b2ecf 100644 --- a/generator/config/accumulator/documentNumber.yaml +++ b/generator/config/accumulator/documentNumber.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $documentNumber -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/documentNumber/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/documentNumber/ type: - window encode: object @@ -8,15 +8,33 @@ description: | 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. tests: - - - name: 'Document Number for Each State' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/documentNumber/#document-number-for-each-state' - pipeline: - - - $setWindowFields: - partitionBy: '$state' - sortBy: - quantity: -1 - output: - documentNumberForState: - $documentNumber: {} + - name: Document Number for Each State + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/documentNumber/#document-number-for-each-state + pipeline: + - $setWindowFields: + partitionBy: $state + sortBy: + quantity: -1 + output: + documentNumberForState: + $documentNumber: {} + schema: + cakeSales: + _id: + types: + - bsonType: Number + type: + types: + - bsonType: String + orderDate: + types: + - bsonType: Date + state: + types: + - bsonType: String + price: + types: + - bsonType: Number + quantity: + types: + - bsonType: Number diff --git a/generator/config/accumulator/expMovingAvg.yaml b/generator/config/accumulator/expMovingAvg.yaml index 3009dd115..a4b43eab2 100644 --- a/generator/config/accumulator/expMovingAvg.yaml +++ b/generator/config/accumulator/expMovingAvg.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $expMovingAvg -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/expMovingAvg/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/expMovingAvg/ type: - window encode: object @@ -8,53 +8,68 @@ description: | Returns the exponential moving average for the numeric expression. New in MongoDB 5.0. arguments: - - - name: input - type: - - resolvesToNumber - - - name: 'N' - type: - - int - optional: true - description: | - An integer that specifies the number of historical documents that have a significant mathematical weight in the exponential moving average calculation, with the most recent documents contributing the most weight. - You must specify either N or alpha. You cannot specify both. - The N value is used in this formula to calculate the current result based on the expression value from the current document being read and the previous result of the calculation: - - - name: alpha - type: - - double - optional: true - description: | - A double that specifies the exponential decay value to use in the exponential moving average calculation. A higher alpha value assigns a lower mathematical significance to previous results from the calculation. - You must specify either N or alpha. You cannot specify both. + - name: input + type: + - resolvesToNumber + - name: N + type: + - int + optional: true + description: | + An integer that specifies the number of historical documents that have a significant mathematical weight in the exponential moving average calculation, with the most recent documents contributing the most weight. + You must specify either N or alpha. You cannot specify both. + The N value is used in this formula to calculate the current result based on the expression value from the current document being read and the previous result of the calculation: + - name: alpha + type: + - double + optional: true + description: | + A double that specifies the exponential decay value to use in the exponential moving average calculation. A higher alpha value assigns a lower mathematical significance to previous results from the calculation. + You must specify either N or alpha. You cannot specify both. tests: - - - name: 'Exponential Moving Average Using N' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/expMovingAvg/#exponential-moving-average-using-n' - pipeline: - - - $setWindowFields: - partitionBy: '$stock' - sortBy: - date: 1 - output: - expMovingAvgForStock: - $expMovingAvg: - input: '$price' - N: 2 - - - name: 'Exponential Moving Average Using alpha' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/expMovingAvg/#exponential-moving-average-using-alpha' - pipeline: - - - $setWindowFields: - partitionBy: '$stock' - sortBy: - date: 1 - output: - expMovingAvgForStock: - $expMovingAvg: - input: '$price' - alpha: 0.75 + - name: Exponential Moving Average Using N + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/expMovingAvg/#exponential-moving-average-using-n + pipeline: + - $setWindowFields: + partitionBy: $stock + sortBy: + date: 1 + output: + expMovingAvgForStock: + $expMovingAvg: + input: $price + N: 2 + schema: + stockPrices: + stock: + types: + - bsonType: String + date: + types: + - bsonType: Date + price: + types: + - bsonType: Number + - name: Exponential Moving Average Using alpha + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/expMovingAvg/#exponential-moving-average-using-alpha + pipeline: + - $setWindowFields: + partitionBy: $stock + sortBy: + date: 1 + output: + expMovingAvgForStock: + $expMovingAvg: + input: $price + alpha: 0.75 + schema: + stockPrices: + stock: + types: + - bsonType: String + date: + types: + - bsonType: Date + price: + types: + - bsonType: Number diff --git a/generator/config/accumulator/first.yaml b/generator/config/accumulator/first.yaml index d82f831a0..7c5c41bd3 100644 --- a/generator/config/accumulator/first.yaml +++ b/generator/config/accumulator/first.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $first -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/first/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/first/ type: - accumulator - window @@ -9,37 +9,68 @@ description: | 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. arguments: - - - name: expression - type: - - expression + - name: expression + type: + - expression tests: - - - name: 'Use in $group Stage' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/first/#use-in--group-stage' - pipeline: - - - $sort: - item: 1 - date: 1 - - - $group: - _id: '$item' - firstSale: - $first: '$date' - - - name: 'Use in $setWindowFields Stage' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/first/#use-in--setwindowfields-stage' - pipeline: - - - $setWindowFields: - partitionBy: '$state' - sortBy: - orderDate: 1 - output: - firstOrderTypeForState: - $first: '$type' - window: - documents: - - 'unbounded' - - 'current' + - name: Use in $group Stage + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/first/#use-in--group-stage + pipeline: + - $sort: + item: 1 + date: 1 + - $group: + _id: $item + firstSale: + $first: $date + schema: + sales: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + price: + types: + - bsonType: Number + quantity: + types: + - bsonType: Number + date: + types: + - bsonType: Date + - name: Use in $setWindowFields Stage + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/first/#use-in--setwindowfields-stage + pipeline: + - $setWindowFields: + partitionBy: $state + sortBy: + orderDate: 1 + output: + firstOrderTypeForState: + $first: $type + window: + documents: + - unbounded + - current + schema: + cakeSales: + _id: + types: + - bsonType: Number + type: + types: + - bsonType: String + orderDate: + types: + - bsonType: Date + state: + types: + - bsonType: String + price: + types: + - bsonType: Number + quantity: + types: + - bsonType: Number diff --git a/generator/config/accumulator/firstN.yaml b/generator/config/accumulator/firstN.yaml index cb7a6e96c..a24282475 100644 --- a/generator/config/accumulator/firstN.yaml +++ b/generator/config/accumulator/firstN.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $firstN -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/firstN/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/firstN/ type: - accumulator - window @@ -10,113 +10,148 @@ description: | 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. arguments: - - - name: input - type: - - expression - description: | - An expression that resolves to the array from which to return n elements. - - - name: 'n' - type: - - resolvesToInt - description: | - A positive integral expression that is either a constant or depends on the _id value for $group. + - name: input + type: + - expression + description: | + An expression that resolves to the array from which to return n elements. + - name: n + type: + - resolvesToInt + description: | + A positive integral expression that is either a constant or depends on the _id value for $group. tests: - - - name: 'Null and Missing Values' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/firstN/#null-and-missing-values' - pipeline: - - - $documents: - - - playerId: 'PlayerA' - gameId: 'G1' - score: 1 - - - playerId: 'PlayerB' - gameId: 'G1' - score: 2 - - - playerId: 'PlayerC' - gameId: 'G1' - score: 3 - - - playerId: 'PlayerD' - gameId: 'G1' - - - playerId: 'PlayerE' - gameId: 'G1' - score: ~ - - - $group: - _id: '$gameId' - firstFiveScores: - $firstN: - input: '$score' - n: 5 - - - name: 'Find the First Three Player Scores for a Single Game' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/firstN/#find-the-first-three-player-scores-for-a-single-game' - pipeline: - - - $match: - gameId: 'G1' - - - $group: - _id: '$gameId' - firstThreeScores: - $firstN: - input: - - '$playerId' - - '$score' - n: 3 - - - name: 'Finding the First Three Player Scores Across Multiple Games' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/firstN/#finding-the-first-three-player-scores-across-multiple-games' - pipeline: - - - $group: - _id: '$gameId' - playerId: - $firstN: - input: - - '$playerId' - - '$score' - n: 3 - - - name: 'Using $sort With $firstN' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/firstN/#using--sort-with--firstn' - pipeline: - - - $sort: - score: -1 - - - $group: - _id: '$gameId' - playerId: - $firstN: - input: - - '$playerId' - - '$score' - n: 3 - - - name: 'Computing n Based on the Group Key for $group' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/firstN/#computing-n-based-on-the-group-key-for--group' - pipeline: - - - $group: - _id: - gameId: '$gameId' - gamescores: - $firstN: - input: '$score' - n: - $cond: - if: - $eq: - - '$gameId' - - 'G2' - then: 1 - else: 3 - + - name: Null and Missing Values + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/firstN/#null-and-missing-values + pipeline: + - $documents: + - playerId: PlayerA + gameId: G1 + score: 1 + - playerId: PlayerB + gameId: G1 + score: 2 + - playerId: PlayerC + gameId: G1 + score: 3 + - playerId: PlayerD + gameId: G1 + - playerId: PlayerE + gameId: G1 + score: ~ + - $group: + _id: $gameId + firstFiveScores: + $firstN: + input: $score + n: 5 + schema: + TestCollection: + playerId: + types: + - bsonType: String + gameId: + types: + - bsonType: String + score: + types: + - bsonType: Number + - bsonType: 'Null' + - name: Find the First Three Player Scores for a Single Game + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/firstN/#find-the-first-three-player-scores-for-a-single-game + pipeline: + - $match: + gameId: G1 + - $group: + _id: $gameId + firstThreeScores: + $firstN: + input: + - $playerId + - $score + n: 3 + schema: + gamescores: + playerId: + types: + - bsonType: String + gameId: + types: + - bsonType: String + score: + types: + - bsonType: Number + - name: Finding the First Three Player Scores Across Multiple Games + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/firstN/#finding-the-first-three-player-scores-across-multiple-games + pipeline: + - $group: + _id: $gameId + playerId: + $firstN: + input: + - $playerId + - $score + n: 3 + schema: + gamescores: + playerId: + types: + - bsonType: String + gameId: + types: + - bsonType: String + score: + types: + - bsonType: Number + - name: Using $sort With $firstN + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/firstN/#using--sort-with--firstn + pipeline: + - $sort: + score: -1 + - $group: + _id: $gameId + playerId: + $firstN: + input: + - $playerId + - $score + n: 3 + schema: + gamescores: + playerId: + types: + - bsonType: String + gameId: + types: + - bsonType: String + score: + types: + - bsonType: Number + - name: Computing n Based on the Group Key for $group + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/firstN/#computing-n-based-on-the-group-key-for--group + pipeline: + - $group: + _id: + gameId: $gameId + gamescores: + $firstN: + input: $score + n: + $cond: + if: + $eq: + - $gameId + - G2 + then: 1 + else: 3 + schema: + gamescores: + playerId: + types: + - bsonType: String + gameId: + types: + - bsonType: String + score: + types: + - bsonType: Number diff --git a/generator/config/accumulator/integral.yaml b/generator/config/accumulator/integral.yaml index efc803597..1d5463b07 100644 --- a/generator/config/accumulator/integral.yaml +++ b/generator/config/accumulator/integral.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $integral -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/integral/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/integral/ type: - window encode: object @@ -8,36 +8,43 @@ description: | Returns the approximation of the area under a curve. New in MongoDB 5.0. arguments: - - - name: input - type: - - resolvesToNumber - - resolvesToDate - - - name: unit - type: - - timeUnit - optional: true - description: | - A string that specifies the time unit. Use one of these strings: "week", "day","hour", "minute", "second", "millisecond". - If the sortBy field is not a date, you must omit a unit. If you specify a unit, you must specify a date in the sortBy field. + - name: input + type: + - resolvesToNumber + - resolvesToDate + - name: unit + type: + - timeUnit + optional: true + description: | + A string that specifies the time unit. Use one of these strings: "week", "day","hour", "minute", "second", "millisecond". + If the sortBy field is not a date, you must omit a unit. If you specify a unit, you must specify a date in the sortBy field. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/integral/#example' - pipeline: - - - $setWindowFields: - partitionBy: '$powerMeterID' - sortBy: - timeStamp: 1 - output: - powerMeterKilowattHours: - $integral: - input: '$kilowatts' - unit: 'hour' - window: - range: - - 'unbounded' - - 'current' - unit: 'hour' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/integral/#example + pipeline: + - $setWindowFields: + partitionBy: $powerMeterID + sortBy: + timeStamp: 1 + output: + powerMeterKilowattHours: + $integral: + input: $kilowatts + unit: hour + window: + range: + - unbounded + - current + unit: hour + schema: + powerConsumption: + powerMeterID: + types: + - bsonType: String + timeStamp: + types: + - bsonType: Date + kilowatts: + types: + - bsonType: Number diff --git a/generator/config/accumulator/last.yaml b/generator/config/accumulator/last.yaml index 969c05524..39b6b4efb 100644 --- a/generator/config/accumulator/last.yaml +++ b/generator/config/accumulator/last.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $last -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/last/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/last/ type: - accumulator - window @@ -9,37 +9,68 @@ description: | 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. arguments: - - - name: expression - type: - - expression + - name: expression + type: + - expression tests: - - - name: 'Use in $group Stage' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/last/' - pipeline: - - - $sort: - item: 1 - date: 1 - - - $group: - _id: '$item' - lastSalesDate: - $last: '$date' - - - name: 'Use in $setWindowFields Stage' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/last/#use-in--setwindowfields-stage' - pipeline: - - - $setWindowFields: - partitionBy: '$state' - sortBy: - orderDate: 1 - output: - lastOrderTypeForState: - $last: '$type' - window: - documents: - - 'current' - - 'unbounded' + - name: Use in $group Stage + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/last/#use-in--group-stage + pipeline: + - $sort: + item: 1 + date: 1 + - $group: + _id: $item + lastSalesDate: + $last: $date + schema: + sales: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + date: + types: + - bsonType: Date + price: + types: + - bsonType: Number + quantity: + types: + - bsonType: Number + - name: Use in $setWindowFields Stage + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/last/#use-in--setwindowfields-stage + pipeline: + - $setWindowFields: + partitionBy: $state + sortBy: + orderDate: 1 + output: + lastOrderTypeForState: + $last: $type + window: + documents: + - current + - unbounded + schema: + cakeSales: + _id: + types: + - bsonType: Number + type: + types: + - bsonType: String + orderDate: + types: + - bsonType: Date + state: + types: + - bsonType: String + price: + types: + - bsonType: Number + quantity: + types: + - bsonType: Number diff --git a/generator/config/accumulator/lastN.yaml b/generator/config/accumulator/lastN.yaml index 13c9b72bd..85e5c4124 100644 --- a/generator/config/accumulator/lastN.yaml +++ b/generator/config/accumulator/lastN.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $lastN -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/lastN/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/lastN/ type: - accumulator - window @@ -10,80 +10,112 @@ description: | 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. arguments: - - - name: input - type: - - resolvesToArray - description: | - An expression that resolves to the array from which to return n elements. - - - name: 'n' - type: - - resolvesToInt - description: | - An expression that resolves to a positive integer. The integer specifies the number of array elements that $firstN returns. + - name: input + type: + - expression + description: | + An expression that resolves to the array from which to return n elements. + - name: n + type: + - resolvesToInt + description: | + An expression that resolves to a positive integer. The integer specifies the number of array elements that $firstN returns. tests: - - - name: 'Find the Last Three Player Scores for a Single Game' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/lastN/#find-the-last-three-player-scores-for-a-single-game' - pipeline: - - - $match: - gameId: 'G1' - - - $group: - _id: '$gameId' - lastThreeScores: - $lastN: - input: - - '$playerId' - - '$score' - n: 3 - - - name: 'Finding the Last Three Player Scores Across Multiple Games' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/lastN/#finding-the-last-three-player-scores-across-multiple-games' - pipeline: - - - $group: - _id: '$gameId' - playerId: - $lastN: - input: - - '$playerId' - - '$score' - n: 3 - - - name: 'Using $sort With $lastN' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/lastN/#using--sort-with--lastn' - pipeline: - - - $sort: - score: -1 - - - $group: - _id: '$gameId' - playerId: - $lastN: - input: - - '$playerId' - - '$score' - n: 3 - - - name: 'Computing n Based on the Group Key for $group' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/lastN/#computing-n-based-on-the-group-key-for--group' - pipeline: - - - $group: - _id: - gameId: '$gameId' - gamescores: - $lastN: - input: '$score' - n: - $cond: - if: - $eq: - - '$gameId' - - 'G2' - then: 1 - else: 3 + - name: Find the Last Three Player Scores for a Single Game + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/lastN/#find-the-last-three-player-scores-for-a-single-game + pipeline: + - $match: + gameId: G1 + - $group: + _id: $gameId + lastThreeScores: + $lastN: + input: + - $playerId + - $score + n: 3 + schema: + gamescores: + playerId: + types: + - bsonType: String + gameId: + types: + - bsonType: String + score: + types: + - bsonType: Number + - name: Finding the Last Three Player Scores Across Multiple Games + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/lastN/#finding-the-last-three-player-scores-across-multiple-games + pipeline: + - $group: + _id: $gameId + playerId: + $lastN: + input: + - $playerId + - $score + n: 3 + schema: + gamescores: + playerId: + types: + - bsonType: String + gameId: + types: + - bsonType: String + score: + types: + - bsonType: Number + - name: Using $sort With $lastN + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/lastN/#using--sort-with--lastn + pipeline: + - $sort: + score: -1 + - $group: + _id: $gameId + playerId: + $lastN: + input: + - $playerId + - $score + n: 3 + schema: + gamescores: + playerId: + types: + - bsonType: String + gameId: + types: + - bsonType: String + score: + types: + - bsonType: Number + - name: Computing n Based on the Group Key for $group + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/lastN/#computing-n-based-on-the-group-key-for--group + pipeline: + - $group: + _id: + gameId: $gameId + gamescores: + $lastN: + input: $score + n: + $cond: + if: + $eq: + - $gameId + - G2 + then: 1 + else: 3 + schema: + gamescores: + playerId: + types: + - bsonType: String + gameId: + types: + - bsonType: String + score: + types: + - bsonType: Number diff --git a/generator/config/accumulator/linearFill.yaml b/generator/config/accumulator/linearFill.yaml index 034e6ab9e..3fee6d4da 100644 --- a/generator/config/accumulator/linearFill.yaml +++ b/generator/config/accumulator/linearFill.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $linearFill -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/linearFill/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/linearFill/ type: - window encode: single @@ -9,32 +9,43 @@ description: | Available in the $setWindowFields stage. New in MongoDB 5.3. arguments: - - - name: expression - type: - - resolvesToNumber + - name: expression + type: + - resolvesToNumber tests: - - - name: 'Fill Missing Values with Linear Interpolation' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/linearFill/#fill-missing-values-with-linear-interpolation' - pipeline: - - - $setWindowFields: - sortBy: - time: 1 - output: - price: - $linearFill: '$price' - - - name: 'Use Multiple Fill Methods in a Single Stage' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/linearFill/#use-multiple-fill-methods-in-a-single-stage' - pipeline: - - - $setWindowFields: - sortBy: - time: 1 - output: - linearFillPrice: - $linearFill: '$price' - locfPrice: - $locf: '$price' + - name: Fill Missing Values with Linear Interpolation + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/linearFill/#fill-missing-values-with-linear-interpolation + pipeline: + - $setWindowFields: + sortBy: + time: 1 + output: + price: + $linearFill: $price + schema: + stock: + time: + types: + - bsonType: Date + price: + types: + - bsonType: Number + - name: Use Multiple Fill Methods in a Single Stage + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/linearFill/#use-multiple-fill-methods-in-a-single-stage + pipeline: + - $setWindowFields: + sortBy: + time: 1 + output: + linearFillPrice: + $linearFill: $price + locfPrice: + $locf: $price + schema: + stock: + time: + types: + - bsonType: Date + price: + types: + - bsonType: Number diff --git a/generator/config/accumulator/locf.yaml b/generator/config/accumulator/locf.yaml index 63979bca4..0478e41bb 100644 --- a/generator/config/accumulator/locf.yaml +++ b/generator/config/accumulator/locf.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $locf -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/locf/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/locf/ type: - window encode: single @@ -9,19 +9,24 @@ description: | Available in the $setWindowFields stage. New in MongoDB 5.2. arguments: - - - name: expression - type: - - expression + - name: expression + type: + - expression tests: - - - name: 'Fill Missing Values with the Last Observed Value' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/locf/#fill-missing-values-with-the-last-observed-value' - pipeline: - - - $setWindowFields: - sortBy: - time: 1 - output: - price: - $locf: '$price' + - name: Fill Missing Values with the Last Observed Value + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/locf/#fill-missing-values-with-the-last-observed-value + pipeline: + - $setWindowFields: + sortBy: + time: 1 + output: + price: + $locf: $price + schema: + stock: + time: + types: + - bsonType: Date + price: + types: + - bsonType: Number diff --git a/generator/config/accumulator/max.yaml b/generator/config/accumulator/max.yaml index 165cefc43..2698af79b 100644 --- a/generator/config/accumulator/max.yaml +++ b/generator/config/accumulator/max.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $max -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/max/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/max/ type: - accumulator - window @@ -9,38 +9,70 @@ description: | Returns the maximum value that results from applying an expression to each document. Changed in MongoDB 5.0: Available in the $setWindowFields stage. arguments: - - - name: expression - type: - - expression + - name: expression + type: + - expression tests: - - - name: 'Use in $group Stage' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/max/#use-in--group-stage' - pipeline: - - - $group: - _id: '$item' - maxTotalAmount: - $max: - $multiply: - - '$price' - - '$quantity' - maxQuantity: - $max: '$quantity' - - - name: 'Use in $setWindowFields Stage' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/max/#use-in--setwindowfields-stage' - pipeline: - - - $setWindowFields: - partitionBy: '$state' - sortBy: - orderDate: 1 - output: - maximumQuantityForState: - $max: '$quantity' - window: - documents: - - 'unbounded' - - 'current' + - name: Use in $group Stage + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/max/#use-in--group-stage + pipeline: + - $group: + _id: $item + maxTotalAmount: + $max: + $multiply: + - $price + - $quantity + maxQuantity: + $max: $quantity + schema: + sales: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + price: + types: + - bsonType: Number + quantity: + types: + - bsonType: Number + date: + types: + - bsonType: Date + - name: Use in $setWindowFields Stage + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/max/#use-in--setwindowfields-stage + pipeline: + - $setWindowFields: + partitionBy: $state + sortBy: + orderDate: 1 + output: + maximumQuantityForState: + $max: $quantity + window: + documents: + - unbounded + - current + schema: + cakeSales: + _id: + types: + - bsonType: Number + type: + types: + - bsonType: String + orderDate: + types: + - bsonType: Date + state: + types: + - bsonType: String + price: + types: + - bsonType: Number + quantity: + types: + - bsonType: Number diff --git a/generator/config/accumulator/maxN.yaml b/generator/config/accumulator/maxN.yaml index 4014782a8..38300fb6e 100644 --- a/generator/config/accumulator/maxN.yaml +++ b/generator/config/accumulator/maxN.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $maxN -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/maxN/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/maxN/ type: - accumulator - window @@ -8,66 +8,90 @@ encode: object description: | Returns the n largest values in an array. Distinct from the $maxN accumulator. arguments: - - - name: input - type: - - resolvesToArray - description: | - An expression that resolves to the array from which to return the maximal n elements. - - - name: 'n' - type: - - resolvesToInt - description: | - An expression that resolves to a positive integer. The integer specifies the number of array elements that $maxN returns. + - name: input + type: + - resolvesToArray + description: | + An expression that resolves to the array from which to return the maximal n elements. + - name: n + type: + - resolvesToInt + description: | + An expression that resolves to a positive integer. The integer specifies the number of array elements that $maxN returns. tests: - - - name: 'Find the Maximum Three Scores for a Single Game' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/maxN/#find-the-maximum-three-scores-for-a-single-game' - pipeline: - - - $match: - gameId: 'G1' - - - $group: - _id: '$gameId' - maxThreeScores: - $maxN: - input: - - '$score' - - '$playerId' - n: 3 - - - name: 'Finding the Maximum Three Scores Across Multiple Games' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/maxN/#finding-the-maximum-three-scores-across-multiple-games' - pipeline: - - - $group: - _id: '$gameId' - maxScores: - $maxN: - input: - - '$score' - - '$playerId' - n: 3 - - - name: 'Computing n Based on the Group Key for $group' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/maxN/#computing-n-based-on-the-group-key-for--group' - pipeline: - - - $group: - _id: - gameId: '$gameId' - gamescores: - $maxN: - input: - - '$score' - - '$playerId' - n: - $cond: - if: - $eq: - - '$gameId' - - 'G2' - then: 1 - else: 3 + - name: Find the Maximum Three Scores for a Single Game + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/maxN/#find-the-maximum-three-scores-for-a-single-game + pipeline: + - $match: + gameId: G1 + - $group: + _id: $gameId + maxThreeScores: + $maxN: + input: + - $score + - $playerId + n: 3 + schema: + gamescores: + playerId: + types: + - bsonType: String + gameId: + types: + - bsonType: String + score: + types: + - bsonType: Number + - name: Finding the Maximum Three Scores Across Multiple Games + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/maxN/#finding-the-maximum-three-scores-across-multiple-games + pipeline: + - $group: + _id: $gameId + maxScores: + $maxN: + input: + - $score + - $playerId + n: 3 + schema: + gamescores: + playerId: + types: + - bsonType: String + gameId: + types: + - bsonType: String + score: + types: + - bsonType: Number + - name: Computing n Based on the Group Key for $group + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/maxN/#computing-n-based-on-the-group-key-for--group + pipeline: + - $group: + _id: + gameId: $gameId + gamescores: + $maxN: + input: + - $score + - $playerId + n: + $cond: + if: + $eq: + - $gameId + - G2 + then: 1 + else: 3 + schema: + gamescores: + playerId: + types: + - bsonType: String + gameId: + types: + - bsonType: String + score: + types: + - bsonType: Number diff --git a/generator/config/accumulator/median.yaml b/generator/config/accumulator/median.yaml index e743c6982..47af1feea 100644 --- a/generator/config/accumulator/median.yaml +++ b/generator/config/accumulator/median.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $median -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/median/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/median/ type: - accumulator - window @@ -13,49 +13,70 @@ description: | $setWindowFields It is also available as an aggregation expression. arguments: - - - name: input - type: - - resolvesToNumber - description: | - $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. - - - name: method - type: - - accumulatorPercentile - description: | - The method that mongod uses to calculate the 50th percentile value. The method must be 'approximate'. + - name: input + type: + - resolvesToNumber + description: | + $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. + - name: method + type: + - accumulatorPercentile + description: | + The method that mongod uses to calculate the 50th percentile value. The method must be 'approximate'. tests: - - - name: 'Use $median as an Accumulator' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/median/#use-operatorname-as-an-accumulator' - pipeline: - - - $group: - _id: ~ + - name: Use $median as an Accumulator + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/median/#use-operatorname-as-an-accumulator + pipeline: + - $group: + _id: ~ + test01_median: + $median: + input: $test01 + method: approximate + schema: + testScores: + studentId: + types: + - bsonType: String + test01: + types: + - bsonType: Number + test02: + types: + - bsonType: Number + test03: + types: + - bsonType: Number + - name: Use $median in a $setWindowField Stage + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/median/#use-operatorname-in-a--setwindowfield-stage + pipeline: + - $setWindowFields: + sortBy: + test01: 1 + output: test01_median: $median: - input: '$test01' - method: 'approximate' - - - name: 'Use $median in a $setWindowField Stage' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/median/#use-operatorname-in-a--setwindowfield-stage' - pipeline: - - - $setWindowFields: - sortBy: - test01: 1 - output: - test01_median: - $median: - input: '$test01' - method: 'approximate' - window: - range: - - -3 - - 3 - - - $project: - _id: 0 - studentId: 1 - test01_median: 1 + input: $test01 + method: approximate + window: + range: + - -3 + - 3 + - $project: + _id: 0 + studentId: 1 + test01_median: 1 + schema: + testScores: + studentId: + types: + - bsonType: String + test01: + types: + - bsonType: Number + test02: + types: + - bsonType: Number + test03: + types: + - bsonType: Number diff --git a/generator/config/accumulator/mergeObjects.yaml b/generator/config/accumulator/mergeObjects.yaml index d68728001..9aeaeed2d 100644 --- a/generator/config/accumulator/mergeObjects.yaml +++ b/generator/config/accumulator/mergeObjects.yaml @@ -1,25 +1,55 @@ # $schema: ../schema.json name: $mergeObjects -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/mergeObjects/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/mergeObjects/ type: - accumulator encode: single description: | Combines multiple documents into a single document. arguments: - - - name: document - type: - - resolvesToObject - description: | - Any valid expression that resolves to a document. + - name: document + type: + - resolvesToObject + description: | + Any valid expression that resolves to a document. tests: - - - name: '$mergeObjects as an Accumulator' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/mergeObjects/#-mergeobjects-as-an-accumulator' - pipeline: - - - $group: - _id: '$item' - mergedSales: - $mergeObjects: '$quantity' + - name: $mergeObjects as an Accumulator + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/mergeObjects/#-mergeobjects-as-an-accumulator + pipeline: + - $group: + _id: $item + mergedSales: + $mergeObjects: $quantity + schema: + sales: + _id: + types: + - bsonType: Number + year: + types: + - bsonType: Number + item: + types: + - bsonType: String + quantity: + types: + - bsonType: Document + fields: + 2017Q1: + types: + - bsonType: Number + 2017Q2: + types: + - bsonType: Number + 2016Q1: + types: + - bsonType: Number + 2016Q2: + types: + - bsonType: Number + 2016Q3: + types: + - bsonType: Number + 2016Q4: + types: + - bsonType: Number diff --git a/generator/config/accumulator/min.yaml b/generator/config/accumulator/min.yaml index 226d56ec8..569ac11f6 100644 --- a/generator/config/accumulator/min.yaml +++ b/generator/config/accumulator/min.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $min -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/min/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/min/ type: - accumulator - window @@ -9,33 +9,65 @@ description: | Returns the minimum value that results from applying an expression to each document. Changed in MongoDB 5.0: Available in the $setWindowFields stage. arguments: - - - name: expression - type: - - expression + - name: expression + type: + - expression tests: - - - name: 'Use in $group Stage' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/min/#use-in--group-stage' - pipeline: - - - $group: - _id: '$item' - minQuantity: - $min: '$quantity' - - - name: 'Use in $setWindowFields Stage' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/min/#use-in--setwindowfields-stage' - pipeline: - - - $setWindowFields: - partitionBy: '$state' - sortBy: - orderDate: 1 - output: - minimumQuantityForState: - $min: '$quantity' - window: - documents: - - 'unbounded' - - 'current' + - name: Use in $group Stage + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/min/#use-in--group-stage + pipeline: + - $group: + _id: $item + minQuantity: + $min: $quantity + schema: + sales: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + price: + types: + - bsonType: Number + quantity: + types: + - bsonType: Number + date: + types: + - bsonType: Date + - name: Use in $setWindowFields Stage + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/min/#use-in--setwindowfields-stage + pipeline: + - $setWindowFields: + partitionBy: $state + sortBy: + orderDate: 1 + output: + minimumQuantityForState: + $min: $quantity + window: + documents: + - unbounded + - current + schema: + cakeSales: + _id: + types: + - bsonType: Number + type: + types: + - bsonType: String + orderDate: + types: + - bsonType: Date + state: + types: + - bsonType: String + price: + types: + - bsonType: Number + quantity: + types: + - bsonType: Number diff --git a/generator/config/accumulator/minN.yaml b/generator/config/accumulator/minN.yaml index 24719a22a..f7d29b080 100644 --- a/generator/config/accumulator/minN.yaml +++ b/generator/config/accumulator/minN.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $minN -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/minN/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/minN/ type: - accumulator - window @@ -8,66 +8,90 @@ encode: object description: | Returns the n smallest values in an array. Distinct from the $minN accumulator. arguments: - - - name: input - type: - - resolvesToArray - description: | - An expression that resolves to the array from which to return the maximal n elements. - - - name: 'n' - type: - - resolvesToInt - description: | - An expression that resolves to a positive integer. The integer specifies the number of array elements that $maxN returns. + - name: input + type: + - resolvesToArray + description: | + An expression that resolves to the array from which to return the maximal n elements. + - name: n + type: + - resolvesToInt + description: | + An expression that resolves to a positive integer. The integer specifies the number of array elements that $maxN returns. tests: - - - name: 'Find the Minimum Three Scores for a Single Game' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/minN/#find-the-minimum-three-scores-for-a-single-game' - pipeline: - - - $match: - gameId: 'G1' - - - $group: - _id: '$gameId' - minScores: - $minN: - input: - - '$score' - - '$playerId' - n: 3 - - - name: 'Finding the Minimum Three Documents Across Multiple Games' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/minN/#finding-the-minimum-three-documents-across-multiple-games' - pipeline: - - - $group: - _id: '$gameId' - minScores: - $minN: - input: - - '$score' - - '$playerId' - n: 3 - - - name: 'Computing n Based on the Group Key for $group' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/minN/#computing-n-based-on-the-group-key-for--group' - pipeline: - - - $group: - _id: - gameId: '$gameId' - gamescores: - $minN: - input: - - '$score' - - '$playerId' - n: - $cond: - if: - $eq: - - '$gameId' - - 'G2' - then: 1 - else: 3 + - name: Find the Minimum Three Scores for a Single Game + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/minN/#find-the-minimum-three-scores-for-a-single-game + pipeline: + - $match: + gameId: G1 + - $group: + _id: $gameId + minScores: + $minN: + input: + - $score + - $playerId + n: 3 + schema: + gamescores: + playerId: + types: + - bsonType: String + gameId: + types: + - bsonType: String + score: + types: + - bsonType: Number + - name: Finding the Minimum Three Documents Across Multiple Games + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/minN/#finding-the-minimum-three-documents-across-multiple-games + pipeline: + - $group: + _id: $gameId + minScores: + $minN: + input: + - $score + - $playerId + n: 3 + schema: + gamescores: + playerId: + types: + - bsonType: String + gameId: + types: + - bsonType: String + score: + types: + - bsonType: Number + - name: Computing n Based on the Group Key for $group + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/minN/#computing-n-based-on-the-group-key-for--group + pipeline: + - $group: + _id: + gameId: $gameId + gamescores: + $minN: + input: + - $score + - $playerId + n: + $cond: + if: + $eq: + - $gameId + - G2 + then: 1 + else: 3 + schema: + gamescores: + playerId: + types: + - bsonType: String + gameId: + types: + - bsonType: String + score: + types: + - bsonType: Number diff --git a/generator/config/accumulator/percentile.yaml b/generator/config/accumulator/percentile.yaml index b3c41b0e4..1775bec3b 100644 --- a/generator/config/accumulator/percentile.yaml +++ b/generator/config/accumulator/percentile.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $percentile -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/percentile/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/percentile/ type: - accumulator - window @@ -8,95 +8,140 @@ encode: object description: | 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 - It is also available as an aggregation expression. arguments: - - - name: input - type: - - resolvesToNumber - description: | - $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. - - - name: p - type: - - resolvesToArray # of resolvesToNumber - description: | - $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. - $percentile returns results in the same order as the elements in p. - - - name: method - type: - - accumulatorPercentile - description: | - The method that mongod uses to calculate the percentile value. The method must be 'approximate'. + - name: input + type: + - resolvesToNumber + description: | + $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. + - name: p + type: + - resolvesToArray + description: | + $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. + $percentile returns results in the same order as the elements in p. + - name: method + type: + - accumulatorPercentile + description: | + The method that mongod uses to calculate the percentile value. The method must be 'approximate'. tests: - - - name: 'Calculate a Single Value as an Accumulator' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/percentile/#calculate-a-single-value-as-an-accumulator' - pipeline: - - - $group: - _id: ~ - test01_percentiles: + - name: Calculate a Single Value as an Accumulator + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/percentile/#calculate-a-single-value-as-an-accumulator + pipeline: + - $group: + _id: ~ + test01_percentiles: + $percentile: + input: $test01 + p: + - 0.95 + method: approximate + schema: + testScores: + studentId: + types: + - bsonType: String + test01: + types: + - bsonType: Number + test02: + types: + - bsonType: Number + test03: + types: + - bsonType: Number + - name: Calculate Multiple Values as an Accumulator + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/percentile/#calculate-multiple-values-as-an-accumulator + pipeline: + - $group: + _id: ~ + test01_percentiles: + $percentile: + input: $test01 + p: + - 0.5 + - 0.75 + - 0.9 + - 0.95 + method: approximate + test02_percentiles: + $percentile: + input: $test02 + p: + - 0.5 + - 0.75 + - 0.9 + - 0.95 + method: approximate + test03_percentiles: + $percentile: + input: $test03 + p: + - 0.5 + - 0.75 + - 0.9 + - 0.95 + method: approximate + test03_percent_alt: + $percentile: + input: $test03 + p: + - 0.9 + - 0.5 + - 0.75 + - 0.95 + method: approximate + schema: + testScores: + studentId: + types: + - bsonType: String + test01: + types: + - bsonType: Number + test02: + types: + - bsonType: Number + test03: + types: + - bsonType: Number + - name: Use $percentile in a $setWindowField Stage + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/percentile/#use-operatorname-in-a--setwindowfield-stage + pipeline: + - $setWindowFields: + sortBy: + test01: 1 + output: + test01_95percentile: $percentile: - input: '$test01' + input: $test01 p: - 0.95 - method: 'approximate' - - - name: 'Calculate Multiple Values as an Accumulator' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/percentile/#calculate-multiple-values-as-an-accumulator' - pipeline: - - - $group: - _id: ~ - test01_percentiles: - $percentile: - input: '$test01' - p: [0.5, 0.75, 0.9, 0.95] - method: 'approximate' - test02_percentiles: - $percentile: - input: '$test02' - p: [0.5, 0.75, 0.9, 0.95] - method: 'approximate' - test03_percentiles: - $percentile: - input: '$test03' - p: [0.5, 0.75, 0.9, 0.95] - method: 'approximate' - test03_percent_alt: - $percentile: - input: '$test03' - p: [0.9, 0.5, 0.75, 0.95] - method: 'approximate' - - - name: 'Use $percentile in a $setWindowField Stage' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/percentile/#use-operatorname-in-a--setwindowfield-stage' - pipeline: - - - $setWindowFields: - sortBy: - test01: 1 - output: - test01_95percentile: - $percentile: - input: '$test01' - p: - - 0.95 - method: 'approximate' - window: - range: - - -3 - - 3 - - - $project: - _id: 0 - studentId: 1 - test01_95percentile: 1 + method: approximate + window: + range: + - -3 + - 3 + - $project: + _id: 0 + studentId: 1 + test01_95percentile: 1 + schema: + testScores: + studentId: + types: + - bsonType: String + test01: + types: + - bsonType: Number + test02: + types: + - bsonType: Number + test03: + types: + - bsonType: Number diff --git a/generator/config/accumulator/push.yaml b/generator/config/accumulator/push.yaml index 3fc367c59..178915048 100644 --- a/generator/config/accumulator/push.yaml +++ b/generator/config/accumulator/push.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $push -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/push/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/push/ type: - accumulator - window @@ -9,47 +9,76 @@ description: | Returns an array of values that result from applying an expression to each document. Changed in MongoDB 5.0: Available in the $setWindowFields stage. arguments: - - - name: expression - type: - - expression + - name: expression + type: + - expression tests: - - - name: 'Use in $group Stage' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/push/#use-in--group-stage' - pipeline: - - - $sort: - date: 1 - item: 1 - - - $group: - _id: - day: - # Example uses the short form, the builder always generates the verbose form - # $dayOfYear: '$date' - $dayOfYear: - date: '$date' - year: - # Example uses the short form, the builder always generates the verbose form - # $year: '$date' - $year: - date: '$date' - itemsSold: - $push: - item: '$item' - quantity: '$quantity' - - - name: 'Use in $setWindowFields Stage' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/push/#use-in--setwindowfields-stage' - pipeline: - - - $setWindowFields: - partitionBy: '$state' - sortBy: - orderDate: 1 - output: - quantitiesForState: - $push: '$quantity' - window: - documents: ['unbounded', 'current'] + - name: Use in $group Stage + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/push/#use-in--group-stage + pipeline: + - $sort: + date: 1 + item: 1 + - $group: + _id: + day: + $dayOfYear: + date: $date + year: + $year: + date: $date + itemsSold: + $push: + item: $item + quantity: $quantity + schema: + sales: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + price: + types: + - bsonType: Number + quantity: + types: + - bsonType: Number + date: + types: + - bsonType: Date + - name: Use in $setWindowFields Stage + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/push/#use-in--setwindowfields-stage + pipeline: + - $setWindowFields: + partitionBy: $state + sortBy: + orderDate: 1 + output: + quantitiesForState: + $push: $quantity + window: + documents: + - unbounded + - current + schema: + cakeSales: + _id: + types: + - bsonType: Number + type: + types: + - bsonType: String + orderDate: + types: + - bsonType: Date + state: + types: + - bsonType: String + price: + types: + - bsonType: Number + quantity: + types: + - bsonType: Number diff --git a/generator/config/accumulator/rank.yaml b/generator/config/accumulator/rank.yaml index 8b8fd041b..e7f9e9dc0 100644 --- a/generator/config/accumulator/rank.yaml +++ b/generator/config/accumulator/rank.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $rank -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/rank/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/rank/ type: - window encode: object @@ -8,27 +8,63 @@ description: | Returns the document position (known as the rank) relative to other documents in the $setWindowFields stage partition. New in MongoDB 5.0. tests: - - - name: 'Rank Partitions by an Integer Field' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/rank/#rank-partitions-by-an-integer-field' - pipeline: - - - $setWindowFields: - partitionBy: '$state' - sortBy: - quantity: -1 - output: - rankQuantityForState: - $rank: {} - - - name: 'Rank Partitions by a Date Field' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/rank/#rank-partitions-by-a-date-field' - pipeline: - - - $setWindowFields: - partitionBy: '$state' - sortBy: - orderDate: 1 - output: - rankOrderDateForState: - $rank: {} + - name: Rank Partitions by an Integer Field + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/rank/#rank-partitions-by-an-integer-field + pipeline: + - $setWindowFields: + partitionBy: $state + sortBy: + quantity: -1 + output: + rankQuantityForState: + $rank: {} + schema: + cakeSales: + _id: + types: + - bsonType: Number + type: + types: + - bsonType: String + orderDate: + types: + - bsonType: Date + state: + types: + - bsonType: String + price: + types: + - bsonType: Number + quantity: + types: + - bsonType: Number + - name: Rank Partitions by a Date Field + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/rank/#rank-partitions-by-a-date-field + pipeline: + - $setWindowFields: + partitionBy: $state + sortBy: + orderDate: 1 + output: + rankOrderDateForState: + $rank: {} + schema: + cakeSales: + _id: + types: + - bsonType: Number + type: + types: + - bsonType: String + orderDate: + types: + - bsonType: Date + state: + types: + - bsonType: String + price: + types: + - bsonType: Number + quantity: + types: + - bsonType: Number diff --git a/generator/config/accumulator/shift.yaml b/generator/config/accumulator/shift.yaml index f4984f056..7e474b496 100644 --- a/generator/config/accumulator/shift.yaml +++ b/generator/config/accumulator/shift.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $shift -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/shift/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/shift/ type: - window encode: object @@ -8,58 +8,91 @@ description: | 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. arguments: - - - name: output - type: - - expression - description: | - Specifies an expression to evaluate and return in the output. - - - name: by - type: - - int - description: | - Specifies an integer with a numeric document position relative to the current document in the output. - For example: - 1 specifies the document position after the current document. - -1 specifies the document position before the current document. - -2 specifies the document position that is two positions before the current document. - - - name: default - type: - - expression - description: | - Specifies an optional default expression to evaluate if the document position is outside of the implicit $setWindowFields stage window. The implicit window contains all the documents in the partition. - The default expression must evaluate to a constant value. - If you do not specify a default expression, $shift returns null for documents whose positions are outside of the implicit $setWindowFields stage window. + - name: output + type: + - expression + description: | + Specifies an expression to evaluate and return in the output. + - name: by + type: + - int + description: | + Specifies an integer with a numeric document position relative to the current document in the output. + For example: + 1 specifies the document position after the current document. + -1 specifies the document position before the current document. + -2 specifies the document position that is two positions before the current document. + - name: default + type: + - expression + description: | + Specifies an optional default expression to evaluate if the document position is outside of the implicit $setWindowFields stage window. The implicit window contains all the documents in the partition. + The default expression must evaluate to a constant value. + If you do not specify a default expression, $shift returns null for documents whose positions are outside of the implicit $setWindowFields stage window. tests: - - - name: 'Shift Using a Positive Integer' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/shift/#shift-using-a-positive-integer' - pipeline: - - - $setWindowFields: - partitionBy: '$state' - sortBy: - quantity: -1 - output: - shiftQuantityForState: - $shift: - output: '$quantity' - by: 1 - default: 'Not available' - - - name: 'Shift Using a Negative Integer' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/shift/#shift-using-a-negative-integer' - pipeline: - - - $setWindowFields: - partitionBy: '$state' - sortBy: - quantity: -1 - output: - shiftQuantityForState: - $shift: - output: '$quantity' - by: -1 - default: 'Not available' + - name: Shift Using a Positive Integer + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/shift/#shift-using-a-positive-integer + pipeline: + - $setWindowFields: + partitionBy: $state + sortBy: + quantity: -1 + output: + shiftQuantityForState: + $shift: + output: $quantity + by: 1 + default: Not available + schema: + cakeSales: + _id: + types: + - bsonType: Number + type: + types: + - bsonType: String + orderDate: + types: + - bsonType: Date + state: + types: + - bsonType: String + price: + types: + - bsonType: Number + quantity: + types: + - bsonType: Number + - name: Shift Using a Negative Integer + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/shift/#shift-using-a-negative-integer + pipeline: + - $setWindowFields: + partitionBy: $state + sortBy: + quantity: -1 + output: + shiftQuantityForState: + $shift: + output: $quantity + by: -1 + default: Not available + schema: + cakeSales: + _id: + types: + - bsonType: Number + type: + types: + - bsonType: String + orderDate: + types: + - bsonType: Date + state: + types: + - bsonType: String + price: + types: + - bsonType: Number + quantity: + types: + - bsonType: Number diff --git a/generator/config/accumulator/stdDevPop.yaml b/generator/config/accumulator/stdDevPop.yaml index 8916456d4..8efd38b67 100644 --- a/generator/config/accumulator/stdDevPop.yaml +++ b/generator/config/accumulator/stdDevPop.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $stdDevPop -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/stdDevPop/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/stdDevPop/ type: - accumulator - window @@ -10,31 +10,62 @@ description: | 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. arguments: - - - name: expression - type: - - resolvesToNumber + - name: expression + type: + - resolvesToNumber tests: - - - name: 'Use in $group Stage' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/stdDevPop/#use-in--group-stage' - pipeline: - - - $group: - _id: '$quiz' - stdDev: - $stdDevPop: '$score' - - - name: 'Use in $setWindowFields Stage' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/stdDevPop/#use-in--setwindowfields-stage' - pipeline: - - - $setWindowFields: - partitionBy: '$state' - sortBy: - orderDate: 1 - output: - stdDevPopQuantityForState: - $stdDevPop: '$quantity' - window: - documents: ['unbounded', 'current'] + - name: Use in $group Stage + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/stdDevPop/#use-in--group-stage + pipeline: + - $group: + _id: $quiz + stdDev: + $stdDevPop: $score + schema: + users: + _id: + types: + - bsonType: Number + name: + types: + - bsonType: String + quiz: + types: + - bsonType: Number + score: + types: + - bsonType: Number + - name: Use in $setWindowFields Stage + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/stdDevPop/#use-in--setwindowfields-stage + pipeline: + - $setWindowFields: + partitionBy: $state + sortBy: + orderDate: 1 + output: + stdDevPopQuantityForState: + $stdDevPop: $quantity + window: + documents: + - unbounded + - current + schema: + cakeSales: + _id: + types: + - bsonType: Number + type: + types: + - bsonType: String + orderDate: + types: + - bsonType: Date + state: + types: + - bsonType: String + price: + types: + - bsonType: Number + quantity: + types: + - bsonType: Number diff --git a/generator/config/accumulator/stdDevSamp.yaml b/generator/config/accumulator/stdDevSamp.yaml index 94ac33d15..ca0e1b300 100644 --- a/generator/config/accumulator/stdDevSamp.yaml +++ b/generator/config/accumulator/stdDevSamp.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $stdDevSamp -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/stdDevSamp/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/stdDevSamp/ type: - accumulator - window @@ -10,34 +10,61 @@ description: | 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. arguments: - - - name: expression - type: - - resolvesToNumber + - name: expression + type: + - resolvesToNumber tests: - - - name: 'Use in $group Stage' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/stdDevSamp/#use-in--group-stage' - pipeline: - - - $sample: - size: 100 - - - $group: - _id: ~ - ageStdDev: - $stdDevSamp: '$age' - - - name: 'Use in $setWindowFields Stage' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/stdDevSamp/#use-in--setwindowfields-stage' - pipeline: - - - $setWindowFields: - partitionBy: '$state' - sortBy: - orderDate: 1 - output: - stdDevSampQuantityForState: - $stdDevSamp: '$quantity' - window: - documents: ['unbounded', 'current'] + - name: Use in $group Stage + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/stdDevSamp/#use-in--group-stage + pipeline: + - $sample: + size: 100 + - $group: + _id: ~ + ageStdDev: + $stdDevSamp: $age + schema: + users: + _id: + types: + - bsonType: Number + username: + types: + - bsonType: String + age: + types: + - bsonType: Number + - name: Use in $setWindowFields Stage + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/stdDevSamp/#use-in--setwindowfields-stage + pipeline: + - $setWindowFields: + partitionBy: $state + sortBy: + orderDate: 1 + output: + stdDevSampQuantityForState: + $stdDevSamp: $quantity + window: + documents: + - unbounded + - current + schema: + cakeSales: + _id: + types: + - bsonType: Number + type: + types: + - bsonType: String + orderDate: + types: + - bsonType: Date + state: + types: + - bsonType: String + price: + types: + - bsonType: Number + quantity: + types: + - bsonType: Number diff --git a/generator/config/accumulator/sum.yaml b/generator/config/accumulator/sum.yaml index c40417ef4..e31b8ca0e 100644 --- a/generator/config/accumulator/sum.yaml +++ b/generator/config/accumulator/sum.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $sum -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/sum/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/sum/ type: - accumulator - window @@ -9,48 +9,76 @@ description: | Returns a sum of numerical values. Ignores non-numeric values. Changed in MongoDB 5.0: Available in the $setWindowFields stage. arguments: - - - name: expression - type: - - resolvesToNumber + - name: expression + type: + - resolvesToNumber tests: - - - name: 'Use in $group Stage' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/sum/#use-in--group-stage' - pipeline: - - - $group: - _id: - day: - # Example uses the short form, the builder always generates the verbose form - # $dayOfYear: '$date' - $dayOfYear: - date: '$date' - year: - # Example uses the short form, the builder always generates the verbose form - # $year: '$date' - $year: - date: '$date' - totalAmount: - $sum: - $multiply: - - '$price' - - '$quantity' - count: - $sum: 1 - - - name: 'Use in $setWindowFields Stage' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/sum/#use-in--setwindowfields-stage' - pipeline: - - - $setWindowFields: - partitionBy: '$state' - sortBy: - orderDate: 1 - output: - sumQuantityForState: - $sum: '$quantity' - window: - documents: - - 'unbounded' - - 'current' + - name: Use in $group Stage + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/sum/#use-in--group-stage + pipeline: + - $group: + _id: + day: + $dayOfYear: + date: $date + year: + $year: + date: $date + totalAmount: + $sum: + $multiply: + - $price + - $quantity + count: + $sum: 1 + schema: + sales: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + price: + types: + - bsonType: Number + quantity: + types: + - bsonType: Number + date: + types: + - bsonType: Date + - name: Use in $setWindowFields Stage + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/sum/#use-in--setwindowfields-stage + pipeline: + - $setWindowFields: + partitionBy: $state + sortBy: + orderDate: 1 + output: + sumQuantityForState: + $sum: $quantity + window: + documents: + - unbounded + - current + schema: + cakeSales: + _id: + types: + - bsonType: Number + type: + types: + - bsonType: String + orderDate: + types: + - bsonType: Date + state: + types: + - bsonType: String + price: + types: + - bsonType: Number + quantity: + types: + - bsonType: Number diff --git a/generator/config/accumulator/top.yaml b/generator/config/accumulator/top.yaml index 94923cccd..4d3205b96 100644 --- a/generator/config/accumulator/top.yaml +++ b/generator/config/accumulator/top.yaml @@ -1,56 +1,70 @@ # $schema: ../schema.json name: $top -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/top/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/top/ type: - accumulator encode: object description: | 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. arguments: - - - name: sortBy - type: - - sortBy - description: | - Specifies the order of results, with syntax similar to $sort. - - - name: output - type: - - expression - description: | - Represents the output for each element in the group and can be any expression. + - name: sortBy + type: + - sortBy + description: | + Specifies the order of results, with syntax similar to $sort. + - name: output + type: + - expression + description: | + Represents the output for each element in the group and can be any expression. tests: - - - name: 'Find the Top Score' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/top/#find-the-top-score' - pipeline: - - - $match: - gameId: 'G1' - - - $group: - _id: '$gameId' - playerId: - $top: - output: - - '$playerId' - - '$score' - sortBy: - score: -1 - - - name: 'Find the Top Score Across Multiple Games' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/top/#find-the-top-score-across-multiple-games' - pipeline: - - - $group: - _id: '$gameId' - playerId: - $top: - output: - - '$playerId' - - '$score' - sortBy: - score: -1 + - name: Find the Top Score + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/top/#find-the-top-score + pipeline: + - $match: + gameId: G1 + - $group: + _id: $gameId + playerId: + $top: + output: + - $playerId + - $score + sortBy: + score: -1 + schema: + gamescores: + playerId: + types: + - bsonType: String + gameId: + types: + - bsonType: String + score: + types: + - bsonType: Number + - name: Find the Top Score Across Multiple Games + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/top/#find-the-top-score-across-multiple-games + pipeline: + - $group: + _id: $gameId + playerId: + $top: + output: + - $playerId + - $score + sortBy: + score: -1 + schema: + gamescores: + playerId: + types: + - bsonType: String + gameId: + types: + - bsonType: String + score: + types: + - bsonType: Number diff --git a/generator/config/accumulator/topN.yaml b/generator/config/accumulator/topN.yaml index c5eff6056..d2ab525b2 100644 --- a/generator/config/accumulator/topN.yaml +++ b/generator/config/accumulator/topN.yaml @@ -1,85 +1,107 @@ # $schema: ../schema.json name: $topN -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/topN/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/topN/ type: - accumulator encode: object description: | 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. arguments: - - - name: 'n' - type: - - resolvesToInt - description: | - limits the number of results per group and has to be a positive integral expression that is either a constant or depends on the _id value for $group. - - - name: sortBy - type: - - sortBy - description: | - Specifies the order of results, with syntax similar to $sort. - - - name: output - type: - - expression - description: | - Represents the output for each element in the group and can be any expression. + - name: n + type: + - resolvesToInt + description: | + limits the number of results per group and has to be a positive integral expression that is either a constant or depends on the _id value for $group. + - name: sortBy + type: + - sortBy + description: | + Specifies the order of results, with syntax similar to $sort. + - name: output + type: + - expression + description: | + Represents the output for each element in the group and can be any expression. tests: - - - name: 'Find the Three Highest Scores' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/topN/#find-the-three-highest-scores' - pipeline: - - - $match: - gameId: 'G1' - - - $group: - _id: '$gameId' - playerId: - $topN: - output: - - '$playerId' - - '$score' - sortBy: - score: -1 - n: 3 - - - name: 'Finding the Three Highest Score Documents Across Multiple Games' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/topN/#finding-the-three-highest-score-documents-across-multiple-games' - pipeline: - - - $group: - _id: '$gameId' - playerId: - $topN: - output: - - '$playerId' - - '$score' - sortBy: - score: -1 - n: 3 - - - name: 'Computing n Based on the Group Key for $group' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/topN/#computing-n-based-on-the-group-key-for--group' - pipeline: - - - $group: - _id: - gameId: '$gameId' - gamescores: - $topN: - output: '$score' - n: - $cond: - if: - $eq: - - '$gameId' - - 'G2' - then: 1 - else: 3 - sortBy: - score: -1 + - name: Find the Three Highest Scores + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/topN/#find-the-three-highest-scores + pipeline: + - $match: + gameId: G1 + - $group: + _id: $gameId + playerId: + $topN: + output: + - $playerId + - $score + sortBy: + score: -1 + n: 3 + schema: + gamescores: + playerId: + types: + - bsonType: String + gameId: + types: + - bsonType: String + score: + types: + - bsonType: Number + - name: Finding the Three Highest Score Documents Across Multiple Games + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/topN/#finding-the-three-highest-score-documents-across-multiple-games + pipeline: + - $group: + _id: $gameId + playerId: + $topN: + output: + - $playerId + - $score + sortBy: + score: -1 + n: 3 + schema: + gamescores: + playerId: + types: + - bsonType: String + gameId: + types: + - bsonType: String + score: + types: + - bsonType: Number + - name: Computing n Based on the Group Key for $group + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/topN/#computing-n-based-on-the-group-key-for--group + pipeline: + - $group: + _id: + gameId: $gameId + gamescores: + $topN: + output: $score + n: + $cond: + if: + $eq: + - $gameId + - G2 + then: 1 + else: 3 + sortBy: + score: -1 + schema: + gamescores: + playerId: + types: + - bsonType: String + gameId: + types: + - bsonType: String + score: + types: + - bsonType: Number diff --git a/generator/config/expression/abs.yaml b/generator/config/expression/abs.yaml index fe29e44e3..e610b1eba 100644 --- a/generator/config/expression/abs.yaml +++ b/generator/config/expression/abs.yaml @@ -1,25 +1,33 @@ # $schema: ../schema.json name: $abs -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/abs/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/abs/ type: - resolvesToNumber encode: single description: | Returns the absolute value of a number. arguments: - - - name: value - type: - - resolvesToNumber + - name: value + type: + - resolvesToNumber tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/abs/#example' - pipeline: - - - $project: - delta: - $abs: - $subtract: - - '$startTemp' - - '$endTemp' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/abs/#example + pipeline: + - $project: + delta: + $abs: + $subtract: + - $startTemp + - $endTemp + schema: + temperatureChange: + _id: + types: + - bsonType: Number + startTemp: + types: + - bsonType: Number + endTemp: + types: + - bsonType: Number diff --git a/generator/config/expression/acos.yaml b/generator/config/expression/acos.yaml index 7deca736d..2b2004623 100644 --- a/generator/config/expression/acos.yaml +++ b/generator/config/expression/acos.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $acos -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/acos/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/acos/ type: - resolvesToDouble - resolvesToDecimal @@ -8,24 +8,35 @@ encode: single description: | Returns the inverse cosine (arc cosine) of a value in radians. arguments: - - - name: expression - type: - - resolvesToNumber - description: | - $acos takes any valid expression that resolves to a number between -1 and 1, e.g. -1 <= value <= 1. - $acos returns values in radians. Use $radiansToDegrees operator to convert the output value from radians to degrees. - By default $acos returns values as a double. $acos can also return values as a 128-bit decimal as long as the expression resolves to a 128-bit decimal value. + - name: expression + type: + - resolvesToNumber + description: | + $acos takes any valid expression that resolves to a number between -1 and 1, e.g. -1 <= value <= 1. + $acos returns values in radians. Use $radiansToDegrees operator to convert the output value from radians to degrees. + By default $acos returns values as a double. $acos can also return values as a 128-bit decimal as long as the expression resolves to a 128-bit decimal value. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/acos/#example' - pipeline: - - - $addFields: - angle_a: - $radiansToDegrees: - $acos: - $divide: - - '$side_b' - - '$hypotenuse' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/acos/#example + pipeline: + - $addFields: + angle_a: + $radiansToDegrees: + $acos: + $divide: + - $side_b + - $hypotenuse + schema: + TestCollection: + _id: + types: + - bsonType: ObjectId + side_a: + types: + - bsonType: Decimal128 + side_b: + types: + - bsonType: Decimal128 + hypotenuse: + types: + - bsonType: Decimal128 diff --git a/generator/config/expression/acosh.yaml b/generator/config/expression/acosh.yaml index ce575e317..cd0510226 100644 --- a/generator/config/expression/acosh.yaml +++ b/generator/config/expression/acosh.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $acosh -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/acosh/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/acosh/ type: - resolvesToDouble - resolvesToDecimal @@ -8,21 +8,26 @@ encode: single description: | Returns the inverse hyperbolic cosine (hyperbolic arc cosine) of a value in radians. arguments: - - - name: expression - type: - - resolvesToNumber - description: | - $acosh takes any valid expression that resolves to a number between 1 and +Infinity, e.g. 1 <= value <= +Infinity. - $acosh returns values in radians. Use $radiansToDegrees operator to convert the output value from radians to degrees. - By default $acosh returns values as a double. $acosh can also return values as a 128-bit decimal as long as the expression resolves to a 128-bit decimal value. + - name: expression + type: + - resolvesToNumber + description: | + $acosh takes any valid expression that resolves to a number between 1 and +Infinity, e.g. 1 <= value <= +Infinity. + $acosh returns values in radians. Use $radiansToDegrees operator to convert the output value from radians to degrees. + By default $acosh returns values as a double. $acosh can also return values as a 128-bit decimal as long as the expression resolves to a 128-bit decimal value. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/acosh/#example' - pipeline: - - - $addFields: - y-coordinate: - $radiansToDegrees: - $acosh: '$x-coordinate' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/acosh/#example + pipeline: + - $addFields: + y-coordinate: + $radiansToDegrees: + $acosh: $x-coordinate + schema: + TestCollection: + _id: + types: + - bsonType: ObjectId + x-coordinate: + types: + - bsonType: Decimal128 diff --git a/generator/config/expression/add.yaml b/generator/config/expression/add.yaml index fa23253d0..27268071d 100644 --- a/generator/config/expression/add.yaml +++ b/generator/config/expression/add.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $add -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/add/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/add/ type: - resolvesToInt - resolvesToLong @@ -11,34 +11,63 @@ encode: single description: | 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. arguments: - - - name: expression - type: - - resolvesToNumber - - resolvesToDate - variadic: array - description: | - The arguments can be any valid expression as long as they resolve to either all numbers or to numbers and a date. + - name: expression + type: + - resolvesToNumber + - resolvesToDate + variadic: array + description: | + The arguments can be any valid expression as long as they resolve to either all numbers or to numbers and a date. tests: - - - name: 'Add Numbers' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/add/#add-numbers' - pipeline: - - - $project: - item: 1 - total: - $add: - - '$price' - - '$fee' - - - name: 'Perform Addition on a Date' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/add/#perform-addition-on-a-date' - pipeline: - - - $project: - item: 1 - billing_date: - $add: - - '$date' - - 259200000 + - name: Add Numbers + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/add/#add-numbers + pipeline: + - $project: + item: 1 + total: + $add: + - $price + - $fee + schema: + sales: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + price: + types: + - bsonType: Number + fee: + types: + - bsonType: Number + date: + types: + - bsonType: Date + - name: Perform Addition on a Date + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/add/#perform-addition-on-a-date + pipeline: + - $project: + item: 1 + billing_date: + $add: + - $date + - 259200000 + schema: + sales: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + price: + types: + - bsonType: Number + fee: + types: + - bsonType: Number + date: + types: + - bsonType: Date diff --git a/generator/config/expression/allElementsTrue.yaml b/generator/config/expression/allElementsTrue.yaml index 7301f8d68..dfdcbf3c6 100644 --- a/generator/config/expression/allElementsTrue.yaml +++ b/generator/config/expression/allElementsTrue.yaml @@ -1,25 +1,40 @@ # $schema: ../schema.json name: $allElementsTrue -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/allElementsTrue/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/allElementsTrue/ type: - resolvesToBool encode: array description: | Returns true if no element of a set evaluates to false, otherwise, returns false. Accepts a single argument expression. arguments: - - - name: expression - type: - - resolvesToArray + - name: expression + type: + - resolvesToArray tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/allElementsTrue/#example' - pipeline: - - - $project: - responses: 1 - isAllTrue: - $allElementsTrue: - - '$responses' - _id: 0 + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/allElementsTrue/#example + pipeline: + - $project: + responses: 1 + isAllTrue: + $allElementsTrue: + - $responses + _id: 0 + schema: + survey: + _id: + types: + - bsonType: Number + responses: + types: + - bsonType: Array + types: + - bsonType: Boolean + - bsonType: Array + types: + - bsonType: Number + - bsonType: Boolean + - bsonType: Number + - bsonType: String + - bsonType: 'Null' + - bsonType: Undefined diff --git a/generator/config/expression/and.yaml b/generator/config/expression/and.yaml index 96057d249..a0f516e20 100644 --- a/generator/config/expression/and.yaml +++ b/generator/config/expression/and.yaml @@ -1,37 +1,46 @@ # $schema: ../schema.json name: $and -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/and/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/and/ type: - resolvesToBool encode: single description: | Returns true only when all its expressions evaluate to true. Accepts any number of argument expressions. arguments: - - - name: expression - type: - - expression - - resolvesToBool - - resolvesToNumber - - resolvesToString - - resolvesToNull - variadic: array + - name: expression + type: + - expression + - resolvesToBool + - resolvesToNumber + - resolvesToString + - resolvesToNull + variadic: array tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/and/#example' - pipeline: - - - $project: - item: 1 - qty: 1 - result: - $and: - - - $gt: - - '$qty' - - 100 - - - $lt: - - '$qty' - - 250 + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/and/#example + pipeline: + - $project: + item: 1 + qty: 1 + result: + $and: + - $gt: + - $qty + - 100 + - $lt: + - $qty + - 250 + schema: + inventory: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + description: + types: + - bsonType: String + qty: + types: + - bsonType: Number diff --git a/generator/config/expression/anyElementTrue.yaml b/generator/config/expression/anyElementTrue.yaml index 50fe665b6..ba3ef49af 100644 --- a/generator/config/expression/anyElementTrue.yaml +++ b/generator/config/expression/anyElementTrue.yaml @@ -1,25 +1,40 @@ # $schema: ../schema.json name: $anyElementTrue -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/anyElementTrue/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/anyElementTrue/ type: - resolvesToBool encode: array description: | Returns true if any elements of a set evaluate to true; otherwise, returns false. Accepts a single argument expression. arguments: - - - name: expression - type: - - resolvesToArray + - name: expression + type: + - resolvesToArray tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/anyElementTrue/#example' - pipeline: - - - $project: - responses: 1 - isAnyTrue: - $anyElementTrue: - - '$responses' - _id: 0 + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/anyElementTrue/#example + pipeline: + - $project: + responses: 1 + isAnyTrue: + $anyElementTrue: + - $responses + _id: 0 + schema: + survey: + _id: + types: + - bsonType: Number + responses: + types: + - bsonType: Array + types: + - bsonType: Boolean + - bsonType: Array + types: + - bsonType: Number + - bsonType: Boolean + - bsonType: Number + - bsonType: String + - bsonType: 'Null' + - bsonType: Undefined diff --git a/generator/config/expression/arrayElemAt.yaml b/generator/config/expression/arrayElemAt.yaml index 09fe9dae1..c774ebca4 100644 --- a/generator/config/expression/arrayElemAt.yaml +++ b/generator/config/expression/arrayElemAt.yaml @@ -1,33 +1,42 @@ # $schema: ../schema.json name: $arrayElemAt -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/arrayElemAt/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/arrayElemAt/ type: - resolvesToAny encode: array description: | Returns the element at the specified array index. arguments: - - - name: array - type: - - resolvesToArray - - - name: idx - type: - - resolvesToInt + - name: array + type: + - resolvesToArray + - name: idx + type: + - resolvesToInt tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/arrayElemAt/#example' - pipeline: - - - $project: - name: 1 - first: - $arrayElemAt: - - '$favorites' - - 0 - last: - $arrayElemAt: - - '$favorites' - - -1 + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/arrayElemAt/#example + pipeline: + - $project: + name: 1 + first: + $arrayElemAt: + - $favorites + - 0 + last: + $arrayElemAt: + - $favorites + - -1 + schema: + users: + _id: + types: + - bsonType: Number + name: + types: + - bsonType: String + favorites: + types: + - bsonType: Array + types: + - bsonType: String diff --git a/generator/config/expression/arrayToObject.yaml b/generator/config/expression/arrayToObject.yaml index 87026f7a7..203ab7968 100644 --- a/generator/config/expression/arrayToObject.yaml +++ b/generator/config/expression/arrayToObject.yaml @@ -1,50 +1,85 @@ # $schema: ../schema.json name: $arrayToObject -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/arrayToObject/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/arrayToObject/ type: - resolvesToObject encode: array description: | Converts an array of key value pairs to a document. arguments: - - - name: array - type: - - resolvesToArray + - name: array + type: + - resolvesToArray tests: - - - name: '$arrayToObject Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/arrayToObject/#-arraytoobject--example' - pipeline: - - - $project: - item: 1 - dimensions: - # Example uses the short form, the builder always generates the verbose form - # $arrayToObject: '$dimensions' - $arrayToObject: - - '$dimensions' - - - name: '$objectToArray and $arrayToObject Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/arrayToObject/#-objecttoarray----arraytoobject-example' - pipeline: - - - $addFields: - instock: - $objectToArray: '$instock' - - - $addFields: - instock: - $concatArrays: - - '$instock' - - - - - k: 'total' - v: - $sum: - - '$instock.v' - - - $addFields: - instock: - $arrayToObject: - - '$instock' + - name: $arrayToObject Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/arrayToObject/#-arraytoobject--example + pipeline: + - $project: + item: 1 + dimensions: + $arrayToObject: + - $dimensions + schema: + inventory: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + dimensions: + types: + - bsonType: Array + types: + - bsonType: Array + types: + - bsonType: String + - bsonType: Number + - bsonType: Document + fields: + k: + types: + - bsonType: String + v: + types: + - bsonType: Number + - bsonType: String + - name: $objectToArray and $arrayToObject Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/arrayToObject/#-objecttoarray----arraytoobject-example + pipeline: + - $addFields: + instock: + $objectToArray: $instock + - $addFields: + instock: + $concatArrays: + - $instock + - - k: total + v: + $sum: + - $instock.v + - $addFields: + instock: + $arrayToObject: + - $instock + schema: + inventory: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + instock: + types: + - bsonType: Document + fields: + warehouse1: + types: + - bsonType: Number + warehouse2: + types: + - bsonType: Number + warehouse3: + types: + - bsonType: Number diff --git a/generator/config/expression/asin.yaml b/generator/config/expression/asin.yaml index 43e2832a2..2c0f05064 100644 --- a/generator/config/expression/asin.yaml +++ b/generator/config/expression/asin.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $asin -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/asin/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/asin/ type: - resolvesToDouble - resolvesToDecimal @@ -8,24 +8,35 @@ encode: single description: | Returns the inverse sin (arc sine) of a value in radians. arguments: - - - name: expression - type: - - resolvesToNumber - description: | - $asin takes any valid expression that resolves to a number between -1 and 1, e.g. -1 <= value <= 1. - $asin returns values in radians. Use $radiansToDegrees operator to convert the output value from radians to degrees. - By default $asin returns values as a double. $asin can also return values as a 128-bit decimal as long as the expression resolves to a 128-bit decimal value. + - name: expression + type: + - resolvesToNumber + description: | + $asin takes any valid expression that resolves to a number between -1 and 1, e.g. -1 <= value <= 1. + $asin returns values in radians. Use $radiansToDegrees operator to convert the output value from radians to degrees. + By default $asin returns values as a double. $asin can also return values as a 128-bit decimal as long as the expression resolves to a 128-bit decimal value. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/asin/#example' - pipeline: - - - $addFields: - angle_a: - $radiansToDegrees: - $asin: - $divide: - - '$side_a' - - '$hypotenuse' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/asin/#example + pipeline: + - $addFields: + angle_a: + $radiansToDegrees: + $asin: + $divide: + - $side_a + - $hypotenuse + schema: + TestCollection: + _id: + types: + - bsonType: ObjectId + side_a: + types: + - bsonType: Decimal128 + side_b: + types: + - bsonType: Decimal128 + hypotenuse: + types: + - bsonType: Decimal128 diff --git a/generator/config/expression/asinh.yaml b/generator/config/expression/asinh.yaml index 6d45c14fa..9870a9ee5 100644 --- a/generator/config/expression/asinh.yaml +++ b/generator/config/expression/asinh.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $asinh -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/asinh/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/asinh/ type: - resolvesToDouble - resolvesToDecimal @@ -8,21 +8,26 @@ encode: single description: | Returns the inverse hyperbolic sine (hyperbolic arc sine) of a value in radians. arguments: - - - name: expression - type: - - resolvesToNumber - description: | - $asinh takes any valid expression that resolves to a number. - $asinh returns values in radians. Use $radiansToDegrees operator to convert the output value from radians to degrees. - By default $asinh returns values as a double. $asinh can also return values as a 128-bit decimal as long as the expression resolves to a 128-bit decimal value. + - name: expression + type: + - resolvesToNumber + description: | + $asinh takes any valid expression that resolves to a number. + $asinh returns values in radians. Use $radiansToDegrees operator to convert the output value from radians to degrees. + By default $asinh returns values as a double. $asinh can also return values as a 128-bit decimal as long as the expression resolves to a 128-bit decimal value. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/asinh/#example' - pipeline: - - - $addFields: - y-coordinate: - $radiansToDegrees: - $asinh: '$x-coordinate' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/asinh/#example + pipeline: + - $addFields: + y-coordinate: + $radiansToDegrees: + $asinh: $x-coordinate + schema: + TestCollection: + _id: + types: + - bsonType: ObjectId + x-coordinate: + types: + - bsonType: Decimal128 diff --git a/generator/config/expression/atan.yaml b/generator/config/expression/atan.yaml index a8bb1674f..242209a26 100644 --- a/generator/config/expression/atan.yaml +++ b/generator/config/expression/atan.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $atan -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/atan/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/atan/ type: - resolvesToDouble - resolvesToDecimal @@ -8,24 +8,35 @@ encode: single description: | Returns the inverse tangent (arc tangent) of a value in radians. arguments: - - - name: expression - type: - - resolvesToNumber - description: | - $atan takes any valid expression that resolves to a number. - $atan returns values in radians. Use $radiansToDegrees operator to convert the output value from radians to degrees. - By default $atan returns values as a double. $atan can also return values as a 128-bit decimal as long as the expression resolves to a 128-bit decimal value. + - name: expression + type: + - resolvesToNumber + description: | + $atan takes any valid expression that resolves to a number. + $atan returns values in radians. Use $radiansToDegrees operator to convert the output value from radians to degrees. + By default $atan returns values as a double. $atan can also return values as a 128-bit decimal as long as the expression resolves to a 128-bit decimal value. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/atan/#example' - pipeline: - - - $addFields: - angle_a: - $radiansToDegrees: - $atan: - $divide: - - '$side_b' - - '$side_a' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/atan/#example + pipeline: + - $addFields: + angle_a: + $radiansToDegrees: + $atan: + $divide: + - $side_b + - $side_a + schema: + TestCollection: + _id: + types: + - bsonType: ObjectId + side_a: + types: + - bsonType: Decimal128 + side_b: + types: + - bsonType: Decimal128 + hypotenuse: + types: + - bsonType: Decimal128 diff --git a/generator/config/expression/atan2.yaml b/generator/config/expression/atan2.yaml index 1abc55e6a..38b1c5cf4 100644 --- a/generator/config/expression/atan2.yaml +++ b/generator/config/expression/atan2.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $atan2 -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/atan2/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/atan2/ type: - resolvesToDouble - resolvesToDecimal @@ -8,27 +8,37 @@ encode: array description: | 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. arguments: - - - name: 'y' - type: - - resolvesToNumber - description: | - $atan2 takes any valid expression that resolves to a number. - $atan2 returns values in radians. Use $radiansToDegrees operator to convert the output value from radians to degrees. - By default $atan returns values as a double. $atan2 can also return values as a 128-bit decimal as long as the expression resolves to a 128-bit decimal value. - - - name: x - type: - - resolvesToNumber + - name: y + type: + - resolvesToNumber + description: | + $atan2 takes any valid expression that resolves to a number. + $atan2 returns values in radians. Use $radiansToDegrees operator to convert the output value from radians to degrees. + By default $atan returns values as a double. $atan2 can also return values as a 128-bit decimal as long as the expression resolves to a 128-bit decimal value. + - name: x + type: + - resolvesToNumber tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/atan2/#example' - pipeline: - - - $addFields: - angle_a: - $radiansToDegrees: - $atan2: - - '$side_b' - - '$side_a' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/atan2/#example + pipeline: + - $addFields: + angle_a: + $radiansToDegrees: + $atan2: + - $side_b + - $side_a + schema: + TestCollection: + _id: + types: + - bsonType: ObjectId + side_a: + types: + - bsonType: Decimal128 + side_b: + types: + - bsonType: Decimal128 + hypotenuse: + types: + - bsonType: Decimal128 diff --git a/generator/config/expression/atanh.yaml b/generator/config/expression/atanh.yaml index 501fba2bf..dba39aa30 100644 --- a/generator/config/expression/atanh.yaml +++ b/generator/config/expression/atanh.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $atanh -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/atanh/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/atanh/ type: - resolvesToDouble - resolvesToDecimal @@ -8,21 +8,26 @@ encode: single description: | Returns the inverse hyperbolic tangent (hyperbolic arc tangent) of a value in radians. arguments: - - - name: expression - type: - - resolvesToNumber - description: | - $atanh takes any valid expression that resolves to a number between -1 and 1, e.g. -1 <= value <= 1. - $atanh returns values in radians. Use $radiansToDegrees operator to convert the output value from radians to degrees. - By default $atanh returns values as a double. $atanh can also return values as a 128-bit decimal as long as the expression resolves to a 128-bit decimal value. + - name: expression + type: + - resolvesToNumber + description: | + $atanh takes any valid expression that resolves to a number between -1 and 1, e.g. -1 <= value <= 1. + $atanh returns values in radians. Use $radiansToDegrees operator to convert the output value from radians to degrees. + By default $atanh returns values as a double. $atanh can also return values as a 128-bit decimal as long as the expression resolves to a 128-bit decimal value. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/atanh/#example' - pipeline: - - - $addFields: - y-coordinate: - $radiansToDegrees: - $atanh: '$x-coordinate' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/atanh/#example + pipeline: + - $addFields: + y-coordinate: + $radiansToDegrees: + $atanh: $x-coordinate + schema: + TestCollection: + _id: + types: + - bsonType: ObjectId + x-coordinate: + types: + - bsonType: Decimal128 diff --git a/generator/config/expression/avg.yaml b/generator/config/expression/avg.yaml index 3bb771936..a81686101 100644 --- a/generator/config/expression/avg.yaml +++ b/generator/config/expression/avg.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $avg -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/avg/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/avg/ type: - resolvesToNumber encode: single @@ -8,28 +8,41 @@ description: | Returns an average of numerical values. Ignores non-numeric values. Changed in MongoDB 5.0: Available in the $setWindowFields stage. arguments: - - - name: expression - type: - - resolvesToNumber - variadic: array + - name: expression + type: + - resolvesToNumber + variadic: array tests: - - - name: 'Use in $project Stage' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/avg/#use-in--project-stage' - pipeline: - - - $project: - quizAvg: - # Example uses the short form, the builder always generates the verbose form - # $avg: '$quizzes' - $avg: - - '$quizzes' - labAvg: - # $avg: '$labs' - $avg: - - '$labs' - examAvg: - $avg: - - '$final' - - '$midterm' + - name: Use in $project Stage + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/avg/#use-in--project-stage + pipeline: + - $project: + quizAvg: + $avg: $quizzes + labAvg: + $avg: $labs + examAvg: + $avg: + - $final + - $midterm + schema: + TestCollection: + _id: + types: + - bsonType: Number + quizzes: + types: + - bsonType: Array + types: + - bsonType: Number + labs: + types: + - bsonType: Array + types: + - bsonType: Number + final: + types: + - bsonType: Number + midterm: + types: + - bsonType: Number diff --git a/generator/config/expression/binarySize.yaml b/generator/config/expression/binarySize.yaml index eb0146f8c..f74f4c51d 100644 --- a/generator/config/expression/binarySize.yaml +++ b/generator/config/expression/binarySize.yaml @@ -1,25 +1,33 @@ # $schema: ../schema.json name: $binarySize -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/binarySize/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/binarySize/ type: - resolvesToInt encode: single description: | Returns the size of a given string or binary data value's content in bytes. arguments: - - - name: expression - type: - - resolvesToString - - resolvesToBinData - - resolvesToNull + - name: expression + type: + - resolvesToString + - resolvesToBinData + - resolvesToNull tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/binarySize/#example' - pipeline: - - - $project: - name: '$name' - imageSize: - $binarySize: '$binary' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/binarySize/#example + pipeline: + - $project: + name: $name + imageSize: + $binarySize: $binary + schema: + images: + _id: + types: + - bsonType: Number + name: + types: + - bsonType: String + binary: + types: + - bsonType: Binary diff --git a/generator/config/expression/bitAnd.yaml b/generator/config/expression/bitAnd.yaml index 271cc0973..e40c79ee5 100644 --- a/generator/config/expression/bitAnd.yaml +++ b/generator/config/expression/bitAnd.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $bitAnd -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitAnd/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitAnd/ type: - resolvesToInt - resolvesToLong @@ -9,30 +9,47 @@ description: | Returns the result of a bitwise and operation on an array of int or long values. New in MongoDB 6.3. arguments: - - - name: expression - type: - - resolvesToInt - - resolvesToLong - variadic: array + - name: expression + type: + - resolvesToInt + - resolvesToLong + variadic: array tests: - - - name: 'Bitwise AND with Two Integers' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitAnd/#bitwise-and-with-two-integers' - pipeline: - - - $project: - result: - $bitAnd: - - '$a' - - '$b' - - - name: 'Bitwise AND with a Long and Integer' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitAnd/#bitwise-and-with-a-long-and-integer' - pipeline: - - - $project: - result: - $bitAnd: - - '$a' - - { "$numberLong": "63" } + - name: Bitwise AND with Two Integers + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitAnd/#bitwise-and-with-two-integers + pipeline: + - $project: + result: + $bitAnd: + - $a + - $b + schema: + switches: + _id: + types: + - bsonType: Number + a: + types: + - bsonType: Int32 + b: + types: + - bsonType: Int32 + - name: Bitwise AND with a Long and Integer + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitAnd/#bitwise-and-with-a-long-and-integer + pipeline: + - $project: + result: + $bitAnd: + - $a + - $numberLong: '63' + schema: + switches: + _id: + types: + - bsonType: Number + a: + types: + - bsonType: Int32 + b: + types: + - bsonType: Int32 diff --git a/generator/config/expression/bitNot.yaml b/generator/config/expression/bitNot.yaml index 5211fa42a..99de490e0 100644 --- a/generator/config/expression/bitNot.yaml +++ b/generator/config/expression/bitNot.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $bitNot -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitNot/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitNot/ type: - resolvesToInt - resolvesToLong @@ -9,17 +9,25 @@ description: | 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. arguments: - - - name: expression - type: - - resolvesToInt - - resolvesToLong + - name: expression + type: + - resolvesToInt + - resolvesToLong tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitNot/#example' - pipeline: - - - $project: - result: - $bitNot: '$a' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitNot/#example + pipeline: + - $project: + result: + $bitNot: $a + schema: + switches: + _id: + types: + - bsonType: Number + a: + types: + - bsonType: Int32 + b: + types: + - bsonType: Int32 diff --git a/generator/config/expression/bitOr.yaml b/generator/config/expression/bitOr.yaml index 084ac224c..f5c4c504b 100644 --- a/generator/config/expression/bitOr.yaml +++ b/generator/config/expression/bitOr.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $bitOr -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitOr/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitOr/ type: - resolvesToInt - resolvesToLong @@ -9,30 +9,47 @@ description: | Returns the result of a bitwise or operation on an array of int or long values. New in MongoDB 6.3. arguments: - - - name: expression - type: - - resolvesToInt - - resolvesToLong - variadic: array + - name: expression + type: + - resolvesToInt + - resolvesToLong + variadic: array tests: - - - name: 'Bitwise OR with Two Integers' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitOr/#bitwise-or-with-two-integers' - pipeline: - - - $project: - result: - $bitOr: - - '$a' - - '$b' - - - name: 'Bitwise OR with a Long and Integer' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitOr/#bitwise-or-with-a-long-and-integer' - pipeline: - - - $project: - result: - $bitOr: - - '$a' - - { "$numberLong": "63" } + - name: Bitwise OR with Two Integers + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitOr/#bitwise-or-with-two-integers + pipeline: + - $project: + result: + $bitOr: + - $a + - $b + schema: + switches: + _id: + types: + - bsonType: Number + a: + types: + - bsonType: Int32 + b: + types: + - bsonType: Int32 + - name: Bitwise OR with a Long and Integer + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitOr/#bitwise-or-with-a-long-and-integer + pipeline: + - $project: + result: + $bitOr: + - $a + - $numberLong: '63' + schema: + switches: + _id: + types: + - bsonType: Number + a: + types: + - bsonType: Int32 + b: + types: + - bsonType: Int32 diff --git a/generator/config/expression/bitXor.yaml b/generator/config/expression/bitXor.yaml index f4acc4df4..ff5f72813 100644 --- a/generator/config/expression/bitXor.yaml +++ b/generator/config/expression/bitXor.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $bitXor -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitXor/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitXor/ type: - resolvesToInt - resolvesToLong @@ -9,20 +9,28 @@ description: | Returns the result of a bitwise xor (exclusive or) operation on an array of int and long values. New in MongoDB 6.3. arguments: - - - name: expression - type: - - resolvesToInt - - resolvesToLong - variadic: array + - name: expression + type: + - resolvesToInt + - resolvesToLong + variadic: array tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitXor/#example' - pipeline: - - - $project: - result: - $bitXor: - - '$a' - - '$b' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitXor/#example + pipeline: + - $project: + result: + $bitXor: + - $a + - $b + schema: + switches: + _id: + types: + - bsonType: Number + a: + types: + - bsonType: Int32 + b: + types: + - bsonType: Int32 diff --git a/generator/config/expression/bsonSize.yaml b/generator/config/expression/bsonSize.yaml index 712188c52..a4fe1d7c3 100644 --- a/generator/config/expression/bsonSize.yaml +++ b/generator/config/expression/bsonSize.yaml @@ -1,48 +1,141 @@ # $schema: ../schema.json name: $bsonSize -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/bsonSize/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/bsonSize/ type: - resolvesToInt encode: single description: | Returns the size in bytes of a given document (i.e. BSON type Object) when encoded as BSON. arguments: - - - name: object - type: - - resolvesToObject - - resolvesToNull + - name: object + type: + - resolvesToObject + - resolvesToNull tests: - - - name: 'Return Sizes of Documents' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/bsonSize/#return-sizes-of-documents' - pipeline: - - - $project: - name: 1 - object_size: - $bsonSize: '$$ROOT' - - - name: 'Return Combined Size of All Documents in a Collection' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/bsonSize/#return-combined-size-of-all-documents-in-a-collection' - pipeline: - - - $group: - _id: ~ - combined_object_size: - $sum: - $bsonSize: '$$ROOT' - - - name: 'Return Document with Largest Specified Field' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/bsonSize/#return-document-with-largest-specified-field' - pipeline: - - - $project: - name: '$name' - task_object_size: - $bsonSize: '$current_task' - - - $sort: - task_object_size: -1 - - - $limit: 1 + - name: Return Sizes of Documents + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/bsonSize/#return-sizes-of-documents + pipeline: + - $project: + name: 1 + object_size: + $bsonSize: $$ROOT + schema: + employees: + _id: + types: + - bsonType: Number + name: + types: + - bsonType: String + email: + types: + - bsonType: String + position: + types: + - bsonType: String + current_task: + types: + - bsonType: Document + fields: + project_id: + types: + - bsonType: Number + project_name: + types: + - bsonType: String + project_duration: + types: + - bsonType: Number + hours: + types: + - bsonType: Number + notes: + types: + - bsonType: String + - bsonType: 'Null' + - name: Return Combined Size of All Documents in a Collection + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/bsonSize/#return-combined-size-of-all-documents-in-a-collection + pipeline: + - $group: + _id: ~ + combined_object_size: + $sum: + $bsonSize: $$ROOT + schema: + employees: + _id: + types: + - bsonType: Number + name: + types: + - bsonType: String + email: + types: + - bsonType: String + position: + types: + - bsonType: String + current_task: + types: + - bsonType: Document + fields: + project_id: + types: + - bsonType: Number + project_name: + types: + - bsonType: String + project_duration: + types: + - bsonType: Number + hours: + types: + - bsonType: Number + notes: + types: + - bsonType: String + - bsonType: 'Null' + - name: Return Document with Largest Specified Field + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/bsonSize/#return-document-with-largest-specified-field + pipeline: + - $project: + name: $name + task_object_size: + $bsonSize: $current_task + - $sort: + task_object_size: -1 + - $limit: 1 + schema: + employees: + _id: + types: + - bsonType: Number + name: + types: + - bsonType: String + email: + types: + - bsonType: String + position: + types: + - bsonType: String + current_task: + types: + - bsonType: Document + fields: + project_id: + types: + - bsonType: Number + project_name: + types: + - bsonType: String + project_duration: + types: + - bsonType: Number + hours: + types: + - bsonType: Number + notes: + types: + - bsonType: String + - bsonType: 'Null' diff --git a/generator/config/expression/case.yaml b/generator/config/expression/case.yaml index ccf463c90..8c5cd9145 100644 --- a/generator/config/expression/case.yaml +++ b/generator/config/expression/case.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $case -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/switch/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/switch/ type: - switchBranch encode: object @@ -8,15 +8,12 @@ wrapObject: false description: | Represents a single case in a $switch expression arguments: - - - name: case - type: - - resolvesToBool - description: | - Can be any valid expression that resolves to a boolean. If the result is not a boolean, it is coerced to a boolean value. More information about how MongoDB evaluates expressions as either true or false can be found here. - - - name: then - type: - - expression - description: | - Can be any valid expression. + - name: case + type: + - resolvesToBool + description: | + Can be any valid expression that resolves to a boolean. If the result is not a boolean, it is coerced to a boolean value. More information about how MongoDB evaluates expressions as either true or false can be found here. + - name: then + type: + - expression + description: Can be any valid expression. diff --git a/generator/config/expression/ceil.yaml b/generator/config/expression/ceil.yaml index 73c31ddb7..624907476 100644 --- a/generator/config/expression/ceil.yaml +++ b/generator/config/expression/ceil.yaml @@ -1,25 +1,30 @@ # $schema: ../schema.json name: $ceil -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/ceil/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/ceil/ type: - resolvesToInt encode: single description: | Returns the smallest integer greater than or equal to the specified number. arguments: - - - name: expression - type: - - resolvesToNumber - description: | - If the argument resolves to a value of null or refers to a field that is missing, $ceil returns null. If the argument resolves to NaN, $ceil returns NaN. + - name: expression + type: + - resolvesToNumber + description: | + If the argument resolves to a value of null or refers to a field that is missing, $ceil returns null. If the argument resolves to NaN, $ceil returns NaN. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/ceil/#example' - pipeline: - - - $project: - value: 1 - ceilingValue: - $ceil: '$value' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/ceil/#example + pipeline: + - $project: + value: 1 + ceilingValue: + $ceil: $value + schema: + samples: + _id: + types: + - bsonType: Number + value: + types: + - bsonType: Number diff --git a/generator/config/expression/cmp.yaml b/generator/config/expression/cmp.yaml index dd24f9839..718a9dc8c 100644 --- a/generator/config/expression/cmp.yaml +++ b/generator/config/expression/cmp.yaml @@ -1,31 +1,41 @@ # $schema: ../schema.json name: $cmp -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/cmp/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/cmp/ type: - resolvesToInt encode: array description: | 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. arguments: - - - name: expression1 - type: - - expression - - - name: expression2 - type: - - expression + - name: expression1 + type: + - expression + - name: expression2 + type: + - expression tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/cmp/#example' - pipeline: - - - $project: - item: 1 - qty: 1 - cmpTo250: - $cmp: - - '$qty' - - 250 - _id: 0 + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/cmp/#example + pipeline: + - $project: + item: 1 + qty: 1 + cmpTo250: + $cmp: + - $qty + - 250 + _id: 0 + schema: + inventory: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + description: + types: + - bsonType: String + qty: + types: + - bsonType: Number diff --git a/generator/config/expression/concat.yaml b/generator/config/expression/concat.yaml index e8b218d82..67cc439a0 100644 --- a/generator/config/expression/concat.yaml +++ b/generator/config/expression/concat.yaml @@ -1,26 +1,38 @@ # $schema: ../schema.json name: $concat -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/concat/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/concat/ type: - resolvesToString encode: single description: | Concatenates any number of strings. arguments: - - - name: expression - type: - - resolvesToString - variadic: array + - name: expression + type: + - resolvesToString + variadic: array tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/concat/#examples' - pipeline: - - - $project: - itemDescription: - $concat: - - '$item' - - ' - ' - - '$description' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/concat/#example + pipeline: + - $project: + itemDescription: + $concat: + - $item + - ' - ' + - $description + schema: + inventory: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + quarter: + types: + - bsonType: String + description: + types: + - bsonType: String + - bsonType: 'Null' diff --git a/generator/config/expression/concatArrays.yaml b/generator/config/expression/concatArrays.yaml index 026541092..23be611cf 100644 --- a/generator/config/expression/concatArrays.yaml +++ b/generator/config/expression/concatArrays.yaml @@ -1,25 +1,37 @@ # $schema: ../schema.json name: $concatArrays -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/concatArrays/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/concatArrays/ type: - resolvesToArray encode: single description: | Concatenates arrays to return the concatenated array. arguments: - - - name: array - type: - - resolvesToArray - variadic: array + - name: array + type: + - resolvesToArray + variadic: array tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/concatArrays/#example' - pipeline: - - - $project: - items: - $concatArrays: - - '$instock' - - '$ordered' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/concatArrays/#example + pipeline: + - $project: + items: + $concatArrays: + - $instock + - $ordered + schema: + warehouses: + _id: + types: + - bsonType: Number + instock: + types: + - bsonType: Array + types: + - bsonType: String + ordered: + types: + - bsonType: Array + types: + - bsonType: String diff --git a/generator/config/expression/cond.yaml b/generator/config/expression/cond.yaml index e2fd66ad7..12d4be93b 100644 --- a/generator/config/expression/cond.yaml +++ b/generator/config/expression/cond.yaml @@ -1,37 +1,43 @@ # $schema: ../schema.json name: $cond -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/cond/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/cond/ type: - resolvesToAny encode: object description: | 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. arguments: - - - name: if - type: - - resolvesToBool - - - name: then - type: - - expression - - - name: else - type: - - expression + - name: if + type: + - resolvesToBool + - name: then + type: + - expression + - name: else + type: + - expression tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/cond/#example' - pipeline: - - - $project: - item: 1 - discount: - $cond: - if: - $gte: - - '$qty' - - 250 - then: 30 - else: 20 + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/cond/#example + pipeline: + - $project: + item: 1 + discount: + $cond: + if: + $gte: + - $qty + - 250 + then: 30 + else: 20 + schema: + inventory: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + qty: + types: + - bsonType: Number diff --git a/generator/config/expression/convert.yaml b/generator/config/expression/convert.yaml index a76311ed5..a136bfdd1 100644 --- a/generator/config/expression/convert.yaml +++ b/generator/config/expression/convert.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $convert -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/convert/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/convert/ type: - resolvesToAny encode: object @@ -8,75 +8,79 @@ description: | Converts a value to a specified type. New in MongoDB 4.0. arguments: - - - name: input - type: - - expression - - - name: to - type: - - resolvesToString - - resolvesToInt - - - name: onError - type: - - expression - optional: true - description: | - The value to return on encountering an error during conversion, including unsupported type conversions. The arguments can be any valid expression. - If unspecified, the operation throws an error upon encountering an error and stops. - - - name: onNull - type: - - expression - optional: true - description: | - The value to return if the input is null or missing. The arguments can be any valid expression. - If unspecified, $convert returns null if the input is null or missing. + - name: input + type: + - expression + - name: to + type: + - resolvesToString + - resolvesToInt + - name: onError + type: + - expression + optional: true + description: | + The value to return on encountering an error during conversion, including unsupported type conversions. The arguments can be any valid expression. + If unspecified, the operation throws an error upon encountering an error and stops. + - name: onNull + type: + - expression + optional: true + description: | + The value to return if the input is null or missing. The arguments can be any valid expression. + If unspecified, $convert returns null if the input is null or missing. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/convert/#example' - pipeline: - - - $addFields: - convertedPrice: - $convert: - input: '$price' - to: 'decimal' - onError: 'Error' - onNull: !bson_decimal128 '0' - convertedQty: - $convert: - input: '$qty' - to: 'int' - onError: - $concat: - - 'Could not convert ' - - - $toString: '$qty' - - ' to type integer.' - onNull: 0 - - - $project: - totalPrice: - $switch: - branches: - - - case: - $eq: - - - $type: '$convertedPrice' - - 'string' - then: 'NaN' - - - case: - $eq: - - - $type: '$convertedQty' - - 'string' - then: 'NaN' - default: - $multiply: - - '$convertedPrice' - - '$convertedQty' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/convert/#example + pipeline: + - $addFields: + convertedPrice: + $convert: + input: $price + to: decimal + onError: Error + onNull: !bson_decimal128 '0' + convertedQty: + $convert: + input: $qty + to: int + onError: + $concat: + - 'Could not convert ' + - $toString: $qty + - ' to type integer.' + onNull: 0 + - $project: + totalPrice: + $switch: + branches: + - case: + $eq: + - $type: $convertedPrice + - string + then: NaN + - case: + $eq: + - $type: $convertedQty + - string + then: NaN + default: + $multiply: + - $convertedPrice + - $convertedQty + schema: + orders: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + qty: + types: + - bsonType: Number + price: + types: + - bsonType: Decimal128 + - bsonType: Number + - bsonType: String diff --git a/generator/config/expression/cos.yaml b/generator/config/expression/cos.yaml index 0b47670cf..d67ab659d 100644 --- a/generator/config/expression/cos.yaml +++ b/generator/config/expression/cos.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $cos -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/cos/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/cos/ type: - resolvesToDouble - resolvesToDecimal @@ -8,23 +8,30 @@ encode: single description: | Returns the cosine of a value that is measured in radians. arguments: - - - name: expression - type: - - resolvesToNumber - description: | - $cos takes any valid expression that resolves to a number. If the expression returns a value in degrees, use the $degreesToRadians operator to convert the result to radians. - By default $cos returns values as a double. $cos can also return values as a 128-bit decimal as long as the resolves to a 128-bit decimal value. + - name: expression + type: + - resolvesToNumber + description: | + $cos takes any valid expression that resolves to a number. If the expression returns a value in degrees, use the $degreesToRadians operator to convert the result to radians. + By default $cos returns values as a double. $cos can also return values as a 128-bit decimal as long as the resolves to a 128-bit decimal value. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/cos/#example' - pipeline: - - - $addFields: - side_a: - $multiply: - - - $cos: - $degreesToRadians: '$angle_a' - - '$hypotenuse' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/cos/#example + pipeline: + - $addFields: + side_a: + $multiply: + - $cos: + $degreesToRadians: $angle_a + - $hypotenuse + schema: + TestCollection: + _id: + types: + - bsonType: ObjectId + angle_a: + types: + - bsonType: Decimal128 + hypotenuse: + types: + - bsonType: Decimal128 diff --git a/generator/config/expression/cosh.yaml b/generator/config/expression/cosh.yaml index 419fa8caa..471266636 100644 --- a/generator/config/expression/cosh.yaml +++ b/generator/config/expression/cosh.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $cosh -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/cosh/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/cosh/ type: - resolvesToDouble - resolvesToDecimal @@ -8,20 +8,25 @@ encode: single description: | Returns the hyperbolic cosine of a value that is measured in radians. arguments: - - - name: expression - type: - - resolvesToNumber - description: | - $cosh takes any valid expression that resolves to a number, measured in radians. If the expression returns a value in degrees, use the $degreesToRadians operator to convert the value to radians. - By default $cosh returns values as a double. $cosh can also return values as a 128-bit decimal if the resolves to a 128-bit decimal value. + - name: expression + type: + - resolvesToNumber + description: | + $cosh takes any valid expression that resolves to a number, measured in radians. If the expression returns a value in degrees, use the $degreesToRadians operator to convert the value to radians. + By default $cosh returns values as a double. $cosh can also return values as a 128-bit decimal if the resolves to a 128-bit decimal value. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/cosh/#example' - pipeline: - - - $addFields: - cosh_output: - $cosh: - $degreesToRadians: '$angle' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/cosh/#example + pipeline: + - $addFields: + cosh_output: + $cosh: + $degreesToRadians: $angle + schema: + trigonometry: + _id: + types: + - bsonType: ObjectId + angle: + types: + - bsonType: Decimal128 diff --git a/generator/config/expression/dateAdd.yaml b/generator/config/expression/dateAdd.yaml index c7d85d571..caaec955d 100644 --- a/generator/config/expression/dateAdd.yaml +++ b/generator/config/expression/dateAdd.yaml @@ -1,133 +1,148 @@ # $schema: ../schema.json name: $dateAdd -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateAdd/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateAdd/ type: - resolvesToDate encode: object description: | Adds a number of time units to a date object. arguments: - - - name: startDate - type: - - resolvesToDate - - resolvesToTimestamp - - resolvesToObjectId - description: | - The beginning date, in UTC, for the addition operation. The startDate can be any expression that resolves to a Date, a Timestamp, or an ObjectID. - - - name: unit - type: - - timeUnit - description: | - The unit used to measure the amount of time added to the startDate. - - - name: amount - type: - - resolvesToInt - - resolvesToLong - - - name: timezone - type: - - resolvesToString - optional: true - description: | - The timezone to carry out the operation. $timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. + - name: startDate + type: + - resolvesToDate + - resolvesToTimestamp + - resolvesToObjectId + description: | + The beginning date, in UTC, for the addition operation. The startDate can be any expression that resolves to a Date, a Timestamp, or an ObjectID. + - name: unit + type: + - timeUnit + description: | + The unit used to measure the amount of time added to the startDate. + - name: amount + type: + - resolvesToInt + - resolvesToLong + - name: timezone + type: + - resolvesToString + optional: true + description: | + The timezone to carry out the operation. $timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. tests: - - - name: 'Add a Future Date' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateAdd/#add-a-future-date' - pipeline: - - - $project: - expectedDeliveryDate: - $dateAdd: - startDate: '$purchaseDate' - unit: 'day' - amount: 3 - - - # Example uses the short form, the builder always generates the verbose form - # $merge: 'shipping' - $merge: - into: 'shipping' - - - name: 'Filter on a Date Range' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateAdd/#filter-on-a-date-range' - pipeline: - - - $match: - $expr: - $gt: - - '$deliveryDate' - - - $dateAdd: - startDate: '$purchaseDate' - unit: 'day' - amount: 5 - - - $project: - _id: 0 - custId: 1 - purchased: - $dateToString: - format: '%Y-%m-%d' - date: '$purchaseDate' - delivery: - $dateToString: - format: '%Y-%m-%d' - date: '$deliveryDate' - - - name: 'Adjust for Daylight Savings Time' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateAdd/#adjust-for-daylight-savings-time' - pipeline: - - - $project: - _id: 0 - location: 1 - start: - $dateToString: - format: '%Y-%m-%d %H:%M' - date: '$login' - days: - $dateToString: - format: '%Y-%m-%d %H:%M' - date: - $dateAdd: - startDate: '$login' - unit: 'day' - amount: 1 - timezone: '$location' - hours: - $dateToString: - format: '%Y-%m-%d %H:%M' - date: - $dateAdd: - startDate: '$login' - unit: 'hour' - amount: 24 - timezone: '$location' - startTZInfo: - $dateToString: - format: '%Y-%m-%d %H:%M' - date: '$login' - timezone: '$location' - daysTZInfo: - $dateToString: - format: '%Y-%m-%d %H:%M' - date: - $dateAdd: - startDate: '$login' - unit: 'day' - amount: 1 - timezone: '$location' - timezone: '$location' - hoursTZInfo: - $dateToString: - format: '%Y-%m-%d %H:%M' - date: - $dateAdd: - startDate: '$login' - unit: 'hour' - amount: 24 - timezone: '$location' - timezone: '$location' + - name: Add a Future Date + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateAdd/#add-a-future-date + pipeline: + - $project: + expectedDeliveryDate: + $dateAdd: + startDate: $purchaseDate + unit: day + amount: 3 + - $merge: + into: shipping + schema: + shipping: + custId: + types: + - bsonType: Number + purchaseDate: + types: + - bsonType: Date + - name: Filter on a Date Range + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateAdd/#filter-on-a-date-range + pipeline: + - $match: + $expr: + $gt: + - $deliveryDate + - $dateAdd: + startDate: $purchaseDate + unit: day + amount: 5 + - $project: + _id: 0 + custId: 1 + purchased: + $dateToString: + format: '%Y-%m-%d' + date: $purchaseDate + delivery: + $dateToString: + format: '%Y-%m-%d' + date: $deliveryDate + schema: + shipping: + custId: + types: + - bsonType: Int32 + purchaseDate: + types: + - bsonType: Date + deliveryDate: + types: + - bsonType: Date + - name: Adjust for Daylight Savings Time + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateAdd/#adjust-for-daylight-savings-time + pipeline: + - $project: + _id: 0 + location: 1 + start: + $dateToString: + format: '%Y-%m-%d %H:%M' + date: $login + days: + $dateToString: + format: '%Y-%m-%d %H:%M' + date: + $dateAdd: + startDate: $login + unit: day + amount: 1 + timezone: $location + hours: + $dateToString: + format: '%Y-%m-%d %H:%M' + date: + $dateAdd: + startDate: $login + unit: hour + amount: 24 + timezone: $location + startTZInfo: + $dateToString: + format: '%Y-%m-%d %H:%M' + date: $login + timezone: $location + daysTZInfo: + $dateToString: + format: '%Y-%m-%d %H:%M' + date: + $dateAdd: + startDate: $login + unit: day + amount: 1 + timezone: $location + timezone: $location + hoursTZInfo: + $dateToString: + format: '%Y-%m-%d %H:%M' + date: + $dateAdd: + startDate: $login + unit: hour + amount: 24 + timezone: $location + timezone: $location + schema: + billing: + location: + types: + - bsonType: String + login: + types: + - bsonType: Date + logout: + types: + - bsonType: Date diff --git a/generator/config/expression/dateDiff.yaml b/generator/config/expression/dateDiff.yaml index 42cb55d15..1ed98da05 100644 --- a/generator/config/expression/dateDiff.yaml +++ b/generator/config/expression/dateDiff.yaml @@ -1,114 +1,135 @@ # $schema: ../schema.json name: $dateDiff -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateDiff/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateDiff/ type: - resolvesToInt encode: object description: | Returns the difference between two dates. arguments: - - - name: startDate - type: - - resolvesToDate - - resolvesToTimestamp - - resolvesToObjectId - description: | - The start of the time period. The startDate can be any expression that resolves to a Date, a Timestamp, or an ObjectID. - - - name: endDate - type: - - resolvesToDate - - resolvesToTimestamp - - resolvesToObjectId - description: | - The end of the time period. The endDate can be any expression that resolves to a Date, a Timestamp, or an ObjectID. - - - name: unit - type: - - timeUnit - description: | - The time measurement unit between the startDate and endDate - - - name: timezone - type: - - resolvesToString - optional: true - description: | - The timezone to carry out the operation. $timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. - - - name: startOfWeek - type: - - resolvesToString - optional: true - description: | - Used when the unit is equal to week. Defaults to Sunday. The startOfWeek parameter is an expression that resolves to a case insensitive string + - name: startDate + type: + - resolvesToDate + - resolvesToTimestamp + - resolvesToObjectId + description: | + The start of the time period. The startDate can be any expression that resolves to a Date, a Timestamp, or an ObjectID. + - name: endDate + type: + - resolvesToDate + - resolvesToTimestamp + - resolvesToObjectId + description: | + The end of the time period. The endDate can be any expression that resolves to a Date, a Timestamp, or an ObjectID. + - name: unit + type: + - timeUnit + description: | + The time measurement unit between the startDate and endDate + - name: timezone + type: + - resolvesToString + optional: true + description: | + The timezone to carry out the operation. $timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. + - name: startOfWeek + type: + - resolvesToString + optional: true + description: | + Used when the unit is equal to week. Defaults to Sunday. The startOfWeek parameter is an expression that resolves to a case insensitive string tests: - - - name: 'Elapsed Time' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateDiff/#elapsed-time' - pipeline: - - - $group: - _id: ~ - averageTime: - $avg: - $dateDiff: - startDate: '$purchased' - endDate: '$delivered' - unit: 'day' - - - $project: - _id: 0 - numDays: - $trunc: - - '$averageTime' - - 1 - - - name: 'Result Precision' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateDiff/#result-precision' - pipeline: - - - $project: - Start: '$start' - End: '$end' - years: + - name: Elapsed Time + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateDiff/#elapsed-time + pipeline: + - $group: + _id: ~ + averageTime: + $avg: $dateDiff: - startDate: '$start' - endDate: '$end' - unit: 'year' - months: - $dateDiff: - startDate: '$start' - endDate: '$end' - unit: 'month' - days: - $dateDiff: - startDate: '$start' - endDate: '$end' - unit: 'day' - _id: 0 - - - name: 'Weeks Per Month' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateDiff/#weeks-per-month' - pipeline: - - - $project: - wks_default: - $dateDiff: - startDate: '$start' - endDate: '$end' - unit: 'week' - wks_monday: - $dateDiff: - startDate: '$start' - endDate: '$end' - unit: 'week' - startOfWeek: 'Monday' - wks_friday: - $dateDiff: - startDate: '$start' - endDate: '$end' - unit: 'week' - startOfWeek: 'fri' - _id: 0 + startDate: $purchased + endDate: $delivered + unit: day + - $project: + _id: 0 + numDays: + $trunc: + - $averageTime + - 1 + schema: + orders: + custId: + types: + - bsonType: Number + purchased: + types: + - bsonType: Date + delivered: + types: + - bsonType: Date + - name: Result Precision + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateDiff/#result-precision + pipeline: + - $project: + Start: $start + End: $end + years: + $dateDiff: + startDate: $start + endDate: $end + unit: year + months: + $dateDiff: + startDate: $start + endDate: $end + unit: month + days: + $dateDiff: + startDate: $start + endDate: $end + unit: day + _id: 0 + schema: + subscriptions: + custId: + types: + - bsonType: Number + start: + types: + - bsonType: Date + end: + types: + - bsonType: Date + - name: Weeks Per Month + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateDiff/#weeks-per-month + pipeline: + - $project: + wks_default: + $dateDiff: + startDate: $start + endDate: $end + unit: week + wks_monday: + $dateDiff: + startDate: $start + endDate: $end + unit: week + startOfWeek: Monday + wks_friday: + $dateDiff: + startDate: $start + endDate: $end + unit: week + startOfWeek: fri + _id: 0 + schema: + months: + month: + types: + - bsonType: String + start: + types: + - bsonType: Date + end: + types: + - bsonType: Date diff --git a/generator/config/expression/dateFromParts.yaml b/generator/config/expression/dateFromParts.yaml index 3ed35004e..c9c181ee9 100644 --- a/generator/config/expression/dateFromParts.yaml +++ b/generator/config/expression/dateFromParts.yaml @@ -1,114 +1,106 @@ # $schema: ../schema.json name: $dateFromParts -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateFromParts/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateFromParts/ type: - resolvesToDate encode: object description: | Constructs a BSON Date object given the date's constituent parts. arguments: - - - name: year - type: - - resolvesToNumber - optional: true - description: | - Calendar year. Can be any expression that evaluates to a number. - - - name: isoWeekYear - type: - - resolvesToNumber - optional: true - description: | - ISO Week Date Year. Can be any expression that evaluates to a number. - - - name: month - type: - - resolvesToNumber - optional: true - description: | - Month. Defaults to 1. - - - name: isoWeek - type: - - resolvesToNumber - optional: true - description: | - Week of year. Defaults to 1. - - - name: day - type: - - resolvesToNumber - optional: true - description: | - Day of month. Defaults to 1. - - - name: isoDayOfWeek - type: - - resolvesToNumber - optional: true - description: | - Day of week (Monday 1 - Sunday 7). Defaults to 1. - - - name: hour - type: - - resolvesToNumber - optional: true - description: | - Hour. Defaults to 0. - - - name: minute - type: - - resolvesToNumber - optional: true - description: | - Minute. Defaults to 0. - - - name: second - type: - - resolvesToNumber - optional: true - description: | - Second. Defaults to 0. - - - name: millisecond - type: - - resolvesToNumber - optional: true - description: | - Millisecond. Defaults to 0. - - - name: timezone - type: - - resolvesToString - optional: true - description: | - The timezone to carry out the operation. $timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. + - name: year + type: + - resolvesToNumber + optional: true + description: | + Calendar year. Can be any expression that evaluates to a number. + - name: isoWeekYear + type: + - resolvesToNumber + optional: true + description: | + ISO Week Date Year. Can be any expression that evaluates to a number. + - name: month + type: + - resolvesToNumber + optional: true + description: | + Month. Defaults to 1. + - name: isoWeek + type: + - resolvesToNumber + optional: true + description: | + Week of year. Defaults to 1. + - name: day + type: + - resolvesToNumber + optional: true + description: | + Day of month. Defaults to 1. + - name: isoDayOfWeek + type: + - resolvesToNumber + optional: true + description: | + Day of week (Monday 1 - Sunday 7). Defaults to 1. + - name: hour + type: + - resolvesToNumber + optional: true + description: | + Hour. Defaults to 0. + - name: minute + type: + - resolvesToNumber + optional: true + description: | + Minute. Defaults to 0. + - name: second + type: + - resolvesToNumber + optional: true + description: | + Second. Defaults to 0. + - name: millisecond + type: + - resolvesToNumber + optional: true + description: | + Millisecond. Defaults to 0. + - name: timezone + type: + - resolvesToString + optional: true + description: | + The timezone to carry out the operation. $timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateFromParts/#example' - pipeline: - - - $project: - date: - $dateFromParts: - year: 2017 - month: 2 - day: 8 - hour: 12 - date_iso: - $dateFromParts: - isoWeekYear: 2017 - isoWeek: 6 - isoDayOfWeek: 3 - hour: 12 - date_timezone: - $dateFromParts: - year: 2016 - month: 12 - day: 31 - hour: 23 - minute: 46 - second: 12 - timezone: 'America/New_York' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateFromParts/#example + pipeline: + - $project: + date: + $dateFromParts: + year: 2017 + month: 2 + day: 8 + hour: 12 + date_iso: + $dateFromParts: + isoWeekYear: 2017 + isoWeek: 6 + isoDayOfWeek: 3 + hour: 12 + date_timezone: + $dateFromParts: + year: 2016 + month: 12 + day: 31 + hour: 23 + minute: 46 + second: 12 + timezone: America/New_York + schema: + sales: + _id: + types: + - bsonType: ObjectId diff --git a/generator/config/expression/dateFromString.yaml b/generator/config/expression/dateFromString.yaml index 713200f5d..2ae84bb50 100644 --- a/generator/config/expression/dateFromString.yaml +++ b/generator/config/expression/dateFromString.yaml @@ -1,80 +1,105 @@ # $schema: ../schema.json name: $dateFromString -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateFromString/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateFromString/ type: - resolvesToDate encode: object description: | Converts a date/time string to a date object. arguments: - - - name: dateString - type: - - resolvesToString - description: | - The date/time string to convert to a date object. - - - name: format - type: - - resolvesToString - optional: true - description: | - The date format specification of the dateString. The format can be any expression that evaluates to a string literal, containing 0 or more format specifiers. - If unspecified, $dateFromString uses "%Y-%m-%dT%H:%M:%S.%LZ" as the default format but accepts a variety of formats and attempts to parse the dateString if possible. - - - name: timezone - type: - - resolvesToString - optional: true - description: | - The time zone to use to format the date. - - - name: onError - type: - - expression - optional: true - description: | - If $dateFromString encounters an error while parsing the given dateString, it outputs the result value of the provided onError expression. This result value can be of any type. - If you do not specify onError, $dateFromString throws an error if it cannot parse dateString. - - - name: onNull - type: - - expression - optional: true - description: | - If the dateString provided to $dateFromString is null or missing, it outputs the result value of the provided onNull expression. This result value can be of any type. - If you do not specify onNull and dateString is null or missing, then $dateFromString outputs null. + - name: dateString + type: + - resolvesToString + description: | + The date/time string to convert to a date object. + - name: format + type: + - resolvesToString + optional: true + description: | + The date format specification of the dateString. The format can be any expression that evaluates to a string literal, containing 0 or more format specifiers. + If unspecified, $dateFromString uses "%Y-%m-%dT%H:%M:%S.%LZ" as the default format but accepts a variety of formats and attempts to parse the dateString if possible. + - name: timezone + type: + - resolvesToString + optional: true + description: | + The time zone to use to format the date. + - name: onError + type: + - expression + optional: true + description: | + If $dateFromString encounters an error while parsing the given dateString, it outputs the result value of the provided onError expression. This result value can be of any type. + If you do not specify onError, $dateFromString throws an error if it cannot parse dateString. + - name: onNull + type: + - expression + optional: true + description: | + If the dateString provided to $dateFromString is null or missing, it outputs the result value of the provided onNull expression. This result value can be of any type. + If you do not specify onNull and dateString is null or missing, then $dateFromString outputs null. tests: - - - name: 'Converting Dates' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateFromString/#converting-dates' - pipeline: - - - $project: - date: - $dateFromString: - dateString: '$date' - timezone: 'America/New_York' - - - name: 'onError' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateFromString/#onerror' - pipeline: - - - $project: - date: - $dateFromString: - dateString: '$date' - timezone: '$timezone' - onError: '$date' - - - name: 'onNull' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateFromString/#onnull' - pipeline: - - - $project: - date: - $dateFromString: - dateString: '$date' - timezone: '$timezone' - onNull: !bson_utcdatetime 0 - + - name: Converting Dates + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateFromString/#converting-dates + pipeline: + - $project: + date: + $dateFromString: + dateString: $date + timezone: America/New_York + schema: + logmessages: + _id: + types: + - bsonType: Number + date: + types: + - bsonType: String + timezone: + types: + - bsonType: String + message: + types: + - bsonType: String + - name: onError + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateFromString/#onerror + pipeline: + - $project: + date: + $dateFromString: + dateString: $date + timezone: $timezone + onError: $date + schema: + TestCollection: + _id: + types: + - bsonType: Number + date: + types: + - bsonType: String + timezone: + types: + - bsonType: String + - name: onNull + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateFromString/#onnull + pipeline: + - $project: + date: + $dateFromString: + dateString: $date + timezone: $timezone + onNull: !bson_utcdatetime '0' + schema: + TestCollection: + _id: + types: + - bsonType: Number + date: + types: + - bsonType: String + - bsonType: 'Null' + timezone: + types: + - bsonType: String diff --git a/generator/config/expression/dateSubtract.yaml b/generator/config/expression/dateSubtract.yaml index e463fe8f8..11c97f661 100644 --- a/generator/config/expression/dateSubtract.yaml +++ b/generator/config/expression/dateSubtract.yaml @@ -1,139 +1,153 @@ # $schema: ../schema.json name: $dateSubtract -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateSubtract/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateSubtract/ type: - resolvesToDate encode: object description: | Subtracts a number of time units from a date object. arguments: - - - name: startDate - type: - - resolvesToDate - - resolvesToTimestamp - - resolvesToObjectId - description: | - The beginning date, in UTC, for the addition operation. The startDate can be any expression that resolves to a Date, a Timestamp, or an ObjectID. - - - name: unit - type: - - timeUnit - description: | - The unit used to measure the amount of time added to the startDate. - - - name: amount - type: - - resolvesToInt - - resolvesToLong - - - name: timezone - type: - - resolvesToString - optional: true - description: | - The timezone to carry out the operation. $timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. + - name: startDate + type: + - resolvesToDate + - resolvesToTimestamp + - resolvesToObjectId + description: | + The beginning date, in UTC, for the addition operation. The startDate can be any expression that resolves to a Date, a Timestamp, or an ObjectID. + - name: unit + type: + - timeUnit + description: | + The unit used to measure the amount of time added to the startDate. + - name: amount + type: + - resolvesToInt + - resolvesToLong + - name: timezone + type: + - resolvesToString + optional: true + description: | + The timezone to carry out the operation. $timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. tests: - - - name: 'Subtract A Fixed Amount' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateSubtract/#subtract-a-fixed-amount' - pipeline: - - - $match: - $expr: - $eq: - - - # Example uses the short form, the builder always generates the verbose form - # $month: '$logout' - $month: - date: '$logout' - - 1 - - - $project: - logoutTime: - $dateSubtract: - startDate: '$logout' - unit: 'hour' - amount: 3 - - - # Example uses the short form, the builder always generates the verbose form - # $merge: 'connectionTime' - $merge: - into: 'connectionTime' - - - name: 'Filter by Relative Dates' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateSubtract/#filter-by-relative-dates' - pipeline: - - - $match: - $expr: - $gt: - - '$logoutTime' - - - $dateSubtract: - startDate: '$$NOW' - unit: 'week' - amount: 1 - - - $project: - _id: 0 - custId: 1 - loggedOut: - $dateToString: - format: '%Y-%m-%d' - date: '$logoutTime' - - - name: 'Adjust for Daylight Savings Time' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateSubtract/#adjust-for-daylight-savings-time' - pipeline: - - - $project: - _id: 0 - location: 1 - start: - $dateToString: - format: '%Y-%m-%d %H:%M' - date: '$login' - days: - $dateToString: - format: '%Y-%m-%d %H:%M' - date: - $dateSubtract: - startDate: '$login' - unit: 'day' - amount: 1 - timezone: '$location' - hours: - $dateToString: - format: '%Y-%m-%d %H:%M' - date: - $dateSubtract: - startDate: '$login' - unit: 'hour' - amount: 24 - timezone: '$location' - startTZInfo: - $dateToString: - format: '%Y-%m-%d %H:%M' - date: '$login' - timezone: '$location' - daysTZInfo: - $dateToString: - format: '%Y-%m-%d %H:%M' - date: - $dateSubtract: - startDate: '$login' - unit: 'day' - amount: 1 - timezone: '$location' - timezone: '$location' - hoursTZInfo: - $dateToString: - format: '%Y-%m-%d %H:%M' - date: - $dateSubtract: - startDate: '$login' - unit: 'hour' - amount: 24 - timezone: '$location' - timezone: '$location' + - name: Subtract A Fixed Amount + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateSubtract/#subtract-a-fixed-amount + pipeline: + - $match: + $expr: + $eq: + - $month: + date: $logout + - 1 + - $project: + logoutTime: + $dateSubtract: + startDate: $logout + unit: hour + amount: 3 + - $merge: + into: connectionTime + schema: + connectionTime: + custId: + types: + - bsonType: Number + login: + types: + - bsonType: Date + logout: + types: + - bsonType: Date + - name: Filter by Relative Dates + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateSubtract/#filter-by-relative-dates + pipeline: + - $match: + $expr: + $gt: + - $logoutTime + - $dateSubtract: + startDate: $$NOW + unit: week + amount: 1 + - $project: + _id: 0 + custId: 1 + loggedOut: + $dateToString: + format: '%Y-%m-%d' + date: $logoutTime + schema: + connectionTime: + custId: + types: + - bsonType: Number + login: + types: + - bsonType: Date + logout: + types: + - bsonType: Date + - name: Adjust for Daylight Savings Time + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateSubtract/#adjust-for-daylight-savings-time + pipeline: + - $project: + _id: 0 + location: 1 + start: + $dateToString: + format: '%Y-%m-%d %H:%M' + date: $login + days: + $dateToString: + format: '%Y-%m-%d %H:%M' + date: + $dateSubtract: + startDate: $login + unit: day + amount: 1 + timezone: $location + hours: + $dateToString: + format: '%Y-%m-%d %H:%M' + date: + $dateSubtract: + startDate: $login + unit: hour + amount: 24 + timezone: $location + startTZInfo: + $dateToString: + format: '%Y-%m-%d %H:%M' + date: $login + timezone: $location + daysTZInfo: + $dateToString: + format: '%Y-%m-%d %H:%M' + date: + $dateSubtract: + startDate: $login + unit: day + amount: 1 + timezone: $location + timezone: $location + hoursTZInfo: + $dateToString: + format: '%Y-%m-%d %H:%M' + date: + $dateSubtract: + startDate: $login + unit: hour + amount: 24 + timezone: $location + timezone: $location + schema: + billing: + location: + types: + - bsonType: String + login: + types: + - bsonType: Date + logout: + types: + - bsonType: Date diff --git a/generator/config/expression/dateToParts.yaml b/generator/config/expression/dateToParts.yaml index d250e052f..2e281ce33 100644 --- a/generator/config/expression/dateToParts.yaml +++ b/generator/config/expression/dateToParts.yaml @@ -1,49 +1,61 @@ # $schema: ../schema.json name: $dateToParts -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateToParts/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateToParts/ type: - resolvesToObject encode: object description: | Returns a document containing the constituent parts of a date. arguments: - - - name: date - type: - - resolvesToDate - - resolvesToTimestamp - - resolvesToObjectId - description: | - The input date for which to return parts. date can be any expression that resolves to a Date, a Timestamp, or an ObjectID. - - - name: timezone - type: - - resolvesToString - optional: true - description: | - The timezone to carry out the operation. $timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. - - - name: iso8601 - type: - - bool - optional: true - description: | - If set to true, modifies the output document to use ISO week date fields. Defaults to false. + - name: date + type: + - resolvesToDate + - resolvesToTimestamp + - resolvesToObjectId + description: | + The input date for which to return parts. date can be any expression that resolves to a Date, a Timestamp, or an ObjectID. + - name: timezone + type: + - resolvesToString + optional: true + description: | + The timezone to carry out the operation. $timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. + - name: iso8601 + type: + - bool + optional: true + description: | + If set to true, modifies the output document to use ISO week date fields. Defaults to false. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateToParts/#example' - pipeline: - - - $project: - date: - $dateToParts: - date: '$date' - date_iso: - $dateToParts: - date: '$date' - iso8601: true - date_timezone: - $dateToParts: - date: '$date' - timezone: 'America/New_York' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateToParts/#example + pipeline: + - $project: + date: + $dateToParts: + date: $date + date_iso: + $dateToParts: + date: $date + iso8601: true + date_timezone: + $dateToParts: + date: $date + timezone: America/New_York + schema: + sales: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + price: + types: + - bsonType: Number + quantity: + types: + - bsonType: Number + date: + types: + - bsonType: Date diff --git a/generator/config/expression/dateToString.yaml b/generator/config/expression/dateToString.yaml index 29e0ea8c8..d0199da02 100644 --- a/generator/config/expression/dateToString.yaml +++ b/generator/config/expression/dateToString.yaml @@ -1,81 +1,92 @@ # $schema: ../schema.json name: $dateToString -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateToString/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateToString/ type: - resolvesToString encode: object description: | Returns the date as a formatted string. arguments: - - - name: date - type: - - resolvesToDate - - resolvesToTimestamp - - resolvesToObjectId - description: | - The date to convert to string. Must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. - - - name: format - type: - - resolvesToString - optional: true - description: | - The date format specification of the dateString. The format can be any expression that evaluates to a string literal, containing 0 or more format specifiers. - If unspecified, $dateFromString uses "%Y-%m-%dT%H:%M:%S.%LZ" as the default format but accepts a variety of formats and attempts to parse the dateString if possible. - - - name: timezone - type: - - resolvesToString - optional: true - description: | - The time zone to use to format the date. - - - name: onNull - type: - - expression - optional: true - description: | - The value to return if the date is null or missing. - If unspecified, $dateToString returns null if the date is null or missing. + - name: date + type: + - resolvesToDate + - resolvesToTimestamp + - resolvesToObjectId + description: | + The date to convert to string. Must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + - name: format + type: + - resolvesToString + optional: true + description: | + The date format specification of the dateString. The format can be any expression that evaluates to a string literal, containing 0 or more format specifiers. + If unspecified, $dateFromString uses "%Y-%m-%dT%H:%M:%S.%LZ" as the default format but accepts a variety of formats and attempts to parse the dateString if possible. + - name: timezone + type: + - resolvesToString + optional: true + description: | + The time zone to use to format the date. + - name: onNull + type: + - expression + optional: true + description: | + The value to return if the date is null or missing. + If unspecified, $dateToString returns null if the date is null or missing. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateToString/#example' - pipeline: - - - $project: - yearMonthDayUTC: - $dateToString: - format: '%Y-%m-%d' - date: '$date' - timewithOffsetNY: - $dateToString: - format: '%H:%M:%S:%L%z' - date: '$date' - timezone: 'America/New_York' - timewithOffset430: - $dateToString: - format: '%H:%M:%S:%L%z' - date: '$date' - timezone: '+04:30' - minutesOffsetNY: - $dateToString: - format: '%Z' - date: '$date' - timezone: 'America/New_York' - minutesOffset430: - $dateToString: - format: '%Z' - date: '$date' - timezone: '+04:30' - abbreviated_month: - $dateToString: - format: '%b' - date: '$date' - timezone: '+04:30' - full_month: - $dateToString: - format: '%B' - date: '$date' - timezone: '+04:30' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateToString/#example + pipeline: + - $project: + yearMonthDayUTC: + $dateToString: + format: '%Y-%m-%d' + date: $date + timewithOffsetNY: + $dateToString: + format: '%H:%M:%S:%L%z' + date: $date + timezone: America/New_York + timewithOffset430: + $dateToString: + format: '%H:%M:%S:%L%z' + date: $date + timezone: +04:30 + minutesOffsetNY: + $dateToString: + format: '%Z' + date: $date + timezone: America/New_York + minutesOffset430: + $dateToString: + format: '%Z' + date: $date + timezone: +04:30 + abbreviated_month: + $dateToString: + format: '%b' + date: $date + timezone: +04:30 + full_month: + $dateToString: + format: '%B' + date: $date + timezone: +04:30 + schema: + sales: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + price: + types: + - bsonType: Number + quantity: + types: + - bsonType: Number + date: + types: + - bsonType: Date diff --git a/generator/config/expression/dateTrunc.yaml b/generator/config/expression/dateTrunc.yaml index aa3dcd6ca..e89c94e6d 100644 --- a/generator/config/expression/dateTrunc.yaml +++ b/generator/config/expression/dateTrunc.yaml @@ -1,77 +1,108 @@ # $schema: ../schema.json name: $dateTrunc -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateTrunc/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateTrunc/ type: - resolvesToDate encode: object description: | Truncates a date. arguments: - - - name: date - type: - - resolvesToDate - - resolvesToTimestamp - - resolvesToObjectId - description: | - The date to truncate, specified in UTC. The date can be any expression that resolves to a Date, a Timestamp, or an ObjectID. - - - name: unit - type: - - timeUnit - description: | - The unit of time, specified as an expression that must resolve to one of these strings: year, quarter, week, month, day, hour, minute, second. - Together, binSize and unit specify the time period used in the $dateTrunc calculation. - - - name: binSize - type: - - resolvesToNumber - optional: true - description: | - The numeric time value, specified as an expression that must resolve to a positive non-zero number. Defaults to 1. - Together, binSize and unit specify the time period used in the $dateTrunc calculation. - - - name: timezone - type: - - resolvesToString - optional: true - description: | - The timezone to carry out the operation. $timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. - - - name: startOfWeek - type: - - string - optional: true - description: | - The start of the week. Used when - unit is week. Defaults to Sunday. + - name: date + type: + - resolvesToDate + - resolvesToTimestamp + - resolvesToObjectId + description: | + The date to truncate, specified in UTC. The date can be any expression that resolves to a Date, a Timestamp, or an ObjectID. + - name: unit + type: + - timeUnit + description: | + The unit of time, specified as an expression that must resolve to one of these strings: year, quarter, week, month, day, hour, minute, second. + Together, binSize and unit specify the time period used in the $dateTrunc calculation. + - name: binSize + type: + - resolvesToNumber + optional: true + description: | + The numeric time value, specified as an expression that must resolve to a positive non-zero number. Defaults to 1. + Together, binSize and unit specify the time period used in the $dateTrunc calculation. + - name: timezone + type: + - resolvesToString + optional: true + description: | + The timezone to carry out the operation. $timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. + - name: startOfWeek + type: + - string + optional: true + description: | + The start of the week. Used when + unit is week. Defaults to Sunday. tests: - - - name: 'Truncate Order Dates in a $project Pipeline Stage' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateTrunc/#truncate-order-dates-in-a--project-pipeline-stage' - pipeline: - - - $project: - _id: 1 - orderDate: 1 + - name: Truncate Order Dates in a $project Pipeline Stage + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateTrunc/#truncate-order-dates-in-a--project-pipeline-stage + pipeline: + - $project: + _id: 1 + orderDate: 1 + truncatedOrderDate: + $dateTrunc: + date: $orderDate + unit: week + binSize: 2 + timezone: America/Los_Angeles + startOfWeek: Monday + schema: + cakeSales: + _id: + types: + - bsonType: Number + type: + types: + - bsonType: String + orderDate: + types: + - bsonType: Date + state: + types: + - bsonType: String + price: + types: + - bsonType: Number + quantity: + types: + - bsonType: Number + - name: Truncate Order Dates and Obtain Quantity Sum in a $group Pipeline Stage + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateTrunc/#truncate-order-dates-and-obtain-quantity-sum-in-a--group-pipeline-stage + pipeline: + - $group: + _id: truncatedOrderDate: $dateTrunc: - date: '$orderDate' - unit: 'week' - binSize: 2 - timezone: 'America/Los_Angeles' - startOfWeek: 'Monday' - - - name: 'Truncate Order Dates and Obtain Quantity Sum in a $group Pipeline Stage' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateTrunc/#truncate-order-dates-and-obtain-quantity-sum-in-a--group-pipeline-stage' - pipeline: - - - $group: - _id: - truncatedOrderDate: - $dateTrunc: - date: '$orderDate' - unit: 'month' - binSize: 6 - sumQuantity: - $sum: '$quantity' + date: $orderDate + unit: month + binSize: 6 + sumQuantity: + $sum: $quantity + schema: + cakeSales: + _id: + types: + - bsonType: Number + type: + types: + - bsonType: String + orderDate: + types: + - bsonType: Date + state: + types: + - bsonType: String + price: + types: + - bsonType: Number + quantity: + types: + - bsonType: Number diff --git a/generator/config/expression/dayOfMonth.yaml b/generator/config/expression/dayOfMonth.yaml index 46a4de0b7..17582c872 100644 --- a/generator/config/expression/dayOfMonth.yaml +++ b/generator/config/expression/dayOfMonth.yaml @@ -1,36 +1,47 @@ # $schema: ../schema.json name: $dayOfMonth -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/dayOfMonth/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/dayOfMonth/ type: - resolvesToInt encode: object description: | Returns the day of the month for a date as a number between 1 and 31. arguments: - - - name: date - type: - - resolvesToDate - - resolvesToTimestamp - - resolvesToObjectId - description: | - The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. - - - name: timezone - type: - - resolvesToString - optional: true - description: | - The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. + - name: date + type: + - resolvesToDate + - resolvesToTimestamp + - resolvesToObjectId + description: | + The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + - name: timezone + type: + - resolvesToString + optional: true + description: | + The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/dayOfMonth/#example' - pipeline: - - - $project: - day: - # Example uses the short form, the builder always generates the verbose form - # $dayOfMonth: '$date' - $dayOfMonth: - date: '$date' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/dayOfMonth/#example + pipeline: + - $project: + day: + $dayOfMonth: + date: $date + schema: + sales: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + price: + types: + - bsonType: Number + quantity: + types: + - bsonType: Number + date: + types: + - bsonType: Date diff --git a/generator/config/expression/dayOfWeek.yaml b/generator/config/expression/dayOfWeek.yaml index 27a6a809d..5b74b648d 100644 --- a/generator/config/expression/dayOfWeek.yaml +++ b/generator/config/expression/dayOfWeek.yaml @@ -1,36 +1,47 @@ # $schema: ../schema.json name: $dayOfWeek -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/dayOfWeek/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/dayOfWeek/ type: - resolvesToInt encode: object description: | Returns the day of the week for a date as a number between 1 (Sunday) and 7 (Saturday). arguments: - - - name: date - type: - - resolvesToDate - - resolvesToTimestamp - - resolvesToObjectId - description: | - The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. - - - name: timezone - type: - - resolvesToString - optional: true - description: | - The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. + - name: date + type: + - resolvesToDate + - resolvesToTimestamp + - resolvesToObjectId + description: | + The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + - name: timezone + type: + - resolvesToString + optional: true + description: | + The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/dayOfWeek/#example' - pipeline: - - - $project: - dayOfWeek: - # Example uses the short form, the builder always generates the verbose form - # $dayOfWeek: '$date' - $dayOfWeek: - date: '$date' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/dayOfWeek/#example + pipeline: + - $project: + dayOfWeek: + $dayOfWeek: + date: $date + schema: + sales: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + price: + types: + - bsonType: Number + quantity: + types: + - bsonType: Number + date: + types: + - bsonType: Date diff --git a/generator/config/expression/dayOfYear.yaml b/generator/config/expression/dayOfYear.yaml index 8caa0374d..12c78c151 100644 --- a/generator/config/expression/dayOfYear.yaml +++ b/generator/config/expression/dayOfYear.yaml @@ -1,36 +1,47 @@ # $schema: ../schema.json name: $dayOfYear -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/dayOfYear/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/dayOfYear/ type: - resolvesToInt encode: object description: | Returns the day of the year for a date as a number between 1 and 366 (leap year). arguments: - - - name: date - type: - - resolvesToDate - - resolvesToTimestamp - - resolvesToObjectId - description: | - The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. - - - name: timezone - type: - - resolvesToString - optional: true - description: | - The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. + - name: date + type: + - resolvesToDate + - resolvesToTimestamp + - resolvesToObjectId + description: | + The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + - name: timezone + type: + - resolvesToString + optional: true + description: | + The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/dayOfYear/#example' - pipeline: - - - $project: - dayOfYear: - # Example uses the short form, the builder always generates the verbose form - # $dayOfYear: '$date' - $dayOfYear: - date: '$date' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/dayOfYear/#example + pipeline: + - $project: + dayOfYear: + $dayOfYear: + date: $date + schema: + sales: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + price: + types: + - bsonType: Number + quantity: + types: + - bsonType: Number + date: + types: + - bsonType: Date diff --git a/generator/config/expression/degreesToRadians.yaml b/generator/config/expression/degreesToRadians.yaml index 59c18d2e3..d224764cf 100644 --- a/generator/config/expression/degreesToRadians.yaml +++ b/generator/config/expression/degreesToRadians.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $degreesToRadians -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/degreesToRadians/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/degreesToRadians/ type: - resolvesToDouble - resolvesToDecimal @@ -8,23 +8,31 @@ encode: single description: | Converts a value from degrees to radians. arguments: - - - name: expression - type: - - resolvesToNumber - description: | - $degreesToRadians takes any valid expression that resolves to a number. - By default $degreesToRadians returns values as a double. $degreesToRadians can also return values as a 128-bit decimal as long as the resolves to a 128-bit decimal value. + - name: expression + type: + - resolvesToNumber + description: | + $degreesToRadians takes any valid expression that resolves to a number. + By default $degreesToRadians returns values as a double. $degreesToRadians can also return values as a 128-bit decimal as long as the resolves to a 128-bit decimal value. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/degreesToRadians/#example' - pipeline: - - - $addFields: - angle_a_rad: - $degreesToRadians: '$angle_a' - angle_b_rad: - $degreesToRadians: '$angle_b' - angle_c_rad: - $degreesToRadians: '$angle_c' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/degreesToRadians/#example + pipeline: + - $addFields: + angle_a_rad: + $degreesToRadians: $angle_a + angle_b_rad: + $degreesToRadians: $angle_b + angle_c_rad: + $degreesToRadians: $angle_c + schema: + TestCollection: + angle_a: + types: + - bsonType: Decimal128 + angle_b: + types: + - bsonType: Decimal128 + angle_c: + types: + - bsonType: Decimal128 diff --git a/generator/config/expression/divide.yaml b/generator/config/expression/divide.yaml index 3b69389d8..3a2eeba4b 100644 --- a/generator/config/expression/divide.yaml +++ b/generator/config/expression/divide.yaml @@ -1,31 +1,41 @@ # $schema: ../schema.json name: $divide -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/divide/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/divide/ type: - resolvesToDouble encode: array description: | Returns the result of dividing the first number by the second. Accepts two argument expressions. arguments: - - - name: dividend - type: - - resolvesToNumber - description: | - The first argument is the dividend, and the second argument is the divisor; i.e. the first argument is divided by the second argument. - - - name: divisor - type: - - resolvesToNumber + - name: dividend + type: + - resolvesToNumber + description: | + The first argument is the dividend, and the second argument is the divisor; i.e. the first argument is divided by the second argument. + - name: divisor + type: + - resolvesToNumber tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/divide/#example' - pipeline: - - - $project: - city: 1 - workdays: - $divide: - - '$hours' - - 8 + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/divide/#examples + pipeline: + - $project: + city: 1 + workdays: + $divide: + - $hours + - 8 + schema: + conferencePlanning: + _id: + types: + - bsonType: Number + city: + types: + - bsonType: String + hours: + types: + - bsonType: Number + tasks: + types: + - bsonType: Number diff --git a/generator/config/expression/eq.yaml b/generator/config/expression/eq.yaml index 009280ba1..ac84de381 100644 --- a/generator/config/expression/eq.yaml +++ b/generator/config/expression/eq.yaml @@ -1,31 +1,41 @@ # $schema: ../schema.json name: $eq -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/eq/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/eq/ type: - resolvesToBool encode: array description: | Returns true if the values are equivalent. arguments: - - - name: expression1 - type: - - expression - - - name: expression2 - type: - - expression + - name: expression1 + type: + - expression + - name: expression2 + type: + - expression tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/eq/#example' - pipeline: - - - $project: - item: 1 - qty: 1 - qtyEq250: - $eq: - - '$qty' - - 250 - _id: 0 + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/eq/#example + pipeline: + - $project: + item: 1 + qty: 1 + qtyEq250: + $eq: + - $qty + - 250 + _id: 0 + schema: + inventory: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + description: + types: + - bsonType: String + qty: + types: + - bsonType: Number diff --git a/generator/config/expression/exp.yaml b/generator/config/expression/exp.yaml index d1f6982a1..5948e8b52 100644 --- a/generator/config/expression/exp.yaml +++ b/generator/config/expression/exp.yaml @@ -1,25 +1,32 @@ # $schema: ../schema.json name: $exp -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/exp/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/exp/ type: - resolvesToDouble encode: single description: | Raises e to the specified exponent. arguments: - - - name: exponent - type: - - resolvesToNumber + - name: exponent + type: + - resolvesToNumber tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/exp/#example' - pipeline: - - - $project: - effectiveRate: - $subtract: - - - $exp: '$interestRate' - - 1 + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/exp/#example + pipeline: + - $project: + effectiveRate: + $subtract: + - $exp: $interestRate + - 1 + schema: + accounts: + _id: + types: + - bsonType: Number + interestRate: + types: + - bsonType: Number + presentValue: + types: + - bsonType: Number diff --git a/generator/config/expression/filter.yaml b/generator/config/expression/filter.yaml index 0b72f6d75..aff690085 100644 --- a/generator/config/expression/filter.yaml +++ b/generator/config/expression/filter.yaml @@ -1,94 +1,138 @@ # $schema: ../schema.json name: $filter -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/filter/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/filter/ type: - resolvesToArray encode: object description: | Selects a subset of the array to return an array with only the elements that match the filter condition. arguments: - - - name: input - type: - - resolvesToArray - - - name: cond - type: - - resolvesToBool - description: | - An expression that resolves to a boolean value used to determine if an element should be included in the output array. The expression references each element of the input array individually with the variable name specified in as. - - - name: as - type: - - string - optional: true - description: | - 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. - - - name: limit - type: - - resolvesToInt - optional: true - description: | - 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. + - name: input + type: + - resolvesToArray + - name: cond + type: + - resolvesToBool + description: | + An expression that resolves to a boolean value used to determine if an element should be included in the output array. The expression references each element of the input array individually with the variable name specified in as. + - name: as + type: + - string + optional: true + description: | + 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. + - name: limit + type: + - resolvesToInt + optional: true + description: | + 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. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/filter/#examples' - pipeline: - - - $project: - items: - $filter: - input: '$items' - as: 'item' - cond: - $gte: - - '$$item.price' - - 100 - - - name: 'Using the limit field' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/filter/#using-the-limit-field' - pipeline: - - - $project: - items: - $filter: - input: '$items' - cond: - $gte: - - '$$item.price' - - 100 - as: 'item' - limit: 1 - - - name: 'limit as a Numeric Expression' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/filter/#limit-as-a-numeric-expression' - pipeline: - - - $project: - items: - $filter: - input: '$items' - cond: - $lte: - - '$$item.price' - - 150 - as: 'item' - limit: 2 - - - name: 'limit Greater than Possible Matches' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/filter/#limit-greater-than-possible-matches' - pipeline: - - - $project: - items: - $filter: - input: '$items' - cond: - $gte: - - '$$item.price' - - 100 - as: 'item' - limit: 5 + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/filter/#examples + pipeline: + - $project: + items: + $filter: + input: $items + as: item + cond: + $gte: + - $$item.price + - 100 + schema: + sales: + _id: + types: + - bsonType: Number + items: + types: + - bsonType: Array + types: + - bsonType: Document + fields: + item_id: + types: + - bsonType: Number + quantity: + types: + - bsonType: Number + price: + types: + - bsonType: Number + name: + types: + - bsonType: String + - name: Using the limit field + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/filter/#use-the-limit-field + pipeline: + - $project: + items: + $filter: + input: $items + cond: + $gte: + - $$item.price + - 100 + as: item + limit: 1 + schema: + sales: + _id: + types: + - bsonType: Number + items: + types: + - bsonType: Array + types: + - bsonType: Document + fields: + item_id: + types: + - bsonType: Number + quantity: + types: + - bsonType: Number + price: + types: + - bsonType: Number + name: + types: + - bsonType: String + - name: limit Greater than Possible Matches + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/filter/#limit-greater-than-possible-matches + pipeline: + - $project: + items: + $filter: + input: $items + cond: + $gte: + - $$item.price + - 100 + as: item + limit: 5 + schema: + sales: + _id: + types: + - bsonType: Number + items: + types: + - bsonType: Array + types: + - bsonType: Document + fields: + item_id: + types: + - bsonType: Number + quantity: + types: + - bsonType: Number + price: + types: + - bsonType: Number + name: + types: + - bsonType: String diff --git a/generator/config/expression/first.yaml b/generator/config/expression/first.yaml index 262d340c3..0926c5d65 100644 --- a/generator/config/expression/first.yaml +++ b/generator/config/expression/first.yaml @@ -1,21 +1,25 @@ # $schema: ../schema.json name: $first -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/first/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/first/ type: - resolvesToAny encode: single description: | Returns the result of an expression for the first document in an array. arguments: - - - name: expression - type: - - resolvesToArray + - name: expression + type: + - resolvesToArray tests: - - - name: 'Use in $addFields Stage' - pipeline: - - - $addFields: - firstItem: - $first: '$items' + - name: Use in $addFields Stage + pipeline: + - $addFields: + firstItem: + $first: $items + schema: + collection: + items: + types: + - bsonType: Array + types: + - bsonType: String diff --git a/generator/config/expression/firstN.yaml b/generator/config/expression/firstN.yaml index e914ff88c..8ef25a8f4 100644 --- a/generator/config/expression/firstN.yaml +++ b/generator/config/expression/firstN.yaml @@ -1,47 +1,62 @@ # $schema: ../schema.json name: $firstN -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/firstN-array-element/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/firstN-array-element/ type: - resolvesToArray encode: object description: | Returns a specified number of elements from the beginning of an array. arguments: - - - name: 'n' - type: - - resolvesToInt - description: | - An expression that resolves to a positive integer. The integer specifies the number of array elements that $firstN returns. - - - name: input - type: - - resolvesToArray - description: | - An expression that resolves to the array from which to return n elements. - + - name: n + type: + - resolvesToInt + description: | + An expression that resolves to a positive integer. The integer specifies the number of array elements that $firstN returns. + - name: input + type: + - resolvesToArray + description: | + An expression that resolves to the array from which to return n elements. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/firstN-array-element/#example' - pipeline: - - - $addFields: - firstScores: - $firstN: - n: 3 - input: '$score' - - - name: 'Using $firstN as an Aggregation Expression' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/firstN/#using--firstn-as-an-aggregation-expression' - pipeline: - - - $documents: - - - array: [10, 20, 30, 40] - - - $project: - firstThreeElements: - $firstN: - input: '$array' - n: 3 + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/firstN/#example + pipeline: + - $addFields: + firstScores: + $firstN: + n: 3 + input: $score + schema: + games: + playerId: + types: + - bsonType: Number + score: + types: + - bsonType: Array + types: + - bsonType: Number + - bsonType: 'Null' + - bsonType: String + - bsonType: Long + - name: Using $firstN as an Aggregation Expression + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/firstN/#using--firstn-as-an-aggregation-expression + pipeline: + - $documents: + - array: + - 10 + - 20 + - 30 + - 40 + - $project: + firstThreeElements: + $firstN: + input: $array + n: 3 + schema: + TestCollection: + array: + types: + - bsonType: Array + types: + - bsonType: Number diff --git a/generator/config/expression/floor.yaml b/generator/config/expression/floor.yaml index 4c5856264..8782619c0 100644 --- a/generator/config/expression/floor.yaml +++ b/generator/config/expression/floor.yaml @@ -1,23 +1,28 @@ # $schema: ../schema.json name: $floor -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/floor/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/floor/ type: - resolvesToInt encode: single description: | Returns the largest integer less than or equal to the specified number. arguments: - - - name: expression - type: - - resolvesToNumber + - name: expression + type: + - resolvesToNumber tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/floor/#example' - pipeline: - - - $project: - value: 1 - floorValue: - $floor: '$value' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/floor/#example + pipeline: + - $project: + value: 1 + floorValue: + $floor: $value + schema: + samples: + _id: + types: + - bsonType: Number + value: + types: + - bsonType: Number diff --git a/generator/config/expression/function.yaml b/generator/config/expression/function.yaml index fa4dba8b5..0f4394627 100644 --- a/generator/config/expression/function.yaml +++ b/generator/config/expression/function.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $function -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/function/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/function/ type: - resolvesToAny encode: object @@ -8,67 +8,86 @@ description: | Defines a custom function. New in MongoDB 4.4. arguments: - - - name: body - type: - - javascript - description: | - The function definition. You can specify the function definition as either BSON\JavaScript or string. - function(arg1, arg2, ...) { ... } - - - name: args - type: - - array - description: | - Arguments passed to the function body. If the body function does not take an argument, you can specify an empty array [ ]. - default: [] - - - name: lang - type: - - string - default: js + - name: body + type: + - javascript + description: | + The function definition. You can specify the function definition as either BSON\JavaScript or string. + function(arg1, arg2, ...) { ... } + - name: args + type: + - array + description: | + Arguments passed to the function body. If the body function does not take an argument, you can specify an empty array [ ]. + default: [] + - name: lang + type: + - string + default: js tests: - - - name: 'Usage Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/function/#example-1--usage-example' - pipeline: - - - $addFields: - isFound: - $function: - body: - $code: |- - function(name) { - return hex_md5(name) == "15b0a220baa16331e8d80e15367677ad" - } - args: - - '$name' - lang: 'js' - message: - $function: - body: - $code: |- - function(name, scores) { - let total = Array.sum(scores); - return `Hello ${name}. Your total score is ${total}.` - } - args: - - '$name' - - '$scores' - lang: 'js' - - - name: 'Alternative to $where' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/function/#example-2--alternative-to--where' - pipeline: - - - $match: - $expr: - $function: - body: - $code: |- - function(name) { - return hex_md5(name) == "15b0a220baa16331e8d80e15367677ad"; - } - args: - - '$name' - lang: 'js' + - name: Usage Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/function/#example-1--usage-example + pipeline: + - $addFields: + isFound: + $function: + body: + $code: |- + function(name) { + return hex_md5(name) == "15b0a220baa16331e8d80e15367677ad" + } + args: + - $name + lang: js + message: + $function: + body: + $code: |- + function(name, scores) { + let total = Array.sum(scores); + return `Hello ${name}. Your total score is ${total}.` + } + args: + - $name + - $scores + lang: js + schema: + players: + _id: + types: + - bsonType: Number + name: + types: + - bsonType: String + scores: + types: + - bsonType: Array + types: + - bsonType: Number + - name: Alternative to $where + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/function/#example-2--alternative-to--where + pipeline: + - $match: + $expr: + $function: + body: + $code: |- + function(name) { + return hex_md5(name) == "15b0a220baa16331e8d80e15367677ad"; + } + args: + - $name + lang: js + schema: + players: + _id: + types: + - bsonType: Number + name: + types: + - bsonType: String + scores: + types: + - bsonType: Array + types: + - bsonType: Number diff --git a/generator/config/expression/getField.yaml b/generator/config/expression/getField.yaml index 04b5d4ace..dde646964 100644 --- a/generator/config/expression/getField.yaml +++ b/generator/config/expression/getField.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $getField -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/getField/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/getField/ type: - resolvesToAny encode: object @@ -8,62 +8,99 @@ description: | 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. arguments: - - - name: field - type: - - resolvesToString - description: | - Field in the input object for which you want to return a value. field can be any valid expression that resolves to a string constant. - If field begins with a dollar sign ($), place the field name inside of a $literal expression to return its value. - - - name: input - type: - - expression - optional: true - description: | - Default: $$CURRENT - A valid expression that contains the field for which you want to return a value. input must resolve to an object, missing, null, or undefined. If omitted, defaults to the document currently being processed in the pipeline ($$CURRENT). + - name: field + type: + - resolvesToString + description: | + Field in the input object for which you want to return a value. field can be any valid expression that resolves to a string constant. + If field begins with a dollar sign ($), place the field name inside of a $literal expression to return its value. + - name: input + type: + - expression + optional: true + description: | + Default: $$CURRENT + A valid expression that contains the field for which you want to return a value. input must resolve to an object, missing, null, or undefined. If omitted, defaults to the document currently being processed in the pipeline ($$CURRENT). tests: - - - name: 'Query Fields that Contain Periods' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/getField/#query-fields-that-contain-periods--.-' - pipeline: - - - $match: - $expr: - $gt: - - - # Example uses the short form, the builder always generates the verbose form - # $getField: 'price.usd' - $getField: - field: 'price.usd' - - 200 - - - name: 'Query Fields that Start with a Dollar Sign' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/getField/#query-fields-that-start-with-a-dollar-sign----' - pipeline: - - - $match: - $expr: - $gt: - - - $getField: - # Example uses the short form, the builder always generates the verbose form - # $literal: '$price' - field: - $literal: '$price' - - 200 - - - name: 'Query a Field in a Sub-document' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/getField/#query-a-field-in-a-sub-document' - pipeline: - - - $match: - $expr: - $lte: - - - $getField: - field: - $literal: '$small' - input: '$quantity' - - 20 + - name: Query Fields that Contain Periods + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/getField/#query-fields-that-contain-periods--.- + pipeline: + - $match: + $expr: + $gt: + - $getField: + field: price.usd + - 200 + schema: + inventory: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + price.usd: + types: + - bsonType: Number + qty: + types: + - bsonType: Number + - name: Query Fields that Start with a Dollar Sign + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/getField/#query-fields-that-start-with-a-dollar-sign---- + pipeline: + - $match: + $expr: + $gt: + - $getField: + field: + $literal: $price + - 200 + schema: + inventory: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + $price: + types: + - bsonType: Number + qty: + types: + - bsonType: Number + - name: Query a Field in a Sub-document + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/getField/#query-a-field-in-a-sub-document + pipeline: + - $match: + $expr: + $lte: + - $getField: + field: + $literal: $small + input: $quantity + - 20 + schema: + inventory: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + price.usd: + types: + - bsonType: Number + quantity: + types: + - bsonType: Document + fields: + $large: + types: + - bsonType: Number + $medium: + types: + - bsonType: Number + $small: + types: + - bsonType: Number diff --git a/generator/config/expression/gt.yaml b/generator/config/expression/gt.yaml index ddd4dcdd0..d0f7375a3 100644 --- a/generator/config/expression/gt.yaml +++ b/generator/config/expression/gt.yaml @@ -1,31 +1,41 @@ # $schema: ../schema.json name: $gt -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/gt/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/gt/ type: - resolvesToBool encode: array description: | Returns true if the first value is greater than the second. arguments: - - - name: expression1 - type: - - expression - - - name: expression2 - type: - - expression + - name: expression1 + type: + - expression + - name: expression2 + type: + - expression tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/gt/#example' - pipeline: - - - $project: - item: 1 - qty: 1 - qtyGt250: - $gt: - - '$qty' - - 250 - _id: 0 + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/gt/#example + pipeline: + - $project: + item: 1 + qty: 1 + qtyGt250: + $gt: + - $qty + - 250 + _id: 0 + schema: + inventory: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + description: + types: + - bsonType: String + qty: + types: + - bsonType: Number diff --git a/generator/config/expression/gte.yaml b/generator/config/expression/gte.yaml index 6b456daf6..3cac1340f 100644 --- a/generator/config/expression/gte.yaml +++ b/generator/config/expression/gte.yaml @@ -1,31 +1,41 @@ # $schema: ../schema.json name: $gte -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/gte/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/gte/ type: - resolvesToBool encode: array description: | Returns true if the first value is greater than or equal to the second. arguments: - - - name: expression1 - type: - - expression - - - name: expression2 - type: - - expression + - name: expression1 + type: + - expression + - name: expression2 + type: + - expression tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/gte/#example' - pipeline: - - - $project: - item: 1 - qty: 1 - qtyGte250: - $gte: - - '$qty' - - 250 - _id: 0 + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/gte/#example + pipeline: + - $project: + item: 1 + qty: 1 + qtyGte250: + $gte: + - $qty + - 250 + _id: 0 + schema: + inventory: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + description: + types: + - bsonType: String + qty: + types: + - bsonType: Number diff --git a/generator/config/expression/hour.yaml b/generator/config/expression/hour.yaml index ebd62c3a0..2de86625a 100644 --- a/generator/config/expression/hour.yaml +++ b/generator/config/expression/hour.yaml @@ -1,36 +1,47 @@ # $schema: ../schema.json name: $hour -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/hour/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/hour/ type: - resolvesToInt encode: object description: | Returns the hour for a date as a number between 0 and 23. arguments: - - - name: date - type: - - resolvesToDate - - resolvesToTimestamp - - resolvesToObjectId - description: | - The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. - - - name: timezone - type: - - resolvesToString - optional: true - description: | - The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. + - name: date + type: + - resolvesToDate + - resolvesToTimestamp + - resolvesToObjectId + description: | + The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + - name: timezone + type: + - resolvesToString + optional: true + description: | + The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/hour/#example' - pipeline: - - - $project: - hour: - # Example uses the short form, the builder always generates the verbose form - # $hour: '$date' - $hour: - date: '$date' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/hour/#example + pipeline: + - $project: + hour: + $hour: + date: $date + schema: + sales: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + price: + types: + - bsonType: Number + quantity: + types: + - bsonType: Number + date: + types: + - bsonType: Date diff --git a/generator/config/expression/ifNull.yaml b/generator/config/expression/ifNull.yaml index 9be8e9044..45105d813 100644 --- a/generator/config/expression/ifNull.yaml +++ b/generator/config/expression/ifNull.yaml @@ -1,38 +1,63 @@ # $schema: ../schema.json name: $ifNull -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/ifNull/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/ifNull/ type: - resolvesToAny encode: single description: | 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. arguments: - - - name: expression - type: - - expression - variadic: array + - name: expression + type: + - expression + variadic: array tests: - - - name: 'Single Input Expression' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/ifNull/#single-input-expression' - pipeline: - - - $project: - item: 1 - description: - $ifNull: - - '$description' - - 'Unspecified' - - - name: 'Multiple Input Expressions' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/ifNull/#multiple-input-expressions' - pipeline: - - - $project: - item: 1 - value: - $ifNull: - - '$description' - - '$quantity' - - 'Unspecified' + - name: Single Input Expression + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/ifNull/#single-input-expression + pipeline: + - $project: + item: 1 + description: + $ifNull: + - $description + - Unspecified + schema: + inventory: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + description: + types: + - bsonType: String + - bsonType: 'Null' + quantity: + types: + - bsonType: Number + - name: Multiple Input Expressions + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/ifNull/#multiple-input-expressions + pipeline: + - $project: + item: 1 + value: + $ifNull: + - $description + - $quantity + - Unspecified + schema: + inventory: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + description: + types: + - bsonType: String + - bsonType: 'Null' + quantity: + types: + - bsonType: Number diff --git a/generator/config/expression/in.yaml b/generator/config/expression/in.yaml index 7cef8c149..f3cb996ed 100644 --- a/generator/config/expression/in.yaml +++ b/generator/config/expression/in.yaml @@ -1,33 +1,42 @@ # $schema: ../schema.json name: $in -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/in/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/in/ type: - resolvesToBool encode: array description: | Returns a boolean indicating whether a specified value is in an array. arguments: - - - name: expression - type: - - expression - description: | - Any valid expression expression. - - - name: array - type: - - resolvesToArray - description: | - Any valid expression that resolves to an array. + - name: expression + type: + - expression + description: | + Any valid expression expression. + - name: array + type: + - resolvesToArray + description: | + Any valid expression that resolves to an array. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/in/#example' - pipeline: - - - $project: - store location: '$location' - has bananas: - $in: - - 'bananas' - - '$in_stock' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/in/#example + pipeline: + - $project: + store location: $location + has bananas: + $in: + - bananas + - $in_stock + schema: + TestCollection: + _id: + types: + - bsonType: Number + location: + types: + - bsonType: String + in_stock: + types: + - bsonType: Array + types: + - bsonType: String diff --git a/generator/config/expression/indexOfArray.yaml b/generator/config/expression/indexOfArray.yaml index 5840ee0fa..7d4726f95 100644 --- a/generator/config/expression/indexOfArray.yaml +++ b/generator/config/expression/indexOfArray.yaml @@ -1,48 +1,58 @@ # $schema: ../schema.json name: $indexOfArray -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/indexOfArray/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/indexOfArray/ type: - resolvesToInt encode: array description: | Searches an array for an occurrence of a specified value and returns the array index of the first occurrence. Array indexes start at zero. arguments: - - - name: array - type: - - resolvesToArray - description: | - Can be any valid expression as long as it resolves to an array. - If the array expression resolves to a value of null or refers to a field that is missing, $indexOfArray returns null. - If the array expression does not resolve to an array or null nor refers to a missing field, $indexOfArray returns an error. - - - name: search - type: - - expression - - - name: start - type: - - resolvesToInt - optional: true - description: | - An integer, or a number that can be represented as integers (such as 2.0), that specifies the starting index position for the search. Can be any valid expression that resolves to a non-negative integral number. - If unspecified, the starting index position for the search is the beginning of the string. - - - name: end - type: - - resolvesToInt - optional: true - description: | - An integer, or a number that can be represented as integers (such as 2.0), that specifies the ending index position for the search. Can be any valid expression that resolves to a non-negative integral number. If you specify a index value, you should also specify a index value; otherwise, $indexOfArray uses the value as the index value instead of the value. - If unspecified, the ending index position for the search is the end of the string. + - name: array + type: + - resolvesToArray + description: | + Can be any valid expression as long as it resolves to an array. + If the array expression resolves to a value of null or refers to a field that is missing, $indexOfArray returns null. + If the array expression does not resolve to an array or null nor refers to a missing field, $indexOfArray returns an error. + - name: search + type: + - expression + - name: start + type: + - resolvesToInt + optional: true + description: | + An integer, or a number that can be represented as integers (such as 2.0), that specifies the starting index position for the search. Can be any valid expression that resolves to a non-negative integral number. + If unspecified, the starting index position for the search is the beginning of the string. + - name: end + type: + - resolvesToInt + optional: true + description: | + An integer, or a number that can be represented as integers (such as 2.0), that specifies the ending index position for the search. Can be any valid expression that resolves to a non-negative integral number. If you specify a index value, you should also specify a index value; otherwise, $indexOfArray uses the value as the index value instead of the value. + If unspecified, the ending index position for the search is the end of the string. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/indexOfArray/#example' - pipeline: - - - $project: - index: - $indexOfArray: - - '$items' - - 2 + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/indexOfArray/#example + pipeline: + - $project: + index: + $indexOfArray: + - $items + - 2 + schema: + inventory: + _id: + types: + - bsonType: Number + items: + types: + - bsonType: Array + types: + - bsonType: Number + - bsonType: 'Null' + - bsonType: String + - bsonType: 'Null' + amount: + types: + - bsonType: Number diff --git a/generator/config/expression/indexOfBytes.yaml b/generator/config/expression/indexOfBytes.yaml index 7fe890891..a940a738c 100644 --- a/generator/config/expression/indexOfBytes.yaml +++ b/generator/config/expression/indexOfBytes.yaml @@ -1,50 +1,56 @@ # $schema: ../schema.json name: $indexOfBytes -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/indexOfBytes/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/indexOfBytes/ type: - resolvesToInt encode: array description: | 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. arguments: - - - name: string - type: - - resolvesToString - description: | - Can be any valid expression as long as it resolves to a string. - If the string expression resolves to a value of null or refers to a field that is missing, $indexOfBytes returns null. - If the string expression does not resolve to a string or null nor refers to a missing field, $indexOfBytes returns an error. - - - name: substring - type: - - resolvesToString - description: | - Can be any valid expression as long as it resolves to a string. - - - name: start - type: - - resolvesToInt - optional: true - description: | - An integer, or a number that can be represented as integers (such as 2.0), that specifies the starting index position for the search. Can be any valid expression that resolves to a non-negative integral number. - If unspecified, the starting index position for the search is the beginning of the string. - - - name: end - type: - - resolvesToInt - optional: true - description: | - An integer, or a number that can be represented as integers (such as 2.0), that specifies the ending index position for the search. Can be any valid expression that resolves to a non-negative integral number. If you specify a index value, you should also specify a index value; otherwise, $indexOfArray uses the value as the index value instead of the value. - If unspecified, the ending index position for the search is the end of the string. + - name: string + type: + - resolvesToString + description: | + Can be any valid expression as long as it resolves to a string. + If the string expression resolves to a value of null or refers to a field that is missing, $indexOfBytes returns null. + If the string expression does not resolve to a string or null nor refers to a missing field, $indexOfBytes returns an error. + - name: substring + type: + - resolvesToString + description: | + Can be any valid expression as long as it resolves to a string. + - name: start + type: + - resolvesToInt + optional: true + description: | + An integer, or a number that can be represented as integers (such as 2.0), that specifies the starting index position for the search. Can be any valid expression that resolves to a non-negative integral number. + If unspecified, the starting index position for the search is the beginning of the string. + - name: end + type: + - resolvesToInt + optional: true + description: | + An integer, or a number that can be represented as integers (such as 2.0), that specifies the ending index position for the search. Can be any valid expression that resolves to a non-negative integral number. If you specify a index value, you should also specify a index value; otherwise, $indexOfArray uses the value as the index value instead of the value. + If unspecified, the ending index position for the search is the end of the string. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/indexOfBytes/#examples' - pipeline: - - - $project: - byteLocation: - $indexOfBytes: - - '$item' - - 'foo' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/indexOfBytes/#examples + pipeline: + - $project: + byteLocation: + $indexOfBytes: + - $item + - foo + schema: + inventory: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + - bsonType: 'Null' + amount: + types: + - bsonType: Number diff --git a/generator/config/expression/indexOfCP.yaml b/generator/config/expression/indexOfCP.yaml index 88ed55ec6..0af45c319 100644 --- a/generator/config/expression/indexOfCP.yaml +++ b/generator/config/expression/indexOfCP.yaml @@ -1,50 +1,56 @@ # $schema: ../schema.json name: $indexOfCP -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/indexOfCP/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/indexOfCP/ type: - resolvesToInt encode: array description: | 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 arguments: - - - name: string - type: - - resolvesToString - description: | - Can be any valid expression as long as it resolves to a string. - If the string expression resolves to a value of null or refers to a field that is missing, $indexOfCP returns null. - If the string expression does not resolve to a string or null nor refers to a missing field, $indexOfCP returns an error. - - - name: substring - type: - - resolvesToString - description: | - Can be any valid expression as long as it resolves to a string. - - - name: start - type: - - resolvesToInt - optional: true - description: | - An integer, or a number that can be represented as integers (such as 2.0), that specifies the starting index position for the search. Can be any valid expression that resolves to a non-negative integral number. - If unspecified, the starting index position for the search is the beginning of the string. - - - name: end - type: - - resolvesToInt - optional: true - description: | - An integer, or a number that can be represented as integers (such as 2.0), that specifies the ending index position for the search. Can be any valid expression that resolves to a non-negative integral number. If you specify a index value, you should also specify a index value; otherwise, $indexOfArray uses the value as the index value instead of the value. - If unspecified, the ending index position for the search is the end of the string. + - name: string + type: + - resolvesToString + description: | + Can be any valid expression as long as it resolves to a string. + If the string expression resolves to a value of null or refers to a field that is missing, $indexOfCP returns null. + If the string expression does not resolve to a string or null nor refers to a missing field, $indexOfCP returns an error. + - name: substring + type: + - resolvesToString + description: | + Can be any valid expression as long as it resolves to a string. + - name: start + type: + - resolvesToInt + optional: true + description: | + An integer, or a number that can be represented as integers (such as 2.0), that specifies the starting index position for the search. Can be any valid expression that resolves to a non-negative integral number. + If unspecified, the starting index position for the search is the beginning of the string. + - name: end + type: + - resolvesToInt + optional: true + description: | + An integer, or a number that can be represented as integers (such as 2.0), that specifies the ending index position for the search. Can be any valid expression that resolves to a non-negative integral number. If you specify a index value, you should also specify a index value; otherwise, $indexOfArray uses the value as the index value instead of the value. + If unspecified, the ending index position for the search is the end of the string. tests: - - - name: 'Examples' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/indexOfCP/#examples' - pipeline: - - - $project: - cpLocation: - $indexOfCP: - - '$item' - - 'foo' + - name: Examples + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/indexOfCP/#examples + pipeline: + - $project: + cpLocation: + $indexOfCP: + - $item + - foo + schema: + inventory: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + - bsonType: 'Null' + amount: + types: + - bsonType: Number diff --git a/generator/config/expression/isArray.yaml b/generator/config/expression/isArray.yaml index b9a5d5cb5..4f42cabc7 100644 --- a/generator/config/expression/isArray.yaml +++ b/generator/config/expression/isArray.yaml @@ -1,36 +1,45 @@ # $schema: ../schema.json name: $isArray -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/isArray/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/isArray/ type: - resolvesToBool encode: array description: | Determines if the operand is an array. Returns a boolean. arguments: - - - name: expression - type: - - expression + - name: expression + type: + - expression tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/isArray/#example' - pipeline: - - - $project: - items: - $cond: - if: - $and: - # Example uses the short form, the builder always generates the verbose form - - - $isArray: - - '$instock' - - - $isArray: - - '$ordered' - then: - $concatArrays: - - '$instock' - - '$ordered' - else: 'One or more fields is not an array.' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/isArray/#example + pipeline: + - $project: + items: + $cond: + if: + $and: + - $isArray: + - $instock + - $isArray: + - $ordered + then: + $concatArrays: + - $instock + - $ordered + else: One or more fields is not an array. + schema: + warehouses: + _id: + types: + - bsonType: Number + instock: + types: + - bsonType: Array + types: + - bsonType: String + ordered: + types: + - bsonType: Array + types: + - bsonType: String diff --git a/generator/config/expression/isNumber.yaml b/generator/config/expression/isNumber.yaml index 3bce99e99..f6d3b7682 100644 --- a/generator/config/expression/isNumber.yaml +++ b/generator/config/expression/isNumber.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $isNumber -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/isNumber/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/isNumber/ type: - resolvesToBool encode: single @@ -9,67 +9,86 @@ description: | Returns boolean false if the expression resolves to any other BSON type, null, or a missing field. New in MongoDB 4.4. arguments: - - - name: expression - type: - - expression + - name: expression + type: + - expression tests: - - - name: 'Use $isNumber to Check if a Field is Numeric' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/isNumber/#use--isnumber-to-check-if-a-field-is-numeric' - pipeline: - - - $addFields: - isNumber: - $isNumber: '$reading' - hasType: - $type: '$reading' - - - name: 'Conditionally Modify Fields using $isNumber' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/isNumber/#conditionally-modify-fields-using--isnumber' - pipeline: - - - $addFields: - points: - $cond: - if: - $isNumber: '$grade' - then: '$grade' - else: - $switch: - branches: - - - case: - $eq: - - '$grade' - - 'A' - then: 4 - - - case: - $eq: - - '$grade' - - 'B' - then: 3 - - - case: - $eq: - - '$grade' - - 'C' - then: 2 - - - case: - $eq: - - '$grade' - - 'D' - then: 1 - - - case: - $eq: - - '$grade' - - 'F' - then: 0 - - - $group: - _id: '$student_id' - GPA: - $avg: '$points' + - name: Use $isNumber to Check if a Field is Numeric + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/isNumber/#use--isnumber-to-check-if-a-field-is-numeric + pipeline: + - $addFields: + isNumber: + $isNumber: $reading + hasType: + $type: $reading + schema: + sensors: + _id: + types: + - bsonType: Number + reading: + types: + - bsonType: Decimal128 + - bsonType: Long + - bsonType: Int32 + - bsonType: Number + - bsonType: String + - bsonType: Array + types: + - bsonType: Decimal128 + - name: Conditionally Modify Fields using $isNumber + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/isNumber/#conditionally-modify-fields-using--isnumber + pipeline: + - $addFields: + points: + $cond: + if: + $isNumber: $grade + then: $grade + else: + $switch: + branches: + - case: + $eq: + - $grade + - A + then: 4 + - case: + $eq: + - $grade + - B + then: 3 + - case: + $eq: + - $grade + - C + then: 2 + - case: + $eq: + - $grade + - D + then: 1 + - case: + $eq: + - $grade + - F + then: 0 + - $group: + _id: $student_id + GPA: + $avg: $points + schema: + grades: + student_id: + types: + - bsonType: Number + class_id: + types: + - bsonType: String + class_desc: + types: + - bsonType: String + grade: + types: + - bsonType: String + - bsonType: Number diff --git a/generator/config/expression/isoDayOfWeek.yaml b/generator/config/expression/isoDayOfWeek.yaml index 1956ff5c4..4f4c1f41d 100644 --- a/generator/config/expression/isoDayOfWeek.yaml +++ b/generator/config/expression/isoDayOfWeek.yaml @@ -1,38 +1,43 @@ # $schema: ../schema.json name: $isoDayOfWeek -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/isoDayOfWeek/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/isoDayOfWeek/ type: - resolvesToInt encode: object description: | Returns the weekday number in ISO 8601 format, ranging from 1 (for Monday) to 7 (for Sunday). arguments: - - - name: date - type: - - resolvesToDate - - resolvesToTimestamp - - resolvesToObjectId - description: | - The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. - - - name: timezone - type: - - resolvesToString - optional: true - description: | - The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. + - name: date + type: + - resolvesToDate + - resolvesToTimestamp + - resolvesToObjectId + description: | + The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + - name: timezone + type: + - resolvesToString + optional: true + description: | + The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/isoDayOfWeek/#example' - pipeline: - - - $project: - _id: 0 - name: '$name' - dayOfWeek: - # Example uses the short form, the builder always generates the verbose form - # $isoDayOfWeek: '$birthday' - $isoDayOfWeek: - date: '$birthday' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/isoDayOfWeek/#example + pipeline: + - $project: + _id: 0 + name: $name + dayOfWeek: + $isoDayOfWeek: + date: $birthday + schema: + birthdays: + _id: + types: + - bsonType: Number + name: + types: + - bsonType: String + birthday: + types: + - bsonType: Date diff --git a/generator/config/expression/isoWeek.yaml b/generator/config/expression/isoWeek.yaml index 2958a20c3..d80783d65 100644 --- a/generator/config/expression/isoWeek.yaml +++ b/generator/config/expression/isoWeek.yaml @@ -1,38 +1,43 @@ # $schema: ../schema.json name: $isoWeek -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/isoWeek/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/isoWeek/ type: - resolvesToInt encode: object description: | 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. arguments: - - - name: date - type: - - resolvesToDate - - resolvesToTimestamp - - resolvesToObjectId - description: | - The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. - - - name: timezone - type: - - resolvesToString - optional: true - description: | - The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. + - name: date + type: + - resolvesToDate + - resolvesToTimestamp + - resolvesToObjectId + description: | + The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + - name: timezone + type: + - resolvesToString + optional: true + description: | + The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/isoWeek/#example' - pipeline: - - - $project: - _id: 0 - city: '$city' - weekNumber: - # Example uses the short form, the builder always generates the verbose form - # $isoWeek: '$date' - $isoWeek: - date: '$date' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/isoWeek/#example + pipeline: + - $project: + _id: 0 + city: $city + weekNumber: + $isoWeek: + date: $date + schema: + deliveries: + _id: + types: + - bsonType: Number + date: + types: + - bsonType: Date + city: + types: + - bsonType: String diff --git a/generator/config/expression/isoWeekYear.yaml b/generator/config/expression/isoWeekYear.yaml index 5dcefa7dd..3c441f887 100644 --- a/generator/config/expression/isoWeekYear.yaml +++ b/generator/config/expression/isoWeekYear.yaml @@ -1,36 +1,38 @@ # $schema: ../schema.json name: $isoWeekYear -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/isoWeekYear/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/isoWeekYear/ type: - resolvesToInt encode: object description: | 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). arguments: - - - name: date - type: - - resolvesToDate - - resolvesToTimestamp - - resolvesToObjectId - description: | - The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. - - - name: timezone - type: - - resolvesToString - optional: true - description: | - The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. + - name: date + type: + - resolvesToDate + - resolvesToTimestamp + - resolvesToObjectId + description: | + The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + - name: timezone + type: + - resolvesToString + optional: true + description: | + The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/isoWeekYear/#example' - pipeline: - - - $project: - yearNumber: - # Example uses the short form, the builder always generates the verbose form - # $isoWeekYear: '$date' - $isoWeekYear: - date: '$date' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/isoWeekYear/#example + pipeline: + - $project: + yearNumber: + $isoWeekYear: + date: $date + schema: + TestCollection: + _id: + types: + - bsonType: Number + date: + types: + - bsonType: Date diff --git a/generator/config/expression/last.yaml b/generator/config/expression/last.yaml index 2bf18dc7b..976e2f3e0 100644 --- a/generator/config/expression/last.yaml +++ b/generator/config/expression/last.yaml @@ -1,21 +1,25 @@ # $schema: ../schema.json name: $last -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/last/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/last/ type: - resolvesToAny encode: single description: | Returns the result of an expression for the last document in an array. arguments: - - - name: expression - type: - - resolvesToArray + - name: expression + type: + - resolvesToArray tests: - - - name: 'Use in $addFields Stage' - pipeline: - - - $addFields: - lastItem: - $last: '$items' + - name: Use in $addFields Stage + pipeline: + - $addFields: + lastItem: + $last: $items + schema: + collection: + items: + types: + - bsonType: Array + types: + - bsonType: String diff --git a/generator/config/expression/lastN.yaml b/generator/config/expression/lastN.yaml index 0c29ad76e..3e96d5186 100644 --- a/generator/config/expression/lastN.yaml +++ b/generator/config/expression/lastN.yaml @@ -1,51 +1,62 @@ # $schema: ../schema.json name: $lastN -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/lastN-array-element/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/lastN/#array-operator type: - resolvesToArray encode: object description: | Returns a specified number of elements from the end of an array. arguments: - - - name: 'n' - type: - - resolvesToInt - description: | - An expression that resolves to a positive integer. The integer specifies the number of array elements that $firstN returns. - - - name: input - type: - - resolvesToArray - description: | - An expression that resolves to the array from which to return n elements. + - name: n + type: + - resolvesToInt + description: | + An expression that resolves to a positive integer. The integer specifies the number of array elements that $firstN returns. + - name: input + type: + - resolvesToArray + description: | + An expression that resolves to the array from which to return n elements. tests: - - - name: Example - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/lastN-array-element/#example' - pipeline: - - - $addFields: - lastScores: - $lastN: - n: 3 - input: '$score' - - - - name: 'Using $lastN as an Aggregation Expression' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/lastN/#using--lastn-as-an-aggregation-expression' - pipeline: - - - $documents: - - - array: - - 10 - - 20 - - 30 - - 40 - - - $project: - lastThreeElements: - $lastN: - input: '$array' - n: 3 + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/lastN/#example + pipeline: + - $addFields: + lastScores: + $lastN: + n: 3 + input: $score + schema: + games: + playerId: + types: + - bsonType: Number + score: + types: + - bsonType: Array + types: + - bsonType: Number + - bsonType: 'Null' + - bsonType: String + - bsonType: Long + - name: Using $lastN as an Aggregation Expression + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/lastN/#using--lastn-as-an-aggregation-expression + pipeline: + - $documents: + - array: + - 10 + - 20 + - 30 + - 40 + - $project: + lastThreeElements: + $lastN: + input: $array + n: 3 + schema: + TestCollection: + array: + types: + - bsonType: Array + types: + - bsonType: Number diff --git a/generator/config/expression/let.yaml b/generator/config/expression/let.yaml index 7d3017282..426364496 100644 --- a/generator/config/expression/let.yaml +++ b/generator/config/expression/let.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $let -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/let/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/let/ type: - resolvesToAny encode: object @@ -8,39 +8,49 @@ description: | 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. arguments: - - - name: vars - type: - - object # of expression - description: | - 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. - - - name: in - type: - - expression - description: | - The expression to evaluate. + - name: vars + type: + - expressionMap + description: | + 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. + - name: in + type: + - expression + description: | + The expression to evaluate. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/let/#example' - pipeline: - - - $project: - finalTotal: - $let: - vars: - total: - $add: - - '$price' - - '$tax' - discounted: - $cond: - if: '$applyDiscount' - then: 0.9 - else: 1 - in: - $multiply: - - '$$total' - - '$$discounted' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/let/#example + pipeline: + - $project: + finalTotal: + $let: + vars: + total: + $add: + - $price + - $tax + discounted: + $cond: + if: $applyDiscount + then: 0.9 + else: 1 + in: + $multiply: + - $$total + - $$discounted + schema: + sales: + _id: + types: + - bsonType: Number + price: + types: + - bsonType: Number + tax: + types: + - bsonType: Number + applyDiscount: + types: + - bsonType: Boolean diff --git a/generator/config/expression/literal.yaml b/generator/config/expression/literal.yaml index dfae7bbb3..deadd72bf 100644 --- a/generator/config/expression/literal.yaml +++ b/generator/config/expression/literal.yaml @@ -1,15 +1,14 @@ # $schema: ../schema.json name: $literal -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/literal/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/literal/ type: - resolvesToAny encode: single description: | 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. arguments: - - - name: value - type: - - any - description: | - If the value is an expression, $literal does not evaluate the expression but instead returns the unparsed expression. + - name: value + type: + - any + description: If the value is an expression, $literal does not evaluate the expression + but instead returns the unparsed expression. diff --git a/generator/config/expression/ln.yaml b/generator/config/expression/ln.yaml index f7412aeb9..7788a3f9d 100644 --- a/generator/config/expression/ln.yaml +++ b/generator/config/expression/ln.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $ln -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/ln/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/ln/ type: - resolvesToDouble encode: single @@ -8,19 +8,27 @@ description: | 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. arguments: - - - name: number - type: - - resolvesToNumber - description: | - Any valid expression as long as it resolves to a non-negative number. For more information on expressions, see Expressions. + - name: number + type: + - resolvesToNumber + description: | + Any valid expression as long as it resolves to a non-negative number. For more information on expressions, see Expressions. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/ln/#example' - pipeline: - - - $project: - x: '$year' - y: - $ln: '$sales' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/ln/#example + pipeline: + - $project: + x: $year + y: + $ln: $sales + schema: + sales: + _id: + types: + - bsonType: Number + year: + types: + - bsonType: String + sales: + types: + - bsonType: Number diff --git a/generator/config/expression/log.yaml b/generator/config/expression/log.yaml index 462eb9492..deefa534c 100644 --- a/generator/config/expression/log.yaml +++ b/generator/config/expression/log.yaml @@ -1,36 +1,39 @@ # $schema: ../schema.json name: $log -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/log/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/log/ type: - resolvesToDouble encode: array description: | Calculates the log of a number in the specified base. arguments: - - - name: number - type: - - resolvesToNumber - description: | - Any valid expression as long as it resolves to a non-negative number. - - - name: base - type: - - resolvesToNumber - description: | - Any valid expression as long as it resolves to a positive number greater than 1. + - name: number + type: + - resolvesToNumber + description: | + Any valid expression as long as it resolves to a non-negative number. + - name: base + type: + - resolvesToNumber + description: | + Any valid expression as long as it resolves to a positive number greater than 1. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/log/#example' - pipeline: - - - $project: - bitsNeeded: - $floor: - $add: - - 1 - - - $log: - - '$int' - - 2 + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/log/#example + pipeline: + - $project: + bitsNeeded: + $floor: + $add: + - 1 + - $log: + - $int + - 2 + schema: + integers: + _id: + types: + - bsonType: Number + int: + types: + - bsonType: Number diff --git a/generator/config/expression/log10.yaml b/generator/config/expression/log10.yaml index 77cab075a..9be981e08 100644 --- a/generator/config/expression/log10.yaml +++ b/generator/config/expression/log10.yaml @@ -1,27 +1,31 @@ # $schema: ../schema.json name: $log10 -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/log10/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/log10/ type: - resolvesToDouble encode: single description: | Calculates the log base 10 of a number. arguments: - - - name: number - type: - - resolvesToNumber - description: | - Any valid expression as long as it resolves to a non-negative number. + - name: number + type: + - resolvesToNumber + description: | + Any valid expression as long as it resolves to a non-negative number. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/log10/#example' - pipeline: - - - $project: - pH: - $multiply: - - -1 - - - $log10: '$H3O' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/log10/#example + pipeline: + - $project: + pH: + $multiply: + - -1 + - $log10: $H3O + schema: + samples: + _id: + types: + - bsonType: Number + H3O: + types: + - bsonType: Number diff --git a/generator/config/expression/lt.yaml b/generator/config/expression/lt.yaml index 4b7319b97..d64831d6d 100644 --- a/generator/config/expression/lt.yaml +++ b/generator/config/expression/lt.yaml @@ -1,31 +1,41 @@ # $schema: ../schema.json name: $lt -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/lt/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/lt/ type: - resolvesToBool encode: array description: | Returns true if the first value is less than the second. arguments: - - - name: expression1 - type: - - expression - - - name: expression2 - type: - - expression + - name: expression1 + type: + - expression + - name: expression2 + type: + - expression tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/lt/#example' - pipeline: - - - $project: - item: 1 - qty: 1 - qtyLt250: - $lt: - - '$qty' - - 250 - _id: 0 + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/lt/#example + pipeline: + - $project: + item: 1 + qty: 1 + qtyLt250: + $lt: + - $qty + - 250 + _id: 0 + schema: + inventory: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + description: + types: + - bsonType: String + qty: + types: + - bsonType: Number diff --git a/generator/config/expression/lte.yaml b/generator/config/expression/lte.yaml index 91c7b1d88..c79ce0163 100644 --- a/generator/config/expression/lte.yaml +++ b/generator/config/expression/lte.yaml @@ -1,31 +1,41 @@ # $schema: ../schema.json name: $lte -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/lte/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/lte/ type: - resolvesToBool encode: array description: | Returns true if the first value is less than or equal to the second. arguments: - - - name: expression1 - type: - - expression - - - name: expression2 - type: - - expression + - name: expression1 + type: + - expression + - name: expression2 + type: + - expression tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/lte/#example' - pipeline: - - - $project: - item: 1 - qty: 1 - qtyLte250: - $lte: - - '$qty' - - 250 - _id: 0 + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/lte/#example + pipeline: + - $project: + item: 1 + qty: 1 + qtyLte250: + $lte: + - $qty + - 250 + _id: 0 + schema: + inventory: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + description: + types: + - bsonType: String + qty: + types: + - bsonType: Number diff --git a/generator/config/expression/ltrim.yaml b/generator/config/expression/ltrim.yaml index 992b70616..9a0c5705c 100644 --- a/generator/config/expression/ltrim.yaml +++ b/generator/config/expression/ltrim.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $ltrim -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/ltrim/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/ltrim/ type: - resolvesToString encode: object @@ -8,29 +8,40 @@ description: | Removes whitespace or the specified characters from the beginning of a string. New in MongoDB 4.0. arguments: - - - name: input - type: - - resolvesToString - description: | - The string to trim. The argument can be any valid expression that resolves to a string. - - - name: chars - type: - - resolvesToString - optional: true - description: | - The character(s) to trim from the beginning of the input. - The argument can be any valid expression that resolves to a string. The $ltrim operator breaks down the string into individual UTF code point to trim from input. - If unspecified, $ltrim removes whitespace characters, including the null character. + - name: input + type: + - resolvesToString + description: | + The string to trim. The argument can be any valid expression that resolves to a string. + - name: chars + type: + - resolvesToString + optional: true + description: | + The character(s) to trim from the beginning of the input. + The argument can be any valid expression that resolves to a string. The $ltrim operator breaks down the string into individual UTF code point to trim from input. + If unspecified, $ltrim removes whitespace characters, including the null character. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/ltrim/#example' - pipeline: - - - $project: - item: 1 - description: - $ltrim: - input: '$description' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/ltrim/#example + pipeline: + - $project: + item: 1 + description: + $ltrim: + input: $description + schema: + inventory: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + quarter: + types: + - bsonType: String + description: + types: + - bsonType: String + - bsonType: 'Null' diff --git a/generator/config/expression/map.yaml b/generator/config/expression/map.yaml index 11db40c24..d11e26eb3 100644 --- a/generator/config/expression/map.yaml +++ b/generator/config/expression/map.yaml @@ -1,76 +1,91 @@ # $schema: ../schema.json name: $map -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/map/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/map/ type: - resolvesToArray encode: object description: | Applies a subexpression to each element of an array and returns the array of resulting values in order. Accepts named parameters. arguments: - - - name: input - type: - - resolvesToArray - description: | - An expression that resolves to an array. - - - name: as - type: - - resolvesToString - optional: true - description: | - 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. - - - name: in - type: - - expression - description: | - 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. + - name: input + type: + - resolvesToArray + description: | + An expression that resolves to an array. + - name: as + type: + - resolvesToString + optional: true + description: | + 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. + - name: in + type: + - expression + description: | + 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. tests: - - - name: 'Add to Each Element of an Array' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/map/#add-to-each-element-of-an-array' - pipeline: - - - $project: - adjustedGrades: - $map: - input: '$quizzes' - as: 'grade' - in: - $add: - - '$$grade' - - 2 - - - name: 'Truncate Each Array Element' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/map/#truncate-each-array-element' - pipeline: - - - $project: - city: '$city' - integerValues: - $map: - input: '$distances' - as: 'decimalValue' - in: - # Example uses the short form, the builder always generates the verbose form - # $trunc: '$$decimalValue' - $trunc: - - '$$decimalValue' - - - name: 'Convert Celsius Temperatures to Fahrenheit' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/map/#convert-celsius-temperatures-to-fahrenheit' - pipeline: - - - $addFields: - tempsF: - $map: - input: '$tempsC' - as: 'tempInCelsius' - in: - $add: - - - $multiply: - - '$$tempInCelsius' - - 1.8 - - 32 + - name: Add to Each Element of an Array + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/map/#add-to-each-element-of-an-array + pipeline: + - $project: + adjustedGrades: + $map: + input: $quizzes + as: grade + in: + $add: + - $$grade + - 2 + schema: + grades: + quizzes: + types: + - bsonType: Array + types: + - bsonType: Number + - name: Truncate Each Array Element + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/map/#truncate-each-array-element + pipeline: + - $project: + city: $city + integerValues: + $map: + input: $distances + as: decimalValue + in: + $trunc: + - $$decimalValue + schema: + deliveries: + city: + types: + - bsonType: String + distances: + types: + - bsonType: Array + types: + - bsonType: Number + - name: Convert Celsius Temperatures to Fahrenheit + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/map/#convert-celsius-temperatures-to-fahrenheit + pipeline: + - $addFields: + tempsF: + $map: + input: $tempsC + as: tempInCelsius + in: + $add: + - $multiply: + - $$tempInCelsius + - 1.8 + - 32 + schema: + temperatures: + date: + types: + - bsonType: Date + tempsC: + types: + - bsonType: Array + types: + - bsonType: Number diff --git a/generator/config/expression/max.yaml b/generator/config/expression/max.yaml index b413679c5..cf38edf95 100644 --- a/generator/config/expression/max.yaml +++ b/generator/config/expression/max.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $max -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/max/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/max/ type: - resolvesToAny encode: single @@ -8,28 +8,43 @@ description: | Returns the maximum value that results from applying an expression to each document. Changed in MongoDB 5.0: Available in the $setWindowFields stage. arguments: - - - name: expression - type: - - expression - variadic: array + - name: expression + type: + - expression + variadic: array tests: - - - name: 'Use in $project Stage' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/max/#use-in--project-stage' - pipeline: - - - $project: - quizMax: - # Example uses the short form, the builder always generates the verbose form - # $max: '$quizzes' - $max: - - '$quizzes' - labMax: - # $max: '$labs' - $max: - - '$labs' - examMax: - $max: - - '$final' - - '$midterm' + - name: Use in $project Stage + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/max/#use-in--project-stage + pipeline: + - $project: + quizMax: + $max: + - $quizzes + labMax: + $max: + - $labs + examMax: + $max: + - $final + - $midterm + schema: + TestCollection: + _id: + types: + - bsonType: Number + quizzes: + types: + - bsonType: Array + types: + - bsonType: Number + labs: + types: + - bsonType: Array + types: + - bsonType: Number + final: + types: + - bsonType: Number + midterm: + types: + - bsonType: Number diff --git a/generator/config/expression/maxN.yaml b/generator/config/expression/maxN.yaml index e0d9d243e..24f87372a 100644 --- a/generator/config/expression/maxN.yaml +++ b/generator/config/expression/maxN.yaml @@ -1,32 +1,40 @@ # $schema: ../schema.json name: $maxN -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/maxN-array-element/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/maxN-array-element/ type: - resolvesToArray encode: object description: | Returns the n largest values in an array. Distinct from the $maxN accumulator. arguments: - - - name: input - type: - - resolvesToArray - description: | - An expression that resolves to the array from which to return the maximal n elements. - - - name: 'n' - type: - - resolvesToInt - description: | - An expression that resolves to a positive integer. The integer specifies the number of array elements that $maxN returns. + - name: input + type: + - resolvesToArray + description: | + An expression that resolves to the array from which to return the maximal n elements. + - name: n + type: + - resolvesToInt + description: | + An expression that resolves to a positive integer. The integer specifies the number of array elements that $maxN returns. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/maxN-array-element/#example' - pipeline: - - - $addFields: - maxScores: - $maxN: - n: 2 - input: '$score' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/maxN-array-element/#example + pipeline: + - $addFields: + maxScores: + $maxN: + n: 2 + input: $score + schema: + scores: + playerId: + types: + - bsonType: Number + score: + types: + - bsonType: Array + types: + - bsonType: Number + - bsonType: 'Null' + - bsonType: String diff --git a/generator/config/expression/median.yaml b/generator/config/expression/median.yaml index 2aac26a1f..b286bc921 100644 --- a/generator/config/expression/median.yaml +++ b/generator/config/expression/median.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $median -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/median/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/median/ type: - resolvesToDouble encode: object @@ -12,32 +12,42 @@ description: | $setWindowFields It is also available as an aggregation expression. arguments: - - - name: input - type: - - resolvesToNumber - - array # of number - description: | - $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. - - - name: method - type: - - accumulatorPercentile - description: | - The method that mongod uses to calculate the 50th percentile value. The method must be 'approximate'. + - name: input + type: + - resolvesToNumber + - array + description: | + $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. + - name: method + type: + - accumulatorPercentile + description: | + The method that mongod uses to calculate the 50th percentile value. The method must be 'approximate'. tests: - - - name: 'Use $median in a $project Stage' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/median/#use-operatorname-in-a--project-stage' - pipeline: - - - $project: - _id: 0 - studentId: 1 - testMedians: - $median: - input: - - '$test01' - - '$test02' - - '$test03' - method: 'approximate' + - name: Use $median in a $project Stage + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/median/#use-operatorname-in-a--project-stage + pipeline: + - $project: + _id: 0 + studentId: 1 + testMedians: + $median: + input: + - $test01 + - $test02 + - $test03 + method: approximate + schema: + testScores: + studentId: + types: + - bsonType: String + test01: + types: + - bsonType: Number + test02: + types: + - bsonType: Number + test03: + types: + - bsonType: Number diff --git a/generator/config/expression/mergeObjects.yaml b/generator/config/expression/mergeObjects.yaml index 928166852..c56b7fd81 100644 --- a/generator/config/expression/mergeObjects.yaml +++ b/generator/config/expression/mergeObjects.yaml @@ -1,39 +1,47 @@ # $schema: ../schema.json name: $mergeObjects -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/mergeObjects/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/mergeObjects/ type: - resolvesToObject encode: single description: | Combines multiple documents into a single document. arguments: - - - name: document - type: - - resolvesToObject - variadic: array - description: | - Any valid expression that resolves to a document. + - name: document + type: + - resolvesToObject + variadic: array + description: | + Any valid expression that resolves to a document. tests: - - - name: '$mergeObjects' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/mergeObjects/#-mergeobjects' - pipeline: - - - $lookup: - from: 'items' - localField: 'item' - foreignField: 'item' - as: 'fromItems' - - - $replaceRoot: - newRoot: - $mergeObjects: - - - $arrayElemAt: - - '$fromItems' - - 0 - - '$$ROOT' - - - $project: - fromItems: 0 + - name: $mergeObjects + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/mergeObjects/#-mergeobjects + pipeline: + - $lookup: + from: items + localField: item + foreignField: item + as: fromItems + - $replaceRoot: + newRoot: + $mergeObjects: + - $arrayElemAt: + - $fromItems + - 0 + - $$ROOT + - $project: + fromItems: 0 + schema: + orders: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + price: + types: + - bsonType: Number + ordered: + types: + - bsonType: Number diff --git a/generator/config/expression/meta.yaml b/generator/config/expression/meta.yaml index 9a96f7aaf..8e89b7c70 100644 --- a/generator/config/expression/meta.yaml +++ b/generator/config/expression/meta.yaml @@ -1,39 +1,54 @@ # $schema: ../schema.json name: $meta -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/meta/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/meta/ type: - resolvesToAny encode: single description: | Access available per-document metadata related to the aggregation operation. arguments: - - - name: keyword - type: - - string + - name: keyword + type: + - string tests: - - - name: 'textScore' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/meta/#-meta---textscore-' - pipeline: - - - $match: - $text: - $search: 'cake' - - - $group: - _id: - $meta: 'textScore' - count: - $sum: 1 - - - name: 'indexKey' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/meta/#-meta---indexkey-' - pipeline: - - - $match: - type: 'apparel' - - - $addFields: - idxKey: - $meta: 'indexKey' + - name: textScore + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/meta/#-meta---textscore- + pipeline: + - $match: + $text: + $search: cake + - $group: + _id: + $meta: textScore + count: + $sum: 1 + schema: + articles: + _id: + types: + - bsonType: Number + title: + types: + - bsonType: String + - name: indexKey + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/meta/#-meta---indexkey- + pipeline: + - $match: + type: apparel + - $addFields: + idxKey: + $meta: indexKey + schema: + orders: + item: + types: + - bsonType: String + price: + types: + - bsonType: Decimal128 + quantity: + types: + - bsonType: Number + type: + types: + - bsonType: String diff --git a/generator/config/expression/millisecond.yaml b/generator/config/expression/millisecond.yaml index af1d26e75..bb186331a 100644 --- a/generator/config/expression/millisecond.yaml +++ b/generator/config/expression/millisecond.yaml @@ -1,36 +1,47 @@ # $schema: ../schema.json name: $millisecond -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/millisecond/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/millisecond/ type: - resolvesToInt encode: object description: | Returns the milliseconds of a date as a number between 0 and 999. arguments: - - - name: date - type: - - resolvesToDate - - resolvesToTimestamp - - resolvesToObjectId - description: | - The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. - - - name: timezone - type: - - resolvesToString - optional: true - description: | - The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. + - name: date + type: + - resolvesToDate + - resolvesToTimestamp + - resolvesToObjectId + description: | + The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + - name: timezone + type: + - resolvesToString + optional: true + description: | + The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/millisecond/#example' - pipeline: - - - $project: - milliseconds: - # Example uses the short form, the builder always generates the verbose form - # $millisecond: '$date' - $millisecond: - date: '$date' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/millisecond/#example + pipeline: + - $project: + milliseconds: + $millisecond: + date: $date + schema: + sales: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + price: + types: + - bsonType: Number + quantity: + types: + - bsonType: Number + date: + types: + - bsonType: Date diff --git a/generator/config/expression/min.yaml b/generator/config/expression/min.yaml index 1212fd4f7..837551f12 100644 --- a/generator/config/expression/min.yaml +++ b/generator/config/expression/min.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $min -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/min/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/min/ type: - resolvesToAny encode: single @@ -8,28 +8,43 @@ description: | Returns the minimum value that results from applying an expression to each document. Changed in MongoDB 5.0: Available in the $setWindowFields stage. arguments: - - - name: expression - type: - - expression - variadic: array + - name: expression + type: + - expression + variadic: array tests: - - - name: 'Use in $project Stage' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/min/#use-in--project-stage' - pipeline: - - - $project: - quizMin: - # Example uses the short form, the builder always generates the verbose form - # $min: '$quizzes' - $min: - - '$quizzes' - labMin: - # $min: '$labs' - $min: - - '$labs' - examMin: - $min: - - '$final' - - '$midterm' + - name: Use in $project Stage + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/min/#use-in--project-stage + pipeline: + - $project: + quizMin: + $min: + - $quizzes + labMin: + $min: + - $labs + examMin: + $min: + - $final + - $midterm + schema: + TestCollection: + _id: + types: + - bsonType: Number + quizzes: + types: + - bsonType: Array + types: + - bsonType: Number + labs: + types: + - bsonType: Array + types: + - bsonType: Number + final: + types: + - bsonType: Number + midterm: + types: + - bsonType: Number diff --git a/generator/config/expression/minN.yaml b/generator/config/expression/minN.yaml index e7fa8cac1..a3e5a7558 100644 --- a/generator/config/expression/minN.yaml +++ b/generator/config/expression/minN.yaml @@ -1,32 +1,40 @@ # $schema: ../schema.json name: $minN -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/minN-array-element/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/minN-array-element/ type: - resolvesToArray encode: object description: | Returns the n smallest values in an array. Distinct from the $minN accumulator. arguments: - - - name: input - type: - - resolvesToArray - description: | - An expression that resolves to the array from which to return the maximal n elements. - - - name: 'n' - type: - - resolvesToInt - description: | - An expression that resolves to a positive integer. The integer specifies the number of array elements that $maxN returns. + - name: input + type: + - resolvesToArray + description: | + An expression that resolves to the array from which to return the maximal n elements. + - name: n + type: + - resolvesToInt + description: | + An expression that resolves to a positive integer. The integer specifies the number of array elements that $maxN returns. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/minN-array-element/#example' - pipeline: - - - $addFields: - minScores: - $minN: - n: 2 - input: '$score' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/minN-array-element/#example + pipeline: + - $addFields: + minScores: + $minN: + n: 2 + input: $score + schema: + scores: + playerId: + types: + - bsonType: Number + score: + types: + - bsonType: Array + types: + - bsonType: Number + - bsonType: 'Null' + - bsonType: String diff --git a/generator/config/expression/minute.yaml b/generator/config/expression/minute.yaml index 109e87f6b..68a41ea5b 100644 --- a/generator/config/expression/minute.yaml +++ b/generator/config/expression/minute.yaml @@ -1,36 +1,47 @@ # $schema: ../schema.json name: $minute -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/minute/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/minute/ type: - resolvesToInt encode: object description: | Returns the minute for a date as a number between 0 and 59. arguments: - - - name: date - type: - - resolvesToDate - - resolvesToTimestamp - - resolvesToObjectId - description: | - The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. - - - name: timezone - type: - - resolvesToString - optional: true - description: | - The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. + - name: date + type: + - resolvesToDate + - resolvesToTimestamp + - resolvesToObjectId + description: | + The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + - name: timezone + type: + - resolvesToString + optional: true + description: | + The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/minute/#example' - pipeline: - - - $project: - minutes: - # Example uses the short form, the builder always generates the verbose form - # $minute: '$date' - $minute: - date: '$date' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/minute/#example + pipeline: + - $project: + minutes: + $minute: + date: $date + schema: + sales: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + price: + types: + - bsonType: Number + quantity: + types: + - bsonType: Number + date: + types: + - bsonType: Date diff --git a/generator/config/expression/mod.yaml b/generator/config/expression/mod.yaml index 0ac48bd54..2424d0b78 100644 --- a/generator/config/expression/mod.yaml +++ b/generator/config/expression/mod.yaml @@ -1,30 +1,40 @@ # $schema: ../schema.json name: $mod -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/mod/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/mod/ type: - resolvesToInt encode: array description: | Returns the remainder of the first number divided by the second. Accepts two argument expressions. arguments: - - - name: dividend - type: - - resolvesToNumber - description: | - The first argument is the dividend, and the second argument is the divisor; i.e. first argument is divided by the second argument. - - - name: divisor - type: - - resolvesToNumber + - name: dividend + type: + - resolvesToNumber + description: | + The first argument is the dividend, and the second argument is the divisor; i.e. first argument is divided by the second argument. + - name: divisor + type: + - resolvesToNumber tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/mod/#example' - pipeline: - - - $project: - remainder: - $mod: - - '$hours' - - '$tasks' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/mod/#example + pipeline: + - $project: + remainder: + $mod: + - $hours + - $tasks + schema: + conferencePlanning: + _id: + types: + - bsonType: Number + city: + types: + - bsonType: String + hours: + types: + - bsonType: Number + tasks: + types: + - bsonType: Number diff --git a/generator/config/expression/month.yaml b/generator/config/expression/month.yaml index 7bd383be9..eb03af8e0 100644 --- a/generator/config/expression/month.yaml +++ b/generator/config/expression/month.yaml @@ -1,36 +1,47 @@ # $schema: ../schema.json name: $month -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/month/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/month/ type: - resolvesToInt encode: object description: | Returns the month for a date as a number between 1 (January) and 12 (December). arguments: - - - name: date - type: - - resolvesToDate - - resolvesToTimestamp - - resolvesToObjectId - description: | - The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. - - - name: timezone - type: - - resolvesToString - optional: true - description: | - The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. + - name: date + type: + - resolvesToDate + - resolvesToTimestamp + - resolvesToObjectId + description: | + The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + - name: timezone + type: + - resolvesToString + optional: true + description: | + The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/month/#example' - pipeline: - - - $project: - month: - # Example uses the short form, the builder always generates the verbose form - # $month: '$date' - $month: - date: '$date' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/month/#example + pipeline: + - $project: + month: + $month: + date: $date + schema: + sales: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + price: + types: + - bsonType: Number + quantity: + types: + - bsonType: Number + date: + types: + - bsonType: Date diff --git a/generator/config/expression/multiply.yaml b/generator/config/expression/multiply.yaml index 5a069cc8c..c6713ce76 100644 --- a/generator/config/expression/multiply.yaml +++ b/generator/config/expression/multiply.yaml @@ -1,30 +1,44 @@ # $schema: ../schema.json name: $multiply -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/multiply/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/multiply/ type: - resolvesToDecimal encode: single description: | Multiplies numbers to return the product. Accepts any number of argument expressions. arguments: - - - name: expression - type: - - resolvesToNumber - variadic: array - description: | - The arguments can be any valid expression as long as they resolve to numbers. - Starting in MongoDB 6.1 you can optimize the $multiply operation. To improve performance, group references at the end of the argument list. + - name: expression + type: + - resolvesToNumber + variadic: array + description: | + The arguments can be any valid expression as long as they resolve to numbers. + Starting in MongoDB 6.1 you can optimize the $multiply operation. To improve performance, group references at the end of the argument list. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/multiply/#example' - pipeline: - - - $project: - date: 1 - item: 1 - total: - $multiply: - - '$price' - - '$quantity' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/multiply/#example + pipeline: + - $project: + date: 1 + item: 1 + total: + $multiply: + - $price + - $quantity + schema: + sales: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + price: + types: + - bsonType: Number + quantity: + types: + - bsonType: Number + date: + types: + - bsonType: Date diff --git a/generator/config/expression/ne.yaml b/generator/config/expression/ne.yaml index da92f1014..cadd1f3d5 100644 --- a/generator/config/expression/ne.yaml +++ b/generator/config/expression/ne.yaml @@ -1,31 +1,41 @@ # $schema: ../schema.json name: $ne -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/ne/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/ne/ type: - resolvesToBool encode: array description: | Returns true if the values are not equivalent. arguments: - - - name: expression1 - type: - - expression - - - name: expression2 - type: - - expression + - name: expression1 + type: + - expression + - name: expression2 + type: + - expression tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/ne/#example' - pipeline: - - - $project: - item: 1 - qty: 1 - qtyNe250: - $ne: - - '$qty' - - 250 - _id: 0 + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/ne/#example + pipeline: + - $project: + item: 1 + qty: 1 + qtyNe250: + $ne: + - $qty + - 250 + _id: 0 + schema: + inventory: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + description: + types: + - bsonType: String + qty: + types: + - bsonType: Number diff --git a/generator/config/expression/not.yaml b/generator/config/expression/not.yaml index d4e4c90ea..204c10eaf 100644 --- a/generator/config/expression/not.yaml +++ b/generator/config/expression/not.yaml @@ -1,28 +1,38 @@ # $schema: ../schema.json name: $not -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/not/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/not/ type: - resolvesToBool encode: array description: | Returns the boolean value that is the opposite of its argument expression. Accepts a single argument expression. arguments: - - - name: expression - type: - - expression - - resolvesToBool + - name: expression + type: + - expression + - resolvesToBool tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/not/#example' - pipeline: - - - $project: - item: 1 - result: - $not: - - - $gt: - - '$qty' - - 250 + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/not/#example + pipeline: + - $project: + item: 1 + result: + $not: + - $gt: + - $qty + - 250 + schema: + inventory: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + description: + types: + - bsonType: String + qty: + types: + - bsonType: Number diff --git a/generator/config/expression/objectToArray.yaml b/generator/config/expression/objectToArray.yaml index 460977f33..fe29f98f0 100644 --- a/generator/config/expression/objectToArray.yaml +++ b/generator/config/expression/objectToArray.yaml @@ -1,44 +1,76 @@ # $schema: ../schema.json name: $objectToArray -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/objectToArray/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/objectToArray/ type: - resolvesToArray encode: single description: | Converts a document to an array of documents representing key-value pairs. arguments: - - - name: object - type: - - resolvesToObject - description: | - Any valid expression as long as it resolves to a document object. $objectToArray applies to the top-level fields of its argument. If the argument is a document that itself contains embedded document fields, the $objectToArray does not recursively apply to the embedded document fields. + - name: object + type: + - resolvesToObject + description: | + Any valid expression as long as it resolves to a document object. $objectToArray applies to the top-level fields of its argument. If the argument is a document that itself contains embedded document fields, the $objectToArray does not recursively apply to the embedded document fields. tests: - # "$objectToArray and $arrayToObject Example" omitted as it's already in arrayToObject.yaml - - - name: '$objectToArray Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/objectToArray/#-objecttoarray-example' - pipeline: - - - $project: - item: 1 - dimensions: - $objectToArray: '$dimensions' - - - name: '$objectToArray to Sum Nested Fields' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/objectToArray/#-objecttoarray-to-sum-nested-fields' - pipeline: - - - $project: - warehouses: - $objectToArray: '$instock' - - - # Example uses the short form, the builder always generates the verbose form - # $unwind: '$warehouses' - $unwind: - path: '$warehouses' - - - $group: - _id: '$warehouses.k' - total: - $sum: '$warehouses.v' + - name: $objectToArray Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/objectToArray/#-objecttoarray-example + pipeline: + - $project: + item: 1 + dimensions: + $objectToArray: $dimensions + schema: + inventory: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + dimensions: + types: + - bsonType: Document + fields: + l: + types: + - bsonType: Number + w: + types: + - bsonType: Number + uom: + types: + - bsonType: String + - name: $objectToArray to Sum Nested Fields + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/objectToArray/#-objecttoarray-to-sum-nested-fields + pipeline: + - $project: + warehouses: + $objectToArray: $instock + - $unwind: + path: $warehouses + - $group: + _id: $warehouses.k + total: + $sum: $warehouses.v + schema: + inventory: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + instock: + types: + - bsonType: Document + fields: + warehouse1: + types: + - bsonType: Number + warehouse2: + types: + - bsonType: Number + warehouse3: + types: + - bsonType: Number diff --git a/generator/config/expression/or.yaml b/generator/config/expression/or.yaml index 2bbce1910..50146573d 100644 --- a/generator/config/expression/or.yaml +++ b/generator/config/expression/or.yaml @@ -1,33 +1,42 @@ # $schema: ../schema.json name: $or -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/or/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/or/ type: - resolvesToBool encode: single description: | Returns true when any of its expressions evaluates to true. Accepts any number of argument expressions. arguments: - - - name: expression - type: - - expression - - resolvesToBool - variadic: array + - name: expression + type: + - expression + - resolvesToBool + variadic: array tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/or/#example' - pipeline: - - - $project: - item: 1 - result: - $or: - - - $gt: - - '$qty' - - 250 - - - $lt: - - '$qty' - - 200 + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/or/#example + pipeline: + - $project: + item: 1 + result: + $or: + - $gt: + - $qty + - 250 + - $lt: + - $qty + - 200 + schema: + inventory: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + description: + types: + - bsonType: String + qty: + types: + - bsonType: Number diff --git a/generator/config/expression/percentile.yaml b/generator/config/expression/percentile.yaml index b19fc1904..94264a114 100644 --- a/generator/config/expression/percentile.yaml +++ b/generator/config/expression/percentile.yaml @@ -1,51 +1,62 @@ # $schema: ../schema.json name: $percentile -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/percentile/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/percentile/ type: - - resolvesToArray # of scalar + - resolvesToArray encode: object description: | 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 - It is also available as an aggregation expression. arguments: - - - name: input - type: - - resolvesToNumber - - array # of number - description: | - $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. - - - name: p - type: - - resolvesToArray # of resolvesToNumber - description: | - $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. - $percentile returns results in the same order as the elements in p. - - - name: method - type: - - accumulatorPercentile - description: | - The method that mongod uses to calculate the percentile value. The method must be 'approximate'. + - name: input + type: + - resolvesToNumber + - array + description: | + $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. + - name: p + type: + - resolvesToArray + description: | + $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. + $percentile returns results in the same order as the elements in p. + - name: method + type: + - accumulatorPercentile + description: | + The method that mongod uses to calculate the percentile value. The method must be 'approximate'. tests: - - - name: 'Use $percentile in a $project Stage' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/percentile/#use-operatorname-in-a--project-stage' - pipeline: - - - $project: - _id: 0 - studentId: 1 - testPercentiles: - $percentile: - input: ['$test01', '$test02', '$test03'] - p: [0.5, 0.95] - method: 'approximate' + - name: Use $percentile in a $project Stage + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/percentile/#use-operatorname-in-a--project-stage + pipeline: + - $project: + _id: 0 + studentId: 1 + testPercentiles: + $percentile: + input: + - $test01 + - $test02 + - $test03 + p: + - 0.5 + - 0.95 + method: approximate + schema: + testScores: + studentId: + types: + - bsonType: String + test01: + types: + - bsonType: Number + test02: + types: + - bsonType: Number + test03: + types: + - bsonType: Number diff --git a/generator/config/expression/pow.yaml b/generator/config/expression/pow.yaml index afab7f875..110a72249 100644 --- a/generator/config/expression/pow.yaml +++ b/generator/config/expression/pow.yaml @@ -1,31 +1,45 @@ # $schema: ../schema.json name: $pow -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/pow/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/pow/ type: - resolvesToNumber encode: array description: | Raises a number to the specified exponent. arguments: - - - name: number - type: - - resolvesToNumber - - - name: exponent - type: - - resolvesToNumber + - name: number + type: + - resolvesToNumber + - name: exponent + type: + - resolvesToNumber tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/pow/#example' - pipeline: - - - $project: - variance: - $pow: - - - # Example uses the short form, the builder always generates the verbose form - # $stdDevPop: '$scores.score' - $stdDevPop: ['$scores.score'] - - 2 + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/pow/#example + pipeline: + - $project: + variance: + $pow: + - $stdDevPop: + - $scores.score + - 2 + schema: + quizzes: + _id: + types: + - bsonType: Number + scores: + types: + - bsonType: Array + types: + - bsonType: Document + fields: + name: + types: + - bsonType: String + score: + types: + - bsonType: Number + quiz: + types: + - bsonType: Number diff --git a/generator/config/expression/radiansToDegrees.yaml b/generator/config/expression/radiansToDegrees.yaml index be4dd1e1d..b33a25aa1 100644 --- a/generator/config/expression/radiansToDegrees.yaml +++ b/generator/config/expression/radiansToDegrees.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $radiansToDegrees -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/radiansToDegrees/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/radiansToDegrees/ type: - resolvesToDouble - resolvesToDecimal @@ -8,20 +8,28 @@ encode: single description: | Converts a value from radians to degrees. arguments: - - - name: expression - type: - - resolvesToNumber + - name: expression + type: + - resolvesToNumber tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/radiansToDegrees/#example' - pipeline: - - - $addFields: - angle_a_deg: - $radiansToDegrees: '$angle_a' - angle_b_deg: - $radiansToDegrees: '$angle_b' - angle_c_deg: - $radiansToDegrees: '$angle_c' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/radiansToDegrees/#example + pipeline: + - $addFields: + angle_a_deg: + $radiansToDegrees: $angle_a + angle_b_deg: + $radiansToDegrees: $angle_b + angle_c_deg: + $radiansToDegrees: $angle_c + schema: + TestCollection: + angle_a: + types: + - bsonType: Decimal128 + angle_b: + types: + - bsonType: Decimal128 + angle_c: + types: + - bsonType: Decimal128 diff --git a/generator/config/expression/rand.yaml b/generator/config/expression/rand.yaml index a19f3163e..9d84f4a9b 100644 --- a/generator/config/expression/rand.yaml +++ b/generator/config/expression/rand.yaml @@ -1,48 +1,61 @@ # $schema: ../schema.json name: $rand -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/rand/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/rand/ type: - resolvesToDouble encode: object description: | Returns a random float between 0 and 1 tests: - - - name: 'Generate Random Data Points' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/rand/#generate-random-data-points' - pipeline: - - - $set: - amount: - $multiply: - - - $rand: {} - - 100 - - - $set: - amount: - $floor: '$amount' - - - # Example uses the short form, the builder always generates the verbose form - # $merge: 'donors' - $merge: - into: 'donors' - - - name: 'Select Random Items From a Collection' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/rand/#select-random-items-from-a-collection' - pipeline: - - - $match: - district: 3 - - - $match: - $expr: - $lt: - - 0.5 - - - $rand: {} - - - $project: - _id: 0 - name: 1 - registered: 1 + - name: Generate Random Data Points + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/rand/#generate-random-data-points + pipeline: + - $set: + amount: + $multiply: + - $rand: {} + - 100 + - $set: + amount: + $floor: $amount + - $merge: + into: donors + schema: + donors: + donorId: + types: + - bsonType: Number + amount: + types: + - bsonType: Number + frequency: + types: + - bsonType: Number + - name: Select Random Items From a Collection + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/rand/#select-random-items-from-a-collection + pipeline: + - $match: + district: 3 + - $match: + $expr: + $lt: + - 0.5 + - $rand: {} + - $project: + _id: 0 + name: 1 + registered: 1 + schema: + voters: + name: + types: + - bsonType: String + voterId: + types: + - bsonType: Number + district: + types: + - bsonType: Number + registered: + types: + - bsonType: Boolean diff --git a/generator/config/expression/range.yaml b/generator/config/expression/range.yaml index 5c78d8898..536734e54 100644 --- a/generator/config/expression/range.yaml +++ b/generator/config/expression/range.yaml @@ -1,42 +1,48 @@ # $schema: ../schema.json name: $range -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/range/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/range/ type: - - resolvesToArray # of int + - resolvesToArray encode: array description: | Outputs an array containing a sequence of integers according to user-defined inputs. arguments: - - - name: start - type: - - resolvesToInt - description: | - An integer that specifies the start of the sequence. Can be any valid expression that resolves to an integer. - - - name: end - type: - - resolvesToInt - description: | - An integer that specifies the exclusive upper limit of the sequence. Can be any valid expression that resolves to an integer. - - - name: step - type: - - resolvesToInt - optional: true - description: | - An integer that specifies the increment value. Can be any valid expression that resolves to a non-zero integer. Defaults to 1. + - name: start + type: + - resolvesToInt + description: | + An integer that specifies the start of the sequence. Can be any valid expression that resolves to an integer. + - name: end + type: + - resolvesToInt + description: | + An integer that specifies the exclusive upper limit of the sequence. Can be any valid expression that resolves to an integer. + - name: step + type: + - resolvesToInt + optional: true + description: | + An integer that specifies the increment value. Can be any valid expression that resolves to a non-zero integer. Defaults to 1. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/range/#example' - pipeline: - - - $project: - _id: 0 - city: 1 - Rest stops: - $range: - - 0 - - '$distance' - - 25 + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/range/#example + pipeline: + - $project: + _id: 0 + city: 1 + Rest stops: + $range: + - 0 + - $distance + - 25 + schema: + distances: + _id: + types: + - bsonType: Number + city: + types: + - bsonType: String + distance: + types: + - bsonType: Number diff --git a/generator/config/expression/reduce.yaml b/generator/config/expression/reduce.yaml index bf51eabe3..d77a7afd3 100644 --- a/generator/config/expression/reduce.yaml +++ b/generator/config/expression/reduce.yaml @@ -1,134 +1,213 @@ # $schema: ../schema.json name: $reduce -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/reduce/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/reduce/ type: - resolvesToAny encode: object description: | Applies an expression to each element in an array and combines them into a single value. arguments: - - - name: input - type: - - resolvesToArray - description: | - Can be any valid expression that resolves to an array. - If the argument resolves to a value of null or refers to a missing field, $reduce returns null. - If the argument does not resolve to an array or null nor refers to a missing field, $reduce returns an error. - - - name: initialValue - type: - - expression - description: | - The initial cumulative value set before in is applied to the first element of the input array. - - - name: in - type: - - expression - description: | - A valid expression that $reduce applies to each element in the input array in left-to-right order. Wrap the input value with $reverseArray to yield the equivalent of applying the combining expression from right-to-left. - During evaluation of the in expression, two variables will be available: - - value is the variable that represents the cumulative value of the expression. - - this is the variable that refers to the element being processed. + - name: input + type: + - resolvesToArray + description: | + Can be any valid expression that resolves to an array. + If the argument resolves to a value of null or refers to a missing field, $reduce returns null. + If the argument does not resolve to an array or null nor refers to a missing field, $reduce returns an error. + - name: initialValue + type: + - expression + description: | + The initial cumulative value set before in is applied to the first element of the input array. + - name: in + type: + - expression + - expressionMap + syntheticVariables: + - name: this + description: | + The variable that represents the cumulative value of the expression. + - name: value + description: | + The variable that refers to the element being processed. + description: | + A valid expression that $reduce applies to each element in the input array in left-to-right order. Wrap the input value with $reverseArray to yield the equivalent of applying the combining expression from right-to-left. + During evaluation of the in expression, two variables will be available: + - value is the variable that represents the cumulative value of the expression. + - this is the variable that refers to the element being processed. tests: - - - name: 'Multiplication' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/reduce/#multiplication' - pipeline: - - - $group: - _id: '$experimentId' - probabilityArr: - $push: '$probability' - - - $project: - description: 1 - results: - $reduce: - input: '$probabilityArr' - initialValue: 1 - in: - $multiply: - - '$$value' - - '$$this' - - - name: 'Discounted Merchandise' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/reduce/#discounted-merchandise' - pipeline: - - - $project: - discountedPrice: - $reduce: - input: '$discounts' - initialValue: '$price' - in: - $multiply: - - '$$value' - - - $subtract: - - 1 - - '$$this' - - - name: 'String Concatenation' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/reduce/#string-concatenation' - pipeline: - # Filter to return only non-empty arrays - - - $match: - hobbies: - $gt: [] - - - $project: - name: 1 - bio: - $reduce: - input: '$hobbies' - initialValue: 'My hobbies include:' - in: - $concat: - - '$$value' - - - $cond: - if: - $eq: - - '$$value' - - 'My hobbies include:' - then: ' ' - else: ', ' - - '$$this' - - - name: 'Array Concatenation' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/reduce/#array-concatenation' - pipeline: - - - $project: - collapsed: - $reduce: - input: '$arr' - initialValue: [] - in: + - name: Multiplication + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/reduce/#multiplication + pipeline: + - $group: + _id: $experimentId + probabilityArr: + $push: $probability + - $project: + description: 1 + results: + $reduce: + input: $probabilityArr + initialValue: 1 + in: + $multiply: + - $$value + - $$this + schema: + events: + _id: + types: + - bsonType: Number + type: + types: + - bsonType: String + experimentId: + types: + - bsonType: String + description: + types: + - bsonType: String + eventNum: + types: + - bsonType: Number + probability: + types: + - bsonType: Number + - name: Discounted Merchandise + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/reduce/#discounted-merchandise + pipeline: + - $project: + discountedPrice: + $reduce: + input: $discounts + initialValue: $price + in: + $multiply: + - $$value + - $subtract: + - 1 + - $$this + schema: + clothes: + _id: + types: + - bsonType: Number + productId: + types: + - bsonType: String + description: + types: + - bsonType: String + color: + types: + - bsonType: String + size: + types: + - bsonType: String + price: + types: + - bsonType: Number + discounts: + types: + - bsonType: Array + types: + - bsonType: Number + - name: String Concatenation + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/reduce/#string-concatenation + pipeline: + - $match: + hobbies: + $gt: [] + - $project: + name: 1 + bio: + $reduce: + input: $hobbies + initialValue: 'My hobbies include:' + in: + $concat: + - $$value + - $cond: + if: + $eq: + - $$value + - 'My hobbies include:' + then: ' ' + else: ', ' + - $$this + schema: + people: + _id: + types: + - bsonType: Number + name: + types: + - bsonType: String + hobbies: + types: + - bsonType: Array + types: + - bsonType: String + - name: Array Concatenation + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/reduce/#array-concatenation + pipeline: + - $project: + collapsed: + $reduce: + input: $arr + initialValue: [] + in: + $concatArrays: + - $$value + - $$this + schema: + matrices: + _id: + types: + - bsonType: Number + arr: + types: + - bsonType: Array + types: + - bsonType: Array + types: + - bsonType: Number + - name: Computing a Multiple Reductions + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/reduce/#computing-a-multiple-reductions + pipeline: + - $project: + results: + $reduce: + input: $arr + initialValue: [] + in: + collapsed: $concatArrays: - - '$$value' - - '$$this' - - - name: 'Computing a Multiple Reductions' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/reduce/#computing-a-multiple-reductions' - pipeline: - - - $project: - results: - $reduce: - input: '$arr' - initialValue: [] - in: - collapsed: - $concatArrays: - - '$$value.collapsed' - - '$$this' - firstValues: - $concatArrays: - - '$$value.firstValues' - - - $slice: - - '$$this' - - 1 + - $$value.collapsed + - $$this + firstValues: + $concatArrays: + - $$value.firstValues + - $slice: + - $$this + - 1 + schema: + events: + _id: + types: + - bsonType: Number + type: + types: + - bsonType: String + experimentId: + types: + - bsonType: String + description: + types: + - bsonType: String + eventNum: + types: + - bsonType: Number + probability: + types: + - bsonType: Number diff --git a/generator/config/expression/regexFind.yaml b/generator/config/expression/regexFind.yaml index d953a4ae6..b8440404a 100644 --- a/generator/config/expression/regexFind.yaml +++ b/generator/config/expression/regexFind.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $regexFind -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/regexFind/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/regexFind/ type: - resolvesToObject encode: object @@ -8,59 +8,65 @@ description: | Applies a regular expression (regex) to a string and returns information on the first matched substring. New in MongoDB 4.2. arguments: - - - name: input - type: - - resolvesToString - description: | - The string on which you wish to apply the regex pattern. Can be a string or any valid expression that resolves to a string. - - - name: regex - type: - - resolvesToString - - regex - description: | - The regex pattern to apply. Can be any valid expression that resolves to either a string or regex pattern //. When using the regex //, you can also specify the regex options i and m (but not the s or x options) - - - name: options - type: - - string - optional: true + - name: input + type: + - resolvesToString + description: | + The string on which you wish to apply the regex pattern. Can be a string or any valid expression that resolves to a string. + - name: regex + type: + - resolvesToString + - regex + description: | + The regex pattern to apply. Can be any valid expression that resolves to either a string or regex pattern //. When using the regex //, you can also specify the regex options i and m (but not the s or x options) + - name: options + type: + - string + optional: true tests: - - - name: '$regexFind and Its Options' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/regexFind/#-regexfind-and-its-options' - pipeline: - - - $addFields: - returnObject: - $regexFind: - input: '$description' - regex: !bson_regex 'line' - - - name: 'i Option' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/regexFind/#i-option' - pipeline: - - - $addFields: - returnObject: - # Specify i as part of the Regex type - $regexFind: - input: '$description' - regex: !bson_regex ['line', 'i'] - - - $addFields: - returnObject: - # Specify i in the options field - $regexFind: - input: '$description' - regex: 'line' - options: 'i' - - - $addFields: - returnObject: - # Mix Regex type with options field - $regexFind: - input: '$description' - regex: !bson_regex 'line' - options: 'i' + - name: $regexFind and Its Options + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/regexFind/#-regexfind-and-its-options + pipeline: + - $addFields: + returnObject: + $regexFind: + input: $description + regex: !bson_regex line + schema: + products: + _id: + types: + - bsonType: Number + description: + types: + - bsonType: String + - name: i Option + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/regexFind/#i-option + pipeline: + - $addFields: + returnObject: + $regexFind: + input: $description + regex: !bson_regex + - line + - i + - $addFields: + returnObject: + $regexFind: + input: $description + regex: line + options: i + - $addFields: + returnObject: + $regexFind: + input: $description + regex: !bson_regex line + options: i + schema: + products: + _id: + types: + - bsonType: Number + description: + types: + - bsonType: String diff --git a/generator/config/expression/regexFindAll.yaml b/generator/config/expression/regexFindAll.yaml index 6aea184d7..fefd041c5 100644 --- a/generator/config/expression/regexFindAll.yaml +++ b/generator/config/expression/regexFindAll.yaml @@ -1,99 +1,119 @@ # $schema: ../schema.json name: $regexFindAll -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/regexFindAll/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/regexFindAll/ type: - - resolvesToArray # of object + - resolvesToArray encode: object description: | Applies a regular expression (regex) to a string and returns information on the all matched substrings. New in MongoDB 4.2. arguments: - - - name: input - type: - - resolvesToString - description: | - The string on which you wish to apply the regex pattern. Can be a string or any valid expression that resolves to a string. - - - name: regex - type: - - resolvesToString - - regex - description: | - The regex pattern to apply. Can be any valid expression that resolves to either a string or regex pattern //. When using the regex //, you can also specify the regex options i and m (but not the s or x options) - - - name: options - type: - - string - optional: true + - name: input + type: + - resolvesToString + description: | + The string on which you wish to apply the regex pattern. Can be a string or any valid expression that resolves to a string. + - name: regex + type: + - resolvesToString + - regex + description: | + The regex pattern to apply. Can be any valid expression that resolves to either a string or regex pattern //. When using the regex //, you can also specify the regex options i and m (but not the s or x options) + - name: options + type: + - string + optional: true tests: - - - name: '$regexFindAll and Its Options' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/regexFindAll/#-regexfindall-and-its-options' - pipeline: - - - $addFields: - returnObject: - $regexFindAll: - input: '$description' - regex: !bson_regex 'line' - - - name: 'i Option' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/regexFindAll/#i-option' - pipeline: - - - $addFields: - returnObject: - # Specify i as part of the regex type - $regexFindAll: - input: '$description' - regex: !bson_regex ['line', 'i'] - - - $addFields: - returnObject: - # Specify i in the options field - $regexFindAll: - input: '$description' - regex: 'line' - options: 'i' - - - $addFields: - returnObject: - # Mix Regex type with options field - $regexFindAll: - input: '$description' - regex: !bson_regex 'line' - options: 'i' - - - name: 'Use $regexFindAll to Parse Email from String' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/regexFindAll/#use--regexfindall-to-parse-email-from-string' - pipeline: - - - $addFields: - email: - $regexFindAll: - input: '$comment' - regex: !bson_regex ['[a-z0-9_.+-]+@[a-z0-9_.+-]+\.[a-z0-9_.+-]+', 'i'] - - - $set: - email: '$email.match' - - - name: 'Use Captured Groupings to Parse User Name' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/regexFindAll/#use-captured-groupings-to-parse-user-name' - pipeline: - - - $addFields: - names: - $regexFindAll: - input: '$comment' - regex: !bson_regex ['([a-z0-9_.+-]+)@[a-z0-9_.+-]+\.[a-z0-9_.+-]+', 'i'] - - - $set: - names: - $reduce: - input: '$names.captures' - initialValue: [] - in: - $concatArrays: - - '$$value' - - '$$this' + - name: $regexFindAll and Its Options + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/regexFindAll/#-regexfindall-and-its-options + pipeline: + - $addFields: + returnObject: + $regexFindAll: + input: $description + regex: !bson_regex line + schema: + products: + _id: + types: + - bsonType: Number + description: + types: + - bsonType: String + - name: i Option + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/regexFindAll/#i-option + pipeline: + - $addFields: + returnObject: + $regexFindAll: + input: $description + regex: !bson_regex + - line + - i + - $addFields: + returnObject: + $regexFindAll: + input: $description + regex: line + options: i + - $addFields: + returnObject: + $regexFindAll: + input: $description + regex: !bson_regex line + options: i + schema: + products: + _id: + types: + - bsonType: Number + description: + types: + - bsonType: String + - name: Use $regexFindAll to Parse Email from String + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/regexFindAll/#use--regexfindall-to-parse-email-from-string + pipeline: + - $addFields: + email: + $regexFindAll: + input: $comment + regex: !bson_regex + - '[a-z0-9_.+-]+@[a-z0-9_.+-]+\.[a-z0-9_.+-]+' + - i + - $set: + email: $email.match + schema: + feedback: + _id: + types: + - bsonType: Number + comment: + types: + - bsonType: String + - name: Use Captured Groupings to Parse User Name + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/regexFindAll/#use-captured-groupings-to-parse-user-name + pipeline: + - $addFields: + names: + $regexFindAll: + input: $comment + regex: !bson_regex + - ([a-z0-9_.+-]+)@[a-z0-9_.+-]+\.[a-z0-9_.+-]+ + - i + - $set: + names: + $reduce: + input: $names.captures + initialValue: [] + in: + $concatArrays: + - $$value + - $$this + schema: + feedback: + _id: + types: + - bsonType: Number + comment: + types: + - bsonType: String diff --git a/generator/config/expression/regexMatch.yaml b/generator/config/expression/regexMatch.yaml index 4ea9f0aab..cb848634e 100644 --- a/generator/config/expression/regexMatch.yaml +++ b/generator/config/expression/regexMatch.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $regexMatch -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/regexMatch/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/regexMatch/ type: - resolvesToBool encode: object @@ -8,73 +8,87 @@ description: | 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. arguments: - - - name: input - type: - - resolvesToString - description: | - The string on which you wish to apply the regex pattern. Can be a string or any valid expression that resolves to a string. - - - name: regex - type: - - resolvesToString - - regex - description: | - The regex pattern to apply. Can be any valid expression that resolves to either a string or regex pattern //. When using the regex //, you can also specify the regex options i and m (but not the s or x options) - - - name: options - type: - - string - optional: true + - name: input + type: + - resolvesToString + description: | + The string on which you wish to apply the regex pattern. Can be a string or any valid expression that resolves to a string. + - name: regex + type: + - resolvesToString + - regex + description: | + The regex pattern to apply. Can be any valid expression that resolves to either a string or regex pattern //. When using the regex //, you can also specify the regex options i and m (but not the s or x options) + - name: options + type: + - string + optional: true tests: - - - name: '$regexMatch and Its Options' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/regexMatch/#-regexmatch-and-its-options' - pipeline: - - - $addFields: - result: - $regexMatch: - input: '$description' - regex: !bson_regex 'line' - - - name: 'i Option' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/regexMatch/#i-option' - pipeline: - - - $addFields: - result: - # Specify i as part of the Regex type - $regexMatch: - input: '$description' - regex: !bson_regex ['line', 'i'] - - - $addFields: - result: - # Specify i in the options field - $regexMatch: - input: '$description' - regex: 'line' - options: 'i' - - - $addFields: - result: - # Mix Regex type with options field - $regexMatch: - input: '$description' - regex: !bson_regex 'line' - options: 'i' - - - name: 'Use $regexMatch to Check Email Address' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/regexMatch/#use--regexmatch-to-check-email-address' - pipeline: - - - $addFields: - category: - $cond: - if: - $regexMatch: - input: '$comment' - regex: !bson_regex ['[a-z0-9_.+-]+@mongodb.com', 'i'] - then: 'Employee' - else: 'External' + - name: $regexMatch and Its Options + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/regexMatch/#-regexmatch-and-its-options + pipeline: + - $addFields: + result: + $regexMatch: + input: $description + regex: !bson_regex line + schema: + products: + _id: + types: + - bsonType: Number + description: + types: + - bsonType: String + - name: i Option + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/regexMatch/#i-option + pipeline: + - $addFields: + result: + $regexMatch: + input: $description + regex: !bson_regex + - line + - i + - $addFields: + result: + $regexMatch: + input: $description + regex: line + options: i + - $addFields: + result: + $regexMatch: + input: $description + regex: !bson_regex line + options: i + schema: + products: + _id: + types: + - bsonType: Number + description: + types: + - bsonType: String + - name: Use $regexMatch to Check Email Address + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/regexMatch/#use--regexmatch-to-check-email-address + pipeline: + - $addFields: + category: + $cond: + if: + $regexMatch: + input: $comment + regex: !bson_regex + - '[a-z0-9_.+-]+@mongodb.com' + - i + then: Employee + else: External + schema: + feedback: + _id: + types: + - bsonType: Number + comment: + types: + - bsonType: String diff --git a/generator/config/expression/replaceAll.yaml b/generator/config/expression/replaceAll.yaml index 74d479cb7..a21994617 100644 --- a/generator/config/expression/replaceAll.yaml +++ b/generator/config/expression/replaceAll.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $replaceAll -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceAll/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceAll/ type: - resolvesToString encode: object @@ -9,36 +9,39 @@ description: | $replaceAll is both case-sensitive and diacritic-sensitive, and ignores any collation present on a collection. New in MongoDB 4.4. arguments: - - - name: input - type: - - resolvesToString - - resolvesToNull - description: | - 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. - - - name: find - type: - - resolvesToString - - resolvesToNull - description: | - 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. - - - name: replacement - type: - - resolvesToString - - resolvesToNull - description: | - 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. + - name: input + type: + - resolvesToString + - resolvesToNull + description: | + 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. + - name: find + type: + - resolvesToString + - resolvesToNull + description: | + 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. + - name: replacement + type: + - resolvesToString + - resolvesToNull + description: | + 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. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceAll/#example' - pipeline: - - - $project: - item: - $replaceAll: - input: '$item' - find: 'blue paint' - replacement: 'red paint' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceAll/#example + pipeline: + - $project: + item: + $replaceAll: + input: $item + find: blue paint + replacement: red paint + schema: + inventory: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String diff --git a/generator/config/expression/replaceOne.yaml b/generator/config/expression/replaceOne.yaml index 0962cc6c5..83daf14bc 100644 --- a/generator/config/expression/replaceOne.yaml +++ b/generator/config/expression/replaceOne.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $replaceOne -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceOne/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceOne/ type: - resolvesToString encode: object @@ -8,36 +8,39 @@ description: | Replaces the first instance of a matched string in a given input. New in MongoDB 4.4. arguments: - - - name: input - type: - - resolvesToString - - resolvesToNull - description: | - 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. - - - name: find - type: - - resolvesToString - - resolvesToNull - description: | - 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. - - - name: replacement - type: - - resolvesToString - - resolvesToNull - description: | - 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. + - name: input + type: + - resolvesToString + - resolvesToNull + description: | + 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. + - name: find + type: + - resolvesToString + - resolvesToNull + description: | + 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. + - name: replacement + type: + - resolvesToString + - resolvesToNull + description: | + 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. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceOne/#example' - pipeline: - - - $project: - item: - $replaceOne: - input: '$item' - find: 'blue paint' - replacement: 'red paint' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceOne/#example + pipeline: + - $project: + item: + $replaceOne: + input: $item + find: blue paint + replacement: red paint + schema: + inventory: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String diff --git a/generator/config/expression/reverseArray.yaml b/generator/config/expression/reverseArray.yaml index 2cbe3f3cd..6733a780a 100644 --- a/generator/config/expression/reverseArray.yaml +++ b/generator/config/expression/reverseArray.yaml @@ -1,25 +1,35 @@ # $schema: ../schema.json name: $reverseArray -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/reverseArray/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/reverseArray/ type: - resolvesToArray encode: single description: | Returns an array with the elements in reverse order. arguments: - - - name: expression - type: - - resolvesToArray - description: | - The argument can be any valid expression as long as it resolves to an array. + - name: expression + type: + - resolvesToArray + description: | + The argument can be any valid expression as long as it resolves to an array. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/reverseArray/#example' - pipeline: - - - $project: - name: 1 - reverseFavorites: - $reverseArray: '$favorites' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/reverseArray/#example + pipeline: + - $project: + name: 1 + reverseFavorites: + $reverseArray: $favorites + schema: + users: + _id: + types: + - bsonType: Number + name: + types: + - bsonType: String + favorites: + types: + - bsonType: Array + types: + - bsonType: String diff --git a/generator/config/expression/round.yaml b/generator/config/expression/round.yaml index 9bc6961c7..1063d5994 100644 --- a/generator/config/expression/round.yaml +++ b/generator/config/expression/round.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $round -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/round/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/round/ type: - resolvesToInt - resolvesToDouble @@ -10,41 +10,32 @@ encode: array description: | Rounds a number to a whole integer or to a specified decimal place. arguments: - - - name: number - type: - - resolvesToNumber - description: | - Can be any valid expression that resolves to a number. Specifically, the expression must resolve to an integer, double, decimal, or long. - $round returns an error if the expression resolves to a non-numeric data type. - - - name: place - type: - - resolvesToInt - optional: true - description: | - Can be any valid expression that resolves to an integer between -20 and 100, exclusive. + - name: number + type: + - resolvesToNumber + description: | + Can be any valid expression that resolves to a number. Specifically, the expression must resolve to an integer, double, decimal, or long. + $round returns an error if the expression resolves to a non-numeric data type. + - name: place + type: + - resolvesToInt + optional: true + description: | + Can be any valid expression that resolves to an integer between -20 and 100, exclusive. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/round/#example' - pipeline: - - - $project: - roundedValue: - $round: - - '$value' - - 1 - - - name: 'Round Average Rating' - pipeline: - - - $project: - roundedAverageRating: - $avg: - - - $round: - - - $avg: - - '$averageRating' - - 2 + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/round/#example + pipeline: + - $project: + roundedValue: + $round: + - $value + - 1 + schema: + samples: + _id: + types: + - bsonType: Number + value: + types: + - bsonType: Number diff --git a/generator/config/expression/rtrim.yaml b/generator/config/expression/rtrim.yaml index a9d1974db..7985a1827 100644 --- a/generator/config/expression/rtrim.yaml +++ b/generator/config/expression/rtrim.yaml @@ -1,35 +1,46 @@ # $schema: ../schema.json name: $rtrim -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/rtrim/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/rtrim/ type: - resolvesToString encode: object description: | Removes whitespace characters, including null, or the specified characters from the end of a string. arguments: - - - name: input - type: - - resolvesToString - description: | - The string to trim. The argument can be any valid expression that resolves to a string. - - - name: chars - type: - - resolvesToString - optional: true - description: | - The character(s) to trim from the beginning of the input. - The argument can be any valid expression that resolves to a string. The $ltrim operator breaks down the string into individual UTF code point to trim from input. - If unspecified, $ltrim removes whitespace characters, including the null character. + - name: input + type: + - resolvesToString + description: | + The string to trim. The argument can be any valid expression that resolves to a string. + - name: chars + type: + - resolvesToString + optional: true + description: | + The character(s) to trim from the beginning of the input. + The argument can be any valid expression that resolves to a string. The $ltrim operator breaks down the string into individual UTF code point to trim from input. + If unspecified, $ltrim removes whitespace characters, including the null character. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/rtrim/#example' - pipeline: - - - $project: - item: 1 - description: - $rtrim: - input: '$description' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/rtrim/#example + pipeline: + - $project: + item: 1 + description: + $rtrim: + input: $description + schema: + inventory: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + quarter: + types: + - bsonType: String + description: + types: + - bsonType: String + - bsonType: 'Null' diff --git a/generator/config/expression/second.yaml b/generator/config/expression/second.yaml index 83e7fd370..f52d8d17b 100644 --- a/generator/config/expression/second.yaml +++ b/generator/config/expression/second.yaml @@ -1,36 +1,47 @@ # $schema: ../schema.json name: $second -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/second/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/second/ type: - resolvesToInt encode: object description: | Returns the seconds for a date as a number between 0 and 60 (leap seconds). arguments: - - - name: date - type: - - resolvesToDate - - resolvesToTimestamp - - resolvesToObjectId - description: | - The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. - - - name: timezone - type: - - resolvesToString - optional: true - description: | - The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. + - name: date + type: + - resolvesToDate + - resolvesToTimestamp + - resolvesToObjectId + description: | + The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + - name: timezone + type: + - resolvesToString + optional: true + description: | + The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/second/#example' - pipeline: - - - $project: - seconds: - # Example uses the short form, the builder always generates the verbose form - # $second: '$date' - $second: - date: '$date' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/second/#example + pipeline: + - $project: + seconds: + $second: + date: $date + schema: + sales: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + price: + types: + - bsonType: Number + quantity: + types: + - bsonType: Number + date: + types: + - bsonType: Date diff --git a/generator/config/expression/setDifference.yaml b/generator/config/expression/setDifference.yaml index 69f448cb7..415fdb7c0 100644 --- a/generator/config/expression/setDifference.yaml +++ b/generator/config/expression/setDifference.yaml @@ -1,35 +1,49 @@ # $schema: ../schema.json name: $setDifference -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/setDifference/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/setDifference/ type: - resolvesToArray encode: array description: | 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. arguments: - - - name: expression1 - type: - - resolvesToArray - description: | - The arguments can be any valid expression as long as they each resolve to an array. - - - name: expression2 - type: - - resolvesToArray - description: | - The arguments can be any valid expression as long as they each resolve to an array. + - name: expression1 + type: + - resolvesToArray + description: | + The arguments can be any valid expression as long as they each resolve to an array. + - name: expression2 + type: + - resolvesToArray + description: | + The arguments can be any valid expression as long as they each resolve to an array. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/setDifference/#example' - pipeline: - - - $project: - flowerFieldA: 1 - flowerFieldB: 1 - inBOnly: - $setDifference: - - '$flowerFieldB' - - '$flowerFieldA' - _id: 0 + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/setDifference/#example + pipeline: + - $project: + flowerFieldA: 1 + flowerFieldB: 1 + inBOnly: + $setDifference: + - $flowerFieldB + - $flowerFieldA + _id: 0 + schema: + flowers: + _id: + types: + - bsonType: Number + flowerFieldA: + types: + - bsonType: Array + types: + - bsonType: String + flowerFieldB: + types: + - bsonType: Array + types: + - bsonType: String + - bsonType: Array + types: + - bsonType: String diff --git a/generator/config/expression/setEquals.yaml b/generator/config/expression/setEquals.yaml index 5194c9ae9..02d61250d 100644 --- a/generator/config/expression/setEquals.yaml +++ b/generator/config/expression/setEquals.yaml @@ -1,28 +1,40 @@ # $schema: ../schema.json name: $setEquals -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/setEquals/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/setEquals/ type: - resolvesToBool encode: single description: | Returns true if the input sets have the same distinct elements. Accepts two or more argument expressions. arguments: - - - name: expression - type: - - resolvesToArray - variadic: array + - name: expression + type: + - resolvesToArray + variadic: array tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/setEquals/#example' - pipeline: - - - $project: - _id: 0 - cakes: 1 - cupcakes: 1 - sameFlavors: - $setEquals: - - '$cakes' - - '$cupcakes' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/setEquals/#example + pipeline: + - $project: + _id: 0 + cakes: 1 + cupcakes: 1 + sameFlavors: + $setEquals: + - $cakes + - $cupcakes + schema: + bakeryOrders: + _id: + types: + - bsonType: Number + cakes: + types: + - bsonType: Array + types: + - bsonType: String + cupcakes: + types: + - bsonType: Array + types: + - bsonType: String diff --git a/generator/config/expression/setField.yaml b/generator/config/expression/setField.yaml index b53cf6584..78049510a 100644 --- a/generator/config/expression/setField.yaml +++ b/generator/config/expression/setField.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $setField -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/setField/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/setField/ type: - resolvesToObject encode: object @@ -8,102 +8,163 @@ description: | 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. arguments: - - - name: field - type: - - resolvesToString - description: | - Field in the input object that you want to add, update, or remove. field can be any valid expression that resolves to a string constant. - - - name: input - type: - - resolvesToObject - description: | - Document that contains the field that you want to add or update. input must resolve to an object, missing, null, or undefined. - - - name: value - type: - - expression - description: | - The value that you want to assign to field. value can be any valid expression. - Set to $$REMOVE to remove field from the input document. + - name: field + type: + - resolvesToString + description: | + Field in the input object that you want to add, update, or remove. field can be any valid expression that resolves to a string constant. + - name: input + type: + - resolvesToObject + description: | + Document that contains the field that you want to add or update. input must resolve to an object, missing, null, or undefined. + - name: value + type: + - expression + description: | + The value that you want to assign to field. value can be any valid expression. + Set to $$REMOVE to remove field from the input document. tests: - - - name: 'Add Fields that Contain Periods' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/setField/#add-fields-that-contain-periods--.-' - pipeline: - - - $replaceWith: - $setField: - field: 'price.usd' - input: '$$ROOT' - value: '$price' - - - # Example uses the short form, the builder always generates the verbose form - # $unset: 'price' - $unset: - - 'price' - - - name: 'Add Fields that Start with a Dollar Sign' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/setField/#add-fields-that-start-with-a-dollar-sign----' - pipeline: - - - $replaceWith: - $setField: - field: - $literal: '$price' - input: '$$ROOT' - value: '$price' - - - # Example uses the short form, the builder always generates the verbose form - # $unset: 'price' - $unset: - - 'price' - - - name: 'Update Fields that Contain Periods' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/setField/#update-fields-that-contain-periods--.-' - pipeline: - - - $match: - _id: 1 - - - $replaceWith: - $setField: - field: 'price.usd' - input: '$$ROOT' - value: 49.99 - - - name: 'Update Fields that Start with a Dollar Sign' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/setField/#update-fields-that-start-with-a-dollar-sign----' - pipeline: - - - $match: - _id: 1 - - - $replaceWith: - $setField: - field: - $literal: '$price' - input: '$$ROOT' - value: 49.99 - - - name: 'Remove Fields that Contain Periods' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/setField/#remove-fields-that-contain-periods--.-' - pipeline: - - - $replaceWith: - $setField: - field: 'price.usd' - input: '$$ROOT' - value: '$$REMOVE' - - - name: 'Remove Fields that Start with a Dollar Sign' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/setField/#remove-fields-that-start-with-a-dollar-sign----' - pipeline: - - - $replaceWith: - $setField: - field: - $literal: '$price' - input: '$$ROOT' - value: '$$REMOVE' + - name: Add Fields that Contain Periods + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/setField/#add-fields-that-contain-periods--.- + pipeline: + - $replaceWith: + $setField: + field: price.usd + input: $$ROOT + value: $price + - $unset: + - price + schema: + inventory: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + price: + types: + - bsonType: Number + qty: + types: + - bsonType: Number + - name: Add Fields that Start with a Dollar Sign + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/setField/#add-fields-that-start-with-a-dollar-sign---- + pipeline: + - $replaceWith: + $setField: + field: + $literal: $price + input: $$ROOT + value: $price + - $unset: + - price + schema: + inventory: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + price: + types: + - bsonType: Number + qty: + types: + - bsonType: Number + - name: Update Fields that Contain Periods + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/setField/#update-fields-that-contain-periods--.- + pipeline: + - $match: + _id: 1 + - $replaceWith: + $setField: + field: price.usd + input: $$ROOT + value: 49.99 + schema: + inventory: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + qty: + types: + - bsonType: Number + price.usd: + types: + - bsonType: Number + - name: Update Fields that Start with a Dollar Sign + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/setField/#update-fields-that-start-with-a-dollar-sign---- + pipeline: + - $match: + _id: 1 + - $replaceWith: + $setField: + field: + $literal: $price + input: $$ROOT + value: 49.99 + schema: + inventory: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + qty: + types: + - bsonType: Number + $price: + types: + - bsonType: Number + - name: Remove Fields that Contain Periods + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/setField/#remove-fields-that-contain-periods--.- + pipeline: + - $replaceWith: + $setField: + field: price.usd + input: $$ROOT + value: $$REMOVE + schema: + inventory: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + qty: + types: + - bsonType: Number + price.usd: + types: + - bsonType: Number + - name: Remove Fields that Start with a Dollar Sign + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/setField/#remove-fields-that-start-with-a-dollar-sign---- + pipeline: + - $replaceWith: + $setField: + field: + $literal: $price + input: $$ROOT + value: $$REMOVE + schema: + inventory: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + qty: + types: + - bsonType: Number + $price: + types: + - bsonType: Number diff --git a/generator/config/expression/setIntersection.yaml b/generator/config/expression/setIntersection.yaml index 8f03651d5..a41d68136 100644 --- a/generator/config/expression/setIntersection.yaml +++ b/generator/config/expression/setIntersection.yaml @@ -1,44 +1,78 @@ # $schema: ../schema.json name: $setIntersection -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/setIntersection/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/setIntersection/ type: - resolvesToArray encode: single description: | Returns a set with elements that appear in all of the input sets. Accepts any number of argument expressions. arguments: - - - name: expression - type: - - resolvesToArray - variadic: array + - name: expression + type: + - resolvesToArray + variadic: array tests: - - - name: 'Elements Array Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/setIntersection/#elements-array-example' - pipeline: - - - $project: - flowerFieldA: 1 - flowerFieldB: 1 - commonToBoth: - $setIntersection: - - '$flowerFieldA' - - '$flowerFieldB' - _id: 0 - - - name: 'Retrieve Documents for Roles Granted to the Current User' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/setIntersection/#retrieve-documents-for-roles-granted-to-the-current-user' - pipeline: - - - $match: - $expr: - $not: - # the example doesn't use an array inside $not, but the documentation say it is necessary - - - $eq: - - - $setIntersection: - - '$allowedRoles' - - '$$USER_ROLES.role' - - [] + - name: Elements Array Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/setIntersection/#elements-array-example + pipeline: + - $project: + flowerFieldA: 1 + flowerFieldB: 1 + commonToBoth: + $setIntersection: + - $flowerFieldA + - $flowerFieldB + _id: 0 + schema: + flowers: + _id: + types: + - bsonType: Number + flowerFieldA: + types: + - bsonType: Array + types: + - bsonType: String + flowerFieldB: + types: + - bsonType: Array + types: + - bsonType: String + - bsonType: Array + types: + - bsonType: String + - name: Retrieve Documents for Roles Granted to the Current User + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/setIntersection/#retrieve-documents-for-roles-granted-to-the-current-user + pipeline: + - $match: + $expr: + $not: + - $eq: + - $setIntersection: + - $allowedRoles + - $$USER_ROLES.role + - [] + schema: + budget: + _id: + types: + - bsonType: Int32 + allowedRoles: + types: + - bsonType: Array + types: + - bsonType: String + comment: + types: + - bsonType: String + yearlyBudget: + types: + - bsonType: Double + cloudBudget: + types: + - bsonType: Double + - bsonType: Undefined + salesEventsBudget: + types: + - bsonType: Double + - bsonType: Undefined diff --git a/generator/config/expression/setIsSubset.yaml b/generator/config/expression/setIsSubset.yaml index fe7c9ed02..74181df26 100644 --- a/generator/config/expression/setIsSubset.yaml +++ b/generator/config/expression/setIsSubset.yaml @@ -1,32 +1,45 @@ # $schema: ../schema.json name: $setIsSubset -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/setIsSubset/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/setIsSubset/ type: - resolvesToBool encode: array description: | 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. arguments: - - - name: expression1 - type: - - resolvesToArray - - - name: expression2 - type: - - resolvesToArray + - name: expression1 + type: + - resolvesToArray + - name: expression2 + type: + - resolvesToArray tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/setIsSubset/#example' - pipeline: - - - $project: - flowerFieldA: 1 - flowerFieldB: 1 - AisSubset: - $setIsSubset: - - '$flowerFieldA' - - '$flowerFieldB' - _id: 0 - + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/setIsSubset/#example + pipeline: + - $project: + flowerFieldA: 1 + flowerFieldB: 1 + AisSubset: + $setIsSubset: + - $flowerFieldA + - $flowerFieldB + _id: 0 + schema: + flowers: + _id: + types: + - bsonType: Number + flowerFieldA: + types: + - bsonType: Array + types: + - bsonType: String + flowerFieldB: + types: + - bsonType: Array + types: + - bsonType: String + - bsonType: Array + types: + - bsonType: String diff --git a/generator/config/expression/setUnion.yaml b/generator/config/expression/setUnion.yaml index 2cfca3e16..3ff906332 100644 --- a/generator/config/expression/setUnion.yaml +++ b/generator/config/expression/setUnion.yaml @@ -1,28 +1,43 @@ # $schema: ../schema.json name: $setUnion -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/setUnion/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/setUnion/ type: - resolvesToArray encode: single description: | Returns a set with elements that appear in any of the input sets. arguments: - - - name: expression - type: - - resolvesToArray - variadic: array + - name: expression + type: + - resolvesToArray + variadic: array tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/setUnion/#example' - pipeline: - - - $project: - flowerFieldA: 1 - flowerFieldB: 1 - allValues: - $setUnion: - - '$flowerFieldA' - - '$flowerFieldB' - _id: 0 + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/setUnion/#example + pipeline: + - $project: + flowerFieldA: 1 + flowerFieldB: 1 + allValues: + $setUnion: + - $flowerFieldA + - $flowerFieldB + _id: 0 + schema: + flowers: + _id: + types: + - bsonType: Number + flowerFieldA: + types: + - bsonType: Array + types: + - bsonType: String + flowerFieldB: + types: + - bsonType: Array + types: + - bsonType: String + - bsonType: Array + types: + - bsonType: String diff --git a/generator/config/expression/sin.yaml b/generator/config/expression/sin.yaml index fe02b4f28..3f1e8c6e1 100644 --- a/generator/config/expression/sin.yaml +++ b/generator/config/expression/sin.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $sin -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/sin/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/sin/ type: - resolvesToDouble - resolvesToDecimal @@ -8,23 +8,30 @@ encode: single description: | Returns the sine of a value that is measured in radians. arguments: - - - name: expression - type: - - resolvesToNumber - description: | - $sin takes any valid expression that resolves to a number. If the expression returns a value in degrees, use the $degreesToRadians operator to convert the result to radians. - By default $sin returns values as a double. $sin can also return values as a 128-bit decimal as long as the expression resolves to a 128-bit decimal value. + - name: expression + type: + - resolvesToNumber + description: | + $sin takes any valid expression that resolves to a number. If the expression returns a value in degrees, use the $degreesToRadians operator to convert the result to radians. + By default $sin returns values as a double. $sin can also return values as a 128-bit decimal as long as the expression resolves to a 128-bit decimal value. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/sin/#example' - pipeline: - - - $addFields: - side_b: - $multiply: - - - $sin: - $degreesToRadians: '$angle_a' - - '$hypotenuse' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/sin/#example + pipeline: + - $addFields: + side_b: + $multiply: + - $sin: + $degreesToRadians: $angle_a + - $hypotenuse + schema: + TestCollection: + _id: + types: + - bsonType: ObjectId + angle_a: + types: + - bsonType: Decimal128 + hypotenuse: + types: + - bsonType: Decimal128 diff --git a/generator/config/expression/sinh.yaml b/generator/config/expression/sinh.yaml index a5b446add..99597385b 100644 --- a/generator/config/expression/sinh.yaml +++ b/generator/config/expression/sinh.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $sinh -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/sinh/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/sinh/ type: - resolvesToDouble - resolvesToDecimal @@ -8,20 +8,25 @@ encode: single description: | Returns the hyperbolic sine of a value that is measured in radians. arguments: - - - name: expression - type: - - resolvesToNumber - description: | - $sinh takes any valid expression that resolves to a number, measured in radians. If the expression returns a value in degrees, use the $degreesToRadians operator to convert the value to radians. - By default $sinh returns values as a double. $sinh can also return values as a 128-bit decimal if the expression resolves to a 128-bit decimal value. + - name: expression + type: + - resolvesToNumber + description: | + $sinh takes any valid expression that resolves to a number, measured in radians. If the expression returns a value in degrees, use the $degreesToRadians operator to convert the value to radians. + By default $sinh returns values as a double. $sinh can also return values as a 128-bit decimal if the expression resolves to a 128-bit decimal value. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/sinh/#example' - pipeline: - - - $addFields: - sinh_output: - $sinh: - $degreesToRadians: '$angle' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/sinh/#example + pipeline: + - $addFields: + sinh_output: + $sinh: + $degreesToRadians: $angle + schema: + trigonometry: + _id: + types: + - bsonType: ObjectId + angle: + types: + - bsonType: Decimal128 diff --git a/generator/config/expression/size.yaml b/generator/config/expression/size.yaml index ce4fe775e..50d38c9ce 100644 --- a/generator/config/expression/size.yaml +++ b/generator/config/expression/size.yaml @@ -1,33 +1,45 @@ # $schema: ../schema.json name: $size -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/size/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/size/ type: - resolvesToInt encode: single description: | Returns the number of elements in the array. Accepts a single expression as argument. arguments: - - - name: expression - type: - - resolvesToArray - description: | - The argument for $size can be any expression as long as it resolves to an array. + - name: expression + type: + - resolvesToArray + description: | + The argument for $size can be any expression as long as it resolves to an array. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/size/#example' - pipeline: - - - $project: - item: 1 - numberOfColors: - $cond: - if: - # Example uses the short form, the builder always generates the verbose form - # $isArray: '$colors' - $isArray: - - '$colors' - then: - $size: '$colors' - else: 'NA' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/size/#example + pipeline: + - $project: + item: 1 + numberOfColors: + $cond: + if: + $isArray: + - $colors + then: + $size: $colors + else: NA + schema: + inventory: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + description: + types: + - bsonType: String + colors: + types: + - bsonType: Array + types: + - bsonType: String + - bsonType: String diff --git a/generator/config/expression/slice.yaml b/generator/config/expression/slice.yaml index 22cc287e1..a2d32f674 100644 --- a/generator/config/expression/slice.yaml +++ b/generator/config/expression/slice.yaml @@ -1,44 +1,52 @@ # $schema: ../schema.json name: $slice -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/slice/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/slice/ type: - resolvesToArray encode: array description: | Returns a subset of an array. arguments: - - - name: expression - type: - - resolvesToArray - description: | - Any valid expression as long as it resolves to an array. - - - name: position - type: - - resolvesToInt - optional: true - description: | - Any valid expression as long as it resolves to an integer. - If positive, $slice determines the starting position from the start of the array. If position is greater than the number of elements, the $slice returns an empty array. - If negative, $slice determines the starting position from the end of the array. If the absolute value of the is greater than the number of elements, the starting position is the start of the array. - - - name: "n" - type: - - resolvesToInt - description: | - Any valid expression as long as it resolves to an integer. If position is specified, n must resolve to a positive integer. - If positive, $slice returns up to the first n elements in the array. If the position is specified, $slice returns the first n elements starting from the position. - If negative, $slice returns up to the last n elements in the array. n cannot resolve to a negative number if is specified. + - name: expression + type: + - resolvesToArray + description: | + Any valid expression as long as it resolves to an array. + - name: position + type: + - resolvesToInt + optional: true + description: | + Any valid expression as long as it resolves to an integer. + If positive, $slice determines the starting position from the start of the array. If position is greater than the number of elements, the $slice returns an empty array. + If negative, $slice determines the starting position from the end of the array. If the absolute value of the is greater than the number of elements, the starting position is the start of the array. + - name: n + type: + - resolvesToInt + description: | + Any valid expression as long as it resolves to an integer. If position is specified, n must resolve to a positive integer. + If positive, $slice returns up to the first n elements in the array. If the position is specified, $slice returns the first n elements starting from the position. + If negative, $slice returns up to the last n elements in the array. n cannot resolve to a negative number if is specified. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/slice/#example' - pipeline: - - - $project: - name: 1 - threeFavorites: - $slice: - - '$favorites' - - 3 + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/slice/#example + pipeline: + - $project: + name: 1 + threeFavorites: + $slice: + - $favorites + - 3 + schema: + users: + _id: + types: + - bsonType: Number + name: + types: + - bsonType: String + favorites: + types: + - bsonType: Array + types: + - bsonType: String diff --git a/generator/config/expression/sortArray.yaml b/generator/config/expression/sortArray.yaml index d558f2233..862be5191 100644 --- a/generator/config/expression/sortArray.yaml +++ b/generator/config/expression/sortArray.yaml @@ -1,108 +1,212 @@ # $schema: ../schema.json name: $sortArray -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/sortArray/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/sortArray/ type: - resolvesToArray encode: object description: | Sorts the elements of an array. arguments: - - - name: input - type: - - resolvesToArray - description: | - The array to be sorted. - The result is null if the expression: is missing, evaluates to null, or evaluates to undefined - If the expression evaluates to any other non-array value, the document returns an error. - - - name: sortBy - type: - - int - - sortSpec - - sortBy - description: | - The document specifies a sort ordering. + - name: input + type: + - resolvesToArray + description: | + The array to be sorted. + The result is null if the expression: is missing, evaluates to null, or evaluates to undefined + If the expression evaluates to any other non-array value, the document returns an error. + - name: sortBy + type: + - int + - sortSpec + - sortBy + description: | + The document specifies a sort ordering. tests: - - - name: 'Sort on a Field' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/sortArray/#sort-on-a-field' - pipeline: - - - $project: - _id: 0 - result: - $sortArray: - input: '$team' - sortBy: - name: 1 - - - name: 'Sort on a Subfield' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/sortArray/#sort-on-a-subfield' - pipeline: - - - $project: - _id: 0 - result: - $sortArray: - input: '$team' - sortBy: - address.city: -1 - - - name: 'Sort on Multiple Fields' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/sortArray/#sort-on-multiple-fields' - pipeline: - - - $project: - _id: 0 - result: - $sortArray: - input: '$team' - sortBy: - age: -1 - name: 1 - - - name: 'Sort an Array of Integers' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/sortArray/#sort-an-array-of-integers' - pipeline: - - - $project: - _id: 0 - result: - $sortArray: - input: - - 1 - - 4 - - 1 - - 6 - - 12 - - 5 - sortBy: 1 - - - name: 'Sort on Mixed Type Fields' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/sortArray/#sort-on-mixed-type-fields' - pipeline: - - - $project: - _id: 0 - result: - $sortArray: - input: - - 20 - - 4 - - - a: 'Free' - - 6 - - 21 - - 5 - - 'Gratis' - - - a: ~ - - - a: - sale: true - price: 19 - - !bson_decimal128 '10.23' - - - a: 'On sale' - sortBy: 1 + - name: Sort on a Field + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/sortArray/#sort-on-a-field + pipeline: + - $project: + _id: 0 + result: + $sortArray: + input: $team + sortBy: + name: 1 + schema: + engineers: + team: + types: + - bsonType: Array + types: + - bsonType: Document + fields: + name: + types: + - bsonType: String + age: + types: + - bsonType: Number + address: + types: + - bsonType: Document + fields: + street: + types: + - bsonType: String + city: + types: + - bsonType: String + - name: Sort on a Subfield + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/sortArray/#sort-on-a-subfield + pipeline: + - $project: + _id: 0 + result: + $sortArray: + input: $team + sortBy: + address.city: -1 + schema: + engineers: + team: + types: + - bsonType: Array + types: + - bsonType: Document + fields: + name: + types: + - bsonType: String + age: + types: + - bsonType: Number + address: + types: + - bsonType: Document + fields: + street: + types: + - bsonType: String + city: + types: + - bsonType: String + - name: Sort on Multiple Fields + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/sortArray/#sort-on-multiple-fields + pipeline: + - $project: + _id: 0 + result: + $sortArray: + input: $team + sortBy: + age: -1 + name: 1 + schema: + engineers: + team: + types: + - bsonType: Array + types: + - bsonType: Document + fields: + name: + types: + - bsonType: String + age: + types: + - bsonType: Number + address: + types: + - bsonType: Document + fields: + street: + types: + - bsonType: String + city: + types: + - bsonType: String + - name: Sort an Array of Integers + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/sortArray/#sort-an-array-of-integers + pipeline: + - $project: + _id: 0 + result: + $sortArray: + input: + - 1 + - 4 + - 1 + - 6 + - 12 + - 5 + sortBy: 1 + schema: + engineers: + team: + types: + - bsonType: Array + types: + - bsonType: Document + fields: + name: + types: + - bsonType: String + age: + types: + - bsonType: Number + address: + types: + - bsonType: Document + fields: + street: + types: + - bsonType: String + city: + types: + - bsonType: String + - name: Sort on Mixed Type Fields + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/sortArray/#sort-on-mixed-type-fields + pipeline: + - $project: + _id: 0 + result: + $sortArray: + input: + - 20 + - 4 + - a: Free + - 6 + - 21 + - 5 + - Gratis + - a: ~ + - a: + sale: true + price: 19 + - !bson_decimal128 '10.23' + - a: On sale + sortBy: 1 + schema: + engineers: + team: + types: + - bsonType: Array + types: + - bsonType: Document + fields: + name: + types: + - bsonType: String + age: + types: + - bsonType: Number + address: + types: + - bsonType: Document + fields: + street: + types: + - bsonType: String + city: + types: + - bsonType: String diff --git a/generator/config/expression/split.yaml b/generator/config/expression/split.yaml index 1c6169910..e9c467e0b 100644 --- a/generator/config/expression/split.yaml +++ b/generator/config/expression/split.yaml @@ -1,48 +1,51 @@ # $schema: ../schema.json name: $split -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/split/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/split/ type: - - resolvesToArray # of string + - resolvesToArray encode: array description: | 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. arguments: - - - name: string - type: - - resolvesToString - description: | - The string to be split. string expression can be any valid expression as long as it resolves to a string. - - - name: delimiter - type: - - resolvesToString - description: | - The delimiter to use when splitting the string expression. delimiter can be any valid expression as long as it resolves to a string. + - name: string + type: + - resolvesToString + description: | + The string to be split. string expression can be any valid expression as long as it resolves to a string. + - name: delimiter + type: + - resolvesToString + description: | + The delimiter to use when splitting the string expression. delimiter can be any valid expression as long as it resolves to a string. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/split/#example' - pipeline: - - - $project: - city_state: - $split: - - '$city' - - ', ' - qty: 1 - - - $unwind: - path: '$city_state' - - - $match: - city_state: !bson_regex '[A-Z]{2}' - - - $group: - _id: - state: '$city_state' - total_qty: - $sum: '$qty' - - - $sort: - total_qty: -1 + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/split/#example + pipeline: + - $project: + city_state: + $split: + - $city + - ', ' + qty: 1 + - $unwind: + path: $city_state + - $match: + city_state: !bson_regex '[A-Z]{2}' + - $group: + _id: + state: $city_state + total_qty: + $sum: $qty + - $sort: + total_qty: -1 + schema: + deliveries: + _id: + types: + - bsonType: Number + city: + types: + - bsonType: String + qty: + types: + - bsonType: Number diff --git a/generator/config/expression/sqrt.yaml b/generator/config/expression/sqrt.yaml index 52f5bb7c2..40f8ed742 100644 --- a/generator/config/expression/sqrt.yaml +++ b/generator/config/expression/sqrt.yaml @@ -1,39 +1,57 @@ # $schema: ../schema.json name: $sqrt -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/sqrt/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/sqrt/ type: - resolvesToDouble encode: single description: | Calculates the square root. arguments: - - - name: number - type: - - resolvesToNumber - description: | - The argument can be any valid expression as long as it resolves to a non-negative number. + - name: number + type: + - resolvesToNumber + description: | + The argument can be any valid expression as long as it resolves to a non-negative number. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/sqrt/#example' - pipeline: - - - $project: - distance: - $sqrt: - $add: - - - $pow: - - - $subtract: - - '$p2.y' - - '$p1.y' - - 2 - - - $pow: - - - $subtract: - - '$p2.x' - - '$p1.x' - - 2 + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/sqrt/#example + pipeline: + - $project: + distance: + $sqrt: + $add: + - $pow: + - $subtract: + - $p2.y + - $p1.y + - 2 + - $pow: + - $subtract: + - $p2.x + - $p1.x + - 2 + schema: + points: + _id: + types: + - bsonType: Number + p1: + types: + - bsonType: Document + fields: + x: + types: + - bsonType: Number + y: + types: + - bsonType: Number + p2: + types: + - bsonType: Document + fields: + x: + types: + - bsonType: Number + y: + types: + - bsonType: Number diff --git a/generator/config/expression/stdDevPop.yaml b/generator/config/expression/stdDevPop.yaml index 46641ebe8..62154c684 100644 --- a/generator/config/expression/stdDevPop.yaml +++ b/generator/config/expression/stdDevPop.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $stdDevPop -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/stdDevPop/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/stdDevPop/ type: - resolvesToDouble encode: single @@ -9,19 +9,35 @@ description: | 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. arguments: - - - name: expression - type: - - resolvesToNumber - variadic: array + - name: expression + type: + - resolvesToNumber + variadic: array tests: - - - name: 'Use in $project Stage' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/stdDevPop/#use-in--project-stage' - pipeline: - - - $project: - stdDev: - # Example uses the short form, the builder always generates the verbose form - # $stdDevPop: '$scores.score' - $stdDevPop: ['$scores.score'] + - name: Use in $project Stage + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/stdDevPop/#use-in--project-stage + pipeline: + - $project: + stdDev: + $stdDevPop: + - $scores.score + schema: + quizzes: + _id: + types: + - bsonType: Number + scores: + types: + - bsonType: Array + types: + - bsonType: Document + fields: + name: + types: + - bsonType: String + score: + types: + - bsonType: Number + quiz: + types: + - bsonType: Number diff --git a/generator/config/expression/stdDevSamp.yaml b/generator/config/expression/stdDevSamp.yaml index 84b35f52a..0312074f2 100644 --- a/generator/config/expression/stdDevSamp.yaml +++ b/generator/config/expression/stdDevSamp.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $stdDevSamp -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/stdDevSamp/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/stdDevSamp/ type: - resolvesToDouble encode: single @@ -8,8 +8,7 @@ description: | 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. arguments: - - - name: expression - type: - - resolvesToNumber - variadic: array + - name: expression + type: + - resolvesToNumber + variadic: array diff --git a/generator/config/expression/strLenBytes.yaml b/generator/config/expression/strLenBytes.yaml index 301150d19..55012f35d 100644 --- a/generator/config/expression/strLenBytes.yaml +++ b/generator/config/expression/strLenBytes.yaml @@ -1,23 +1,28 @@ # $schema: ../schema.json name: $strLenBytes -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/strLenBytes/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/strLenBytes/ type: - resolvesToInt encode: single description: | Returns the number of UTF-8 encoded bytes in a string. arguments: - - - name: expression - type: - - resolvesToString + - name: expression + type: + - resolvesToString tests: - - - name: 'Single-Byte and Multibyte Character Set' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/strLenBytes/#single-byte-and-multibyte-character-set' - pipeline: - - - $project: - name: 1 - length: - $strLenBytes: '$name' + - name: Single-Byte and Multibyte Character Set + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/strLenBytes/#single-byte-and-multibyte-character-set + pipeline: + - $project: + name: 1 + length: + $strLenBytes: $name + schema: + food: + _id: + types: + - bsonType: Number + name: + types: + - bsonType: String diff --git a/generator/config/expression/strLenCP.yaml b/generator/config/expression/strLenCP.yaml index b852c80ec..e0586ee38 100644 --- a/generator/config/expression/strLenCP.yaml +++ b/generator/config/expression/strLenCP.yaml @@ -1,23 +1,28 @@ # $schema: ../schema.json name: $strLenCP -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/strLenCP/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/strLenCP/ type: - resolvesToInt encode: single description: | Returns the number of UTF-8 code points in a string. arguments: - - - name: expression - type: - - resolvesToString + - name: expression + type: + - resolvesToString tests: - - - name: 'Single-Byte and Multibyte Character Set' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/strLenBytes/#single-byte-and-multibyte-character-set' - pipeline: - - - $project: - name: 1 - length: - $strLenCP: '$name' + - name: Single-Byte and Multibyte Character Set + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/strLenBytes/#single-byte-and-multibyte-character-set + pipeline: + - $project: + name: 1 + length: + $strLenCP: $name + schema: + food: + _id: + types: + - bsonType: Number + name: + types: + - bsonType: String diff --git a/generator/config/expression/strcasecmp.yaml b/generator/config/expression/strcasecmp.yaml index 6775c44b1..78cf85c33 100644 --- a/generator/config/expression/strcasecmp.yaml +++ b/generator/config/expression/strcasecmp.yaml @@ -1,29 +1,40 @@ # $schema: ../schema.json name: $strcasecmp -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/strcasecmp/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/strcasecmp/ type: - resolvesToInt encode: array description: | 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. arguments: - - - name: expression1 - type: - - resolvesToString - - - name: expression2 - type: - - resolvesToString + - name: expression1 + type: + - resolvesToString + - name: expression2 + type: + - resolvesToString tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/strcasecmp/#example' - pipeline: - - - $project: - item: 1 - comparisonResult: - $strcasecmp: - - '$quarter' - - '13q4' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/strcasecmp/#example + pipeline: + - $project: + item: 1 + comparisonResult: + $strcasecmp: + - $quarter + - 13q4 + schema: + inventory: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + quarter: + types: + - bsonType: String + description: + types: + - bsonType: String + - bsonType: 'Null' diff --git a/generator/config/expression/substr.yaml b/generator/config/expression/substr.yaml index 6bcf6143f..457b679c0 100644 --- a/generator/config/expression/substr.yaml +++ b/generator/config/expression/substr.yaml @@ -1,43 +1,53 @@ # $schema: ../schema.json name: $substr -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/substr/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/substr/ type: - resolvesToString encode: array description: | Deprecated. Use $substrBytes or $substrCP. arguments: - - - name: string - type: - - resolvesToString - - - name: start - type: - - resolvesToInt - description: | - If start is a negative number, $substr returns an empty string "". - - - name: length - type: - - resolvesToInt - description: | - If length is a negative number, $substr returns a substring that starts at the specified index and includes the rest of the string. + - name: string + type: + - resolvesToString + - name: start + type: + - resolvesToInt + description: | + If start is a negative number, $substr returns an empty string "". + - name: length + type: + - resolvesToInt + description: | + If length is a negative number, $substr returns a substring that starts at the specified index and includes the rest of the string. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/substr/#example' - pipeline: - - - $project: - item: 1 - yearSubstring: - $substr: - - '$quarter' - - 0 - - 2 - quarterSubtring: - $substr: - - '$quarter' - - 2 - - -1 + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/substr/#example + pipeline: + - $project: + item: 1 + yearSubstring: + $substr: + - $quarter + - 0 + - 2 + quarterSubtring: + $substr: + - $quarter + - 2 + - -1 + schema: + inventory: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + quarter: + types: + - bsonType: String + description: + types: + - bsonType: String + - bsonType: 'Null' diff --git a/generator/config/expression/substrBytes.yaml b/generator/config/expression/substrBytes.yaml index fed7677c8..b3abec24d 100644 --- a/generator/config/expression/substrBytes.yaml +++ b/generator/config/expression/substrBytes.yaml @@ -1,59 +1,73 @@ # $schema: ../schema.json name: $substrBytes -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/substrBytes/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/substrBytes/ type: - resolvesToString encode: array description: | 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. arguments: - - - name: string - type: - - resolvesToString - - - name: start - type: - - resolvesToInt - description: | - If start is a negative number, $substr returns an empty string "". - - - name: length - type: - - resolvesToInt - description: | - If length is a negative number, $substr returns a substring that starts at the specified index and includes the rest of the string. + - name: string + type: + - resolvesToString + - name: start + type: + - resolvesToInt + description: | + If start is a negative number, $substr returns an empty string "". + - name: length + type: + - resolvesToInt + description: | + If length is a negative number, $substr returns a substring that starts at the specified index and includes the rest of the string. tests: - - - name: 'Single-Byte Character Set' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/substrBytes/#single-byte-character-set' - pipeline: - - - $project: - item: 1 - yearSubstring: - $substrBytes: - - '$quarter' - - 0 - - 2 - quarterSubtring: - $substrBytes: - - '$quarter' - - 2 - - - $subtract: - - - $strLenBytes: '$quarter' - - 2 - - - name: 'Single-Byte and Multibyte Character Set' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/substrBytes/#single-byte-and-multibyte-character-set' - pipeline: - - - $project: - name: 1 - menuCode: - $substrBytes: - - '$name' - - 0 - - 3 + - name: Single-Byte Character Set + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/substrBytes/#single-byte-character-set + pipeline: + - $project: + item: 1 + yearSubstring: + $substrBytes: + - $quarter + - 0 + - 2 + quarterSubtring: + $substrBytes: + - $quarter + - 2 + - $subtract: + - $strLenBytes: $quarter + - 2 + schema: + inventory: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + quarter: + types: + - bsonType: String + description: + types: + - bsonType: String + - bsonType: 'Null' + - name: Single-Byte and Multibyte Character Set + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/substrBytes/#single-byte-and-multibyte-character-set + pipeline: + - $project: + name: 1 + menuCode: + $substrBytes: + - $name + - 0 + - 3 + schema: + food: + _id: + types: + - bsonType: Number + name: + types: + - bsonType: String diff --git a/generator/config/expression/substrCP.yaml b/generator/config/expression/substrCP.yaml index 843b2ca1a..d0a278607 100644 --- a/generator/config/expression/substrCP.yaml +++ b/generator/config/expression/substrCP.yaml @@ -1,59 +1,73 @@ # $schema: ../schema.json name: $substrCP -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/substrCP/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/substrCP/ type: - resolvesToString encode: array description: | 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. arguments: - - - name: string - type: - - resolvesToString - - - name: start - type: - - resolvesToInt - description: | - If start is a negative number, $substr returns an empty string "". - - - name: length - type: - - resolvesToInt - description: | - If length is a negative number, $substr returns a substring that starts at the specified index and includes the rest of the string. + - name: string + type: + - resolvesToString + - name: start + type: + - resolvesToInt + description: | + If start is a negative number, $substr returns an empty string "". + - name: length + type: + - resolvesToInt + description: | + If length is a negative number, $substr returns a substring that starts at the specified index and includes the rest of the string. tests: - - - name: 'Single-Byte Character Set' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/substrCP/#single-byte-character-set' - pipeline: - - - $project: - item: 1 - yearSubstring: - $substrCP: - - '$quarter' - - 0 - - 2 - quarterSubtring: - $substrCP: - - '$quarter' - - 2 - - - $subtract: - - - $strLenCP: '$quarter' - - 2 - - - name: 'Single-Byte and Multibyte Character Set' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/substrCP/#single-byte-and-multibyte-character-set' - pipeline: - - - $project: - name: 1 - menuCode: - $substrCP: - - '$name' - - 0 - - 3 + - name: Single-Byte Character Set + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/substrCP/#single-byte-character-set + pipeline: + - $project: + item: 1 + yearSubstring: + $substrCP: + - $quarter + - 0 + - 2 + quarterSubtring: + $substrCP: + - $quarter + - 2 + - $subtract: + - $strLenCP: $quarter + - 2 + schema: + inventory: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + quarter: + types: + - bsonType: String + description: + types: + - bsonType: String + - bsonType: 'Null' + - name: Single-Byte and Multibyte Character Set + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/substrCP/#single-byte-and-multibyte-character-set + pipeline: + - $project: + name: 1 + menuCode: + $substrCP: + - $name + - 0 + - 3 + schema: + food: + _id: + types: + - bsonType: Number + name: + types: + - bsonType: String diff --git a/generator/config/expression/subtract.yaml b/generator/config/expression/subtract.yaml index b6db65ac9..e5f0770a0 100644 --- a/generator/config/expression/subtract.yaml +++ b/generator/config/expression/subtract.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $subtract -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/subtract/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/subtract/ type: - resolvesToInt - resolvesToLong @@ -11,50 +11,101 @@ encode: array description: | 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. arguments: - - - name: expression1 - type: - - resolvesToNumber - - resolvesToDate - - - name: expression2 - type: - - resolvesToNumber - - resolvesToDate + - name: expression1 + type: + - resolvesToNumber + - resolvesToDate + - name: expression2 + type: + - resolvesToNumber + - resolvesToDate tests: - - - name: 'Subtract Numbers' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/subtract/#subtract-numbers' - pipeline: - - - $project: - item: 1 - total: - $subtract: - - - $add: - - '$price' - - '$fee' - - '$discount' - - - name: 'Subtract Two Dates' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/subtract/#subtract-two-dates' - pipeline: - - - $project: - item: 1 - dateDifference: - $subtract: - - '$$NOW' - - '$date' - - - name: 'Subtract Milliseconds from a Date' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/subtract/#subtract-milliseconds-from-a-date' - pipeline: - - - $project: - item: 1 - dateDifference: - $subtract: - - '$date' - - 300000 + - name: Subtract Numbers + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/subtract/#subtract-numbers + pipeline: + - $project: + item: 1 + total: + $subtract: + - $add: + - $price + - $fee + - $discount + schema: + sales: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + price: + types: + - bsonType: Number + fee: + types: + - bsonType: Number + discount: + types: + - bsonType: Number + date: + types: + - bsonType: Date + - name: Subtract Two Dates + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/subtract/#subtract-two-dates + pipeline: + - $project: + item: 1 + dateDifference: + $subtract: + - $$NOW + - $date + schema: + sales: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + price: + types: + - bsonType: Number + fee: + types: + - bsonType: Number + discount: + types: + - bsonType: Number + date: + types: + - bsonType: Date + - name: Subtract Milliseconds from a Date + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/subtract/#subtract-milliseconds-from-a-date + pipeline: + - $project: + item: 1 + dateDifference: + $subtract: + - $date + - 300000 + schema: + sales: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + price: + types: + - bsonType: Number + fee: + types: + - bsonType: Number + discount: + types: + - bsonType: Number + date: + types: + - bsonType: Date diff --git a/generator/config/expression/sum.yaml b/generator/config/expression/sum.yaml index 25b323ab1..7e3e359df 100644 --- a/generator/config/expression/sum.yaml +++ b/generator/config/expression/sum.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $sum -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/sum/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/sum/ type: - resolvesToNumber encode: single @@ -8,29 +8,44 @@ description: | Returns a sum of numerical values. Ignores non-numeric values. Changed in MongoDB 5.0: Available in the $setWindowFields stage. arguments: - - - name: expression - type: - - resolvesToNumber - - resolvesToArray - variadic: array + - name: expression + type: + - resolvesToNumber + - resolvesToArray + variadic: array tests: - - - name: 'Use in $project Stage' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/sum/#use-in--project-stage' - pipeline: - - - $project: - quizTotal: - # Example uses the short form, the builder always generates the verbose form - # $sum: '$quizzes' - $sum: - - '$quizzes' - labTotal: - # $sum: '$labs' - $sum: - - '$labs' - examTotal: - $sum: - - '$final' - - '$midterm' + - name: Use in $project Stage + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/sum/#use-in--project-stage + pipeline: + - $project: + quizTotal: + $sum: + - $quizzes + labTotal: + $sum: + - $labs + examTotal: + $sum: + - $final + - $midterm + schema: + students: + _id: + types: + - bsonType: Number + quizzes: + types: + - bsonType: Array + types: + - bsonType: Number + labs: + types: + - bsonType: Array + types: + - bsonType: Number + final: + types: + - bsonType: Number + midterm: + types: + - bsonType: Number diff --git a/generator/config/expression/switch.yaml b/generator/config/expression/switch.yaml index d668e3d94..f68a82775 100644 --- a/generator/config/expression/switch.yaml +++ b/generator/config/expression/switch.yaml @@ -1,70 +1,70 @@ # $schema: ../schema.json name: $switch -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/switch/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/switch/ type: - resolvesToAny encode: object description: | 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. arguments: - - - name: branches - type: - - array # of CaseOperator - description: | - An array of control branch documents. Each branch is a document with the following fields: - - case Can be any valid expression that resolves to a boolean. If the result is not a boolean, it is coerced to a boolean value. More information about how MongoDB evaluates expressions as either true or false can be found here. - - then Can be any valid expression. - The branches array must contain at least one branch document. - - - name: default - type: - - expression - optional: true - description: | - The path to take if no branch case expression evaluates to true. - Although optional, if default is unspecified and no branch case evaluates to true, $switch returns an error. + - name: branches + type: + - array + description: | + An array of control branch documents. Each branch is a document with the following fields: + - case Can be any valid expression that resolves to a boolean. If the result is not a boolean, it is coerced to a boolean value. More information about how MongoDB evaluates expressions as either true or false can be found here. + - then Can be any valid expression. + The branches array must contain at least one branch document. + - name: default + type: + - expression + optional: true + description: | + The path to take if no branch case expression evaluates to true. + Although optional, if default is unspecified and no branch case evaluates to true, $switch returns an error. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/switch/#example' - pipeline: - - - $project: - name: 1 - summary: - $switch: - branches: - - - case: - $gte: - - - #$avg: '$scores' - $avg: [ '$scores' ] - - 90 - then: 'Doing great!' - - - case: - $and: - - - $gte: - - - #$avg: '$scores' - $avg: [ '$scores' ] - - 80 - - - $lt: - - - #$avg: '$scores' - $avg: [ '$scores' ] - - 90 - then: 'Doing pretty well.' - - - case: - $lt: - - - #$avg: '$scores' - $avg: [ '$scores' ] + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/switch/#example + pipeline: + - $project: + name: 1 + summary: + $switch: + branches: + - case: + $gte: + - $avg: + - $scores + - 90 + then: Doing great! + - case: + $and: + - $gte: + - $avg: + - $scores - 80 - then: 'Needs improvement.' - default: 'No scores found.' + - $lt: + - $avg: + - $scores + - 90 + then: Doing pretty well. + - case: + $lt: + - $avg: + - $scores + - 80 + then: Needs improvement. + default: No scores found. + schema: + TestCollection: + _id: + types: + - bsonType: Number + name: + types: + - bsonType: String + scores: + types: + - bsonType: Array + types: + - bsonType: Number diff --git a/generator/config/expression/tan.yaml b/generator/config/expression/tan.yaml index 17b11ee63..859c4a5d0 100644 --- a/generator/config/expression/tan.yaml +++ b/generator/config/expression/tan.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $tan -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/tan/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/tan/ type: - resolvesToDouble - resolvesToDecimal @@ -8,23 +8,30 @@ encode: single description: | Returns the tangent of a value that is measured in radians. arguments: - - - name: expression - type: - - resolvesToNumber - description: | - $tan takes any valid expression that resolves to a number. If the expression returns a value in degrees, use the $degreesToRadians operator to convert the result to radians. - By default $tan returns values as a double. $tan can also return values as a 128-bit decimal as long as the expression resolves to a 128-bit decimal value. + - name: expression + type: + - resolvesToNumber + description: | + $tan takes any valid expression that resolves to a number. If the expression returns a value in degrees, use the $degreesToRadians operator to convert the result to radians. + By default $tan returns values as a double. $tan can also return values as a 128-bit decimal as long as the expression resolves to a 128-bit decimal value. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/tan/#example' - pipeline: - - - $addFields: - side_b: - $multiply: - - - $tan: - $degreesToRadians: '$angle_a' - - '$side_a' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/tan/#example + pipeline: + - $addFields: + side_b: + $multiply: + - $tan: + $degreesToRadians: $angle_a + - $side_a + schema: + TestCollection: + _id: + types: + - bsonType: ObjectId + angle_a: + types: + - bsonType: Decimal128 + side_a: + types: + - bsonType: Decimal128 diff --git a/generator/config/expression/tanh.yaml b/generator/config/expression/tanh.yaml index 364589452..67daa9d1a 100644 --- a/generator/config/expression/tanh.yaml +++ b/generator/config/expression/tanh.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $tanh -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/tanh/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/tanh/ type: - resolvesToDouble - resolvesToDecimal @@ -8,20 +8,25 @@ encode: single description: | Returns the hyperbolic tangent of a value that is measured in radians. arguments: - - - name: expression - type: - - resolvesToNumber - description: | - $tanh takes any valid expression that resolves to a number, measured in radians. If the expression returns a value in degrees, use the $degreesToRadians operator to convert the value to radians. - By default $tanh returns values as a double. $tanh can also return values as a 128-bit decimal if the expression resolves to a 128-bit decimal value. + - name: expression + type: + - resolvesToNumber + description: | + $tanh takes any valid expression that resolves to a number, measured in radians. If the expression returns a value in degrees, use the $degreesToRadians operator to convert the value to radians. + By default $tanh returns values as a double. $tanh can also return values as a 128-bit decimal if the expression resolves to a 128-bit decimal value. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/tanh/#example' - pipeline: - - - $addFields: - tanh_output: - $tanh: - $degreesToRadians: '$angle' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/tanh/#example + pipeline: + - $addFields: + tanh_output: + $tanh: + $degreesToRadians: $angle + schema: + trigonometry: + _id: + types: + - bsonType: ObjectId + angle: + types: + - bsonType: Decimal128 diff --git a/generator/config/expression/toBool.yaml b/generator/config/expression/toBool.yaml index 7f771ec8d..748aa5411 100644 --- a/generator/config/expression/toBool.yaml +++ b/generator/config/expression/toBool.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $toBool -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/toBool/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/toBool/ type: - resolvesToBool encode: single @@ -8,34 +8,44 @@ description: | Converts value to a boolean. New in MongoDB 4.0. arguments: - - - name: expression - type: - - expression + - name: expression + type: + - expression tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/toBool/#example' - pipeline: - - - $addFields: - convertedShippedFlag: - $switch: - branches: - - - case: - $eq: - - '$shipped' - - 'false' - then: false - - - case: - $eq: - - '$shipped' - - '' - then: false - default: - $toBool: '$shipped' - - - $match: - convertedShippedFlag: false + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/toBool/#example + pipeline: + - $addFields: + convertedShippedFlag: + $switch: + branches: + - case: + $eq: + - $shipped + - 'false' + then: false + - case: + $eq: + - $shipped + - '' + then: false + default: + $toBool: $shipped + - $match: + convertedShippedFlag: false + schema: + orders: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + qty: + types: + - bsonType: Number + shipped: + types: + - bsonType: String + - bsonType: Number + - bsonType: Boolean diff --git a/generator/config/expression/toDate.yaml b/generator/config/expression/toDate.yaml index d9434a6bd..ebf4218dd 100644 --- a/generator/config/expression/toDate.yaml +++ b/generator/config/expression/toDate.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $toDate -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/toDate/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/toDate/ type: - resolvesToDate encode: single @@ -8,19 +8,33 @@ description: | Converts value to a Date. New in MongoDB 4.0. arguments: - - - name: expression - type: - - expression + - name: expression + type: + - expression tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/toDate/#example' - pipeline: - - - $addFields: - convertedDate: - $toDate: '$order_date' - - - $sort: - convertedDate: 1 + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/toDate/#example + pipeline: + - $addFields: + convertedDate: + $toDate: $order_date + - $sort: + convertedDate: 1 + schema: + orders: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + qty: + types: + - bsonType: Number + price: + types: + - bsonType: Number + order_date: + types: + - bsonType: Date + - bsonType: String diff --git a/generator/config/expression/toDecimal.yaml b/generator/config/expression/toDecimal.yaml index 2f3588323..2af8c6efa 100644 --- a/generator/config/expression/toDecimal.yaml +++ b/generator/config/expression/toDecimal.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $toDecimal -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/toDecimal/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/toDecimal/ type: - resolvesToDecimal encode: single @@ -8,16 +8,29 @@ description: | Converts value to a Decimal128. New in MongoDB 4.0. arguments: - - - name: expression - type: - - expression + - name: expression + type: + - expression tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/toDecimal/#example' - pipeline: - - - $addFields: - convertedPrice: - $toDecimal: '$price' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/toDecimal/#example + pipeline: + - $addFields: + convertedPrice: + $toDecimal: $price + schema: + orders: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + qty: + types: + - bsonType: Number + price: + types: + - bsonType: Number + - bsonType: Decimal128 + - bsonType: String diff --git a/generator/config/expression/toDouble.yaml b/generator/config/expression/toDouble.yaml index f34c36e9a..f7a5eec60 100644 --- a/generator/config/expression/toDouble.yaml +++ b/generator/config/expression/toDouble.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $toDouble -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/toDouble/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/toDouble/ type: - resolvesToDouble encode: single @@ -8,20 +8,28 @@ description: | Converts value to a double. New in MongoDB 4.0. arguments: - - - name: expression - type: - - expression + - name: expression + type: + - expression tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/toDouble/#example' - pipeline: - - - $addFields: - degrees: - $toDouble: - $substrBytes: - - '$temp' - - 0 - - 4 + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/toDouble/#example + pipeline: + - $addFields: + degrees: + $toDouble: + $substrBytes: + - $temp + - 0 + - 4 + schema: + weather: + _id: + types: + - bsonType: Number + date: + types: + - bsonType: Date + temp: + types: + - bsonType: String diff --git a/generator/config/expression/toHashedIndexKey.yaml b/generator/config/expression/toHashedIndexKey.yaml index f5811f56d..260a2ea6e 100644 --- a/generator/config/expression/toHashedIndexKey.yaml +++ b/generator/config/expression/toHashedIndexKey.yaml @@ -1,28 +1,28 @@ # $schema: ../schema.json name: $toHashedIndexKey -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/toHashedIndexKey/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/toHashedIndexKey/ type: - - resolvesToLong + - resolvesToLong encode: single description: | - 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. + 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. arguments: - - - name: value - type: - - expression - description: | - key or string to hash + - name: value + type: + - expression + description: | + key or string to hash tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/toHashedIndexKey/#example' - pipeline: - - - $documents: - - - val: 'string to hash' - - - $addFields: - hashedVal: - $toHashedIndexKey: '$val' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/toHashedIndexKey/#example + pipeline: + - $documents: + - val: string to hash + - $addFields: + hashedVal: + $toHashedIndexKey: $val + schema: + TestCollection: + val: + types: + - bsonType: String diff --git a/generator/config/expression/toInt.yaml b/generator/config/expression/toInt.yaml index 2b0239955..5d2a79fc0 100644 --- a/generator/config/expression/toInt.yaml +++ b/generator/config/expression/toInt.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $toInt -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/toInt/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/toInt/ type: - resolvesToInt encode: single @@ -8,16 +8,29 @@ description: | Converts value to an integer. New in MongoDB 4.0. arguments: - - - name: expression - type: - - expression + - name: expression + type: + - expression tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/toInt/#example' - pipeline: - - - $addFields: - convertedQty: - $toInt: '$qty' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/toInt/#example + pipeline: + - $addFields: + convertedQty: + $toInt: $qty + schema: + orders: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + qty: + types: + - bsonType: String + price: + types: + - bsonType: Number + - bsonType: Decimal128 + - bsonType: String diff --git a/generator/config/expression/toLong.yaml b/generator/config/expression/toLong.yaml index 3168ad9ff..cd278dd98 100644 --- a/generator/config/expression/toLong.yaml +++ b/generator/config/expression/toLong.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $toLong -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/toLong/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/toLong/ type: - resolvesToLong encode: single @@ -8,19 +8,28 @@ description: | Converts value to a long. New in MongoDB 4.0. arguments: - - - name: expression - type: - - expression + - name: expression + type: + - expression tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/toLong/#example' - pipeline: - - - $addFields: - convertedQty: - $toLong: '$qty' - - - $sort: - convertedQty: -1 + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/toLong/#example + pipeline: + - $addFields: + convertedQty: + $toLong: $qty + - $sort: + convertedQty: -1 + schema: + orders: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + qty: + types: + - bsonType: String + - bsonType: Int32 + - bsonType: Long diff --git a/generator/config/expression/toLower.yaml b/generator/config/expression/toLower.yaml index 0d6176672..7dc0861f5 100644 --- a/generator/config/expression/toLower.yaml +++ b/generator/config/expression/toLower.yaml @@ -1,24 +1,36 @@ # $schema: ../schema.json name: $toLower -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/toLower/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/toLower/ type: - resolvesToString encode: single description: | Converts a string to lowercase. Accepts a single argument expression. arguments: - - - name: expression - type: - - resolvesToString + - name: expression + type: + - resolvesToString tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/toLower/#example' - pipeline: - - - $project: - item: - $toLower: '$item' - description: - $toLower: '$description' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/toLower/#example + pipeline: + - $project: + item: + $toLower: $item + description: + $toLower: $description + schema: + inventory: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + quarter: + types: + - bsonType: String + description: + types: + - bsonType: String + - bsonType: 'Null' diff --git a/generator/config/expression/toObjectId.yaml b/generator/config/expression/toObjectId.yaml index 803f7cafa..5a1c75ed7 100644 --- a/generator/config/expression/toObjectId.yaml +++ b/generator/config/expression/toObjectId.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $toObjectId -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/toObjectId/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/toObjectId/ type: - resolvesToObjectId encode: single @@ -8,19 +8,27 @@ description: | Converts value to an ObjectId. New in MongoDB 4.0. arguments: - - - name: expression - type: - - expression + - name: expression + type: + - expression tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/toObjectId/#example' - pipeline: - - - $addFields: - convertedId: - $toObjectId: '$_id' - - - $sort: - convertedId: -1 + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/toObjectId/#example + pipeline: + - $addFields: + convertedId: + $toObjectId: $_id + - $sort: + convertedId: -1 + schema: + orders: + _id: + types: + - bsonType: String + - bsonType: ObjectId + item: + types: + - bsonType: String + qty: + types: + - bsonType: Number diff --git a/generator/config/expression/toString.yaml b/generator/config/expression/toString.yaml index 0fd068562..44c139922 100644 --- a/generator/config/expression/toString.yaml +++ b/generator/config/expression/toString.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $toString -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/toString/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/toString/ type: - resolvesToString encode: single @@ -8,19 +8,30 @@ description: | Converts value to a string. New in MongoDB 4.0. arguments: - - - name: expression - type: - - expression + - name: expression + type: + - expression tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/toString/#example' - pipeline: - - - $addFields: - convertedZipCode: - $toString: '$zipcode' - - - $sort: - convertedZipCode: 1 + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/toString/#example + pipeline: + - $addFields: + convertedZipCode: + $toString: $zipcode + - $sort: + convertedZipCode: 1 + schema: + orders: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + qty: + types: + - bsonType: Number + zipcode: + types: + - bsonType: Number + - bsonType: String diff --git a/generator/config/expression/toUpper.yaml b/generator/config/expression/toUpper.yaml index c2c71e1bc..a69c1ab35 100644 --- a/generator/config/expression/toUpper.yaml +++ b/generator/config/expression/toUpper.yaml @@ -1,24 +1,36 @@ # $schema: ../schema.json name: $toUpper -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/toUpper/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/toUpper/ type: - resolvesToString encode: single description: | Converts a string to uppercase. Accepts a single argument expression. arguments: - - - name: expression - type: - - resolvesToString + - name: expression + type: + - resolvesToString tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/toUpper/#example' - pipeline: - - - $project: - item: - $toUpper: '$item' - description: - $toUpper: '$description' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/toUpper/#example + pipeline: + - $project: + item: + $toUpper: $item + description: + $toUpper: $description + schema: + inventory: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + quarter: + types: + - bsonType: String + description: + types: + - bsonType: String + - bsonType: 'Null' diff --git a/generator/config/expression/trim.yaml b/generator/config/expression/trim.yaml index d63423910..4c5d4c699 100644 --- a/generator/config/expression/trim.yaml +++ b/generator/config/expression/trim.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $trim -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/trim/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/trim/ type: - resolvesToString encode: object @@ -8,29 +8,40 @@ description: | Removes whitespace or the specified characters from the beginning and end of a string. New in MongoDB 4.0. arguments: - - - name: input - type: - - resolvesToString - description: | - The string to trim. The argument can be any valid expression that resolves to a string. - - - name: chars - type: - - resolvesToString - optional: true - description: | - The character(s) to trim from the beginning of the input. - The argument can be any valid expression that resolves to a string. The $ltrim operator breaks down the string into individual UTF code point to trim from input. - If unspecified, $ltrim removes whitespace characters, including the null character. + - name: input + type: + - resolvesToString + description: | + The string to trim. The argument can be any valid expression that resolves to a string. + - name: chars + type: + - resolvesToString + optional: true + description: | + The character(s) to trim from the beginning of the input. + The argument can be any valid expression that resolves to a string. The $ltrim operator breaks down the string into individual UTF code point to trim from input. + If unspecified, $ltrim removes whitespace characters, including the null character. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/trim/#example' - pipeline: - - - $project: - item: 1 - description: - $trim: - input: '$description' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/trim/#example + pipeline: + - $project: + item: 1 + description: + $trim: + input: $description + schema: + inventory: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + quarter: + types: + - bsonType: String + description: + types: + - bsonType: String + - bsonType: 'Null' diff --git a/generator/config/expression/trunc.yaml b/generator/config/expression/trunc.yaml index f930cf027..1db19b2f6 100644 --- a/generator/config/expression/trunc.yaml +++ b/generator/config/expression/trunc.yaml @@ -1,34 +1,38 @@ # $schema: ../schema.json name: $trunc -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/trunc/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/trunc/ type: - resolvesToString encode: array description: | Truncates a number to a whole integer or to a specified decimal place. arguments: - - - name: number - type: - - resolvesToNumber - description: | - Can be any valid expression that resolves to a number. Specifically, the expression must resolve to an integer, double, decimal, or long. - $trunc returns an error if the expression resolves to a non-numeric data type. - - - name: place - type: - - resolvesToInt - optional: true - description: | - Can be any valid expression that resolves to an integer between -20 and 100, exclusive. e.g. -20 < place < 100. Defaults to 0. + - name: number + type: + - resolvesToNumber + description: | + Can be any valid expression that resolves to a number. Specifically, the expression must resolve to an integer, double, decimal, or long. + $trunc returns an error if the expression resolves to a non-numeric data type. + - name: place + type: + - resolvesToInt + optional: true + description: | + Can be any valid expression that resolves to an integer between -20 and 100, exclusive. e.g. -20 < place < 100. Defaults to 0. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/trunc/#example' - pipeline: - - - $project: - truncatedValue: - $trunc: - - '$value' - - 1 + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/trunc/#example + pipeline: + - $project: + truncatedValue: + $trunc: + - $value + - 1 + schema: + samples: + _id: + types: + - bsonType: Number + value: + types: + - bsonType: Number diff --git a/generator/config/expression/tsIncrement.yaml b/generator/config/expression/tsIncrement.yaml index 9fded2143..e00416892 100644 --- a/generator/config/expression/tsIncrement.yaml +++ b/generator/config/expression/tsIncrement.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $tsIncrement -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/tsIncrement/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/tsIncrement/ type: - resolvesToLong encode: single @@ -8,32 +8,47 @@ description: | Returns the incrementing ordinal from a timestamp as a long. New in MongoDB 5.1. arguments: - - - name: expression - type: - - resolvesToTimestamp + - name: expression + type: + - resolvesToTimestamp tests: - - - name: 'Obtain the Incrementing Ordinal from a Timestamp Field' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/tsIncrement/#obtain-the-incrementing-ordinal-from-a-timestamp-field' - pipeline: - - - $project: - _id: 0 - saleTimestamp: 1 - saleIncrement: - $tsIncrement: '$saleTimestamp' - - - name: 'Use $tsSecond in a Change Stream Cursor to Monitor Collection Changes' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/tsSecond/#use--tssecond-in-a-change-stream-cursor-to-monitor-collection-changes' - pipeline: - - - $match: - $expr: - $eq: - - - $mod: - - - $tsIncrement: '$clusterTime' - - 2 - - 0 + - name: Obtain the Incrementing Ordinal from a Timestamp Field + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/tsIncrement/#obtain-the-incrementing-ordinal-from-a-timestamp-field + pipeline: + - $project: + _id: 0 + saleTimestamp: 1 + saleIncrement: + $tsIncrement: $saleTimestamp + schema: + stockSales: + _id: + types: + - bsonType: Number + symbol: + types: + - bsonType: String + saleTimestamp: + types: + - bsonType: Timestamp + - name: Use $tsSecond in a Change Stream Cursor to Monitor Collection Changes + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/tsSecond/#use--tssecond-in-a-change-stream-cursor-to-monitor-collection-changes + pipeline: + - $match: + $expr: + $eq: + - $mod: + - $tsIncrement: $clusterTime + - 2 + - 0 + schema: + stockSales: + _id: + types: + - bsonType: Number + symbol: + types: + - bsonType: String + saleTimestamp: + types: + - bsonType: Timestamp diff --git a/generator/config/expression/tsSecond.yaml b/generator/config/expression/tsSecond.yaml index 20a84904b..4f40426c3 100644 --- a/generator/config/expression/tsSecond.yaml +++ b/generator/config/expression/tsSecond.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $tsSecond -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/tsSecond/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/tsSecond/ type: - resolvesToLong encode: single @@ -8,26 +8,43 @@ description: | Returns the seconds from a timestamp as a long. New in MongoDB 5.1. arguments: - - - name: expression - type: - - resolvesToTimestamp + - name: expression + type: + - resolvesToTimestamp tests: - - - name: 'Obtain the Number of Seconds from a Timestamp Field' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/tsSecond/#obtain-the-number-of-seconds-from-a-timestamp-field' - pipeline: - - - $project: - _id: 0 - saleTimestamp: 1 - saleSeconds: - $tsSecond: '$saleTimestamp' - - - name: 'Use $tsSecond in a Change Stream Cursor to Monitor Collection Changes' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/tsSecond/#use--tssecond-in-a-change-stream-cursor-to-monitor-collection-changes' - pipeline: - - - $addFields: - clusterTimeSeconds: - $tsSecond: '$clusterTime' + - name: Obtain the Number of Seconds from a Timestamp Field + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/tsSecond/#obtain-the-number-of-seconds-from-a-timestamp-field + pipeline: + - $project: + _id: 0 + saleTimestamp: 1 + saleSeconds: + $tsSecond: $saleTimestamp + schema: + stockSales: + _id: + types: + - bsonType: Number + symbol: + types: + - bsonType: String + saleTimestamp: + types: + - bsonType: Timestamp + - name: Use $tsSecond in a Change Stream Cursor to Monitor Collection Changes + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/tsSecond/#use--tssecond-in-a-change-stream-cursor-to-monitor-collection-changes + pipeline: + - $addFields: + clusterTimeSeconds: + $tsSecond: $clusterTime + schema: + stockSales: + _id: + types: + - bsonType: Number + symbol: + types: + - bsonType: String + saleTimestamp: + types: + - bsonType: Timestamp diff --git a/generator/config/expression/type.yaml b/generator/config/expression/type.yaml index c1f63db79..3f9eb7fa4 100644 --- a/generator/config/expression/type.yaml +++ b/generator/config/expression/type.yaml @@ -1,22 +1,43 @@ # $schema: ../schema.json name: $type -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/type/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/type/ type: - resolvesToString encode: single description: | Return the BSON data type of the field. arguments: - - - name: expression - type: - - expression + - name: expression + type: + - expression tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/type/#example' - pipeline: - - - $project: - a: - $type: '$a' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/type/#example + pipeline: + - $project: + a: + $type: $a + schema: + TestCollection: + _id: + types: + - bsonType: Number + a: + types: + - bsonType: Number + - bsonType: Array + types: + - bsonType: Number + - bsonType: Document + fields: + a: + types: + - bsonType: String + b: + types: + - bsonType: String + c: + types: + - bsonType: String + - bsonType: String + - bsonType: Long diff --git a/generator/config/expression/unsetField.yaml b/generator/config/expression/unsetField.yaml index a4365a646..0dd1b0eba 100644 --- a/generator/config/expression/unsetField.yaml +++ b/generator/config/expression/unsetField.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $unsetField -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/unsetField/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/unsetField/ type: - resolvesToObject encode: object @@ -8,52 +8,91 @@ description: | 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. arguments: - - - name: field - type: - - resolvesToString - description: | - Field in the input object that you want to add, update, or remove. field can be any valid expression that resolves to a string constant. - - - name: input - type: - - resolvesToObject - description: | - Document that contains the field that you want to add or update. input must resolve to an object, missing, null, or undefined. + - name: field + type: + - resolvesToString + description: | + Field in the input object that you want to add, update, or remove. field can be any valid expression that resolves to a string constant. + - name: input + type: + - resolvesToObject + description: | + Document that contains the field that you want to add or update. input must resolve to an object, missing, null, or undefined. tests: - - - name: 'Remove Fields that Contain Periods' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/unsetField/#remove-fields-that-contain-periods--.-' - pipeline: - - - $replaceWith: - $unsetField: - field: 'price.usd' - input: '$$ROOT' - - - name: 'Remove Fields that Start with a Dollar Sign' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/unsetField/#remove-fields-that-start-with-a-dollar-sign----' - pipeline: - - - $replaceWith: - $unsetField: - field: - $literal: '$price' - input: '$$ROOT' - - - name: 'Remove A Subfield' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/unsetField/#remove-a-subfield' - pipeline: - - - $replaceWith: - $setField: - field: 'price' - input: '$$ROOT' - value: - $unsetField: - field: 'euro' - input: - # Example uses the short form, the builder always generates the verbose form - # $getField: 'price' - $getField: - field: 'price' + - name: Remove Fields that Contain Periods + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/unsetField/#remove-fields-that-contain-periods--.- + pipeline: + - $replaceWith: + $unsetField: + field: price.usd + input: $$ROOT + schema: + inventory: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + qty: + types: + - bsonType: Number + price.usd: + types: + - bsonType: Number + - name: Remove Fields that Start with a Dollar Sign + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/unsetField/#remove-fields-that-start-with-a-dollar-sign---- + pipeline: + - $replaceWith: + $unsetField: + field: + $literal: $price + input: $$ROOT + schema: + inventory: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + qty: + types: + - bsonType: Number + $price: + types: + - bsonType: Number + - name: Remove A Subfield + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/unsetField/#remove-a-subfield + pipeline: + - $replaceWith: + $setField: + field: price + input: $$ROOT + value: + $unsetField: + field: euro + input: + $getField: + field: price + schema: + inventory: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + qty: + types: + - bsonType: Number + price: + types: + - bsonType: Document + fields: + usd: + types: + - bsonType: Number + euro: + types: + - bsonType: Number diff --git a/generator/config/expression/week.yaml b/generator/config/expression/week.yaml index 6086f57ee..978513add 100644 --- a/generator/config/expression/week.yaml +++ b/generator/config/expression/week.yaml @@ -1,36 +1,47 @@ # $schema: ../schema.json name: $week -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/week/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/week/ type: - resolvesToInt encode: object description: | 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). arguments: - - - name: date - type: - - resolvesToDate - - resolvesToTimestamp - - resolvesToObjectId - description: | - The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. - - - name: timezone - type: - - resolvesToString - optional: true - description: | - The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. + - name: date + type: + - resolvesToDate + - resolvesToTimestamp + - resolvesToObjectId + description: | + The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + - name: timezone + type: + - resolvesToString + optional: true + description: | + The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/week/#example' - pipeline: - - - $project: - week: - # Example uses the short form, the builder always generates the verbose form - # $week: '$date' - $week: - date: '$date' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/week/#example + pipeline: + - $project: + week: + $week: + date: $date + schema: + sales: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + price: + types: + - bsonType: Number + quantity: + types: + - bsonType: Number + date: + types: + - bsonType: Date diff --git a/generator/config/expression/year.yaml b/generator/config/expression/year.yaml index 3326e3495..6ac43e610 100644 --- a/generator/config/expression/year.yaml +++ b/generator/config/expression/year.yaml @@ -1,36 +1,47 @@ # $schema: ../schema.json name: $year -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/year/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/year/ type: - resolvesToInt encode: object description: | Returns the year for a date as a number (e.g. 2014). arguments: - - - name: date - type: - - resolvesToDate - - resolvesToTimestamp - - resolvesToObjectId - description: | - The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. - - - name: timezone - type: - - resolvesToString - optional: true - description: | - The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. + - name: date + type: + - resolvesToDate + - resolvesToTimestamp + - resolvesToObjectId + description: | + The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + - name: timezone + type: + - resolvesToString + optional: true + description: | + The timezone of the operation result. timezone must be a valid expression that resolves to a string formatted as either an Olson Timezone Identifier or a UTC Offset. If no timezone is provided, the result is displayed in UTC. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/year/#example' - pipeline: - - - $project: - year: - # Example uses the short form, the builder always generates the verbose form - # $year: '$date' - $year: - date: '$date' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/year/#example + pipeline: + - $project: + year: + $year: + date: $date + schema: + sales: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + price: + types: + - bsonType: Number + quantity: + types: + - bsonType: Number + date: + types: + - bsonType: Date diff --git a/generator/config/expression/zip.yaml b/generator/config/expression/zip.yaml index 76402dac5..48c7fe942 100644 --- a/generator/config/expression/zip.yaml +++ b/generator/config/expression/zip.yaml @@ -1,87 +1,101 @@ # $schema: ../schema.json name: $zip -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/zip/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/zip/ type: - - resolvesToArray # of array + - resolvesToArray encode: object description: | Merge two arrays together. arguments: - - - name: inputs - type: - - resolvesToArray # of array - description: | - An array of expressions that resolve to arrays. The elements of these input arrays combine to form the arrays of the output array. - If any of the inputs arrays resolves to a value of null or refers to a missing field, $zip returns null. - If any of the inputs arrays does not resolve to an array or null nor refers to a missing field, $zip returns an error. - - - name: useLongestLength - type: - - bool - optional: true - description: | - A boolean which specifies whether the length of the longest array determines the number of arrays in the output array. - The default value is false: the shortest array length determines the number of arrays in the output array. - - - name: defaults - type: - - array - optional: true - description: | - An array of default element values to use if the input arrays have different lengths. You must specify useLongestLength: true along with this field, or else $zip will return an error. - If useLongestLength: true but defaults is empty or not specified, $zip uses null as the default value. - If specifying a non-empty defaults, you must specify a default for each input array or else $zip will return an error. + - name: inputs + type: + - resolvesToArray + description: | + An array of expressions that resolve to arrays. The elements of these input arrays combine to form the arrays of the output array. + If any of the inputs arrays resolves to a value of null or refers to a missing field, $zip returns null. + If any of the inputs arrays does not resolve to an array or null nor refers to a missing field, $zip returns an error. + - name: useLongestLength + type: + - bool + optional: true + description: | + A boolean which specifies whether the length of the longest array determines the number of arrays in the output array. + The default value is false: the shortest array length determines the number of arrays in the output array. + - name: defaults + type: + - array + optional: true + description: | + An array of default element values to use if the input arrays have different lengths. You must specify useLongestLength: true along with this field, or else $zip will return an error. + If useLongestLength: true but defaults is empty or not specified, $zip uses null as the default value. + If specifying a non-empty defaults, you must specify a default for each input array or else $zip will return an error. tests: - - - name: 'Matrix Transposition' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/zip/#matrix-transposition' - pipeline: - - - $project: - _id: false - transposed: - $zip: - inputs: - - - $arrayElemAt: - - '$matrix' - - 0 - - - $arrayElemAt: - - '$matrix' + - name: Matrix Transposition + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/zip/#matrix-transposition + pipeline: + - $project: + _id: false + transposed: + $zip: + inputs: + - $arrayElemAt: + - $matrix + - 0 + - $arrayElemAt: + - $matrix + - 1 + - $arrayElemAt: + - $matrix + - 2 + schema: + matrices: + matrix: + types: + - bsonType: Array + types: + - bsonType: Array + types: + - bsonType: Number + - name: Filtering and Preserving Indexes + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/zip/#filtering-and-preserving-indexes + pipeline: + - $project: + _id: false + pages: + $filter: + input: + $zip: + inputs: + - $pages + - $range: + - 0 + - $size: $pages + as: pageWithIndex + cond: + $let: + vars: + page: + $arrayElemAt: + - $$pageWithIndex + - 0 + in: + $gte: + - $$page.reviews - 1 - - - $arrayElemAt: - - '$matrix' - - 2 - - - name: 'Filtering and Preserving Indexes' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/zip/#filtering-and-preserving-indexes' - pipeline: - - - $project: - _id: false - pages: - $filter: - input: - $zip: - inputs: - - '$pages' - - - $range: - - 0 - - - $size: '$pages' - as: 'pageWithIndex' - cond: - $let: - vars: - page: - $arrayElemAt: - - '$$pageWithIndex' - - 0 - in: - $gte: - - '$$page.reviews' - - 1 + schema: + pages: + category: + types: + - bsonType: String + pages: + types: + - bsonType: Array + types: + - bsonType: Document + fields: + title: + types: + - bsonType: String + reviews: + types: + - bsonType: Number diff --git a/generator/config/query/all.yaml b/generator/config/query/all.yaml index 868e205e2..a17c092e7 100644 --- a/generator/config/query/all.yaml +++ b/generator/config/query/all.yaml @@ -1,43 +1,92 @@ # $schema: ../schema.json name: $all -link: 'https://www.mongodb.com/docs/manual/reference/operator/query/all/' +link: https://www.mongodb.com/docs/manual/reference/operator/query/all/ type: - fieldQuery encode: single description: | Matches arrays that contain all elements specified in the query. arguments: - - - name: value - type: - - fieldQuery - variadic: array + - name: value + type: + - fieldQuery + variadic: array tests: - - - name: 'Use $all to Match Values' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/all/#use--all-to-match-values' - pipeline: - - - $match: - tags: - $all: - - 'appliance' - - 'school' - - 'book' - - - name: 'Use $all with $elemMatch' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/all/#use--all-with--elemmatch' - pipeline: - - - $match: - qty: - $all: - - - $elemMatch: - size: 'M' - num: - $gt: 50 - - - $elemMatch: - num: 100 - color: 'green' + - name: Use $all to Match Values + link: https://www.mongodb.com/docs/manual/reference/operator/query/all/#use--all-to-match-values + pipeline: + - $match: + tags: + $all: + - appliance + - school + - book + schema: + inventory: + _id: + types: + - bsonType: ObjectId + code: + types: + - bsonType: String + tags: + types: + - bsonType: Array + types: + - bsonType: String + qty: + types: + - bsonType: Array + types: + - bsonType: Document + fields: + size: + types: + - bsonType: String + num: + types: + - bsonType: Number + color: + types: + - bsonType: String + - name: Use $all with $elemMatch + link: https://www.mongodb.com/docs/manual/reference/operator/query/all/#use--all-with--elemmatch + pipeline: + - $match: + qty: + $all: + - $elemMatch: + size: M + num: + $gt: 50 + - $elemMatch: + num: 100 + color: green + schema: + inventory: + _id: + types: + - bsonType: ObjectId + code: + types: + - bsonType: String + tags: + types: + - bsonType: Array + types: + - bsonType: String + qty: + types: + - bsonType: Array + types: + - bsonType: Document + fields: + size: + types: + - bsonType: String + num: + types: + - bsonType: Number + color: + types: + - bsonType: String diff --git a/generator/config/query/and.yaml b/generator/config/query/and.yaml index 74ebf506e..dcf231c02 100644 --- a/generator/config/query/and.yaml +++ b/generator/config/query/and.yaml @@ -1,51 +1,61 @@ # $schema: ../schema.json name: $and -link: 'https://www.mongodb.com/docs/manual/reference/operator/query/and/' +link: https://www.mongodb.com/docs/manual/reference/operator/query/and/ type: - query encode: single description: | Joins query clauses with a logical AND returns all documents that match the conditions of both clauses. arguments: - - - name: queries - type: - - query - variadic: array - variadicMin: 1 + - name: queries + type: + - query + variadic: array + variadicMin: 1 tests: - - - name: 'AND Queries With Multiple Expressions Specifying the Same Field' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/and/#and-queries-with-multiple-expressions-specifying-the-same-field' - pipeline: - - - $match: - $and: - - - price: - $ne: 1.99 - - - price: - $exists: true - - - name: 'AND Queries With Multiple Expressions Specifying the Same Operator' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/and/#and-queries-with-multiple-expressions-specifying-the-same-operator' - pipeline: - - - $match: - $and: - - - $or: - - - qty: - $lt: 10 - - - qty: - $gt: 50 - - - $or: - - - sale: true - - - price: - $lt: 5 + - name: AND Queries With Multiple Expressions Specifying the Same Field + link: https://www.mongodb.com/docs/manual/reference/operator/query/and/#and-queries-with-multiple-expressions-specifying-the-same-field + pipeline: + - $match: + $and: + - price: + $ne: 1.99 + - price: + $exists: true + schema: + inventory: &ref_0 + price: + types: + - bsonType: Double + qty: + types: + - bsonType: Int32 + - bsonType: Undefined + quantity: + types: + - bsonType: Int32 + - bsonType: Undefined + sale: + types: + - bsonType: Boolean + tags: + types: + - bsonType: Array + types: + - bsonType: String + - name: AND Queries With Multiple Expressions Specifying the Same Operator + link: https://www.mongodb.com/docs/manual/reference/operator/query/and/#and-queries-with-multiple-expressions-specifying-the-same-operator + pipeline: + - $match: + $and: + - $or: + - qty: + $lt: 10 + - qty: + $gt: 50 + - $or: + - sale: true + - price: + $lt: 5 + schema: + inventory: *ref_0 diff --git a/generator/config/query/bitsAllClear.yaml b/generator/config/query/bitsAllClear.yaml index 48e98037d..160dd6410 100644 --- a/generator/config/query/bitsAllClear.yaml +++ b/generator/config/query/bitsAllClear.yaml @@ -1,38 +1,71 @@ # $schema: ../schema.json name: $bitsAllClear -link: 'https://www.mongodb.com/docs/manual/reference/operator/query/bitsAllClear/' +link: https://www.mongodb.com/docs/manual/reference/operator/query/bitsAllClear/ type: - fieldQuery encode: single description: | Matches numeric or binary values in which a set of bit positions all have a value of 0. arguments: - - - name: bitmask - type: - - int - - binData - - array # of int + - name: bitmask + type: + - int + - binData + - array tests: - - - name: 'Bit Position Array' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/bitsAllClear/#bit-position-array' - pipeline: - - - $match: - a: - $bitsAllClear: [1, 5] - - - name: 'Integer Bitmask' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/bitsAllClear/#integer-bitmask' - pipeline: - - $match: - a: - $bitsAllClear: 35 - - - name: 'BinData Bitmask' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/bitsAllClear/#bindata-bitmask' - pipeline: - - $match: - a: - $bitsAllClear: !bson_binary 'IA==' + - name: Bit Position Array + link: https://www.mongodb.com/docs/manual/reference/operator/query/bitsAllClear/#bit-position-array + pipeline: + - $match: + a: + $bitsAllClear: + - 1 + - 5 + schema: + collection: + _id: + types: + - bsonType: Number + a: + types: + - bsonType: Number + - bsonType: Binary + binaryValueofA: + types: + - bsonType: String + - name: Integer Bitmask + link: https://www.mongodb.com/docs/manual/reference/operator/query/bitsAllClear/#integer-bitmask + pipeline: + - $match: + a: + $bitsAllClear: 35 + schema: + collection: + _id: + types: + - bsonType: Number + a: + types: + - bsonType: Number + - bsonType: Binary + binaryValueofA: + types: + - bsonType: String + - name: BinData Bitmask + link: https://www.mongodb.com/docs/manual/reference/operator/query/bitsAllClear/#bindata-bitmask + pipeline: + - $match: + a: + $bitsAllClear: !bson_binary IA== + schema: + collection: + _id: + types: + - bsonType: Number + a: + types: + - bsonType: Number + - bsonType: Binary + binaryValueofA: + types: + - bsonType: String diff --git a/generator/config/query/bitsAllSet.yaml b/generator/config/query/bitsAllSet.yaml index 25e2c6eb8..ad9f35a77 100644 --- a/generator/config/query/bitsAllSet.yaml +++ b/generator/config/query/bitsAllSet.yaml @@ -1,38 +1,71 @@ # $schema: ../schema.json name: $bitsAllSet -link: 'https://www.mongodb.com/docs/manual/reference/operator/query/bitsAllSet/' +link: https://www.mongodb.com/docs/manual/reference/operator/query/bitsAllSet/ type: - fieldQuery encode: single description: | Matches numeric or binary values in which a set of bit positions all have a value of 1. arguments: - - - name: bitmask - type: - - int - - binData - - array # of int + - name: bitmask + type: + - int + - binData + - array tests: - - - name: 'Bit Position Array' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/bitsAllSet/#bit-position-array' - pipeline: - - - $match: - a: - $bitsAllSet: [1, 5] - - - name: 'Integer Bitmask' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/bitsAllSet/#integer-bitmask' - pipeline: - - $match: - a: - $bitsAllSet: 50 - - - name: 'BinData Bitmask' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/bitsAllSet/#bindata-bitmask' - pipeline: - - $match: - a: - $bitsAllSet: !bson_binary 'MA==' + - name: Bit Position Array + link: https://www.mongodb.com/docs/manual/reference/operator/query/bitsAllSet/#bit-position-array + pipeline: + - $match: + a: + $bitsAllSet: + - 1 + - 5 + schema: + collection: + _id: + types: + - bsonType: Number + a: + types: + - bsonType: Number + - bsonType: Binary + binaryValueofA: + types: + - bsonType: String + - name: Integer Bitmask + link: https://www.mongodb.com/docs/manual/reference/operator/query/bitsAllSet/#integer-bitmask + pipeline: + - $match: + a: + $bitsAllSet: 50 + schema: + collection: + _id: + types: + - bsonType: Number + a: + types: + - bsonType: Number + - bsonType: Binary + binaryValueofA: + types: + - bsonType: String + - name: BinData Bitmask + link: https://www.mongodb.com/docs/manual/reference/operator/query/bitsAllSet/#bindata-bitmask + pipeline: + - $match: + a: + $bitsAllSet: !bson_binary MA== + schema: + collection: + _id: + types: + - bsonType: Number + a: + types: + - bsonType: Number + - bsonType: Binary + binaryValueofA: + types: + - bsonType: String diff --git a/generator/config/query/bitsAnyClear.yaml b/generator/config/query/bitsAnyClear.yaml index a41260998..c4f4a2114 100644 --- a/generator/config/query/bitsAnyClear.yaml +++ b/generator/config/query/bitsAnyClear.yaml @@ -1,38 +1,71 @@ # $schema: ../schema.json name: $bitsAnyClear -link: 'https://www.mongodb.com/docs/manual/reference/operator/query/bitsAnyClear/' +link: https://www.mongodb.com/docs/manual/reference/operator/query/bitsAnyClear/ type: - fieldQuery encode: single description: | Matches numeric or binary values in which any bit from a set of bit positions has a value of 0. arguments: - - - name: bitmask - type: - - int - - binData - - array # of int + - name: bitmask + type: + - int + - binData + - array tests: - - - name: 'Bit Position Array' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/bitsAnyClear/#bit-position-array' - pipeline: - - - $match: - a: - $bitsAnyClear: [1, 5] - - - name: 'Integer Bitmask' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/bitsAnyClear/#integer-bitmask' - pipeline: - - $match: - a: - $bitsAnyClear: 35 - - - name: 'BinData Bitmask' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/bitsAnyClear/#bindata-bitmask' - pipeline: - - $match: - a: - $bitsAnyClear: !bson_binary 'MA==' + - name: Bit Position Array + link: https://www.mongodb.com/docs/manual/reference/operator/query/bitsAnyClear/#bit-position-array + pipeline: + - $match: + a: + $bitsAnyClear: + - 1 + - 5 + schema: + collection: + _id: + types: + - bsonType: Number + a: + types: + - bsonType: Number + - bsonType: Binary + binaryValueofA: + types: + - bsonType: String + - name: Integer Bitmask + link: https://www.mongodb.com/docs/manual/reference/operator/query/bitsAnyClear/#integer-bitmask + pipeline: + - $match: + a: + $bitsAnyClear: 35 + schema: + collection: + _id: + types: + - bsonType: Number + a: + types: + - bsonType: Number + - bsonType: Binary + binaryValueofA: + types: + - bsonType: String + - name: BinData Bitmask + link: https://www.mongodb.com/docs/manual/reference/operator/query/bitsAnyClear/#bindata-bitmask + pipeline: + - $match: + a: + $bitsAnyClear: !bson_binary MA== + schema: + collection: + _id: + types: + - bsonType: Number + a: + types: + - bsonType: Number + - bsonType: Binary + binaryValueofA: + types: + - bsonType: String diff --git a/generator/config/query/bitsAnySet.yaml b/generator/config/query/bitsAnySet.yaml index 95aae908a..df82d9b39 100644 --- a/generator/config/query/bitsAnySet.yaml +++ b/generator/config/query/bitsAnySet.yaml @@ -1,38 +1,71 @@ # $schema: ../schema.json name: $bitsAnySet -link: 'https://www.mongodb.com/docs/manual/reference/operator/query/bitsAnySet/' +link: https://www.mongodb.com/docs/manual/reference/operator/query/bitsAnySet/ type: - fieldQuery encode: single description: | Matches numeric or binary values in which any bit from a set of bit positions has a value of 1. arguments: - - - name: bitmask - type: - - int - - binData - - array # of int + - name: bitmask + type: + - int + - binData + - array tests: - - - name: 'Bit Position Array' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/bitsAnySet/#bit-position-array' - pipeline: - - - $match: - a: - $bitsAnySet: [1, 5] - - - name: 'Integer Bitmask' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/bitsAnySet/#integer-bitmask' - pipeline: - - $match: - a: - $bitsAnySet: 35 - - - name: 'BinData Bitmask' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/bitsAnySet/#bindata-bitmask' - pipeline: - - $match: - a: - $bitsAnySet: !bson_binary 'MA==' + - name: Bit Position Array + link: https://www.mongodb.com/docs/manual/reference/operator/query/bitsAnySet/#bit-position-array + pipeline: + - $match: + a: + $bitsAnySet: + - 1 + - 5 + schema: + collection: + _id: + types: + - bsonType: Number + a: + types: + - bsonType: Number + - bsonType: Binary + binaryValueofA: + types: + - bsonType: String + - name: Integer Bitmask + link: https://www.mongodb.com/docs/manual/reference/operator/query/bitsAnySet/#integer-bitmask + pipeline: + - $match: + a: + $bitsAnySet: 35 + schema: + collection: + _id: + types: + - bsonType: Number + a: + types: + - bsonType: Number + - bsonType: Binary + binaryValueofA: + types: + - bsonType: String + - name: BinData Bitmask + link: https://www.mongodb.com/docs/manual/reference/operator/query/bitsAnySet/#bindata-bitmask + pipeline: + - $match: + a: + $bitsAnySet: !bson_binary MA== + schema: + collection: + _id: + types: + - bsonType: Number + a: + types: + - bsonType: Number + - bsonType: Binary + binaryValueofA: + types: + - bsonType: String diff --git a/generator/config/query/box.yaml b/generator/config/query/box.yaml index 14043c4ae..66091fb09 100644 --- a/generator/config/query/box.yaml +++ b/generator/config/query/box.yaml @@ -1,13 +1,12 @@ # $schema: ../schema.json name: $box -link: 'https://www.mongodb.com/docs/manual/reference/operator/query/box/' +link: https://www.mongodb.com/docs/manual/reference/operator/query/box/ type: - geometry encode: single description: | Specifies a rectangular box using legacy coordinate pairs for $geoWithin queries. The 2d index supports $box. arguments: - - - name: value - type: - - array + - name: value + type: + - array diff --git a/generator/config/query/center.yaml b/generator/config/query/center.yaml index c86215a52..38c86aae5 100644 --- a/generator/config/query/center.yaml +++ b/generator/config/query/center.yaml @@ -1,13 +1,12 @@ # $schema: ../schema.json name: $center -link: 'https://www.mongodb.com/docs/manual/reference/operator/query/center/' +link: https://www.mongodb.com/docs/manual/reference/operator/query/center/ type: - geometry encode: single description: | Specifies a circle using legacy coordinate pairs to $geoWithin queries when using planar geometry. The 2d index supports $center. arguments: - - - name: value - type: - - array + - name: value + type: + - array diff --git a/generator/config/query/centerSphere.yaml b/generator/config/query/centerSphere.yaml index e3677dade..47ead5c66 100644 --- a/generator/config/query/centerSphere.yaml +++ b/generator/config/query/centerSphere.yaml @@ -1,13 +1,12 @@ # $schema: ../schema.json name: $centerSphere -link: 'https://www.mongodb.com/docs/manual/reference/operator/query/centerSphere/' +link: https://www.mongodb.com/docs/manual/reference/operator/query/centerSphere/ type: - geometry encode: single description: | 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. arguments: - - - name: value - type: - - array + - name: value + type: + - array diff --git a/generator/config/query/comment.yaml b/generator/config/query/comment.yaml deleted file mode 100644 index 13a344613..000000000 --- a/generator/config/query/comment.yaml +++ /dev/null @@ -1,31 +0,0 @@ -# $schema: ../schema.json -name: $comment -link: 'https://www.mongodb.com/docs/manual/reference/operator/query/comment/' -type: - - query -encode: single -description: | - Adds a comment to a query predicate. -arguments: - - - name: comment - type: - - string -tests: - - - name: 'Attach a Comment to an Aggregation Expression' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/comment/#attach-a-comment-to-an-aggregation-expression' - pipeline: - - - $match: - x: - $gt: 0 - $comment: 'Don''t allow negative inputs.' - - - $group: - _id: - $mod: - - '$x' - - 2 - total: - $sum: '$x' diff --git a/generator/config/query/elemMatch.yaml b/generator/config/query/elemMatch.yaml index 95db9572e..b0c9aa0d7 100644 --- a/generator/config/query/elemMatch.yaml +++ b/generator/config/query/elemMatch.yaml @@ -1,68 +1,84 @@ # $schema: ../schema.json name: $elemMatch -link: 'https://www.mongodb.com/docs/manual/reference/operator/query/elemMatch/' +link: https://www.mongodb.com/docs/manual/reference/operator/query/elemMatch/ type: - fieldQuery encode: single description: | The $elemMatch operator matches documents that contain an array field with at least one element that matches all the specified query criteria. arguments: - - - name: query - type: - - query - - fieldQuery + - name: query + type: + - query + - fieldQuery tests: - - - name: 'Element Match' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/elemMatch/#element-match' - pipeline: - - - $match: - results: - $elemMatch: - $gte: 80 - $lt: 85 - - - name: 'Array of Embedded Documents' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/elemMatch/#array-of-embedded-documents' - pipeline: - - - $match: - results: - $elemMatch: - product: 'xyz' - score: - $gte: 8 - - - name: 'Single Query Condition' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/elemMatch/#single-query-condition' - pipeline: - - - $match: - results: - $elemMatch: + - name: Element Match + link: https://www.mongodb.com/docs/manual/reference/operator/query/elemMatch/#element-match + pipeline: + - $match: + results: + $elemMatch: + $gte: 80 + $lt: 85 + schema: + TestCollection: + _id: + types: + - bsonType: Number + results: + types: + - bsonType: Array + types: + - bsonType: Number + - name: Array of Embedded Documents + link: https://www.mongodb.com/docs/manual/reference/operator/query/elemMatch/#array-of-embedded-documents + pipeline: + - $match: + results: + $elemMatch: + product: xyz + score: + $gte: 8 + schema: + survey: + _id: + types: + - bsonType: Number + results: + types: + - bsonType: Array + types: + - bsonType: Document + fields: + product: + types: + - bsonType: String + score: + types: + - bsonType: Number + - bsonType: Document + fields: product: - $ne: 'xyz' - - - name: 'Using $or with $elemMatch' - pipeline: - - - $match: - game: - $elemMatch: - $or: - - - score: - $gt: 10 - - - score: - $lt: 5 - - - name: 'Single field operator' - pipeline: - - - $match: - results: - $elemMatch: - $gt: 10 + types: + - bsonType: String + score: + types: + - bsonType: Number + - name: Single Query Condition + link: https://www.mongodb.com/docs/manual/reference/operator/query/elemMatch/#single-query-condition + pipeline: + - $match: + results: + $elemMatch: + product: + $ne: xyz + schema: + TestCollection: + _id: + types: + - bsonType: Number + results: + types: + - bsonType: Array + types: + - bsonType: Number diff --git a/generator/config/query/eq.yaml b/generator/config/query/eq.yaml index 5629114cc..fca3f1096 100644 --- a/generator/config/query/eq.yaml +++ b/generator/config/query/eq.yaml @@ -1,61 +1,132 @@ # $schema: ../schema.json name: $eq -link: 'https://www.mongodb.com/docs/manual/reference/operator/query/eq/' +link: https://www.mongodb.com/docs/manual/reference/operator/query/eq/ type: - fieldQuery encode: single description: | Matches values that are equal to a specified value. arguments: - - - name: value - type: - - any + - name: value + type: + - expression tests: - - - name: 'Equals a Specified Value' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/eq/#equals-a-specified-value' - pipeline: - - - $match: - qty: - $eq: 20 - - - - name: 'Field in Embedded Document Equals a Value' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/eq/#field-in-embedded-document-equals-a-value' - pipeline: - - - $match: - 'item.name': - $eq: 'ab' - - - - name: 'Equals an Array Value' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/eq/#equals-an-array-value' - pipeline: - - - $match: - tags: - $eq: ['A', 'B'] - - - - name: 'Regex Match Behaviour' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/eq/#regex-match-behaviour' - pipeline: - - - $match: - company: 'MongoDB' - - - $match: - company: - $eq: 'MongoDB' - - - $match: - company: - !bson_regex '^MongoDB' - - - $match: - company: - $eq: - !bson_regex '^MongoDB' + - name: Equals a Specified Value + link: https://www.mongodb.com/docs/manual/reference/operator/query/eq/#equals-a-specified-value + pipeline: + - $match: + qty: + $eq: 20 + schema: + inventory: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: Document + fields: + name: + types: + - bsonType: String + code: + types: + - bsonType: String + qty: + types: + - bsonType: Number + tags: + types: + - bsonType: Array + types: + - bsonType: String + - bsonType: Array + types: + - bsonType: String + - name: Field in Embedded Document Equals a Value + link: https://www.mongodb.com/docs/manual/reference/operator/query/eq/#field-in-embedded-document-equals-a-value + pipeline: + - $match: + item.name: + $eq: ab + schema: + inventory: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: Document + fields: + name: + types: + - bsonType: String + code: + types: + - bsonType: String + qty: + types: + - bsonType: Number + tags: + types: + - bsonType: Array + types: + - bsonType: String + - bsonType: Array + types: + - bsonType: String + - name: Equals an Array Value + link: https://www.mongodb.com/docs/manual/reference/operator/query/eq/#equals-an-array-value + pipeline: + - $match: + tags: + $eq: + - A + - B + schema: + inventory: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: Document + fields: + name: + types: + - bsonType: String + code: + types: + - bsonType: String + qty: + types: + - bsonType: Number + tags: + types: + - bsonType: Array + types: + - bsonType: String + - bsonType: Array + types: + - bsonType: String + - name: Regex Match Behaviour + link: https://www.mongodb.com/docs/manual/reference/operator/query/eq/#regex-match-behaviour + pipeline: + - $match: + company: MongoDB + - $match: + company: + $eq: MongoDB + - $match: + company: !bson_regex ^MongoDB + - $match: + company: + $eq: !bson_regex ^MongoDB + schema: + companies: + _id: + types: + - bsonType: Int32 + company: + types: + - bsonType: String diff --git a/generator/config/query/exists.yaml b/generator/config/query/exists.yaml index 00d7ce2cb..ff5997fde 100644 --- a/generator/config/query/exists.yaml +++ b/generator/config/query/exists.yaml @@ -1,39 +1,52 @@ # $schema: ../schema.json name: $exists -link: 'https://www.mongodb.com/docs/manual/reference/operator/query/exists/' +link: https://www.mongodb.com/docs/manual/reference/operator/query/exists/ type: - fieldQuery encode: single description: | Matches documents that have the specified field. arguments: - - - name: exists - type: - - bool - default: true + - name: exists + type: + - bool + default: true tests: - - - name: 'Exists and Not Equal To' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/exists/#exists-and-not-equal-to' - pipeline: - - - $match: - qty: - $exists: true - $nin: [5, 15] - - - name: 'Null Values' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/exists/#null-values' - pipeline: - - - $match: - qty: - $exists: true - - - name: 'Missing Field' - pipeline: - - - $match: - qty: - $exists: false + - name: Exists and Not Equal To + link: https://www.mongodb.com/docs/manual/reference/operator/query/exists/#exists-and-not-equal-to + pipeline: + - $match: + qty: + $exists: true + $nin: + - 5 + - 15 + schema: + inventory: &ref_0 + price: + types: + - bsonType: Double + qty: + types: + - bsonType: Int32 + - bsonType: Undefined + quantity: + types: + - bsonType: Int32 + - bsonType: Undefined + sale: + types: + - bsonType: Boolean + tags: + types: + - bsonType: Array + types: + - bsonType: String + - name: Null Values + link: https://www.mongodb.com/docs/manual/reference/operator/query/exists/#null-values + pipeline: + - $match: + qty: + $exists: true + schema: + inventory: *ref_0 diff --git a/generator/config/query/expr.yaml b/generator/config/query/expr.yaml index 320c84507..4484698fe 100644 --- a/generator/config/query/expr.yaml +++ b/generator/config/query/expr.yaml @@ -1,47 +1,69 @@ # $schema: ../schema.json name: $expr -link: 'https://www.mongodb.com/docs/manual/reference/operator/query/expr/' +link: https://www.mongodb.com/docs/manual/reference/operator/query/expr/ type: - query encode: single description: | Allows use of aggregation expressions within the query language. arguments: - - - name: expression - type: - - expression + - name: expression + type: + - expression tests: - - - name: 'Compare Two Fields from A Single Document' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/expr/#compare-two-fields-from-a-single-document' - pipeline: - - - $match: - $expr: - $gt: - - '$spent' - - '$budget' - - - name: 'Using $expr With Conditional Statements' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/expr/#using--expr-with-conditional-statements' - pipeline: - - - $match: - $expr: - $lt: - - - $cond: - if: - $gte: - - '$qty' - - 100 - then: - $multiply: - - '$price' - - 0.5 - else: - $multiply: - - '$price' - - 0.75 - - 5 + - name: Compare Two Fields from A Single Document + link: https://www.mongodb.com/docs/manual/reference/operator/query/expr/#compare-two-fields-from-a-single-document + pipeline: + - $match: + $expr: + $gt: + - $spent + - $budget + schema: + monthlyBudget: + _id: + types: + - bsonType: Number + category: + types: + - bsonType: String + budget: + types: + - bsonType: Number + spent: + types: + - bsonType: Number + - name: Using $expr With Conditional Statements + link: https://www.mongodb.com/docs/manual/reference/operator/query/expr/#use--expr-with-conditional-statements + pipeline: + - $match: + $expr: + $lt: + - $cond: + if: + $gte: + - $qty + - 100 + then: + $multiply: + - $price + - 0.5 + else: + $multiply: + - $price + - 0.75 + - 5 + schema: + supplies: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + qty: + types: + - bsonType: Int32 + price: + types: + - bsonType: Decimal128 diff --git a/generator/config/query/geoIntersects.yaml b/generator/config/query/geoIntersects.yaml index 4df3a43de..01adb3226 100644 --- a/generator/config/query/geoIntersects.yaml +++ b/generator/config/query/geoIntersects.yaml @@ -1,53 +1,76 @@ # $schema: ../schema.json name: $geoIntersects -link: 'https://www.mongodb.com/docs/manual/reference/operator/query/geoIntersects/' +link: https://www.mongodb.com/docs/manual/reference/operator/query/geoIntersects/ type: - fieldQuery encode: object description: | Selects geometries that intersect with a GeoJSON geometry. The 2dsphere index supports $geoIntersects. arguments: - - - name: geometry - mergeObject: true - type: - - geometry + - name: geometry + mergeObject: true + type: + - geometry tests: - - - name: 'Intersects a Polygon' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/geoIntersects/#intersects-a-polygon' - pipeline: - - - $match: - loc: - $geoIntersects: - $geometry: - type: 'Polygon' - coordinates: - - - - [ 0, 0 ] - - [ 3, 6 ] - - [ 6, 1 ] - - [ 0, 0 ] - - - name: 'Intersects a Big Polygon' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/geoIntersects/#intersects-a--big--polygon' - 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' + - name: Intersects a Polygon + link: https://www.mongodb.com/docs/manual/reference/operator/query/geoIntersects/#intersects-a-polygon + pipeline: + - $match: + loc: + $geoIntersects: + $geometry: + type: Polygon + coordinates: + - - - 0 + - 0 + - - 3 + - 6 + - - 6 + - 1 + - - 0 + - 0 + schema: + places: &ref_0 + loc: + types: + - bsonType: Document + fields: + type: + types: + - bsonType: String + coordinates: + types: + - bsonType: Array + types: + - bsonType: Array + types: + - bsonType: Array + types: + - bsonType: Double + - name: Intersects a Big Polygon + link: https://www.mongodb.com/docs/manual/reference/operator/query/geoIntersects/#intersects-a--big--polygon + 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 + schema: + places: *ref_0 diff --git a/generator/config/query/geoWithin.yaml b/generator/config/query/geoWithin.yaml index f9f6204d0..8363e5612 100644 --- a/generator/config/query/geoWithin.yaml +++ b/generator/config/query/geoWithin.yaml @@ -1,53 +1,76 @@ # $schema: ../schema.json name: $geoWithin -link: 'https://www.mongodb.com/docs/manual/reference/operator/query/geoWithin/' +link: https://www.mongodb.com/docs/manual/reference/operator/query/geoWithin/ type: - fieldQuery encode: object description: | Selects geometries within a bounding GeoJSON geometry. The 2dsphere and 2d indexes support $geoWithin. arguments: - - - name: geometry - mergeObject: true - type: - - geometry + - name: geometry + mergeObject: true + type: + - geometry tests: - - - name: 'Within a Polygon' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/geoWithin/#within-a-polygon' - pipeline: - - - $match: - loc: - $geoWithin: - $geometry: - type: 'Polygon' - coordinates: - - - - [ 0, 0 ] - - [ 3, 6 ] - - [ 6, 1 ] - - [ 0, 0 ] - - - name: 'Within a Big Polygon' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/geoWithin/#within-a--big--polygon' - 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' + - name: Within a Polygon + link: https://www.mongodb.com/docs/manual/reference/operator/query/geoWithin/#within-a-polygon + pipeline: + - $match: + loc: + $geoWithin: + $geometry: + type: Polygon + coordinates: + - - - 0 + - 0 + - - 3 + - 6 + - - 6 + - 1 + - - 0 + - 0 + schema: + places: &ref_0 + loc: + types: + - bsonType: Document + fields: + type: + types: + - bsonType: String + coordinates: + types: + - bsonType: Array + types: + - bsonType: Array + types: + - bsonType: Array + types: + - bsonType: Double + - name: Within a Big Polygon + link: https://www.mongodb.com/docs/manual/reference/operator/query/geoWithin/#within-a--big--polygon + 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 + schema: + places: *ref_0 diff --git a/generator/config/query/geometry.yaml b/generator/config/query/geometry.yaml index 40b18dc99..90190f3cc 100644 --- a/generator/config/query/geometry.yaml +++ b/generator/config/query/geometry.yaml @@ -1,22 +1,19 @@ # $schema: ../schema.json name: $geometry -link: 'https://www.mongodb.com/docs/manual/reference/operator/query/geometry/' +link: https://www.mongodb.com/docs/manual/reference/operator/query/geometry/ type: - geometry encode: object description: | Specifies a geometry in GeoJSON format to geospatial query operators. arguments: - - - name: type - type: - - string - - - name: coordinates - type: - - array - - - name: crs - type: - - object - optional: true + - name: type + type: + - string + - name: coordinates + type: + - array + - name: crs + type: + - object + optional: true diff --git a/generator/config/query/gt.yaml b/generator/config/query/gt.yaml index 9914a5f34..147d2d57c 100644 --- a/generator/config/query/gt.yaml +++ b/generator/config/query/gt.yaml @@ -1,22 +1,37 @@ # $schema: ../schema.json name: $gt -link: 'https://www.mongodb.com/docs/manual/reference/operator/query/gt/' +link: https://www.mongodb.com/docs/manual/reference/operator/query/gt/ type: - fieldQuery encode: single description: | Matches values that are greater than a specified value. arguments: - - - name: value - type: - - any + - name: value + type: + - any tests: - - - name: 'Match Document Fields' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/gt/#match-document-fields' - pipeline: - - - $match: - qty: - $gt: 20 + - name: Match Document Fields + link: https://www.mongodb.com/docs/manual/reference/operator/query/gt/#match-document-fields + pipeline: + - $match: + quantity: + $gt: 20 + schema: + inventory: + item: + types: + - bsonType: String + quantity: + types: + - bsonType: Number + carrier: + types: + - bsonType: Document + fields: + name: + types: + - bsonType: String + fee: + types: + - bsonType: Number diff --git a/generator/config/query/gte.yaml b/generator/config/query/gte.yaml index d8617a7c6..3b8e421bd 100644 --- a/generator/config/query/gte.yaml +++ b/generator/config/query/gte.yaml @@ -1,22 +1,37 @@ # $schema: ../schema.json name: $gte -link: 'https://www.mongodb.com/docs/manual/reference/operator/query/gte/' +link: https://www.mongodb.com/docs/manual/reference/operator/query/gte/ type: - fieldQuery encode: single description: | Matches values that are greater than or equal to a specified value. arguments: - - - name: value - type: - - any + - name: value + type: + - any tests: - - - name: 'Match Document Fields' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/gte/#match-document-fields' - pipeline: - - - $match: - qty: - $gte: 20 + - name: Match Document Fields + link: https://www.mongodb.com/docs/manual/reference/operator/query/gte/#match-document-fields + pipeline: + - $match: + quantity: + $gte: 20 + schema: + inventory: + item: + types: + - bsonType: String + quantity: + types: + - bsonType: Number + carrier: + types: + - bsonType: Document + fields: + name: + types: + - bsonType: String + fee: + types: + - bsonType: Number diff --git a/generator/config/query/in.yaml b/generator/config/query/in.yaml index 67f069416..59539de62 100644 --- a/generator/config/query/in.yaml +++ b/generator/config/query/in.yaml @@ -1,32 +1,55 @@ # $schema: ../schema.json name: $in -link: 'https://www.mongodb.com/docs/manual/reference/operator/query/in/' +link: https://www.mongodb.com/docs/manual/reference/operator/query/in/ type: - fieldQuery encode: single description: | Matches any of the values specified in an array. arguments: - - - name: value - type: - - array # of expression + - name: value + type: + - array tests: - - - name: 'Use the $in Operator to Match Values in an Array' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/in/#use-the--in-operator-to-match-values' - pipeline: - - - $match: - tags: - $in: ['home', 'school'] - - - name: 'Use the $in Operator with a Regular Expression' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/in/#use-the--in-operator-with-a-regular-expression' - pipeline: - - - $match: - tags: - $in: - - !bson_regex '^be' - - !bson_regex '^st' + - name: Use the $in Operator to Match Values in an Array + link: https://www.mongodb.com/docs/manual/reference/operator/query/in/#use-the--in-operator-to-match-values + pipeline: + - $match: + tags: + $in: + - home + - school + schema: + inventory: + item: + types: + - bsonType: String + quantity: + types: + - bsonType: Number + tags: + types: + - bsonType: Array + types: + - bsonType: String + - name: Use the $in Operator with a Regular Expression + link: https://www.mongodb.com/docs/manual/reference/operator/query/in/#use-the--in-operator-with-a-regular-expression + pipeline: + - $match: + tags: + $in: + - !bson_regex ^be + - !bson_regex ^st + schema: + inventory: + item: + types: + - bsonType: String + quantity: + types: + - bsonType: Number + tags: + types: + - bsonType: Array + types: + - bsonType: String diff --git a/generator/config/query/jsonSchema.yaml b/generator/config/query/jsonSchema.yaml index 4c1dca6ad..645381318 100644 --- a/generator/config/query/jsonSchema.yaml +++ b/generator/config/query/jsonSchema.yaml @@ -1,39 +1,57 @@ # $schema: ../schema.json name: $jsonSchema -link: 'https://www.mongodb.com/docs/manual/reference/operator/query/jsonSchema/' +link: https://www.mongodb.com/docs/manual/reference/operator/query/jsonSchema/ type: - query encode: single description: | Validate documents against the given JSON Schema. arguments: - - - name: schema - type: - - object + - name: schema + type: + - object tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/jsonSchema/#syntax' - 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' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/query/jsonSchema/#syntax + 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 + schema: + TestCollection: + name: + types: + - bsonType: String + major: + types: + - bsonType: String + gpa: + types: + - bsonType: Double + address: + types: + - bsonType: Document + fields: + street: + types: + - bsonType: String + zipcode: + types: + - bsonType: String diff --git a/generator/config/query/lt.yaml b/generator/config/query/lt.yaml index f1c996ded..c9e6c264c 100644 --- a/generator/config/query/lt.yaml +++ b/generator/config/query/lt.yaml @@ -1,22 +1,37 @@ # $schema: ../schema.json name: $lt -link: 'https://www.mongodb.com/docs/manual/reference/operator/query/lt/' +link: https://www.mongodb.com/docs/manual/reference/operator/query/lt/ type: - fieldQuery encode: single description: | Matches values that are less than a specified value. arguments: - - - name: value - type: - - any + - name: value + type: + - any tests: - - - name: 'Match Document Fields' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/lt/#match-document-fields' - pipeline: - - - $match: - qty: - $lt: 20 + - name: Match Document Fields + link: https://www.mongodb.com/docs/manual/reference/operator/query/lt/#match-document-fields + pipeline: + - $match: + quantity: + $lt: 20 + schema: + inventory: + item: + types: + - bsonType: String + quantity: + types: + - bsonType: Number + carrier: + types: + - bsonType: Document + fields: + name: + types: + - bsonType: String + fee: + types: + - bsonType: Number diff --git a/generator/config/query/lte.yaml b/generator/config/query/lte.yaml index e61d01b03..b39775396 100644 --- a/generator/config/query/lte.yaml +++ b/generator/config/query/lte.yaml @@ -1,22 +1,37 @@ # $schema: ../schema.json name: $lte -link: 'https://www.mongodb.com/docs/manual/reference/operator/query/lte/' +link: https://www.mongodb.com/docs/manual/reference/operator/query/lte/ type: - fieldQuery encode: single description: | Matches values that are less than or equal to a specified value. arguments: - - - name: value - type: - - any + - name: value + type: + - any tests: - - - name: 'Match Document Fields' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/lte/#match-document-fields' - pipeline: - - - $match: - qty: - $lte: 20 + - name: Match Document Fields + link: https://www.mongodb.com/docs/manual/reference/operator/query/lte/#match-document-fields + pipeline: + - $match: + quantity: + $lte: 20 + schema: + inventory: + item: + types: + - bsonType: String + quantity: + types: + - bsonType: Number + carrier: + types: + - bsonType: Document + fields: + name: + types: + - bsonType: String + fee: + types: + - bsonType: Number diff --git a/generator/config/query/maxDistance.yaml b/generator/config/query/maxDistance.yaml index e95212d23..ea89d03ef 100644 --- a/generator/config/query/maxDistance.yaml +++ b/generator/config/query/maxDistance.yaml @@ -1,13 +1,12 @@ # $schema: ../schema.json name: $maxDistance -link: 'https://www.mongodb.com/docs/manual/reference/operator/query/maxDistance/' +link: https://www.mongodb.com/docs/manual/reference/operator/query/maxDistance/ type: - fieldQuery encode: single description: | Specifies a maximum distance to limit the results of $near and $nearSphere queries. The 2dsphere and 2d indexes support $maxDistance. arguments: - - - name: value - type: - - number + - name: value + type: + - number diff --git a/generator/config/query/minDistance.yaml b/generator/config/query/minDistance.yaml index fd467a96f..f4605cfb7 100644 --- a/generator/config/query/minDistance.yaml +++ b/generator/config/query/minDistance.yaml @@ -1,14 +1,13 @@ # $schema: ../schema.json name: $minDistance -link: 'https://www.mongodb.com/docs/manual/reference/operator/query/minDistance/' +link: https://www.mongodb.com/docs/manual/reference/operator/query/minDistance/ type: - fieldQuery encode: single description: | Specifies a minimum distance to limit the results of $near and $nearSphere queries. For use with 2dsphere index only. arguments: - - - name: value - type: - - int - - double + - name: value + type: + - int + - double diff --git a/generator/config/query/mod.yaml b/generator/config/query/mod.yaml index 04a187253..9199c11e5 100644 --- a/generator/config/query/mod.yaml +++ b/generator/config/query/mod.yaml @@ -1,42 +1,64 @@ # $schema: ../schema.json name: $mod -link: 'https://www.mongodb.com/docs/manual/reference/operator/query/mod/' +link: https://www.mongodb.com/docs/manual/reference/operator/query/mod/ type: - fieldQuery encode: array description: | Performs a modulo operation on the value of a field and selects documents with a specified result. arguments: - - - name: divisor - type: - - number - - - name: remainder - type: - - number + - name: divisor + type: + - number + - name: remainder + type: + - number tests: - - - name: 'Use $mod to Select Documents' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/mod/#use--mod-to-select-documents' - pipeline: - - - $match: - qty: - $mod: [4, 0] - - - name: 'Floating Point Arguments' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/mod/#floating-point-arguments' - pipeline: - - - $match: - qty: - $mod: [4.0, 0] - - - $match: - qty: - $mod: [4.5, 0] - - - $match: - qty: - $mod: [4.99, 0] + - name: Use $mod to Select Documents + link: https://www.mongodb.com/docs/manual/reference/operator/query/mod/#use--mod-to-select-documents + pipeline: + - $match: + qty: + $mod: + - 4 + - 0 + schema: + inventory: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + qty: + types: + - bsonType: Number + - name: Floating Point Arguments + link: https://www.mongodb.com/docs/manual/reference/operator/query/mod/#floating-point-arguments + pipeline: + - $match: + qty: + $mod: + - 4 + - 0 + - $match: + qty: + $mod: + - 4.5 + - 0 + - $match: + qty: + $mod: + - 4.99 + - 0 + schema: + inventory: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + qty: + types: + - bsonType: Number diff --git a/generator/config/query/ne.yaml b/generator/config/query/ne.yaml index a1f5a046b..f997c8931 100644 --- a/generator/config/query/ne.yaml +++ b/generator/config/query/ne.yaml @@ -1,22 +1,37 @@ # $schema: ../schema.json name: $ne -link: 'https://www.mongodb.com/docs/manual/reference/operator/query/ne/' +link: https://www.mongodb.com/docs/manual/reference/operator/query/ne/ type: - fieldQuery encode: single description: | Matches all values that are not equal to a specified value. arguments: - - - name: value - type: - - any + - name: value + type: + - any tests: - - - name: 'Match Document Fields' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/ne/#match-document-fields' - pipeline: - - - $match: - quantity: - $ne: 20 + - name: Match Document Fields + link: https://www.mongodb.com/docs/manual/reference/operator/query/ne/#match-document-fields-that-are-not-equal + pipeline: + - $match: + quantity: + $ne: 20 + schema: + inventory: + item: + types: + - bsonType: String + quantity: + types: + - bsonType: Number + carrier: + types: + - bsonType: Document + fields: + name: + types: + - bsonType: String + fee: + types: + - bsonType: Number diff --git a/generator/config/query/near.yaml b/generator/config/query/near.yaml index 89d7f511f..5749e12ea 100644 --- a/generator/config/query/near.yaml +++ b/generator/config/query/near.yaml @@ -1,44 +1,53 @@ # $schema: ../schema.json name: $near -link: 'https://www.mongodb.com/docs/manual/reference/operator/query/near/' +link: https://www.mongodb.com/docs/manual/reference/operator/query/near/ type: - fieldQuery encode: object description: | Returns geospatial objects in proximity to a point. Requires a geospatial index. The 2dsphere and 2d indexes support $near. arguments: - - - name: geometry - mergeObject: true - type: - - geometry - - - name: $maxDistance - type: - - number - optional: true - description: | - Distance in meters. Limits the results to those documents that are at most the specified distance from the center point. - - - name: $minDistance - type: - - number - optional: true - description: | - Distance in meters. Limits the results to those documents that are at least the specified distance from the center point. + - name: geometry + mergeObject: true + type: + - geometry + - name: $maxDistance + type: + - number + optional: true + description: | + Distance in meters. Limits the results to those documents that are at most the specified distance from the center point. + - name: $minDistance + type: + - number + optional: true + description: | + Distance in meters. Limits the results to those documents that are at least the specified distance from the center point. tests: - - - name: 'Query on GeoJSON Data' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/near/#query-on-geojson-data' - pipeline: - - - $match: - location: - $near: - $geometry: - type: 'Point' - coordinates: - - -73.9667 - - 40.78 - $minDistance: 1000 - $maxDistance: 5000 + - name: Query on GeoJSON Data + link: https://www.mongodb.com/docs/manual/reference/operator/query/near/#query-on-geojson-data + pipeline: + - $match: + location: + $near: + $geometry: + type: Point + coordinates: + - -73.9667 + - 40.78 + $minDistance: 1000 + $maxDistance: 5000 + schema: + places: + location: + types: + - bsonType: Document + fields: + type: + types: + - bsonType: String + coordinates: + types: + - bsonType: Array + types: + - bsonType: Double diff --git a/generator/config/query/nearSphere.yaml b/generator/config/query/nearSphere.yaml index 72e8e18e9..82607bad6 100644 --- a/generator/config/query/nearSphere.yaml +++ b/generator/config/query/nearSphere.yaml @@ -1,42 +1,53 @@ # $schema: ../schema.json name: $nearSphere -link: 'https://www.mongodb.com/docs/manual/reference/operator/query/nearSphere/' +link: https://www.mongodb.com/docs/manual/reference/operator/query/nearSphere/ type: - fieldQuery encode: object description: | Returns geospatial objects in proximity to a point on a sphere. Requires a geospatial index. The 2dsphere and 2d indexes support $nearSphere. arguments: - - - name: geometry - mergeObject: true - type: - - geometry - - - name: $maxDistance - type: - - number - optional: true - description: | - Distance in meters. - - - name: $minDistance - type: - - number - optional: true - description: | - Distance in meters. Limits the results to those documents that are at least the specified distance from the center point. + - name: geometry + mergeObject: true + type: + - geometry + - name: $maxDistance + type: + - number + optional: true + description: | + Distance in meters. + - name: $minDistance + type: + - number + optional: true + description: | + Distance in meters. Limits the results to those documents that are at least the specified distance from the center point. tests: - - - name: 'Specify Center Point Using GeoJSON' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/nearSphere/#specify-center-point-using-geojson' - pipeline: - - - $match: - location: - $nearSphere: - $geometry: - type: 'Point' - coordinates: [-73.9667, 40.78] - $minDistance: 1000 - $maxDistance: 5000 + - name: Specify Center Point Using GeoJSON + link: https://www.mongodb.com/docs/manual/reference/operator/query/nearSphere/#specify-center-point-using-geojson + pipeline: + - $match: + location: + $nearSphere: + $geometry: + type: Point + coordinates: + - -73.9667 + - 40.78 + $minDistance: 1000 + $maxDistance: 5000 + schema: + places: + location: + types: + - bsonType: Document + fields: + type: + types: + - bsonType: String + coordinates: + types: + - bsonType: Array + types: + - bsonType: Double diff --git a/generator/config/query/nin.yaml b/generator/config/query/nin.yaml index 4285e4fe7..5eb818699 100644 --- a/generator/config/query/nin.yaml +++ b/generator/config/query/nin.yaml @@ -1,30 +1,54 @@ # $schema: ../schema.json name: $nin -link: 'https://www.mongodb.com/docs/manual/reference/operator/query/nin/' +link: https://www.mongodb.com/docs/manual/reference/operator/query/nin/ type: - fieldQuery encode: single description: | Matches none of the values specified in an array. arguments: - - - name: value - type: - - array # of expression + - name: value + type: + - array tests: - - - name: 'Select on Unmatching Documents' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/nin/#select-on-unmatching-documents' - pipeline: - - - $match: - quantity: - $nin: [5, 15] - - - name: 'Select on Elements Not in an Array' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/nin/#select-on-elements-not-in-an-array' - pipeline: - - - $match: - tags: - $nin: ['school'] + - name: Select on Unmatching Documents + link: https://www.mongodb.com/docs/manual/reference/operator/query/nin/#select-on-unmatching-documents + pipeline: + - $match: + quantity: + $nin: + - 5 + - 15 + schema: + inventory: + item: + types: + - bsonType: String + quantity: + types: + - bsonType: Number + tags: + types: + - bsonType: Array + types: + - bsonType: String + - name: Select on Elements Not in an Array + link: https://www.mongodb.com/docs/manual/reference/operator/query/nin/#select-on-elements-not-in-an-array + pipeline: + - $match: + tags: + $nin: + - school + schema: + inventory: + item: + types: + - bsonType: String + quantity: + types: + - bsonType: Number + tags: + types: + - bsonType: Array + types: + - bsonType: String diff --git a/generator/config/query/nor.yaml b/generator/config/query/nor.yaml index d1ad7159a..a609e6431 100644 --- a/generator/config/query/nor.yaml +++ b/generator/config/query/nor.yaml @@ -1,58 +1,67 @@ # $schema: ../schema.json name: $nor -link: 'https://www.mongodb.com/docs/manual/reference/operator/query/nor/' +link: https://www.mongodb.com/docs/manual/reference/operator/query/nor/ type: - query encode: single description: | Joins query clauses with a logical NOR returns all documents that fail to match both clauses. arguments: - - - name: queries - type: - - query - variadic: array - variadicMin: 1 + - name: queries + type: + - query + variadic: array + variadicMin: 1 tests: - - - name: 'Query with Two Expressions' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/nor/#-nor-query-with-two-expressions' - pipeline: - - - $match: - $nor: - - - price: 1.99 - - - sale: true - - - name: 'Additional Comparisons' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/nor/#-nor-and-additional-comparisons' - pipeline: - - - $match: - $nor: - - - price: 1.99 - - - qty: - $lt: 20 - - - sale: true - - - name: '$nor and $exists' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/nor/#-nor-and--exists' - pipeline: - - - $match: - $nor: - - - price: 1.99 - - - price: - $exists: false - - - sale: true - - - sale: - $exists: false + - name: Query with Two Expressions + link: https://www.mongodb.com/docs/manual/reference/operator/query/nor/#-nor-query-with-two-expressions + pipeline: + - $match: + $nor: + - price: 1.99 + - sale: true + schema: + inventory: &ref_0 + price: + types: + - bsonType: Double + qty: + types: + - bsonType: Int32 + - bsonType: Undefined + quantity: + types: + - bsonType: Int32 + - bsonType: Undefined + sale: + types: + - bsonType: Boolean + tags: + types: + - bsonType: Array + types: + - bsonType: String + - name: Additional Comparisons + link: https://www.mongodb.com/docs/manual/reference/operator/query/nor/#-nor-and-additional-comparisons + pipeline: + - $match: + $nor: + - price: 1.99 + - qty: + $lt: 20 + - sale: true + schema: + inventory: *ref_0 + - name: $nor and $exists + link: https://www.mongodb.com/docs/manual/reference/operator/query/nor/#-nor-and--exists + pipeline: + - $match: + $nor: + - price: 1.99 + - price: + $exists: false + - sale: true + - sale: + $exists: false + schema: + inventory: *ref_0 diff --git a/generator/config/query/not.yaml b/generator/config/query/not.yaml index eb2b43cdb..a4b98f920 100644 --- a/generator/config/query/not.yaml +++ b/generator/config/query/not.yaml @@ -1,31 +1,49 @@ # $schema: ../schema.json name: $not -link: 'https://www.mongodb.com/docs/manual/reference/operator/query/not/' +link: https://www.mongodb.com/docs/manual/reference/operator/query/not/ type: - fieldQuery encode: single description: | Inverts the effect of a query expression and returns documents that do not match the query expression. arguments: - - - name: expression - type: - - fieldQuery + - name: expression + type: + - fieldQuery tests: - - - name: 'Syntax' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/not/#syntax' - pipeline: - - - $match: - price: - $not: - $gt: 1.99 - - - name: 'Regular Expressions' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/not/#-not-and-regular-expressions' - pipeline: - - - $match: - price: - $not: !bson_regex '^p.*' + - name: Syntax + link: https://www.mongodb.com/docs/manual/reference/operator/query/not/#syntax + pipeline: + - $match: + price: + $not: + $gt: 1.99 + schema: + inventory: &ref_0 + price: + types: + - bsonType: Double + qty: + types: + - bsonType: Int32 + - bsonType: Undefined + quantity: + types: + - bsonType: Int32 + - bsonType: Undefined + sale: + types: + - bsonType: Boolean + tags: + types: + - bsonType: Array + types: + - bsonType: String + - name: Regular Expressions + link: https://www.mongodb.com/docs/manual/reference/operator/query/not/#regular-expressions + pipeline: + - $match: + price: + $not: !bson_regex ^p.* + schema: + inventory: *ref_0 diff --git a/generator/config/query/or.yaml b/generator/config/query/or.yaml index ce2b7603c..25fc4038b 100644 --- a/generator/config/query/or.yaml +++ b/generator/config/query/or.yaml @@ -1,47 +1,62 @@ # $schema: ../schema.json name: $or -link: 'https://www.mongodb.com/docs/manual/reference/operator/query/or/' +link: https://www.mongodb.com/docs/manual/reference/operator/query/or/ type: - query encode: single description: | Joins query clauses with a logical OR returns all documents that match the conditions of either clause. arguments: - - - name: queries - type: - - query - variadic: array - variadicMin: 1 + - name: queries + type: + - query + variadic: array + variadicMin: 1 tests: - - - name: '$or Clauses' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/or/#-or-clauses-and-indexes' - pipeline: - - - $match: - $or: - - - quantity: - $lt: 20 - - - price: 10 - - - - name: 'Error Handling' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/or/#error-handling' - pipeline: - - - $match: - $or: - - - x: - $eq: 0 - - - $expr: - $eq: - - - $divide: - - 1 - - '$x' - - 3 + - name: $or Clauses + link: https://www.mongodb.com/docs/manual/reference/operator/query/or/#-or-clauses-and-indexes + pipeline: + - $match: + $or: + - quantity: + $lt: 20 + - price: 10 + schema: + inventory: + price: + types: + - bsonType: Double + qty: + types: + - bsonType: Int32 + - bsonType: Undefined + quantity: + types: + - bsonType: Int32 + - bsonType: Undefined + sale: + types: + - bsonType: Boolean + tags: + types: + - bsonType: Array + types: + - bsonType: String + - name: Error Handling + link: https://www.mongodb.com/docs/manual/reference/operator/query/or/#error-handling + pipeline: + - $match: + $or: + - x: + $eq: 0 + - $expr: + $eq: + - $divide: + - 1 + - $x + - 3 + schema: + example: + x: + types: + - bsonType: Int32 diff --git a/generator/config/query/polygon.yaml b/generator/config/query/polygon.yaml index 1a46f2bc4..c74fbf1d9 100644 --- a/generator/config/query/polygon.yaml +++ b/generator/config/query/polygon.yaml @@ -1,13 +1,12 @@ # $schema: ../schema.json name: $polygon -link: 'https://www.mongodb.com/docs/manual/reference/operator/query/polygon/' +link: https://www.mongodb.com/docs/manual/reference/operator/query/polygon/ type: - geometry encode: single description: | Specifies a polygon to using legacy coordinate pairs for $geoWithin queries. The 2d index supports $center. arguments: - - - name: points - type: - - array + - name: points + type: + - array diff --git a/generator/config/query/rand.yaml b/generator/config/query/rand.yaml index 6773ae0d5..7674f411f 100644 --- a/generator/config/query/rand.yaml +++ b/generator/config/query/rand.yaml @@ -1,26 +1,36 @@ # $schema: ../schema.json name: $rand -link: 'https://www.mongodb.com/docs/manual/reference/operator/query/rand/' +link: https://www.mongodb.com/docs/manual/reference/operator/query/rand/ type: - resolvesToDouble encode: object description: | Generates a random float between 0 and 1. tests: - - - name: 'Select Random Items From a Collection' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/rand/#select-random-items-from-a-collection' - pipeline: - - - $match: - district: 3 - $expr: - $lt: - - 0.5 - - - $rand: {} - - - $project: - _id: 0 - name: 1 - registered: 1 + - name: Select Random Items From a Collection + link: https://www.mongodb.com/docs/manual/reference/operator/query/rand/#select-random-items-from-a-collection + pipeline: + - $match: + district: 3 + $expr: + $lt: + - 0.5 + - $rand: {} + - $project: + _id: 0 + name: 1 + registered: 1 + schema: + voters: + name: + types: + - bsonType: String + voterId: + types: + - bsonType: Number + district: + types: + - bsonType: Number + registered: + types: + - bsonType: Boolean diff --git a/generator/config/query/regex.yaml b/generator/config/query/regex.yaml index c7e378ddd..de91f521d 100644 --- a/generator/config/query/regex.yaml +++ b/generator/config/query/regex.yaml @@ -1,33 +1,49 @@ # $schema: ../schema.json name: $regex -link: 'https://www.mongodb.com/docs/manual/reference/operator/query/regex/' +link: https://www.mongodb.com/docs/manual/reference/operator/query/regex/ type: - fieldQuery encode: single description: | Selects documents where values match a specified regular expression. arguments: - - - name: regex - type: - - regex - + - name: regex + type: + - regex tests: - - - name: 'Perform a LIKE Match' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/regex/#perform-a-like-match' - pipeline: - - - $match: - sku: - $regex: - !bson_regex '789$' - - - name: 'Perform Case-Insensitive Regular Expression Match' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/regex/#perform-case-insensitive-regular-expression-match' - pipeline: - - - $match: - sku: - $regex: - !bson_regex ['^ABC', 'i'] + - name: Perform a LIKE Match + link: https://www.mongodb.com/docs/manual/reference/operator/query/regex/#perform-a-like-match + pipeline: + - $match: + sku: + $regex: !bson_regex 789$ + schema: + products: + _id: + types: + - bsonType: Number + sku: + types: + - bsonType: String + description: + types: + - bsonType: String + - name: Perform Case-Insensitive Regular Expression Match + link: https://www.mongodb.com/docs/manual/reference/operator/query/regex/#perform-case-insensitive-regular-expression-match + pipeline: + - $match: + sku: + $regex: !bson_regex + - ^ABC + - i + schema: + products: + _id: + types: + - bsonType: Number + sku: + types: + - bsonType: String + description: + types: + - bsonType: String diff --git a/generator/config/query/sampleRate.yaml b/generator/config/query/sampleRate.yaml index 9995e2d8b..950b9217c 100644 --- a/generator/config/query/sampleRate.yaml +++ b/generator/config/query/sampleRate.yaml @@ -1,26 +1,27 @@ # $schema: ../schema.json name: $sampleRate -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/sampleRate/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/sampleRate/ type: - query encode: single description: | 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. arguments: - - - name: rate - type: - - resolvesToDouble - description: | - The selection process uses a uniform random distribution. The sample rate is a floating point number between 0 and 1, inclusive, which represents the probability that a given document will be selected as it passes through the pipeline. - For example, a sample rate of 0.33 selects roughly one document in three. + - name: rate + type: + - resolvesToDouble + description: | + The selection process uses a uniform random distribution. The sample rate is a floating point number between 0 and 1, inclusive, which represents the probability that a given document will be selected as it passes through the pipeline. + For example, a sample rate of 0.33 selects roughly one document in three. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/sampleRate/#examples' - pipeline: - - - $match: - $sampleRate: 0.33 - - - $count: 'numMatches' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/sampleRate/#examples + pipeline: + - $match: + $sampleRate: 0.33 + - $count: numMatches + schema: + TestCollection: + _id: + types: + - bsonType: ObjectId diff --git a/generator/config/query/size.yaml b/generator/config/query/size.yaml index 629de4035..237f0e535 100644 --- a/generator/config/query/size.yaml +++ b/generator/config/query/size.yaml @@ -1,22 +1,40 @@ # $schema: ../schema.json name: $size -link: 'https://www.mongodb.com/docs/manual/reference/operator/query/size/' +link: https://www.mongodb.com/docs/manual/reference/operator/query/size/ type: - fieldQuery encode: single description: | Selects documents if the array field is a specified size. arguments: - - - name: value - type: - - int + - name: value + type: + - int tests: - - - name: 'Query an Array by Array Length' - link: 'https://www.mongodb.com/docs/manual/tutorial/query-arrays/#query-an-array-by-array-length' - pipeline: - - - $match: - tags: - $size: 3 + - name: Query an Array by Array Length + link: https://www.mongodb.com/docs/manual/tutorial/query-arrays/#query-an-array-by-array-length + pipeline: + - $match: + tags: + $size: 3 + schema: + inventory: + price: + types: + - bsonType: Double + qty: + types: + - bsonType: Int32 + - bsonType: Undefined + quantity: + types: + - bsonType: Int32 + - bsonType: Undefined + sale: + types: + - bsonType: Boolean + tags: + types: + - bsonType: Array + types: + - bsonType: String diff --git a/generator/config/query/text.yaml b/generator/config/query/text.yaml index 574ee4508..bae9d6c20 100644 --- a/generator/config/query/text.yaml +++ b/generator/config/query/text.yaml @@ -1,114 +1,170 @@ # $schema: ../schema.json name: $text -link: 'https://www.mongodb.com/docs/manual/reference/operator/query/text/' +link: https://www.mongodb.com/docs/manual/reference/operator/query/text/ type: - query encode: object description: | Performs text search. arguments: - - - name: $search - type: - - string - description: | - A string of terms that MongoDB parses and uses to query the text index. MongoDB performs a logical OR search of the terms unless specified as a phrase. - - - name: $language - type: - - string - optional: true - description: | - The language that determines the list of stop words for the search and the rules for the stemmer and tokenizer. If not specified, the search uses the default language of the index. - If you specify a default_language value of none, then the text index parses through each word in the field, including stop words, and ignores suffix stemming. - - - name: $caseSensitive - type: - - bool - optional: true - description: | - A boolean flag to enable or disable case sensitive search. Defaults to false; i.e. the search defers to the case insensitivity of the text index. - - - name: $diacriticSensitive - type: - - bool - optional: true - description: | - A boolean flag to enable or disable diacritic sensitive search against version 3 text indexes. Defaults to false; i.e. the search defers to the diacritic insensitivity of the text index. - Text searches against earlier versions of the text index are inherently diacritic sensitive and cannot be diacritic insensitive. As such, the $diacriticSensitive option has no effect with earlier versions of the text index. + - name: $search + type: + - string + description: | + A string of terms that MongoDB parses and uses to query the text index. MongoDB performs a logical OR search of the terms unless specified as a phrase. + - name: $language + type: + - string + optional: true + description: | + The language that determines the list of stop words for the search and the rules for the stemmer and tokenizer. If not specified, the search uses the default language of the index. + If you specify a default_language value of none, then the text index parses through each word in the field, including stop words, and ignores suffix stemming. + - name: $caseSensitive + type: + - bool + optional: true + description: | + A boolean flag to enable or disable case sensitive search. Defaults to false; i.e. the search defers to the case insensitivity of the text index. + - name: $diacriticSensitive + type: + - bool + optional: true + description: | + A boolean flag to enable or disable diacritic sensitive search against version 3 text indexes. Defaults to false; i.e. the search defers to the diacritic insensitivity of the text index. + Text searches against earlier versions of the text index are inherently diacritic sensitive and cannot be diacritic insensitive. As such, the $diacriticSensitive option has no effect with earlier versions of the text index. tests: - - - name: 'Search for a Single Word' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/text/#search-for-a-single-word' - pipeline: - - - $match: - $text: - $search: 'coffee' - - - name: 'Match Any of the Search Terms' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/text/#search-for-a-single-word' - pipeline: - - - $match: - $text: - $search: 'bake coffee cake' - - - name: 'Search a Different Language' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/text/#search-a-different-language' - pipeline: - - - $match: - $text: - $search: 'leche' - $language: 'es' - - - name: 'Case and Diacritic Insensitive Search' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/text/#case-and-diacritic-insensitive-search' - pipeline: - - - $match: - $text: - $search: 'сы́рники CAFÉS' - - - name: 'Perform Case Sensitive Search' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/text/#perform-case-sensitive-search' - pipeline: - - - $match: - $text: - $search: 'Coffee' - $caseSensitive: true - - - $match: - $text: - $search: '\"Café Con Leche\"' - $caseSensitive: true - - - name: 'Diacritic Sensitive Search' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/text/#perform-case-sensitive-search' - pipeline: - - - $match: - $text: - $search: 'CAFÉ' - $diacriticSensitive: true - - - name: 'Text Search Score Examples' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/text/#perform-case-sensitive-search' - pipeline: - - - $match: - $text: - $search: 'CAFÉ' - $diacriticSensitive: true - - - $project: - score: - $meta: 'textScore' - - - $sort: - score: - $meta: 'textScore' - - - $limit: 5 + - name: Search for a Single Word + link: https://www.mongodb.com/docs/manual/reference/operator/query/text/#-text-with-a-single-word + pipeline: + - $match: + $text: + $search: coffee + schema: + articles: + _id: + types: + - bsonType: Number + subject: + types: + - bsonType: String + author: + types: + - bsonType: String + views: + types: + - bsonType: Number + - name: Query a Different Language + link: https://www.mongodb.com/docs/manual/reference/operator/query/text/#query-a-different-language + pipeline: + - $match: + $text: + $search: leche + $language: es + schema: + articles: + _id: + types: + - bsonType: Number + subject: + types: + - bsonType: String + author: + types: + - bsonType: String + views: + types: + - bsonType: Number + - name: Case and Diacritic Insensitive Search + link: https://www.mongodb.com/docs/manual/reference/operator/query/text/#case-and-diacritic-insensitivity + pipeline: + - $match: + $text: + $search: сы́рники CAFÉS + schema: + articles: + _id: + types: + - bsonType: Number + subject: + types: + - bsonType: String + author: + types: + - bsonType: String + views: + types: + - bsonType: Number + - name: Perform Case Sensitive Search + link: https://www.mongodb.com/docs/manual/reference/operator/query/text/#case-sensitivity + pipeline: + - $match: + $text: + $search: Coffee + $caseSensitive: true + - $match: + $text: + $search: \"Café Con Leche\" + $caseSensitive: true + schema: + articles: + _id: + types: + - bsonType: Number + subject: + types: + - bsonType: String + author: + types: + - bsonType: String + views: + types: + - bsonType: Number + - name: Diacritic Sensitive Search + link: https://www.mongodb.com/docs/manual/reference/operator/query/text/#diacritic-sensitivity + pipeline: + - $match: + $text: + $search: CAFÉ + $diacriticSensitive: true + schema: + articles: + _id: + types: + - bsonType: Number + subject: + types: + - bsonType: String + author: + types: + - bsonType: String + views: + types: + - bsonType: Number + - name: Text Search Score Examples + link: https://www.mongodb.com/docs/manual/reference/operator/query/text/#relevance-score-examples + pipeline: + - $match: + $text: + $search: CAFÉ + $diacriticSensitive: true + - $project: + score: + $meta: textScore + - $sort: + score: + $meta: textScore + - $limit: 5 + schema: + articles: + _id: + types: + - bsonType: Number + subject: + types: + - bsonType: String + author: + types: + - bsonType: String + views: + types: + - bsonType: Number diff --git a/generator/config/query/type.yaml b/generator/config/query/type.yaml index d8cd7bc86..43f5c4709 100644 --- a/generator/config/query/type.yaml +++ b/generator/config/query/type.yaml @@ -1,88 +1,131 @@ # $schema: ../schema.json name: $type -link: 'https://www.mongodb.com/docs/manual/reference/operator/query/type/' +link: https://www.mongodb.com/docs/manual/reference/operator/query/type/ type: - fieldQuery encode: single description: | Selects documents if a field is of the specified type. arguments: - - - name: type - type: - - int - - string - variadic: array + - name: type + type: + - int + - string + variadic: array tests: - - - name: 'Querying by Data Type' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/type/#querying-by-data-type' - pipeline: - - - $match: - zipCode: - # Example uses the short form, the builder always generates the verbose form - # $type: 2 - $type: [2] - - - $match: - zipCode: - # Example uses the short form, the builder always generates the verbose form - # $type: 'string' - $type: ['string'] - - - $match: - zipCode: - # Example uses the short form, the builder always generates the verbose form - # $type: 1 - $type: [1] - - - $match: - zipCode: - # Example uses the short form, the builder always generates the verbose form - # $type: 'double' - $type: ['double'] - - - $match: - zipCode: - # Example uses the short form, the builder always generates the verbose form - # $type: 'number' - $type: ['number'] - - - name: 'Querying by Multiple Data Type' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/type/#querying-by-multiple-data-type' - pipeline: - - - $match: - zipCode: - $type: [2, 1] - - - $match: - zipCode: - $type: ['string', 'double'] - - - name: 'Querying by MinKey and MaxKey' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/type/#querying-by-minkey-and-maxkey' - pipeline: - - - $match: - zipCode: - # Example uses the short form, the builder always generates the verbose form - # $type: 'minKey' - $type: ['minKey'] - - - $match: - zipCode: - # Example uses the short form, the builder always generates the verbose form - # $type: 'maxKey' - $type: ['maxKey'] - - - name: 'Querying by Array Type' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/type/#querying-by-array-type' - pipeline: - - - $match: - zipCode: - # Example uses the short form, the builder always generates the verbose form - # $type: 'array' - $type: ['array'] + - name: Querying by Data Type + link: https://www.mongodb.com/docs/manual/reference/operator/query/type/#querying-by-data-type + pipeline: + - $match: + zipCode: + $type: + - 2 + - $match: + zipCode: + $type: + - string + - $match: + zipCode: + $type: + - 1 + - $match: + zipCode: + $type: + - double + - $match: + zipCode: + $type: + - number + schema: + addressBook: + _id: + types: + - bsonType: Number + address: + types: + - bsonType: String + zipCode: + types: + - bsonType: String + - bsonType: Number + - bsonType: Long + - bsonType: Int32 + - bsonType: Array + types: + - bsonType: String + - name: Querying by Multiple Data Type + link: https://www.mongodb.com/docs/manual/reference/operator/query/type/#querying-by-multiple-data-types + pipeline: + - $match: + classAverage: + $type: + - 2 + - 1 + - $match: + classAverage: + $type: + - string + - double + schema: + grades: + _id: + types: + - bsonType: Number + name: + types: + - bsonType: String + classAverage: + types: + - bsonType: String + - bsonType: Number + - bsonType: Int32 + - name: Querying by MinKey and MaxKey + link: https://www.mongodb.com/docs/manual/reference/operator/query/type/#querying-by-minkey-and-maxkey + pipeline: + - $match: + zipCode: + $type: + - minKey + - $match: + zipCode: + $type: + - maxKey + schema: + addressBook: + _id: + types: + - bsonType: Number + address: + types: + - bsonType: String + zipCode: + types: + - bsonType: String + - bsonType: Number + - bsonType: Long + - bsonType: Int32 + - bsonType: Array + types: + - bsonType: String + - name: Querying by Array Type + link: https://www.mongodb.com/docs/manual/reference/operator/query/type/#querying-by-array-type + pipeline: + - $match: + readings: + $type: + - array + schema: + sensorReading: + _id: + types: + - bsonType: Number + readings: + types: + - bsonType: Array + types: + - bsonType: Number + - bsonType: Array + types: + - bsonType: String + - bsonType: Number + - bsonType: Number diff --git a/generator/config/query/where.yaml b/generator/config/query/where.yaml index 5f5c974ab..925e08866 100644 --- a/generator/config/query/where.yaml +++ b/generator/config/query/where.yaml @@ -1,36 +1,47 @@ # $schema: ../schema.json name: $where -link: 'https://www.mongodb.com/docs/manual/reference/operator/query/where/' +link: https://www.mongodb.com/docs/manual/reference/operator/query/where/ type: - query encode: single description: | Matches documents that satisfy a JavaScript expression. arguments: - - - name: function - type: - - javascript + - name: function + type: + - javascript tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/query/where/#example' - pipeline: - - - $match: - $where: - $code: |- - function() { - return hex_md5(this.name) == "9b53e667f30cd329dca1ec9e6a83e994" - } - - - $match: - $expr: - $function: - body: - $code: |- - function(name) { - return hex_md5(name) == "9b53e667f30cd329dca1ec9e6a83e994"; - } - args: ['$name'] - lang: 'js' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/query/where/#example + pipeline: + - $match: + $where: + $code: |- + function() { + return hex_md5(this.name) == "9b53e667f30cd329dca1ec9e6a83e994" + } + - $match: + $expr: + $function: + body: + $code: |- + function(name) { + return hex_md5(name) == "9b53e667f30cd329dca1ec9e6a83e994"; + } + args: + - $name + lang: js + schema: + players: + _id: + types: + - bsonType: Number + name: + types: + - bsonType: String + username: + types: + - bsonType: String + first_login: + types: + - bsonType: String diff --git a/generator/config/schema.json b/generator/config/schema.json index 63739ebcb..da0a65286 100644 --- a/generator/config/schema.json +++ b/generator/config/schema.json @@ -52,17 +52,17 @@ } }, "encode": { - "$comment": "Specifies how operator parameters are encoded.", - "$comment": "array: parameters are encoded as an array of values in the order they are defined by the spec", - "$comment": "object: parameters are encoded as an object with keys matching the parameter names", - "$comment": "single: get the single parameter value", - "$comment": "group: specific for $group stage", + "$comment": [ + "Specifies how operator parameters are encoded.", + "array: parameters are encoded as an array of values in the order they are defined by the spec", + "object: parameters are encoded as an object with keys matching the parameter names", + "single: get the single parameter value" + ], "type": "string", "enum": [ "array", "object", - "single", - "search" + "single" ] }, "description": { @@ -117,8 +117,10 @@ "pipeline", "window", "expression", + "expressionMap", "geometry", "fieldPath", + "unprefixedFieldPath", "timeUnit", "sortSpec", "any", @@ -132,23 +134,58 @@ "range", "sortBy", "geoPoint", - "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", "searchOperator" + "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", + "searchOperator", + "searchHighlight" ] } }, @@ -183,12 +220,36 @@ }, "default": { "$comment": "The default value for the argument.", - "type": ["array", "boolean", "number", "string"] + "type": [ + "array", + "boolean", + "number", + "string" + ] }, "mergeObject": { "$comment": "Skip the name in object encoding and merge the properties of the value into the operator", "type": "boolean", "default": false + }, + "syntheticVariables": { + "$comment": "A list of variables that are automatically made available during evaluation", + "type": "array", + "items": { + "type": "object", + "properties": { + "name": { + "type": "string", + "pattern": "^[$]?[a-zA-Z0-9]*$" + }, + "description": { + "type": "string" + } + }, + "required": [ + "name" + ] + } } }, "required": [ @@ -214,8 +275,124 @@ "items": { "type": "object" } + }, + "schema": { + "type": [ + "string", + "object" + ], + "additionalProperties": { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/SimplifiedSchemaField" + } + } } } + }, + "SimplifiedSchemaType": { + "anyOf": [ + { + "$ref": "#/definitions/SimplifiedSchemaBaseType" + }, + { + "$ref": "#/definitions/SimplifiedSchemaArrayType" + }, + { + "$ref": "#/definitions/SimplifiedSchemaDocumentType" + } + ] + }, + "SimplifiedSchemaField": { + "additionalProperties": false, + "properties": { + "types": { + "items": { + "$ref": "#/definitions/SimplifiedSchemaType" + }, + "type": "array" + } + }, + "required": [ + "types" + ], + "type": "object" + }, + "SimplifiedSchemaArrayType": { + "additionalProperties": false, + "properties": { + "bsonType": { + "const": "Array", + "type": "string" + }, + "types": { + "items": { + "type": "object" + }, + "type": "array" + } + }, + "required": [ + "bsonType", + "types" + ], + "type": "object" + }, + "SimplifiedSchemaBaseType": { + "additionalProperties": false, + "properties": { + "bsonType": { + "enum": [ + "Array", + "Binary", + "Boolean", + "Code", + "CodeWScope", + "Date", + "Decimal128", + "Double", + "Int32", + "Int64", + "Long", + "MaxKey", + "MinKey", + "Null", + "ObjectId", + "BSONRegExp", + "String", + "BSONSymbol", + "Timestamp", + "Undefined", + "Document", + "Number" + ], + "type": "string" + } + }, + "required": [ + "bsonType" + ], + "type": "object" + }, + "SimplifiedSchemaDocumentType": { + "additionalProperties": false, + "properties": { + "bsonType": { + "const": "Document", + "type": "string" + }, + "fields": { + "type": "object", + "additionalProperties": { + "type": "object" + } + } + }, + "required": [ + "bsonType", + "fields" + ], + "type": "object" } } } diff --git a/generator/config/search/autocomplete.yaml b/generator/config/search/autocomplete.yaml index a984b9a39..b4bde643d 100644 --- a/generator/config/search/autocomplete.yaml +++ b/generator/config/search/autocomplete.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: autocomplete -link: 'https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/' +link: https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/ type: - searchOperator encode: object @@ -10,143 +10,254 @@ description: | fields that you intend to query with the autocomplete operator must be indexed with the autocomplete data type in the collection's index definition. arguments: - - - name: path - type: - - searchPath - - - name: query - type: - - string - - - name: tokenOrder - optional: true - type: - - string # any|sequential - - - name: fuzzy - optional: true - type: - - object - - - name: score - optional: true - type: - - searchScore + - name: path + type: + - searchPath + - name: query + type: + - string + - name: tokenOrder + optional: true + type: + - string + - name: fuzzy + optional: true + type: + - object + - name: score + optional: true + type: + - searchScore tests: - - - name: 'Basic' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/#basic-example' - pipeline: - - - $search: - autocomplete: - query: 'off' - path: 'title' - - - $limit: 10 - - - $project: - _id: 0 - title: 1 - - - - name: 'Fuzzy' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/#fuzzy-example' - pipeline: - - - $search: - autocomplete: - query: 'pre' - path: 'title' - fuzzy: - maxEdits: 1 - prefixLength: 1 - maxExpansions: 256 - - - $limit: 10 - - - $project: - _id: 0 - title: 1 - - - - name: 'Token Order any' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/#simple-any-example' - pipeline: - - - $search: - autocomplete: - query: 'men with' - path: 'title' - tokenOrder: 'any' - - - $limit: 4 - - - $project: - _id: 0 - title: 1 - - - - name: 'Token Order sequential' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/#simple-sequential-example' - pipeline: - - - $search: - autocomplete: - query: 'men with' - path: 'title' - tokenOrder: 'sequential' - - - $limit: 4 - - - $project: - _id: 0 - title: 1 - - - - name: 'Highlighting' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/#highlighting-example' - pipeline: - - - $search: - autocomplete: - query: 'ger' - path: 'title' - highlight: - path: 'title' - - - $limit: 5 - - - $project: - score: - $meta: 'searchScore' - _id: 0 - title: 1 - highlights: - $meta: 'searchHighlights' - - - - name: 'Across Multiple Fields' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/#search-across-multiple-fields' - 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 + - name: Basic + link: https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/#basic-example + pipeline: + - $search: + autocomplete: + query: 'off' + path: title + - $limit: 10 + - $project: + _id: 0 + title: 1 + schema: + movies: &ref_0 + _id: + types: + - bsonType: Document + fields: + $oid: + types: + - bsonType: String + title: + types: + - bsonType: String + year: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + runtime: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + released: + types: + - bsonType: Document + fields: + $date: + types: + - bsonType: Document + fields: + $numberLong: + types: + - bsonType: String + poster: + types: + - bsonType: String + plot: + types: + - bsonType: String + fullplot: + types: + - bsonType: String + lastupdated: + types: + - bsonType: String + type: + types: + - bsonType: String + directors: + types: + - bsonType: Array + types: + - bsonType: String + imdb: + types: + - bsonType: Document + fields: + rating: + types: + - bsonType: Document + fields: + $numberDouble: + types: + - bsonType: String + votes: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + id: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + cast: + types: + - bsonType: Array + types: + - bsonType: String + countries: + types: + - bsonType: Array + types: + - bsonType: String + genres: + types: + - bsonType: Array + types: + - bsonType: String + tomatoes: + types: + - bsonType: Document + fields: + viewer: + types: + - bsonType: Document + fields: + rating: + types: + - bsonType: Document + fields: + $numberDouble: + types: + - bsonType: String + numReviews: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + lastUpdated: + types: + - bsonType: Document + fields: + $date: + types: + - bsonType: Document + fields: + $numberLong: + types: + - bsonType: String + num_mflix_comments: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + - name: Fuzzy + link: https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/#fuzzy-example + pipeline: + - $search: + autocomplete: + query: pre + path: title + fuzzy: + maxEdits: 1 + prefixLength: 1 + maxExpansions: 256 + - $limit: 10 + - $project: + _id: 0 + title: 1 + schema: + movies: *ref_0 + - name: Token Order any + link: https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/#simple-any-example + pipeline: + - $search: + autocomplete: + query: men with + path: title + tokenOrder: any + - $limit: 4 + - $project: + _id: 0 + title: 1 + schema: + movies: *ref_0 + - name: Token Order sequential + link: https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/#simple-sequential-example + pipeline: + - $search: + autocomplete: + query: men with + path: title + tokenOrder: sequential + - $limit: 4 + - $project: + _id: 0 + title: 1 + schema: + movies: *ref_0 + - name: Highlighting + link: https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/#highlighting-example + pipeline: + - $search: + autocomplete: + query: ger + path: title + highlight: + path: title + - $limit: 5 + - $project: + score: + $meta: searchScore + _id: 0 + title: 1 + highlights: + $meta: searchHighlights + schema: + movies: *ref_0 + - name: Across Multiple Fields + link: https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/#search-across-multiple-fields + 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 + schema: + movies: *ref_0 diff --git a/generator/config/search/compound.yaml b/generator/config/search/compound.yaml index 7a1d9f419..5c547fd94 100644 --- a/generator/config/search/compound.yaml +++ b/generator/config/search/compound.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: compound -link: 'https://www.mongodb.com/docs/atlas/atlas-search/compound/' +link: https://www.mongodb.com/docs/atlas/atlas-search/compound/ type: - searchOperator encode: object @@ -9,148 +9,198 @@ description: | Each element of a compound query is called a clause, and each clause consists of one or more sub-queries. arguments: - - - name: must - optional: true - type: - - searchOperator - - array # of searchOperator - - - name: mustNot - optional: true - type: - - searchOperator - - array # of searchOperator - - - name: should - optional: true - type: - - searchOperator - - array # of searchOperator - - - name: filter - optional: true - type: - - searchOperator - - array # of searchOperator - - - name: minimumShouldMatch - optional: true - type: - - int - - - name: score - optional: true - type: - - searchScore + - name: must + optional: true + type: + - searchOperator + - array + - name: mustNot + optional: true + type: + - searchOperator + - array + - name: should + optional: true + type: + - searchOperator + - array + - name: filter + optional: true + type: + - searchOperator + - array + - name: minimumShouldMatch + optional: true + type: + - int + - name: score + optional: true + type: + - searchScore tests: - - - name: 'must and mustNot' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/compound/#must-and-mustnot-example' - pipeline: - - - $search: - compound: - must: - - - text: - query: 'varieties' - path: 'description' - mustNot: - - - text: - query: 'apples' - path: 'description' - - - - name: 'must and should' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/compound/#must-and-should-example' - pipeline: - - - $search: - compound: - must: - - - text: - query: 'varieties' - path: 'description' - should: - - - text: - query: 'Fuji' - path: 'description' - - - $project: - score: - $meta: 'searchScore' - - - - name: 'minimumShouldMatch' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/compound/#minimumshouldmatch-example' - pipeline: - - - $search: - compound: - must: - - - text: - query: 'varieties' - path: 'description' - should: - - - text: - query: 'Fuji' - path: 'description' - - - text: - query: 'Golden Delicious' - path: 'description' - minimumShouldMatch: 1 - - - - name: 'Filter' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/compound/#filter-examples' - pipeline: - - - $search: - compound: - must: - - - text: - query: 'varieties' - path: 'description' - should: - - - text: - query: 'banana' - path: 'description' - filter: - - - text: - query: 'granny' - path: 'description' - - - - name: 'Nested' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/compound/#nested-example' - pipeline: - - - $search: - compound: - should: - - - text: - query: 'apple' - path: 'type' - - - compound: - must: - - - text: - query: 'organic' - path: 'category' - - - equals: - value: true - path: 'in_stock' - minimumShouldMatch: 1 + - name: must and mustNot + link: https://www.mongodb.com/docs/atlas/atlas-search/compound/#must-and-mustnot-example + pipeline: + - $search: + compound: + must: + - text: + query: varieties + path: description + mustNot: + - text: + query: apples + path: description + schema: + TestCollection: + _id: + types: + - bsonType: Number + type: + types: + - bsonType: String + description: + types: + - bsonType: String + category: + types: + - bsonType: String + in_stock: + types: + - bsonType: Boolean + - name: must and should + link: https://www.mongodb.com/docs/atlas/atlas-search/compound/#must-and-should-example + pipeline: + - $search: + compound: + must: + - text: + query: varieties + path: description + should: + - text: + query: Fuji + path: description + - $project: + score: + $meta: searchScore + schema: + TestCollection: + _id: + types: + - bsonType: Number + type: + types: + - bsonType: String + description: + types: + - bsonType: String + category: + types: + - bsonType: String + in_stock: + types: + - bsonType: Boolean + - name: minimumShouldMatch + link: https://www.mongodb.com/docs/atlas/atlas-search/compound/#minimumshouldmatch-example + pipeline: + - $search: + compound: + must: + - text: + query: varieties + path: description + should: + - text: + query: Fuji + path: description + - text: + query: Golden Delicious + path: description + minimumShouldMatch: 1 + schema: + TestCollection: + _id: + types: + - bsonType: Number + type: + types: + - bsonType: String + description: + types: + - bsonType: String + category: + types: + - bsonType: String + in_stock: + types: + - bsonType: Boolean + - name: Filter + link: https://www.mongodb.com/docs/atlas/atlas-search/compound/#filter-examples + pipeline: + - $search: + compound: + must: + - text: + query: varieties + path: description + should: + - text: + query: banana + path: description + filter: + - text: + query: granny + path: description + schema: + TestCollection: + _id: + types: + - bsonType: Number + type: + types: + - bsonType: String + description: + types: + - bsonType: String + category: + types: + - bsonType: String + in_stock: + types: + - bsonType: Boolean + - name: Nested + link: https://www.mongodb.com/docs/atlas/atlas-search/compound/#nested-example + pipeline: + - $search: + compound: + should: + - text: + query: apple + path: type + - compound: + must: + - text: + query: organic + path: category + - equals: + value: true + path: in_stock + minimumShouldMatch: 1 + schema: + TestCollection: + _id: + types: + - bsonType: Number + type: + types: + - bsonType: String + description: + types: + - bsonType: String + category: + types: + - bsonType: String + in_stock: + types: + - bsonType: Boolean diff --git a/generator/config/search/embeddedDocument.yaml b/generator/config/search/embeddedDocument.yaml index 19c804625..58295586a 100644 --- a/generator/config/search/embeddedDocument.yaml +++ b/generator/config/search/embeddedDocument.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: embeddedDocument -link: 'https://www.mongodb.com/docs/atlas/atlas-search/embedded-document/' +link: https://www.mongodb.com/docs/atlas/atlas-search/embedded-document/ type: - searchOperator encode: object @@ -10,146 +10,203 @@ description: | element of an array of embedded documents. embeddedDocument can be used only for queries over fields of the embeddedDocuments arguments: - - - name: path - type: - - searchPath - - - name: operator - type: - - searchOperator - - - name: score - optional: true - type: - - searchScore + - name: path + type: + - searchPath + - name: operator + type: + - searchOperator + - name: score + optional: true + type: + - searchScore tests: - - - name: 'Basic' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/embedded-document/#index-definition' - pipeline: - - - $search: - embeddedDocument: - path: 'items' - operator: - compound: - must: - - - text: - path: 'items.tags' - query: 'school' - should: - - - text: - path: 'items.name' - query: 'backpack' - score: - embedded: - aggregate: 'mean' - - - $limit: 5 - - - $project: - _id: 0 - items.name: 1 - items.tags: 1 + - name: Basic + link: https://www.mongodb.com/docs/atlas/atlas-search/embedded-document/#index-definition + pipeline: + - $search: + embeddedDocument: + path: items + operator: + compound: + must: + - text: + path: items.tags + query: school + should: + - text: + path: items.name + query: backpack score: - $meta: 'searchScore' - - - - name: 'Facet' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/embedded-document/#facet-query' - pipeline: - - - $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' - - - - name: 'Query and Sort' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/embedded-document/#query-and-sort' - pipeline: - - - $search: - embeddedDocument: - path: 'items' - operator: - text: - path: 'items.name' - query: 'laptop' - sort: - items.tags: 1 - - - $limit: 5 - - - $project: - _id: 0 - items.name: 1 + embedded: + aggregate: mean + - $limit: 5 + - $project: + _id: 0 + items.name: 1 + items.tags: 1 + score: + $meta: searchScore + schema: + sales: &ref_0 + _id: + types: + - bsonType: Document + fields: + $oid: + types: + - bsonType: String + saleDate: + types: + - bsonType: Document + fields: + $date: + types: + - bsonType: Document + fields: + $numberLong: + types: + - bsonType: String + items: + types: + - bsonType: Array + types: + - bsonType: Document + fields: + name: + types: + - bsonType: String + tags: + types: + - bsonType: Array + types: + - bsonType: String + price: + types: + - bsonType: Document + fields: + $numberDecimal: + types: + - bsonType: String + quantity: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + storeLocation: + types: + - bsonType: String + customer: + types: + - bsonType: Document + fields: + gender: + types: + - bsonType: String + age: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + email: + types: + - bsonType: String + satisfaction: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + couponUsed: + types: + - bsonType: Boolean + purchaseMethod: + types: + - bsonType: String + - name: Facet + link: https://www.mongodb.com/docs/atlas/atlas-search/embedded-document/#facet-query + pipeline: + - $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 + schema: + sales: *ref_0 + - name: Query and Sort + link: https://www.mongodb.com/docs/atlas/atlas-search/embedded-document/#query-and-sort + pipeline: + - $search: + embeddedDocument: + path: items + operator: + text: + path: items.name + query: laptop + sort: items.tags: 1 - score: - $meta: 'searchScore' - - - - name: 'Query for Matching Embedded Documents Only' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/embedded-document/#query-for-matching-embedded-documents-only' - 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 - - - $project: - _id: 0 - storeLocation: 1 - items: - $filter: - input: '$items' - cond: - $and: - - - $ifNull: - - '$$this.price' - - 'false' - - - $gt: - - '$$this.quantity' - - 2 - - - $in: - - 'office' - - '$$this.tags' + - $limit: 5 + - $project: + _id: 0 + items.name: 1 + items.tags: 1 + score: + $meta: searchScore + schema: + sales: *ref_0 + - name: Query for Matching Embedded Documents Only + link: https://www.mongodb.com/docs/atlas/atlas-search/embedded-document/#query-for-matching-embedded-documents-only + 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 + - $project: + _id: 0 + storeLocation: 1 + items: + $filter: + input: $items + cond: + $and: + - $ifNull: + - $$this.price + - 'false' + - $gt: + - $$this.quantity + - 2 + - $in: + - office + - $$this.tags + schema: + sales: *ref_0 diff --git a/generator/config/search/equals.yaml b/generator/config/search/equals.yaml index b3e50c641..65c2abdfe 100644 --- a/generator/config/search/equals.yaml +++ b/generator/config/search/equals.yaml @@ -1,104 +1,374 @@ # $schema: ../schema.json name: equals -link: 'https://www.mongodb.com/docs/atlas/atlas-search/equals/' +link: https://www.mongodb.com/docs/atlas/atlas-search/equals/ type: - searchOperator encode: object description: | The equals operator checks whether a field matches a value you specify. arguments: - - - name: path - type: - - searchPath - - - name: value - type: - - binData - - bool - - date - - objectId - - 'null' - - number - - string - - - name: score - optional: true - type: - - searchScore + - name: path + type: + - searchPath + - name: value + type: + - binData + - bool + - date + - objectId + - 'null' + - number + - string + - name: score + optional: true + type: + - searchScore tests: - - - name: 'Boolean' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/equals/#boolean-examples' - pipeline: - - - $search: - equals: - path: 'verified_user' - value: true - - - $project: - name: 1 - _id: 0 - score: - $meta: 'searchScore' - - - - name: 'ObjectId' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/equals/#objectid-example' - pipeline: - - - $search: - equals: - path: 'teammates' - value: !bson_objectId '5a9427648b0beebeb69589a1' - - - - name: 'Date' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/equals/#date-example' - pipeline: - - - $search: - equals: - path: 'account_created' - value: !bson_utcdatetime '2022-05-04T05:01:08.000+00:00' - - - - name: 'Number' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/equals/#number-example' - pipeline: - - - $search: - equals: - path: 'employee_number' - value: 259 - - - - name: 'String' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/equals/#string-example' - pipeline: - - - $search: - equals: - path: 'name' - value: 'jim hall' - - - - name: 'UUID' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/equals/#uuid-example' - pipeline: - - - $search: - equals: - path: 'uuid' - value: !bson_uuid 'fac32260-b511-4c69-8485-a2be5b7dda9e' - - - - name: 'Null' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/equals/#null-example' - pipeline: - - - $search: - equals: - path: 'job_title' - value: ~ + - name: Boolean + link: https://www.mongodb.com/docs/atlas/atlas-search/equals/#boolean-examples + pipeline: + - $search: + equals: + path: verified_user + value: true + - $project: + name: 1 + _id: 0 + score: + $meta: searchScore + schema: + users: + _id: + types: + - bsonType: ObjectId + name: + types: + - bsonType: String + verified_user: + types: + - bsonType: Boolean + account: + types: + - bsonType: Document + fields: + new_user: + types: + - bsonType: Boolean + active_user: + types: + - bsonType: Boolean + teammates: + types: + - bsonType: Array + types: + - bsonType: ObjectId + region: + types: + - bsonType: String + account_created: + types: + - bsonType: Date + employee_number: + types: + - bsonType: Number + uuid: + types: + - bsonType: Binary + job_title: + types: + - bsonType: 'Null' + - bsonType: String + - name: ObjectId + link: https://www.mongodb.com/docs/atlas/atlas-search/equals/#objectid-example + pipeline: + - $search: + equals: + path: teammates + value: !bson_objectId 5a9427648b0beebeb69589a1 + schema: + users: + _id: + types: + - bsonType: ObjectId + name: + types: + - bsonType: String + verified_user: + types: + - bsonType: Boolean + account: + types: + - bsonType: Document + fields: + new_user: + types: + - bsonType: Boolean + active_user: + types: + - bsonType: Boolean + teammates: + types: + - bsonType: Array + types: + - bsonType: ObjectId + region: + types: + - bsonType: String + account_created: + types: + - bsonType: Date + employee_number: + types: + - bsonType: Number + uuid: + types: + - bsonType: Binary + job_title: + types: + - bsonType: 'Null' + - bsonType: String + - name: Date + link: https://www.mongodb.com/docs/atlas/atlas-search/equals/#date-example + pipeline: + - $search: + equals: + path: account_created + value: !bson_utcdatetime '2022-05-04T05:01:08.000Z' + schema: + users: + _id: + types: + - bsonType: ObjectId + name: + types: + - bsonType: String + verified_user: + types: + - bsonType: Boolean + account: + types: + - bsonType: Document + fields: + new_user: + types: + - bsonType: Boolean + active_user: + types: + - bsonType: Boolean + teammates: + types: + - bsonType: Array + types: + - bsonType: ObjectId + region: + types: + - bsonType: String + account_created: + types: + - bsonType: Date + employee_number: + types: + - bsonType: Number + uuid: + types: + - bsonType: Binary + job_title: + types: + - bsonType: 'Null' + - bsonType: String + - name: Number + link: https://www.mongodb.com/docs/atlas/atlas-search/equals/#number-example + pipeline: + - $search: + equals: + path: employee_number + value: 259 + schema: + users: + _id: + types: + - bsonType: ObjectId + name: + types: + - bsonType: String + verified_user: + types: + - bsonType: Boolean + account: + types: + - bsonType: Document + fields: + new_user: + types: + - bsonType: Boolean + active_user: + types: + - bsonType: Boolean + teammates: + types: + - bsonType: Array + types: + - bsonType: ObjectId + region: + types: + - bsonType: String + account_created: + types: + - bsonType: Date + employee_number: + types: + - bsonType: Number + uuid: + types: + - bsonType: Binary + job_title: + types: + - bsonType: 'Null' + - bsonType: String + - name: String + link: https://www.mongodb.com/docs/atlas/atlas-search/equals/#string-example + pipeline: + - $search: + equals: + path: name + value: jim hall + schema: + users: + _id: + types: + - bsonType: ObjectId + name: + types: + - bsonType: String + verified_user: + types: + - bsonType: Boolean + account: + types: + - bsonType: Document + fields: + new_user: + types: + - bsonType: Boolean + active_user: + types: + - bsonType: Boolean + teammates: + types: + - bsonType: Array + types: + - bsonType: ObjectId + region: + types: + - bsonType: String + account_created: + types: + - bsonType: Date + employee_number: + types: + - bsonType: Number + uuid: + types: + - bsonType: Binary + job_title: + types: + - bsonType: 'Null' + - bsonType: String + - name: UUID + link: https://www.mongodb.com/docs/atlas/atlas-search/equals/#uuid-example + pipeline: + - $search: + equals: + path: uuid + value: !bson_uuid fac32260-b511-4c69-8485-a2be5b7dda9e + schema: + users: + _id: + types: + - bsonType: ObjectId + name: + types: + - bsonType: String + verified_user: + types: + - bsonType: Boolean + account: + types: + - bsonType: Document + fields: + new_user: + types: + - bsonType: Boolean + active_user: + types: + - bsonType: Boolean + teammates: + types: + - bsonType: Array + types: + - bsonType: ObjectId + region: + types: + - bsonType: String + account_created: + types: + - bsonType: Date + employee_number: + types: + - bsonType: Number + uuid: + types: + - bsonType: Binary + job_title: + types: + - bsonType: 'Null' + - bsonType: String + - name: 'Null' + link: https://www.mongodb.com/docs/atlas/atlas-search/equals/#null-example + pipeline: + - $search: + equals: + path: job_title + value: ~ + schema: + users: + _id: + types: + - bsonType: ObjectId + name: + types: + - bsonType: String + verified_user: + types: + - bsonType: Boolean + account: + types: + - bsonType: Document + fields: + new_user: + types: + - bsonType: Boolean + active_user: + types: + - bsonType: Boolean + teammates: + types: + - bsonType: Array + types: + - bsonType: ObjectId + region: + types: + - bsonType: String + account_created: + types: + - bsonType: Date + employee_number: + types: + - bsonType: Number + uuid: + types: + - bsonType: Binary + job_title: + types: + - bsonType: 'Null' + - bsonType: String diff --git a/generator/config/search/exists.yaml b/generator/config/search/exists.yaml index 062e8ba59..5e49f56d2 100644 --- a/generator/config/search/exists.yaml +++ b/generator/config/search/exists.yaml @@ -1,56 +1,116 @@ # $schema: ../schema.json name: exists -link: 'https://www.mongodb.com/docs/atlas/atlas-search/exists/' +link: https://www.mongodb.com/docs/atlas/atlas-search/exists/ type: - searchOperator encode: object description: | The exists operator tests if a path to a specified indexed field name exists in a document. arguments: - - - name: path - type: - - searchPath - - - name: score - optional: true - type: - - searchScore + - name: path + type: + - searchPath + - name: score + optional: true + type: + - searchScore tests: - - - name: 'Basic' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/exists/#basic-example' - pipeline: - - - $search: - exists: - path: 'type' - - - - name: 'Embedded' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/exists/#embedded-example' - pipeline: - - - $search: - exists: - path: 'quantities.lemons' - - - - name: 'Compound' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/exists/#compound-example' - pipeline: - - - $search: - compound: - must: - - - exists: - path: 'type' - - - text: - query: 'apple' - path: 'type' - should: - text: - query: 'fuji' - path: 'description' + - name: Basic + link: https://www.mongodb.com/docs/atlas/atlas-search/exists/#basic-example + pipeline: + - $search: + exists: + path: type + schema: + TestCollection: + _id: + types: + - bsonType: Number + type: + types: + - bsonType: String + description: + types: + - bsonType: String + quantities: + types: + - bsonType: Document + fields: + lemons: + types: + - bsonType: Number + oranges: + types: + - bsonType: Number + grapefruit: + types: + - bsonType: Number + - name: Embedded + link: https://www.mongodb.com/docs/atlas/atlas-search/exists/#embedded-example + pipeline: + - $search: + exists: + path: quantities.lemons + schema: + TestCollection: + _id: + types: + - bsonType: Number + type: + types: + - bsonType: String + description: + types: + - bsonType: String + quantities: + types: + - bsonType: Document + fields: + lemons: + types: + - bsonType: Number + oranges: + types: + - bsonType: Number + grapefruit: + types: + - bsonType: Number + - name: Compound + link: https://www.mongodb.com/docs/atlas/atlas-search/exists/#compound-example + pipeline: + - $search: + compound: + must: + - exists: + path: type + - text: + query: apple + path: type + should: + text: + query: fuji + path: description + schema: + TestCollection: + _id: + types: + - bsonType: Number + type: + types: + - bsonType: String + description: + types: + - bsonType: String + quantities: + types: + - bsonType: Document + fields: + lemons: + types: + - bsonType: Number + oranges: + types: + - bsonType: Number + grapefruit: + types: + - bsonType: Number diff --git a/generator/config/search/facet.yaml b/generator/config/search/facet.yaml index 53dc8cba9..9cfd0f499 100644 --- a/generator/config/search/facet.yaml +++ b/generator/config/search/facet.yaml @@ -1,56 +1,183 @@ # $schema: ../schema.json name: facet -link: 'https://www.mongodb.com/docs/atlas/atlas-search/facet/' +link: https://www.mongodb.com/docs/atlas/atlas-search/facet/ type: - - searchOperator # should be searchCollector + - searchOperator encode: object description: | The facet collector groups results by values or ranges in the specified faceted fields and returns the count for each of those groups. arguments: - - - name: facets - type: - - object # map of facetDefinition - - - name: operator - optional: true - type: - - searchOperator + - name: facets + type: + - object + - name: operator + optional: true + type: + - searchOperator tests: - - - name: 'Facet' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/facet/#examples' - pipeline: - - - $search: - facet: - operator: - near: - path: 'released' - origin: !bson_utcdatetime '1999-07-01T00:00:00.000+00:00' - pivot: 7776000000 - facets: - genresFacet: - type: 'string' - path: 'genres' - - - $limit: 2 - - - $facet: - docs: - - - $project: - title: 1 - released: 1 - meta: - - - $replaceWith: '$$SEARCH_META' - - - $limit: 1 - - - $set: - meta: - $arrayElemAt: - - '$meta' - - 0 + - name: Facet + link: https://www.mongodb.com/docs/atlas/atlas-search/facet/#examples + pipeline: + - $search: + facet: + operator: + near: + path: released + origin: !bson_utcdatetime '1999-07-01T00:00:00.000Z' + pivot: 7776000000 + facets: + genresFacet: + type: string + path: genres + - $limit: 2 + - $facet: + docs: + - $project: + title: 1 + released: 1 + meta: + - $replaceWith: $$SEARCH_META + - $limit: 1 + - $set: + meta: + $arrayElemAt: + - $meta + - 0 + schema: + movies: + _id: + types: + - bsonType: Document + fields: + $oid: + types: + - bsonType: String + title: + types: + - bsonType: String + year: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + runtime: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + released: + types: + - bsonType: Document + fields: + $date: + types: + - bsonType: Document + fields: + $numberLong: + types: + - bsonType: String + poster: + types: + - bsonType: String + plot: + types: + - bsonType: String + fullplot: + types: + - bsonType: String + lastupdated: + types: + - bsonType: String + type: + types: + - bsonType: String + directors: + types: + - bsonType: Array + types: + - bsonType: String + imdb: + types: + - bsonType: Document + fields: + rating: + types: + - bsonType: Document + fields: + $numberDouble: + types: + - bsonType: String + votes: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + id: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + cast: + types: + - bsonType: Array + types: + - bsonType: String + countries: + types: + - bsonType: Array + types: + - bsonType: String + genres: + types: + - bsonType: Array + types: + - bsonType: String + tomatoes: + types: + - bsonType: Document + fields: + viewer: + types: + - bsonType: Document + fields: + rating: + types: + - bsonType: Document + fields: + $numberDouble: + types: + - bsonType: String + numReviews: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + lastUpdated: + types: + - bsonType: Document + fields: + $date: + types: + - bsonType: Document + fields: + $numberLong: + types: + - bsonType: String + num_mflix_comments: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String diff --git a/generator/config/search/geoShape.yaml b/generator/config/search/geoShape.yaml index 4da121e45..23e8bcc60 100644 --- a/generator/config/search/geoShape.yaml +++ b/generator/config/search/geoShape.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: geoShape -link: 'https://www.mongodb.com/docs/atlas/atlas-search/geoShape/' +link: https://www.mongodb.com/docs/atlas/atlas-search/geoShape/ type: - searchOperator encode: object @@ -8,116 +8,517 @@ description: | The geoShape operator supports querying shapes with a relation to a given geometry if indexShapes is set to true in the index definition. arguments: - - - name: path - type: - - searchPath - - - name: relation - type: - - string # contains | disjoint | intersects | within - - - name: geometry - type: - - geometry - - - name: score - optional: true - type: - - searchScore + - name: path + type: + - searchPath + - name: relation + type: + - string + - name: geometry + type: + - geometry + - name: score + optional: true + type: + - searchScore tests: - - - name: 'Disjoint' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/geoShape/#disjoint-example' - pipeline: - - - $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' - - - $limit: 3 - - - $project: - _id: 0 - name: 1 - address: 1 - score: - $meta: 'searchScore' - - - - name: 'Intersect' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/geoShape/#intersects-example' - pipeline: - - - $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' - - - $limit: 3 - - - $project: - _id: 0 - name: 1 - address: 1 - score: - $meta: 'searchScore' - - - - name: 'Within' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/geoShape/#within-example' - pipeline: - - - $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' - - - $limit: 3 - - - $project: - _id: 0 - name: 1 - address: 1 - score: - $meta: 'searchScore' + - name: Disjoint + link: https://www.mongodb.com/docs/atlas/atlas-search/geoShape/#disjoint-example + pipeline: + - $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 + - $limit: 3 + - $project: + _id: 0 + name: 1 + address: 1 + score: + $meta: searchScore + schema: + listingsAndReviews: &ref_0 + _id: + types: + - bsonType: String + listing_url: + types: + - bsonType: String + name: + types: + - bsonType: String + summary: + types: + - bsonType: String + interaction: + types: + - bsonType: String + house_rules: + types: + - bsonType: String + property_type: + types: + - bsonType: String + room_type: + types: + - bsonType: String + bed_type: + types: + - bsonType: String + minimum_nights: + types: + - bsonType: String + maximum_nights: + types: + - bsonType: String + cancellation_policy: + types: + - bsonType: String + last_scraped: + types: + - bsonType: Document + fields: + $date: + types: + - bsonType: Document + fields: + $numberLong: + types: + - bsonType: String + calendar_last_scraped: + types: + - bsonType: Document + fields: + $date: + types: + - bsonType: Document + fields: + $numberLong: + types: + - bsonType: String + first_review: + types: + - bsonType: Document + fields: + $date: + types: + - bsonType: Document + fields: + $numberLong: + types: + - bsonType: String + last_review: + types: + - bsonType: Document + fields: + $date: + types: + - bsonType: Document + fields: + $numberLong: + types: + - bsonType: String + accommodates: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + bedrooms: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + beds: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + number_of_reviews: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + bathrooms: + types: + - bsonType: Document + fields: + $numberDecimal: + types: + - bsonType: String + amenities: + types: + - bsonType: Array + types: + - bsonType: String + price: + types: + - bsonType: Document + fields: + $numberDecimal: + types: + - bsonType: String + security_deposit: + types: + - bsonType: Document + fields: + $numberDecimal: + types: + - bsonType: String + cleaning_fee: + types: + - bsonType: Document + fields: + $numberDecimal: + types: + - bsonType: String + extra_people: + types: + - bsonType: Document + fields: + $numberDecimal: + types: + - bsonType: String + guests_included: + types: + - bsonType: Document + fields: + $numberDecimal: + types: + - bsonType: String + images: + types: + - bsonType: Document + fields: + thumbnail_url: + types: + - bsonType: String + medium_url: + types: + - bsonType: String + picture_url: + types: + - bsonType: String + xl_picture_url: + types: + - bsonType: String + host: + types: + - bsonType: Document + fields: + host_id: + types: + - bsonType: String + host_url: + types: + - bsonType: String + host_name: + types: + - bsonType: String + host_location: + types: + - bsonType: String + host_about: + types: + - bsonType: String + host_response_time: + types: + - bsonType: String + host_thumbnail_url: + types: + - bsonType: String + host_picture_url: + types: + - bsonType: String + host_neighbourhood: + types: + - bsonType: String + host_response_rate: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + host_is_superhost: + types: + - bsonType: Boolean + host_has_profile_pic: + types: + - bsonType: Boolean + host_identity_verified: + types: + - bsonType: Boolean + host_listings_count: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + host_total_listings_count: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + host_verifications: + types: + - bsonType: Array + types: + - bsonType: String + address: + types: + - bsonType: Document + fields: + street: + types: + - bsonType: String + suburb: + types: + - bsonType: String + government_area: + types: + - bsonType: String + market: + types: + - bsonType: String + country: + types: + - bsonType: String + country_code: + types: + - bsonType: String + location: + types: + - bsonType: Document + fields: + type: + types: + - bsonType: String + coordinates: + types: + - bsonType: Array + types: + - bsonType: Document + fields: + $numberDouble: + types: + - bsonType: String + is_location_exact: + types: + - bsonType: Boolean + availability: + types: + - bsonType: Document + fields: + availability_30: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + availability_60: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + availability_90: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + availability_365: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + review_scores: + types: + - bsonType: Document + fields: + review_scores_accuracy: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + review_scores_cleanliness: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + review_scores_checkin: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + review_scores_communication: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + review_scores_location: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + review_scores_value: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + review_scores_rating: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + reviews: + types: + - bsonType: Array + types: + - bsonType: Document + fields: + _id: + types: + - bsonType: String + date: + types: + - bsonType: Document + fields: + $date: + types: + - bsonType: Document + fields: + $numberLong: + types: + - bsonType: String + listing_id: + types: + - bsonType: String + reviewer_id: + types: + - bsonType: String + reviewer_name: + types: + - bsonType: String + comments: + types: + - bsonType: String + - name: Intersect + link: https://www.mongodb.com/docs/atlas/atlas-search/geoShape/#intersects-example + pipeline: + - $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 + - $limit: 3 + - $project: + _id: 0 + name: 1 + address: 1 + score: + $meta: searchScore + schema: + listingsAndReviews: *ref_0 + - name: Within + link: https://www.mongodb.com/docs/atlas/atlas-search/geoShape/#within-example + pipeline: + - $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 + - $limit: 3 + - $project: + _id: 0 + name: 1 + address: 1 + score: + $meta: searchScore + schema: + listingsAndReviews: *ref_0 diff --git a/generator/config/search/geoWithin.yaml b/generator/config/search/geoWithin.yaml index 1739f1997..08b7f72c9 100644 --- a/generator/config/search/geoWithin.yaml +++ b/generator/config/search/geoWithin.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: geoWithin -link: 'https://www.mongodb.com/docs/atlas/atlas-search/geoWithin/' +link: https://www.mongodb.com/docs/atlas/atlas-search/geoWithin/ type: - searchOperator encode: object @@ -9,95 +9,486 @@ description: | geometry. Only points are returned, even if indexShapes value is true in the index definition. arguments: - - - name: path - type: - - searchPath - - - name: box - optional: true - type: - - object - - - name: circle - optional: true - type: - - object - - - name: geometry - optional: true - type: - - geometry - - - name: score - optional: true - type: - - searchScore + - name: path + type: + - searchPath + - name: box + optional: true + type: + - object + - name: circle + optional: true + type: + - object + - name: geometry + optional: true + type: + - geometry + - name: score + optional: true + type: + - searchScore tests: - - - name: 'box' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/geoWithin/#box-example' - pipeline: - - - $search: - geoWithin: - path: 'address.location' - box: - bottomLeft: - type: 'Point' - coordinates: [112.467, -55.05] - topRight: - type: 'Point' - coordinates: [168, -9.133] - - - $limit: 3 - - - $project: - _id: 0 - name: 1 - address: 1 - - - - name: 'circle' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/geoWithin/#circle-example' - pipeline: - - - $search: - geoWithin: - circle: - center: - type: 'Point' - coordinates: [-73.54, 45.54] - radius: 1600 - path: 'address.location' - - - $limit: 3 - - - $project: - _id: 0 - name: 1 - address: 1 - - - - name: 'geometry' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/geoWithin/#geometry-examples' - pipeline: - - - $search: - geoWithin: - geometry: - type: 'Polygon' + - name: box + link: https://www.mongodb.com/docs/atlas/atlas-search/geoWithin/#box-example + pipeline: + - $search: + geoWithin: + path: address.location + box: + bottomLeft: + type: Point coordinates: - - - - [-161.323242, 22.512557] - - [-152.446289, 22.065278] - - [-156.09375, 17.811456] - - [-161.323242, 22.512557] - path: 'address.location' - - - $limit: 3 - - - $project: - _id: 0 - name: 1 - address: 1 + - 112.467 + - -55.05 + topRight: + type: Point + coordinates: + - 168 + - -9.133 + - $limit: 3 + - $project: + _id: 0 + name: 1 + address: 1 + schema: + listingsAndReviews: &ref_0 + _id: + types: + - bsonType: String + listing_url: + types: + - bsonType: String + name: + types: + - bsonType: String + summary: + types: + - bsonType: String + interaction: + types: + - bsonType: String + house_rules: + types: + - bsonType: String + property_type: + types: + - bsonType: String + room_type: + types: + - bsonType: String + bed_type: + types: + - bsonType: String + minimum_nights: + types: + - bsonType: String + maximum_nights: + types: + - bsonType: String + cancellation_policy: + types: + - bsonType: String + last_scraped: + types: + - bsonType: Document + fields: + $date: + types: + - bsonType: Document + fields: + $numberLong: + types: + - bsonType: String + calendar_last_scraped: + types: + - bsonType: Document + fields: + $date: + types: + - bsonType: Document + fields: + $numberLong: + types: + - bsonType: String + first_review: + types: + - bsonType: Document + fields: + $date: + types: + - bsonType: Document + fields: + $numberLong: + types: + - bsonType: String + last_review: + types: + - bsonType: Document + fields: + $date: + types: + - bsonType: Document + fields: + $numberLong: + types: + - bsonType: String + accommodates: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + bedrooms: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + beds: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + number_of_reviews: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + bathrooms: + types: + - bsonType: Document + fields: + $numberDecimal: + types: + - bsonType: String + amenities: + types: + - bsonType: Array + types: + - bsonType: String + price: + types: + - bsonType: Document + fields: + $numberDecimal: + types: + - bsonType: String + security_deposit: + types: + - bsonType: Document + fields: + $numberDecimal: + types: + - bsonType: String + cleaning_fee: + types: + - bsonType: Document + fields: + $numberDecimal: + types: + - bsonType: String + extra_people: + types: + - bsonType: Document + fields: + $numberDecimal: + types: + - bsonType: String + guests_included: + types: + - bsonType: Document + fields: + $numberDecimal: + types: + - bsonType: String + images: + types: + - bsonType: Document + fields: + thumbnail_url: + types: + - bsonType: String + medium_url: + types: + - bsonType: String + picture_url: + types: + - bsonType: String + xl_picture_url: + types: + - bsonType: String + host: + types: + - bsonType: Document + fields: + host_id: + types: + - bsonType: String + host_url: + types: + - bsonType: String + host_name: + types: + - bsonType: String + host_location: + types: + - bsonType: String + host_about: + types: + - bsonType: String + host_response_time: + types: + - bsonType: String + host_thumbnail_url: + types: + - bsonType: String + host_picture_url: + types: + - bsonType: String + host_neighbourhood: + types: + - bsonType: String + host_response_rate: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + host_is_superhost: + types: + - bsonType: Boolean + host_has_profile_pic: + types: + - bsonType: Boolean + host_identity_verified: + types: + - bsonType: Boolean + host_listings_count: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + host_total_listings_count: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + host_verifications: + types: + - bsonType: Array + types: + - bsonType: String + address: + types: + - bsonType: Document + fields: + street: + types: + - bsonType: String + suburb: + types: + - bsonType: String + government_area: + types: + - bsonType: String + market: + types: + - bsonType: String + country: + types: + - bsonType: String + country_code: + types: + - bsonType: String + location: + types: + - bsonType: Document + fields: + type: + types: + - bsonType: String + coordinates: + types: + - bsonType: Array + types: + - bsonType: Document + fields: + $numberDouble: + types: + - bsonType: String + is_location_exact: + types: + - bsonType: Boolean + availability: + types: + - bsonType: Document + fields: + availability_30: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + availability_60: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + availability_90: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + availability_365: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + review_scores: + types: + - bsonType: Document + fields: + review_scores_accuracy: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + review_scores_cleanliness: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + review_scores_checkin: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + review_scores_communication: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + review_scores_location: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + review_scores_value: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + review_scores_rating: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + reviews: + types: + - bsonType: Array + types: + - bsonType: Document + fields: + _id: + types: + - bsonType: String + date: + types: + - bsonType: Document + fields: + $date: + types: + - bsonType: Document + fields: + $numberLong: + types: + - bsonType: String + listing_id: + types: + - bsonType: String + reviewer_id: + types: + - bsonType: String + reviewer_name: + types: + - bsonType: String + comments: + types: + - bsonType: String + - name: circle + link: https://www.mongodb.com/docs/atlas/atlas-search/geoWithin/#circle-example + pipeline: + - $search: + geoWithin: + circle: + center: + type: Point + coordinates: + - -73.54 + - 45.54 + radius: 1600 + path: address.location + - $limit: 3 + - $project: + _id: 0 + name: 1 + address: 1 + schema: + listingsAndReviews: *ref_0 + - name: geometry + link: https://www.mongodb.com/docs/atlas/atlas-search/geoWithin/#geometry-examples + pipeline: + - $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 + - $limit: 3 + - $project: + _id: 0 + name: 1 + address: 1 + schema: + listingsAndReviews: *ref_0 diff --git a/generator/config/search/in.yaml b/generator/config/search/in.yaml index cc1aa6c33..04f2cf7a6 100644 --- a/generator/config/search/in.yaml +++ b/generator/config/search/in.yaml @@ -1,89 +1,127 @@ # $schema: ../schema.json name: in -link: 'https://www.mongodb.com/docs/atlas/atlas-search/in/' +link: https://www.mongodb.com/docs/atlas/atlas-search/in/ type: - searchOperator encode: object description: | The in operator performs a search for an array of BSON values in a field. arguments: - - - name: path - type: - - searchPath - - - name: value - type: - - any - - array # of any - - - name: score - optional: true - type: - - searchScore + - name: path + type: + - searchPath + - name: value + type: + - any + - array + - name: score + optional: true + type: + - searchScore tests: - - - name: 'Single Value Field Match' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/in/#examples' - pipeline: - - - $search: - in: - path: 'birthdate' - value: - - !bson_utcdatetime '1977-03-02T02:20:31.000+00:00' - - !bson_utcdatetime '1977-03-01T00:00:00.000+00:00' - - !bson_utcdatetime '1977-05-06T21:57:35.000+00:00' - - - $project: - _id: 0 - name: 1 - birthdate: 1 - - - - name: 'Array Value Field Match' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/in/#examples' - pipeline: - - - $search: - in: - path: 'accounts' - value: - - 371138 - - 371139 - - 371140 - - - $project: - _id: 0 - name: 1 - accounts: 1 - - - - name: 'Compound Query Match' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/in/#examples' - pipeline: - - - $search: - compound: - must: - - - in: - path: 'name' - value: - - 'james sanchez' - - 'jennifer lawrence' - should: - - - in: - path: '_id' - value: - - !bson_objectId '5ca4bbcea2dd94ee58162a72' - - !bson_objectId '5ca4bbcea2dd94ee58162a91' - - - $limit: 5 - - - $project: - _id: 1 - name: 1 - score: - $meta: 'searchScore' + - name: Single Value Field Match + link: https://www.mongodb.com/docs/atlas/atlas-search/in/#examples + pipeline: + - $search: + in: + path: birthdate + value: + - !bson_utcdatetime '1977-03-02T02:20:31.000Z' + - !bson_utcdatetime '1977-03-01T00:00:00.000Z' + - !bson_utcdatetime '1977-05-06T21:57:35.000Z' + - $project: + _id: 0 + name: 1 + birthdate: 1 + schema: + customers: &ref_0 + _id: + types: + - bsonType: ObjectId + username: + types: + - bsonType: String + name: + types: + - bsonType: String + address: + types: + - bsonType: String + birthdate: + types: + - bsonType: Document + fields: + $date: + types: + - bsonType: Double + email: + types: + - bsonType: String + accounts: + types: + - bsonType: Array + types: + - bsonType: Double + tier_and_details: + types: + - bsonType: Document + fields: + b5f19cb532fa436a9be2cf1d7d1cac8a: + types: + - bsonType: Document + fields: + tier: + types: + - bsonType: String + benefits: + types: + - bsonType: Array + types: + - bsonType: String + active: + types: + - bsonType: Boolean + id: + types: + - bsonType: String + - name: Array Value Field Match + link: https://www.mongodb.com/docs/atlas/atlas-search/in/#examples + pipeline: + - $search: + in: + path: accounts + value: + - 371138 + - 371139 + - 371140 + - $project: + _id: 0 + name: 1 + accounts: 1 + schema: + customers: *ref_0 + - name: Compound Query Match + link: https://www.mongodb.com/docs/atlas/atlas-search/in/#examples + pipeline: + - $search: + compound: + must: + - in: + path: name + value: + - james sanchez + - jennifer lawrence + should: + - in: + path: _id + value: + - !bson_objectId 5ca4bbcea2dd94ee58162a72 + - !bson_objectId 5ca4bbcea2dd94ee58162a91 + - $limit: 5 + - $project: + _id: 1 + name: 1 + score: + $meta: searchScore + schema: + customers: *ref_0 diff --git a/generator/config/search/moreLikeThis.yaml b/generator/config/search/moreLikeThis.yaml index 8c4803bdd..008860d0a 100644 --- a/generator/config/search/moreLikeThis.yaml +++ b/generator/config/search/moreLikeThis.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: moreLikeThis -link: 'https://www.mongodb.com/docs/atlas/atlas-search/moreLikeThis/' +link: https://www.mongodb.com/docs/atlas/atlas-search/moreLikeThis/ type: - searchOperator encode: object @@ -9,91 +9,212 @@ description: | The moreLikeThis operator allows you to build features for your applications that display similar or alternative results based on one or more given documents. arguments: - - - name: like - type: - - object - - array # of object - - - name: score - optional: true - type: - - searchScore + - name: like + type: + - object + - array + - name: score + optional: true + type: + - searchScore tests: - - - name: 'Single Document with Multiple Fields' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/morelikethis/#example-1--single-document-with-multiple-fields' - pipeline: - - - $search: - moreLikeThis: - like: - title: 'The Godfather' - genres: 'action' - - - $limit: 5 - - - $project: - _id: 0 - title: 1 - released: 1 - genres: 1 - - - - name: 'Input Document Excluded in Results' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/morelikethis/#example-2--input-document-excluded-in-results' - pipeline: - - - $search: - compound: - must: - - - moreLikeThis: - like: - _id: !bson_objectId '573a1396f29313caabce4a9a' - genres: - - 'Crime' - - 'Drama' - title: 'The Godfather' - mustNot: - - - equals: - path: '_id' - value: !bson_objectId '573a1396f29313caabce4a9a' - - - $limit: 5 - - - $project: - _id: 1 - title: 1 - released: 1 - genres: 1 - - - - name: 'Multiple Analyzers' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/morelikethis/#example-3--multiple-analyzers' - pipeline: - - - $search: - compound: - should: - - - moreLikeThis: - like: - _id: !bson_objectId '573a1396f29313caabce4a9a' - genres: - - 'Crime' - - 'Drama' - title: 'The Godfather' - mustNot: - - - equals: - path: '_id' - value: !bson_objectId '573a1394f29313caabcde9ef' - - - $limit: 10 - - - $project: - title: 1 - genres: 1 - _id: 1 + - name: Single Document with Multiple Fields + link: https://www.mongodb.com/docs/atlas/atlas-search/morelikethis/#example-1--single-document-with-multiple-fields + pipeline: + - $search: + moreLikeThis: + like: + title: The Godfather + genres: action + - $limit: 5 + - $project: + _id: 0 + title: 1 + released: 1 + genres: 1 + schema: + movies: &ref_0 + _id: + types: + - bsonType: Document + fields: + $oid: + types: + - bsonType: String + title: + types: + - bsonType: String + year: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + runtime: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + released: + types: + - bsonType: Document + fields: + $date: + types: + - bsonType: Document + fields: + $numberLong: + types: + - bsonType: String + poster: + types: + - bsonType: String + plot: + types: + - bsonType: String + fullplot: + types: + - bsonType: String + lastupdated: + types: + - bsonType: String + type: + types: + - bsonType: String + directors: + types: + - bsonType: Array + types: + - bsonType: String + imdb: + types: + - bsonType: Document + fields: + rating: + types: + - bsonType: Document + fields: + $numberDouble: + types: + - bsonType: String + votes: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + id: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + cast: + types: + - bsonType: Array + types: + - bsonType: String + countries: + types: + - bsonType: Array + types: + - bsonType: String + genres: + types: + - bsonType: Array + types: + - bsonType: String + tomatoes: + types: + - bsonType: Document + fields: + viewer: + types: + - bsonType: Document + fields: + rating: + types: + - bsonType: Document + fields: + $numberDouble: + types: + - bsonType: String + numReviews: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + lastUpdated: + types: + - bsonType: Document + fields: + $date: + types: + - bsonType: Document + fields: + $numberLong: + types: + - bsonType: String + num_mflix_comments: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + - name: Input Document Excluded in Results + link: https://www.mongodb.com/docs/atlas/atlas-search/morelikethis/#example-2--input-document-excluded-in-results + pipeline: + - $search: + compound: + must: + - moreLikeThis: + like: + _id: !bson_objectId 573a1396f29313caabce4a9a + genres: + - Crime + - Drama + title: The Godfather + mustNot: + - equals: + path: _id + value: !bson_objectId 573a1396f29313caabce4a9a + - $limit: 5 + - $project: + _id: 1 + title: 1 + released: 1 + genres: 1 + schema: + movies: *ref_0 + - name: Multiple Analyzers + link: https://www.mongodb.com/docs/atlas/atlas-search/morelikethis/#example-3--multiple-analyzers + pipeline: + - $search: + compound: + should: + - moreLikeThis: + like: + _id: !bson_objectId 573a1396f29313caabce4a9a + genres: + - Crime + - Drama + title: The Godfather + mustNot: + - equals: + path: _id + value: !bson_objectId 573a1394f29313caabcde9ef + - $limit: 10 + - $project: + title: 1 + genres: 1 + _id: 1 + schema: + movies: *ref_0 diff --git a/generator/config/search/near.yaml b/generator/config/search/near.yaml index bd4119cf9..2c00ae424 100644 --- a/generator/config/search/near.yaml +++ b/generator/config/search/near.yaml @@ -1,124 +1,639 @@ # $schema: ../schema.json name: near -link: 'https://www.mongodb.com/docs/atlas/atlas-search/near/' +link: https://www.mongodb.com/docs/atlas/atlas-search/near/ type: - searchOperator encode: object description: | The near operator supports querying and scoring numeric, date, and GeoJSON point values. arguments: - - - name: path - type: - - searchPath - - - name: origin - type: - - date - - number - - geometry - - - name: pivot - type: - - number - - - name: score - optional: true - type: - - searchScore + - name: path + type: + - searchPath + - name: origin + type: + - date + - number + - geometry + - name: pivot + type: + - number + - name: score + optional: true + type: + - searchScore tests: - - - name: 'Number' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/near/#number-example' - pipeline: - - - $search: - index: 'runtimes' - near: - path: 'runtime' - origin: 279 - pivot: 2 - - - $limit: 7 - - - $project: - _id: 0 - title: 1 - runtime: 1 - score: - $meta: 'searchScore' - - - - name: 'Date' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/near/#date-example' - pipeline: - - - $search: - index: 'releaseddate' - near: - path: 'released' - origin: !bson_utcdatetime '1915-09-13T00:00:00.000+00:00' - pivot: 7776000000 - - - $limit: 3 - - - $project: - _id: 0 - title: 1 - released: 1 - score: - $meta: 'searchScore' - - - - name: 'GeoJSON Point' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/near/#geojson-point-examples' - pipeline: - - - $search: - near: - origin: - type: 'Point' - coordinates: - - -8.61308 - - 41.1413 - pivot: 1000 - path: 'address.location' - - - $limit: 3 - - - $project: - _id: 0 - name: 1 - address: 1 - score: - $meta: 'searchScore' - - - - name: 'Compound' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/near/#compound-example' - pipeline: - - - $search: - compound: - must: - text: - query: 'Apartment' - path: 'property_type' - should: - near: - origin: - type: 'Point' - coordinates: - - 114.15027 - - 22.28158 - pivot: 1000 - path: 'address.location' - - - $limit: 3 - - - $project: - _id: 0 - property_type: 1 - address: 1 - score: - $meta: 'searchScore' + - name: Number + link: https://www.mongodb.com/docs/atlas/atlas-search/near/#number-example + pipeline: + - $search: + index: runtimes + near: + path: runtime + origin: 279 + pivot: 2 + - $limit: 7 + - $project: + _id: 0 + title: 1 + runtime: 1 + score: + $meta: searchScore + schema: + movies: &ref_0 + _id: + types: + - bsonType: Document + fields: + $oid: + types: + - bsonType: String + title: + types: + - bsonType: String + year: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + runtime: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + released: + types: + - bsonType: Document + fields: + $date: + types: + - bsonType: Document + fields: + $numberLong: + types: + - bsonType: String + poster: + types: + - bsonType: String + plot: + types: + - bsonType: String + fullplot: + types: + - bsonType: String + lastupdated: + types: + - bsonType: String + type: + types: + - bsonType: String + directors: + types: + - bsonType: Array + types: + - bsonType: String + imdb: + types: + - bsonType: Document + fields: + rating: + types: + - bsonType: Document + fields: + $numberDouble: + types: + - bsonType: String + votes: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + id: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + cast: + types: + - bsonType: Array + types: + - bsonType: String + countries: + types: + - bsonType: Array + types: + - bsonType: String + genres: + types: + - bsonType: Array + types: + - bsonType: String + tomatoes: + types: + - bsonType: Document + fields: + viewer: + types: + - bsonType: Document + fields: + rating: + types: + - bsonType: Document + fields: + $numberDouble: + types: + - bsonType: String + numReviews: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + lastUpdated: + types: + - bsonType: Document + fields: + $date: + types: + - bsonType: Document + fields: + $numberLong: + types: + - bsonType: String + num_mflix_comments: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + - name: Date + link: https://www.mongodb.com/docs/atlas/atlas-search/near/#date-example + pipeline: + - $search: + index: releaseddate + near: + path: released + origin: !bson_utcdatetime '1915-09-13T00:00:00.000Z' + pivot: 7776000000 + - $limit: 3 + - $project: + _id: 0 + title: 1 + released: 1 + score: + $meta: searchScore + schema: + movies: *ref_0 + - name: GeoJSON Point + link: https://www.mongodb.com/docs/atlas/atlas-search/near/#geojson-point-examples + pipeline: + - $search: + near: + origin: + type: Point + coordinates: + - -8.61308 + - 41.1413 + pivot: 1000 + path: address.location + - $limit: 3 + - $project: + _id: 0 + name: 1 + address: 1 + score: + $meta: searchScore + schema: + listingsAndReviews: &ref_1 + _id: + types: + - bsonType: String + listing_url: + types: + - bsonType: String + name: + types: + - bsonType: String + summary: + types: + - bsonType: String + interaction: + types: + - bsonType: String + house_rules: + types: + - bsonType: String + property_type: + types: + - bsonType: String + room_type: + types: + - bsonType: String + bed_type: + types: + - bsonType: String + minimum_nights: + types: + - bsonType: String + maximum_nights: + types: + - bsonType: String + cancellation_policy: + types: + - bsonType: String + last_scraped: + types: + - bsonType: Document + fields: + $date: + types: + - bsonType: Document + fields: + $numberLong: + types: + - bsonType: String + calendar_last_scraped: + types: + - bsonType: Document + fields: + $date: + types: + - bsonType: Document + fields: + $numberLong: + types: + - bsonType: String + first_review: + types: + - bsonType: Document + fields: + $date: + types: + - bsonType: Document + fields: + $numberLong: + types: + - bsonType: String + last_review: + types: + - bsonType: Document + fields: + $date: + types: + - bsonType: Document + fields: + $numberLong: + types: + - bsonType: String + accommodates: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + bedrooms: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + beds: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + number_of_reviews: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + bathrooms: + types: + - bsonType: Document + fields: + $numberDecimal: + types: + - bsonType: String + amenities: + types: + - bsonType: Array + types: + - bsonType: String + price: + types: + - bsonType: Document + fields: + $numberDecimal: + types: + - bsonType: String + security_deposit: + types: + - bsonType: Document + fields: + $numberDecimal: + types: + - bsonType: String + cleaning_fee: + types: + - bsonType: Document + fields: + $numberDecimal: + types: + - bsonType: String + extra_people: + types: + - bsonType: Document + fields: + $numberDecimal: + types: + - bsonType: String + guests_included: + types: + - bsonType: Document + fields: + $numberDecimal: + types: + - bsonType: String + images: + types: + - bsonType: Document + fields: + thumbnail_url: + types: + - bsonType: String + medium_url: + types: + - bsonType: String + picture_url: + types: + - bsonType: String + xl_picture_url: + types: + - bsonType: String + host: + types: + - bsonType: Document + fields: + host_id: + types: + - bsonType: String + host_url: + types: + - bsonType: String + host_name: + types: + - bsonType: String + host_location: + types: + - bsonType: String + host_about: + types: + - bsonType: String + host_response_time: + types: + - bsonType: String + host_thumbnail_url: + types: + - bsonType: String + host_picture_url: + types: + - bsonType: String + host_neighbourhood: + types: + - bsonType: String + host_response_rate: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + host_is_superhost: + types: + - bsonType: Boolean + host_has_profile_pic: + types: + - bsonType: Boolean + host_identity_verified: + types: + - bsonType: Boolean + host_listings_count: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + host_total_listings_count: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + host_verifications: + types: + - bsonType: Array + types: + - bsonType: String + address: + types: + - bsonType: Document + fields: + street: + types: + - bsonType: String + suburb: + types: + - bsonType: String + government_area: + types: + - bsonType: String + market: + types: + - bsonType: String + country: + types: + - bsonType: String + country_code: + types: + - bsonType: String + location: + types: + - bsonType: Document + fields: + type: + types: + - bsonType: String + coordinates: + types: + - bsonType: Array + types: + - bsonType: Document + fields: + $numberDouble: + types: + - bsonType: String + is_location_exact: + types: + - bsonType: Boolean + availability: + types: + - bsonType: Document + fields: + availability_30: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + availability_60: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + availability_90: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + availability_365: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + review_scores: + types: + - bsonType: Document + fields: + review_scores_accuracy: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + review_scores_cleanliness: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + review_scores_checkin: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + review_scores_communication: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + review_scores_location: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + review_scores_value: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + review_scores_rating: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + reviews: + types: + - bsonType: Array + types: + - bsonType: Document + fields: + _id: + types: + - bsonType: String + date: + types: + - bsonType: Document + fields: + $date: + types: + - bsonType: Document + fields: + $numberLong: + types: + - bsonType: String + listing_id: + types: + - bsonType: String + reviewer_id: + types: + - bsonType: String + reviewer_name: + types: + - bsonType: String + comments: + types: + - bsonType: String + - name: Compound + link: https://www.mongodb.com/docs/atlas/atlas-search/near/#compound-example + pipeline: + - $search: + compound: + must: + text: + query: Apartment + path: property_type + should: + near: + origin: + type: Point + coordinates: + - 114.15027 + - 22.28158 + pivot: 1000 + path: address.location + - $limit: 3 + - $project: + _id: 0 + property_type: 1 + address: 1 + score: + $meta: searchScore + schema: + listingsAndReviews: *ref_1 diff --git a/generator/config/search/phrase.yaml b/generator/config/search/phrase.yaml index 4d9b75c4e..63c1ad5d4 100644 --- a/generator/config/search/phrase.yaml +++ b/generator/config/search/phrase.yaml @@ -1,109 +1,229 @@ # $schema: ../schema.json name: phrase -link: 'https://www.mongodb.com/docs/atlas/atlas-search/phrase/' +link: https://www.mongodb.com/docs/atlas/atlas-search/phrase/ type: - searchOperator encode: object description: | The phrase operator performs search for documents containing an ordered sequence of terms using the analyzer specified in the index configuration. arguments: - - - name: path - type: - - searchPath - - - name: query - type: - - string - - array # of string - - - name: slop - optional: true - type: - - int - - - name: synonyms - optional: true - type: - - string - - - name: score - optional: true - type: - - searchScore + - name: path + type: + - searchPath + - name: query + type: + - string + - array + - name: slop + optional: true + type: + - int + - name: synonyms + optional: true + type: + - string + - name: score + optional: true + type: + - searchScore tests: - - - name: 'Single Phrase' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/phrase/#single-phrase-example' - pipeline: - - - $search: - phrase: - path: 'title' - query: 'new york' - - - $limit: 10 - - - $project: - _id: 0 - title: 1 - score: - $meta: 'searchScore' - - - - name: 'Multiple Phrase' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/phrase/#multiple-phrases-example' - pipeline: - - - $search: - phrase: - path: 'title' - query: - - 'the man' - - 'the moon' - - - $limit: 10 - - - $project: - _id: 0 - title: 1 - score: - $meta: 'searchScore' - - - - name: 'Phrase Slop' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/phrase/#slop-example' - pipeline: - - - $search: - phrase: - path: 'title' - query: 'men women' - slop: 5 - - - $project: - _id: 0 - title: 1 - score: - $meta: 'searchScore' - - - - name: 'Phrase Synonyms' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/phrase/#synonyms-example' - 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' + - name: Single Phrase + link: https://www.mongodb.com/docs/atlas/atlas-search/phrase/#single-phrase-example + pipeline: + - $search: + phrase: + path: title + query: new york + - $limit: 10 + - $project: + _id: 0 + title: 1 + score: + $meta: searchScore + schema: + movies: &ref_0 + _id: + types: + - bsonType: Document + fields: + $oid: + types: + - bsonType: String + title: + types: + - bsonType: String + year: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + runtime: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + released: + types: + - bsonType: Document + fields: + $date: + types: + - bsonType: Document + fields: + $numberLong: + types: + - bsonType: String + poster: + types: + - bsonType: String + plot: + types: + - bsonType: String + fullplot: + types: + - bsonType: String + lastupdated: + types: + - bsonType: String + type: + types: + - bsonType: String + directors: + types: + - bsonType: Array + types: + - bsonType: String + imdb: + types: + - bsonType: Document + fields: + rating: + types: + - bsonType: Document + fields: + $numberDouble: + types: + - bsonType: String + votes: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + id: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + cast: + types: + - bsonType: Array + types: + - bsonType: String + countries: + types: + - bsonType: Array + types: + - bsonType: String + genres: + types: + - bsonType: Array + types: + - bsonType: String + tomatoes: + types: + - bsonType: Document + fields: + viewer: + types: + - bsonType: Document + fields: + rating: + types: + - bsonType: Document + fields: + $numberDouble: + types: + - bsonType: String + numReviews: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + lastUpdated: + types: + - bsonType: Document + fields: + $date: + types: + - bsonType: Document + fields: + $numberLong: + types: + - bsonType: String + num_mflix_comments: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + - name: Multiple Phrase + link: https://www.mongodb.com/docs/atlas/atlas-search/phrase/#multiple-phrases-example + pipeline: + - $search: + phrase: + path: title + query: + - the man + - the moon + - $limit: 10 + - $project: + _id: 0 + title: 1 + score: + $meta: searchScore + schema: + movies: *ref_0 + - name: Phrase Slop + link: https://www.mongodb.com/docs/atlas/atlas-search/phrase/#slop-example + pipeline: + - $search: + phrase: + path: title + query: men women + slop: 5 + - $project: + _id: 0 + title: 1 + score: + $meta: searchScore + schema: + movies: *ref_0 + - name: Phrase Synonyms + link: https://www.mongodb.com/docs/atlas/atlas-search/phrase/#synonyms-example + 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 + schema: + movies: *ref_0 diff --git a/generator/config/search/queryString.yaml b/generator/config/search/queryString.yaml index 8202771c9..e3625270a 100644 --- a/generator/config/search/queryString.yaml +++ b/generator/config/search/queryString.yaml @@ -1,35 +1,162 @@ # $schema: ../schema.json name: queryString -link: 'https://www.mongodb.com/docs/atlas/atlas-search/queryString/' +link: https://www.mongodb.com/docs/atlas/atlas-search/queryString/ type: - searchOperator encode: object -description: | - +description: '' arguments: - - - name: defaultPath - type: - - searchPath - - - name: query - type: - - string - -# The various example from the doc are variations of the "query" parameter -# this is not pertinent for testing the aggregation builder, unless we create -# a queryString builder. + - name: defaultPath + type: + - searchPath + - name: query + type: + - string tests: - - - name: 'Boolean Operator Queries' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/queryString/#boolean-operator-queries' - pipeline: - - - $search: - queryString: - defaultPath: 'title' - query: 'Rocky AND (IV OR 4 OR Four)' - - - $project: - _id: 0 - title: 1 + - name: Boolean Operator Queries + link: https://www.mongodb.com/docs/atlas/atlas-search/queryString/#boolean-operator-queries + pipeline: + - $search: + queryString: + defaultPath: title + query: Rocky AND (IV OR 4 OR Four) + - $project: + _id: 0 + title: 1 + schema: + movies: + _id: + types: + - bsonType: Document + fields: + $oid: + types: + - bsonType: String + title: + types: + - bsonType: String + year: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + runtime: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + released: + types: + - bsonType: Document + fields: + $date: + types: + - bsonType: Document + fields: + $numberLong: + types: + - bsonType: String + poster: + types: + - bsonType: String + plot: + types: + - bsonType: String + fullplot: + types: + - bsonType: String + lastupdated: + types: + - bsonType: String + type: + types: + - bsonType: String + directors: + types: + - bsonType: Array + types: + - bsonType: String + imdb: + types: + - bsonType: Document + fields: + rating: + types: + - bsonType: Document + fields: + $numberDouble: + types: + - bsonType: String + votes: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + id: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + cast: + types: + - bsonType: Array + types: + - bsonType: String + countries: + types: + - bsonType: Array + types: + - bsonType: String + genres: + types: + - bsonType: Array + types: + - bsonType: String + tomatoes: + types: + - bsonType: Document + fields: + viewer: + types: + - bsonType: Document + fields: + rating: + types: + - bsonType: Document + fields: + $numberDouble: + types: + - bsonType: String + numReviews: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + lastUpdated: + types: + - bsonType: Document + fields: + $date: + types: + - bsonType: Document + fields: + $numberLong: + types: + - bsonType: String + num_mflix_comments: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String diff --git a/generator/config/search/range.yaml b/generator/config/search/range.yaml index f42c69176..da8226537 100644 --- a/generator/config/search/range.yaml +++ b/generator/config/search/range.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: range -link: 'https://www.mongodb.com/docs/atlas/atlas-search/range/' +link: https://www.mongodb.com/docs/atlas/atlas-search/range/ type: - searchOperator encode: object @@ -8,132 +8,248 @@ description: | 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. arguments: - - - name: path - type: - - searchPath - - - name: gt - optional: true - type: - - date - - number - - string - - objectId - - - name: gte - optional: true - type: - - date - - number - - string - - objectId - - - name: lt - optional: true - type: - - date - - number - - string - - objectId - - - name: lte - optional: true - type: - - date - - number - - string - - objectId - - - name: score - optional: true - type: - - searchScore + - name: path + type: + - searchPath + - name: gt + optional: true + type: + - date + - number + - string + - objectId + - name: gte + optional: true + type: + - date + - number + - string + - objectId + - name: lt + optional: true + type: + - date + - number + - string + - objectId + - name: lte + optional: true + type: + - date + - number + - string + - objectId + - name: score + optional: true + type: + - searchScore tests: - - - name: 'Number gte lte' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/range/#number-example' - pipeline: - - - $search: - range: - path: 'runtime' - gte: 2 - lte: 3 - - - $limit: 5 - - - $project: - _id: 0 - title: 1 - runtime: 1 - - - - name: 'Number lte' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/range/#number-example' - pipeline: - - - $search: - range: - path: 'runtime' - lte: 2 - - - $limit: 5 - - - $project: - _id: 0 - title: 1 - runtime: 1 - score: - $meta: 'searchScore' - - - - name: 'Date' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/range/#date-example' - pipeline: - - - $search: - range: - path: 'released' - gt: !bson_utcdatetime '2010-01-01T00:00:00.000Z' - lt: !bson_utcdatetime '2015-01-01T00:00:00.000Z' - - - $limit: 5 - - - $project: - _id: 0 - title: 1 - released: 1 - - - - name: 'ObjectId' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/range/#objectid-example' - pipeline: - - - $search: - range: - path: '_id' - gte: !bson_objectId '573a1396f29313caabce4a9a' - lte: !bson_objectId '573a1396f29313caabce4ae7' - - - $project: - _id: 1 - title: 1 - released: 1 - - - - name: 'String' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/range/#string-example' - pipeline: - - - $search: - range: - path: 'title' - gt: 'city' - lt: 'country' - - - $limit: 5 - - - $project: - _id: 0 - title: 1 + - name: Number gte lte + link: https://www.mongodb.com/docs/atlas/atlas-search/range/#number-example + pipeline: + - $search: + range: + path: runtime + gte: 2 + lte: 3 + - $limit: 5 + - $project: + _id: 0 + title: 1 + runtime: 1 + schema: + movies: &ref_0 + _id: + types: + - bsonType: Document + fields: + $oid: + types: + - bsonType: String + title: + types: + - bsonType: String + year: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + runtime: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + released: + types: + - bsonType: Document + fields: + $date: + types: + - bsonType: Document + fields: + $numberLong: + types: + - bsonType: String + poster: + types: + - bsonType: String + plot: + types: + - bsonType: String + fullplot: + types: + - bsonType: String + lastupdated: + types: + - bsonType: String + type: + types: + - bsonType: String + directors: + types: + - bsonType: Array + types: + - bsonType: String + imdb: + types: + - bsonType: Document + fields: + rating: + types: + - bsonType: Document + fields: + $numberDouble: + types: + - bsonType: String + votes: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + id: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + cast: + types: + - bsonType: Array + types: + - bsonType: String + countries: + types: + - bsonType: Array + types: + - bsonType: String + genres: + types: + - bsonType: Array + types: + - bsonType: String + tomatoes: + types: + - bsonType: Document + fields: + viewer: + types: + - bsonType: Document + fields: + rating: + types: + - bsonType: Document + fields: + $numberDouble: + types: + - bsonType: String + numReviews: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + lastUpdated: + types: + - bsonType: Document + fields: + $date: + types: + - bsonType: Document + fields: + $numberLong: + types: + - bsonType: String + num_mflix_comments: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + - name: Number lte + link: https://www.mongodb.com/docs/atlas/atlas-search/range/#number-example + pipeline: + - $search: + range: + path: runtime + lte: 2 + - $limit: 5 + - $project: + _id: 0 + title: 1 + runtime: 1 + score: + $meta: searchScore + schema: + movies: *ref_0 + - name: Date + link: https://www.mongodb.com/docs/atlas/atlas-search/range/#date-example + pipeline: + - $search: + range: + path: released + gt: !bson_utcdatetime '2010-01-01T00:00:00.000Z' + lt: !bson_utcdatetime '2015-01-01T00:00:00.000Z' + - $limit: 5 + - $project: + _id: 0 + title: 1 + released: 1 + schema: + movies: *ref_0 + - name: ObjectId + link: https://www.mongodb.com/docs/atlas/atlas-search/range/#objectid-example + pipeline: + - $search: + range: + path: _id + gte: !bson_objectId 573a1396f29313caabce4a9a + lte: !bson_objectId 573a1396f29313caabce4ae7 + - $project: + _id: 1 + title: 1 + released: 1 + schema: + movies: *ref_0 + - name: String + link: https://www.mongodb.com/docs/atlas/atlas-search/range/#string-example + pipeline: + - $search: + range: + path: title + gt: city + lt: country + - $limit: 5 + - $project: + _id: 0 + title: 1 + schema: + movies: *ref_0 diff --git a/generator/config/search/regex.yaml b/generator/config/search/regex.yaml index 869ffabde..028bc364d 100644 --- a/generator/config/search/regex.yaml +++ b/generator/config/search/regex.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: regex -link: 'https://www.mongodb.com/docs/atlas/atlas-search/regex/' +link: https://www.mongodb.com/docs/atlas/atlas-search/regex/ type: - searchOperator encode: object @@ -8,35 +8,165 @@ description: | regex interprets the query field as a regular expression. regex is a term-level operator, meaning that the query field isn't analyzed. arguments: - - - name: path - type: - - searchPath - - - name: query - type: - - string - - - name: allowAnalyzedField - optional: true - type: - - bool - - - name: score - optional: true - type: - - searchScore + - name: path + type: + - searchPath + - name: query + type: + - string + - name: allowAnalyzedField + optional: true + type: + - bool + - name: score + optional: true + type: + - searchScore tests: - - - name: 'Regex' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/regex/#examples' - pipeline: - - - $search: - regex: - path: 'title' - query: '[0-9]{2} (.){4}s' - - - $project: - _id: 0 - title: 1 + - name: Regex + link: https://www.mongodb.com/docs/atlas/atlas-search/regex/#examples + pipeline: + - $search: + regex: + path: title + query: '[0-9]{2} (.){4}s' + - $project: + _id: 0 + title: 1 + schema: + movies: + _id: + types: + - bsonType: Document + fields: + $oid: + types: + - bsonType: String + title: + types: + - bsonType: String + year: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + runtime: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + released: + types: + - bsonType: Document + fields: + $date: + types: + - bsonType: Document + fields: + $numberLong: + types: + - bsonType: String + poster: + types: + - bsonType: String + plot: + types: + - bsonType: String + fullplot: + types: + - bsonType: String + lastupdated: + types: + - bsonType: String + type: + types: + - bsonType: String + directors: + types: + - bsonType: Array + types: + - bsonType: String + imdb: + types: + - bsonType: Document + fields: + rating: + types: + - bsonType: Document + fields: + $numberDouble: + types: + - bsonType: String + votes: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + id: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + cast: + types: + - bsonType: Array + types: + - bsonType: String + countries: + types: + - bsonType: Array + types: + - bsonType: String + genres: + types: + - bsonType: Array + types: + - bsonType: String + tomatoes: + types: + - bsonType: Document + fields: + viewer: + types: + - bsonType: Document + fields: + rating: + types: + - bsonType: Document + fields: + $numberDouble: + types: + - bsonType: String + numReviews: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + lastUpdated: + types: + - bsonType: Document + fields: + $date: + types: + - bsonType: Document + fields: + $numberLong: + types: + - bsonType: String + num_mflix_comments: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String diff --git a/generator/config/search/text.yaml b/generator/config/search/text.yaml index dbd48cdd0..1ef63552f 100644 --- a/generator/config/search/text.yaml +++ b/generator/config/search/text.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: text -link: 'https://www.mongodb.com/docs/atlas/atlas-search/text/' +link: https://www.mongodb.com/docs/atlas/atlas-search/text/ type: - searchOperator encode: object @@ -8,187 +8,296 @@ description: | 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. arguments: - - - name: path - type: - - searchPath - - - name: query - type: - - string - - - name: fuzzy - optional: true - type: - - object - - - name: matchCriteria - optional: true - type: - - string # "any" | "all" - - - name: synonyms - optional: true - type: - - string - - - name: score - optional: true - type: - - searchScore + - name: path + type: + - searchPath + - name: query + type: + - string + - name: fuzzy + optional: true + type: + - object + - name: matchCriteria + optional: true + type: + - string + - name: synonyms + optional: true + type: + - string + - name: score + optional: true + type: + - searchScore tests: - - - name: 'Basic' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/text/#basic-example' - pipeline: - - - $search: - text: - path: 'title' - query: 'surfer' - - - $project: - _id: 0 - title: 1 - score: - $meta: 'searchScore' - - - name: 'Fuzzy Default' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/text/#fuzzy-examples' - pipeline: - - - $search: - text: - path: 'title' - query: 'naw yark' - fuzzy: {} - - - $limit: 10 - - - $project: - _id: 0 - title: 1 - score: - $meta: 'searchScore' - - - - name: 'Fuzzy maxExpansions' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/text/#fuzzy-examples' - pipeline: - - - $search: - text: - path: 'title' - query: 'naw yark' - fuzzy: - maxEdits: 1 - maxExpansions: 100 - - - $limit: 10 - - - $project: - _id: 0 - title: 1 - score: - $meta: 'searchScore' - - - - name: 'Fuzzy prefixLength' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/text/#fuzzy-examples' - pipeline: - - - $search: - text: - path: 'title' - query: 'naw yark' - fuzzy: - maxEdits: 1 - prefixLength: 2 - - - $limit: 8 - - - $project: - _id: 1 - title: 1 - score: - $meta: 'searchScore' - - - - name: 'Match any Using equivalent Mapping' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/text/#match-any-using-equivalent-mapping' - pipeline: - - - $search: - text: - path: 'plot' - query: 'attire' - synonyms: 'my_synonyms' - matchCriteria: 'any' - - - $limit: 5 - - - $project: - _id: 0 - plot: 1 - title: 1 - score: - $meta: 'searchScore' - - - - name: 'Match any Using explicit Mapping' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/text/#match-any-using-explicit-mapping' - 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' - - - - name: 'Match all Using Synonyms' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/text/#match-all-using-synonyms' - 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' - - - - name: 'Wildcard Path' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/text/' - pipeline: - - - $search: - text: - path: - wildcard: '*' - query: 'surfer' - - - $project: - _id: 0 - title: 1 - score: - $meta: 'searchScore' + - name: Basic + link: https://www.mongodb.com/docs/atlas/atlas-search/text/#basic-example + pipeline: + - $search: + text: + path: title + query: surfer + - $project: + _id: 0 + title: 1 + score: + $meta: searchScore + schema: + movies: &ref_0 + _id: + types: + - bsonType: Document + fields: + $oid: + types: + - bsonType: String + title: + types: + - bsonType: String + year: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + runtime: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + released: + types: + - bsonType: Document + fields: + $date: + types: + - bsonType: Document + fields: + $numberLong: + types: + - bsonType: String + poster: + types: + - bsonType: String + plot: + types: + - bsonType: String + fullplot: + types: + - bsonType: String + lastupdated: + types: + - bsonType: String + type: + types: + - bsonType: String + directors: + types: + - bsonType: Array + types: + - bsonType: String + imdb: + types: + - bsonType: Document + fields: + rating: + types: + - bsonType: Document + fields: + $numberDouble: + types: + - bsonType: String + votes: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + id: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + cast: + types: + - bsonType: Array + types: + - bsonType: String + countries: + types: + - bsonType: Array + types: + - bsonType: String + genres: + types: + - bsonType: Array + types: + - bsonType: String + tomatoes: + types: + - bsonType: Document + fields: + viewer: + types: + - bsonType: Document + fields: + rating: + types: + - bsonType: Document + fields: + $numberDouble: + types: + - bsonType: String + numReviews: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + lastUpdated: + types: + - bsonType: Document + fields: + $date: + types: + - bsonType: Document + fields: + $numberLong: + types: + - bsonType: String + num_mflix_comments: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + - name: Fuzzy Default + link: https://www.mongodb.com/docs/atlas/atlas-search/text/#fuzzy-examples + pipeline: + - $search: + text: + path: title + query: naw yark + fuzzy: {} + - $limit: 10 + - $project: + _id: 0 + title: 1 + score: + $meta: searchScore + schema: + movies: *ref_0 + - name: Fuzzy maxExpansions + link: https://www.mongodb.com/docs/atlas/atlas-search/text/#fuzzy-examples + pipeline: + - $search: + text: + path: title + query: naw yark + fuzzy: + maxEdits: 1 + maxExpansions: 100 + - $limit: 10 + - $project: + _id: 0 + title: 1 + score: + $meta: searchScore + schema: + movies: *ref_0 + - name: Fuzzy prefixLength + link: https://www.mongodb.com/docs/atlas/atlas-search/text/#fuzzy-examples + pipeline: + - $search: + text: + path: title + query: naw yark + fuzzy: + maxEdits: 1 + prefixLength: 2 + - $limit: 8 + - $project: + _id: 1 + title: 1 + score: + $meta: searchScore + schema: + movies: *ref_0 + - name: Match any Using equivalent Mapping + link: https://www.mongodb.com/docs/atlas/atlas-search/text/#match-any-using-equivalent-mapping + pipeline: + - $search: + text: + path: plot + query: attire + synonyms: my_synonyms + matchCriteria: any + - $limit: 5 + - $project: + _id: 0 + plot: 1 + title: 1 + score: + $meta: searchScore + schema: + movies: *ref_0 + - name: Match any Using explicit Mapping + link: https://www.mongodb.com/docs/atlas/atlas-search/text/#match-any-using-explicit-mapping + 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 + schema: + movies: *ref_0 + - name: Match all Using Synonyms + link: https://www.mongodb.com/docs/atlas/atlas-search/text/#match-all-using-synonyms + 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 + schema: + movies: *ref_0 + - name: Wildcard Path + link: https://www.mongodb.com/docs/atlas/atlas-search/text/ + pipeline: + - $search: + text: + path: + wildcard: '*' + query: surfer + - $project: + _id: 0 + title: 1 + score: + $meta: searchScore + schema: + movies: *ref_0 diff --git a/generator/config/search/wildcard.yaml b/generator/config/search/wildcard.yaml index d17fb4803..9e66395ef 100644 --- a/generator/config/search/wildcard.yaml +++ b/generator/config/search/wildcard.yaml @@ -1,60 +1,186 @@ # $schema: ../schema.json name: wildcard -link: 'https://www.mongodb.com/docs/atlas/atlas-search/wildcard/' +link: https://www.mongodb.com/docs/atlas/atlas-search/wildcard/ type: - searchOperator encode: object description: | The wildcard operator enables queries which use special characters in the search string that can match any character. arguments: - - - name: path - type: - - searchPath - - - name: query - type: - - string - - - name: allowAnalyzedField - optional: true - type: - - bool - - - name: score - optional: true - type: - - searchScore + - name: path + type: + - searchPath + - name: query + type: + - string + - name: allowAnalyzedField + optional: true + type: + - bool + - name: score + optional: true + type: + - searchScore tests: - - - name: 'Wildcard Path' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/wildcard/#index-definition' - pipeline: - - - $search: - wildcard: - query: 'Wom?n *' - path: - wildcard: '*' - - - $limit: 5 - - - $project: - _id: 0 - title: 1 - - - - name: 'Escape Character Example' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/wildcard/#escape-character-example' - pipeline: - - - $search: - wildcard: - query: '*\?' - path: 'title' - - - $limit: 5 - - - $project: - _id: 0 - title: 1 + - name: Wildcard Path + link: https://www.mongodb.com/docs/atlas/atlas-search/wildcard/#index-definition + pipeline: + - $search: + wildcard: + query: Wom?n * + path: + wildcard: '*' + - $limit: 5 + - $project: + _id: 0 + title: 1 + schema: + movies: &ref_0 + _id: + types: + - bsonType: Document + fields: + $oid: + types: + - bsonType: String + title: + types: + - bsonType: String + year: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + runtime: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + released: + types: + - bsonType: Document + fields: + $date: + types: + - bsonType: Document + fields: + $numberLong: + types: + - bsonType: String + poster: + types: + - bsonType: String + plot: + types: + - bsonType: String + fullplot: + types: + - bsonType: String + lastupdated: + types: + - bsonType: String + type: + types: + - bsonType: String + directors: + types: + - bsonType: Array + types: + - bsonType: String + imdb: + types: + - bsonType: Document + fields: + rating: + types: + - bsonType: Document + fields: + $numberDouble: + types: + - bsonType: String + votes: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + id: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + cast: + types: + - bsonType: Array + types: + - bsonType: String + countries: + types: + - bsonType: Array + types: + - bsonType: String + genres: + types: + - bsonType: Array + types: + - bsonType: String + tomatoes: + types: + - bsonType: Document + fields: + viewer: + types: + - bsonType: Document + fields: + rating: + types: + - bsonType: Document + fields: + $numberDouble: + types: + - bsonType: String + numReviews: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + lastUpdated: + types: + - bsonType: Document + fields: + $date: + types: + - bsonType: Document + fields: + $numberLong: + types: + - bsonType: String + num_mflix_comments: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + - name: Escape Character Example + link: https://www.mongodb.com/docs/atlas/atlas-search/wildcard/#escape-character-example + pipeline: + - $search: + wildcard: + query: '*\?' + path: title + - $limit: 5 + - $project: + _id: 0 + title: 1 + schema: + movies: *ref_0 diff --git a/generator/config/stage/addFields.yaml b/generator/config/stage/addFields.yaml index e98f5de18..1a4ee3a56 100644 --- a/generator/config/stage/addFields.yaml +++ b/generator/config/stage/addFields.yaml @@ -1,64 +1,123 @@ # $schema: ../schema.json name: $addFields -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/addFields/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/addFields/ type: - stage encode: single description: | Adds new fields to documents. Outputs documents that contain all existing fields from the input documents and newly added fields. arguments: - - - name: expression - type: - - expression - variadic: object - description: | - Specify the name of each field to add and set its value to an aggregation expression or an empty object. + - name: expression + type: + - expression + variadic: object + description: | + Specify the name of each field to add and set its value to an aggregation expression or an empty object. tests: - - - name: 'Using Two $addFields Stages' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/addFields/#using-two--addfields-stages' - pipeline: - - - $addFields: - totalHomework: - # The example renders a single value, but the builder generates an array for consistency - # $sum: '$homework' - $sum: ['$homework'] - totalQuiz: - # $sum: '$quiz' - $sum: ['$quiz'] - - - $addFields: - totalScore: - $add: - - '$totalHomework' - - '$totalQuiz' - - '$extraCredit' - - - name: 'Adding Fields to an Embedded Document' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/addFields/#adding-fields-to-an-embedded-document' - pipeline: - - - $addFields: - specs.fuel_type: 'unleaded' - - - name: 'Overwriting an existing field' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/addFields/#overwriting-an-existing-field' - pipeline: - - - $addFields: - cats: 20 - - - name: 'Add Element to an Array' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/addFields/#add-element-to-an-array' - pipeline: - - - $match: - _id: 1 - - - $addFields: - homework: - $concatArrays: - - '$homework' - - [7] + - name: Using Two $addFields Stages + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/addFields/#using-two--addfields-stages + pipeline: + - $addFields: + totalHomework: + $sum: + - $homework + totalQuiz: + $sum: + - $quiz + - $addFields: + totalScore: + $add: + - $totalHomework + - $totalQuiz + - $extraCredit + schema: + scores: + _id: + types: + - bsonType: Number + student: + types: + - bsonType: String + homework: + types: + - bsonType: Array + types: + - bsonType: Number + quiz: + types: + - bsonType: Array + types: + - bsonType: Number + extraCredit: + types: + - bsonType: Number + - name: Adding Fields to an Embedded Document + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/addFields/#adding-fields-to-an-embedded-document + pipeline: + - $addFields: + specs.fuel_type: unleaded + schema: + vehicles: + _id: + types: + - bsonType: Number + type: + types: + - bsonType: String + specs: + types: + - bsonType: Document + fields: + doors: + types: + - bsonType: Number + wheels: + types: + - bsonType: Number + - name: Overwriting an existing field + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/addFields/#overwriting-an-existing-field + pipeline: + - $addFields: + cats: 20 + schema: + animals: + _id: + types: + - bsonType: Number + dogs: + types: + - bsonType: Number + cats: + types: + - bsonType: Number + - name: Add Element to an Array + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/addFields/#add-element-to-an-array + pipeline: + - $match: + _id: 1 + - $addFields: + homework: + $concatArrays: + - $homework + - - 7 + schema: + scores: + _id: + types: + - bsonType: Number + student: + types: + - bsonType: String + homework: + types: + - bsonType: Array + types: + - bsonType: Number + quiz: + types: + - bsonType: Array + types: + - bsonType: Number + extraCredit: + types: + - bsonType: Number diff --git a/generator/config/stage/bucket.yaml b/generator/config/stage/bucket.yaml index 0cd65feac..e6bdeeb32 100644 --- a/generator/config/stage/bucket.yaml +++ b/generator/config/stage/bucket.yaml @@ -1,101 +1,139 @@ # $schema: ../schema.json name: $bucket -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/bucket/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/bucket/ type: - stage encode: object description: | Categorizes incoming documents into groups, called buckets, based on a specified expression and bucket boundaries. arguments: - - - name: groupBy - type: - - expression # mainly fieldPath - description: | - An expression to group documents by. To specify a field path, prefix the field name with a dollar sign $ and enclose it in quotes. - Unless $bucket includes a default specification, each input document must resolve the groupBy field path or expression to a value that falls within one of the ranges specified by the boundaries. - - - name: boundaries - type: - - array # of expression - description: | - An array of values based on the groupBy expression that specify the boundaries for each bucket. Each adjacent pair of values acts as the inclusive lower boundary and the exclusive upper boundary for the bucket. You must specify at least two boundaries. - The specified values must be in ascending order and all of the same type. The exception is if the values are of mixed numeric types, such as: - - - name: default - type: - - expression - optional: true - description: | - A literal that specifies the _id of an additional bucket that contains all documents whose groupBy expression result does not fall into a bucket specified by boundaries. - If unspecified, each input document must resolve the groupBy expression to a value within one of the bucket ranges specified by boundaries or the operation throws an error. - The default value must be less than the lowest boundaries value, or greater than or equal to the highest boundaries value. - The default value can be of a different type than the entries in boundaries. - - - name: output - type: - - object # of Accumulator - optional: true - description: | - A document that specifies the fields to include in the output documents in addition to the _id field. To specify the field to include, you must use accumulator expressions. - If you do not specify an output document, the operation returns a count field containing the number of documents in each bucket. - If you specify an output document, only the fields specified in the document are returned; i.e. the count field is not returned unless it is explicitly included in the output document. + - name: groupBy + type: + - expression + description: | + An expression to group documents by. To specify a field path, prefix the field name with a dollar sign $ and enclose it in quotes. + Unless $bucket includes a default specification, each input document must resolve the groupBy field path or expression to a value that falls within one of the ranges specified by the boundaries. + - name: boundaries + type: + - array + description: | + An array of values based on the groupBy expression that specify the boundaries for each bucket. Each adjacent pair of values acts as the inclusive lower boundary and the exclusive upper boundary for the bucket. You must specify at least two boundaries. + The specified values must be in ascending order and all of the same type. The exception is if the values are of mixed numeric types, such as: + - name: default + type: + - expression + optional: true + description: | + A literal that specifies the _id of an additional bucket that contains all documents whose groupBy expression result does not fall into a bucket specified by boundaries. + If unspecified, each input document must resolve the groupBy expression to a value within one of the bucket ranges specified by boundaries or the operation throws an error. + The default value must be less than the lowest boundaries value, or greater than or equal to the highest boundaries value. + The default value can be of a different type than the entries in boundaries. + - name: output + type: + - object + optional: true + description: | + A document that specifies the fields to include in the output documents in addition to the _id field. To specify the field to include, you must use accumulator expressions. + If you do not specify an output document, the operation returns a count field containing the number of documents in each bucket. + If you specify an output document, only the fields specified in the document are returned; i.e. the count field is not returned unless it is explicitly included in the output document. tests: - - - name: 'Bucket by Year and Filter by Bucket Results' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/bucket/#bucket-by-year-and-filter-by-bucket-results' - 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' - - - $match: + - name: Bucket by Year and Filter by Bucket Results + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/bucket/#bucket-by-year-and-filter-by-bucket-results + pipeline: + - $bucket: + groupBy: $year_born + boundaries: + - 1840 + - 1850 + - 1860 + - 1870 + - 1880 + default: Other + output: count: - $gt: 3 - - - name: 'Use $bucket with $facet to Bucket by Multiple Fields' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/bucket/#use--bucket-with--facet-to-bucket-by-multiple-fields' - 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' + $sum: 1 + artists: + $push: + name: + $concat: + - $first_name + - ' ' + - $last_name + year_born: $year_born + - $match: + count: + $gt: 3 + schema: + artists: + _id: + types: + - bsonType: Number + last_name: + types: + - bsonType: String + first_name: + types: + - bsonType: String + year_born: + types: + - bsonType: Number + year_died: + types: + - bsonType: Number + nationality: + types: + - bsonType: String + - name: Use $bucket with $facet to Bucket by Multiple Fields + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/bucket/#use--bucket-with--facet-to-bucket-by-multiple-fields + 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 + schema: + artwork: + _id: + types: + - bsonType: Number + title: + types: + - bsonType: String + artist: + types: + - bsonType: String + year: + types: + - bsonType: Number + price: + types: + - bsonType: Decimal128 diff --git a/generator/config/stage/bucketAuto.yaml b/generator/config/stage/bucketAuto.yaml index 73775fde8..e064995ab 100644 --- a/generator/config/stage/bucketAuto.yaml +++ b/generator/config/stage/bucketAuto.yaml @@ -1,46 +1,70 @@ # $schema: ../schema.json name: $bucketAuto -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/bucketAuto/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/bucketAuto/ type: - stage encode: object description: | 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. arguments: - - - name: groupBy - type: - - expression - description: | - An expression to group documents by. To specify a field path, prefix the field name with a dollar sign $ and enclose it in quotes. - - - name: buckets - type: - - int - description: | - A positive 32-bit integer that specifies the number of buckets into which input documents are grouped. - - - name: output - type: - - object # of Accumulator - optional: true - description: | - A document that specifies the fields to include in the output documents in addition to the _id field. To specify the field to include, you must use accumulator expressions. - The default count field is not included in the output document when output is specified. Explicitly specify the count expression as part of the output document to include it. - - - name: granularity - type: - - granularity - optional: true - description: | - A string that specifies the preferred number series to use to ensure that the calculated boundary edges end on preferred round numbers or their powers of 10. - Available only if the all groupBy values are numeric and none of them are NaN. + - name: groupBy + type: + - expression + description: | + An expression to group documents by. To specify a field path, prefix the field name with a dollar sign $ and enclose it in quotes. + - name: buckets + type: + - int + description: | + A positive 32-bit integer that specifies the number of buckets into which input documents are grouped. + - name: output + type: + - object + optional: true + description: | + A document that specifies the fields to include in the output documents in addition to the _id field. To specify the field to include, you must use accumulator expressions. + The default count field is not included in the output document when output is specified. Explicitly specify the count expression as part of the output document to include it. + - name: granularity + type: + - granularity + optional: true + description: | + A string that specifies the preferred number series to use to ensure that the calculated boundary edges end on preferred round numbers or their powers of 10. + Available only if the all groupBy values are numeric and none of them are NaN. tests: - - - name: 'Single Facet Aggregation' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/bucketAuto/#single-facet-aggregation' - pipeline: - - - $bucketAuto: - groupBy: '$price' - buckets: 4 + - name: Single Facet Aggregation + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/bucketAuto/#single-facet-aggregation + pipeline: + - $bucketAuto: + groupBy: $price + buckets: 4 + schema: + artwork: + _id: + types: + - bsonType: Int32 + title: + types: + - bsonType: String + artist: + types: + - bsonType: String + year: + types: + - bsonType: Int32 + price: + types: + - bsonType: Decimal128 + dimensions: + types: + - bsonType: Document + fields: + height: + types: + - bsonType: Int32 + width: + types: + - bsonType: Int32 + units: + types: + - bsonType: String diff --git a/generator/config/stage/changeStream.yaml b/generator/config/stage/changeStream.yaml index be413ef5d..d7518d4a5 100644 --- a/generator/config/stage/changeStream.yaml +++ b/generator/config/stage/changeStream.yaml @@ -1,66 +1,62 @@ # $schema: ../schema.json name: $changeStream -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/changeStream/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/changeStream/ type: - stage encode: object description: | 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. arguments: - - - name: allChangesForCluster - type: - - bool - optional: true - description: | - A flag indicating whether the stream should report all changes that occur on the deployment, aside from those on internal databases or collections. - - - name: fullDocument - type: - - fullDocument - optional: true - description: | - Specifies whether change notifications include a copy of the full document when modified by update operations. - - - name: fullDocumentBeforeChange - type: - - fullDocumentBeforeChange - optional: true - description: | - Valid values are "off", "whenAvailable", or "required". If set to "off", the "fullDocumentBeforeChange" field of the output document is always omitted. If set to "whenAvailable", the "fullDocumentBeforeChange" field will be populated with the pre-image of the document modified by the current change event if such a pre-image is available, and will be omitted otherwise. If set to "required", then the "fullDocumentBeforeChange" field is always populated and an exception is thrown if the pre-image is not available. - - - name: resumeAfter - type: - - int - optional: true - description: | - Specifies a resume token as the logical starting point for the change stream. Cannot be used with startAfter or startAtOperationTime fields. - - - name: showExpandedEvents - type: - - bool - optional: true - description: | - Specifies whether to include additional change events, such as such as DDL and index operations. - New in MongoDB 6.0. - - - name: startAfter - type: - - object - optional: true - description: | - Specifies a resume token as the logical starting point for the change stream. Cannot be used with resumeAfter or startAtOperationTime fields. - - - name: startAtOperationTime - type: - - timestamp - optional: true - description: | - Specifies a time as the logical starting point for the change stream. Cannot be used with resumeAfter or startAfter fields. + - name: allChangesForCluster + type: + - bool + optional: true + description: | + A flag indicating whether the stream should report all changes that occur on the deployment, aside from those on internal databases or collections. + - name: fullDocument + type: + - fullDocument + optional: true + description: | + Specifies whether change notifications include a copy of the full document when modified by update operations. + - name: fullDocumentBeforeChange + type: + - fullDocumentBeforeChange + optional: true + description: | + Valid values are "off", "whenAvailable", or "required". If set to "off", the "fullDocumentBeforeChange" field of the output document is always omitted. If set to "whenAvailable", the "fullDocumentBeforeChange" field will be populated with the pre-image of the document modified by the current change event if such a pre-image is available, and will be omitted otherwise. If set to "required", then the "fullDocumentBeforeChange" field is always populated and an exception is thrown if the pre-image is not available. + - name: resumeAfter + type: + - int + optional: true + description: | + Specifies a resume token as the logical starting point for the change stream. Cannot be used with startAfter or startAtOperationTime fields. + - name: showExpandedEvents + type: + - bool + optional: true + description: | + Specifies whether to include additional change events, such as such as DDL and index operations. + New in MongoDB 6.0. + - name: startAfter + type: + - object + optional: true + description: | + Specifies a resume token as the logical starting point for the change stream. Cannot be used with resumeAfter or startAtOperationTime fields. + - name: startAtOperationTime + type: + - timestamp + optional: true + description: | + Specifies a time as the logical starting point for the change stream. Cannot be used with resumeAfter or startAfter fields. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/changeStream/#examples' - pipeline: - - - $changeStream: {} + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/changeStream/#examples + pipeline: + - $changeStream: {} + schema: + names: + _id: + types: + - bsonType: ObjectId diff --git a/generator/config/stage/changeStreamSplitLargeEvent.yaml b/generator/config/stage/changeStreamSplitLargeEvent.yaml index 208129346..6d2440306 100644 --- a/generator/config/stage/changeStreamSplitLargeEvent.yaml +++ b/generator/config/stage/changeStreamSplitLargeEvent.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $changeStreamSplitLargeEvent -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/changeStreamSplitLargeEvent/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/changeStreamSplitLargeEvent/ type: - stage encode: object @@ -8,9 +8,15 @@ description: | 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. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/changeStreamSplitLargeEvent/#example' - pipeline: - - - $changeStreamSplitLargeEvent: {} + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/changeStreamSplitLargeEvent/#example + pipeline: + - $changeStreamSplitLargeEvent: {} + schema: + myCollection: + _id: + types: + - bsonType: Int32 + largeField: + types: + - bsonType: String diff --git a/generator/config/stage/collStats.yaml b/generator/config/stage/collStats.yaml index 26cbbc470..e3e70114f 100644 --- a/generator/config/stage/collStats.yaml +++ b/generator/config/stage/collStats.yaml @@ -1,59 +1,58 @@ # $schema: ../schema.json name: $collStats -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/collStats/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/collStats/ type: - stage encode: object description: | Returns statistics regarding a collection or view. arguments: - - - name: latencyStats - type: - - object - optional: true - - - name: storageStats - type: - - object - optional: true - - - name: count - type: - - object # empty object - optional: true - - - name: queryExecStats - type: - - object # empty object - optional: true + - name: latencyStats + type: + - object + optional: true + - name: storageStats + type: + - object + optional: true + - name: count + type: + - object + optional: true + - name: queryExecStats + type: + - object + optional: true tests: - - - name: 'latencyStats Document' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/collStats/#latencystats-document' - pipeline: - - - $collStats: - latencyStats: - histograms: true - - - name: 'storageStats Document' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/collStats/#storagestats-document' - pipeline: - - - $collStats: - storageStats: {} - - - name: 'count Field' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/collStats/#count-field' - pipeline: - - - $collStats: - count: {} - - - name: 'queryExecStats Document' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/collStats/#queryexecstats-document' - pipeline: - - - $collStats: - queryExecStats: {} + - name: latencyStats Document + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/collStats/#latencystats-document + pipeline: + - $collStats: + latencyStats: + histograms: true + schema: + TestCollection: &ref_0 + _id: + types: + - bsonType: ObjectId + - name: storageStats Document + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/collStats/#storagestats-document + pipeline: + - $collStats: + storageStats: {} + schema: + TestCollection: *ref_0 + - name: count Field + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/collStats/#count-field + pipeline: + - $collStats: + count: {} + schema: + TestCollection: *ref_0 + - name: queryExecStats Document + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/collStats/#queryexecstats-document + pipeline: + - $collStats: + queryExecStats: {} + schema: + TestCollection: *ref_0 diff --git a/generator/config/stage/count.yaml b/generator/config/stage/count.yaml index a0fa3ba57..a9dc2a581 100644 --- a/generator/config/stage/count.yaml +++ b/generator/config/stage/count.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $count -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/count/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/count/ type: - stage encode: single @@ -8,20 +8,27 @@ description: | Returns a count of the number of documents at this stage of the aggregation pipeline. Distinct from the $count aggregation accumulator. arguments: - - - name: field - type: - - string - description: | - Name of the output field which has the count as its value. It must be a non-empty string, must not start with $ and must not contain the . character. + - name: field + type: + - string + description: | + Name of the output field which has the count as its value. It must be a non-empty string, must not start with $ and must not contain the . character. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/count/#example' - pipeline: - - - $match: - score: - $gt: 80 - - - $count: 'passing_scores' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/count/#examples + pipeline: + - $match: + score: + $gt: 80 + - $count: passing_scores + schema: + scores: + _id: + types: + - bsonType: Number + subject: + types: + - bsonType: String + score: + types: + - bsonType: Number diff --git a/generator/config/stage/currentOp.yaml b/generator/config/stage/currentOp.yaml index 024c71318..a6ea9620b 100644 --- a/generator/config/stage/currentOp.yaml +++ b/generator/config/stage/currentOp.yaml @@ -1,59 +1,55 @@ # $schema: ../schema.json name: $currentOp -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/currentOp/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/currentOp/ type: - stage encode: object description: | Returns information on active and/or dormant operations for the MongoDB deployment. To run, use the db.aggregate() method. arguments: - - - name: allUsers - type: - - bool - optional: true - - - name: idleConnections - type: - - bool - optional: true - - - name: idleCursors - type: - - bool - optional: true - - - name: idleSessions - type: - - bool - optional: true - - - name: localOps - type: - - bool - optional: true + - name: allUsers + type: + - bool + optional: true + - name: idleConnections + type: + - bool + optional: true + - name: idleCursors + type: + - bool + optional: true + - name: idleSessions + type: + - bool + optional: true + - name: localOps + type: + - bool + optional: true tests: - - - name: 'Inactive Sessions' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/currentOp/#inactive-sessions' - pipeline: - - - $currentOp: - allUsers: true - idleSessions: true - - - $match: - active: false - transaction: - $exists: true - - - name: 'Sampled Queries' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/currentOp/#sampled-queries' - pipeline: - - - $currentOp: - allUsers: true - localOps: true - - - $match: - desc: 'query analyzer' + - name: Inactive Sessions + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/currentOp/#inactive-sessions + pipeline: + - $currentOp: + allUsers: true + idleSessions: true + - $match: + active: false + transaction: + $exists: true + schema: + TestCollection: &ref_0 + _id: + types: + - bsonType: ObjectId + - name: Sampled Queries + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/currentOp/#sampled-queries + pipeline: + - $currentOp: + allUsers: true + localOps: true + - $match: + desc: query analyzer + schema: + TestCollection: *ref_0 diff --git a/generator/config/stage/densify.yaml b/generator/config/stage/densify.yaml index 46ccbd6dd..50c0330bc 100644 --- a/generator/config/stage/densify.yaml +++ b/generator/config/stage/densify.yaml @@ -1,56 +1,81 @@ # $schema: ../schema.json name: $densify -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/densify/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/densify/ type: - stage encode: object description: | Creates new documents in a sequence of documents where certain values in a field are missing. arguments: - - - name: field - type: - - string # field name - description: | - The field to densify. The values of the specified field must either be all numeric values or all dates. - Documents that do not contain the specified field continue through the pipeline unmodified. - To specify a in an embedded document or in an array, use dot notation. - - - name: partitionByFields - type: - - array # of string - optional: true - description: | - The field(s) that will be used as the partition keys. - - - name: range - type: - - range - description: | - Specification for range based densification. + - name: field + type: + - string + description: | + The field to densify. The values of the specified field must either be all numeric values or all dates. + Documents that do not contain the specified field continue through the pipeline unmodified. + To specify a in an embedded document or in an array, use dot notation. + - name: partitionByFields + type: + - array + optional: true + description: | + The field(s) that will be used as the partition keys. + - name: range + type: + - range + description: | + Specification for range based densification. tests: - - - name: 'Densify Time Series Data' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/densify/#densify-time-series-data' - pipeline: - - - $densify: - field: 'timestamp' - range: - step: 1 - unit: 'hour' - bounds: - - !bson_utcdatetime '2021-05-18T00:00:00.000Z' - - !bson_utcdatetime '2021-05-18T08:00:00.000Z' - - - name: 'Densifiction with Partitions' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/densify/#densifiction-with-partitions' - pipeline: - - - $densify: - field: 'altitude' - partitionByFields: - - 'variety' - range: - bounds: 'full' - step: 200 + - name: Densify Time Series Data + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/densify/#densify-time-series-data + pipeline: + - $densify: + field: timestamp + range: + step: 1 + unit: hour + bounds: + - !bson_utcdatetime '2021-05-18T00:00:00.000Z' + - !bson_utcdatetime '2021-05-18T08:00:00.000Z' + schema: + weather: + metadata: + types: + - bsonType: Document + fields: + sensorId: + types: + - bsonType: Number + type: + types: + - bsonType: String + timestamp: + types: + - bsonType: Date + temp: + types: + - bsonType: Number + - name: Densifiction with Partitions + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/densify/#densification-with-partitions + pipeline: + - $densify: + field: altitude + partitionByFields: + - variety + range: + bounds: full + step: 200 + schema: + coffee: + altitude: + types: + - bsonType: Number + variety: + types: + - bsonType: String + score: + types: + - bsonType: Number + price: + types: + - bsonType: Number diff --git a/generator/config/stage/documents.yaml b/generator/config/stage/documents.yaml index 666468da8..1f9ec211f 100644 --- a/generator/config/stage/documents.yaml +++ b/generator/config/stage/documents.yaml @@ -1,53 +1,56 @@ # $schema: ../schema.json name: $documents -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/documents/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/documents/ type: - stage encode: single description: | Returns literal documents from input values. arguments: - - - name: documents - type: - - resolvesToArray # of object - description: | - $documents accepts any valid expression that resolves to an array of objects. This includes: - - system variables, such as $$NOW or $$SEARCH_META - - $let expressions - - variables in scope from $lookup expressions - Expressions that do not resolve to a current document, like $myField or $$ROOT, will result in an error. + - name: documents + type: + - resolvesToArray + description: | + $documents accepts any valid expression that resolves to an array of objects. This includes: + - system variables, such as $$NOW or $$SEARCH_META + - $let expressions + - variables in scope from $lookup expressions + Expressions that do not resolve to a current document, like $myField or $$ROOT, will result in an error. tests: - - - name: 'Test a Pipeline Stage' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/documents/#test-a-pipeline-stage' - pipeline: - - - $documents: - - { x: 10 } - - { x: 2 } - - { x: 5 } - - - $bucketAuto: - groupBy: '$x' - buckets: 4 - - - name: 'Use a $documents Stage in a $lookup Stage' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/documents/#use-a--documents-stage-in-a--lookup-stage' - 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' + - name: Test a Pipeline Stage + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/documents/#test-a-pipeline-stage + pipeline: + - $documents: + - x: 10 + - x: 2 + - x: 5 + - $bucketAuto: + groupBy: $x + buckets: 4 + schema: + TestCollection: + x: + types: + - bsonType: Number + - name: Use a $documents Stage in a $lookup Stage + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/documents/#use-a--documents-stage-in-a--lookup-stage + 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 + schema: + locations: + zip: + types: + - bsonType: Number + name: + types: + - bsonType: String diff --git a/generator/config/stage/facet.yaml b/generator/config/stage/facet.yaml index 013163c2a..33dc9cb49 100644 --- a/generator/config/stage/facet.yaml +++ b/generator/config/stage/facet.yaml @@ -1,51 +1,66 @@ # $schema: ../schema.json name: $facet -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/facet/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/facet/ type: - stage encode: single description: | 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. arguments: - - - name: facet - type: - - pipeline - variadic: object + - name: facet + type: + - pipeline + variadic: object tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/facet/#example' - pipeline: - - - $facet: - categorizedByTags: - - - # The builder uses the verbose form of the $unwind operator - # $unwind: '$tags' - $unwind: - path: '$tags' - - - $sortByCount: '$tags' - categorizedByPrice: - - - $match: - price: - # The example uses an int, but the builder requires a bool - # $exists: 1 - $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 + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/facet/#example + 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 + schema: + artwork: + _id: + types: + - bsonType: Number + title: + types: + - bsonType: String + artist: + types: + - bsonType: String + year: + types: + - bsonType: Number + price: + types: + - bsonType: Decimal128 + tags: + types: + - bsonType: Array + types: + - bsonType: String diff --git a/generator/config/stage/fill.yaml b/generator/config/stage/fill.yaml index 2c98fac5c..8a0256997 100644 --- a/generator/config/stage/fill.yaml +++ b/generator/config/stage/fill.yaml @@ -1,110 +1,143 @@ # $schema: ../schema.json name: $fill -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/fill/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/fill/ type: - stage encode: object description: | Populates null and missing field values within documents. arguments: - - - name: partitionBy - type: - - object # of expression - - string - optional: true - description: | - Specifies an expression to group the documents. In the $fill stage, a group of documents is known as a partition. - If you omit partitionBy and partitionByFields, $fill uses one partition for the entire collection. - partitionBy and partitionByFields are mutually exclusive. - - - name: partitionByFields - type: - - array # of string - optional: true - description: | - Specifies an array of fields as the compound key to group the documents. In the $fill stage, each group of documents is known as a partition. - If you omit partitionBy and partitionByFields, $fill uses one partition for the entire collection. - partitionBy and partitionByFields are mutually exclusive. - - - name: sortBy - type: - - sortBy - optional: true - description: | - Specifies the field or fields to sort the documents within each partition. Uses the same syntax as the $sort stage. - - - name: output - type: - - object # of object{value:expression} or object{method:string}> - description: | - Specifies an object containing each field for which to fill missing values. You can specify multiple fields in the output object. - The object name is the name of the field to fill. The object value specifies how the field is filled. + - name: partitionBy + type: + - object + - string + optional: true + description: | + Specifies an expression to group the documents. In the $fill stage, a group of documents is known as a partition. + If you omit partitionBy and partitionByFields, $fill uses one partition for the entire collection. + partitionBy and partitionByFields are mutually exclusive. + - name: partitionByFields + type: + - array + optional: true + description: | + Specifies an array of fields as the compound key to group the documents. In the $fill stage, each group of documents is known as a partition. + If you omit partitionBy and partitionByFields, $fill uses one partition for the entire collection. + partitionBy and partitionByFields are mutually exclusive. + - name: sortBy + type: + - sortBy + optional: true + description: | + Specifies the field or fields to sort the documents within each partition. Uses the same syntax as the $sort stage. + - name: output + type: + - object + description: | + Specifies an object containing each field for which to fill missing values. You can specify multiple fields in the output object. + The object name is the name of the field to fill. The object value specifies how the field is filled. tests: - - - name: 'Fill Missing Field Values with a Constant Value' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/fill/#fill-missing-field-values-with-a-constant-value' - pipeline: - - - $fill: - output: - bootsSold: - value: 0 - sandalsSold: - value: 0 - sneakersSold: - value: 0 - - - name: 'Fill Missing Field Values with Linear Interpolation' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/fill/#fill-missing-field-values-with-linear-interpolation' - pipeline: - - - $fill: - sortBy: - time: 1 - output: - price: - method: 'linear' - - - name: 'Fill Missing Field Values Based on the Last Observed Value' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/fill/#fill-missing-field-values-based-on-the-last-observed-value' - pipeline: - - - $fill: - sortBy: - date: 1 - output: - score: - method: 'locf' - - - name: 'Fill Data for Distinct Partitions' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/fill/#fill-data-for-distinct-partitions' - pipeline: - - - $fill: - sortBy: - date: 1 - partitionBy: - restaurant: '$restaurant' - output: - score: - method: 'locf' - - - name: 'Indicate if a Field was Populated Using $fill' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/fill/#indicate-if-a-field-was-populated-using--fill' - pipeline: - - - $set: - valueExisted: - $ifNull: - - - $toBool: - $toString: '$score' - - false - - - $fill: - sortBy: - date: 1 - output: - score: - method: 'locf' + - name: Fill Missing Field Values with a Constant Value + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/fill/#fill-missing-field-values-with-a-constant-value + pipeline: + - $fill: + output: + bootsSold: + value: 0 + sandalsSold: + value: 0 + sneakersSold: + value: 0 + schema: + dailySales: + date: + types: + - bsonType: Date + bootsSold: + types: + - bsonType: Number + sandalsSold: + types: + - bsonType: Number + sneakersSold: + types: + - bsonType: Number + - name: Fill Missing Field Values with Linear Interpolation + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/fill/#fill-missing-field-values-with-linear-interpolation + pipeline: + - $fill: + sortBy: + time: 1 + output: + price: + method: linear + schema: + stock: + time: + types: + - bsonType: Date + price: + types: + - bsonType: Number + - name: Fill Missing Field Values Based on the Last Observed Value + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/fill/#fill-missing-field-values-based-on-the-last-observed-value + pipeline: + - $fill: + sortBy: + date: 1 + output: + score: + method: locf + schema: + restaurantReviews: + date: + types: + - bsonType: Date + score: + types: + - bsonType: Number + - name: Fill Data for Distinct Partitions + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/fill/#fill-data-for-distinct-partitions + pipeline: + - $fill: + sortBy: + date: 1 + partitionBy: + restaurant: $restaurant + output: + score: + method: locf + schema: + restaurantReviewsMultiple: + date: + types: + - bsonType: Date + restaurant: + types: + - bsonType: String + score: + types: + - bsonType: Number + - name: Indicate if a Field was Populated Using $fill + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/fill/#indicate-if-a-field-was-populated-using--fill + pipeline: + - $set: + valueExisted: + $ifNull: + - $toBool: + $toString: $score + - false + - $fill: + sortBy: + date: 1 + output: + score: + method: locf + schema: + restaurantReviews: + date: + types: + - bsonType: Date + score: + types: + - bsonType: Number diff --git a/generator/config/stage/geoNear.yaml b/generator/config/stage/geoNear.yaml index 4967a0823..e4f1a53a7 100644 --- a/generator/config/stage/geoNear.yaml +++ b/generator/config/stage/geoNear.yaml @@ -1,161 +1,247 @@ # $schema: ../schema.json name: $geoNear -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/geoNear/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/geoNear/ type: - stage encode: object description: | 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. arguments: - - - name: distanceField - type: - - string - optional: true - description: | - The output field that contains the calculated distance. To specify a field within an embedded document, use dot notation. - - - name: distanceMultiplier - type: - - number - optional: true - description: | - The factor to multiply all distances returned by the query. For example, use the distanceMultiplier to convert radians, as returned by a spherical query, to kilometers by multiplying by the radius of the Earth. - - - name: includeLocs - type: - - string - optional: true - description: | - This specifies the output field that identifies the location used to calculate the distance. This option is useful when a location field contains multiple locations. To specify a field within an embedded document, use dot notation. - - - name: key - type: - - string - optional: true - description: | - Specify the geospatial indexed field to use when calculating the distance. - - - name: maxDistance - type: - - number - optional: true - description: | - The maximum distance from the center point that the documents can be. MongoDB limits the results to those documents that fall within the specified distance from the center point. - Specify the distance in meters if the specified point is GeoJSON and in radians if the specified point is legacy coordinate pairs. - - - name: minDistance - type: - - number - optional: true - description: | - The minimum distance from the center point that the documents can be. MongoDB limits the results to those documents that fall outside the specified distance from the center point. - Specify the distance in meters for GeoJSON data and in radians for legacy coordinate pairs. - - - name: near - type: - - geoPoint - - resolvesToObject - description: | - The point for which to find the closest documents. - - - name: query - type: - - query - optional: true - description: | - Limits the results to the documents that match the query. The query syntax is the usual MongoDB read operation query syntax. - You cannot specify a $near predicate in the query field of the $geoNear stage. - - - name: spherical - type: - - bool - optional: true - description: | - Determines how MongoDB calculates the distance between two points: - - When true, MongoDB uses $nearSphere semantics and calculates distances using spherical geometry. - - When false, MongoDB uses $near semantics: spherical geometry for 2dsphere indexes and planar geometry for 2d indexes. - Default: false. + - name: distanceField + type: + - string + optional: true + description: | + The output field that contains the calculated distance. To specify a field within an embedded document, use dot notation. + - name: distanceMultiplier + type: + - number + optional: true + description: | + The factor to multiply all distances returned by the query. For example, use the distanceMultiplier to convert radians, as returned by a spherical query, to kilometers by multiplying by the radius of the Earth. + - name: includeLocs + type: + - string + optional: true + description: | + This specifies the output field that identifies the location used to calculate the distance. This option is useful when a location field contains multiple locations. To specify a field within an embedded document, use dot notation. + - name: key + type: + - string + optional: true + description: | + Specify the geospatial indexed field to use when calculating the distance. + - name: maxDistance + type: + - number + optional: true + description: | + The maximum distance from the center point that the documents can be. MongoDB limits the results to those documents that fall within the specified distance from the center point. + Specify the distance in meters if the specified point is GeoJSON and in radians if the specified point is legacy coordinate pairs. + - name: minDistance + type: + - number + optional: true + description: | + The minimum distance from the center point that the documents can be. MongoDB limits the results to those documents that fall outside the specified distance from the center point. + Specify the distance in meters for GeoJSON data and in radians for legacy coordinate pairs. + - name: near + type: + - geoPoint + - resolvesToObject + description: | + The point for which to find the closest documents. + - name: query + type: + - query + optional: true + description: | + Limits the results to the documents that match the query. The query syntax is the usual MongoDB read operation query syntax. + You cannot specify a $near predicate in the query field of the $geoNear stage. + - name: spherical + type: + - bool + optional: true + description: | + Determines how MongoDB calculates the distance between two points: + - When true, MongoDB uses $nearSphere semantics and calculates distances using spherical geometry. + - When false, MongoDB uses $near semantics: spherical geometry for 2dsphere indexes and planar geometry for 2d indexes. + Default: false. tests: - - - name: 'Maximum Distance' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/geoNear/#maximum-distance' - pipeline: - - - $geoNear: - near: - type: 'Point' - coordinates: - - -73.99279 - - 40.719296 - distanceField: 'dist.calculated' - maxDistance: 2 - query: - category: 'Parks' - includeLocs: 'dist.location' - spherical: true - - - name: 'Minimum Distance' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/geoNear/#minimum-distance' - pipeline: - - - $geoNear: - near: - type: 'Point' - coordinates: - - -73.99279 - - 40.719296 - distanceField: 'dist.calculated' - minDistance: 2 - query: - category: 'Parks' - includeLocs: 'dist.location' - spherical: true - - - name: 'with the let option' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/geoNear/#-geonear-with-the-let-option' - pipeline: - - - $geoNear: - near: '$$pt' - distanceField: 'distance' - maxDistance: 2 - query: - category: 'Parks' - includeLocs: 'dist.location' - spherical: true - - - name: 'with Bound let Option' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/geoNear/#-geonear-with-bound-let-option' - pipeline: - - - $lookup: - from: 'places' - let: - pt: '$location' - pipeline: - - - $geoNear: - near: '$$pt' - distanceField: 'distance' - as: 'joinedField' - - - $match: - name: 'Sara D. Roosevelt Park' - - - name: 'Specify Which Geospatial Index to Use' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/geoNear/#specify-which-geospatial-index-to-use' - pipeline: - - - $geoNear: - near: - type: 'Point' - coordinates: - - -73.98142 - - 40.71782 - key: 'location' - distanceField: 'dist.calculated' - query: - category: 'Parks' - - - $limit: 5 + - name: Maximum Distance + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/geoNear/#maximum-distance + pipeline: + - $geoNear: + near: + type: Point + coordinates: + - -73.99279 + - 40.719296 + distanceField: dist.calculated + maxDistance: 2 + query: + category: Parks + includeLocs: dist.location + spherical: true + schema: + places: + name: + types: + - bsonType: String + location: + types: + - bsonType: Document + fields: + type: + types: + - bsonType: String + coordinates: + types: + - bsonType: Array + types: + - bsonType: Number + category: + types: + - bsonType: String + - name: Minimum Distance + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/geoNear/#minimum-distance + pipeline: + - $geoNear: + near: + type: Point + coordinates: + - -73.99279 + - 40.719296 + distanceField: dist.calculated + minDistance: 2 + query: + category: Parks + includeLocs: dist.location + spherical: true + schema: + places: + name: + types: + - bsonType: String + location: + types: + - bsonType: Document + fields: + type: + types: + - bsonType: String + coordinates: + types: + - bsonType: Array + types: + - bsonType: Number + category: + types: + - bsonType: String + - name: with the let option + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/geoNear/#-geonear-with-the-let-option + pipeline: + - $geoNear: + near: $$pt + distanceField: distance + maxDistance: 2 + query: + category: Parks + includeLocs: dist.location + spherical: true + schema: + places: + name: + types: + - bsonType: String + location: + types: + - bsonType: Document + fields: + type: + types: + - bsonType: String + coordinates: + types: + - bsonType: Array + types: + - bsonType: Number + category: + types: + - bsonType: String + - name: with Bound let Option + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/geoNear/#-geonear-with-bound-let-option + pipeline: + - $lookup: + from: places + let: + pt: $location + pipeline: + - $geoNear: + near: $$pt + distanceField: distance + as: joinedField + - $match: + name: Sara D. Roosevelt Park + schema: + places: + name: + types: + - bsonType: String + location: + types: + - bsonType: Document + fields: + type: + types: + - bsonType: String + coordinates: + types: + - bsonType: Array + types: + - bsonType: Number + category: + types: + - bsonType: String + - name: Specify Which Geospatial Index to Use + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/geoNear/#specify-which-geospatial-index-to-use + pipeline: + - $geoNear: + near: + type: Point + coordinates: + - -73.98142 + - 40.71782 + key: location + distanceField: dist.calculated + query: + category: Parks + - $limit: 5 + schema: + places: + _id: + types: + - bsonType: Number + name: + types: + - bsonType: String + location: + types: + - bsonType: Document + fields: + type: + types: + - bsonType: String + coordinates: + types: + - bsonType: Array + types: + - bsonType: Number + legacy: + types: + - bsonType: Array + types: + - bsonType: Number + category: + types: + - bsonType: String diff --git a/generator/config/stage/graphLookup.yaml b/generator/config/stage/graphLookup.yaml index ae220620b..0d38e8b22 100644 --- a/generator/config/stage/graphLookup.yaml +++ b/generator/config/stage/graphLookup.yaml @@ -1,108 +1,134 @@ # $schema: ../schema.json name: $graphLookup -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/graphLookup/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/graphLookup/ type: - stage encode: object description: | 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. arguments: - - - name: from - type: - - string - description: | - Target collection for the $graphLookup operation to search, recursively matching the connectFromField to the connectToField. The from collection must be in the same database as any other collections used in the operation. - Starting in MongoDB 5.1, the collection specified in the from parameter can be sharded. - - - name: startWith - type: - - expression - - array - description: | - 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. - - - name: connectFromField - type: - - string - description: | - 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. - - - name: connectToField - type: - - string - description: | - Field name in other documents against which to match the value of the field specified by the connectFromField parameter. - - - name: as - type: - - string - description: | - Name of the array field added to each output document. Contains the documents traversed in the $graphLookup stage to reach the document. - - - name: maxDepth - type: - - int - optional: true - description: | - Non-negative integral number specifying the maximum recursion depth. - - - name: depthField - type: - - string - optional: true - description: | - Name of the field to add to each traversed document in the search path. The value of this field is the recursion depth for the document, represented as a NumberLong. Recursion depth value starts at zero, so the first lookup corresponds to zero depth. - - - name: restrictSearchWithMatch - type: - - query - optional: true - description: | - A document specifying additional conditions for the recursive search. The syntax is identical to query filter syntax. + - name: from + type: + - string + description: | + Target collection for the $graphLookup operation to search, recursively matching the connectFromField to the connectToField. The from collection must be in the same database as any other collections used in the operation. + Starting in MongoDB 5.1, the collection specified in the from parameter can be sharded. + - name: startWith + type: + - expression + - array + description: | + 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. + - name: connectFromField + type: + - string + description: | + 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. + - name: connectToField + type: + - string + description: | + Field name in other documents against which to match the value of the field specified by the connectFromField parameter. + - name: as + type: + - string + description: | + Name of the array field added to each output document. Contains the documents traversed in the $graphLookup stage to reach the document. + - name: maxDepth + type: + - int + optional: true + description: | + Non-negative integral number specifying the maximum recursion depth. + - name: depthField + type: + - string + optional: true + description: | + Name of the field to add to each traversed document in the search path. The value of this field is the recursion depth for the document, represented as a NumberLong. Recursion depth value starts at zero, so the first lookup corresponds to zero depth. + - name: restrictSearchWithMatch + type: + - query + optional: true + description: | + A document specifying additional conditions for the recursive search. The syntax is identical to query filter syntax. tests: - - - name: 'Within a Single Collection' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/graphLookup/#within-a-single-collection' - pipeline: - - - $graphLookup: - from: 'employees' - startWith: '$reportsTo' - connectFromField: 'reportsTo' - connectToField: 'name' - as: 'reportingHierarchy' - - - name: 'Across Multiple Collections' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/graphLookup/#across-multiple-collections' - pipeline: - - - $graphLookup: - from: 'airports' - startWith: '$nearestAirport' - connectFromField: 'connects' - connectToField: 'airport' - maxDepth: 2 - depthField: 'numConnections' - as: 'destinations' - - - name: 'With a Query Filter' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/graphLookup/#with-a-query-filter' - 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' + - name: Within a Single Collection + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/graphLookup/#within-a-single-collection + pipeline: + - $graphLookup: + from: employees + startWith: $reportsTo + connectFromField: reportsTo + connectToField: name + as: reportingHierarchy + schema: + employees: + _id: + types: + - bsonType: Number + name: + types: + - bsonType: String + reportsTo: + types: + - bsonType: String + - name: Across Multiple Collections + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/graphLookup/#across-multiple-collections + pipeline: + - $graphLookup: + from: airports + startWith: $nearestAirport + connectFromField: connects + connectToField: airport + maxDepth: 2 + depthField: numConnections + as: destinations + schema: + airports: + _id: + types: + - bsonType: Number + airport: + types: + - bsonType: String + connects: + types: + - bsonType: Array + types: + - bsonType: String + - name: With a Query Filter + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/graphLookup/#with-a-query-filter + 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 + schema: + people: + _id: + types: + - bsonType: Number + name: + types: + - bsonType: String + friends: + types: + - bsonType: Array + types: + - bsonType: String + hobbies: + types: + - bsonType: Array + types: + - bsonType: String diff --git a/generator/config/stage/group.yaml b/generator/config/stage/group.yaml index a4bae60c2..a546c54e3 100644 --- a/generator/config/stage/group.yaml +++ b/generator/config/stage/group.yaml @@ -1,123 +1,220 @@ # $schema: ../schema.json name: $group -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/group/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/group/ type: - stage encode: object description: | 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. arguments: - - - name: _id - type: - - expression - description: | - 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. - - - name: field - mergeObject: true - type: - - accumulator - variadic: object - variadicMin: 0 - description: | - Computed using the accumulator operators. + - name: _id + type: + - expression + - expressionMap + description: | + 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. + - name: field + mergeObject: true + type: + - accumulator + variadic: object + variadicMin: 0 + description: | + Computed using the accumulator operators. tests: - - - name: 'Count the Number of Documents in a Collection' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/group/#count-the-number-of-documents-in-a-collection' - pipeline: - - - $group: - _id: ~ - count: - $count: {} - - - name: 'Retrieve Distinct Values' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/group/#retrieve-distinct-values' - pipeline: - - - $group: - _id: '$item' - - - name: 'Group by Item Having' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/group/#group-by-item-having' - pipeline: - - - $group: - _id: '$item' - totalSaleAmount: - $sum: - $multiply: - - '$price' - - '$quantity' - - - $match: - totalSaleAmount: - $gte: 100 - - - name: 'Calculate Count Sum and Average' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/group/#calculate-count--sum--and-average' - pipeline: - - - $match: - date: - $gte: !bson_utcdatetime '2014-01-01' - $lt: !bson_utcdatetime '2015-01-01' - - - $group: - _id: - $dateToString: - format: '%Y-%m-%d' - date: '$date' - totalSaleAmount: - $sum: - $multiply: - - '$price' - - '$quantity' - averageQuantity: - $avg: '$quantity' - count: - $sum: 1 - - - $sort: - totalSaleAmount: -1 - - - name: 'Group by null' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/group/#group-by-null' - pipeline: - - - $group: - _id: ~ - totalSaleAmount: - $sum: - $multiply: - - '$price' - - '$quantity' - averageQuantity: - $avg: '$quantity' - count: - $sum: 1 - - - name: 'Pivot Data' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/group/#pivot-data' - pipeline: - - - $group: - _id: '$author' - books: - $push: '$title' - - - name: 'Group Documents by author' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/group/#group-documents-by-author' - pipeline: - - - $group: - _id: '$author' - books: - $push: '$$ROOT' - - - $addFields: - totalCopies: - # $sum: '$books.copies' - $sum: ['$books.copies'] + - name: Count the Number of Documents in a Collection + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/group/#count-the-number-of-documents-in-a-collection + pipeline: + - $group: + _id: ~ + count: + $count: {} + schema: + sales: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + price: + types: + - bsonType: Decimal128 + quantity: + types: + - bsonType: Int32 + date: + types: + - bsonType: Date + - name: Retrieve Distinct Values + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/group/#retrieve-distinct-values + pipeline: + - $group: + _id: $item + schema: + sales: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + price: + types: + - bsonType: Decimal128 + quantity: + types: + - bsonType: Int32 + date: + types: + - bsonType: Date + - name: Group by Item Having + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/group/#group-by-item-having + pipeline: + - $group: + _id: $item + totalSaleAmount: + $sum: + $multiply: + - $price + - $quantity + - $match: + totalSaleAmount: + $gte: 100 + schema: + sales: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + price: + types: + - bsonType: Decimal128 + quantity: + types: + - bsonType: Int32 + date: + types: + - bsonType: Date + - name: Calculate Count Sum and Average + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/group/#calculate-count--sum--and-average + pipeline: + - $match: + date: + $gte: !bson_utcdatetime '2014-01-01T00:00:00.000Z' + $lt: !bson_utcdatetime '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 + schema: + sales: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + price: + types: + - bsonType: Decimal128 + quantity: + types: + - bsonType: Int32 + date: + types: + - bsonType: Date + - name: Group by null + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/group/#group-by-null + pipeline: + - $group: + _id: ~ + totalSaleAmount: + $sum: + $multiply: + - $price + - $quantity + averageQuantity: + $avg: $quantity + count: + $sum: 1 + schema: + sales: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + price: + types: + - bsonType: Decimal128 + quantity: + types: + - bsonType: Int32 + date: + types: + - bsonType: Date + - name: Pivot Data + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/group/#pivot-data + pipeline: + - $group: + _id: $author + books: + $push: $title + schema: + books: + _id: + types: + - bsonType: Number + title: + types: + - bsonType: String + author: + types: + - bsonType: String + copies: + types: + - bsonType: Number + - name: Group Documents by author + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/group/#group-documents-by-author + pipeline: + - $group: + _id: $author + books: + $push: $$ROOT + - $addFields: + totalCopies: + $sum: + - $books.copies + schema: + sales: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + price: + types: + - bsonType: Decimal128 + quantity: + types: + - bsonType: Int32 + date: + types: + - bsonType: Date diff --git a/generator/config/stage/indexStats.yaml b/generator/config/stage/indexStats.yaml index 178b209d8..14bac9c24 100644 --- a/generator/config/stage/indexStats.yaml +++ b/generator/config/stage/indexStats.yaml @@ -1,15 +1,30 @@ # $schema: ../schema.json name: $indexStats -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/indexStats/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/indexStats/ type: - stage encode: object description: | Returns statistics regarding the use of each index for the collection. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/indexStats/#example' - pipeline: - - - $indexStats: {} + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/indexStats/#example + pipeline: + - $indexStats: {} + schema: + orders: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + price: + types: + - bsonType: Number + quantity: + types: + - bsonType: Number + type: + types: + - bsonType: String diff --git a/generator/config/stage/limit.yaml b/generator/config/stage/limit.yaml index fff391a01..736d197fd 100644 --- a/generator/config/stage/limit.yaml +++ b/generator/config/stage/limit.yaml @@ -1,20 +1,22 @@ # $schema: ../schema.json name: $limit -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/limit/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/limit/ type: - stage encode: single description: | 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). arguments: - - - name: limit - type: - - int + - name: limit + type: + - int tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/limit/#example' - pipeline: - - - $limit: 5 + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/limit/#example + pipeline: + - $limit: 5 + schema: + TestCollection: + _id: + types: + - bsonType: ObjectId diff --git a/generator/config/stage/listLocalSessions.yaml b/generator/config/stage/listLocalSessions.yaml index 50dccc30e..6f00eddfa 100644 --- a/generator/config/stage/listLocalSessions.yaml +++ b/generator/config/stage/listLocalSessions.yaml @@ -1,47 +1,47 @@ # $schema: ../schema.json name: $listLocalSessions -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/listLocalSessions/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/listLocalSessions/ type: - stage encode: object description: | 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. arguments: - - - name: users - type: - - array - optional: true - description: | - Returns all sessions for the specified users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster to list sessions for other users. - - - name: allUsers - type: - - bool - optional: true - description: | - Returns all sessions for all users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster. + - name: users + type: + - array + optional: true + description: | + Returns all sessions for the specified users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster to list sessions for other users. + - name: allUsers + type: + - bool + optional: true + description: | + Returns all sessions for all users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster. tests: - - - name: 'List All Local Sessions' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/listLocalSessions/#list-all-local-sessions' - pipeline: - - - $listLocalSessions: - allUsers: true - - - name: 'List All Local Sessions for the Specified Users' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/listLocalSessions/#list-all-local-sessions-for-the-specified-users' - pipeline: - - - $listLocalSessions: - users: - - - user: 'myAppReader' - db: 'test' - - - name: 'List All Local Sessions for the Current User' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/listLocalSessions/#list-all-local-sessions-for-the-current-user' - pipeline: - - - $listLocalSessions: {} + - name: List All Local Sessions + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/listLocalSessions/#list-all-local-sessions + pipeline: + - $listLocalSessions: + allUsers: true + schema: + TestCollection: &ref_0 + _id: + types: + - bsonType: ObjectId + - name: List All Local Sessions for the Specified Users + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/listLocalSessions/#list-all-local-sessions-for-the-specified-users + pipeline: + - $listLocalSessions: + users: + - user: myAppReader + db: test + schema: + TestCollection: *ref_0 + - name: List All Local Sessions for the Current User + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/listLocalSessions/#list-all-local-sessions-for-the-current-user + pipeline: + - $listLocalSessions: {} + schema: + TestCollection: *ref_0 diff --git a/generator/config/stage/listSampledQueries.yaml b/generator/config/stage/listSampledQueries.yaml index f767f0d04..1c1f5e8c5 100644 --- a/generator/config/stage/listSampledQueries.yaml +++ b/generator/config/stage/listSampledQueries.yaml @@ -1,29 +1,30 @@ # $schema: ../schema.json name: $listSampledQueries -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSampledQueries/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSampledQueries/ type: - stage encode: object description: | Lists sampled queries for all collections or a specific collection. arguments: - - - name: namespace - type: - - string - optional: true + - name: namespace + type: + - string + optional: true tests: - - - name: 'List Sampled Queries for All Collections' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSampledQueries/#list-sampled-queries-for-all-collections' - pipeline: - - - $listSampledQueries: {} - - - - name: 'List Sampled Queries for A Specific Collection' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSampledQueries/#list-sampled-queries-for-a-specific-collection' - pipeline: - - - $listSampledQueries: - namespace: 'social.post' + - name: List Sampled Queries for All Collections + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSampledQueries/#list-sampled-queries-for-all-collections + pipeline: + - $listSampledQueries: {} + schema: + TestCollection: &ref_0 + _id: + types: + - bsonType: ObjectId + - name: List Sampled Queries for A Specific Collection + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSampledQueries/#list-sampled-queries-for-a-specific-collection + pipeline: + - $listSampledQueries: + namespace: social.post + schema: + TestCollection: *ref_0 diff --git a/generator/config/stage/listSearchIndexes.yaml b/generator/config/stage/listSearchIndexes.yaml index afc4f6d05..aada0e7ce 100644 --- a/generator/config/stage/listSearchIndexes.yaml +++ b/generator/config/stage/listSearchIndexes.yaml @@ -1,44 +1,45 @@ # $schema: ../schema.json name: $listSearchIndexes -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSearchIndexes/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSearchIndexes/ type: - stage encode: object description: | Returns information about existing Atlas Search indexes on a specified collection. arguments: - - - name: id - type: - - string - optional: true - description: | - The id of the index to return information about. - - - name: name - type: - - string - optional: true - description: | - The name of the index to return information about. + - name: id + type: + - string + optional: true + description: | + The id of the index to return information about. + - name: name + type: + - string + optional: true + description: | + The name of the index to return information about. tests: - - - name: 'Return All Search Indexes' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSearchIndexes/#return-all-search-indexes' - pipeline: - - - $listSearchIndexes: {} - - - name: 'Return a Single Search Index by Name' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSearchIndexes/#return-a-single-search-index-by-name' - pipeline: - - - $listSearchIndexes: - name: 'synonym-mappings' - - - name: 'Return a Single Search Index by id' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSearchIndexes/#return-a-single-search-index-by-id' - pipeline: - - - $listSearchIndexes: - id: '6524096020da840844a4c4a7' + - name: Return All Search Indexes + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSearchIndexes/#return-all-search-indexes + pipeline: + - $listSearchIndexes: {} + schema: + TestCollection: &ref_0 + _id: + types: + - bsonType: ObjectId + - name: Return a Single Search Index by Name + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSearchIndexes/#return-a-single-search-index-by-name + pipeline: + - $listSearchIndexes: + name: synonym-mappings + schema: + TestCollection: *ref_0 + - name: Return a Single Search Index by id + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSearchIndexes/#return-a-single-search-index-by-id + pipeline: + - $listSearchIndexes: + id: 6524096020da840844a4c4a7 + schema: + TestCollection: *ref_0 diff --git a/generator/config/stage/listSessions.yaml b/generator/config/stage/listSessions.yaml index efb56de05..7bf658614 100644 --- a/generator/config/stage/listSessions.yaml +++ b/generator/config/stage/listSessions.yaml @@ -1,48 +1,47 @@ # $schema: ../schema.json name: $listSessions -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSessions/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSessions/ type: - stage encode: object description: | Lists all sessions that have been active long enough to propagate to the system.sessions collection. arguments: - - - name: users - type: - - array - optional: true - description: | - Returns all sessions for the specified users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster to list sessions for other users. - - - name: allUsers - type: - - bool - optional: true - description: | - Returns all sessions for all users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster. + - name: users + type: + - array + optional: true + description: | + Returns all sessions for the specified users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster to list sessions for other users. + - name: allUsers + type: + - bool + optional: true + description: | + Returns all sessions for all users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster. tests: - - - name: 'List All Sessions' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSessions/#list-all-sessions' - pipeline: - - - $listSessions: - allUsers: true - - - name: 'List All Sessions for the Specified Users' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSessions/#list-all-sessions-for-the-specified-users' - pipeline: - - - $listSessions: - users: - - - user: 'myAppReader' - db: 'test' - - - name: 'List All Sessions for the Current User' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSessions/#list-all-sessions-for-the-current-user' - pipeline: - - - $listSessions: {} - + - name: List All Sessions + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSessions/#list-all-sessions + pipeline: + - $listSessions: + allUsers: true + schema: + TestCollection: &ref_0 + _id: + types: + - bsonType: ObjectId + - name: List All Sessions for the Specified Users + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSessions/#list-all-sessions-for-the-specified-users + pipeline: + - $listSessions: + users: + - user: myAppReader + db: test + schema: + TestCollection: *ref_0 + - name: List All Sessions for the Current User + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSessions/#list-all-sessions-for-the-current-user + pipeline: + - $listSessions: {} + schema: + TestCollection: *ref_0 diff --git a/generator/config/stage/lookup.yaml b/generator/config/stage/lookup.yaml index b73770e47..2f57c8bff 100644 --- a/generator/config/stage/lookup.yaml +++ b/generator/config/stage/lookup.yaml @@ -1,165 +1,215 @@ # $schema: ../schema.json name: $lookup -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/lookup/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/lookup/ type: - stage encode: object description: | Performs a left outer join to another collection in the same database to filter in documents from the "joined" collection for processing. arguments: - - - name: from - type: - - string - optional: true - description: | - Specifies the collection in the same database to perform the join with. - from is optional, you can use a $documents stage in a $lookup stage instead. For an example, see Use a $documents Stage in a $lookup Stage. - Starting in MongoDB 5.1, the collection specified in the from parameter can be sharded. - - - name: localField - type: - - string - optional: true - description: | - Specifies the field from the documents input to the $lookup stage. $lookup performs an equality match on the localField to the foreignField from the documents of the from collection. If an input document does not contain the localField, the $lookup treats the field as having a value of null for matching purposes. - - - name: foreignField - type: - - string - optional: true - description: | - Specifies the field from the documents in the from collection. $lookup performs an equality match on the foreignField to the localField from the input documents. If a document in the from collection does not contain the foreignField, the $lookup treats the value as null for matching purposes. - - - name: let - type: - - object # of expression - optional: true - description: | - Specifies variables to use in the pipeline stages. Use the variable expressions to access the fields from the joined collection's documents that are input to the pipeline. - - - name: pipeline - type: - - pipeline - optional: true - description: | - Specifies the pipeline to run on the joined collection. The pipeline determines the resulting documents from the joined collection. To return all documents, specify an empty pipeline []. - 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. - - - name: as - type: - - string - description: | - 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. + - name: from + type: + - string + optional: true + description: | + Specifies the collection in the same database to perform the join with. + from is optional, you can use a $documents stage in a $lookup stage instead. For an example, see Use a $documents Stage in a $lookup Stage. + Starting in MongoDB 5.1, the collection specified in the from parameter can be sharded. + - name: localField + type: + - string + optional: true + description: | + Specifies the field from the documents input to the $lookup stage. $lookup performs an equality match on the localField to the foreignField from the documents of the from collection. If an input document does not contain the localField, the $lookup treats the field as having a value of null for matching purposes. + - name: foreignField + type: + - string + optional: true + description: | + Specifies the field from the documents in the from collection. $lookup performs an equality match on the foreignField to the localField from the input documents. If a document in the from collection does not contain the foreignField, the $lookup treats the value as null for matching purposes. + - name: let + type: + - object + optional: true + description: | + Specifies variables to use in the pipeline stages. Use the variable expressions to access the fields from the joined collection's documents that are input to the pipeline. + - name: pipeline + type: + - pipeline + optional: true + description: | + Specifies the pipeline to run on the joined collection. The pipeline determines the resulting documents from the joined collection. To return all documents, specify an empty pipeline []. + 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. + - name: as + type: + - string + description: | + 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. tests: - - - name: 'Perform a Single Equality Join with $lookup' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/lookup/#perform-a-single-equality-join-with--lookup' - pipeline: - - - $lookup: - from: 'inventory' - localField: 'item' - foreignField: 'sku' - as: 'inventory_docs' - - - name: 'Use $lookup with an Array' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/lookup/#use--lookup-with-an-array' - pipeline: - - - $lookup: - from: 'members' - localField: 'enrollmentlist' - foreignField: 'name' - as: 'enrollee_info' - - - name: 'Use $lookup with $mergeObjects' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/lookup/#use--lookup-with--mergeobjects' - pipeline: - - - $lookup: - from: 'items' - localField: 'item' - foreignField: 'item' - as: 'fromItems' - - - $replaceRoot: - newRoot: - $mergeObjects: - - - $arrayElemAt: - - '$fromItems' - - 0 - - '$$ROOT' - - - $project: - fromItems: 0 - - - name: 'Perform Multiple Joins and a Correlated Subquery with $lookup' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/lookup/#perform-multiple-joins-and-a-correlated-subquery-with--lookup' - pipeline: - - - $lookup: - from: 'warehouses' - let: - order_item: '$item' - order_qty: '$ordered' - pipeline: - - - $match: - $expr: - $and: - - - $eq: - - '$stock_item' - - '$$order_item' - - - $gte: - - '$instock' - - '$$order_qty' - - - $project: - stock_item: 0 - _id: 0 - as: 'stockdata' - - - name: 'Perform an Uncorrelated Subquery with $lookup' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/lookup/#perform-an-uncorrelated-subquery-with--lookup' - pipeline: - - - $lookup: - from: 'holidays' - pipeline: - - - $match: - year: 2018 - - - $project: - _id: 0 - date: - name: '$name' - date: '$date' - - - $replaceRoot: - newRoot: '$date' - as: 'holidays' - - - name: 'Perform a Concise Correlated Subquery with $lookup' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/lookup/#perform-a-concise-correlated-subquery-with--lookup' - pipeline: - - - $lookup: - from: 'restaurants' - localField: 'restaurant_name' - foreignField: 'name' - let: - orders_drink: '$drink' - pipeline: - - - $match: - $expr: - $in: - - '$$orders_drink' - - '$beverages' - as: 'matches' + - name: Perform a Single Equality Join with $lookup + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/lookup/#perform-a-single-equality-join-with--lookup + pipeline: + - $lookup: + from: inventory + localField: item + foreignField: sku + as: inventory_docs + schema: + orders: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + price: + types: + - bsonType: Number + quantity: + types: + - bsonType: Number + - name: Use $lookup with an Array + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/lookup/#use--lookup-with-an-array + pipeline: + - $lookup: + from: members + localField: enrollmentlist + foreignField: name + as: enrollee_info + schema: + classes: + _id: + types: + - bsonType: Number + title: + types: + - bsonType: String + enrollmentlist: + types: + - bsonType: Array + types: + - bsonType: String + days: + types: + - bsonType: Array + types: + - bsonType: String + - name: Use $lookup with $mergeObjects + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/lookup/#use--lookup-with--mergeobjects + pipeline: + - $lookup: + from: items + localField: item + foreignField: item + as: fromItems + - $replaceRoot: + newRoot: + $mergeObjects: + - $arrayElemAt: + - $fromItems + - 0 + - $$ROOT + - $project: + fromItems: 0 + schema: + orders: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + price: + types: + - bsonType: Number + quantity: + types: + - bsonType: Number + - name: Perform Multiple Joins and a Correlated Subquery with $lookup + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/lookup/#perform-multiple-joins-and-a-correlated-subquery-with--lookup + pipeline: + - $lookup: + from: warehouses + let: + order_item: $item + order_qty: $ordered + pipeline: + - $match: + $expr: + $and: + - $eq: + - $stock_item + - $$order_item + - $gte: + - $instock + - $$order_qty + - $project: + stock_item: 0 + _id: 0 + as: stockdata + schema: '// TODO: No schema found in docs' + - name: Perform an Uncorrelated Subquery with $lookup + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/lookup/#perform-an-uncorrelated-subquery-with--lookup + pipeline: + - $lookup: + from: holidays + pipeline: + - $match: + year: 2018 + - $project: + _id: 0 + date: + name: $name + date: $date + - $replaceRoot: + newRoot: $date + as: holidays + schema: + orders: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + price: + types: + - bsonType: Number + quantity: + types: + - bsonType: Number + - name: Perform a Concise Correlated Subquery with $lookup + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/lookup/#perform-a-concise-correlated-subquery-with--lookup + pipeline: + - $lookup: + from: restaurants + localField: restaurant_name + foreignField: name + let: + orders_drink: $drink + pipeline: + - $match: + $expr: + $in: + - $$orders_drink + - $beverages + as: matches + schema: + restaurants: + _id: + types: + - bsonType: Number + name: + types: + - bsonType: String + food: + types: + - bsonType: Array + types: + - bsonType: String + beverages: + types: + - bsonType: Array + types: + - bsonType: String diff --git a/generator/config/stage/match.yaml b/generator/config/stage/match.yaml index ab0081fd0..27454c6a3 100644 --- a/generator/config/stage/match.yaml +++ b/generator/config/stage/match.yaml @@ -1,40 +1,60 @@ # $schema: ../schema.json name: $match -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/match/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/match/ type: - stage encode: single description: | 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). arguments: - - - name: query - type: - - query + - name: query + type: + - query tests: - - - name: 'Equality Match' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/match/#equality-match' - pipeline: - - - $match: - author: 'dave' - - - name: 'Perform a Count' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/match/#perform-a-count' - pipeline: - - - $match: - $or: - - - score: - $gt: 70 - $lt: 90 - - - views: - $gte: 1000 - - - $group: - _id: ~ - count: - $sum: 1 + - name: Equality Match + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/match/#equality-match + pipeline: + - $match: + author: dave + schema: + TestCollection: + _id: + types: + - bsonType: ObjectId + author: + types: + - bsonType: String + score: + types: + - bsonType: Number + views: + types: + - bsonType: Number + - name: Perform a Count + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/match/#perform-a-count + pipeline: + - $match: + $or: + - score: + $gt: 70 + $lt: 90 + - views: + $gte: 1000 + - $group: + _id: ~ + count: + $sum: 1 + schema: + TestCollection: + _id: + types: + - bsonType: ObjectId + author: + types: + - bsonType: String + score: + types: + - bsonType: Number + views: + types: + - bsonType: Number diff --git a/generator/config/stage/merge.yaml b/generator/config/stage/merge.yaml index 766092d82..705a8f45e 100644 --- a/generator/config/stage/merge.yaml +++ b/generator/config/stage/merge.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $merge -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/ type: - stage encode: object @@ -8,173 +8,241 @@ description: | 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. arguments: - - - name: into - type: - - string - - outCollection - description: | - The output collection. - - - name: 'on' - type: - - string - - array # of string - optional: true - description: | - 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. - - - name: let - type: - - object - optional: true - description: | - Specifies variables for use in the whenMatched pipeline. - - - name: whenMatched - type: - - whenMatched - - pipeline - optional: true - description: | - 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). - - - name: whenNotMatched - type: - - whenNotMatched - optional: true - description: | - The behavior of $merge if a result document does not match an existing document in the out collection. + - name: into + type: + - string + - outCollection + description: | + The output collection. + - name: 'on' + type: + - string + - array + optional: true + description: | + 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. + - name: let + type: + - object + optional: true + description: | + Specifies variables for use in the whenMatched pipeline. + - name: whenMatched + type: + - whenMatched + - pipeline + optional: true + description: | + 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). + - name: whenNotMatched + type: + - whenNotMatched + optional: true + description: | + The behavior of $merge if a result document does not match an existing document in the out collection. tests: - - - name: 'On-Demand Materialized View Initial Creation' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/#on-demand-materialized-view--initial-creation' - pipeline: - - - $group: - _id: - fiscal_year: '$fiscal_year' - dept: '$dept' - salaries: - $sum: '$salary' - - - $merge: - into: - db: 'reporting' - coll: 'budgets' - on: '_id' - whenMatched: 'replace' - whenNotMatched: 'insert' - - - name: 'On-Demand Materialized View Update Replace Data' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/#on-demand-materialized-view--update-replace-data' - 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' - - - name: 'Only Insert New Data' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/#only-insert-new-data' - 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' - - - name: 'Merge Results from Multiple Collections' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/#merge-results-from-multiple-collections' - pipeline: - - - $group: - _id: '$quarter' - purchased: - $sum: '$qty' - - - $merge: - into: 'quarterlyreport' - on: '_id' - whenMatched: 'merge' - whenNotMatched: 'insert' - - - name: 'Use the Pipeline to Customize the Merge' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/#use-the-pipeline-to-customize-the-merge' - pipeline: - - - $match: - date: - $gte: !bson_utcdatetime '2019-05-07' - $lt: !bson_utcdatetime '2019-05-08' - - - $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' - - - name: 'Use Variables to Customize the Merge' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/#use-variables-to-customize-the-merge' - pipeline: - - - $merge: - into: 'cakeSales' - let: - year: '2020' - whenMatched: - - - $addFields: - salesYear: '$$year' + - name: On-Demand Materialized View Initial Creation + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/#on-demand-materialized-view--initial-creation + pipeline: + - $group: + _id: + fiscal_year: $fiscal_year + dept: $dept + salaries: + $sum: $salary + - $merge: + into: + db: reporting + coll: budgets + on: _id + whenMatched: replace + whenNotMatched: insert + schema: + salaries: + _id: + types: + - bsonType: Number + employee: + types: + - bsonType: String + dept: + types: + - bsonType: String + salary: + types: + - bsonType: Number + fiscal_year: + types: + - bsonType: Number + - name: On-Demand Materialized View Update Replace Data + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/#on-demand-materialized-view--update-replace-data + 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 + schema: + salaries: + _id: + types: + - bsonType: Number + employee: + types: + - bsonType: String + dept: + types: + - bsonType: String + salary: + types: + - bsonType: Number + fiscal_year: + types: + - bsonType: Number + - name: Only Insert New Data + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/#only-insert-new-data + 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 + schema: + salaries: + _id: + types: + - bsonType: Number + employee: + types: + - bsonType: String + dept: + types: + - bsonType: String + salary: + types: + - bsonType: Number + fiscal_year: + types: + - bsonType: Number + - name: Merge Results from Multiple Collections + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/#merge-results-from-multiple-collections + pipeline: + - $group: + _id: $quarter + purchased: + $sum: $qty + - $merge: + into: quarterlyreport + on: _id + whenMatched: merge + whenNotMatched: insert + schema: + purchaseorders: + _id: + types: + - bsonType: Number + quarter: + types: + - bsonType: String + region: + types: + - bsonType: String + qty: + types: + - bsonType: Number + reportDate: + types: + - bsonType: Date + - name: Use the Pipeline to Customize the Merge + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/#use-the-pipeline-to-customize-the-merge + pipeline: + - $match: + date: + $gte: !bson_utcdatetime '2019-05-07T00:00:00.000Z' + $lt: !bson_utcdatetime '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 + schema: + votes: + date: + types: + - bsonType: Date + thumbsup: + types: + - bsonType: Number + thumbsdown: + types: + - bsonType: Number + - name: Use Variables to Customize the Merge + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/#use-variables-to-customize-the-merge + pipeline: + - $merge: + into: cakeSales + let: + year: '2020' + whenMatched: + - $addFields: + salesYear: $$year + schema: + salaries: + _id: + types: + - bsonType: Number + employee: + types: + - bsonType: String + dept: + types: + - bsonType: String + salary: + types: + - bsonType: Number + fiscal_year: + types: + - bsonType: Number diff --git a/generator/config/stage/out.yaml b/generator/config/stage/out.yaml index 0c3597fdf..cb9301906 100644 --- a/generator/config/stage/out.yaml +++ b/generator/config/stage/out.yaml @@ -1,40 +1,62 @@ # $schema: ../schema.json name: $out -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/out/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/out/ type: - stage encode: single description: | 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. arguments: - - name: coll - type: - - string - - outCollection - description: | - Target database name to write documents from $out to. + - name: coll + type: + - string + - outCollection + description: | + Target database name to write documents from $out to. tests: - - - name: 'Output to Same Database' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/out/#output-to-same-database' - pipeline: - - - $group: - _id: '$author' - books: - $push: '$title' - - - $out: 'authors' - - - name: 'Output to a Different Database' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/out/#output-to-a-different-database' - pipeline: - - - $group: - _id: '$author' - books: - $push: '$title' - - - $out: - db: 'reporting' - coll: 'authors' + - name: Output to Same Database + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/out/#output-to-same-database + pipeline: + - $group: + _id: $author + books: + $push: $title + - $out: authors + schema: + books: + _id: + types: + - bsonType: Number + title: + types: + - bsonType: String + author: + types: + - bsonType: String + copies: + types: + - bsonType: Number + - name: Output to a Different Database + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/out/#output-to-a-different-database + pipeline: + - $group: + _id: $author + books: + $push: $title + - $out: + db: reporting + coll: authors + schema: + books: + _id: + types: + - bsonType: Number + title: + types: + - bsonType: String + author: + types: + - bsonType: String + copies: + types: + - bsonType: Number diff --git a/generator/config/stage/planCacheStats.yaml b/generator/config/stage/planCacheStats.yaml index 995caa74e..2dff1a55e 100644 --- a/generator/config/stage/planCacheStats.yaml +++ b/generator/config/stage/planCacheStats.yaml @@ -1,24 +1,53 @@ # $schema: ../schema.json name: $planCacheStats -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/planCacheStats/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/planCacheStats/ type: - stage encode: object description: | Returns plan cache information for a collection. tests: - - - name: 'Return Information for All Entries in the Query Cache' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/planCacheStats/#return-information-for-all-entries-in-the-query-cache' - pipeline: - - - $planCacheStats: {} - - - name: 'Find Cache Entry Details for a Query Hash' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/planCacheStats/#find-cache-entry-details-for-a-query-hash' - pipeline: - - - $planCacheStats: {} - - - $match: - planCacheKey: 'B1435201' + - name: Return Information for All Entries in the Query Cache + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/planCacheStats/#return-information-for-all-entries-in-the-query-cache + pipeline: + - $planCacheStats: {} + schema: + orders: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + price: + types: + - bsonType: Decimal128 + quantity: + types: + - bsonType: Number + type: + types: + - bsonType: String + - name: Find Cache Entry Details for a Query Hash + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/planCacheStats/#find-cache-entry-details-for-a-query-hash + pipeline: + - $planCacheStats: {} + - $match: + planCacheKey: B1435201 + schema: + orders: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + price: + types: + - bsonType: Decimal128 + quantity: + types: + - bsonType: Number + type: + types: + - bsonType: String diff --git a/generator/config/stage/project.yaml b/generator/config/stage/project.yaml index c7b0f7d59..b653301c9 100644 --- a/generator/config/stage/project.yaml +++ b/generator/config/stage/project.yaml @@ -1,124 +1,306 @@ # $schema: ../schema.json name: $project -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/project/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/project/ type: - stage encode: single description: | Reshapes each document in the stream, such as by adding new fields or removing existing fields. For each input document, outputs one document. arguments: - - - name: specification - type: - - expression - variadic: object + - name: specification + type: + - expression + variadic: object tests: - - - name: 'Include Specific Fields in Output Documents' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/project/#include-specific-fields-in-output-documents' - pipeline: - - - $project: + - name: Include Specific Fields in Output Documents + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/project/#include-specific-fields-in-output-documents + pipeline: + - $project: + title: 1 + author: 1 + schema: + books: + _id: + types: + - bsonType: Number + title: + types: + - bsonType: String + isbn: + types: + - bsonType: String + author: + types: + - bsonType: Document + fields: + last: + types: + - bsonType: String + first: + types: + - bsonType: String + copies: + types: + - bsonType: Number + - name: Suppress id Field in the Output Documents + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/project/#suppress-_id-field-in-the-output-documents + pipeline: + - $project: + _id: 0 + title: 1 + author: 1 + schema: + books: + _id: + types: + - bsonType: Number + title: + types: + - bsonType: String + isbn: + types: + - bsonType: String + author: + types: + - bsonType: Document + fields: + last: + types: + - bsonType: String + first: + types: + - bsonType: String + copies: + types: + - bsonType: Number + - name: Exclude Fields from Output Documents + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/project/#exclude-fields-from-output-documents + pipeline: + - $project: + lastModified: 0 + schema: + books: + _id: + types: + - bsonType: Number + title: + types: + - bsonType: String + isbn: + types: + - bsonType: String + author: + types: + - bsonType: Document + fields: + last: + types: + - bsonType: String + first: + types: + - bsonType: String + copies: + types: + - bsonType: Number + lastModified: + types: + - bsonType: String + - name: Exclude Fields from Embedded Documents + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/project/#exclude-fields-from-embedded-documents + pipeline: + - $project: + author.first: 0 + lastModified: 0 + - $project: + author: + first: 0 + lastModified: 0 + schema: + books: + _id: + types: + - bsonType: Number + title: + types: + - bsonType: String + isbn: + types: + - bsonType: String + author: + types: + - bsonType: Document + fields: + last: + types: + - bsonType: String + first: + types: + - bsonType: String + copies: + types: + - bsonType: Number + lastModified: + types: + - bsonType: String + - name: Conditionally Exclude Fields + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/project/#conditionally-exclude-fields + pipeline: + - $project: + title: 1 + author.first: 1 + author.last: 1 + author.middle: + $cond: + if: + $eq: + - '' + - $author.middle + then: $$REMOVE + else: $author.middle + schema: + books: + _id: + types: + - bsonType: Number + title: + types: + - bsonType: String + isbn: + types: + - bsonType: String + author: + types: + - bsonType: Document + fields: + last: + types: + - bsonType: String + first: + types: + - bsonType: String + middle: + types: + - bsonType: String + copies: + types: + - bsonType: Number + lastModified: + types: + - bsonType: String + - name: Include Specific Fields from Embedded Documents + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/project/#include-specific-fields-from-embedded-documents + pipeline: + - $project: + stop.title: 1 + - $project: + stop: title: 1 - author: 1 - - - name: 'Suppress id Field in the Output Documents' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/project/#suppress-_id-field-in-the-output-documents' - pipeline: - - - $project: - _id: 0 - title: 1 - author: 1 - - - name: 'Exclude Fields from Output Documents' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/project/#exclude-fields-from-output-documents' - pipeline: - - - $project: - lastModified: 0 - - - name: 'Exclude Fields from Embedded Documents' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/project/#exclude-fields-from-embedded-documents' - pipeline: - - - $project: - author.first: 0 - lastModified: 0 - - - $project: - author: - first: 0 - lastModified: 0 - - - name: 'Conditionally Exclude Fields' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/project/#conditionally-exclude-fields' - pipeline: - - - $project: - title: 1 - author.first: 1 - author.last: 1 - author.middle: - $cond: - if: - $eq: - - '' - - '$author.middle' - then: '$$REMOVE' - else: '$author.middle' - - - name: 'Include Specific Fields from Embedded Documents' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/project/#include-specific-fields-from-embedded-documents' - pipeline: - - - $project: - stop.title: 1 - - - $project: - stop: - title: 1 - - - name: 'Include Computed Fields' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/project/#include-computed-fields' - 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' - - - name: 'Project New Array Fields' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/project/#project-new-array-fields' - pipeline: - - - $project: - myArray: - - '$x' - - '$y' + schema: + bookmarks: + _id: + types: + - bsonType: Number + user: + types: + - bsonType: String + stop: + types: + - bsonType: Document + fields: + title: + types: + - bsonType: String + author: + types: + - bsonType: String + page: + types: + - bsonType: Number + - bsonType: Array + types: + - bsonType: Document + fields: + title: + types: + - bsonType: String + author: + types: + - bsonType: String + page: + types: + - bsonType: Number + - name: Include Computed Fields + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/project/#include-computed-fields + 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 + schema: + books: + _id: + types: + - bsonType: Number + title: + types: + - bsonType: String + isbn: + types: + - bsonType: String + author: + types: + - bsonType: Document + fields: + last: + types: + - bsonType: String + first: + types: + - bsonType: String + copies: + types: + - bsonType: Number + - name: Project New Array Fields + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/project/#project-new-array-fields + pipeline: + - $project: + myArray: + - $x + - $y + schema: + TestCollection: + _id: + types: + - bsonType: ObjectId + x: + types: + - bsonType: Number + y: + types: + - bsonType: Number diff --git a/generator/config/stage/redact.yaml b/generator/config/stage/redact.yaml index 07698119c..0fe938250 100644 --- a/generator/config/stage/redact.yaml +++ b/generator/config/stage/redact.yaml @@ -1,52 +1,129 @@ # $schema: ../schema.json name: $redact -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/redact/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/redact/ type: - stage encode: single description: | 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. arguments: - - - name: expression - type: - - expression + - name: expression + type: + - expression tests: - - - name: 'Evaluate Access at Every Document Level' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/redact/#evaluate-access-at-every-document-level' - pipeline: - - - $match: - year: 2014 - - - $redact: - $cond: - if: - $gt: - - - $size: - $setIntersection: - - '$tags' - - - - 'STLW' - - 'G' - - 0 - then: '$$DESCEND' - else: '$$PRUNE' - - - name: 'Exclude All Fields at a Given Level' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/redact/#exclude-all-fields-at-a-given-level' - pipeline: - - - $match: - status: 'A' - - - $redact: - $cond: - if: - $eq: - - '$level' - - 5 - then: '$$PRUNE' - else: '$$DESCEND' + - name: Evaluate Access at Every Document Level + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/redact/#evaluate-access-at-every-document-level + pipeline: + - $match: + year: 2014 + - $redact: + $cond: + if: + $gt: + - $size: + $setIntersection: + - $tags + - - STLW + - G + - 0 + then: $$DESCEND + else: $$PRUNE + schema: + forecasts: + _id: + types: + - bsonType: Number + title: + types: + - bsonType: String + tags: + types: + - bsonType: Array + types: + - bsonType: String + year: + types: + - bsonType: Number + subsections: + types: + - bsonType: Array + types: + - bsonType: Document + fields: + subtitle: + types: + - bsonType: String + tags: + types: + - bsonType: Array + types: + - bsonType: String + content: + types: + - bsonType: String + - bsonType: Document + fields: + text: + types: + - bsonType: String + tags: + types: + - bsonType: Array + types: + - bsonType: String + - name: Exclude All Fields at a Given Level + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/redact/#exclude-all-fields-at-a-given-level + pipeline: + - $match: + status: A + - $redact: + $cond: + if: + $eq: + - $level + - 5 + then: $$PRUNE + else: $$DESCEND + schema: + forecasts: + _id: + types: + - bsonType: Number + title: + types: + - bsonType: String + tags: + types: + - bsonType: Array + types: + - bsonType: String + year: + types: + - bsonType: Number + subsections: + types: + - bsonType: Array + types: + - bsonType: Document + fields: + subtitle: + types: + - bsonType: String + tags: + types: + - bsonType: Array + types: + - bsonType: String + content: + types: + - bsonType: String + - bsonType: Document + fields: + text: + types: + - bsonType: String + tags: + types: + - bsonType: Array + types: + - bsonType: String diff --git a/generator/config/stage/replaceRoot.yaml b/generator/config/stage/replaceRoot.yaml index 4de474e00..e0e6ac83e 100644 --- a/generator/config/stage/replaceRoot.yaml +++ b/generator/config/stage/replaceRoot.yaml @@ -1,71 +1,134 @@ # $schema: ../schema.json name: $replaceRoot -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceRoot/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceRoot/ type: - stage encode: object description: | 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. arguments: - - - name: newRoot - type: - - resolvesToObject + - name: newRoot + type: + - resolvesToObject tests: - - - name: 'with an Embedded Document Field' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceRoot/#-replaceroot-with-an-embedded-document-field' - pipeline: - - - $replaceRoot: - newRoot: - $mergeObjects: - - - dogs: 0 - cats: 0 - birds: 0 - fish: 0 - - '$pets' - - - name: 'with a Document Nested in an Array' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceRoot/#-replaceroot-with-a-document-nested-in-an-array' - pipeline: - - - # The builder uses the verbose form of the $unwind operator - # $unwind: '$grades' - $unwind: - path: '$grades' - - - $match: - grades.grade: - $gte: 90 - - - $replaceRoot: - newRoot: '$grades' - - - name: 'with a newly created document' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceRoot/#-replaceroot-with-a-newly-created-document' - pipeline: - - - $replaceRoot: - newRoot: - full_name: - $concat: - - '$first_name' - - ' ' - - '$last_name' - - - name: 'with a New Document Created from $$ROOT and a Default Document' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceRoot/#-replaceroot-with-a-new-document-created-from---root-and-a-default-document' - pipeline: - - - $replaceRoot: - newRoot: - $mergeObjects: - - - _id: '' - name: '' - email: '' - cell: '' - home: '' - - '$$ROOT' + - name: with an Embedded Document Field + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceRoot/#-replaceroot-with-an-embedded-document-field + pipeline: + - $replaceRoot: + newRoot: + $mergeObjects: + - dogs: 0 + cats: 0 + birds: 0 + fish: 0 + - $pets + schema: + TestCollection: + _id: + types: + - bsonType: Number + name: + types: + - bsonType: String + age: + types: + - bsonType: Number + pets: + types: + - bsonType: Document + fields: + dogs: + types: + - bsonType: Number + cats: + types: + - bsonType: Number + fish: + types: + - bsonType: Number + - name: with a Document Nested in an Array + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceRoot/#-replaceroot-with-a-document-nested-in-an-array + pipeline: + - $unwind: + path: $grades + - $match: + grades.grade: + $gte: 90 + - $replaceRoot: + newRoot: $grades + schema: + students: + _id: + types: + - bsonType: Number + grades: + types: + - bsonType: Array + types: + - bsonType: Document + fields: + test: + types: + - bsonType: Number + grade: + types: + - bsonType: Number + mean: + types: + - bsonType: Number + std: + types: + - bsonType: Number + - name: with a newly created document + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceRoot/#-replaceroot-with-a-newly-created-document + pipeline: + - $replaceRoot: + newRoot: + full_name: + $concat: + - $first_name + - ' ' + - $last_name + schema: + TestCollection: + _id: + types: + - bsonType: Number + first_name: + types: + - bsonType: String + last_name: + types: + - bsonType: String + city: + types: + - bsonType: String + - name: with a New Document Created from $$ROOT and a Default Document + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceRoot/#-replaceroot-with-a-new-document-created-from---root-and-a-default-document + pipeline: + - $replaceRoot: + newRoot: + $mergeObjects: + - _id: '' + name: '' + email: '' + cell: '' + home: '' + - $$ROOT + schema: + contacts: + _id: + types: + - bsonType: Number + name: + types: + - bsonType: String + email: + types: + - bsonType: String + cell: + types: + - bsonType: String + home: + types: + - bsonType: String diff --git a/generator/config/stage/replaceWith.yaml b/generator/config/stage/replaceWith.yaml index 10c5fa3a2..1acb3805c 100644 --- a/generator/config/stage/replaceWith.yaml +++ b/generator/config/stage/replaceWith.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $replaceWith -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceWith/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceWith/ type: - stage encode: single @@ -8,67 +8,132 @@ description: | 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. arguments: - - - name: expression - type: - - resolvesToObject + - name: expression + type: + - resolvesToObject tests: - - - name: 'an Embedded Document Field' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceWith/#-replacewith-an-embedded-document-field' - pipeline: - - - $replaceWith: - $mergeObjects: - - - dogs: 0 - cats: 0 - birds: 0 - fish: 0 - - '$pets' - - - name: 'a Document Nested in an Array' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceWith/#-replacewith-a-document-nested-in-an-array' - pipeline: - - - # The builder uses the verbose form of the $unwind operator - # $unwind: '$grades' - $unwind: - path: '$grades' - - - $match: - grades.grade: - $gte: 90 - - - $replaceWith: '$grades' - - - name: 'a Newly Created Document' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceWith/#-replacewith-a-newly-created-document' - pipeline: - - - $match: - status: 'C' - - - $replaceWith: - _id: '$_id' - item: '$item' - amount: - $multiply: - - '$price' - - '$quantity' - status: 'Complete' - asofDate: '$$NOW' - - - name: 'a New Document Created from $$ROOT and a Default Document' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceWith/#-replacewith-a-new-document-created-from---root-and-a-default-document' - pipeline: - - - $replaceWith: - $mergeObjects: - - - _id: '' - name: '' - email: '' - cell: '' - home: '' - - '$$ROOT' + - name: an Embedded Document Field + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceWith/#-replacewith-an-embedded-document-field + pipeline: + - $replaceWith: + $mergeObjects: + - dogs: 0 + cats: 0 + birds: 0 + fish: 0 + - $pets + schema: + people: + _id: + types: + - bsonType: Number + name: + types: + - bsonType: String + age: + types: + - bsonType: Number + pets: + types: + - bsonType: Document + fields: + dogs: + types: + - bsonType: Number + cats: + types: + - bsonType: Number + fish: + types: + - bsonType: Number + - name: a Document Nested in an Array + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceWith/#-replacewith-a-document-nested-in-an-array + pipeline: + - $unwind: + path: $grades + - $match: + grades.grade: + $gte: 90 + - $replaceWith: $grades + schema: + students: + _id: + types: + - bsonType: Number + grades: + types: + - bsonType: Array + types: + - bsonType: Document + fields: + test: + types: + - bsonType: Number + grade: + types: + - bsonType: Number + mean: + types: + - bsonType: Number + std: + types: + - bsonType: Number + - name: a Newly Created Document + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceWith/#-replacewith-a-newly-created-document + pipeline: + - $match: + status: C + - $replaceWith: + _id: $_id + item: $item + amount: + $multiply: + - $price + - $quantity + status: Complete + asofDate: $$NOW + schema: + sales: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + price: + types: + - bsonType: Number + quantity: + types: + - bsonType: Number + date: + types: + - bsonType: Date + status: + types: + - bsonType: String + - name: a New Document Created from $$ROOT and a Default Document + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceWith/#-replacewith-a-new-document-created-from---root-and-a-default-document + pipeline: + - $replaceWith: + $mergeObjects: + - _id: '' + name: '' + email: '' + cell: '' + home: '' + - $$ROOT + schema: + contacts: + _id: + types: + - bsonType: Number + name: + types: + - bsonType: String + email: + types: + - bsonType: String + cell: + types: + - bsonType: String diff --git a/generator/config/stage/sample.yaml b/generator/config/stage/sample.yaml index 757382aaf..0680f81dd 100644 --- a/generator/config/stage/sample.yaml +++ b/generator/config/stage/sample.yaml @@ -1,23 +1,34 @@ # $schema: ../schema.json name: $sample -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/sample/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/sample/ type: - stage encode: object description: | Randomly selects the specified number of documents from its input. arguments: - - - name: size - type: - - int - description: | - The number of documents to randomly select. + - name: size + type: + - int + description: | + The number of documents to randomly select. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/sample/#example' - pipeline: - - - $sample: - size: 3 + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/sample/#examples + pipeline: + - $sample: + size: 3 + schema: + users: + _id: + types: + - bsonType: Number + name: + types: + - bsonType: String + q1: + types: + - bsonType: Boolean + q2: + types: + - bsonType: Boolean diff --git a/generator/config/stage/search.yaml b/generator/config/stage/search.yaml index 44756ce23..943fe7717 100644 --- a/generator/config/stage/search.yaml +++ b/generator/config/stage/search.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $search -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/search/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/search/ type: - stage encode: object @@ -8,258 +8,361 @@ description: | 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. arguments: - - - name: operator - mergeObject: true - type: - - searchOperator - description: | - Operator to search with. You can provide a specific operator or use - the compound operator to run a compound query with multiple operators. - - - name: index - optional: true - type: - - string - description: | - Name of the Atlas Search index to use. If omitted, defaults to "default". - - - name: highlight - optional: true - type: - # @todo support "highlight" type object - # https://www.mongodb.com/docs/atlas/atlas-search/highlighting/ - - object - description: | - Specifies the highlighting options for displaying search terms in their original context. - - - name: concurrent - optional: true - type: - - bool - description: | - Parallelize search across segments on dedicated search nodes. - If you don't have separate search nodes on your cluster, - Atlas Search ignores this flag. If omitted, defaults to false. - - - name: count - optional: true - type: - - object - description: | - Document that specifies the count options for retrieving a count of the results. - - - name: searchAfter - optional: true - type: - - string - description: | - Reference point for retrieving results. searchAfter returns documents starting immediately following the specified reference point. - - - name: searchBefore - optional: true - type: - - string - description: | - Reference point for retrieving results. searchBefore returns documents starting immediately before the specified reference point. - - - name: scoreDetails - optional: true - type: - - bool - description: | - Flag that specifies whether to retrieve a detailed breakdown of the score for the documents in the results. If omitted, defaults to false. - - - name: sort - optional: true - type: - - object - description: | - Document that specifies the fields to sort the Atlas Search results by in ascending or descending order. - - - name: returnStoredSource - optional: true - type: - - bool - description: | - Flag that specifies whether to perform a full document lookup on the backend database or return only stored source fields directly from Atlas Search. - - - name: tracking - optional: true - type: - - object - description: | - Document that specifies the tracking option to retrieve analytics information on the search terms. + - name: operator + mergeObject: true + type: + - searchOperator + description: | + Operator to search with. You can provide a specific operator or use + the compound operator to run a compound query with multiple operators. + - name: index + optional: true + type: + - string + description: | + Name of the Atlas Search index to use. If omitted, defaults to "default". + - name: highlight + optional: true + type: + - searchHighlight + description: | + Specifies the highlighting options for displaying search terms in their original context. + - name: concurrent + optional: true + type: + - bool + description: | + Parallelize search across segments on dedicated search nodes. + If you don't have separate search nodes on your cluster, + Atlas Search ignores this flag. If omitted, defaults to false. + - name: count + optional: true + type: + - object + description: | + Document that specifies the count options for retrieving a count of the results. + - name: searchAfter + optional: true + type: + - string + description: | + Reference point for retrieving results. searchAfter returns documents starting immediately following the specified reference point. + - name: searchBefore + optional: true + type: + - string + description: | + Reference point for retrieving results. searchBefore returns documents starting immediately before the specified reference point. + - name: scoreDetails + optional: true + type: + - bool + description: | + Flag that specifies whether to retrieve a detailed breakdown of the score for the documents in the results. If omitted, defaults to false. + - name: sort + optional: true + type: + - object + description: | + Document that specifies the fields to sort the Atlas Search results by in ascending or descending order. + - name: returnStoredSource + optional: true + type: + - bool + description: | + Flag that specifies whether to perform a full document lookup on the backend database or return only stored source fields directly from Atlas Search. + - name: tracking + optional: true + type: + - object + description: | + Document that specifies the tracking option to retrieve analytics information on the search terms. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/query-syntax/#aggregation-variable' - pipeline: - - - $search: - near: - path: 'released' - origin: !bson_utcdatetime '2011-09-01T00:00:00.000+00:00' - pivot: 7776000000 - - - $project: - _id: 0 - title: 1 - released: 1 - - - $limit: 5 - - - $facet: - docs: [] - meta: - - - $replaceWith: '$$SEARCH_META' - - - $limit: 1 - - - name: 'Date Search and Sort' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/sort/#date-search-and-sort' - pipeline: - - - $search: - range: - path: 'released' - gt: !bson_utcdatetime '2010-01-01T00:00:00.000Z' - lt: !bson_utcdatetime '2015-01-01T00:00:00.000Z' - sort: - released: -1 - - - $limit: 5 - - - $project: - _id: 0 - title: 1 + - name: Example + link: https://www.mongodb.com/docs/atlas/atlas-search/aggregation-stages/search/#aggregation-variable + pipeline: + - $search: + near: + path: released + origin: !bson_utcdatetime '2011-09-01T00:00:00.000Z' + pivot: 7776000000 + - $project: + _id: 0 + title: 1 + released: 1 + - $limit: 5 + - $facet: + docs: [] + meta: + - $replaceWith: $$SEARCH_META + - $limit: 1 + schema: + movies: &ref_0 + _id: + types: + - bsonType: Document + fields: + $oid: + types: + - bsonType: String + title: + types: + - bsonType: String + year: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + runtime: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + released: + types: + - bsonType: Document + fields: + $date: + types: + - bsonType: Document + fields: + $numberLong: + types: + - bsonType: String + poster: + types: + - bsonType: String + plot: + types: + - bsonType: String + fullplot: + types: + - bsonType: String + lastupdated: + types: + - bsonType: String + type: + types: + - bsonType: String + directors: + types: + - bsonType: Array + types: + - bsonType: String + imdb: + types: + - bsonType: Document + fields: + rating: + types: + - bsonType: Document + fields: + $numberDouble: + types: + - bsonType: String + votes: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + id: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + cast: + types: + - bsonType: Array + types: + - bsonType: String + countries: + types: + - bsonType: Array + types: + - bsonType: String + genres: + types: + - bsonType: Array + types: + - bsonType: String + tomatoes: + types: + - bsonType: Document + fields: + viewer: + types: + - bsonType: Document + fields: + rating: + types: + - bsonType: Document + fields: + $numberDouble: + types: + - bsonType: String + numReviews: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + lastUpdated: + types: + - bsonType: Document + fields: + $date: + types: + - bsonType: Document + fields: + $numberLong: + types: + - bsonType: String + num_mflix_comments: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + - name: Date Search and Sort + link: https://www.mongodb.com/docs/atlas/atlas-search/sort/#date-search-and-sort + pipeline: + - $search: + range: + path: released + gt: !bson_utcdatetime '2010-01-01T00:00:00.000Z' + lt: !bson_utcdatetime '2015-01-01T00:00:00.000Z' + sort: + released: -1 + - $limit: 5 + - $project: + _id: 0 + title: 1 + released: 1 + schema: + movies: *ref_0 + - name: Number Search and Sort + link: https://www.mongodb.com/docs/atlas/atlas-search/sort/#number-search-and-sort + pipeline: + - $search: + range: + path: awards.wins + gt: 3 + sort: + awards.wins: -1 + - $limit: 5 + - $project: + _id: 0 + title: 1 + awards.wins: 1 + schema: + movies: *ref_0 + - name: Sort by score + link: https://www.mongodb.com/docs/atlas/atlas-search/sort/#sort-by-score + pipeline: + - $search: + text: + path: title + query: story + sort: + score: + $meta: searchScore + order: 1 + - $limit: 5 + - $project: + _id: 0 + title: 1 + score: + $meta: searchScore + schema: + movies: *ref_0 + - name: Paginate results after a token + link: https://www.mongodb.com/docs/atlas/atlas-search/paginate-results/#search-after-the-reference-point + pipeline: + - $search: + text: + path: title + query: war + sort: + score: + $meta: searchScore released: 1 - - - name: 'Number Search and Sort' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/sort/#number-search-and-sort' - pipeline: - - - $search: - range: - path: 'awards.wins' - gt: 3 - sort: - awards.wins: -1 - - - $limit: 5 - - - $project: - _id: 0 - title: 1 - awards.wins: 1 - - - name: 'Sort by score' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/sort/#sort-by-score' - pipeline: - - - $search: - text: - path: 'title' - query: 'story' - sort: - score: - $meta: 'searchScore' - order: 1 - - - $limit: 5 - - - $project: - _id: 0 - title: 1 + searchAfter: CMtJGgYQuq+ngwgaCSkAjBYH7AAAAA== + schema: + movies: *ref_0 + - name: Paginate results before a token + link: https://www.mongodb.com/docs/atlas/atlas-search/paginate-results/#search-before-the-reference-point + pipeline: + - $search: + text: + path: title + query: war + sort: score: - $meta: 'searchScore' - - - name: 'Paginate results after a token' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/paginate-results/#search-after-the-reference-point' - pipeline: - - - $search: - text: - path: 'title' - query: 'war' - sort: - score: - $meta: 'searchScore' - released: 1 - searchAfter: 'CMtJGgYQuq+ngwgaCSkAjBYH7AAAAA==' - - - name: 'Paginate results before a token' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/paginate-results/#search-before-the-reference-point' - pipeline: - - - $search: - text: - path: 'title' - query: 'war' - sort: - score: - $meta: 'searchScore' - released: 1 - searchBefore: 'CJ6kARoGELqvp4MIGgkpACDA3U8BAAA=' - - - name: 'Count results' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/counting/#count-results' - pipeline: - - - $search: - near: - path: 'released' - origin: !bson_utcdatetime '2011-09-01T00:00:00.000+00:00' - pivot: 7776000000 - count: - type: 'total' - - - $project: - meta: '$$SEARCH_META' - title: 1 + $meta: searchScore released: 1 - - - $limit: 2 - - - name: 'Track Search terms' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/tracking/#examples' - pipeline: - - - $search: - text: - query: 'summer' - path: 'title' - tracking: - searchTerms: 'summer' - - - $limit: 5 - - - $project: - _id: 0 - title: 1 - - - name: 'Return Stored Source Fields' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/return-stored-source/#examples' - pipeline: - - - $search: - text: - query: 'baseball' - path: 'title' - returnStoredSource: true - - - $match: - $or: - - - imdb.rating: - $gt: 8.2 - - - imdb.votes: - $gte: 4500 - - - $lookup: - from: 'movies' - localField: '_id' - foreignField: '_id' - as: 'document' + searchBefore: CJ6kARoGELqvp4MIGgkpACDA3U8BAAA= + schema: + movies: *ref_0 + - name: Count results + link: https://www.mongodb.com/docs/atlas/atlas-search/counting/#count-results + pipeline: + - $search: + near: + path: released + origin: !bson_utcdatetime '2011-09-01T00:00:00.000Z' + pivot: 7776000000 + count: + type: total + - $project: + meta: $$SEARCH_META + title: 1 + released: 1 + - $limit: 2 + schema: + movies: *ref_0 + - name: Track Search terms + link: https://www.mongodb.com/docs/atlas/atlas-search/tracking/#examples + pipeline: + - $search: + text: + query: summer + path: title + tracking: + searchTerms: summer + - $limit: 5 + - $project: + _id: 0 + title: 1 + schema: + movies: *ref_0 + - name: Return Stored Source Fields + link: https://www.mongodb.com/docs/atlas/atlas-search/return-stored-source/#examples + pipeline: + - $search: + text: + query: baseball + path: title + returnStoredSource: true + - $match: + $or: + - imdb.rating: + $gt: 8.2 + - imdb.votes: + $gte: 4500 + - $lookup: + from: movies + localField: _id + foreignField: _id + as: document + schema: + movies: *ref_0 diff --git a/generator/config/stage/searchMeta.yaml b/generator/config/stage/searchMeta.yaml index a7d92c272..51a68cced 100644 --- a/generator/config/stage/searchMeta.yaml +++ b/generator/config/stage/searchMeta.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $searchMeta -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/searchMeta/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/searchMeta/ type: - stage encode: object @@ -8,125 +8,253 @@ description: | 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. arguments: - - - name: operator - mergeObject: true - type: - - searchOperator - description: | - Operator to search with. You can provide a specific operator or use - the compound operator to run a compound query with multiple operators. - - - name: index - optional: true - type: - - string - description: | - Name of the Atlas Search index to use. If omitted, defaults to default. - - - - name: count - optional: true - type: - - object - description: | - Document that specifies the count options for retrieving a count of the results. + - name: operator + mergeObject: true + type: + - searchOperator + description: | + Operator to search with. You can provide a specific operator or use + the compound operator to run a compound query with multiple operators. + - name: index + optional: true + type: + - string + description: | + Name of the Atlas Search index to use. If omitted, defaults to default. + - name: count + optional: true + type: + - object + description: | + Document that specifies the count options for retrieving a count of the results. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/query-syntax/#example' - pipeline: - - - $searchMeta: - range: - path: 'year' - gte: 1998 - lt: 1999 - count: - type: 'total' - - - - name: 'Year Facet' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/facet/#example-1' - pipeline: - - $searchMeta: - facet: - operator: - range: - path: 'year' - gte: 1980 - lte: 2000 - facets: - yearFacet: - type: 'number' - path: 'year' - boundaries: - - 1980 - - 1990 - - 2000 - default: 'other' - - - - name: 'Date Facet' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/facet/#example-2' - pipeline: - - - $searchMeta: - facet: - operator: - range: - path: 'released' - gte: !bson_utcdatetime '2000-01-01T00:00:00.000Z' - lte: !bson_utcdatetime '2015-01-31T00:00:00.000Z' - facets: - yearFacet: - type: 'date' - path: 'released' - boundaries: - - !bson_utcdatetime '2000-01-01' - - !bson_utcdatetime '2005-01-01' - - !bson_utcdatetime '2010-01-01' - - !bson_utcdatetime '2015-01-01' - default: 'other' - - - - name: 'Metadata Results' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/facet/#examples' - pipeline: - - - $searchMeta: - facet: - operator: - range: - path: 'released' - gte: !bson_utcdatetime '2000-01-01T00:00:00.000Z' - lte: !bson_utcdatetime '2015-01-31T00:00:00.000Z' - facets: - directorsFacet: - type: 'string' - path: 'directors' - numBuckets: 7 - yearFacet: - type: 'number' - path: 'year' - boundaries: - - 2000 - - 2005 - - 2010 - - 2015 - - - - name: 'Autocomplete Bucket Results through Facet Queries' - link: 'https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/#bucket-results-through-facet-queries' - pipeline: - - - $searchMeta: - facet: - operator: - autocomplete: - path: 'title' - query: 'Gravity' - facets: - titleFacet: - type: 'string' - path: 'title' + - name: Example + link: https://www.mongodb.com/docs/atlas/atlas-search/aggregation-stages/searchMeta/#example + pipeline: + - $searchMeta: + range: + path: year + gte: 1998 + lt: 1999 + count: + type: total + schema: + movies: &ref_0 + _id: + types: + - bsonType: Document + fields: + $oid: + types: + - bsonType: String + title: + types: + - bsonType: String + year: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + runtime: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + released: + types: + - bsonType: Document + fields: + $date: + types: + - bsonType: Document + fields: + $numberLong: + types: + - bsonType: String + poster: + types: + - bsonType: String + plot: + types: + - bsonType: String + fullplot: + types: + - bsonType: String + lastupdated: + types: + - bsonType: String + type: + types: + - bsonType: String + directors: + types: + - bsonType: Array + types: + - bsonType: String + imdb: + types: + - bsonType: Document + fields: + rating: + types: + - bsonType: Document + fields: + $numberDouble: + types: + - bsonType: String + votes: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + id: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + cast: + types: + - bsonType: Array + types: + - bsonType: String + countries: + types: + - bsonType: Array + types: + - bsonType: String + genres: + types: + - bsonType: Array + types: + - bsonType: String + tomatoes: + types: + - bsonType: Document + fields: + viewer: + types: + - bsonType: Document + fields: + rating: + types: + - bsonType: Document + fields: + $numberDouble: + types: + - bsonType: String + numReviews: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + lastUpdated: + types: + - bsonType: Document + fields: + $date: + types: + - bsonType: Document + fields: + $numberLong: + types: + - bsonType: String + num_mflix_comments: + types: + - bsonType: Document + fields: + $numberInt: + types: + - bsonType: String + - name: Year Facet + link: https://www.mongodb.com/docs/atlas/atlas-search/facet/#example-1 + pipeline: + - $searchMeta: + facet: + operator: + range: + path: year + gte: 1980 + lte: 2000 + facets: + yearFacet: + type: number + path: year + boundaries: + - 1980 + - 1990 + - 2000 + default: other + schema: + movies: *ref_0 + - name: Date Facet + link: https://www.mongodb.com/docs/atlas/atlas-search/facet/#example-2 + pipeline: + - $searchMeta: + facet: + operator: + range: + path: released + gte: !bson_utcdatetime '2000-01-01T00:00:00.000Z' + lte: !bson_utcdatetime '2015-01-31T00:00:00.000Z' + facets: + yearFacet: + type: date + path: released + boundaries: + - !bson_utcdatetime '2000-01-01T00:00:00.000Z' + - !bson_utcdatetime '2005-01-01T00:00:00.000Z' + - !bson_utcdatetime '2010-01-01T00:00:00.000Z' + - !bson_utcdatetime '2015-01-01T00:00:00.000Z' + default: other + schema: + movies: *ref_0 + - name: Metadata Results + link: https://www.mongodb.com/docs/atlas/atlas-search/facet/#examples + pipeline: + - $searchMeta: + facet: + operator: + range: + path: released + gte: !bson_utcdatetime '2000-01-01T00:00:00.000Z' + lte: !bson_utcdatetime '2015-01-31T00:00:00.000Z' + facets: + directorsFacet: + type: string + path: directors + numBuckets: 7 + yearFacet: + type: number + path: year + boundaries: + - 2000 + - 2005 + - 2010 + - 2015 + schema: + movies: *ref_0 + - name: Autocomplete Bucket Results through Facet Queries + link: https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/#bucket-results-through-facet-queries + pipeline: + - $searchMeta: + facet: + operator: + autocomplete: + path: title + query: Gravity + facets: + titleFacet: + type: string + path: title + schema: + movies: *ref_0 diff --git a/generator/config/stage/set.yaml b/generator/config/stage/set.yaml index a5861aa29..ef514ba1e 100644 --- a/generator/config/stage/set.yaml +++ b/generator/config/stage/set.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $set -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/set/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/set/ type: - stage encode: single @@ -8,66 +8,143 @@ description: | Adds new fields to documents. Outputs documents that contain all existing fields from the input documents and newly added fields. Alias for $addFields. arguments: - - - name: field - type: - - expression - variadic: object + - name: field + type: + - expression + variadic: object tests: - - - name: 'Using Two $set Stages' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/set/#using-two--set-stages' - pipeline: - - - $set: - totalHomework: - # The $sum expression is always build as an array, even if the value is an array field name - # $sum: '$homework' - $sum: ['$homework'] - totalQuiz: - # $sum: '$quiz' - $sum: ['$quiz'] - - - $set: - totalScore: - $add: - - '$totalHomework' - - '$totalQuiz' - - '$extraCredit' - - - name: 'Adding Fields to an Embedded Document' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/set/#adding-fields-to-an-embedded-document' - pipeline: - - - $set: - specs.fuel_type: 'unleaded' - - - name: 'Overwriting an existing field' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/set/#overwriting-an-existing-field' - pipeline: - - - $set: - cats: 20 - - - name: 'Add Element to an Array' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/set/#add-element-to-an-array' - pipeline: - - - $match: - _id: 1 - - - $set: - homework: - $concatArrays: - - '$homework' - - - - 7 - - - name: 'Creating a New Field with Existing Fields' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/set/#creating-a-new-field-with-existing-fields' - pipeline: - - - $set: - quizAverage: - # $avg: '$quiz' - $avg: ['$quiz'] + - name: Using Two $set Stages + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/set/#using-two--set-stages + pipeline: + - $set: + totalHomework: + $sum: + - $homework + totalQuiz: + $sum: + - $quiz + - $set: + totalScore: + $add: + - $totalHomework + - $totalQuiz + - $extraCredit + schema: + scores: + _id: + types: + - bsonType: Number + student: + types: + - bsonType: String + homework: + types: + - bsonType: Array + types: + - bsonType: Number + quiz: + types: + - bsonType: Array + types: + - bsonType: Number + extraCredit: + types: + - bsonType: Number + - name: Adding Fields to an Embedded Document + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/set/#adding-fields-to-an-embedded-document + pipeline: + - $set: + specs.fuel_type: unleaded + schema: + vehicles: + _id: + types: + - bsonType: Number + type: + types: + - bsonType: String + specs: + types: + - bsonType: Document + fields: + doors: + types: + - bsonType: Number + wheels: + types: + - bsonType: Number + - name: Overwriting an existing field + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/set/#overwriting-an-existing-field + pipeline: + - $set: + cats: 20 + schema: + animals: + _id: + types: + - bsonType: Number + dogs: + types: + - bsonType: Number + cats: + types: + - bsonType: Number + - name: Add Element to an Array + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/set/#add-element-to-an-array + pipeline: + - $match: + _id: 1 + - $set: + homework: + $concatArrays: + - $homework + - - 7 + schema: + scores: + _id: + types: + - bsonType: Number + student: + types: + - bsonType: String + homework: + types: + - bsonType: Array + types: + - bsonType: Number + quiz: + types: + - bsonType: Array + types: + - bsonType: Number + extraCredit: + types: + - bsonType: Number + - name: Creating a New Field with Existing Fields + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/set/#creating-a-new-field-with-existing-fields + pipeline: + - $set: + quizAverage: + $avg: + - $quiz + schema: + scores: + _id: + types: + - bsonType: Number + student: + types: + - bsonType: String + homework: + types: + - bsonType: Array + types: + - bsonType: Number + quiz: + types: + - bsonType: Array + types: + - bsonType: Number + extraCredit: + types: + - bsonType: Number diff --git a/generator/config/stage/setWindowFields.yaml b/generator/config/stage/setWindowFields.yaml index 6f86472d7..e31c4135f 100644 --- a/generator/config/stage/setWindowFields.yaml +++ b/generator/config/stage/setWindowFields.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $setWindowFields -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/setWindowFields/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/setWindowFields/ type: - stage encode: object @@ -8,137 +8,274 @@ description: | Groups documents into windows and applies one or more operators to the documents in each window. New in MongoDB 5.0. arguments: - - - name: sortBy - type: - - sortBy - description: | - Specifies the field(s) to sort the documents by in the partition. Uses the same syntax as the $sort stage. Default is no sorting. - - - name: output - type: - - object - description: | - Specifies the field(s) to append to the documents in the output returned by the $setWindowFields stage. Each field is set to the result returned by the window operator. - A field can contain dots to specify embedded document fields and array fields. The semantics for the embedded document dotted notation in the $setWindowFields stage are the same as the $addFields and $set stages. - - - name: partitionBy - type: - - expression - description: | - Specifies an expression to group the documents. In the $setWindowFields stage, the group of documents is known as a partition. Default is one partition for the entire collection. - optional: true + - name: sortBy + type: + - sortBy + description: | + Specifies the field(s) to sort the documents by in the partition. Uses the same syntax as the $sort stage. Default is no sorting. + - name: output + type: + - object + description: | + Specifies the field(s) to append to the documents in the output returned by the $setWindowFields stage. Each field is set to the result returned by the window operator. + A field can contain dots to specify embedded document fields and array fields. The semantics for the embedded document dotted notation in the $setWindowFields stage are the same as the $addFields and $set stages. + - name: partitionBy + type: + - expression + description: | + Specifies an expression to group the documents. In the $setWindowFields stage, the group of documents is known as a partition. Default is one partition for the entire collection. + optional: true tests: - - - name: 'Use Documents Window to Obtain Cumulative Quantity for Each State' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/setWindowFields/#use-documents-window-to-obtain-cumulative-quantity-for-each-state' - pipeline: - - - $setWindowFields: - partitionBy: '$state' - sortBy: - orderDate: 1 - output: - cumulativeQuantityForState: - $sum: '$quantity' - window: - documents: ['unbounded', 'current'] - - - name: 'Use Documents Window to Obtain Cumulative Quantity for Each Year' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/setWindowFields/#use-documents-window-to-obtain-cumulative-quantity-for-each-year' - pipeline: - - - $setWindowFields: - partitionBy: - # $year: '$orderDate' - $year: - date: '$orderDate' - sortBy: - orderDate: 1 - output: - cumulativeQuantityForYear: - $sum: '$quantity' - window: - documents: ['unbounded', 'current'] - - - name: 'Use Documents Window to Obtain Moving Average Quantity for Each Year' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/setWindowFields/#use-documents-window-to-obtain-moving-average-quantity-for-each-year' - pipeline: - - - $setWindowFields: - partitionBy: - # $year: '$orderDate' - $year: - date: '$orderDate' - sortBy: - orderDate: 1 - output: - averageQuantity: - $avg: '$quantity' - window: - documents: [-1, 0] - - - name: 'Use Documents Window to Obtain Cumulative and Maximum Quantity for Each Year' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/setWindowFields/#use-documents-window-to-obtain-cumulative-and-maximum-quantity-for-each-year' - pipeline: - - - $setWindowFields: - partitionBy: - # $year: '$orderDate' - $year: - date: '$orderDate' - sortBy: - orderDate: 1 - output: - cumulativeQuantityForYear: - $sum: '$quantity' - window: - documents: ['unbounded', 'current'] - maximumQuantityForYear: - $max: '$quantity' - window: - documents: ['unbounded', 'unbounded'] - - - name: 'Range Window Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/setWindowFields/#range-window-example' - pipeline: - - - $setWindowFields: - partitionBy: '$state' - sortBy: - price: 1 - output: - quantityFromSimilarOrders: - $sum: '$quantity' - window: - range: [-10, 10] - - - name: 'Use a Time Range Window with a Positive Upper Bound' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/setWindowFields/#use-a-time-range-window-with-a-positive-upper-bound' - pipeline: - - - $setWindowFields: - partitionBy: '$state' - sortBy: - orderDate: 1 - output: - recentOrders: - $push: '$orderDate' - window: - range: ['unbounded', 10] - unit: 'month' - - - name: 'Use a Time Range Window with a Negative Upper Bound' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/setWindowFields/#use-a-time-range-window-with-a-negative-upper-bound' - pipeline: - - - $setWindowFields: - partitionBy: '$state' - sortBy: - orderDate: 1 - output: - recentOrders: - $push: '$orderDate' - window: - range: ['unbounded', -10] - unit: 'month' + - name: Use Documents Window to Obtain Cumulative Quantity for Each State + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/setWindowFields/#use-documents-window-to-obtain-cumulative-quantity-for-each-state + pipeline: + - $setWindowFields: + partitionBy: $state + sortBy: + orderDate: 1 + output: + cumulativeQuantityForState: + $sum: $quantity + window: + documents: + - unbounded + - current + schema: + cakeSales: + _id: + types: + - bsonType: Number + type: + types: + - bsonType: String + orderDate: + types: + - bsonType: Date + state: + types: + - bsonType: String + price: + types: + - bsonType: Number + quantity: + types: + - bsonType: Number + - name: Use Documents Window to Obtain Cumulative Quantity for Each Year + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/setWindowFields/#use-documents-window-to-obtain-cumulative-quantity-for-each-year + pipeline: + - $setWindowFields: + partitionBy: + $year: + date: $orderDate + sortBy: + orderDate: 1 + output: + cumulativeQuantityForYear: + $sum: $quantity + window: + documents: + - unbounded + - current + schema: + cakeSales: + _id: + types: + - bsonType: Number + type: + types: + - bsonType: String + orderDate: + types: + - bsonType: Date + state: + types: + - bsonType: String + price: + types: + - bsonType: Number + quantity: + types: + - bsonType: Number + - name: Use Documents Window to Obtain Moving Average Quantity for Each Year + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/setWindowFields/#use-documents-window-to-obtain-moving-average-quantity-for-each-year + pipeline: + - $setWindowFields: + partitionBy: + $year: + date: $orderDate + sortBy: + orderDate: 1 + output: + averageQuantity: + $avg: $quantity + window: + documents: + - -1 + - 0 + schema: + cakeSales: + _id: + types: + - bsonType: Number + type: + types: + - bsonType: String + orderDate: + types: + - bsonType: Date + state: + types: + - bsonType: String + price: + types: + - bsonType: Number + quantity: + types: + - bsonType: Number + - name: Use Documents Window to Obtain Cumulative and Maximum Quantity for Each + Year + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/setWindowFields/#use-documents-window-to-obtain-cumulative-and-maximum-quantity-for-each-year + pipeline: + - $setWindowFields: + partitionBy: + $year: + date: $orderDate + sortBy: + orderDate: 1 + output: + cumulativeQuantityForYear: + $sum: $quantity + window: + documents: + - unbounded + - current + maximumQuantityForYear: + $max: $quantity + window: + documents: + - unbounded + - unbounded + schema: + cakeSales: + _id: + types: + - bsonType: Number + type: + types: + - bsonType: String + orderDate: + types: + - bsonType: Date + state: + types: + - bsonType: String + price: + types: + - bsonType: Number + quantity: + types: + - bsonType: Number + - name: Range Window Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/setWindowFields/#range-window-example + pipeline: + - $setWindowFields: + partitionBy: $state + sortBy: + price: 1 + output: + quantityFromSimilarOrders: + $sum: $quantity + window: + range: + - -10 + - 10 + schema: + cakeSales: + _id: + types: + - bsonType: Number + type: + types: + - bsonType: String + orderDate: + types: + - bsonType: Date + state: + types: + - bsonType: String + price: + types: + - bsonType: Number + quantity: + types: + - bsonType: Number + - name: Use a Time Range Window with a Positive Upper Bound + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/setWindowFields/#use-a-time-range-window-with-a-positive-upper-bound + pipeline: + - $setWindowFields: + partitionBy: $state + sortBy: + orderDate: 1 + output: + recentOrders: + $push: $orderDate + window: + range: + - unbounded + - 10 + unit: month + schema: + cakeSales: + _id: + types: + - bsonType: Number + type: + types: + - bsonType: String + orderDate: + types: + - bsonType: Date + state: + types: + - bsonType: String + price: + types: + - bsonType: Number + quantity: + types: + - bsonType: Number + - name: Use a Time Range Window with a Negative Upper Bound + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/setWindowFields/#use-a-time-range-window-with-a-negative-upper-bound + pipeline: + - $setWindowFields: + partitionBy: $state + sortBy: + orderDate: 1 + output: + recentOrders: + $push: $orderDate + window: + range: + - unbounded + - -10 + unit: month + schema: + cakeSales: + _id: + types: + - bsonType: Number + type: + types: + - bsonType: String + orderDate: + types: + - bsonType: Date + state: + types: + - bsonType: String + price: + types: + - bsonType: Number + quantity: + types: + - bsonType: Number diff --git a/generator/config/stage/shardedDataDistribution.yaml b/generator/config/stage/shardedDataDistribution.yaml index 2f298ca0f..87864231e 100644 --- a/generator/config/stage/shardedDataDistribution.yaml +++ b/generator/config/stage/shardedDataDistribution.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $shardedDataDistribution -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/shardedDataDistribution/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/shardedDataDistribution/ type: - stage encode: object @@ -8,9 +8,12 @@ description: | Provides data and size distribution information on sharded collections. New in MongoDB 6.0.3. tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/shardedDataDistribution/#examples' - pipeline: - - - $shardedDataDistribution: {} + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/shardedDataDistribution/#examples + pipeline: + - $shardedDataDistribution: {} + schema: + TestCollection: + _id: + types: + - bsonType: ObjectId diff --git a/generator/config/stage/skip.yaml b/generator/config/stage/skip.yaml index 2128fe226..cb9ad7c50 100644 --- a/generator/config/stage/skip.yaml +++ b/generator/config/stage/skip.yaml @@ -1,20 +1,22 @@ # $schema: ../schema.json name: $skip -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/skip/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/skip/ type: - stage encode: single description: | 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). arguments: - - - name: skip - type: - - int + - name: skip + type: + - int tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/skip/#example' - pipeline: - - - $skip: 5 + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/skip/#examples + pipeline: + - $skip: 5 + schema: + TestCollection: + _id: + types: + - bsonType: ObjectId diff --git a/generator/config/stage/sort.yaml b/generator/config/stage/sort.yaml index d35e23b63..be4776c6d 100644 --- a/generator/config/stage/sort.yaml +++ b/generator/config/stage/sort.yaml @@ -1,37 +1,44 @@ # $schema: ../schema.json name: $sort -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/sort/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/sort/ type: - stage encode: single description: | Reorders the document stream by a specified sort key. Only the order changes; the documents remain unmodified. For each input document, outputs one document. arguments: - - - name: sort - type: - - expression - - sortSpec - variadic: object + - name: sort + type: + - expression + - sortSpec + variadic: object tests: - - - name: 'Ascending Descending Sort' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/sort/#ascending-descending-sort' - pipeline: - - - $sort: - age: -1 - posts: 1 - - - name: 'Text Score Metadata Sort' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/sort/#text-score-metadata-sort' - pipeline: - - - $match: - $text: - $search: 'operating' - - - $sort: - score: - $meta: 'textScore' - posts: -1 + - name: Ascending Descending Sort + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/sort/#ascending-descending-sort + pipeline: + - $sort: + age: -1 + posts: 1 + schema: + users: &ref_0 + age: + types: + - bsonType: Int32 + posts: + types: + - bsonType: Int32 + name: + types: + - bsonType: String + - name: Text Score Metadata Sort + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/sort/#text-score-metadata-sort + pipeline: + - $match: + $text: + $search: operating + - $sort: + score: + $meta: textScore + posts: -1 + schema: + users: *ref_0 diff --git a/generator/config/stage/sortByCount.yaml b/generator/config/stage/sortByCount.yaml index a32d7aff4..5565fa550 100644 --- a/generator/config/stage/sortByCount.yaml +++ b/generator/config/stage/sortByCount.yaml @@ -1,25 +1,38 @@ # $schema: ../schema.json name: $sortByCount -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/sortByCount/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/sortByCount/ type: - stage encode: single description: | Groups incoming documents based on the value of a specified expression, then computes the count of documents in each distinct group. arguments: - - - name: expression - type: - - expression + - name: expression + type: + - expression tests: - - - name: 'Example' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/sortByCount/#example' - pipeline: - - - # The builder uses the verbose form of the $unwind operator - # $unwind: '$tags' - $unwind: - path: '$tags' - - - $sortByCount: '$tags' + - name: Example + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/sortByCount/#examples + pipeline: + - $unwind: + path: $tags + - $sortByCount: $tags + schema: + exhibits: + _id: + types: + - bsonType: Number + title: + types: + - bsonType: String + artist: + types: + - bsonType: String + year: + types: + - bsonType: Number + tags: + types: + - bsonType: Array + types: + - bsonType: String diff --git a/generator/config/stage/unionWith.yaml b/generator/config/stage/unionWith.yaml index eafa44110..722b8c843 100644 --- a/generator/config/stage/unionWith.yaml +++ b/generator/config/stage/unionWith.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $unionWith -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/unionWith/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/unionWith/ type: - stage encode: object @@ -8,76 +8,77 @@ description: | Performs a union of two collections; i.e. combines pipeline results from two collections into a single result set. New in MongoDB 4.4. arguments: - - - name: coll - type: - - string - description: | - The collection or view whose pipeline results you wish to include in the result set. - - - name: pipeline - type: - - pipeline - optional: true - description: | - 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. + - name: coll + type: + - string + description: | + The collection or view whose pipeline results you wish to include in the result set. + - name: pipeline + type: + - pipeline + optional: true + description: | + 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. tests: - - - name: 'Report 1 All Sales by Year and Stores and Items' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/unionWith/#report-1--all-sales-by-year-and-stores-and-items' - 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 - - - name: 'Report 2 Aggregated Sales by Items' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/unionWith/#report-2--aggregated-sales-by-items' - pipeline: - - - # Example uses the short form, the builder always generates the verbose form - # $unionWith: 'sales_2018' - $unionWith: - coll: 'sales_2018' - - - # $unionWith: 'sales_2019' - $unionWith: - coll: 'sales_2019' - - - # $unionWith: 'sales_2020' - $unionWith: - coll: 'sales_2020' - - - $group: - _id: '$item' - total: - $sum: '$quantity' - - - $sort: - total: -1 + - name: Report 1 All Sales by Year and Stores and Items + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/unionWith/#report-1--all-sales-by-year-and-stores-and-items + 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 + schema: + sales_2017: + store: + types: + - bsonType: String + item: + types: + - bsonType: String + quantity: + types: + - bsonType: Number + - name: Report 2 Aggregated Sales by Items + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/unionWith/#report-2--aggregated-sales-by-items + pipeline: + - $unionWith: + coll: sales_2018 + - $unionWith: + coll: sales_2019 + - $unionWith: + coll: sales_2020 + - $group: + _id: $item + total: + $sum: $quantity + - $sort: + total: -1 + schema: + sales_2017: + store: + types: + - bsonType: String + item: + types: + - bsonType: String + quantity: + types: + - bsonType: Number diff --git a/generator/config/stage/unset.yaml b/generator/config/stage/unset.yaml index cef9cdd6d..39a7a81a3 100644 --- a/generator/config/stage/unset.yaml +++ b/generator/config/stage/unset.yaml @@ -1,6 +1,6 @@ # $schema: ../schema.json name: $unset -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/unset/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/unset/ type: - stage encode: single @@ -8,35 +8,125 @@ description: | Removes or excludes fields from documents. Alias for $project stage that removes or excludes fields. arguments: - - - name: field - type: - - fieldPath - variadic: array + - name: field + type: + - unprefixedFieldPath + variadic: array tests: - - - name: 'Remove a Single Field' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/unset/#remove-a-single-field' - pipeline: - - - # The example in the docs uses the short syntax whereas - # the aggregation builder always uses the equivalent array syntax. - # $unset: 'copies' - $unset: ['copies'] - - - name: 'Remove Top-Level Fields' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/unset/#remove-top-level-fields' - pipeline: - - - $unset: - - 'isbn' - - 'copies' - - - name: 'Remove Embedded Fields' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/unset/#remove-embedded-fields' - pipeline: - - - $unset: - - 'isbn' - - 'author.first' - - 'copies.warehouse' + - name: Remove a Single Field + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/unset/#remove-a-single-field + pipeline: + - $unset: + - copies + schema: + books: + _id: + types: + - bsonType: Number + title: + types: + - bsonType: String + isbn: + types: + - bsonType: String + author: + types: + - bsonType: Document + fields: + last: + types: + - bsonType: String + first: + types: + - bsonType: String + copies: + types: + - bsonType: Array + types: + - bsonType: Document + fields: + warehouse: + types: + - bsonType: String + qty: + types: + - bsonType: Number + - name: Remove Top-Level Fields + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/unset/#remove-top-level-fields + pipeline: + - $unset: + - isbn + - copies + schema: + books: + _id: + types: + - bsonType: Number + title: + types: + - bsonType: String + isbn: + types: + - bsonType: String + author: + types: + - bsonType: Document + fields: + last: + types: + - bsonType: String + first: + types: + - bsonType: String + copies: + types: + - bsonType: Array + types: + - bsonType: Document + fields: + warehouse: + types: + - bsonType: String + qty: + types: + - bsonType: Number + - name: Remove Embedded Fields + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/unset/#remove-embedded-fields + pipeline: + - $unset: + - isbn + - author.first + - copies.warehouse + schema: + books: + _id: + types: + - bsonType: Number + title: + types: + - bsonType: String + isbn: + types: + - bsonType: String + author: + types: + - bsonType: Document + fields: + last: + types: + - bsonType: String + first: + types: + - bsonType: String + copies: + types: + - bsonType: Array + types: + - bsonType: Document + fields: + warehouse: + types: + - bsonType: String + qty: + types: + - bsonType: Number diff --git a/generator/config/stage/unwind.yaml b/generator/config/stage/unwind.yaml index a1f93edbc..ecad4b6fc 100644 --- a/generator/config/stage/unwind.yaml +++ b/generator/config/stage/unwind.yaml @@ -1,95 +1,154 @@ # $schema: ../schema.json name: $unwind -link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/unwind/' +link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/unwind/ type: - stage encode: object description: | 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. arguments: - - - name: path - type: - - arrayFieldPath - description: | - Field path to an array field. - - - name: includeArrayIndex - type: - - string - optional: true - description: | - The name of a new field to hold the array index of the element. The name cannot start with a dollar sign $. - - - name: preserveNullAndEmptyArrays - type: - - bool - optional: true - description: | - If true, if the path is null, missing, or an empty array, $unwind outputs the document. - If false, if path is null, missing, or an empty array, $unwind does not output a document. - The default value is false. + - name: path + type: + - arrayFieldPath + description: | + Field path to an array field. + - name: includeArrayIndex + type: + - string + optional: true + description: | + The name of a new field to hold the array index of the element. The name cannot start with a dollar sign $. + - name: preserveNullAndEmptyArrays + type: + - bool + optional: true + description: | + If true, if the path is null, missing, or an empty array, $unwind outputs the document. + If false, if path is null, missing, or an empty array, $unwind does not output a document. + The default value is false. tests: - - - name: 'Unwind Array' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/unwind/#unwind-array' - pipeline: - - - # Example uses the short form, the builder always generates the verbose form - # $unwind: '$sizes' - $unwind: - path: '$sizes' - - - name: 'preserveNullAndEmptyArrays' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/unwind/#preservenullandemptyarrays' - pipeline: - - - $unwind: - path: '$sizes' - preserveNullAndEmptyArrays: true - - - name: 'includeArrayIndex' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/unwind/#includearrayindex' - pipeline: - - - $unwind: - path: '$sizes' - includeArrayIndex: 'arrayIndex' - - - name: 'Group by Unwound Values' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/unwind/#group-by-unwound-values' - pipeline: - - - $unwind: - path: '$sizes' - preserveNullAndEmptyArrays: true - - - $group: - _id: '$sizes' - averagePrice: - $avg: '$price' - - - $sort: - averagePrice: -1 - - - name: 'Unwind Embedded Arrays' - link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/unwind/#unwind-embedded-arrays' - pipeline: - - - # Example uses the short form, the builder always generates the verbose form - # $unwind: '$items' - $unwind: - path: '$items' - - - # Example uses the short form, the builder always generates the verbose form - # $unwind: '$items.tags' - $unwind: - path: '$items.tags' - - - $group: - _id: '$items.tags' - totalSalesAmount: - $sum: - $multiply: - - '$items.price' - - '$items.quantity' + - name: Unwind Array + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/unwind/#unwind-array + pipeline: + - $unwind: + path: $sizes + schema: + inventory: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + sizes: + types: + - bsonType: Array + types: + - bsonType: String + - name: preserveNullAndEmptyArrays + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/unwind/#preservenullandemptyarrays + pipeline: + - $unwind: + path: $sizes + preserveNullAndEmptyArrays: true + schema: + inventory: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + sizes: + types: + - bsonType: Array + types: + - bsonType: String + - name: includeArrayIndex + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/unwind/#includearrayindex + pipeline: + - $unwind: + path: $sizes + includeArrayIndex: arrayIndex + schema: + inventory: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + sizes: + types: + - bsonType: Array + types: + - bsonType: String + - name: Group by Unwound Values + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/unwind/#group-by-unwound-values + pipeline: + - $unwind: + path: $sizes + preserveNullAndEmptyArrays: true + - $group: + _id: $sizes + averagePrice: + $avg: $price + - $sort: + averagePrice: -1 + schema: + inventory2: + _id: + types: + - bsonType: Number + item: + types: + - bsonType: String + price: + types: + - bsonType: Decimal128 + sizes: + types: + - bsonType: Array + types: + - bsonType: String + - bsonType: String + - bsonType: 'Null' + - name: Unwind Embedded Arrays + link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/unwind/#unwind-embedded-arrays + pipeline: + - $unwind: + path: $items + - $unwind: + path: $items.tags + - $group: + _id: $items.tags + totalSalesAmount: + $sum: + $multiply: + - $items.price + - $items.quantity + schema: + sales: + _id: + types: + - bsonType: String + items: + types: + - bsonType: Array + types: + - bsonType: Document + fields: + name: + types: + - bsonType: String + tags: + types: + - bsonType: Array + types: + - bsonType: String + price: + types: + - bsonType: Decimal128 + quantity: + types: + - bsonType: Int32 diff --git a/generator/config/stage/vectorSearch.yaml b/generator/config/stage/vectorSearch.yaml index bcd3c008a..a5d1a4e63 100644 --- a/generator/config/stage/vectorSearch.yaml +++ b/generator/config/stage/vectorSearch.yaml @@ -1,119 +1,141 @@ # $schema: ../schema.json name: $vectorSearch -link: 'https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-stage/' +link: https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-stage/ type: - stage encode: object description: | The $vectorSearch stage performs an ANN or ENN search on a vector in the specified field. arguments: - - - name: index - type: - - string - description: | - Name of the Atlas Vector Search index to use. - - - name: limit - type: - - int - description: | - Number of documents to return in the results. This value can't exceed the value of numCandidates if you specify numCandidates. - - - name: path - type: - - string - description: | - Indexed vector type field to search. - - - name: queryVector - type: - - array # of numbers - description: | - Array of numbers that represent the query vector. The number type must match the indexed field value type. - - - name: exact - optional: true - type: - - bool - description: | - This is required if numCandidates is omitted. false to run ANN search. true to run ENN search. - - - name: filter - optional: true - type: - - query - description: | - 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. - - - name: numCandidates - optional: true - type: - - int - description: | - This field is required if exact is false or omitted. - 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). - + - name: index + type: + - string + description: | + Name of the Atlas Vector Search index to use. + - name: limit + type: + - int + description: | + Number of documents to return in the results. This value can't exceed the value of numCandidates if you specify numCandidates. + - name: path + type: + - string + description: | + Indexed vector type field to search. + - name: queryVector + type: + - array + description: | + Array of numbers that represent the query vector. The number type must match the indexed field value type. + - name: exact + optional: true + type: + - bool + description: | + This is required if numCandidates is omitted. false to run ANN search. true to run ENN search. + - name: filter + optional: true + type: + - query + description: | + 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. + - name: numCandidates + optional: true + type: + - int + description: | + This field is required if exact is false or omitted. + 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). tests: - - - name: 'ANN Basic' - link: 'https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-stage/#ann-examples' - pipeline: - - - $vectorSearch: - index: 'vector_index' - path: 'plot_embedding' - queryVector: [-0.0016261312, -0.028070757, -0.011342932] # skip other numbers, not relevant to the test - numCandidates: 150 - limit: 10 - - - $project: - _id: 0 - plot: 1 - title: 1 - score: - $meta: 'vectorSearchScore' - - - - name: 'ANN Filter' - link: 'https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-stage/#ann-examples' - pipeline: - - - $vectorSearch: - index: 'vector_index' - path: 'plot_embedding' - filter: - $and: - - - year: - $lt: 1975 - queryVector: [0.02421053, -0.022372592, -0.006231137] # skip other numbers, not relevant to the test - numCandidates: 150 - limit: 10 - - - $project: - _id: 0 - title: 1 - plot: 1 - year: 1 - score: - $meta: 'vectorSearchScore' - - - - name: 'ENN' - link: 'https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-stage/#enn-examples' - pipeline: - - - $vectorSearch: - index: 'vector_index' - path: 'plot_embedding' - queryVector: [-0.006954097, -0.009932499, -0.001311474] # skip other numbers, not relevant to the test - exact: true - limit: 10 - - - $project: - _id: 0 - plot: 1 - title: 1 - score: - $meta: 'vectorSearchScore' + - name: ANN Basic + link: https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-stage/#ann-examples + 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 + schema: + TestCollection: + plot: + types: + - bsonType: String + title: + types: + - bsonType: String + score: + types: + - bsonType: Number + - name: ANN Filter + link: https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-stage/#ann-examples + pipeline: + - $vectorSearch: + index: vector_index + path: plot_embedding + filter: + $and: + - year: + $lt: 1975 + queryVector: + - 0.02421053 + - -0.022372592 + - -0.006231137 + numCandidates: 150 + limit: 10 + - $project: + _id: 0 + title: 1 + plot: 1 + year: 1 + score: + $meta: vectorSearchScore + schema: + TestCollection: + plot: + types: + - bsonType: String + title: + types: + - bsonType: String + score: + types: + - bsonType: Number + - name: ENN + link: https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-stage/#enn-example + 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 + schema: + TestCollection: + plot: + types: + - bsonType: String + title: + types: + - bsonType: String + score: + types: + - bsonType: Number