From 6fe98091c0f46b0c3bbc1d99c368529677719102 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Wed, 4 Oct 2023 12:02:41 +0200 Subject: [PATCH 01/37] Create Yaml files from Google Sheet --- generator/composer.json | 2 + generator/config/schema.json | 122 ++++++++++++ generator/generate | 2 + generator/src/Command/ScrapeCommand.php | 235 ++++++++++++++++++++++++ 4 files changed, 361 insertions(+) create mode 100644 generator/config/schema.json create mode 100644 generator/src/Command/ScrapeCommand.php diff --git a/generator/composer.json b/generator/composer.json index 7974a887e..436f0ad75 100644 --- a/generator/composer.json +++ b/generator/composer.json @@ -18,6 +18,8 @@ "mongodb/mongodb": "@dev", "nette/php-generator": "^4", "symfony/console": "^6.3", + "symfony/css-selector": "^6.3", + "symfony/dom-crawler": "^6.3", "symfony/yaml": "^6.3" }, "license": "Apache-2.0", diff --git a/generator/config/schema.json b/generator/config/schema.json new file mode 100644 index 000000000..422b52c39 --- /dev/null +++ b/generator/config/schema.json @@ -0,0 +1,122 @@ +{ + "$schema": "http://json-schema.org/draft-06/schema#", + "$ref": "#/definitions/Operator", + "definitions": { + "Operator": { + "type": "object", + "additionalProperties": false, + "properties": { + "name": { + "$comment": "The name of the operator. Must start with a $", + "type": "string", + "pattern": "^\\$[a-z][a-zA-Z]+$" + }, + "category": { + "$comment": "The category as defined by MongoDB's documentation.", + "type": "array", + "items": { + "type": "string" + } + }, + "link": { + "$comment": "The link to the operator's documentation on MongoDB's website.", + "type": "string", + "format": "uri", + "qt-uri-protocols": [ + "https" + ] + }, + "returnType": { + "type": "array", + "items": { + "type": "string" + } + }, + "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", + "type": "string", + "enum": [ + "array", + "object", + "single" + ] + }, + "description": { + "$comment": "The description of the argument from MongoDB's documentation.", + "type": "string" + }, + "parameters": { + "$comment": "An optional list of parameters for the operator.", + "type": "array", + "items": { + "$ref": "#/definitions/Parameter" + } + } + }, + "required": [ + "category", + "description", + "encode", + "link", + "name", + "parameters", + "returnType" + ], + "title": "Operator" + }, + "Parameter": { + "type": "object", + "additionalProperties": false, + "properties": { + "name": { + "type": "string", + "pattern": "^[a-z][a-zA-Z0-9]+$" + }, + "returnType": { + "type": "array", + "items": { + "type": "string" + } + }, + "description": { + "$comment": "The description of the argument from MongoDB's documentation.", + "type": "string" + }, + "optional": { + "$comment": "Whether the parameter is optional or not.", + "type": "boolean" + }, + "valueMin": { + "$comment": "The minimum value for a numeric parameter.", + "type": "number" + }, + "valueMax": { + "$comment": "The minimum value for a numeric parameter.", + "type": "number" + }, + "variadic": { + "$comment": "Whether the parameter is variadic or not.", + "type": "string", + "enum": [ + "list", + "map" + ] + }, + "variadicMin": { + "$comment": "The minimum number of arguments for a variadic parameter.", + "type": "integer", + "minimum": 0 + } + }, + "required": [ + "description", + "name", + "type" + ], + "title": "Parameter" + } + } +} diff --git a/generator/generate b/generator/generate index 017dbef6e..caa436278 100755 --- a/generator/generate +++ b/generator/generate @@ -2,6 +2,7 @@ add(new GenerateCommand(__DIR__ . '/../', __DIR__ . '/config')); +$application->add(new ScrapeCommand(__DIR__ . '/config')); $application->setDefaultCommand('generate'); $application->run(); diff --git a/generator/src/Command/ScrapeCommand.php b/generator/src/Command/ScrapeCommand.php new file mode 100644 index 000000000..5b455eaf0 --- /dev/null +++ b/generator/src/Command/ScrapeCommand.php @@ -0,0 +1,235 @@ + $tabs Associative array of names to table ids */ + private array $tabs; + + public function __construct( + private string $configDir, + ) { + parent::__construct(); + } + + public function configure(): void + { + $this->setName('scrape'); + } + + public function execute(InputInterface $input, OutputInterface $output): int + { + $index = file_get_contents('https://docs.google.com/spreadsheets/d/e/2PACX-1vROpGTJGXAKf2SVuSZaw16NwMVtzMVGH9b-YiMtddgZRZOjOO6jK2YLbTUZ0N_qe74nxGY9hYhUe-l2/pubhtml'); + $this->crawler = new Crawler($index); + $this->extractTabs(); + + $docs = $this->getTableData($this->crawler, 'aggregation pipeline operators'); + foreach ($docs as $doc) { + $this->writeYamlFile('aggregation-operators', $this->formatSpec($doc)); + } + + $docs = $this->getTableData($this->crawler, 'query operators'); + foreach ($docs as $doc) { + $this->writeYamlFile('query-operators', $this->formatSpec($doc)); + } + + $docs = $this->getTableData($this->crawler, 'aggregation pipeline stages'); + foreach ($docs as $doc) { + $this->writeYamlFile('aggregation-stages', $this->formatSpec($doc)); + } + + return Command::SUCCESS; + } + + private function extractTabs(): void + { + // Extract tab names and ids + $tabs = $this->crawler->filter('#sheet-menu > li')->each(fn (Crawler $li) => [ + 'name' => $li->text(), + 'id' => str_replace('sheet-button-', '', $li->attr('id')), + ]); + + $this->tabs = array_combine(array_column($tabs, 'name'), array_column($tabs, 'id')); + } + + private function getTableData(Crawler $crawler, string $tabName): array + { + $id = $this->tabs[$tabName] ?? throw new InvalidArgumentException('Invalid tab name: ' . $tabName); + + $table = $crawler->filter('#' . $id . ' table > tbody'); + + // Load the table into a 2D array + $rows = []; + $table->filter('tr')->each(function (Crawler $row, $rowIndex) use (&$rows): void { + $cellIndex = 0; + + $row->filter('td')->each(function (Crawler $cell) use (&$rows, &$rowIndex, &$cellIndex): bool { + // Skip freezebar cells + if (str_contains($cell->attr('class') ?? '', 'freezebar-cell')) { + return true; + } + + $rowspan = $cell->attr('rowspan') ?: 1; + + // Advance to the next available cell + while (array_key_exists($rowIndex, $rows) && array_key_exists($cellIndex, $rows[$rowIndex])) { + $cellIndex++; + } + + $value = $cell->html(); + $value = str_replace(['
', '
', '
'], PHP_EOL, $value); + $value = strip_tags($value); + $value = htmlspecialchars_decode($value); + $value = trim($value); + + // Fill the next cells with null for colspan and rowspan + for ($rowIndexLoop = $rowIndex; $rowIndexLoop < $rowIndex + $rowspan; $rowIndexLoop++) { + if ($rowIndexLoop === $rowIndex) { + $rows[$rowIndexLoop][$cellIndex] = $value; + } else { + $rows[$rowIndexLoop][$cellIndex] = null; + } + } + + return false; + }); + + if (isset($rows[$rowIndex])) { + ksort($rows[$rowIndex]); + } + }); + + // Extract headers from first row + $headers = array_shift($rows); + + // Map header to field names + aggregate args + $docs = []; + $docId = 0; + $argId = 0; + foreach ($rows as $row) { + // Create a new document for each row that starts with a non-empty cell + if ($row[0] && $docs !== []) { + $docId++; + $argId = 0; + } + + foreach ($row as $index => $cell) { + if (str_contains($headers[$index], 'Arg')) { + $docs[$docId]['Args'][$argId][str_replace('Arg', '', $headers[$index])] = $cell; + } elseif (null !== $cell) { + $docs[$docId][$headers[$index]] = $cell; + } + } + + $argId++; + } + + return $docs; + } + + /** + * @param array{ + * Name: string, + * Category: string, + * Description: string, + * Link: string, + * ReturnType: string, + * Encode: string, + * Args: array{ Name: string, Type: string, Options: string, Description: string } + * } $doc + */ + private function formatSpec(array $doc): array + { + foreach (['Name', 'Category', 'Description', 'Link', 'ReturnType', 'Encode', 'Args'] as $key) { + assert(isset($doc[$key]), 'Missing ' . $key . ' for ' . var_export($doc, true)); + } + + $spec = []; + $spec['name'] = $doc['Name']; + $spec['category'] = explode(PHP_EOL, $doc['Category']); + sort($spec['category']); + $spec['link'] = $doc['Link']; + $spec['returnType'] = explode(PHP_EOL, $doc['ReturnType']); + $spec['encode'] = $doc['Encode']; + + if ($doc['Description']) { + $spec['description'] = $doc['Description'] . PHP_EOL; + } + + foreach ($doc['Args'] as $arg) { + foreach (['Name', 'Type', 'Options', 'Description'] as $key) { + assert(isset($arg[$key]), 'Missing Arg' . $key . ' for ' . var_export($doc, true)); + } + + $parameter = []; + $parameter['name'] = $arg['Name']; + $parameter['type'] = explode(PHP_EOL, $doc['ReturnType']); + if (str_contains($arg['Options'], 'Optional')) { + $parameter['optional'] = true; + } + + if ($arg['Description']) { + $parameter['description'] = $arg['Description'] . PHP_EOL; + } + + $spec['parameters'][] = $parameter; + } + + return $spec; + } + + private function writeYamlFile(string $dirname, array $data): void + { + $yaml = Yaml::dump($data, 3, 4, Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK); + $dirname = $this->configDir . '/' . $dirname; + if (! file_exists($dirname)) { + mkdir($dirname, 0755); + } + + $name = str_replace('$', '', $data['name']) ?: 'positional'; + $filename = $dirname . '/' . $name . '.yaml'; + + // Add a schema reference to the top of the file + $schema = '# $schema: ../schema.json' . PHP_EOL; + + // Add a trailing newline if one is not present + if (! str_ends_with($yaml, PHP_EOL)) { + $yaml .= PHP_EOL; + } + + file_put_contents($filename, $schema . $yaml); + } +} From 204e88fe1cc906c083719c68709fa46bf97caa3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Thu, 5 Oct 2023 01:40:07 +0200 Subject: [PATCH 02/37] Import all operators and stages --- generator/composer.json | 1 + .../config/aggregation-operators/abs.yaml | 15 + .../aggregation-operators/accumulator.yaml | 57 + .../config/aggregation-operators/acos.yaml | 20 + .../config/aggregation-operators/acosh.yaml | 20 + .../config/aggregation-operators/add.yaml | 21 + .../aggregation-operators/addToSet.yaml | 18 + .../allElementsTrue.yaml | 16 + .../config/aggregation-operators/and.yaml | 20 + .../aggregation-operators/anyElementTrue.yaml | 15 + .../aggregation-operators/arrayElemAt.yaml | 19 + .../aggregation-operators/arrayToObject.yaml | 15 + .../config/aggregation-operators/asin.yaml | 20 + .../config/aggregation-operators/asinh.yaml | 20 + .../config/aggregation-operators/atan.yaml | 20 + .../config/aggregation-operators/atan2.yaml | 24 + .../config/aggregation-operators/atanh.yaml | 20 + .../config/aggregation-operators/avg.yaml | 20 + .../aggregation-operators/binarySize.yaml | 17 + .../config/aggregation-operators/bitAnd.yaml | 19 + .../config/aggregation-operators/bitNot.yaml | 18 + .../config/aggregation-operators/bitOr.yaml | 19 + .../config/aggregation-operators/bitXor.yaml | 12 + .../config/aggregation-operators/bottom.yaml | 27 + .../config/aggregation-operators/bottomN.yaml | 32 + .../aggregation-operators/bsonSize.yaml | 16 + .../config/aggregation-operators/ceil.yaml | 17 + .../config/aggregation-operators/cmp.yaml | 19 + .../config/aggregation-operators/concat.yaml | 16 + .../aggregation-operators/concatArrays.yaml | 16 + .../config/aggregation-operators/cond.yaml | 23 + .../config/aggregation-operators/convert.yaml | 37 + .../config/aggregation-operators/cos.yaml | 19 + .../config/aggregation-operators/cosh.yaml | 19 + .../config/aggregation-operators/count.yaml | 18 + .../aggregation-operators/covariancePop.yaml | 21 + .../aggregation-operators/covarianceSamp.yaml | 21 + .../config/aggregation-operators/dateAdd.yaml | 37 + .../aggregation-operators/dateDiff.yaml | 47 + .../aggregation-operators/dateFromParts.yaml | 86 + .../aggregation-operators/dateFromString.yaml | 49 + .../aggregation-operators/dateSubtract.yaml | 37 + .../aggregation-operators/dateToParts.yaml | 33 + .../aggregation-operators/dateToString.yaml | 43 + .../aggregation-operators/dateTrunc.yaml | 49 + .../aggregation-operators/dayOfMonth.yaml | 26 + .../aggregation-operators/dayOfWeek.yaml | 26 + .../aggregation-operators/dayOfYear.yaml | 26 + .../degreesToRadians.yaml | 19 + .../aggregation-operators/denseRank.yaml | 11 + .../aggregation-operators/derivative.yaml | 25 + .../config/aggregation-operators/divide.yaml | 21 + .../aggregation-operators/documentNumber.yaml | 11 + .../config/aggregation-operators/eq.yaml | 19 + .../config/aggregation-operators/exp.yaml | 15 + .../aggregation-operators/expMovingAvg.yaml | 33 + .../config/aggregation-operators/filter.yaml | 36 + .../config/aggregation-operators/first.yaml | 19 + .../config/aggregation-operators/firstN.yaml | 23 + .../config/aggregation-operators/floor.yaml | 15 + .../aggregation-operators/function.yaml | 28 + .../aggregation-operators/getField.yaml | 27 + .../config/aggregation-operators/gt.yaml | 19 + .../config/aggregation-operators/gte.yaml | 19 + .../config/aggregation-operators/hour.yaml | 26 + .../config/aggregation-operators/ifNull.yaml | 16 + .../config/aggregation-operators/in.yaml | 23 + .../aggregation-operators/indexOfArray.yaml | 39 + .../aggregation-operators/indexOfBytes.yaml | 41 + .../aggregation-operators/indexOfCP.yaml | 41 + .../aggregation-operators/integral.yaml | 26 + .../config/aggregation-operators/isArray.yaml | 16 + .../aggregation-operators/isNumber.yaml | 18 + .../aggregation-operators/isoDayOfWeek.yaml | 26 + .../config/aggregation-operators/isoWeek.yaml | 26 + .../aggregation-operators/isoWeekYear.yaml | 26 + .../config/aggregation-operators/last.yaml | 19 + .../config/aggregation-operators/lastN.yaml | 23 + .../config/aggregation-operators/let.yaml | 25 + .../aggregation-operators/linearFill.yaml | 17 + .../config/aggregation-operators/literal.yaml | 17 + .../config/aggregation-operators/ln.yaml | 18 + .../config/aggregation-operators/locf.yaml | 17 + .../config/aggregation-operators/log.yaml | 23 + .../config/aggregation-operators/log10.yaml | 17 + .../config/aggregation-operators/lt.yaml | 19 + .../config/aggregation-operators/lte.yaml | 19 + .../config/aggregation-operators/ltrim.yaml | 27 + .../config/aggregation-operators/map.yaml | 30 + .../config/aggregation-operators/max.yaml | 20 + .../config/aggregation-operators/maxN.yaml | 23 + .../config/aggregation-operators/median.yaml | 30 + .../aggregation-operators/mergeObjects.yaml | 19 + .../config/aggregation-operators/meta.yaml | 15 + .../aggregation-operators/millisecond.yaml | 26 + .../config/aggregation-operators/min.yaml | 20 + .../config/aggregation-operators/minN.yaml | 23 + .../config/aggregation-operators/minute.yaml | 26 + .../config/aggregation-operators/mod.yaml | 21 + .../config/aggregation-operators/month.yaml | 26 + .../aggregation-operators/multiply.yaml | 19 + .../config/aggregation-operators/ne.yaml | 19 + .../config/aggregation-operators/not.yaml | 16 + .../aggregation-operators/objectToArray.yaml | 18 + .../config/aggregation-operators/or.yaml | 17 + .../aggregation-operators/percentile.yaml | 40 + .../config/aggregation-operators/pow.yaml | 19 + .../config/aggregation-operators/push.yaml | 17 + .../radiansToDegrees.yaml | 16 + .../config/aggregation-operators/rand.yaml | 10 + .../config/aggregation-operators/range.yaml | 30 + .../config/aggregation-operators/rank.yaml | 11 + .../config/aggregation-operators/reduce.yaml | 34 + .../aggregation-operators/regexFind.yaml | 30 + .../aggregation-operators/regexFindAll.yaml | 30 + .../aggregation-operators/regexMatch.yaml | 30 + .../aggregation-operators/replaceAll.yaml | 34 + .../aggregation-operators/replaceOne.yaml | 33 + .../aggregation-operators/reverseArray.yaml | 17 + .../config/aggregation-operators/round.yaml | 31 + .../config/aggregation-operators/rtrim.yaml | 26 + .../aggregation-operators/sampleRate.yaml | 18 + .../config/aggregation-operators/second.yaml | 26 + .../aggregation-operators/setDifference.yaml | 23 + .../aggregation-operators/setEquals.yaml | 16 + .../aggregation-operators/setField.yaml | 31 + .../setIntersection.yaml | 16 + .../aggregation-operators/setIsSubset.yaml | 19 + .../aggregation-operators/setUnion.yaml | 16 + .../config/aggregation-operators/shift.yaml | 36 + .../config/aggregation-operators/sin.yaml | 19 + .../config/aggregation-operators/sinh.yaml | 19 + .../config/aggregation-operators/size.yaml | 17 + .../config/aggregation-operators/slice.yaml | 34 + .../aggregation-operators/sortArray.yaml | 23 + .../config/aggregation-operators/split.yaml | 23 + .../config/aggregation-operators/sqrt.yaml | 17 + .../aggregation-operators/stdDevPop.yaml | 21 + .../aggregation-operators/stdDevSamp.yaml | 21 + .../aggregation-operators/strLenBytes.yaml | 15 + .../aggregation-operators/strLenCP.yaml | 15 + .../aggregation-operators/strcasecmp.yaml | 19 + .../config/aggregation-operators/substr.yaml | 27 + .../aggregation-operators/substrBytes.yaml | 27 + .../aggregation-operators/substrCP.yaml | 27 + .../aggregation-operators/subtract.yaml | 23 + .../config/aggregation-operators/sum.yaml | 20 + .../config/aggregation-operators/switch.yaml | 28 + .../config/aggregation-operators/tan.yaml | 19 + .../config/aggregation-operators/tanh.yaml | 19 + .../config/aggregation-operators/toBool.yaml | 16 + .../config/aggregation-operators/toDate.yaml | 16 + .../aggregation-operators/toDecimal.yaml | 16 + .../aggregation-operators/toDouble.yaml | 16 + .../config/aggregation-operators/toInt.yaml | 16 + .../config/aggregation-operators/toLong.yaml | 16 + .../config/aggregation-operators/toLower.yaml | 15 + .../aggregation-operators/toObjectId.yaml | 16 + .../aggregation-operators/toString.yaml | 17 + .../config/aggregation-operators/toUpper.yaml | 15 + .../config/aggregation-operators/top.yaml | 27 + .../config/aggregation-operators/topN.yaml | 33 + .../config/aggregation-operators/trim.yaml | 27 + .../config/aggregation-operators/trunc.yaml | 25 + .../aggregation-operators/tsIncrement.yaml | 16 + .../aggregation-operators/tsSecond.yaml | 16 + .../config/aggregation-operators/type.yaml | 15 + .../aggregation-operators/unsetField.yaml | 24 + .../config/aggregation-operators/week.yaml | 26 + .../config/aggregation-operators/year.yaml | 26 + .../config/aggregation-operators/zip.yaml | 34 + .../config/aggregation-stages/addFields.yaml | 18 + .../config/aggregation-stages/bucket.yaml | 45 + .../config/aggregation-stages/bucketAuto.yaml | 39 + .../aggregation-stages/changeStream.yaml | 61 + .../changeStreamSplitLargeEvent.yaml | 11 + .../config/aggregation-stages/collStats.yaml | 15 + .../config/aggregation-stages/count.yaml | 16 + .../config/aggregation-stages/currentOp.yaml | 10 + .../config/aggregation-stages/densify.yaml | 32 + .../config/aggregation-stages/documents.yaml | 21 + .../config/aggregation-stages/facet.yaml | 16 + generator/config/aggregation-stages/fill.yaml | 44 + .../config/aggregation-stages/geoNear.yaml | 78 + .../aggregation-stages/graphLookup.yaml | 64 + .../config/aggregation-stages/group.yaml | 24 + .../config/aggregation-stages/indexStats.yaml | 10 + .../config/aggregation-stages/limit.yaml | 15 + .../aggregation-stages/listLocalSessions.yaml | 25 + .../listSampledQueries.yaml | 16 + .../aggregation-stages/listSearchIndexes.yaml | 25 + .../aggregation-stages/listSessions.yaml | 25 + .../config/aggregation-stages/lookup.yaml | 56 + .../config/aggregation-stages/match.yaml | 16 + .../config/aggregation-stages/merge.yaml | 48 + generator/config/aggregation-stages/out.yaml | 29 + .../aggregation-stages/planCacheStats.yaml | 10 + .../config/aggregation-stages/project.yaml | 18 + .../config/aggregation-stages/redact.yaml | 15 + .../aggregation-stages/replaceRoot.yaml | 15 + .../aggregation-stages/replaceWith.yaml | 16 + .../config/aggregation-stages/sample.yaml | 17 + .../config/aggregation-stages/search.yaml | 16 + .../config/aggregation-stages/searchMeta.yaml | 16 + generator/config/aggregation-stages/set.yaml | 17 + .../aggregation-stages/setWindowFields.yaml | 38 + .../shardedDataDistribution.yaml | 11 + generator/config/aggregation-stages/skip.yaml | 15 + generator/config/aggregation-stages/sort.yaml | 15 + .../aggregation-stages/sortByCount.yaml | 15 + .../config/aggregation-stages/unionWith.yaml | 26 + .../config/aggregation-stages/unset.yaml | 17 + .../config/aggregation-stages/unwind.yaml | 15 + generator/config/aggregation.md | 34 + generator/config/expressions.php | 60 +- generator/config/operators.php | 6 +- generator/config/pipeline-operators.yaml | 92 - generator/config/query-operators.yaml | 32 - generator/config/query-operators/all.yaml | 16 + generator/config/query-operators/and.yaml | 16 + .../config/query-operators/bitsAllClear.yaml | 17 + .../config/query-operators/bitsAllSet.yaml | 17 + .../config/query-operators/bitsAnyClear.yaml | 17 + .../config/query-operators/bitsAnySet.yaml | 17 + generator/config/query-operators/box.yaml | 15 + generator/config/query-operators/center.yaml | 15 + .../config/query-operators/centerSphere.yaml | 15 + generator/config/query-operators/comment.yaml | 15 + .../config/query-operators/elemMatch.yaml | 15 + generator/config/query-operators/eq.yaml | 15 + generator/config/query-operators/exists.yaml | 15 + generator/config/query-operators/expr.yaml | 15 + .../config/query-operators/geoIntersects.yaml | 15 + .../config/query-operators/geoWithin.yaml | 15 + .../config/query-operators/geometry.yaml | 23 + generator/config/query-operators/gt.yaml | 15 + generator/config/query-operators/gte.yaml | 15 + generator/config/query-operators/in.yaml | 15 + .../config/query-operators/jsonSchema.yaml | 15 + generator/config/query-operators/lt.yaml | 15 + generator/config/query-operators/lte.yaml | 15 + .../config/query-operators/maxDistance.yaml | 16 + generator/config/query-operators/meta.yaml | 10 + .../config/query-operators/minDistance.yaml | 16 + generator/config/query-operators/mod.yaml | 19 + generator/config/query-operators/natural.yaml | 10 + generator/config/query-operators/ne.yaml | 15 + generator/config/query-operators/near.yaml | 29 + .../config/query-operators/nearSphere.yaml | 29 + generator/config/query-operators/nin.yaml | 15 + generator/config/query-operators/nor.yaml | 16 + generator/config/query-operators/not.yaml | 15 + generator/config/query-operators/or.yaml | 16 + generator/config/query-operators/polygon.yaml | 15 + .../config/query-operators/positional.yaml | 10 + generator/config/query-operators/rand.yaml | 10 + generator/config/query-operators/regex.yaml | 15 + generator/config/query-operators/size.yaml | 15 + generator/config/query-operators/slice.yaml | 19 + generator/config/query-operators/text.yaml | 40 + generator/config/query-operators/type.yaml | 18 + generator/config/query-operators/where.yaml | 15 + generator/config/schema.json | 14 +- generator/config/stages.yaml | 33 - generator/src/AbstractGenerator.php | 2 +- generator/src/Command/GenerateCommand.php | 2 +- generator/src/Command/ScrapeCommand.php | 27 +- .../src/Definition/ArgumentDefinition.php | 25 +- .../src/Definition/GeneratorDefinition.php | 2 +- .../src/Definition/OperatorDefinition.php | 45 +- generator/src/Definition/VariadicType.php | 9 + generator/src/Definition/YamlReader.php | 16 +- generator/src/OperatorClassGenerator.php | 111 +- generator/src/OperatorFactoryGenerator.php | 74 +- generator/src/OperatorGenerator.php | 46 +- src/Builder/Aggregation.php | 2034 ++++++++++++++++- src/Builder/Aggregation/AbsAggregation.php | 29 + .../Aggregation/AccumulatorAggregation.php | 74 + .../Aggregation/AccumulatorInterface.php | 11 + src/Builder/Aggregation/AcosAggregation.php | 37 + src/Builder/Aggregation/AcoshAggregation.php | 37 + src/Builder/Aggregation/AddAggregation.php | 38 + .../Aggregation/AddToSetAggregation.php | 28 + src/Builder/Aggregation/Aggregation.php | 42 + .../AllElementsTrueAggregation.php | 37 + src/Builder/Aggregation/AndAggregation.php | 26 +- .../Aggregation/AnyElementTrueAggregation.php | 34 + .../Aggregation/ArrayElemAtAggregation.php | 40 + .../Aggregation/ArrayToObjectAggregation.php | 34 + src/Builder/Aggregation/AsinAggregation.php | 37 + src/Builder/Aggregation/AsinhAggregation.php | 37 + src/Builder/Aggregation/Atan2Aggregation.php | 44 + src/Builder/Aggregation/AtanAggregation.php | 37 + src/Builder/Aggregation/AtanhAggregation.php | 37 + src/Builder/Aggregation/AvgAggregation.php | 35 + .../Aggregation/BinarySizeAggregation.php | 31 + src/Builder/Aggregation/BitAndAggregation.php | 35 + src/Builder/Aggregation/BitNotAggregation.php | 29 + src/Builder/Aggregation/BitOrAggregation.php | 35 + src/Builder/Aggregation/BitXorAggregation.php | 21 + src/Builder/Aggregation/BottomAggregation.php | 32 + .../Aggregation/BottomNAggregation.php | 39 + .../Aggregation/BsonSizeAggregation.php | 31 + src/Builder/Aggregation/CeilAggregation.php | 30 + src/Builder/Aggregation/CmpAggregation.php | 33 + src/Builder/Aggregation/ConcatAggregation.php | 33 + .../Aggregation/ConcatArraysAggregation.php | 36 + src/Builder/Aggregation/CondAggregation.php | 38 + .../Aggregation/ConvertAggregation.php | 58 + src/Builder/Aggregation/CosAggregation.php | 35 + src/Builder/Aggregation/CoshAggregation.php | 35 + src/Builder/Aggregation/CountAggregation.php | 26 + .../Aggregation/CovariancePopAggregation.php | 38 + .../Aggregation/CovarianceSampAggregation.php | 38 + .../Aggregation/DateAddAggregation.php | 55 + .../Aggregation/DateDiffAggregation.php | 60 + .../Aggregation/DateFromPartsAggregation.php | 93 + .../Aggregation/DateFromStringAggregation.php | 67 + .../Aggregation/DateSubtractAggregation.php | 55 + .../Aggregation/DateToPartsAggregation.php | 48 + .../Aggregation/DateToStringAggregation.php | 62 + .../Aggregation/DateTruncAggregation.php | 73 + .../Aggregation/DayOfMonthAggregation.php | 42 + .../Aggregation/DayOfWeekAggregation.php | 42 + .../Aggregation/DayOfYearAggregation.php | 42 + .../DegreesToRadiansAggregation.php | 35 + .../Aggregation/DenseRankAggregation.php | 20 + .../Aggregation/DerivativeAggregation.php | 44 + src/Builder/Aggregation/DivideAggregation.php | 37 + .../Aggregation/DocumentNumberAggregation.php | 20 + src/Builder/Aggregation/EqAggregation.php | 6 +- src/Builder/Aggregation/ExpAggregation.php | 30 + .../Aggregation/ExpMovingAvgAggregation.php | 54 + src/Builder/Aggregation/FilterAggregation.php | 29 +- src/Builder/Aggregation/FirstAggregation.php | 27 + src/Builder/Aggregation/FirstNAggregation.php | 40 + src/Builder/Aggregation/FloorAggregation.php | 30 + .../Aggregation/FunctionAggregation.php | 42 + .../Aggregation/GetFieldAggregation.php | 41 + src/Builder/Aggregation/GtAggregation.php | 6 +- src/Builder/Aggregation/GteAggregation.php | 6 +- src/Builder/Aggregation/HourAggregation.php | 42 + src/Builder/Aggregation/IfNullAggregation.php | 33 + src/Builder/Aggregation/InAggregation.php | 39 + .../Aggregation/IndexOfArrayAggregation.php | 64 + .../Aggregation/IndexOfBytesAggregation.php | 63 + .../Aggregation/IndexOfCPAggregation.php | 63 + .../Aggregation/IntegralAggregation.php | 46 + .../Aggregation/IsArrayAggregation.php | 34 + .../Aggregation/IsNumberAggregation.php | 34 + .../Aggregation/IsoDayOfWeekAggregation.php | 42 + .../Aggregation/IsoWeekAggregation.php | 42 + .../Aggregation/IsoWeekYearAggregation.php | 42 + src/Builder/Aggregation/LastAggregation.php | 27 + src/Builder/Aggregation/LastNAggregation.php | 40 + src/Builder/Aggregation/LetAggregation.php | 38 + .../Aggregation/LinearFillAggregation.php | 29 + .../Aggregation/LiteralAggregation.php | 27 + src/Builder/Aggregation/LnAggregation.php | 30 + src/Builder/Aggregation/LocfAggregation.php | 27 + src/Builder/Aggregation/Log10Aggregation.php | 30 + src/Builder/Aggregation/LogAggregation.php | 37 + src/Builder/Aggregation/LtAggregation.php | 6 +- src/Builder/Aggregation/LteAggregation.php | 33 + src/Builder/Aggregation/LtrimAggregation.php | 41 + src/Builder/Aggregation/MapAggregation.php | 48 + src/Builder/Aggregation/MaxAggregation.php | 16 +- src/Builder/Aggregation/MaxNAggregation.php | 40 + src/Builder/Aggregation/MedianAggregation.php | 35 + .../Aggregation/MergeObjectsAggregation.php | 35 + src/Builder/Aggregation/MetaAggregation.php | 27 + .../Aggregation/MillisecondAggregation.php | 42 + src/Builder/Aggregation/MinAggregation.php | 16 +- src/Builder/Aggregation/MinNAggregation.php | 40 + src/Builder/Aggregation/MinuteAggregation.php | 42 + src/Builder/Aggregation/ModAggregation.php | 31 +- src/Builder/Aggregation/MonthAggregation.php | 42 + .../Aggregation/MultiplyAggregation.php | 40 + src/Builder/Aggregation/NeAggregation.php | 6 +- src/Builder/Aggregation/NotAggregation.php | 28 + .../Aggregation/ObjectToArrayAggregation.php | 30 + src/Builder/Aggregation/OrAggregation.php | 34 + .../Aggregation/PercentileAggregation.php | 53 + src/Builder/Aggregation/PowAggregation.php | 36 + src/Builder/Aggregation/PushAggregation.php | 27 + .../RadiansToDegreesAggregation.php | 31 + src/Builder/Aggregation/RandAggregation.php | 20 + src/Builder/Aggregation/RangeAggregation.php | 43 + src/Builder/Aggregation/RankAggregation.php | 20 + src/Builder/Aggregation/ReduceAggregation.php | 57 + .../Aggregation/RegexFindAggregation.php | 43 + .../Aggregation/RegexFindAllAggregation.php | 43 + .../Aggregation/RegexMatchAggregation.php | 43 + .../Aggregation/ReplaceAllAggregation.php | 41 + .../Aggregation/ReplaceOneAggregation.php | 41 + .../Aggregation/ReverseArrayAggregation.php | 33 + src/Builder/Aggregation/RoundAggregation.php | 44 + src/Builder/Aggregation/RtrimAggregation.php | 41 + .../Aggregation/SampleRateAggregation.php | 33 + src/Builder/Aggregation/SecondAggregation.php | 42 + .../Aggregation/SetDifferenceAggregation.php | 43 + .../Aggregation/SetEqualsAggregation.php | 37 + .../Aggregation/SetFieldAggregation.php | 45 + .../SetIntersectionAggregation.php | 36 + .../Aggregation/SetIsSubsetAggregation.php | 44 + .../Aggregation/SetUnionAggregation.php | 36 + src/Builder/Aggregation/ShiftAggregation.php | 54 + src/Builder/Aggregation/SinAggregation.php | 35 + src/Builder/Aggregation/SinhAggregation.php | 35 + src/Builder/Aggregation/SizeAggregation.php | 34 + src/Builder/Aggregation/SliceAggregation.php | 61 + .../Aggregation/SortArrayAggregation.php | 38 + src/Builder/Aggregation/SplitAggregation.php | 33 + src/Builder/Aggregation/SqrtAggregation.php | 30 + .../Aggregation/StdDevPopAggregation.php | 36 + .../Aggregation/StdDevSampAggregation.php | 36 + .../Aggregation/StrLenBytesAggregation.php | 28 + .../Aggregation/StrLenCPAggregation.php | 28 + .../Aggregation/StrcasecmpAggregation.php | 33 + src/Builder/Aggregation/SubstrAggregation.php | 42 + .../Aggregation/SubstrBytesAggregation.php | 42 + .../Aggregation/SubstrCPAggregation.php | 42 + .../Aggregation/SubtractAggregation.php | 28 +- src/Builder/Aggregation/SumAggregation.php | 23 +- src/Builder/Aggregation/SwitchAggregation.php | 50 + src/Builder/Aggregation/TanAggregation.php | 35 + src/Builder/Aggregation/TanhAggregation.php | 35 + src/Builder/Aggregation/ToBoolAggregation.php | 28 + src/Builder/Aggregation/ToDateAggregation.php | 28 + .../Aggregation/ToDecimalAggregation.php | 28 + .../Aggregation/ToDoubleAggregation.php | 28 + src/Builder/Aggregation/ToIntAggregation.php | 28 + src/Builder/Aggregation/ToLongAggregation.php | 28 + .../Aggregation/ToLowerAggregation.php | 27 + .../Aggregation/ToObjectIdAggregation.php | 28 + .../Aggregation/ToStringAggregation.php | 28 + .../Aggregation/ToUpperAggregation.php | 27 + src/Builder/Aggregation/TopAggregation.php | 32 + src/Builder/Aggregation/TopNAggregation.php | 39 + src/Builder/Aggregation/TrimAggregation.php | 41 + src/Builder/Aggregation/TruncAggregation.php | 43 + .../Aggregation/TsIncrementAggregation.php | 29 + .../Aggregation/TsSecondAggregation.php | 29 + src/Builder/Aggregation/TypeAggregation.php | 28 + .../Aggregation/UnsetFieldAggregation.php | 35 + src/Builder/Aggregation/WeekAggregation.php | 42 + src/Builder/Aggregation/YearAggregation.php | 42 + src/Builder/Aggregation/ZipAggregation.php | 65 + src/Builder/BuilderEncoder.php | 36 +- src/Builder/Encode.php | 12 + src/Builder/Expression.php | 30 + src/Builder/Expression/BinaryFieldPath.php | 17 + src/Builder/Expression/DoubleFieldPath.php | 17 + src/Builder/Expression/LongFieldPath.php | 17 + src/Builder/Expression/ObjectIdFieldPath.php | 17 + src/Builder/Expression/ResolvesToBinary.php | 11 + src/Builder/Expression/ResolvesToDouble.php | 11 + src/Builder/Expression/ResolvesToLong.php | 11 + src/Builder/Expression/ResolvesToObjectId.php | 11 + .../Expression/ResolvesToTimestamp.php | 11 + src/Builder/Expression/TimestampFieldPath.php | 17 + src/Builder/Query.php | 385 +++- src/Builder/Query/AllQuery.php | 32 + src/Builder/Query/AndQuery.php | 24 +- src/Builder/Query/BitsAllClearQuery.php | 34 + src/Builder/Query/BitsAllSetQuery.php | 34 + src/Builder/Query/BitsAnyClearQuery.php | 34 + src/Builder/Query/BitsAnySetQuery.php | 34 + src/Builder/Query/BoxQuery.php | 32 + src/Builder/Query/CenterQuery.php | 32 + src/Builder/Query/CenterSphereQuery.php | 32 + src/Builder/Query/CommentQuery.php | 27 + src/Builder/Query/ElemMatchQuery.php | 28 + src/Builder/Query/EqQuery.php | 26 + src/Builder/Query/ExistsQuery.php | 26 + src/Builder/Query/ExprQuery.php | 6 +- src/Builder/Query/GeoIntersectsQuery.php | 26 + src/Builder/Query/GeoWithinQuery.php | 26 + src/Builder/Query/GeometryQuery.php | 44 + src/Builder/Query/GtQuery.php | 10 +- src/Builder/Query/GteQuery.php | 10 +- src/Builder/Query/InQuery.php | 26 + src/Builder/Query/JsonSchemaQuery.php | 28 + src/Builder/Query/LtQuery.php | 10 +- src/Builder/Query/LteQuery.php | 26 + src/Builder/Query/MaxDistanceQuery.php | 27 + src/Builder/Query/MetaQuery.php | 20 + src/Builder/Query/MinDistanceQuery.php | 27 + src/Builder/Query/ModQuery.php | 32 + src/Builder/Query/NaturalQuery.php | 20 + src/Builder/Query/NeQuery.php | 26 + src/Builder/Query/NearQuery.php | 41 + src/Builder/Query/NearSphereQuery.php | 41 + src/Builder/Query/NinQuery.php | 26 + src/Builder/Query/NorQuery.php | 32 + src/Builder/Query/NotQuery.php | 26 + src/Builder/Query/OrQuery.php | 25 +- src/Builder/Query/PolygonQuery.php | 32 + src/Builder/Query/Query.php | 26 + src/Builder/Query/QueryInterface.php | 11 + src/Builder/Query/RandQuery.php | 20 + src/Builder/Query/RegexQuery.php | 27 + src/Builder/Query/SizeQuery.php | 27 + src/Builder/Query/SliceQuery.php | 32 + src/Builder/Query/TextQuery.php | 54 + src/Builder/Query/TypeQuery.php | 33 + src/Builder/Query/WhereQuery.php | 26 + src/Builder/Stage.php | 515 ++++- src/Builder/Stage/AddFieldsStage.php | 35 + src/Builder/Stage/BucketAutoStage.php | 58 + src/Builder/Stage/BucketStage.php | 77 + .../ChangeStreamSplitLargeEventStage.php | 19 + src/Builder/Stage/ChangeStreamStage.php | 71 + src/Builder/Stage/CollStatsStage.php | 28 + src/Builder/Stage/CountStage.php | 26 + src/Builder/Stage/CurrentOpStage.php | 19 + src/Builder/Stage/DensifyStage.php | 53 + src/Builder/Stage/DocumentsStage.php | 43 + src/Builder/Stage/FacetStage.php | 35 + src/Builder/Stage/FillStage.php | 70 + src/Builder/Stage/GeoNearStage.php | 99 + src/Builder/Stage/GraphLookupStage.php | 82 + src/Builder/Stage/GroupStage.php | 25 +- src/Builder/Stage/IndexStatsStage.php | 19 + src/Builder/Stage/LimitStage.php | 4 +- src/Builder/Stage/ListLocalSessionsStage.php | 40 + src/Builder/Stage/ListSampledQueriesStage.php | 27 + src/Builder/Stage/ListSearchIndexesStage.php | 34 + src/Builder/Stage/ListSessionsStage.php | 40 + src/Builder/Stage/LookupStage.php | 73 + src/Builder/Stage/MatchStage.php | 20 +- src/Builder/Stage/MergeStage.php | 60 + src/Builder/Stage/OutStage.php | 38 + src/Builder/Stage/PlanCacheStatsStage.php | 19 + src/Builder/Stage/ProjectStage.php | 24 +- src/Builder/Stage/RedactStage.php | 27 + src/Builder/Stage/ReplaceRootStage.php | 29 + src/Builder/Stage/ReplaceWithStage.php | 29 + src/Builder/Stage/SampleStage.php | 27 + src/Builder/Stage/SearchMetaStage.php | 28 + src/Builder/Stage/SearchStage.php | 28 + src/Builder/Stage/SetStage.php | 35 + src/Builder/Stage/SetWindowFieldsStage.php | 53 + .../Stage/ShardedDataDistributionStage.php | 19 + src/Builder/Stage/SkipStage.php | 27 + src/Builder/Stage/SortByCountStage.php | 27 + src/Builder/Stage/SortStage.php | 20 +- src/Builder/Stage/Stage.php | 30 + src/Builder/Stage/UnionWithStage.php | 37 + src/Builder/Stage/UnsetStage.php | 33 + src/Builder/Stage/UnwindStage.php | 27 + tests/Builder/BuilderEncoderTest.php | 2 +- 552 files changed, 18181 insertions(+), 508 deletions(-) create mode 100644 generator/config/aggregation-operators/abs.yaml create mode 100644 generator/config/aggregation-operators/accumulator.yaml create mode 100644 generator/config/aggregation-operators/acos.yaml create mode 100644 generator/config/aggregation-operators/acosh.yaml create mode 100644 generator/config/aggregation-operators/add.yaml create mode 100644 generator/config/aggregation-operators/addToSet.yaml create mode 100644 generator/config/aggregation-operators/allElementsTrue.yaml create mode 100644 generator/config/aggregation-operators/and.yaml create mode 100644 generator/config/aggregation-operators/anyElementTrue.yaml create mode 100644 generator/config/aggregation-operators/arrayElemAt.yaml create mode 100644 generator/config/aggregation-operators/arrayToObject.yaml create mode 100644 generator/config/aggregation-operators/asin.yaml create mode 100644 generator/config/aggregation-operators/asinh.yaml create mode 100644 generator/config/aggregation-operators/atan.yaml create mode 100644 generator/config/aggregation-operators/atan2.yaml create mode 100644 generator/config/aggregation-operators/atanh.yaml create mode 100644 generator/config/aggregation-operators/avg.yaml create mode 100644 generator/config/aggregation-operators/binarySize.yaml create mode 100644 generator/config/aggregation-operators/bitAnd.yaml create mode 100644 generator/config/aggregation-operators/bitNot.yaml create mode 100644 generator/config/aggregation-operators/bitOr.yaml create mode 100644 generator/config/aggregation-operators/bitXor.yaml create mode 100644 generator/config/aggregation-operators/bottom.yaml create mode 100644 generator/config/aggregation-operators/bottomN.yaml create mode 100644 generator/config/aggregation-operators/bsonSize.yaml create mode 100644 generator/config/aggregation-operators/ceil.yaml create mode 100644 generator/config/aggregation-operators/cmp.yaml create mode 100644 generator/config/aggregation-operators/concat.yaml create mode 100644 generator/config/aggregation-operators/concatArrays.yaml create mode 100644 generator/config/aggregation-operators/cond.yaml create mode 100644 generator/config/aggregation-operators/convert.yaml create mode 100644 generator/config/aggregation-operators/cos.yaml create mode 100644 generator/config/aggregation-operators/cosh.yaml create mode 100644 generator/config/aggregation-operators/count.yaml create mode 100644 generator/config/aggregation-operators/covariancePop.yaml create mode 100644 generator/config/aggregation-operators/covarianceSamp.yaml create mode 100644 generator/config/aggregation-operators/dateAdd.yaml create mode 100644 generator/config/aggregation-operators/dateDiff.yaml create mode 100644 generator/config/aggregation-operators/dateFromParts.yaml create mode 100644 generator/config/aggregation-operators/dateFromString.yaml create mode 100644 generator/config/aggregation-operators/dateSubtract.yaml create mode 100644 generator/config/aggregation-operators/dateToParts.yaml create mode 100644 generator/config/aggregation-operators/dateToString.yaml create mode 100644 generator/config/aggregation-operators/dateTrunc.yaml create mode 100644 generator/config/aggregation-operators/dayOfMonth.yaml create mode 100644 generator/config/aggregation-operators/dayOfWeek.yaml create mode 100644 generator/config/aggregation-operators/dayOfYear.yaml create mode 100644 generator/config/aggregation-operators/degreesToRadians.yaml create mode 100644 generator/config/aggregation-operators/denseRank.yaml create mode 100644 generator/config/aggregation-operators/derivative.yaml create mode 100644 generator/config/aggregation-operators/divide.yaml create mode 100644 generator/config/aggregation-operators/documentNumber.yaml create mode 100644 generator/config/aggregation-operators/eq.yaml create mode 100644 generator/config/aggregation-operators/exp.yaml create mode 100644 generator/config/aggregation-operators/expMovingAvg.yaml create mode 100644 generator/config/aggregation-operators/filter.yaml create mode 100644 generator/config/aggregation-operators/first.yaml create mode 100644 generator/config/aggregation-operators/firstN.yaml create mode 100644 generator/config/aggregation-operators/floor.yaml create mode 100644 generator/config/aggregation-operators/function.yaml create mode 100644 generator/config/aggregation-operators/getField.yaml create mode 100644 generator/config/aggregation-operators/gt.yaml create mode 100644 generator/config/aggregation-operators/gte.yaml create mode 100644 generator/config/aggregation-operators/hour.yaml create mode 100644 generator/config/aggregation-operators/ifNull.yaml create mode 100644 generator/config/aggregation-operators/in.yaml create mode 100644 generator/config/aggregation-operators/indexOfArray.yaml create mode 100644 generator/config/aggregation-operators/indexOfBytes.yaml create mode 100644 generator/config/aggregation-operators/indexOfCP.yaml create mode 100644 generator/config/aggregation-operators/integral.yaml create mode 100644 generator/config/aggregation-operators/isArray.yaml create mode 100644 generator/config/aggregation-operators/isNumber.yaml create mode 100644 generator/config/aggregation-operators/isoDayOfWeek.yaml create mode 100644 generator/config/aggregation-operators/isoWeek.yaml create mode 100644 generator/config/aggregation-operators/isoWeekYear.yaml create mode 100644 generator/config/aggregation-operators/last.yaml create mode 100644 generator/config/aggregation-operators/lastN.yaml create mode 100644 generator/config/aggregation-operators/let.yaml create mode 100644 generator/config/aggregation-operators/linearFill.yaml create mode 100644 generator/config/aggregation-operators/literal.yaml create mode 100644 generator/config/aggregation-operators/ln.yaml create mode 100644 generator/config/aggregation-operators/locf.yaml create mode 100644 generator/config/aggregation-operators/log.yaml create mode 100644 generator/config/aggregation-operators/log10.yaml create mode 100644 generator/config/aggregation-operators/lt.yaml create mode 100644 generator/config/aggregation-operators/lte.yaml create mode 100644 generator/config/aggregation-operators/ltrim.yaml create mode 100644 generator/config/aggregation-operators/map.yaml create mode 100644 generator/config/aggregation-operators/max.yaml create mode 100644 generator/config/aggregation-operators/maxN.yaml create mode 100644 generator/config/aggregation-operators/median.yaml create mode 100644 generator/config/aggregation-operators/mergeObjects.yaml create mode 100644 generator/config/aggregation-operators/meta.yaml create mode 100644 generator/config/aggregation-operators/millisecond.yaml create mode 100644 generator/config/aggregation-operators/min.yaml create mode 100644 generator/config/aggregation-operators/minN.yaml create mode 100644 generator/config/aggregation-operators/minute.yaml create mode 100644 generator/config/aggregation-operators/mod.yaml create mode 100644 generator/config/aggregation-operators/month.yaml create mode 100644 generator/config/aggregation-operators/multiply.yaml create mode 100644 generator/config/aggregation-operators/ne.yaml create mode 100644 generator/config/aggregation-operators/not.yaml create mode 100644 generator/config/aggregation-operators/objectToArray.yaml create mode 100644 generator/config/aggregation-operators/or.yaml create mode 100644 generator/config/aggregation-operators/percentile.yaml create mode 100644 generator/config/aggregation-operators/pow.yaml create mode 100644 generator/config/aggregation-operators/push.yaml create mode 100644 generator/config/aggregation-operators/radiansToDegrees.yaml create mode 100644 generator/config/aggregation-operators/rand.yaml create mode 100644 generator/config/aggregation-operators/range.yaml create mode 100644 generator/config/aggregation-operators/rank.yaml create mode 100644 generator/config/aggregation-operators/reduce.yaml create mode 100644 generator/config/aggregation-operators/regexFind.yaml create mode 100644 generator/config/aggregation-operators/regexFindAll.yaml create mode 100644 generator/config/aggregation-operators/regexMatch.yaml create mode 100644 generator/config/aggregation-operators/replaceAll.yaml create mode 100644 generator/config/aggregation-operators/replaceOne.yaml create mode 100644 generator/config/aggregation-operators/reverseArray.yaml create mode 100644 generator/config/aggregation-operators/round.yaml create mode 100644 generator/config/aggregation-operators/rtrim.yaml create mode 100644 generator/config/aggregation-operators/sampleRate.yaml create mode 100644 generator/config/aggregation-operators/second.yaml create mode 100644 generator/config/aggregation-operators/setDifference.yaml create mode 100644 generator/config/aggregation-operators/setEquals.yaml create mode 100644 generator/config/aggregation-operators/setField.yaml create mode 100644 generator/config/aggregation-operators/setIntersection.yaml create mode 100644 generator/config/aggregation-operators/setIsSubset.yaml create mode 100644 generator/config/aggregation-operators/setUnion.yaml create mode 100644 generator/config/aggregation-operators/shift.yaml create mode 100644 generator/config/aggregation-operators/sin.yaml create mode 100644 generator/config/aggregation-operators/sinh.yaml create mode 100644 generator/config/aggregation-operators/size.yaml create mode 100644 generator/config/aggregation-operators/slice.yaml create mode 100644 generator/config/aggregation-operators/sortArray.yaml create mode 100644 generator/config/aggregation-operators/split.yaml create mode 100644 generator/config/aggregation-operators/sqrt.yaml create mode 100644 generator/config/aggregation-operators/stdDevPop.yaml create mode 100644 generator/config/aggregation-operators/stdDevSamp.yaml create mode 100644 generator/config/aggregation-operators/strLenBytes.yaml create mode 100644 generator/config/aggregation-operators/strLenCP.yaml create mode 100644 generator/config/aggregation-operators/strcasecmp.yaml create mode 100644 generator/config/aggregation-operators/substr.yaml create mode 100644 generator/config/aggregation-operators/substrBytes.yaml create mode 100644 generator/config/aggregation-operators/substrCP.yaml create mode 100644 generator/config/aggregation-operators/subtract.yaml create mode 100644 generator/config/aggregation-operators/sum.yaml create mode 100644 generator/config/aggregation-operators/switch.yaml create mode 100644 generator/config/aggregation-operators/tan.yaml create mode 100644 generator/config/aggregation-operators/tanh.yaml create mode 100644 generator/config/aggregation-operators/toBool.yaml create mode 100644 generator/config/aggregation-operators/toDate.yaml create mode 100644 generator/config/aggregation-operators/toDecimal.yaml create mode 100644 generator/config/aggregation-operators/toDouble.yaml create mode 100644 generator/config/aggregation-operators/toInt.yaml create mode 100644 generator/config/aggregation-operators/toLong.yaml create mode 100644 generator/config/aggregation-operators/toLower.yaml create mode 100644 generator/config/aggregation-operators/toObjectId.yaml create mode 100644 generator/config/aggregation-operators/toString.yaml create mode 100644 generator/config/aggregation-operators/toUpper.yaml create mode 100644 generator/config/aggregation-operators/top.yaml create mode 100644 generator/config/aggregation-operators/topN.yaml create mode 100644 generator/config/aggregation-operators/trim.yaml create mode 100644 generator/config/aggregation-operators/trunc.yaml create mode 100644 generator/config/aggregation-operators/tsIncrement.yaml create mode 100644 generator/config/aggregation-operators/tsSecond.yaml create mode 100644 generator/config/aggregation-operators/type.yaml create mode 100644 generator/config/aggregation-operators/unsetField.yaml create mode 100644 generator/config/aggregation-operators/week.yaml create mode 100644 generator/config/aggregation-operators/year.yaml create mode 100644 generator/config/aggregation-operators/zip.yaml create mode 100644 generator/config/aggregation-stages/addFields.yaml create mode 100644 generator/config/aggregation-stages/bucket.yaml create mode 100644 generator/config/aggregation-stages/bucketAuto.yaml create mode 100644 generator/config/aggregation-stages/changeStream.yaml create mode 100644 generator/config/aggregation-stages/changeStreamSplitLargeEvent.yaml create mode 100644 generator/config/aggregation-stages/collStats.yaml create mode 100644 generator/config/aggregation-stages/count.yaml create mode 100644 generator/config/aggregation-stages/currentOp.yaml create mode 100644 generator/config/aggregation-stages/densify.yaml create mode 100644 generator/config/aggregation-stages/documents.yaml create mode 100644 generator/config/aggregation-stages/facet.yaml create mode 100644 generator/config/aggregation-stages/fill.yaml create mode 100644 generator/config/aggregation-stages/geoNear.yaml create mode 100644 generator/config/aggregation-stages/graphLookup.yaml create mode 100644 generator/config/aggregation-stages/group.yaml create mode 100644 generator/config/aggregation-stages/indexStats.yaml create mode 100644 generator/config/aggregation-stages/limit.yaml create mode 100644 generator/config/aggregation-stages/listLocalSessions.yaml create mode 100644 generator/config/aggregation-stages/listSampledQueries.yaml create mode 100644 generator/config/aggregation-stages/listSearchIndexes.yaml create mode 100644 generator/config/aggregation-stages/listSessions.yaml create mode 100644 generator/config/aggregation-stages/lookup.yaml create mode 100644 generator/config/aggregation-stages/match.yaml create mode 100644 generator/config/aggregation-stages/merge.yaml create mode 100644 generator/config/aggregation-stages/out.yaml create mode 100644 generator/config/aggregation-stages/planCacheStats.yaml create mode 100644 generator/config/aggregation-stages/project.yaml create mode 100644 generator/config/aggregation-stages/redact.yaml create mode 100644 generator/config/aggregation-stages/replaceRoot.yaml create mode 100644 generator/config/aggregation-stages/replaceWith.yaml create mode 100644 generator/config/aggregation-stages/sample.yaml create mode 100644 generator/config/aggregation-stages/search.yaml create mode 100644 generator/config/aggregation-stages/searchMeta.yaml create mode 100644 generator/config/aggregation-stages/set.yaml create mode 100644 generator/config/aggregation-stages/setWindowFields.yaml create mode 100644 generator/config/aggregation-stages/shardedDataDistribution.yaml create mode 100644 generator/config/aggregation-stages/skip.yaml create mode 100644 generator/config/aggregation-stages/sort.yaml create mode 100644 generator/config/aggregation-stages/sortByCount.yaml create mode 100644 generator/config/aggregation-stages/unionWith.yaml create mode 100644 generator/config/aggregation-stages/unset.yaml create mode 100644 generator/config/aggregation-stages/unwind.yaml create mode 100644 generator/config/aggregation.md delete mode 100644 generator/config/pipeline-operators.yaml delete mode 100644 generator/config/query-operators.yaml create mode 100644 generator/config/query-operators/all.yaml create mode 100644 generator/config/query-operators/and.yaml create mode 100644 generator/config/query-operators/bitsAllClear.yaml create mode 100644 generator/config/query-operators/bitsAllSet.yaml create mode 100644 generator/config/query-operators/bitsAnyClear.yaml create mode 100644 generator/config/query-operators/bitsAnySet.yaml create mode 100644 generator/config/query-operators/box.yaml create mode 100644 generator/config/query-operators/center.yaml create mode 100644 generator/config/query-operators/centerSphere.yaml create mode 100644 generator/config/query-operators/comment.yaml create mode 100644 generator/config/query-operators/elemMatch.yaml create mode 100644 generator/config/query-operators/eq.yaml create mode 100644 generator/config/query-operators/exists.yaml create mode 100644 generator/config/query-operators/expr.yaml create mode 100644 generator/config/query-operators/geoIntersects.yaml create mode 100644 generator/config/query-operators/geoWithin.yaml create mode 100644 generator/config/query-operators/geometry.yaml create mode 100644 generator/config/query-operators/gt.yaml create mode 100644 generator/config/query-operators/gte.yaml create mode 100644 generator/config/query-operators/in.yaml create mode 100644 generator/config/query-operators/jsonSchema.yaml create mode 100644 generator/config/query-operators/lt.yaml create mode 100644 generator/config/query-operators/lte.yaml create mode 100644 generator/config/query-operators/maxDistance.yaml create mode 100644 generator/config/query-operators/meta.yaml create mode 100644 generator/config/query-operators/minDistance.yaml create mode 100644 generator/config/query-operators/mod.yaml create mode 100644 generator/config/query-operators/natural.yaml create mode 100644 generator/config/query-operators/ne.yaml create mode 100644 generator/config/query-operators/near.yaml create mode 100644 generator/config/query-operators/nearSphere.yaml create mode 100644 generator/config/query-operators/nin.yaml create mode 100644 generator/config/query-operators/nor.yaml create mode 100644 generator/config/query-operators/not.yaml create mode 100644 generator/config/query-operators/or.yaml create mode 100644 generator/config/query-operators/polygon.yaml create mode 100644 generator/config/query-operators/positional.yaml create mode 100644 generator/config/query-operators/rand.yaml create mode 100644 generator/config/query-operators/regex.yaml create mode 100644 generator/config/query-operators/size.yaml create mode 100644 generator/config/query-operators/slice.yaml create mode 100644 generator/config/query-operators/text.yaml create mode 100644 generator/config/query-operators/type.yaml create mode 100644 generator/config/query-operators/where.yaml delete mode 100644 generator/config/stages.yaml create mode 100644 generator/src/Definition/VariadicType.php create mode 100644 src/Builder/Aggregation/AbsAggregation.php create mode 100644 src/Builder/Aggregation/AccumulatorAggregation.php create mode 100644 src/Builder/Aggregation/AccumulatorInterface.php create mode 100644 src/Builder/Aggregation/AcosAggregation.php create mode 100644 src/Builder/Aggregation/AcoshAggregation.php create mode 100644 src/Builder/Aggregation/AddAggregation.php create mode 100644 src/Builder/Aggregation/AddToSetAggregation.php create mode 100644 src/Builder/Aggregation/Aggregation.php create mode 100644 src/Builder/Aggregation/AllElementsTrueAggregation.php create mode 100644 src/Builder/Aggregation/AnyElementTrueAggregation.php create mode 100644 src/Builder/Aggregation/ArrayElemAtAggregation.php create mode 100644 src/Builder/Aggregation/ArrayToObjectAggregation.php create mode 100644 src/Builder/Aggregation/AsinAggregation.php create mode 100644 src/Builder/Aggregation/AsinhAggregation.php create mode 100644 src/Builder/Aggregation/Atan2Aggregation.php create mode 100644 src/Builder/Aggregation/AtanAggregation.php create mode 100644 src/Builder/Aggregation/AtanhAggregation.php create mode 100644 src/Builder/Aggregation/AvgAggregation.php create mode 100644 src/Builder/Aggregation/BinarySizeAggregation.php create mode 100644 src/Builder/Aggregation/BitAndAggregation.php create mode 100644 src/Builder/Aggregation/BitNotAggregation.php create mode 100644 src/Builder/Aggregation/BitOrAggregation.php create mode 100644 src/Builder/Aggregation/BitXorAggregation.php create mode 100644 src/Builder/Aggregation/BottomAggregation.php create mode 100644 src/Builder/Aggregation/BottomNAggregation.php create mode 100644 src/Builder/Aggregation/BsonSizeAggregation.php create mode 100644 src/Builder/Aggregation/CeilAggregation.php create mode 100644 src/Builder/Aggregation/CmpAggregation.php create mode 100644 src/Builder/Aggregation/ConcatAggregation.php create mode 100644 src/Builder/Aggregation/ConcatArraysAggregation.php create mode 100644 src/Builder/Aggregation/CondAggregation.php create mode 100644 src/Builder/Aggregation/ConvertAggregation.php create mode 100644 src/Builder/Aggregation/CosAggregation.php create mode 100644 src/Builder/Aggregation/CoshAggregation.php create mode 100644 src/Builder/Aggregation/CountAggregation.php create mode 100644 src/Builder/Aggregation/CovariancePopAggregation.php create mode 100644 src/Builder/Aggregation/CovarianceSampAggregation.php create mode 100644 src/Builder/Aggregation/DateAddAggregation.php create mode 100644 src/Builder/Aggregation/DateDiffAggregation.php create mode 100644 src/Builder/Aggregation/DateFromPartsAggregation.php create mode 100644 src/Builder/Aggregation/DateFromStringAggregation.php create mode 100644 src/Builder/Aggregation/DateSubtractAggregation.php create mode 100644 src/Builder/Aggregation/DateToPartsAggregation.php create mode 100644 src/Builder/Aggregation/DateToStringAggregation.php create mode 100644 src/Builder/Aggregation/DateTruncAggregation.php create mode 100644 src/Builder/Aggregation/DayOfMonthAggregation.php create mode 100644 src/Builder/Aggregation/DayOfWeekAggregation.php create mode 100644 src/Builder/Aggregation/DayOfYearAggregation.php create mode 100644 src/Builder/Aggregation/DegreesToRadiansAggregation.php create mode 100644 src/Builder/Aggregation/DenseRankAggregation.php create mode 100644 src/Builder/Aggregation/DerivativeAggregation.php create mode 100644 src/Builder/Aggregation/DivideAggregation.php create mode 100644 src/Builder/Aggregation/DocumentNumberAggregation.php create mode 100644 src/Builder/Aggregation/ExpAggregation.php create mode 100644 src/Builder/Aggregation/ExpMovingAvgAggregation.php create mode 100644 src/Builder/Aggregation/FirstAggregation.php create mode 100644 src/Builder/Aggregation/FirstNAggregation.php create mode 100644 src/Builder/Aggregation/FloorAggregation.php create mode 100644 src/Builder/Aggregation/FunctionAggregation.php create mode 100644 src/Builder/Aggregation/GetFieldAggregation.php create mode 100644 src/Builder/Aggregation/HourAggregation.php create mode 100644 src/Builder/Aggregation/IfNullAggregation.php create mode 100644 src/Builder/Aggregation/InAggregation.php create mode 100644 src/Builder/Aggregation/IndexOfArrayAggregation.php create mode 100644 src/Builder/Aggregation/IndexOfBytesAggregation.php create mode 100644 src/Builder/Aggregation/IndexOfCPAggregation.php create mode 100644 src/Builder/Aggregation/IntegralAggregation.php create mode 100644 src/Builder/Aggregation/IsArrayAggregation.php create mode 100644 src/Builder/Aggregation/IsNumberAggregation.php create mode 100644 src/Builder/Aggregation/IsoDayOfWeekAggregation.php create mode 100644 src/Builder/Aggregation/IsoWeekAggregation.php create mode 100644 src/Builder/Aggregation/IsoWeekYearAggregation.php create mode 100644 src/Builder/Aggregation/LastAggregation.php create mode 100644 src/Builder/Aggregation/LastNAggregation.php create mode 100644 src/Builder/Aggregation/LetAggregation.php create mode 100644 src/Builder/Aggregation/LinearFillAggregation.php create mode 100644 src/Builder/Aggregation/LiteralAggregation.php create mode 100644 src/Builder/Aggregation/LnAggregation.php create mode 100644 src/Builder/Aggregation/LocfAggregation.php create mode 100644 src/Builder/Aggregation/Log10Aggregation.php create mode 100644 src/Builder/Aggregation/LogAggregation.php create mode 100644 src/Builder/Aggregation/LteAggregation.php create mode 100644 src/Builder/Aggregation/LtrimAggregation.php create mode 100644 src/Builder/Aggregation/MapAggregation.php create mode 100644 src/Builder/Aggregation/MaxNAggregation.php create mode 100644 src/Builder/Aggregation/MedianAggregation.php create mode 100644 src/Builder/Aggregation/MergeObjectsAggregation.php create mode 100644 src/Builder/Aggregation/MetaAggregation.php create mode 100644 src/Builder/Aggregation/MillisecondAggregation.php create mode 100644 src/Builder/Aggregation/MinNAggregation.php create mode 100644 src/Builder/Aggregation/MinuteAggregation.php create mode 100644 src/Builder/Aggregation/MonthAggregation.php create mode 100644 src/Builder/Aggregation/MultiplyAggregation.php create mode 100644 src/Builder/Aggregation/NotAggregation.php create mode 100644 src/Builder/Aggregation/ObjectToArrayAggregation.php create mode 100644 src/Builder/Aggregation/OrAggregation.php create mode 100644 src/Builder/Aggregation/PercentileAggregation.php create mode 100644 src/Builder/Aggregation/PowAggregation.php create mode 100644 src/Builder/Aggregation/PushAggregation.php create mode 100644 src/Builder/Aggregation/RadiansToDegreesAggregation.php create mode 100644 src/Builder/Aggregation/RandAggregation.php create mode 100644 src/Builder/Aggregation/RangeAggregation.php create mode 100644 src/Builder/Aggregation/RankAggregation.php create mode 100644 src/Builder/Aggregation/ReduceAggregation.php create mode 100644 src/Builder/Aggregation/RegexFindAggregation.php create mode 100644 src/Builder/Aggregation/RegexFindAllAggregation.php create mode 100644 src/Builder/Aggregation/RegexMatchAggregation.php create mode 100644 src/Builder/Aggregation/ReplaceAllAggregation.php create mode 100644 src/Builder/Aggregation/ReplaceOneAggregation.php create mode 100644 src/Builder/Aggregation/ReverseArrayAggregation.php create mode 100644 src/Builder/Aggregation/RoundAggregation.php create mode 100644 src/Builder/Aggregation/RtrimAggregation.php create mode 100644 src/Builder/Aggregation/SampleRateAggregation.php create mode 100644 src/Builder/Aggregation/SecondAggregation.php create mode 100644 src/Builder/Aggregation/SetDifferenceAggregation.php create mode 100644 src/Builder/Aggregation/SetEqualsAggregation.php create mode 100644 src/Builder/Aggregation/SetFieldAggregation.php create mode 100644 src/Builder/Aggregation/SetIntersectionAggregation.php create mode 100644 src/Builder/Aggregation/SetIsSubsetAggregation.php create mode 100644 src/Builder/Aggregation/SetUnionAggregation.php create mode 100644 src/Builder/Aggregation/ShiftAggregation.php create mode 100644 src/Builder/Aggregation/SinAggregation.php create mode 100644 src/Builder/Aggregation/SinhAggregation.php create mode 100644 src/Builder/Aggregation/SizeAggregation.php create mode 100644 src/Builder/Aggregation/SliceAggregation.php create mode 100644 src/Builder/Aggregation/SortArrayAggregation.php create mode 100644 src/Builder/Aggregation/SplitAggregation.php create mode 100644 src/Builder/Aggregation/SqrtAggregation.php create mode 100644 src/Builder/Aggregation/StdDevPopAggregation.php create mode 100644 src/Builder/Aggregation/StdDevSampAggregation.php create mode 100644 src/Builder/Aggregation/StrLenBytesAggregation.php create mode 100644 src/Builder/Aggregation/StrLenCPAggregation.php create mode 100644 src/Builder/Aggregation/StrcasecmpAggregation.php create mode 100644 src/Builder/Aggregation/SubstrAggregation.php create mode 100644 src/Builder/Aggregation/SubstrBytesAggregation.php create mode 100644 src/Builder/Aggregation/SubstrCPAggregation.php create mode 100644 src/Builder/Aggregation/SwitchAggregation.php create mode 100644 src/Builder/Aggregation/TanAggregation.php create mode 100644 src/Builder/Aggregation/TanhAggregation.php create mode 100644 src/Builder/Aggregation/ToBoolAggregation.php create mode 100644 src/Builder/Aggregation/ToDateAggregation.php create mode 100644 src/Builder/Aggregation/ToDecimalAggregation.php create mode 100644 src/Builder/Aggregation/ToDoubleAggregation.php create mode 100644 src/Builder/Aggregation/ToIntAggregation.php create mode 100644 src/Builder/Aggregation/ToLongAggregation.php create mode 100644 src/Builder/Aggregation/ToLowerAggregation.php create mode 100644 src/Builder/Aggregation/ToObjectIdAggregation.php create mode 100644 src/Builder/Aggregation/ToStringAggregation.php create mode 100644 src/Builder/Aggregation/ToUpperAggregation.php create mode 100644 src/Builder/Aggregation/TopAggregation.php create mode 100644 src/Builder/Aggregation/TopNAggregation.php create mode 100644 src/Builder/Aggregation/TrimAggregation.php create mode 100644 src/Builder/Aggregation/TruncAggregation.php create mode 100644 src/Builder/Aggregation/TsIncrementAggregation.php create mode 100644 src/Builder/Aggregation/TsSecondAggregation.php create mode 100644 src/Builder/Aggregation/TypeAggregation.php create mode 100644 src/Builder/Aggregation/UnsetFieldAggregation.php create mode 100644 src/Builder/Aggregation/WeekAggregation.php create mode 100644 src/Builder/Aggregation/YearAggregation.php create mode 100644 src/Builder/Aggregation/ZipAggregation.php create mode 100644 src/Builder/Encode.php create mode 100644 src/Builder/Expression/BinaryFieldPath.php create mode 100644 src/Builder/Expression/DoubleFieldPath.php create mode 100644 src/Builder/Expression/LongFieldPath.php create mode 100644 src/Builder/Expression/ObjectIdFieldPath.php create mode 100644 src/Builder/Expression/ResolvesToBinary.php create mode 100644 src/Builder/Expression/ResolvesToDouble.php create mode 100644 src/Builder/Expression/ResolvesToLong.php create mode 100644 src/Builder/Expression/ResolvesToObjectId.php create mode 100644 src/Builder/Expression/ResolvesToTimestamp.php create mode 100644 src/Builder/Expression/TimestampFieldPath.php create mode 100644 src/Builder/Query/AllQuery.php create mode 100644 src/Builder/Query/BitsAllClearQuery.php create mode 100644 src/Builder/Query/BitsAllSetQuery.php create mode 100644 src/Builder/Query/BitsAnyClearQuery.php create mode 100644 src/Builder/Query/BitsAnySetQuery.php create mode 100644 src/Builder/Query/BoxQuery.php create mode 100644 src/Builder/Query/CenterQuery.php create mode 100644 src/Builder/Query/CenterSphereQuery.php create mode 100644 src/Builder/Query/CommentQuery.php create mode 100644 src/Builder/Query/ElemMatchQuery.php create mode 100644 src/Builder/Query/EqQuery.php create mode 100644 src/Builder/Query/ExistsQuery.php create mode 100644 src/Builder/Query/GeoIntersectsQuery.php create mode 100644 src/Builder/Query/GeoWithinQuery.php create mode 100644 src/Builder/Query/GeometryQuery.php create mode 100644 src/Builder/Query/InQuery.php create mode 100644 src/Builder/Query/JsonSchemaQuery.php create mode 100644 src/Builder/Query/LteQuery.php create mode 100644 src/Builder/Query/MaxDistanceQuery.php create mode 100644 src/Builder/Query/MetaQuery.php create mode 100644 src/Builder/Query/MinDistanceQuery.php create mode 100644 src/Builder/Query/ModQuery.php create mode 100644 src/Builder/Query/NaturalQuery.php create mode 100644 src/Builder/Query/NeQuery.php create mode 100644 src/Builder/Query/NearQuery.php create mode 100644 src/Builder/Query/NearSphereQuery.php create mode 100644 src/Builder/Query/NinQuery.php create mode 100644 src/Builder/Query/NorQuery.php create mode 100644 src/Builder/Query/NotQuery.php create mode 100644 src/Builder/Query/PolygonQuery.php create mode 100644 src/Builder/Query/Query.php create mode 100644 src/Builder/Query/QueryInterface.php create mode 100644 src/Builder/Query/RandQuery.php create mode 100644 src/Builder/Query/RegexQuery.php create mode 100644 src/Builder/Query/SizeQuery.php create mode 100644 src/Builder/Query/SliceQuery.php create mode 100644 src/Builder/Query/TextQuery.php create mode 100644 src/Builder/Query/TypeQuery.php create mode 100644 src/Builder/Query/WhereQuery.php create mode 100644 src/Builder/Stage/AddFieldsStage.php create mode 100644 src/Builder/Stage/BucketAutoStage.php create mode 100644 src/Builder/Stage/BucketStage.php create mode 100644 src/Builder/Stage/ChangeStreamSplitLargeEventStage.php create mode 100644 src/Builder/Stage/ChangeStreamStage.php create mode 100644 src/Builder/Stage/CollStatsStage.php create mode 100644 src/Builder/Stage/CountStage.php create mode 100644 src/Builder/Stage/CurrentOpStage.php create mode 100644 src/Builder/Stage/DensifyStage.php create mode 100644 src/Builder/Stage/DocumentsStage.php create mode 100644 src/Builder/Stage/FacetStage.php create mode 100644 src/Builder/Stage/FillStage.php create mode 100644 src/Builder/Stage/GeoNearStage.php create mode 100644 src/Builder/Stage/GraphLookupStage.php create mode 100644 src/Builder/Stage/IndexStatsStage.php create mode 100644 src/Builder/Stage/ListLocalSessionsStage.php create mode 100644 src/Builder/Stage/ListSampledQueriesStage.php create mode 100644 src/Builder/Stage/ListSearchIndexesStage.php create mode 100644 src/Builder/Stage/ListSessionsStage.php create mode 100644 src/Builder/Stage/LookupStage.php create mode 100644 src/Builder/Stage/MergeStage.php create mode 100644 src/Builder/Stage/OutStage.php create mode 100644 src/Builder/Stage/PlanCacheStatsStage.php create mode 100644 src/Builder/Stage/RedactStage.php create mode 100644 src/Builder/Stage/ReplaceRootStage.php create mode 100644 src/Builder/Stage/ReplaceWithStage.php create mode 100644 src/Builder/Stage/SampleStage.php create mode 100644 src/Builder/Stage/SearchMetaStage.php create mode 100644 src/Builder/Stage/SearchStage.php create mode 100644 src/Builder/Stage/SetStage.php create mode 100644 src/Builder/Stage/SetWindowFieldsStage.php create mode 100644 src/Builder/Stage/ShardedDataDistributionStage.php create mode 100644 src/Builder/Stage/SkipStage.php create mode 100644 src/Builder/Stage/SortByCountStage.php create mode 100644 src/Builder/Stage/Stage.php create mode 100644 src/Builder/Stage/UnionWithStage.php create mode 100644 src/Builder/Stage/UnsetStage.php create mode 100644 src/Builder/Stage/UnwindStage.php diff --git a/generator/composer.json b/generator/composer.json index 436f0ad75..6641fd6bd 100644 --- a/generator/composer.json +++ b/generator/composer.json @@ -20,6 +20,7 @@ "symfony/console": "^6.3", "symfony/css-selector": "^6.3", "symfony/dom-crawler": "^6.3", + "symfony/finder": "^6.3", "symfony/yaml": "^6.3" }, "license": "Apache-2.0", diff --git a/generator/config/aggregation-operators/abs.yaml b/generator/config/aggregation-operators/abs.yaml new file mode 100644 index 000000000..dc4078f01 --- /dev/null +++ b/generator/config/aggregation-operators/abs.yaml @@ -0,0 +1,15 @@ +# $schema: ../schema.json +name: $abs +category: + - 'Arithmetic Expression' +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 diff --git a/generator/config/aggregation-operators/accumulator.yaml b/generator/config/aggregation-operators/accumulator.yaml new file mode 100644 index 000000000..c4071c6d1 --- /dev/null +++ b/generator/config/aggregation-operators/accumulator.yaml @@ -0,0 +1,57 @@ +# $schema: ../schema.json +name: $accumulator +category: + - Accumulators + - 'Custom Aggregation Expression Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/accumulator/' +type: + - Accumulator +encode: object +description: | + Defines a custom accumulator function. + New in version 4.4. +arguments: + - + name: init + type: + - string + 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: + - string + 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: + - string + 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: + - string + optional: true + description: | + Function used to update the result of the accumulation. + - + name: lang + type: + - string + description: | + The language used in the $accumulator code. diff --git a/generator/config/aggregation-operators/acos.yaml b/generator/config/aggregation-operators/acos.yaml new file mode 100644 index 000000000..a76fe600b --- /dev/null +++ b/generator/config/aggregation-operators/acos.yaml @@ -0,0 +1,20 @@ +# $schema: ../schema.json +name: $acos +category: + - 'Trigonometry Expression Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/acos/' +type: + - resolvesToDouble + - resolvesToDecimal +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. diff --git a/generator/config/aggregation-operators/acosh.yaml b/generator/config/aggregation-operators/acosh.yaml new file mode 100644 index 000000000..02aa26f6d --- /dev/null +++ b/generator/config/aggregation-operators/acosh.yaml @@ -0,0 +1,20 @@ +# $schema: ../schema.json +name: $acosh +category: + - 'Trigonometry Expression Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/acosh/' +type: + - resolvesToDouble + - resolvesToDecimal +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. diff --git a/generator/config/aggregation-operators/add.yaml b/generator/config/aggregation-operators/add.yaml new file mode 100644 index 000000000..426e32b1e --- /dev/null +++ b/generator/config/aggregation-operators/add.yaml @@ -0,0 +1,21 @@ +# $schema: ../schema.json +name: $add +category: + - 'Arithmetic Expression Operator' + - 'Date Expression Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/add/' +type: + - resolvesToNumber + - resolvesToDate +encode: array +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. diff --git a/generator/config/aggregation-operators/addToSet.yaml b/generator/config/aggregation-operators/addToSet.yaml new file mode 100644 index 000000000..32d3b5042 --- /dev/null +++ b/generator/config/aggregation-operators/addToSet.yaml @@ -0,0 +1,18 @@ +# $schema: ../schema.json +name: $addToSet +category: + - Accumulators + - 'Window Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/addToSet/' +type: + - Accumulator +encode: single +description: | + Returns an array of unique expression values for each group. Order of the array elements is undefined. + Changed in version 5.0: Available in the $setWindowFields stage. +arguments: + - + name: expression + type: + - expression + - fieldPath diff --git a/generator/config/aggregation-operators/allElementsTrue.yaml b/generator/config/aggregation-operators/allElementsTrue.yaml new file mode 100644 index 000000000..b81b8d168 --- /dev/null +++ b/generator/config/aggregation-operators/allElementsTrue.yaml @@ -0,0 +1,16 @@ +# $schema: ../schema.json +name: $allElementsTrue +category: + - 'Set Expression Operator' +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 + variadic: array diff --git a/generator/config/aggregation-operators/and.yaml b/generator/config/aggregation-operators/and.yaml new file mode 100644 index 000000000..522a043c6 --- /dev/null +++ b/generator/config/aggregation-operators/and.yaml @@ -0,0 +1,20 @@ +# $schema: ../schema.json +name: $and +category: + - 'Boolean Expression Operator' +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 diff --git a/generator/config/aggregation-operators/anyElementTrue.yaml b/generator/config/aggregation-operators/anyElementTrue.yaml new file mode 100644 index 000000000..e97049101 --- /dev/null +++ b/generator/config/aggregation-operators/anyElementTrue.yaml @@ -0,0 +1,15 @@ +# $schema: ../schema.json +name: $anyElementTrue +category: + - 'Set Expression Operator' +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 diff --git a/generator/config/aggregation-operators/arrayElemAt.yaml b/generator/config/aggregation-operators/arrayElemAt.yaml new file mode 100644 index 000000000..9f0119ed9 --- /dev/null +++ b/generator/config/aggregation-operators/arrayElemAt.yaml @@ -0,0 +1,19 @@ +# $schema: ../schema.json +name: $arrayElemAt +category: + - 'Array Expression Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/arrayElemAt/' +type: + - resolvesToAnything +encode: array +description: | + Returns the element at the specified array index. +arguments: + - + name: array + type: + - resolvesToArray + - + name: idx + type: + - resolvesToInt diff --git a/generator/config/aggregation-operators/arrayToObject.yaml b/generator/config/aggregation-operators/arrayToObject.yaml new file mode 100644 index 000000000..f5f709d38 --- /dev/null +++ b/generator/config/aggregation-operators/arrayToObject.yaml @@ -0,0 +1,15 @@ +# $schema: ../schema.json +name: $arrayToObject +category: + - 'Array Expression Operator' +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 diff --git a/generator/config/aggregation-operators/asin.yaml b/generator/config/aggregation-operators/asin.yaml new file mode 100644 index 000000000..5fefa4822 --- /dev/null +++ b/generator/config/aggregation-operators/asin.yaml @@ -0,0 +1,20 @@ +# $schema: ../schema.json +name: $asin +category: + - 'Trigonometry Expression Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/asin/' +type: + - resolvesToDouble + - resolvesToDecimal +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. diff --git a/generator/config/aggregation-operators/asinh.yaml b/generator/config/aggregation-operators/asinh.yaml new file mode 100644 index 000000000..34dc79311 --- /dev/null +++ b/generator/config/aggregation-operators/asinh.yaml @@ -0,0 +1,20 @@ +# $schema: ../schema.json +name: $asinh +category: + - 'Trigonometry Expression Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/asinh/' +type: + - resolvesToDouble + - resolvesToDecimal +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. diff --git a/generator/config/aggregation-operators/atan.yaml b/generator/config/aggregation-operators/atan.yaml new file mode 100644 index 000000000..71570877b --- /dev/null +++ b/generator/config/aggregation-operators/atan.yaml @@ -0,0 +1,20 @@ +# $schema: ../schema.json +name: $atan +category: + - 'Trigonometry Expression Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/atan/' +type: + - resolvesToDouble + - resolvesToDecimal +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. diff --git a/generator/config/aggregation-operators/atan2.yaml b/generator/config/aggregation-operators/atan2.yaml new file mode 100644 index 000000000..d82167da0 --- /dev/null +++ b/generator/config/aggregation-operators/atan2.yaml @@ -0,0 +1,24 @@ +# $schema: ../schema.json +name: $atan2 +category: + - 'Trigonometry Expression Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/atan2/' +type: + - resolvesToDouble + - resolvesToDecimal +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 diff --git a/generator/config/aggregation-operators/atanh.yaml b/generator/config/aggregation-operators/atanh.yaml new file mode 100644 index 000000000..d422943ca --- /dev/null +++ b/generator/config/aggregation-operators/atanh.yaml @@ -0,0 +1,20 @@ +# $schema: ../schema.json +name: $atanh +category: + - 'Trigonometry Expression Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/atanh/' +type: + - resolvesToDouble + - resolvesToDecimal +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. diff --git a/generator/config/aggregation-operators/avg.yaml b/generator/config/aggregation-operators/avg.yaml new file mode 100644 index 000000000..c2a7eaee9 --- /dev/null +++ b/generator/config/aggregation-operators/avg.yaml @@ -0,0 +1,20 @@ +# $schema: ../schema.json +name: $avg +category: + - Accumulators + - 'Accumulators (in Other Stages)' + - 'Window Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/avg/' +type: + - resolvesToNumber + - Accumulator +encode: single +description: | + Returns an average of numerical values. Ignores non-numeric values. + Changed in version 5.0: Available in the $setWindowFields stage. +arguments: + - + name: expression + type: + - resolvesToNumber + variadic: array diff --git a/generator/config/aggregation-operators/binarySize.yaml b/generator/config/aggregation-operators/binarySize.yaml new file mode 100644 index 000000000..7b2af86cd --- /dev/null +++ b/generator/config/aggregation-operators/binarySize.yaml @@ -0,0 +1,17 @@ +# $schema: ../schema.json +name: $binarySize +category: + - 'Data Size Operator' +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 + - resolvesToBinary + - resolvesToNull diff --git a/generator/config/aggregation-operators/bitAnd.yaml b/generator/config/aggregation-operators/bitAnd.yaml new file mode 100644 index 000000000..463441dc3 --- /dev/null +++ b/generator/config/aggregation-operators/bitAnd.yaml @@ -0,0 +1,19 @@ +# $schema: ../schema.json +name: $bitAnd +category: + - 'Bitwise Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitAnd/' +type: + - resolvesToInt + - resolvesToLong +encode: single +description: | + Returns the result of a bitwise and operation on an array of int or long values. + New in version 6.3. +arguments: + - + name: expression + type: + - resolvesToInt + - resolvesToLong + variadic: array diff --git a/generator/config/aggregation-operators/bitNot.yaml b/generator/config/aggregation-operators/bitNot.yaml new file mode 100644 index 000000000..20867917d --- /dev/null +++ b/generator/config/aggregation-operators/bitNot.yaml @@ -0,0 +1,18 @@ +# $schema: ../schema.json +name: $bitNot +category: + - 'Bitwise Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitNot/' +type: + - resolvesToInt + - resolvesToLong +encode: single +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 version 6.3. +arguments: + - + name: expression + type: + - resolvesToInt + - resolvesToLong diff --git a/generator/config/aggregation-operators/bitOr.yaml b/generator/config/aggregation-operators/bitOr.yaml new file mode 100644 index 000000000..10f4a600e --- /dev/null +++ b/generator/config/aggregation-operators/bitOr.yaml @@ -0,0 +1,19 @@ +# $schema: ../schema.json +name: $bitOr +category: + - 'Bitwise Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitOr/' +type: + - resolvesToInt + - resolvesToLong +encode: single +description: | + Returns the result of a bitwise or operation on an array of int or long values. + New in version 6.3. +arguments: + - + name: expression + type: + - resolvesToInt + - resolvesToLong + variadic: array diff --git a/generator/config/aggregation-operators/bitXor.yaml b/generator/config/aggregation-operators/bitXor.yaml new file mode 100644 index 000000000..4aca36e01 --- /dev/null +++ b/generator/config/aggregation-operators/bitXor.yaml @@ -0,0 +1,12 @@ +# $schema: ../schema.json +name: $bitXor +category: + - 'Bitwise Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitXor/' +type: + - resolvesToInt + - resolvesToLong +encode: single +description: | + Returns the result of a bitwise xor (exclusive or) operation on an array of int and long values. + New in version 6.3. diff --git a/generator/config/aggregation-operators/bottom.yaml b/generator/config/aggregation-operators/bottom.yaml new file mode 100644 index 000000000..22c69b337 --- /dev/null +++ b/generator/config/aggregation-operators/bottom.yaml @@ -0,0 +1,27 @@ +# $schema: ../schema.json +name: $bottom +category: + - Accumulators + - 'Window Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/bottom/' +type: + - Accumulator +encode: object +description: | + Returns the bottom element within a group according to the specified sort order. + New in version 5.2. + + Available in the $group and $setWindowFields stages. +arguments: + - + name: sortBy + type: + - SortSpec + 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. diff --git a/generator/config/aggregation-operators/bottomN.yaml b/generator/config/aggregation-operators/bottomN.yaml new file mode 100644 index 000000000..d4ce53d16 --- /dev/null +++ b/generator/config/aggregation-operators/bottomN.yaml @@ -0,0 +1,32 @@ +# $schema: ../schema.json +name: $bottomN +category: + - Accumulators + - 'Window Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/bottomN/' +type: + - Accumulator +encode: object +description: | + Returns an aggregation of the bottom n elements within a group, according to the specified sort order. If the group contains fewer than n elements, $bottomN returns all elements in the group. + New in version 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: + - SortSpec + 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. diff --git a/generator/config/aggregation-operators/bsonSize.yaml b/generator/config/aggregation-operators/bsonSize.yaml new file mode 100644 index 000000000..ead8ef2c5 --- /dev/null +++ b/generator/config/aggregation-operators/bsonSize.yaml @@ -0,0 +1,16 @@ +# $schema: ../schema.json +name: $bsonSize +category: + - 'Data Size Operator' +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. bsontype Object) when encoded as BSON. +arguments: + - + name: object + type: + - resolvesToObject + - resolvesToNull diff --git a/generator/config/aggregation-operators/ceil.yaml b/generator/config/aggregation-operators/ceil.yaml new file mode 100644 index 000000000..438fede0d --- /dev/null +++ b/generator/config/aggregation-operators/ceil.yaml @@ -0,0 +1,17 @@ +# $schema: ../schema.json +name: $ceil +category: + - 'Arithmetic Expression Operator' +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. diff --git a/generator/config/aggregation-operators/cmp.yaml b/generator/config/aggregation-operators/cmp.yaml new file mode 100644 index 000000000..6f0d9dcdf --- /dev/null +++ b/generator/config/aggregation-operators/cmp.yaml @@ -0,0 +1,19 @@ +# $schema: ../schema.json +name: $cmp +category: + - 'Comparison Expression Operator' +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 diff --git a/generator/config/aggregation-operators/concat.yaml b/generator/config/aggregation-operators/concat.yaml new file mode 100644 index 000000000..d231453c3 --- /dev/null +++ b/generator/config/aggregation-operators/concat.yaml @@ -0,0 +1,16 @@ +# $schema: ../schema.json +name: $concat +category: + - 'String Expression Operator' +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 diff --git a/generator/config/aggregation-operators/concatArrays.yaml b/generator/config/aggregation-operators/concatArrays.yaml new file mode 100644 index 000000000..f9e951b18 --- /dev/null +++ b/generator/config/aggregation-operators/concatArrays.yaml @@ -0,0 +1,16 @@ +# $schema: ../schema.json +name: $concatArrays +category: + - 'Array Expression Operator' +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 diff --git a/generator/config/aggregation-operators/cond.yaml b/generator/config/aggregation-operators/cond.yaml new file mode 100644 index 000000000..5630dd00c --- /dev/null +++ b/generator/config/aggregation-operators/cond.yaml @@ -0,0 +1,23 @@ +# $schema: ../schema.json +name: $cond +category: + - 'Conditional Expression Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/cond/' +type: + - resolvesToAnything +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 diff --git a/generator/config/aggregation-operators/convert.yaml b/generator/config/aggregation-operators/convert.yaml new file mode 100644 index 000000000..20e1f17ab --- /dev/null +++ b/generator/config/aggregation-operators/convert.yaml @@ -0,0 +1,37 @@ +# $schema: ../schema.json +name: $convert +category: + - 'Type Expression Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/convert/' +type: + - resolvesToAnything +encode: object +description: | + Converts a value to a specified type. + New in version 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. diff --git a/generator/config/aggregation-operators/cos.yaml b/generator/config/aggregation-operators/cos.yaml new file mode 100644 index 000000000..6073937c2 --- /dev/null +++ b/generator/config/aggregation-operators/cos.yaml @@ -0,0 +1,19 @@ +# $schema: ../schema.json +name: $cos +category: + - 'Trigonometry Expression Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/cos/' +type: + - resolvesToDouble + - resolvesToDecimal +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. diff --git a/generator/config/aggregation-operators/cosh.yaml b/generator/config/aggregation-operators/cosh.yaml new file mode 100644 index 000000000..293261180 --- /dev/null +++ b/generator/config/aggregation-operators/cosh.yaml @@ -0,0 +1,19 @@ +# $schema: ../schema.json +name: $cosh +category: + - 'Trigonometry Expression Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/cosh/' +type: + - resolvesToDouble + - resolvesToDecimal +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. diff --git a/generator/config/aggregation-operators/count.yaml b/generator/config/aggregation-operators/count.yaml new file mode 100644 index 000000000..828ae9f56 --- /dev/null +++ b/generator/config/aggregation-operators/count.yaml @@ -0,0 +1,18 @@ +# $schema: ../schema.json +name: $count +category: + - Accumulators + - 'Window Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/count/' +type: + - Accumulator +encode: object +description: | + Returns the number of documents in the group or window. + Distinct from the $count pipeline stage. + New in version 5.0. +arguments: + - + name: field + type: + - string diff --git a/generator/config/aggregation-operators/covariancePop.yaml b/generator/config/aggregation-operators/covariancePop.yaml new file mode 100644 index 000000000..084ef15e7 --- /dev/null +++ b/generator/config/aggregation-operators/covariancePop.yaml @@ -0,0 +1,21 @@ +# $schema: ../schema.json +name: $covariancePop +category: + - 'Window Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/covariancePop/' +type: + - resolvesToDouble + - resolvesToDecimal +encode: array +description: | + Returns the population covariance of two numeric expressions. + New in version 5.0. +arguments: + - + name: expression1 + type: + - resolvesToNumber + - + name: expression2 + type: + - resolvesToNumber diff --git a/generator/config/aggregation-operators/covarianceSamp.yaml b/generator/config/aggregation-operators/covarianceSamp.yaml new file mode 100644 index 000000000..701776b3f --- /dev/null +++ b/generator/config/aggregation-operators/covarianceSamp.yaml @@ -0,0 +1,21 @@ +# $schema: ../schema.json +name: $covarianceSamp +category: + - 'Window Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/covarianceSamp/' +type: + - resolvesToDouble + - resolvesToDecimal +encode: array +description: | + Returns the sample covariance of two numeric expressions. + New in version 5.0. +arguments: + - + name: expression1 + type: + - resolvesToNumber + - + name: expression2 + type: + - resolvesToNumber diff --git a/generator/config/aggregation-operators/dateAdd.yaml b/generator/config/aggregation-operators/dateAdd.yaml new file mode 100644 index 000000000..0febc38c0 --- /dev/null +++ b/generator/config/aggregation-operators/dateAdd.yaml @@ -0,0 +1,37 @@ +# $schema: ../schema.json +name: $dateAdd +category: + - 'Date Expression Operator' +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: + - resolvesToString + 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. diff --git a/generator/config/aggregation-operators/dateDiff.yaml b/generator/config/aggregation-operators/dateDiff.yaml new file mode 100644 index 000000000..c18a2ee2b --- /dev/null +++ b/generator/config/aggregation-operators/dateDiff.yaml @@ -0,0 +1,47 @@ +# $schema: ../schema.json +name: $dateDiff +category: + - 'Date Expression Operator' +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: + - resolvesToString + 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 diff --git a/generator/config/aggregation-operators/dateFromParts.yaml b/generator/config/aggregation-operators/dateFromParts.yaml new file mode 100644 index 000000000..a0c49ae6e --- /dev/null +++ b/generator/config/aggregation-operators/dateFromParts.yaml @@ -0,0 +1,86 @@ +# $schema: ../schema.json +name: $dateFromParts +category: + - 'Date Expression Operator' +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 + description: | + Calendar year. Can be any expression that evaluates to a number. + - + name: isoWeekYear + type: + - resolvesToNumber + 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. diff --git a/generator/config/aggregation-operators/dateFromString.yaml b/generator/config/aggregation-operators/dateFromString.yaml new file mode 100644 index 000000000..537ed78e9 --- /dev/null +++ b/generator/config/aggregation-operators/dateFromString.yaml @@ -0,0 +1,49 @@ +# $schema: ../schema.json +name: $dateFromString +category: + - 'Date Expression Operator' + - 'String Expression Operator' +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. diff --git a/generator/config/aggregation-operators/dateSubtract.yaml b/generator/config/aggregation-operators/dateSubtract.yaml new file mode 100644 index 000000000..9c8f076e2 --- /dev/null +++ b/generator/config/aggregation-operators/dateSubtract.yaml @@ -0,0 +1,37 @@ +# $schema: ../schema.json +name: $dateSubtract +category: + - 'Date Expression Operator' +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: + - resolvesToString + 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. diff --git a/generator/config/aggregation-operators/dateToParts.yaml b/generator/config/aggregation-operators/dateToParts.yaml new file mode 100644 index 000000000..9b748f489 --- /dev/null +++ b/generator/config/aggregation-operators/dateToParts.yaml @@ -0,0 +1,33 @@ +# $schema: ../schema.json +name: $dateToParts +category: + - 'Date Expression Operator' +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. diff --git a/generator/config/aggregation-operators/dateToString.yaml b/generator/config/aggregation-operators/dateToString.yaml new file mode 100644 index 000000000..2fde362eb --- /dev/null +++ b/generator/config/aggregation-operators/dateToString.yaml @@ -0,0 +1,43 @@ +# $schema: ../schema.json +name: $dateToString +category: + - 'Date Expression Operator' + - 'String Expression Operator' +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. diff --git a/generator/config/aggregation-operators/dateTrunc.yaml b/generator/config/aggregation-operators/dateTrunc.yaml new file mode 100644 index 000000000..aefae3749 --- /dev/null +++ b/generator/config/aggregation-operators/dateTrunc.yaml @@ -0,0 +1,49 @@ +# $schema: ../schema.json +name: $dateTrunc +category: + - 'Date Expression Operator' +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: + - resolvesToString + 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. diff --git a/generator/config/aggregation-operators/dayOfMonth.yaml b/generator/config/aggregation-operators/dayOfMonth.yaml new file mode 100644 index 000000000..de585b8dc --- /dev/null +++ b/generator/config/aggregation-operators/dayOfMonth.yaml @@ -0,0 +1,26 @@ +# $schema: ../schema.json +name: $dayOfMonth +category: + - 'Date Expression Operator' +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. diff --git a/generator/config/aggregation-operators/dayOfWeek.yaml b/generator/config/aggregation-operators/dayOfWeek.yaml new file mode 100644 index 000000000..c38e08252 --- /dev/null +++ b/generator/config/aggregation-operators/dayOfWeek.yaml @@ -0,0 +1,26 @@ +# $schema: ../schema.json +name: $dayOfWeek +category: + - 'Date Expression Operator' +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. diff --git a/generator/config/aggregation-operators/dayOfYear.yaml b/generator/config/aggregation-operators/dayOfYear.yaml new file mode 100644 index 000000000..82e579b4f --- /dev/null +++ b/generator/config/aggregation-operators/dayOfYear.yaml @@ -0,0 +1,26 @@ +# $schema: ../schema.json +name: $dayOfYear +category: + - 'Date Expression Operator' +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. diff --git a/generator/config/aggregation-operators/degreesToRadians.yaml b/generator/config/aggregation-operators/degreesToRadians.yaml new file mode 100644 index 000000000..394730a9d --- /dev/null +++ b/generator/config/aggregation-operators/degreesToRadians.yaml @@ -0,0 +1,19 @@ +# $schema: ../schema.json +name: $degreesToRadians +category: + - 'Trigonometry Expression Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/degreesToRadians/' +type: + - resolvesToDouble + - resolvesToDecimal +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. diff --git a/generator/config/aggregation-operators/denseRank.yaml b/generator/config/aggregation-operators/denseRank.yaml new file mode 100644 index 000000000..0f3c3ab77 --- /dev/null +++ b/generator/config/aggregation-operators/denseRank.yaml @@ -0,0 +1,11 @@ +# $schema: ../schema.json +name: $denseRank +category: + - 'Window Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/denseRank/' +type: + - resolvesToInt +encode: object +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 version 5.0. diff --git a/generator/config/aggregation-operators/derivative.yaml b/generator/config/aggregation-operators/derivative.yaml new file mode 100644 index 000000000..f8d13922c --- /dev/null +++ b/generator/config/aggregation-operators/derivative.yaml @@ -0,0 +1,25 @@ +# $schema: ../schema.json +name: $derivative +category: + - 'Window Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/derivative/' +type: + - resolvesToDouble +encode: object +description: | + Returns the average rate of change within the specified window. + New in version 5.0. +arguments: + - + name: input + type: + - resolvesToNumber + - resolvesToDate + - + name: unit + type: + - string + 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. diff --git a/generator/config/aggregation-operators/divide.yaml b/generator/config/aggregation-operators/divide.yaml new file mode 100644 index 000000000..31bf39e6e --- /dev/null +++ b/generator/config/aggregation-operators/divide.yaml @@ -0,0 +1,21 @@ +# $schema: ../schema.json +name: $divide +category: + - 'Arithmetic Expression Operator' +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 diff --git a/generator/config/aggregation-operators/documentNumber.yaml b/generator/config/aggregation-operators/documentNumber.yaml new file mode 100644 index 000000000..745d546a8 --- /dev/null +++ b/generator/config/aggregation-operators/documentNumber.yaml @@ -0,0 +1,11 @@ +# $schema: ../schema.json +name: $documentNumber +category: + - 'Window Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/documentNumber/' +type: + - resolvesToInt +encode: object +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 version 5.0. diff --git a/generator/config/aggregation-operators/eq.yaml b/generator/config/aggregation-operators/eq.yaml new file mode 100644 index 000000000..64f5016d1 --- /dev/null +++ b/generator/config/aggregation-operators/eq.yaml @@ -0,0 +1,19 @@ +# $schema: ../schema.json +name: $eq +category: + - 'Comparison Expression Operator' +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 diff --git a/generator/config/aggregation-operators/exp.yaml b/generator/config/aggregation-operators/exp.yaml new file mode 100644 index 000000000..cfc85050e --- /dev/null +++ b/generator/config/aggregation-operators/exp.yaml @@ -0,0 +1,15 @@ +# $schema: ../schema.json +name: $exp +category: + - 'Arithmetic Expression Operator' +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 diff --git a/generator/config/aggregation-operators/expMovingAvg.yaml b/generator/config/aggregation-operators/expMovingAvg.yaml new file mode 100644 index 000000000..f380fc715 --- /dev/null +++ b/generator/config/aggregation-operators/expMovingAvg.yaml @@ -0,0 +1,33 @@ +# $schema: ../schema.json +name: $expMovingAvg +category: + - 'Window Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/expMovingAvg/' +type: + - resolvesToDouble +encode: object +description: | + Returns the exponential moving average for the numeric expression. + New in version 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: + - float + 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. diff --git a/generator/config/aggregation-operators/filter.yaml b/generator/config/aggregation-operators/filter.yaml new file mode 100644 index 000000000..ddf538abd --- /dev/null +++ b/generator/config/aggregation-operators/filter.yaml @@ -0,0 +1,36 @@ +# $schema: ../schema.json +name: $filter +category: + - 'Array Expression Operator' +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. diff --git a/generator/config/aggregation-operators/first.yaml b/generator/config/aggregation-operators/first.yaml new file mode 100644 index 000000000..64597678f --- /dev/null +++ b/generator/config/aggregation-operators/first.yaml @@ -0,0 +1,19 @@ +# $schema: ../schema.json +name: $first +category: + - Accumulators + - 'Accumulators (in Other Stages)' + - 'Window Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/first/' +type: + - resolvesToAnything + - Accumulator +encode: single +description: | + Returns the result of an expression for the first document in a group or window. + Changed in version 5.0: Available in the $setWindowFields stage. +arguments: + - + name: expression + type: + - expression diff --git a/generator/config/aggregation-operators/firstN.yaml b/generator/config/aggregation-operators/firstN.yaml new file mode 100644 index 000000000..fd2af2411 --- /dev/null +++ b/generator/config/aggregation-operators/firstN.yaml @@ -0,0 +1,23 @@ +# $schema: ../schema.json +name: $firstN +category: + - 'Array Expression Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/firstN-array-element/' +type: + - Accumulator +encode: object +description: | + Returns a specified number of elements from the beginning of an array. Distinct from the $firstN accumulator. +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. diff --git a/generator/config/aggregation-operators/floor.yaml b/generator/config/aggregation-operators/floor.yaml new file mode 100644 index 000000000..385dad121 --- /dev/null +++ b/generator/config/aggregation-operators/floor.yaml @@ -0,0 +1,15 @@ +# $schema: ../schema.json +name: $floor +category: + - 'Arithmetic Expression Operator' +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 diff --git a/generator/config/aggregation-operators/function.yaml b/generator/config/aggregation-operators/function.yaml new file mode 100644 index 000000000..ee21d5b58 --- /dev/null +++ b/generator/config/aggregation-operators/function.yaml @@ -0,0 +1,28 @@ +# $schema: ../schema.json +name: $function +category: + - 'Custom Aggregation Expression Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/function/' +type: + - resolvesToAnything +encode: object +description: | + Defines a custom function. + New in version 4.4. +arguments: + - + name: body + type: + - string + description: | + The function definition. You can specify the function definition as either BSON type Code or String. + - + 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 [ ]. + - + name: lang + type: + - string diff --git a/generator/config/aggregation-operators/getField.yaml b/generator/config/aggregation-operators/getField.yaml new file mode 100644 index 000000000..3870bb83f --- /dev/null +++ b/generator/config/aggregation-operators/getField.yaml @@ -0,0 +1,27 @@ +# $schema: ../schema.json +name: $getField +category: + - 'Miscellaneous Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/getField/' +type: + - resolvesToAnything +encode: object +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 version 5.0. +arguments: + - + name: field + type: + - string + 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). diff --git a/generator/config/aggregation-operators/gt.yaml b/generator/config/aggregation-operators/gt.yaml new file mode 100644 index 000000000..bdc4d3d7f --- /dev/null +++ b/generator/config/aggregation-operators/gt.yaml @@ -0,0 +1,19 @@ +# $schema: ../schema.json +name: $gt +category: + - 'Comparison Expression Operator' +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 diff --git a/generator/config/aggregation-operators/gte.yaml b/generator/config/aggregation-operators/gte.yaml new file mode 100644 index 000000000..b16c00882 --- /dev/null +++ b/generator/config/aggregation-operators/gte.yaml @@ -0,0 +1,19 @@ +# $schema: ../schema.json +name: $gte +category: + - 'Comparison Expression Operator' +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 diff --git a/generator/config/aggregation-operators/hour.yaml b/generator/config/aggregation-operators/hour.yaml new file mode 100644 index 000000000..c15cea6bb --- /dev/null +++ b/generator/config/aggregation-operators/hour.yaml @@ -0,0 +1,26 @@ +# $schema: ../schema.json +name: $hour +category: + - 'Date Expression Operator' +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. diff --git a/generator/config/aggregation-operators/ifNull.yaml b/generator/config/aggregation-operators/ifNull.yaml new file mode 100644 index 000000000..089a0721b --- /dev/null +++ b/generator/config/aggregation-operators/ifNull.yaml @@ -0,0 +1,16 @@ +# $schema: ../schema.json +name: $ifNull +category: + - 'Conditional Expression Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/ifNull/' +type: + - resolvesToAnything +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 diff --git a/generator/config/aggregation-operators/in.yaml b/generator/config/aggregation-operators/in.yaml new file mode 100644 index 000000000..4c885f999 --- /dev/null +++ b/generator/config/aggregation-operators/in.yaml @@ -0,0 +1,23 @@ +# $schema: ../schema.json +name: $in +category: + - 'Array Expression Operator' +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. diff --git a/generator/config/aggregation-operators/indexOfArray.yaml b/generator/config/aggregation-operators/indexOfArray.yaml new file mode 100644 index 000000000..24e1d1a7e --- /dev/null +++ b/generator/config/aggregation-operators/indexOfArray.yaml @@ -0,0 +1,39 @@ +# $schema: ../schema.json +name: $indexOfArray +category: + - 'Array Expression Operator' +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: + - resolvesToString + 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. diff --git a/generator/config/aggregation-operators/indexOfBytes.yaml b/generator/config/aggregation-operators/indexOfBytes.yaml new file mode 100644 index 000000000..57e826b4c --- /dev/null +++ b/generator/config/aggregation-operators/indexOfBytes.yaml @@ -0,0 +1,41 @@ +# $schema: ../schema.json +name: $indexOfBytes +category: + - 'String Expression Operator' +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. diff --git a/generator/config/aggregation-operators/indexOfCP.yaml b/generator/config/aggregation-operators/indexOfCP.yaml new file mode 100644 index 000000000..dc78d1446 --- /dev/null +++ b/generator/config/aggregation-operators/indexOfCP.yaml @@ -0,0 +1,41 @@ +# $schema: ../schema.json +name: $indexOfCP +category: + - 'String Expression Operator' +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. diff --git a/generator/config/aggregation-operators/integral.yaml b/generator/config/aggregation-operators/integral.yaml new file mode 100644 index 000000000..05aa06756 --- /dev/null +++ b/generator/config/aggregation-operators/integral.yaml @@ -0,0 +1,26 @@ +# $schema: ../schema.json +name: $integral +category: + - 'Window Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/integral/' +type: + - resolvesToDouble + - resolvesToDecimal +encode: object +description: | + Returns the approximation of the area under a curve. + New in version 5.0. +arguments: + - + name: input + type: + - resolvesToNumber + - resolvesToDate + - + name: unit + type: + - resolvesToString + 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. diff --git a/generator/config/aggregation-operators/isArray.yaml b/generator/config/aggregation-operators/isArray.yaml new file mode 100644 index 000000000..36bb38c30 --- /dev/null +++ b/generator/config/aggregation-operators/isArray.yaml @@ -0,0 +1,16 @@ +# $schema: ../schema.json +name: $isArray +category: + - 'Array Expression Operator' +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 + variadic: array diff --git a/generator/config/aggregation-operators/isNumber.yaml b/generator/config/aggregation-operators/isNumber.yaml new file mode 100644 index 000000000..1c15d45de --- /dev/null +++ b/generator/config/aggregation-operators/isNumber.yaml @@ -0,0 +1,18 @@ +# $schema: ../schema.json +name: $isNumber +category: + - 'Type Expression Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/isNumber/' +type: + - resolvesToBool +encode: single +description: | + Returns boolean true if the specified expression resolves to an integer, decimal, double, or long. + Returns boolean false if the expression resolves to any other BSON type, null, or a missing field. + New in version 4.4. +arguments: + - + name: expression + type: + - expression + variadic: array diff --git a/generator/config/aggregation-operators/isoDayOfWeek.yaml b/generator/config/aggregation-operators/isoDayOfWeek.yaml new file mode 100644 index 000000000..86bfecb12 --- /dev/null +++ b/generator/config/aggregation-operators/isoDayOfWeek.yaml @@ -0,0 +1,26 @@ +# $schema: ../schema.json +name: $isoDayOfWeek +category: + - 'Date Expression Operator' +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. diff --git a/generator/config/aggregation-operators/isoWeek.yaml b/generator/config/aggregation-operators/isoWeek.yaml new file mode 100644 index 000000000..8219c2856 --- /dev/null +++ b/generator/config/aggregation-operators/isoWeek.yaml @@ -0,0 +1,26 @@ +# $schema: ../schema.json +name: $isoWeek +category: + - 'Date Expression Operator' +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. diff --git a/generator/config/aggregation-operators/isoWeekYear.yaml b/generator/config/aggregation-operators/isoWeekYear.yaml new file mode 100644 index 000000000..3becc3228 --- /dev/null +++ b/generator/config/aggregation-operators/isoWeekYear.yaml @@ -0,0 +1,26 @@ +# $schema: ../schema.json +name: $isoWeekYear +category: + - 'Date Expression Operator' +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. diff --git a/generator/config/aggregation-operators/last.yaml b/generator/config/aggregation-operators/last.yaml new file mode 100644 index 000000000..bbe68eb5c --- /dev/null +++ b/generator/config/aggregation-operators/last.yaml @@ -0,0 +1,19 @@ +# $schema: ../schema.json +name: $last +category: + - Accumulators + - 'Accumulators (in Other Stages)' + - 'Window Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/last/' +type: + - resolvesToAnything + - Accumulator +encode: single +description: | + Returns the result of an expression for the last document in a group or window. + Changed in version 5.0: Available in the $setWindowFields stage. +arguments: + - + name: expression + type: + - expression diff --git a/generator/config/aggregation-operators/lastN.yaml b/generator/config/aggregation-operators/lastN.yaml new file mode 100644 index 000000000..121859038 --- /dev/null +++ b/generator/config/aggregation-operators/lastN.yaml @@ -0,0 +1,23 @@ +# $schema: ../schema.json +name: $lastN +category: + - 'Array Expression Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/lastN/' +type: + - resolvesToArray +encode: object +description: | + Returns a specified number of elements from the end of an array. Distinct from the $lastN accumulator. +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. diff --git a/generator/config/aggregation-operators/let.yaml b/generator/config/aggregation-operators/let.yaml new file mode 100644 index 000000000..36d40ced7 --- /dev/null +++ b/generator/config/aggregation-operators/let.yaml @@ -0,0 +1,25 @@ +# $schema: ../schema.json +name: $let +category: + - 'Variable Expression Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/let/' +type: + - resolvesToAnything +encode: object +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 + 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. diff --git a/generator/config/aggregation-operators/linearFill.yaml b/generator/config/aggregation-operators/linearFill.yaml new file mode 100644 index 000000000..cfd1e1c7f --- /dev/null +++ b/generator/config/aggregation-operators/linearFill.yaml @@ -0,0 +1,17 @@ +# $schema: ../schema.json +name: $linearFill +category: + - 'Window Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/linearFill/' +type: + - resolvesToNumber +encode: single +description: | + Fills null and missing fields in a window using linear interpolation based on surrounding field values. + Available in the $setWindowFields stage. + New in version 5.3. +arguments: + - + name: expression + type: + - resolvesToNumber diff --git a/generator/config/aggregation-operators/literal.yaml b/generator/config/aggregation-operators/literal.yaml new file mode 100644 index 000000000..3ec2d79c9 --- /dev/null +++ b/generator/config/aggregation-operators/literal.yaml @@ -0,0 +1,17 @@ +# $schema: ../schema.json +name: $literal +category: + - 'Literal Expression Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/literal/' +type: + - resolvesToAnything +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: + - mixed + description: | + If the value is an expression, $literal does not evaluate the expression but instead returns the unparsed expression. diff --git a/generator/config/aggregation-operators/ln.yaml b/generator/config/aggregation-operators/ln.yaml new file mode 100644 index 000000000..f1a18f761 --- /dev/null +++ b/generator/config/aggregation-operators/ln.yaml @@ -0,0 +1,18 @@ +# $schema: ../schema.json +name: $ln +category: + - 'Arithmetic Expression Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/ln/' +type: + - resolvesToDouble +encode: single +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. diff --git a/generator/config/aggregation-operators/locf.yaml b/generator/config/aggregation-operators/locf.yaml new file mode 100644 index 000000000..a0e9a065d --- /dev/null +++ b/generator/config/aggregation-operators/locf.yaml @@ -0,0 +1,17 @@ +# $schema: ../schema.json +name: $locf +category: + - 'Window Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/locf/' +type: + - resolvesToAnything +encode: single +description: | + Last observation carried forward. Sets values for null and missing fields in a window to the last non-null value for the field. + Available in the $setWindowFields stage. + New in version 5.2. +arguments: + - + name: expression + type: + - expression diff --git a/generator/config/aggregation-operators/log.yaml b/generator/config/aggregation-operators/log.yaml new file mode 100644 index 000000000..35108021f --- /dev/null +++ b/generator/config/aggregation-operators/log.yaml @@ -0,0 +1,23 @@ +# $schema: ../schema.json +name: $log +category: + - 'Arithmetic Expression Operator' +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. diff --git a/generator/config/aggregation-operators/log10.yaml b/generator/config/aggregation-operators/log10.yaml new file mode 100644 index 000000000..1d95617b9 --- /dev/null +++ b/generator/config/aggregation-operators/log10.yaml @@ -0,0 +1,17 @@ +# $schema: ../schema.json +name: $log10 +category: + - 'Arithmetic Expression Operator' +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. diff --git a/generator/config/aggregation-operators/lt.yaml b/generator/config/aggregation-operators/lt.yaml new file mode 100644 index 000000000..513c362d6 --- /dev/null +++ b/generator/config/aggregation-operators/lt.yaml @@ -0,0 +1,19 @@ +# $schema: ../schema.json +name: $lt +category: + - 'Comparison Expression Operator' +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 diff --git a/generator/config/aggregation-operators/lte.yaml b/generator/config/aggregation-operators/lte.yaml new file mode 100644 index 000000000..180889a3d --- /dev/null +++ b/generator/config/aggregation-operators/lte.yaml @@ -0,0 +1,19 @@ +# $schema: ../schema.json +name: $lte +category: + - 'Comparison Expression Operator' +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 diff --git a/generator/config/aggregation-operators/ltrim.yaml b/generator/config/aggregation-operators/ltrim.yaml new file mode 100644 index 000000000..d3221dc9d --- /dev/null +++ b/generator/config/aggregation-operators/ltrim.yaml @@ -0,0 +1,27 @@ +# $schema: ../schema.json +name: $ltrim +category: + - 'String Expression Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/ltrim/' +type: + - resolvesToString +encode: object +description: | + Removes whitespace or the specified characters from the beginning of a string. + New in version 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. diff --git a/generator/config/aggregation-operators/map.yaml b/generator/config/aggregation-operators/map.yaml new file mode 100644 index 000000000..43ae94a37 --- /dev/null +++ b/generator/config/aggregation-operators/map.yaml @@ -0,0 +1,30 @@ +# $schema: ../schema.json +name: $map +category: + - 'Array Expression Operator' +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. diff --git a/generator/config/aggregation-operators/max.yaml b/generator/config/aggregation-operators/max.yaml new file mode 100644 index 000000000..491a7a01b --- /dev/null +++ b/generator/config/aggregation-operators/max.yaml @@ -0,0 +1,20 @@ +# $schema: ../schema.json +name: $max +category: + - Accumulators + - 'Accumulators (in Other Stages)' + - 'Window Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/max/' +type: + - resolvesToAnything + - Accumulator +encode: single +description: | + Returns the maximum value that results from applying an expression to each document. + Changed in version 5.0: Available in the $setWindowFields stage. +arguments: + - + name: expression + type: + - expression + variadic: array diff --git a/generator/config/aggregation-operators/maxN.yaml b/generator/config/aggregation-operators/maxN.yaml new file mode 100644 index 000000000..9bc55aa2f --- /dev/null +++ b/generator/config/aggregation-operators/maxN.yaml @@ -0,0 +1,23 @@ +# $schema: ../schema.json +name: $maxN +category: + - 'Array Expression Operator' +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. diff --git a/generator/config/aggregation-operators/median.yaml b/generator/config/aggregation-operators/median.yaml new file mode 100644 index 000000000..39089b699 --- /dev/null +++ b/generator/config/aggregation-operators/median.yaml @@ -0,0 +1,30 @@ +# $schema: ../schema.json +name: $median +category: + - Accumulators + - 'Accumulators (in Other Stages)' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/median/' +type: + - resolvesToDouble + - Accumulator +encode: object +description: | + Returns an approximation of the median, the 50th percentile, as a scalar value. + New in version 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: | + $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'. diff --git a/generator/config/aggregation-operators/mergeObjects.yaml b/generator/config/aggregation-operators/mergeObjects.yaml new file mode 100644 index 000000000..28f0ad85c --- /dev/null +++ b/generator/config/aggregation-operators/mergeObjects.yaml @@ -0,0 +1,19 @@ +# $schema: ../schema.json +name: $mergeObjects +category: + - Accumulators + - 'Object Expression Operator' +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 + variadic: array + description: | + Any valid expression that resolves to a document. diff --git a/generator/config/aggregation-operators/meta.yaml b/generator/config/aggregation-operators/meta.yaml new file mode 100644 index 000000000..d4fd59c85 --- /dev/null +++ b/generator/config/aggregation-operators/meta.yaml @@ -0,0 +1,15 @@ +# $schema: ../schema.json +name: $meta +category: + - 'Text Expression Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/meta/' +type: + - resolvesToDecimal +encode: single +description: | + Access available per-document metadata related to the aggregation operation. +arguments: + - + name: keyword + type: + - string diff --git a/generator/config/aggregation-operators/millisecond.yaml b/generator/config/aggregation-operators/millisecond.yaml new file mode 100644 index 000000000..79f13bca2 --- /dev/null +++ b/generator/config/aggregation-operators/millisecond.yaml @@ -0,0 +1,26 @@ +# $schema: ../schema.json +name: $millisecond +category: + - 'Date Expression Operator' +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. diff --git a/generator/config/aggregation-operators/min.yaml b/generator/config/aggregation-operators/min.yaml new file mode 100644 index 000000000..d581c2cc2 --- /dev/null +++ b/generator/config/aggregation-operators/min.yaml @@ -0,0 +1,20 @@ +# $schema: ../schema.json +name: $min +category: + - Accumulators + - 'Accumulators (in Other Stages)' + - 'Window Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/min/' +type: + - resolvesToAnything + - Accumulator +encode: single +description: | + Returns the minimum value that results from applying an expression to each document. + Changed in version 5.0: Available in the $setWindowFields stage. +arguments: + - + name: expression + type: + - expression + variadic: array diff --git a/generator/config/aggregation-operators/minN.yaml b/generator/config/aggregation-operators/minN.yaml new file mode 100644 index 000000000..9c55a4e84 --- /dev/null +++ b/generator/config/aggregation-operators/minN.yaml @@ -0,0 +1,23 @@ +# $schema: ../schema.json +name: $minN +category: + - 'Array Expression Operator' +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. diff --git a/generator/config/aggregation-operators/minute.yaml b/generator/config/aggregation-operators/minute.yaml new file mode 100644 index 000000000..c8cfa060e --- /dev/null +++ b/generator/config/aggregation-operators/minute.yaml @@ -0,0 +1,26 @@ +# $schema: ../schema.json +name: $minute +category: + - 'Date Expression Operator' +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. diff --git a/generator/config/aggregation-operators/mod.yaml b/generator/config/aggregation-operators/mod.yaml new file mode 100644 index 000000000..e3ada87c4 --- /dev/null +++ b/generator/config/aggregation-operators/mod.yaml @@ -0,0 +1,21 @@ +# $schema: ../schema.json +name: $mod +category: + - 'Arithmetic Expression Operator' +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 diff --git a/generator/config/aggregation-operators/month.yaml b/generator/config/aggregation-operators/month.yaml new file mode 100644 index 000000000..70149f848 --- /dev/null +++ b/generator/config/aggregation-operators/month.yaml @@ -0,0 +1,26 @@ +# $schema: ../schema.json +name: $month +category: + - 'Date Expression Operator' +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. diff --git a/generator/config/aggregation-operators/multiply.yaml b/generator/config/aggregation-operators/multiply.yaml new file mode 100644 index 000000000..18e2d25d9 --- /dev/null +++ b/generator/config/aggregation-operators/multiply.yaml @@ -0,0 +1,19 @@ +# $schema: ../schema.json +name: $multiply +category: + - 'Arithmetic Expression Operator' +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. diff --git a/generator/config/aggregation-operators/ne.yaml b/generator/config/aggregation-operators/ne.yaml new file mode 100644 index 000000000..b6df6b38d --- /dev/null +++ b/generator/config/aggregation-operators/ne.yaml @@ -0,0 +1,19 @@ +# $schema: ../schema.json +name: $ne +category: + - 'Comparison Expression Operator' +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 diff --git a/generator/config/aggregation-operators/not.yaml b/generator/config/aggregation-operators/not.yaml new file mode 100644 index 000000000..6a5932c97 --- /dev/null +++ b/generator/config/aggregation-operators/not.yaml @@ -0,0 +1,16 @@ +# $schema: ../schema.json +name: $not +category: + - 'Boolean Expression Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/not/' +type: + - resolvesToBool +encode: single +description: | + Returns the boolean value that is the opposite of its argument expression. Accepts a single argument expression. +arguments: + - + name: expression + type: + - expression + - resolvesToBool diff --git a/generator/config/aggregation-operators/objectToArray.yaml b/generator/config/aggregation-operators/objectToArray.yaml new file mode 100644 index 000000000..5467d4dab --- /dev/null +++ b/generator/config/aggregation-operators/objectToArray.yaml @@ -0,0 +1,18 @@ +# $schema: ../schema.json +name: $objectToArray +category: + - 'Array Expression Operator' + - 'Object Expression Operator' +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. diff --git a/generator/config/aggregation-operators/or.yaml b/generator/config/aggregation-operators/or.yaml new file mode 100644 index 000000000..b9c34b0d7 --- /dev/null +++ b/generator/config/aggregation-operators/or.yaml @@ -0,0 +1,17 @@ +# $schema: ../schema.json +name: $or +category: + - 'Boolean Expression Operator' +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 diff --git a/generator/config/aggregation-operators/percentile.yaml b/generator/config/aggregation-operators/percentile.yaml new file mode 100644 index 000000000..2efefd783 --- /dev/null +++ b/generator/config/aggregation-operators/percentile.yaml @@ -0,0 +1,40 @@ +# $schema: ../schema.json +name: $percentile +category: + - Accumulators + - 'Accumulators (in Other Stages)' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/percentile/' +type: + - resolvesToArray + - Accumulator +encode: object +description: | + Returns an array of scalar values that correspond to specified percentile values. + New in version 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 + 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'. diff --git a/generator/config/aggregation-operators/pow.yaml b/generator/config/aggregation-operators/pow.yaml new file mode 100644 index 000000000..f97b5651a --- /dev/null +++ b/generator/config/aggregation-operators/pow.yaml @@ -0,0 +1,19 @@ +# $schema: ../schema.json +name: $pow +category: + - 'Arithmetic Expression Operator' +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 diff --git a/generator/config/aggregation-operators/push.yaml b/generator/config/aggregation-operators/push.yaml new file mode 100644 index 000000000..abc36eabc --- /dev/null +++ b/generator/config/aggregation-operators/push.yaml @@ -0,0 +1,17 @@ +# $schema: ../schema.json +name: $push +category: + - Accumulators + - 'Window Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/push/' +type: + - Accumulator +encode: single +description: | + Returns an array of values that result from applying an expression to each document. + Changed in version 5.0: Available in the $setWindowFields stage. +arguments: + - + name: expression + type: + - expression diff --git a/generator/config/aggregation-operators/radiansToDegrees.yaml b/generator/config/aggregation-operators/radiansToDegrees.yaml new file mode 100644 index 000000000..23eb9d63c --- /dev/null +++ b/generator/config/aggregation-operators/radiansToDegrees.yaml @@ -0,0 +1,16 @@ +# $schema: ../schema.json +name: $radiansToDegrees +category: + - 'Trigonometry Expression Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/radiansToDegrees/' +type: + - resolvesToDouble + - resolvesToDecimal +encode: single +description: | + Converts a value from radians to degrees. +arguments: + - + name: expression + type: + - resolvesToNumber diff --git a/generator/config/aggregation-operators/rand.yaml b/generator/config/aggregation-operators/rand.yaml new file mode 100644 index 000000000..ff8954bb1 --- /dev/null +++ b/generator/config/aggregation-operators/rand.yaml @@ -0,0 +1,10 @@ +# $schema: ../schema.json +name: $rand +category: + - 'Miscellaneous Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/rand/' +type: + - resolvesToFloat +encode: object +description: | + Returns a random float between 0 and 1 diff --git a/generator/config/aggregation-operators/range.yaml b/generator/config/aggregation-operators/range.yaml new file mode 100644 index 000000000..f121e3907 --- /dev/null +++ b/generator/config/aggregation-operators/range.yaml @@ -0,0 +1,30 @@ +# $schema: ../schema.json +name: $range +category: + - 'Array Expression Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/range/' +type: + - 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. diff --git a/generator/config/aggregation-operators/rank.yaml b/generator/config/aggregation-operators/rank.yaml new file mode 100644 index 000000000..d826f5339 --- /dev/null +++ b/generator/config/aggregation-operators/rank.yaml @@ -0,0 +1,11 @@ +# $schema: ../schema.json +name: $rank +category: + - 'Window Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/rank/' +type: + - resolvesToInt +encode: object +description: | + Returns the document position (known as the rank) relative to other documents in the $setWindowFields stage partition. + New in version 5.0. diff --git a/generator/config/aggregation-operators/reduce.yaml b/generator/config/aggregation-operators/reduce.yaml new file mode 100644 index 000000000..e4c3ec6cb --- /dev/null +++ b/generator/config/aggregation-operators/reduce.yaml @@ -0,0 +1,34 @@ +# $schema: ../schema.json +name: $reduce +category: + - 'Array Expression Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/reduce/' +type: + - resolvesToAnything +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. diff --git a/generator/config/aggregation-operators/regexFind.yaml b/generator/config/aggregation-operators/regexFind.yaml new file mode 100644 index 000000000..92293f6dd --- /dev/null +++ b/generator/config/aggregation-operators/regexFind.yaml @@ -0,0 +1,30 @@ +# $schema: ../schema.json +name: $regexFind +category: + - 'String Expression Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/regexFind/' +type: + - resolvesToObject +encode: object +description: | + Applies a regular expression (regex) to a string and returns information on the first matched substring. + New in version 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 diff --git a/generator/config/aggregation-operators/regexFindAll.yaml b/generator/config/aggregation-operators/regexFindAll.yaml new file mode 100644 index 000000000..4fae32660 --- /dev/null +++ b/generator/config/aggregation-operators/regexFindAll.yaml @@ -0,0 +1,30 @@ +# $schema: ../schema.json +name: $regexFindAll +category: + - 'String Expression Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/regexFindAll/' +type: + - resolvesToArray +encode: object +description: | + Applies a regular expression (regex) to a string and returns information on the all matched substrings. + New in version 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 diff --git a/generator/config/aggregation-operators/regexMatch.yaml b/generator/config/aggregation-operators/regexMatch.yaml new file mode 100644 index 000000000..11f3e66ef --- /dev/null +++ b/generator/config/aggregation-operators/regexMatch.yaml @@ -0,0 +1,30 @@ +# $schema: ../schema.json +name: $regexMatch +category: + - 'String Expression Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/regexMatch/' +type: + - resolvesToBool +encode: object +description: | + Applies a regular expression (regex) to a string and returns a boolean that indicates if a match is found or not. + New in version 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 diff --git a/generator/config/aggregation-operators/replaceAll.yaml b/generator/config/aggregation-operators/replaceAll.yaml new file mode 100644 index 000000000..46e8953b3 --- /dev/null +++ b/generator/config/aggregation-operators/replaceAll.yaml @@ -0,0 +1,34 @@ +# $schema: ../schema.json +name: $replaceAll +category: + - 'String Expression Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceAll/' +type: + - resolvesToString +encode: object +description: | + Replaces all instances of a search string in an input string with a replacement string. + $replaceAll is both case-sensitive and diacritic-sensitive, and ignores any collation present on a collection. + New in version 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. diff --git a/generator/config/aggregation-operators/replaceOne.yaml b/generator/config/aggregation-operators/replaceOne.yaml new file mode 100644 index 000000000..8e50178cc --- /dev/null +++ b/generator/config/aggregation-operators/replaceOne.yaml @@ -0,0 +1,33 @@ +# $schema: ../schema.json +name: $replaceOne +category: + - 'String Expression Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceOne/' +type: + - resolvesToString +encode: object +description: | + Replaces the first instance of a matched string in a given input. + New in version 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. diff --git a/generator/config/aggregation-operators/reverseArray.yaml b/generator/config/aggregation-operators/reverseArray.yaml new file mode 100644 index 000000000..69d183ea1 --- /dev/null +++ b/generator/config/aggregation-operators/reverseArray.yaml @@ -0,0 +1,17 @@ +# $schema: ../schema.json +name: $reverseArray +category: + - 'Array Expression Operator' +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. diff --git a/generator/config/aggregation-operators/round.yaml b/generator/config/aggregation-operators/round.yaml new file mode 100644 index 000000000..0705e3b74 --- /dev/null +++ b/generator/config/aggregation-operators/round.yaml @@ -0,0 +1,31 @@ +# $schema: ../schema.json +name: $round +category: + - 'Arithmetic Expression Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/round/' +type: + - resolvesToInt + - resolvesToDouble + - resolvesToDecimal + - resolvesToLong +encode: array +description: | + Rounds a number to to a whole integer or to a specified decimal place. +arguments: + - + name: number + type: + - resolvesToInt + - resolvesToDouble + - resolvesToDecimal + - resolvesToLong + 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. diff --git a/generator/config/aggregation-operators/rtrim.yaml b/generator/config/aggregation-operators/rtrim.yaml new file mode 100644 index 000000000..9a629e964 --- /dev/null +++ b/generator/config/aggregation-operators/rtrim.yaml @@ -0,0 +1,26 @@ +# $schema: ../schema.json +name: $rtrim +category: + - 'String Expression Operator' +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. diff --git a/generator/config/aggregation-operators/sampleRate.yaml b/generator/config/aggregation-operators/sampleRate.yaml new file mode 100644 index 000000000..e463a7cb1 --- /dev/null +++ b/generator/config/aggregation-operators/sampleRate.yaml @@ -0,0 +1,18 @@ +# $schema: ../schema.json +name: $sampleRate +category: + - 'Miscellaneous Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/sampleRate/' +type: + - resolvesToAnything +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: + - resolvesToFloat + 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. diff --git a/generator/config/aggregation-operators/second.yaml b/generator/config/aggregation-operators/second.yaml new file mode 100644 index 000000000..d9901bb8e --- /dev/null +++ b/generator/config/aggregation-operators/second.yaml @@ -0,0 +1,26 @@ +# $schema: ../schema.json +name: $second +category: + - 'Date Expression Operator' +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. diff --git a/generator/config/aggregation-operators/setDifference.yaml b/generator/config/aggregation-operators/setDifference.yaml new file mode 100644 index 000000000..cd5d07569 --- /dev/null +++ b/generator/config/aggregation-operators/setDifference.yaml @@ -0,0 +1,23 @@ +# $schema: ../schema.json +name: $setDifference +category: + - 'Set Expression Operator' +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. diff --git a/generator/config/aggregation-operators/setEquals.yaml b/generator/config/aggregation-operators/setEquals.yaml new file mode 100644 index 000000000..51dbf2441 --- /dev/null +++ b/generator/config/aggregation-operators/setEquals.yaml @@ -0,0 +1,16 @@ +# $schema: ../schema.json +name: $setEquals +category: + - 'Set Expression Operator' +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 diff --git a/generator/config/aggregation-operators/setField.yaml b/generator/config/aggregation-operators/setField.yaml new file mode 100644 index 000000000..86fb002aa --- /dev/null +++ b/generator/config/aggregation-operators/setField.yaml @@ -0,0 +1,31 @@ +# $schema: ../schema.json +name: $setField +category: + - 'Object Expression Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/setField/' +type: + - resolvesToObject +encode: object +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 version 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. diff --git a/generator/config/aggregation-operators/setIntersection.yaml b/generator/config/aggregation-operators/setIntersection.yaml new file mode 100644 index 000000000..137c3d5b2 --- /dev/null +++ b/generator/config/aggregation-operators/setIntersection.yaml @@ -0,0 +1,16 @@ +# $schema: ../schema.json +name: $setIntersection +category: + - 'Set Expression Operator' +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 diff --git a/generator/config/aggregation-operators/setIsSubset.yaml b/generator/config/aggregation-operators/setIsSubset.yaml new file mode 100644 index 000000000..fc1f11c18 --- /dev/null +++ b/generator/config/aggregation-operators/setIsSubset.yaml @@ -0,0 +1,19 @@ +# $schema: ../schema.json +name: $setIsSubset +category: + - 'Set Expression Operator' +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 diff --git a/generator/config/aggregation-operators/setUnion.yaml b/generator/config/aggregation-operators/setUnion.yaml new file mode 100644 index 000000000..638b97b34 --- /dev/null +++ b/generator/config/aggregation-operators/setUnion.yaml @@ -0,0 +1,16 @@ +# $schema: ../schema.json +name: $setUnion +category: + - 'Set Expression Operator' +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 diff --git a/generator/config/aggregation-operators/shift.yaml b/generator/config/aggregation-operators/shift.yaml new file mode 100644 index 000000000..9cc161a65 --- /dev/null +++ b/generator/config/aggregation-operators/shift.yaml @@ -0,0 +1,36 @@ +# $schema: ../schema.json +name: $shift +category: + - 'Window Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/shift/' +type: + - resolvesToAnything +encode: object +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 version 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. diff --git a/generator/config/aggregation-operators/sin.yaml b/generator/config/aggregation-operators/sin.yaml new file mode 100644 index 000000000..2c484411f --- /dev/null +++ b/generator/config/aggregation-operators/sin.yaml @@ -0,0 +1,19 @@ +# $schema: ../schema.json +name: $sin +category: + - 'Trigonometry Expression Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/sin/' +type: + - resolvesToDouble + - resolvesToDecimal +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. diff --git a/generator/config/aggregation-operators/sinh.yaml b/generator/config/aggregation-operators/sinh.yaml new file mode 100644 index 000000000..e64e8477e --- /dev/null +++ b/generator/config/aggregation-operators/sinh.yaml @@ -0,0 +1,19 @@ +# $schema: ../schema.json +name: $sinh +category: + - 'Trigonometry Expression Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/sinh/' +type: + - resolvesToDouble + - resolvesToDecimal +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. diff --git a/generator/config/aggregation-operators/size.yaml b/generator/config/aggregation-operators/size.yaml new file mode 100644 index 000000000..b6077e2c9 --- /dev/null +++ b/generator/config/aggregation-operators/size.yaml @@ -0,0 +1,17 @@ +# $schema: ../schema.json +name: $size +category: + - 'Array Expression Operator' +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. diff --git a/generator/config/aggregation-operators/slice.yaml b/generator/config/aggregation-operators/slice.yaml new file mode 100644 index 000000000..7d6af314d --- /dev/null +++ b/generator/config/aggregation-operators/slice.yaml @@ -0,0 +1,34 @@ +# $schema: ../schema.json +name: $slice +category: + - 'Array Expression Operator' +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. diff --git a/generator/config/aggregation-operators/sortArray.yaml b/generator/config/aggregation-operators/sortArray.yaml new file mode 100644 index 000000000..974597cdf --- /dev/null +++ b/generator/config/aggregation-operators/sortArray.yaml @@ -0,0 +1,23 @@ +# $schema: ../schema.json +name: $sortArray +category: + - 'Array Expression Operator' +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. + - + name: sortBy + type: + - SortSpec + description: | + The document specifies a sort ordering. diff --git a/generator/config/aggregation-operators/split.yaml b/generator/config/aggregation-operators/split.yaml new file mode 100644 index 000000000..50b523328 --- /dev/null +++ b/generator/config/aggregation-operators/split.yaml @@ -0,0 +1,23 @@ +# $schema: ../schema.json +name: $split +category: + - 'String Expression Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/split/' +type: + - 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. diff --git a/generator/config/aggregation-operators/sqrt.yaml b/generator/config/aggregation-operators/sqrt.yaml new file mode 100644 index 000000000..4f94c228b --- /dev/null +++ b/generator/config/aggregation-operators/sqrt.yaml @@ -0,0 +1,17 @@ +# $schema: ../schema.json +name: $sqrt +category: + - 'Arithmetic Expression Operator' +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. diff --git a/generator/config/aggregation-operators/stdDevPop.yaml b/generator/config/aggregation-operators/stdDevPop.yaml new file mode 100644 index 000000000..428636250 --- /dev/null +++ b/generator/config/aggregation-operators/stdDevPop.yaml @@ -0,0 +1,21 @@ +# $schema: ../schema.json +name: $stdDevPop +category: + - Accumulators + - 'Accumulators (in Other Stages)' + - 'Window Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/stdDevPop/' +type: + - resolvesToDouble + - Accumulator +encode: single +description: | + Calculates the population standard deviation of the input values. Use if the values encompass the entire population of data you want to represent and do not wish to generalize about a larger population. $stdDevPop ignores non-numeric values. + If the values represent only a sample of a population of data from which to generalize about the population, use $stdDevSamp instead. + Changed in version 5.0: Available in the $setWindowFields stage. +arguments: + - + name: expression + type: + - resolvesToNumber + variadic: array diff --git a/generator/config/aggregation-operators/stdDevSamp.yaml b/generator/config/aggregation-operators/stdDevSamp.yaml new file mode 100644 index 000000000..ea251b362 --- /dev/null +++ b/generator/config/aggregation-operators/stdDevSamp.yaml @@ -0,0 +1,21 @@ +# $schema: ../schema.json +name: $stdDevSamp +category: + - Accumulators + - 'Accumulators (in Other Stages)' + - 'Window Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/stdDevSamp/' +type: + - resolvesToDouble + - Accumulator +encode: single +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. + Changed in version 5.0: Available in the $setWindowFields stage. +arguments: + - + name: expression + type: + - resolvesToNumber + variadic: array diff --git a/generator/config/aggregation-operators/strLenBytes.yaml b/generator/config/aggregation-operators/strLenBytes.yaml new file mode 100644 index 000000000..5fd5eb85e --- /dev/null +++ b/generator/config/aggregation-operators/strLenBytes.yaml @@ -0,0 +1,15 @@ +# $schema: ../schema.json +name: $strLenBytes +category: + - 'String Expression Operator' +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 diff --git a/generator/config/aggregation-operators/strLenCP.yaml b/generator/config/aggregation-operators/strLenCP.yaml new file mode 100644 index 000000000..7953ea746 --- /dev/null +++ b/generator/config/aggregation-operators/strLenCP.yaml @@ -0,0 +1,15 @@ +# $schema: ../schema.json +name: $strLenCP +category: + - 'String Expression Operator' +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 diff --git a/generator/config/aggregation-operators/strcasecmp.yaml b/generator/config/aggregation-operators/strcasecmp.yaml new file mode 100644 index 000000000..56ec07ce5 --- /dev/null +++ b/generator/config/aggregation-operators/strcasecmp.yaml @@ -0,0 +1,19 @@ +# $schema: ../schema.json +name: $strcasecmp +category: + - 'String Expression Operator' +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 diff --git a/generator/config/aggregation-operators/substr.yaml b/generator/config/aggregation-operators/substr.yaml new file mode 100644 index 000000000..32e1d9dd2 --- /dev/null +++ b/generator/config/aggregation-operators/substr.yaml @@ -0,0 +1,27 @@ +# $schema: ../schema.json +name: $substr +category: + - 'String Expression Operator' +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. diff --git a/generator/config/aggregation-operators/substrBytes.yaml b/generator/config/aggregation-operators/substrBytes.yaml new file mode 100644 index 000000000..5d41c93e8 --- /dev/null +++ b/generator/config/aggregation-operators/substrBytes.yaml @@ -0,0 +1,27 @@ +# $schema: ../schema.json +name: $substrBytes +category: + - 'String Expression Operator' +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. diff --git a/generator/config/aggregation-operators/substrCP.yaml b/generator/config/aggregation-operators/substrCP.yaml new file mode 100644 index 000000000..7db93701f --- /dev/null +++ b/generator/config/aggregation-operators/substrCP.yaml @@ -0,0 +1,27 @@ +# $schema: ../schema.json +name: $substrCP +category: + - 'String Expression Operator' +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. diff --git a/generator/config/aggregation-operators/subtract.yaml b/generator/config/aggregation-operators/subtract.yaml new file mode 100644 index 000000000..a71d9aa6d --- /dev/null +++ b/generator/config/aggregation-operators/subtract.yaml @@ -0,0 +1,23 @@ +# $schema: ../schema.json +name: $subtract +category: + - 'Arithmetic Expression Operator' + - 'Date Expression Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/subtract/' +type: + - resolvesToNumber + - resolvesToDate +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 diff --git a/generator/config/aggregation-operators/sum.yaml b/generator/config/aggregation-operators/sum.yaml new file mode 100644 index 000000000..eddf779e6 --- /dev/null +++ b/generator/config/aggregation-operators/sum.yaml @@ -0,0 +1,20 @@ +# $schema: ../schema.json +name: $sum +category: + - Accumulators + - 'Accumulators (in Other Stages)' + - 'Window Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/sum/' +type: + - resolvesToNumber + - Accumulator +encode: single +description: | + Returns a sum of numerical values. Ignores non-numeric values. + Changed in version 5.0: Available in the $setWindowFields stage. +arguments: + - + name: expression + type: + - resolvesToNumber + variadic: array diff --git a/generator/config/aggregation-operators/switch.yaml b/generator/config/aggregation-operators/switch.yaml new file mode 100644 index 000000000..a302b6c00 --- /dev/null +++ b/generator/config/aggregation-operators/switch.yaml @@ -0,0 +1,28 @@ +# $schema: ../schema.json +name: $switch +category: + - 'Conditional Expression Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/switch/' +type: + - resolvesToAnything +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{case:resolvesToBool, then:expression}' + 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. diff --git a/generator/config/aggregation-operators/tan.yaml b/generator/config/aggregation-operators/tan.yaml new file mode 100644 index 000000000..ff253e0d0 --- /dev/null +++ b/generator/config/aggregation-operators/tan.yaml @@ -0,0 +1,19 @@ +# $schema: ../schema.json +name: $tan +category: + - 'Trigonometry Expression Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/tan/' +type: + - resolvesToDouble + - resolvesToDecimal +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. diff --git a/generator/config/aggregation-operators/tanh.yaml b/generator/config/aggregation-operators/tanh.yaml new file mode 100644 index 000000000..cd1ee57a3 --- /dev/null +++ b/generator/config/aggregation-operators/tanh.yaml @@ -0,0 +1,19 @@ +# $schema: ../schema.json +name: $tanh +category: + - 'Trigonometry Expression Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/tanh/' +type: + - resolvesToDouble + - resolvesToDecimal +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. diff --git a/generator/config/aggregation-operators/toBool.yaml b/generator/config/aggregation-operators/toBool.yaml new file mode 100644 index 000000000..a065eba35 --- /dev/null +++ b/generator/config/aggregation-operators/toBool.yaml @@ -0,0 +1,16 @@ +# $schema: ../schema.json +name: $toBool +category: + - 'Type Expression Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/toBool/' +type: + - resolvesToBool +encode: single +description: | + Converts value to a boolean. + New in version 4.0. +arguments: + - + name: expression + type: + - expression diff --git a/generator/config/aggregation-operators/toDate.yaml b/generator/config/aggregation-operators/toDate.yaml new file mode 100644 index 000000000..d2f0b0bb9 --- /dev/null +++ b/generator/config/aggregation-operators/toDate.yaml @@ -0,0 +1,16 @@ +# $schema: ../schema.json +name: $toDate +category: + - 'Date Expression Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/toDate/' +type: + - resolvesToDate +encode: single +description: | + Converts value to a Date. + New in version 4.0. +arguments: + - + name: expression + type: + - expression diff --git a/generator/config/aggregation-operators/toDecimal.yaml b/generator/config/aggregation-operators/toDecimal.yaml new file mode 100644 index 000000000..64295bead --- /dev/null +++ b/generator/config/aggregation-operators/toDecimal.yaml @@ -0,0 +1,16 @@ +# $schema: ../schema.json +name: $toDecimal +category: + - 'Type Expression Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/toDecimal/' +type: + - resolvesToDecimal +encode: single +description: | + Converts value to a Decimal128. + New in version 4.0. +arguments: + - + name: expression + type: + - expression diff --git a/generator/config/aggregation-operators/toDouble.yaml b/generator/config/aggregation-operators/toDouble.yaml new file mode 100644 index 000000000..475c70f93 --- /dev/null +++ b/generator/config/aggregation-operators/toDouble.yaml @@ -0,0 +1,16 @@ +# $schema: ../schema.json +name: $toDouble +category: + - 'Type Expression Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/toDouble/' +type: + - resolvesToDouble +encode: single +description: | + Converts value to a double. + New in version 4.0. +arguments: + - + name: expression + type: + - expression diff --git a/generator/config/aggregation-operators/toInt.yaml b/generator/config/aggregation-operators/toInt.yaml new file mode 100644 index 000000000..c4a54424b --- /dev/null +++ b/generator/config/aggregation-operators/toInt.yaml @@ -0,0 +1,16 @@ +# $schema: ../schema.json +name: $toInt +category: + - 'Type Expression Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/toInt/' +type: + - resolvesToInt +encode: single +description: | + Converts value to an integer. + New in version 4.0. +arguments: + - + name: expression + type: + - expression diff --git a/generator/config/aggregation-operators/toLong.yaml b/generator/config/aggregation-operators/toLong.yaml new file mode 100644 index 000000000..4a8ed6f64 --- /dev/null +++ b/generator/config/aggregation-operators/toLong.yaml @@ -0,0 +1,16 @@ +# $schema: ../schema.json +name: $toLong +category: + - 'Type Expression Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/toLong/' +type: + - resolvesToLong +encode: single +description: | + Converts value to a long. + New in version 4.0. +arguments: + - + name: expression + type: + - expression diff --git a/generator/config/aggregation-operators/toLower.yaml b/generator/config/aggregation-operators/toLower.yaml new file mode 100644 index 000000000..a2a6efdd6 --- /dev/null +++ b/generator/config/aggregation-operators/toLower.yaml @@ -0,0 +1,15 @@ +# $schema: ../schema.json +name: $toLower +category: + - 'String Expression Operator' +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 diff --git a/generator/config/aggregation-operators/toObjectId.yaml b/generator/config/aggregation-operators/toObjectId.yaml new file mode 100644 index 000000000..62ed90a0d --- /dev/null +++ b/generator/config/aggregation-operators/toObjectId.yaml @@ -0,0 +1,16 @@ +# $schema: ../schema.json +name: $toObjectId +category: + - 'Type Expression Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/toObjectId/' +type: + - resolvesToObjectId +encode: single +description: | + Converts value to an ObjectId. + New in version 4.0. +arguments: + - + name: expression + type: + - expression diff --git a/generator/config/aggregation-operators/toString.yaml b/generator/config/aggregation-operators/toString.yaml new file mode 100644 index 000000000..1f8749fb5 --- /dev/null +++ b/generator/config/aggregation-operators/toString.yaml @@ -0,0 +1,17 @@ +# $schema: ../schema.json +name: $toString +category: + - 'String Expression Operator' + - 'Type Expression Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/toString/' +type: + - resolvesToString +encode: single +description: | + Converts value to a string. + New in version 4.0. +arguments: + - + name: expression + type: + - expression diff --git a/generator/config/aggregation-operators/toUpper.yaml b/generator/config/aggregation-operators/toUpper.yaml new file mode 100644 index 000000000..973d66688 --- /dev/null +++ b/generator/config/aggregation-operators/toUpper.yaml @@ -0,0 +1,15 @@ +# $schema: ../schema.json +name: $toUpper +category: + - 'String Expression Operator' +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 diff --git a/generator/config/aggregation-operators/top.yaml b/generator/config/aggregation-operators/top.yaml new file mode 100644 index 000000000..d8c746ac9 --- /dev/null +++ b/generator/config/aggregation-operators/top.yaml @@ -0,0 +1,27 @@ +# $schema: ../schema.json +name: $top +category: + - Accumulators + - 'Window Operator' +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 version 5.2. + + Available in the $group and $setWindowFields stages. +arguments: + - + name: sortBy + type: + - SortSpec + 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. diff --git a/generator/config/aggregation-operators/topN.yaml b/generator/config/aggregation-operators/topN.yaml new file mode 100644 index 000000000..a3ff0afe4 --- /dev/null +++ b/generator/config/aggregation-operators/topN.yaml @@ -0,0 +1,33 @@ +# $schema: ../schema.json +name: $topN +category: + - Accumulators + - 'Window Operator' +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 version 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: + - SortSpec + 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. diff --git a/generator/config/aggregation-operators/trim.yaml b/generator/config/aggregation-operators/trim.yaml new file mode 100644 index 000000000..8bbdf6ddd --- /dev/null +++ b/generator/config/aggregation-operators/trim.yaml @@ -0,0 +1,27 @@ +# $schema: ../schema.json +name: $trim +category: + - 'String Expression Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/trim/' +type: + - resolvesToString +encode: object +description: | + Removes whitespace or the specified characters from the beginning and end of a string. + New in version 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. diff --git a/generator/config/aggregation-operators/trunc.yaml b/generator/config/aggregation-operators/trunc.yaml new file mode 100644 index 000000000..930f76215 --- /dev/null +++ b/generator/config/aggregation-operators/trunc.yaml @@ -0,0 +1,25 @@ +# $schema: ../schema.json +name: $trunc +category: + - 'Arithmetic Expression Operator' +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. diff --git a/generator/config/aggregation-operators/tsIncrement.yaml b/generator/config/aggregation-operators/tsIncrement.yaml new file mode 100644 index 000000000..5a225a21b --- /dev/null +++ b/generator/config/aggregation-operators/tsIncrement.yaml @@ -0,0 +1,16 @@ +# $schema: ../schema.json +name: $tsIncrement +category: + - 'Timestamp Expression Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/tsIncrement/' +type: + - resolvesToLong +encode: single +description: | + Returns the incrementing ordinal from a timestamp as a long. + New in version 5.1. +arguments: + - + name: expression + type: + - resolvesToTimestamp diff --git a/generator/config/aggregation-operators/tsSecond.yaml b/generator/config/aggregation-operators/tsSecond.yaml new file mode 100644 index 000000000..1c2fa21e0 --- /dev/null +++ b/generator/config/aggregation-operators/tsSecond.yaml @@ -0,0 +1,16 @@ +# $schema: ../schema.json +name: $tsSecond +category: + - 'Timestamp Expression Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/tsSecond/' +type: + - resolvesToLong +encode: single +description: | + Returns the seconds from a timestamp as a long. + New in version 5.1. +arguments: + - + name: expression + type: + - resolvesToTimestamp diff --git a/generator/config/aggregation-operators/type.yaml b/generator/config/aggregation-operators/type.yaml new file mode 100644 index 000000000..793eb0ac9 --- /dev/null +++ b/generator/config/aggregation-operators/type.yaml @@ -0,0 +1,15 @@ +# $schema: ../schema.json +name: $type +category: + - 'Type Expression Operator' +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 diff --git a/generator/config/aggregation-operators/unsetField.yaml b/generator/config/aggregation-operators/unsetField.yaml new file mode 100644 index 000000000..69affcf80 --- /dev/null +++ b/generator/config/aggregation-operators/unsetField.yaml @@ -0,0 +1,24 @@ +# $schema: ../schema.json +name: $unsetField +category: + - 'Object Expression Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/unsetField/' +type: + - resolvesToObject +encode: object +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. diff --git a/generator/config/aggregation-operators/week.yaml b/generator/config/aggregation-operators/week.yaml new file mode 100644 index 000000000..71d2314e4 --- /dev/null +++ b/generator/config/aggregation-operators/week.yaml @@ -0,0 +1,26 @@ +# $schema: ../schema.json +name: $week +category: + - 'Date Expression Operator' +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. diff --git a/generator/config/aggregation-operators/year.yaml b/generator/config/aggregation-operators/year.yaml new file mode 100644 index 000000000..d76f003f9 --- /dev/null +++ b/generator/config/aggregation-operators/year.yaml @@ -0,0 +1,26 @@ +# $schema: ../schema.json +name: $year +category: + - 'Date Expression Operator' +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. diff --git a/generator/config/aggregation-operators/zip.yaml b/generator/config/aggregation-operators/zip.yaml new file mode 100644 index 000000000..0985edb42 --- /dev/null +++ b/generator/config/aggregation-operators/zip.yaml @@ -0,0 +1,34 @@ +# $schema: ../schema.json +name: $zip +category: + - 'Array Expression Operator' +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/zip/' +type: + - resolvesToArray +encode: object +description: | + Merge two arrays together. +arguments: + - + 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 + 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 + 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. diff --git a/generator/config/aggregation-stages/addFields.yaml b/generator/config/aggregation-stages/addFields.yaml new file mode 100644 index 000000000..147675eed --- /dev/null +++ b/generator/config/aggregation-stages/addFields.yaml @@ -0,0 +1,18 @@ +# $schema: ../schema.json +name: $addFields +category: + - Stage +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. diff --git a/generator/config/aggregation-stages/bucket.yaml b/generator/config/aggregation-stages/bucket.yaml new file mode 100644 index 000000000..fd8fcb16d --- /dev/null +++ b/generator/config/aggregation-stages/bucket.yaml @@ -0,0 +1,45 @@ +# $schema: ../schema.json +name: $bucket +category: + - Stage +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 + - 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 + 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. diff --git a/generator/config/aggregation-stages/bucketAuto.yaml b/generator/config/aggregation-stages/bucketAuto.yaml new file mode 100644 index 000000000..5a6b084df --- /dev/null +++ b/generator/config/aggregation-stages/bucketAuto.yaml @@ -0,0 +1,39 @@ +# $schema: ../schema.json +name: $bucketAuto +category: + - Stage +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 + 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. diff --git a/generator/config/aggregation-stages/changeStream.yaml b/generator/config/aggregation-stages/changeStream.yaml new file mode 100644 index 000000000..05fe2408d --- /dev/null +++ b/generator/config/aggregation-stages/changeStream.yaml @@ -0,0 +1,61 @@ +# $schema: ../schema.json +name: $changeStream +category: + - Stage +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 version 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. diff --git a/generator/config/aggregation-stages/changeStreamSplitLargeEvent.yaml b/generator/config/aggregation-stages/changeStreamSplitLargeEvent.yaml new file mode 100644 index 000000000..39352daa8 --- /dev/null +++ b/generator/config/aggregation-stages/changeStreamSplitLargeEvent.yaml @@ -0,0 +1,11 @@ +# $schema: ../schema.json +name: $changeStreamSplitLargeEvent +category: + - Stage +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/changeStreamSplitLargeEvent/' +type: + - Stage +encode: object +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. diff --git a/generator/config/aggregation-stages/collStats.yaml b/generator/config/aggregation-stages/collStats.yaml new file mode 100644 index 000000000..96698f899 --- /dev/null +++ b/generator/config/aggregation-stages/collStats.yaml @@ -0,0 +1,15 @@ +# $schema: ../schema.json +name: $collStats +category: + - Stage +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/collStats/' +type: + - Stage +encode: single +description: | + Returns statistics regarding a collection or view. +arguments: + - + name: config + type: + - object diff --git a/generator/config/aggregation-stages/count.yaml b/generator/config/aggregation-stages/count.yaml new file mode 100644 index 000000000..7ab62453a --- /dev/null +++ b/generator/config/aggregation-stages/count.yaml @@ -0,0 +1,16 @@ +# $schema: ../schema.json +name: $count +category: + - Stage +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/count/' +type: + - Stage +encode: single +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 diff --git a/generator/config/aggregation-stages/currentOp.yaml b/generator/config/aggregation-stages/currentOp.yaml new file mode 100644 index 000000000..62a2ab550 --- /dev/null +++ b/generator/config/aggregation-stages/currentOp.yaml @@ -0,0 +1,10 @@ +# $schema: ../schema.json +name: $currentOp +category: + - Stage +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. diff --git a/generator/config/aggregation-stages/densify.yaml b/generator/config/aggregation-stages/densify.yaml new file mode 100644 index 000000000..ab572474c --- /dev/null +++ b/generator/config/aggregation-stages/densify.yaml @@ -0,0 +1,32 @@ +# $schema: ../schema.json +name: $densify +category: + - Stage +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: + - FieldPath + 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. diff --git a/generator/config/aggregation-stages/documents.yaml b/generator/config/aggregation-stages/documents.yaml new file mode 100644 index 000000000..ac9d60e5e --- /dev/null +++ b/generator/config/aggregation-stages/documents.yaml @@ -0,0 +1,21 @@ +# $schema: ../schema.json +name: $documents +category: + - Stage +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 + 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. diff --git a/generator/config/aggregation-stages/facet.yaml b/generator/config/aggregation-stages/facet.yaml new file mode 100644 index 000000000..f2a31d772 --- /dev/null +++ b/generator/config/aggregation-stages/facet.yaml @@ -0,0 +1,16 @@ +# $schema: ../schema.json +name: $facet +category: + - Stage +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 diff --git a/generator/config/aggregation-stages/fill.yaml b/generator/config/aggregation-stages/fill.yaml new file mode 100644 index 000000000..a3c6c7f75 --- /dev/null +++ b/generator/config/aggregation-stages/fill.yaml @@ -0,0 +1,44 @@ +# $schema: ../schema.json +name: $fill +category: + - Stage +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 + - 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: + - list + 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: + - SortSpec + 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. diff --git a/generator/config/aggregation-stages/geoNear.yaml b/generator/config/aggregation-stages/geoNear.yaml new file mode 100644 index 000000000..4a4246dc8 --- /dev/null +++ b/generator/config/aggregation-stages/geoNear.yaml @@ -0,0 +1,78 @@ +# $schema: ../schema.json +name: $geoNear +category: + - Stage +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 + 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 + description: | + The point for which to find the closest documents. + - + name: query + type: + - Query + optional: true + description: | + imits 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. diff --git a/generator/config/aggregation-stages/graphLookup.yaml b/generator/config/aggregation-stages/graphLookup.yaml new file mode 100644 index 000000000..a8513b7f4 --- /dev/null +++ b/generator/config/aggregation-stages/graphLookup.yaml @@ -0,0 +1,64 @@ +# $schema: ../schema.json +name: $graphLookup +category: + - Stage +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 + - list + 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. diff --git a/generator/config/aggregation-stages/group.yaml b/generator/config/aggregation-stages/group.yaml new file mode 100644 index 000000000..ec4a618b2 --- /dev/null +++ b/generator/config/aggregation-stages/group.yaml @@ -0,0 +1,24 @@ +# $schema: ../schema.json +name: $group +category: + - Stage +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/group/' +type: + - Stage +encode: group +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 + type: + - Accumulator + variadic: object + description: | + Computed using the accumulator operators. diff --git a/generator/config/aggregation-stages/indexStats.yaml b/generator/config/aggregation-stages/indexStats.yaml new file mode 100644 index 000000000..3d2c9dab6 --- /dev/null +++ b/generator/config/aggregation-stages/indexStats.yaml @@ -0,0 +1,10 @@ +# $schema: ../schema.json +name: $indexStats +category: + - Stage +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. diff --git a/generator/config/aggregation-stages/limit.yaml b/generator/config/aggregation-stages/limit.yaml new file mode 100644 index 000000000..9fb542214 --- /dev/null +++ b/generator/config/aggregation-stages/limit.yaml @@ -0,0 +1,15 @@ +# $schema: ../schema.json +name: $limit +category: + - Stage +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 diff --git a/generator/config/aggregation-stages/listLocalSessions.yaml b/generator/config/aggregation-stages/listLocalSessions.yaml new file mode 100644 index 000000000..7517b93a6 --- /dev/null +++ b/generator/config/aggregation-stages/listLocalSessions.yaml @@ -0,0 +1,25 @@ +# $schema: ../schema.json +name: $listLocalSessions +category: + - Stage +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. diff --git a/generator/config/aggregation-stages/listSampledQueries.yaml b/generator/config/aggregation-stages/listSampledQueries.yaml new file mode 100644 index 000000000..c63cd33e5 --- /dev/null +++ b/generator/config/aggregation-stages/listSampledQueries.yaml @@ -0,0 +1,16 @@ +# $schema: ../schema.json +name: $listSampledQueries +category: + - Stage +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 diff --git a/generator/config/aggregation-stages/listSearchIndexes.yaml b/generator/config/aggregation-stages/listSearchIndexes.yaml new file mode 100644 index 000000000..4cd8f604d --- /dev/null +++ b/generator/config/aggregation-stages/listSearchIndexes.yaml @@ -0,0 +1,25 @@ +# $schema: ../schema.json +name: $listSearchIndexes +category: + - Stage +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. diff --git a/generator/config/aggregation-stages/listSessions.yaml b/generator/config/aggregation-stages/listSessions.yaml new file mode 100644 index 000000000..e854a0982 --- /dev/null +++ b/generator/config/aggregation-stages/listSessions.yaml @@ -0,0 +1,25 @@ +# $schema: ../schema.json +name: $listSessions +category: + - Stage +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. diff --git a/generator/config/aggregation-stages/lookup.yaml b/generator/config/aggregation-stages/lookup.yaml new file mode 100644 index 000000000..aa0e8c991 --- /dev/null +++ b/generator/config/aggregation-stages/lookup.yaml @@ -0,0 +1,56 @@ +# $schema: ../schema.json +name: $lookup +category: + - Stage +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 + 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 $mergestage. 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. diff --git a/generator/config/aggregation-stages/match.yaml b/generator/config/aggregation-stages/match.yaml new file mode 100644 index 000000000..fad43935d --- /dev/null +++ b/generator/config/aggregation-stages/match.yaml @@ -0,0 +1,16 @@ +# $schema: ../schema.json +name: $match +category: + - Stage +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 + variadic: object diff --git a/generator/config/aggregation-stages/merge.yaml b/generator/config/aggregation-stages/merge.yaml new file mode 100644 index 000000000..77b483108 --- /dev/null +++ b/generator/config/aggregation-stages/merge.yaml @@ -0,0 +1,48 @@ +# $schema: ../schema.json +name: $merge +category: + - Stage +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/' +type: + - Stage +encode: object +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 version 4.2. +arguments: + - + name: into + type: + - string + - OutCollection + description: | + The output collection. + - + name: 'on' + type: + - string + - list + 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 + 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. diff --git a/generator/config/aggregation-stages/out.yaml b/generator/config/aggregation-stages/out.yaml new file mode 100644 index 000000000..3d439c9f5 --- /dev/null +++ b/generator/config/aggregation-stages/out.yaml @@ -0,0 +1,29 @@ +# $schema: ../schema.json +name: $out +category: + - Stage +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: db + type: + - string + description: | + Target collection name to write documents from $out to. + - + name: coll + type: + - string + description: | + Target database name to write documents from $out to. + - + name: timeseries + type: + - object + description: | + If set, the aggregation stage will use these options to create or replace a time-series collection in the given namespace. diff --git a/generator/config/aggregation-stages/planCacheStats.yaml b/generator/config/aggregation-stages/planCacheStats.yaml new file mode 100644 index 000000000..d8b52bc97 --- /dev/null +++ b/generator/config/aggregation-stages/planCacheStats.yaml @@ -0,0 +1,10 @@ +# $schema: ../schema.json +name: $planCacheStats +category: + - Stage +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/planCacheStats/' +type: + - Stage +encode: object +description: | + Returns plan cache information for a collection. diff --git a/generator/config/aggregation-stages/project.yaml b/generator/config/aggregation-stages/project.yaml new file mode 100644 index 000000000..6ac6c524d --- /dev/null +++ b/generator/config/aggregation-stages/project.yaml @@ -0,0 +1,18 @@ +# $schema: ../schema.json +name: $project +category: + - Stage +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: + - bool + - int + - expression + variadic: object diff --git a/generator/config/aggregation-stages/redact.yaml b/generator/config/aggregation-stages/redact.yaml new file mode 100644 index 000000000..e6dfc1223 --- /dev/null +++ b/generator/config/aggregation-stages/redact.yaml @@ -0,0 +1,15 @@ +# $schema: ../schema.json +name: $redact +category: + - Stage +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 diff --git a/generator/config/aggregation-stages/replaceRoot.yaml b/generator/config/aggregation-stages/replaceRoot.yaml new file mode 100644 index 000000000..da09d784b --- /dev/null +++ b/generator/config/aggregation-stages/replaceRoot.yaml @@ -0,0 +1,15 @@ +# $schema: ../schema.json +name: $replaceRoot +category: + - Stage +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 diff --git a/generator/config/aggregation-stages/replaceWith.yaml b/generator/config/aggregation-stages/replaceWith.yaml new file mode 100644 index 000000000..95e9e2d6e --- /dev/null +++ b/generator/config/aggregation-stages/replaceWith.yaml @@ -0,0 +1,16 @@ +# $schema: ../schema.json +name: $replaceWith +category: + - Stage +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceWith/' +type: + - Stage +encode: single +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 diff --git a/generator/config/aggregation-stages/sample.yaml b/generator/config/aggregation-stages/sample.yaml new file mode 100644 index 000000000..347869768 --- /dev/null +++ b/generator/config/aggregation-stages/sample.yaml @@ -0,0 +1,17 @@ +# $schema: ../schema.json +name: $sample +category: + - Stage +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. diff --git a/generator/config/aggregation-stages/search.yaml b/generator/config/aggregation-stages/search.yaml new file mode 100644 index 000000000..3664e418b --- /dev/null +++ b/generator/config/aggregation-stages/search.yaml @@ -0,0 +1,16 @@ +# $schema: ../schema.json +name: $search +category: + - Stage +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/search/' +type: + - Stage +encode: single +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: search + type: + - object diff --git a/generator/config/aggregation-stages/searchMeta.yaml b/generator/config/aggregation-stages/searchMeta.yaml new file mode 100644 index 000000000..97beabdab --- /dev/null +++ b/generator/config/aggregation-stages/searchMeta.yaml @@ -0,0 +1,16 @@ +# $schema: ../schema.json +name: $searchMeta +category: + - Stage +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/searchMeta/' +type: + - Stage +encode: single +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: meta + type: + - object diff --git a/generator/config/aggregation-stages/set.yaml b/generator/config/aggregation-stages/set.yaml new file mode 100644 index 000000000..48984ae7f --- /dev/null +++ b/generator/config/aggregation-stages/set.yaml @@ -0,0 +1,17 @@ +# $schema: ../schema.json +name: $set +category: + - Stage +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/set/' +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. + Alias for $addFields. +arguments: + - + name: field + type: + - expression + variadic: object diff --git a/generator/config/aggregation-stages/setWindowFields.yaml b/generator/config/aggregation-stages/setWindowFields.yaml new file mode 100644 index 000000000..6670d8f1c --- /dev/null +++ b/generator/config/aggregation-stages/setWindowFields.yaml @@ -0,0 +1,38 @@ +# $schema: ../schema.json +name: $setWindowFields +category: + - Stage +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/setWindowFields/' +type: + - Stage +encode: object +description: | + Groups documents into windows and applies one or more operators to the documents in each window. + New in version 5.0. +arguments: + - + 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. + - + name: sortBy + type: + - SortSpec + 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: window + type: + - Window + optional: true + description: | + Specifies the window boundaries and parameters. Window boundaries are inclusive. Default is an unbounded window, which includes all documents in the partition. diff --git a/generator/config/aggregation-stages/shardedDataDistribution.yaml b/generator/config/aggregation-stages/shardedDataDistribution.yaml new file mode 100644 index 000000000..aa6925748 --- /dev/null +++ b/generator/config/aggregation-stages/shardedDataDistribution.yaml @@ -0,0 +1,11 @@ +# $schema: ../schema.json +name: $shardedDataDistribution +category: + - Stage +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/shardedDataDistribution/' +type: + - Stage +encode: object +description: | + Provides data and size distribution information on sharded collections. + New in version 6.0.3. diff --git a/generator/config/aggregation-stages/skip.yaml b/generator/config/aggregation-stages/skip.yaml new file mode 100644 index 000000000..29d1fdb7a --- /dev/null +++ b/generator/config/aggregation-stages/skip.yaml @@ -0,0 +1,15 @@ +# $schema: ../schema.json +name: $skip +category: + - Stage +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 diff --git a/generator/config/aggregation-stages/sort.yaml b/generator/config/aggregation-stages/sort.yaml new file mode 100644 index 000000000..ce2dd0039 --- /dev/null +++ b/generator/config/aggregation-stages/sort.yaml @@ -0,0 +1,15 @@ +# $schema: ../schema.json +name: $sort +category: + - Stage +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: + - SortSpec diff --git a/generator/config/aggregation-stages/sortByCount.yaml b/generator/config/aggregation-stages/sortByCount.yaml new file mode 100644 index 000000000..d9925574b --- /dev/null +++ b/generator/config/aggregation-stages/sortByCount.yaml @@ -0,0 +1,15 @@ +# $schema: ../schema.json +name: $sortByCount +category: + - Stage +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/sortByCount/' +type: + - Stage +encode: object +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 diff --git a/generator/config/aggregation-stages/unionWith.yaml b/generator/config/aggregation-stages/unionWith.yaml new file mode 100644 index 000000000..fb4658b74 --- /dev/null +++ b/generator/config/aggregation-stages/unionWith.yaml @@ -0,0 +1,26 @@ +# $schema: ../schema.json +name: $unionWith +category: + - Stage +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/unionWith/' +type: + - Stage +encode: object +description: | + Performs a union of two collections; i.e. combines pipeline results from two collections into a single result set. + New in version 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. diff --git a/generator/config/aggregation-stages/unset.yaml b/generator/config/aggregation-stages/unset.yaml new file mode 100644 index 000000000..df2b6f1b7 --- /dev/null +++ b/generator/config/aggregation-stages/unset.yaml @@ -0,0 +1,17 @@ +# $schema: ../schema.json +name: $unset +category: + - Stage +link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/unset/' +type: + - Stage +encode: single +description: | + Removes or excludes fields from documents. + Alias for $project stage that removes or excludes fields. +arguments: + - + name: field + type: + - FieldPath + variadic: array diff --git a/generator/config/aggregation-stages/unwind.yaml b/generator/config/aggregation-stages/unwind.yaml new file mode 100644 index 000000000..23a7553d0 --- /dev/null +++ b/generator/config/aggregation-stages/unwind.yaml @@ -0,0 +1,15 @@ +# $schema: ../schema.json +name: $unwind +category: + - Stage +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: field + type: + - ArrayFieldPath diff --git a/generator/config/aggregation.md b/generator/config/aggregation.md new file mode 100644 index 000000000..11920554b --- /dev/null +++ b/generator/config/aggregation.md @@ -0,0 +1,34 @@ +Name +Description +$abs +Returns the absolute value of a number. +$add +Adds numbers to return the sum, or adds numbers and a date to return a new date. If adding numbers and a date, treats the numbers as milliseconds. Accepts any number of argument expressions, but at most, one expression can resolve to a date. +$ceil +Returns the smallest integer greater than or equal to the specified number. +$divide +Returns the result of dividing the first number by the second. Accepts two argument expressions. +$exp +Raises e to the specified exponent. +$floor +Returns the largest integer less than or equal to the specified number. +$ln +Calculates the natural log of a number. +$log +Calculates the log of a number in the specified base. +$log10 +Calculates the log base 10 of a number. +$mod +Returns the remainder of the first number divided by the second. Accepts two argument expressions. +$multiply +Multiplies numbers to return the product. Accepts any number of argument expressions. +$pow +Raises a number to the specified exponent. +$round +Rounds a number to to a whole integer or to a specified decimal place. +$sqrt +Calculates the square root. +$subtract +Returns the result of subtracting the second value from the first. If the two values are numbers, return the difference. If the two values are dates, return the difference in milliseconds. If the two values are a date and a number in milliseconds, return the resulting date. Accepts two argument expressions. If the two values are a date and a number, specify the date argument first as it is not meaningful to subtract a date from a number. +$trunc +Truncates a number to a whole integer or to a specified decimal place. diff --git a/generator/config/expressions.php b/generator/config/expressions.php index 5e8a6b5d3..d1f70c144 100644 --- a/generator/config/expressions.php +++ b/generator/config/expressions.php @@ -5,6 +5,9 @@ namespace MongoDB\Builder\Expression; use MongoDB\BSON; +use MongoDB\Builder\Aggregation\AccumulatorInterface; +use MongoDB\Builder\Pipeline; +use MongoDB\Builder\Query\QueryInterface; use MongoDB\Model\BSONArray; use stdClass; @@ -20,14 +23,44 @@ function typeFieldPath(string $resolvesTo): array } return [ + 'mixed' => ['scalar' => true, 'types' => ['mixed']], 'null' => ['scalar' => true, 'types' => ['null']], 'int' => ['scalar' => true, 'types' => ['int', BSON\Int64::class]], 'double' => ['scalar' => true, 'types' => ['int', BSON\Int64::class, 'float']], + 'float' => ['scalar' => true, 'types' => ['int', BSON\Int64::class, 'float']], 'decimal' => ['scalar' => true, 'types' => ['int', BSON\Int64::class, 'float', BSON\Decimal128::class]], 'number' => ['scalar' => true, 'types' => ['int', BSON\Int64::class, 'float', BSON\Decimal128::class]], 'string' => ['scalar' => true, 'types' => ['string']], - 'boolean' => ['scalar' => true, 'types' => ['bool']], + 'bool' => ['scalar' => true, 'types' => ['bool']], 'object' => ['scalar' => true, 'types' => ['array', 'object', BSON\Document::class, BSON\Serializable::class]], + 'Regex' => ['scalar' => true, 'types' => [BSON\Regex::class]], + 'Constant' => ['scalar' => true, 'types' => ['mixed']], + 'Binary' => ['scalar' => true, 'types' => ['string', BSON\Binary::class]], + + AccumulatorInterface::class => ['scalar' => true, 'types' => [AccumulatorInterface::class]], + QueryInterface::class => ['scalar' => true, 'types' => [QueryInterface::class, 'array', 'object']], + + // @todo merge this types + 'list' => ['scalar' => true, 'types' => ['list', BSONArray::class, BSON\PackedArray::class]], + 'array' => ['scalar' => true, 'types' => ['list', BSONArray::class, BSON\PackedArray::class]], + + // @todo fine-tune all this types + 'Granularity' => ['scalar' => true, 'types' => ['string']], + 'FullDocument' => ['scalar' => true, 'types' => ['string']], + 'FullDocumentBeforeChange' => ['scalar' => true, 'types' => ['string']], + 'AccumulatorPercentile' => ['scalar' => true, 'types' => ['string']], + 'Timestamp' => ['scalar' => true, 'types' => ['int']], + 'CollStats' => ['scalar' => true, 'types' => ['object', 'array']], + 'Range' => ['scalar' => true, 'types' => ['object', 'array']], + 'FillOut' => ['scalar' => true, 'types' => ['object', 'array']], + 'WhenMatched' => ['scalar' => true, 'types' => ['string']], + 'WhenNotMatched' => ['scalar' => true, 'types' => ['string']], + 'OutCollection' => ['scalar' => true, 'types' => ['string', 'object', 'array']], + 'Pipeline' => ['scalar' => true, 'types' => [Pipeline::class, 'array']], + 'SortSpec' => ['scalar' => true, 'types' => ['object', 'array']], + 'Window' => ['scalar' => true, 'types' => ['object', 'array']], + 'GeoPoint' => ['scalar' => true, 'types' => ['object', 'array']], + 'Geometry' => ['scalar' => true, 'types' => ['object', 'array']], // Use Interface suffix to avoid confusion with MongoDB\Builder\Expression factory class ExpressionInterface::class => [ @@ -81,6 +114,16 @@ function typeFieldPath(string $resolvesTo): array 'types' => ['DateTimeInterface', 'UTCDateTime'], ], DateFieldPath::class => typeFieldPath(ResolvesToDate::class), + ResolvesToTimestamp::class => [ + 'implements' => [ResolvesToInt::class], + 'types' => ['int', BSON\Int64::class], + ], + TimestampFieldPath::class => typeFieldPath(ResolvesToTimestamp::class), + ResolvesToObjectId::class => [ + 'implements' => [ExpressionInterface::class], + 'types' => [BSON\ObjectId::class], + ], + ObjectIdFieldPath::class => typeFieldPath(ResolvesToObjectId::class), ResolvesToObject::class => [ 'implements' => [ExpressionInterface::class], 'types' => ['array', 'object', BSON\Document::class, BSON\Serializable::class], @@ -101,6 +144,11 @@ function typeFieldPath(string $resolvesTo): array 'types' => ['int', 'float', BSON\Int64::class, BSON\Decimal128::class], ], DecimalFieldPath::class => typeFieldPath(ResolvesToDecimal::class), + ResolvesToDouble::class => [ + 'implements' => [ResolvesToNumber::class], + 'types' => ['int', BSON\Int64::class, 'float'], + ], + DoubleFieldPath::class => typeFieldPath(ResolvesToDouble::class), ResolvesToFloat::class => [ 'implements' => [ResolvesToNumber::class], 'types' => ['int', 'float', BSON\Int64::class], @@ -111,9 +159,19 @@ function typeFieldPath(string $resolvesTo): array 'types' => ['int', BSON\Int64::class], ], IntFieldPath::class => typeFieldPath(ResolvesToInt::class), + ResolvesToLong::class => [ + 'implements' => [ResolvesToNumber::class], + 'types' => ['int', BSON\Int64::class], + ], + LongFieldPath::class => typeFieldPath(ResolvesToLong::class), ResolvesToString::class => [ 'implements' => [ExpressionInterface::class], 'types' => ['string'], ], StringFieldPath::class => typeFieldPath(ResolvesToString::class), + ResolvesToBinary::class => [ + 'implements' => [ExpressionInterface::class], + 'types' => ['string', BSON\Binary::class], + ], + BinaryFieldPath::class => typeFieldPath(ResolvesToBinary::class), ]; diff --git a/generator/config/operators.php b/generator/config/operators.php index e9d1583e2..5ea99a850 100644 --- a/generator/config/operators.php +++ b/generator/config/operators.php @@ -8,7 +8,7 @@ return [ // Aggregation Pipeline Stages [ - 'configFile' => __DIR__ . '/stages.yaml', + 'configFiles' => __DIR__ . '/aggregation-stages', 'namespace' => 'MongoDB\\Builder\\Stage', 'classNameSuffix' => 'Stage', 'generators' => [ @@ -19,7 +19,7 @@ // Aggregation Pipeline Operators [ - 'configFile' => __DIR__ . '/pipeline-operators.yaml', + 'configFiles' => __DIR__ . '/aggregation-operators', 'namespace' => 'MongoDB\\Builder\\Aggregation', 'classNameSuffix' => 'Aggregation', 'generators' => [ @@ -30,7 +30,7 @@ // Query Operators [ - 'configFile' => __DIR__ . '/query-operators.yaml', + 'configFiles' => __DIR__ . '/query-operators', 'namespace' => 'MongoDB\\Builder\\Query', 'classNameSuffix' => 'Query', 'generators' => [ diff --git a/generator/config/pipeline-operators.yaml b/generator/config/pipeline-operators.yaml deleted file mode 100644 index 9e2af1fc8..000000000 --- a/generator/config/pipeline-operators.yaml +++ /dev/null @@ -1,92 +0,0 @@ -- name: and - type: resolvesToBool - args: - - name: expressions - type: expression - isVariadic: true - variadicMin: 1 -- name: eq - encode: array - type: resolvesToBool - args: - - name: expression1 - type: expression - - name: expression2 - type: expression -- name: gt - encode: array - type: resolvesToBool - args: - - name: expression1 - type: expression - - name: expression2 - type: expression -- name: gte - encode: array - type: resolvesToBool - args: - - name: expression1 - type: expression - - name: expression2 - type: expression -- name: lt - encode: array - type: resolvesToBool - args: - - name: expression1 - type: expression - - name: expression2 - type: expression -- name: ne - encode: array - type: resolvesToBool - args: - - name: expression1 - type: expression - - name: expression2 - type: expression -- name: filter - encode: object - type: resolvesToArray - args: - - name: input - type: resolvesToArray - - name: cond - type: resolvesToBool - - name: as - type: resolvesToString - isOptional: true - - name: limit - type: resolvesToInt - isOptional: true -- name: sum - type: resolvesToInt - args: - - name: expression - type: expression -- name: min - type: expression - args: - - name: expression - type: expression -- name: max - type: expression - args: - - name: expression - type: expression -- name: subtract - type: expression - encode: array - args: - - name: expression1 - type: expression - - name: expression2 - type: expression -- name: mod - type: expression - encode: array - args: - - name: expression1 - type: expression - - name: expression2 - type: expression diff --git a/generator/config/query-operators.yaml b/generator/config/query-operators.yaml deleted file mode 100644 index 433038f3f..000000000 --- a/generator/config/query-operators.yaml +++ /dev/null @@ -1,32 +0,0 @@ -- name: and - type: resolvesToBool - args: - - name: query - type: resolvesToBool - isVariadic: true -- name: or - type: resolvesToBool - args: - - name: query - type: expression - isVariadic: true -- name: expr - type: expression - args: - - name: expression - type: expression -- name: gt - type: resolvesToBool - args: - - name: value - type: expression -- name: lt - type: resolvesToBool - args: - - name: value - type: expression -- name: gte - type: resolvesToBool - args: - - name: value - type: expression diff --git a/generator/config/query-operators/all.yaml b/generator/config/query-operators/all.yaml new file mode 100644 index 000000000..3235e1046 --- /dev/null +++ b/generator/config/query-operators/all.yaml @@ -0,0 +1,16 @@ +# $schema: ../schema.json +name: $all +category: + - 'Array Query Operators' +link: 'https://www.mongodb.com/docs/manual/reference/operator/query/all/' +type: + - Query +encode: single +description: | + Matches arrays that contain all elements specified in the query. +arguments: + - + name: value + type: + - mixed + variadic: array diff --git a/generator/config/query-operators/and.yaml b/generator/config/query-operators/and.yaml new file mode 100644 index 000000000..7fc8b2239 --- /dev/null +++ b/generator/config/query-operators/and.yaml @@ -0,0 +1,16 @@ +# $schema: ../schema.json +name: $and +category: + - 'Logical Query Operators' +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: expression + type: + - Query + variadic: array diff --git a/generator/config/query-operators/bitsAllClear.yaml b/generator/config/query-operators/bitsAllClear.yaml new file mode 100644 index 000000000..cfbcff655 --- /dev/null +++ b/generator/config/query-operators/bitsAllClear.yaml @@ -0,0 +1,17 @@ +# $schema: ../schema.json +name: $bitsAllClear +category: + - 'Bitwise Query Operators' +link: 'https://www.mongodb.com/docs/manual/reference/operator/query/bitsAllClear/' +type: + - Query +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 + - Binary + - list diff --git a/generator/config/query-operators/bitsAllSet.yaml b/generator/config/query-operators/bitsAllSet.yaml new file mode 100644 index 000000000..49a0cdeb3 --- /dev/null +++ b/generator/config/query-operators/bitsAllSet.yaml @@ -0,0 +1,17 @@ +# $schema: ../schema.json +name: $bitsAllSet +category: + - 'Bitwise Query Operators' +link: 'https://www.mongodb.com/docs/manual/reference/operator/query/bitsAllSet/' +type: + - Query +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 + - Binary + - list diff --git a/generator/config/query-operators/bitsAnyClear.yaml b/generator/config/query-operators/bitsAnyClear.yaml new file mode 100644 index 000000000..64b7bc7ae --- /dev/null +++ b/generator/config/query-operators/bitsAnyClear.yaml @@ -0,0 +1,17 @@ +# $schema: ../schema.json +name: $bitsAnyClear +category: + - 'Bitwise Query Operators' +link: 'https://www.mongodb.com/docs/manual/reference/operator/query/bitsAnyClear/' +type: + - Query +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 + - Binary + - list diff --git a/generator/config/query-operators/bitsAnySet.yaml b/generator/config/query-operators/bitsAnySet.yaml new file mode 100644 index 000000000..d06ae1b19 --- /dev/null +++ b/generator/config/query-operators/bitsAnySet.yaml @@ -0,0 +1,17 @@ +# $schema: ../schema.json +name: $bitsAnySet +category: + - 'Bitwise Query Operators' +link: 'https://www.mongodb.com/docs/manual/reference/operator/query/bitsAnySet/' +type: + - Query +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 + - Binary + - list diff --git a/generator/config/query-operators/box.yaml b/generator/config/query-operators/box.yaml new file mode 100644 index 000000000..b026177c0 --- /dev/null +++ b/generator/config/query-operators/box.yaml @@ -0,0 +1,15 @@ +# $schema: ../schema.json +name: $box +category: + - 'Geospatial Geometry Specifiers' +link: 'https://www.mongodb.com/docs/manual/reference/operator/query/box/' +type: + - Query +encode: single +description: | + Specifies a rectangular box using legacy coordinate pairs for $geoWithin queries. The 2d index supports $box. +arguments: + - + name: value + type: + - array diff --git a/generator/config/query-operators/center.yaml b/generator/config/query-operators/center.yaml new file mode 100644 index 000000000..9b7b1b50f --- /dev/null +++ b/generator/config/query-operators/center.yaml @@ -0,0 +1,15 @@ +# $schema: ../schema.json +name: $center +category: + - 'Geospatial Geometry Specifiers' +link: 'https://www.mongodb.com/docs/manual/reference/operator/query/center/' +type: + - Query +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 diff --git a/generator/config/query-operators/centerSphere.yaml b/generator/config/query-operators/centerSphere.yaml new file mode 100644 index 000000000..7c0f2560a --- /dev/null +++ b/generator/config/query-operators/centerSphere.yaml @@ -0,0 +1,15 @@ +# $schema: ../schema.json +name: $centerSphere +category: + - 'Geospatial Geometry Specifiers' +link: 'https://www.mongodb.com/docs/manual/reference/operator/query/centerSphere/' +type: + - Query +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 diff --git a/generator/config/query-operators/comment.yaml b/generator/config/query-operators/comment.yaml new file mode 100644 index 000000000..6ec1a93da --- /dev/null +++ b/generator/config/query-operators/comment.yaml @@ -0,0 +1,15 @@ +# $schema: ../schema.json +name: $comment +category: + - 'Miscellaneous Query Operators' +link: 'https://www.mongodb.com/docs/manual/reference/operator/query/comment/' +type: + - expression +encode: single +description: | + Adds a comment to a query predicate. +arguments: + - + name: comment + type: + - string diff --git a/generator/config/query-operators/elemMatch.yaml b/generator/config/query-operators/elemMatch.yaml new file mode 100644 index 000000000..09913c5bb --- /dev/null +++ b/generator/config/query-operators/elemMatch.yaml @@ -0,0 +1,15 @@ +# $schema: ../schema.json +name: $elemMatch +category: + - 'Projection Operators' +link: 'https://www.mongodb.com/docs/manual/reference/operator/query/elemMatch/' +type: + - Query +encode: object +description: | + Projects the first element in an array that matches the specified $elemMatch condition. +arguments: + - + name: queries + type: + - object diff --git a/generator/config/query-operators/eq.yaml b/generator/config/query-operators/eq.yaml new file mode 100644 index 000000000..44343af19 --- /dev/null +++ b/generator/config/query-operators/eq.yaml @@ -0,0 +1,15 @@ +# $schema: ../schema.json +name: $eq +category: + - 'Comparison Query Operators' +link: 'https://www.mongodb.com/docs/manual/reference/operator/query/eq/' +type: + - Query +encode: single +description: | + Matches values that are equal to a specified value. +arguments: + - + name: value + type: + - Constant diff --git a/generator/config/query-operators/exists.yaml b/generator/config/query-operators/exists.yaml new file mode 100644 index 000000000..f5bd2b6e1 --- /dev/null +++ b/generator/config/query-operators/exists.yaml @@ -0,0 +1,15 @@ +# $schema: ../schema.json +name: $exists +category: + - 'Element Query Operators' +link: 'https://www.mongodb.com/docs/manual/reference/operator/query/exists/' +type: + - Query +encode: single +description: | + Matches documents that have the specified field. +arguments: + - + name: exists + type: + - bool diff --git a/generator/config/query-operators/expr.yaml b/generator/config/query-operators/expr.yaml new file mode 100644 index 000000000..1c5125d34 --- /dev/null +++ b/generator/config/query-operators/expr.yaml @@ -0,0 +1,15 @@ +# $schema: ../schema.json +name: $expr +category: + - 'Evaluation Query Operators' +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 diff --git a/generator/config/query-operators/geoIntersects.yaml b/generator/config/query-operators/geoIntersects.yaml new file mode 100644 index 000000000..45daa4325 --- /dev/null +++ b/generator/config/query-operators/geoIntersects.yaml @@ -0,0 +1,15 @@ +# $schema: ../schema.json +name: $geoIntersects +category: + - 'Geospatial Query Selectors' +link: 'https://www.mongodb.com/docs/manual/reference/operator/query/geoIntersects/' +type: + - Query +encode: single +description: | + Selects geometries that intersect with a GeoJSON geometry. The 2dsphere index supports $geoIntersects. +arguments: + - + name: geometry + type: + - Geometry diff --git a/generator/config/query-operators/geoWithin.yaml b/generator/config/query-operators/geoWithin.yaml new file mode 100644 index 000000000..400963854 --- /dev/null +++ b/generator/config/query-operators/geoWithin.yaml @@ -0,0 +1,15 @@ +# $schema: ../schema.json +name: $geoWithin +category: + - 'Geospatial Query Selectors' +link: 'https://www.mongodb.com/docs/manual/reference/operator/query/geoWithin/' +type: + - Query +encode: single +description: | + Selects geometries within a bounding GeoJSON geometry. The 2dsphere and 2d indexes support $geoWithin. +arguments: + - + name: geometry + type: + - Geometry diff --git a/generator/config/query-operators/geometry.yaml b/generator/config/query-operators/geometry.yaml new file mode 100644 index 000000000..2bcfcc6a9 --- /dev/null +++ b/generator/config/query-operators/geometry.yaml @@ -0,0 +1,23 @@ +# $schema: ../schema.json +name: $geometry +category: + - 'Geospatial Geometry Specifiers' +link: 'https://www.mongodb.com/docs/manual/reference/operator/query/geometry/' +type: + - expression +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 diff --git a/generator/config/query-operators/gt.yaml b/generator/config/query-operators/gt.yaml new file mode 100644 index 000000000..4043d7d57 --- /dev/null +++ b/generator/config/query-operators/gt.yaml @@ -0,0 +1,15 @@ +# $schema: ../schema.json +name: $gt +category: + - 'Comparison Query Operators' +link: 'https://www.mongodb.com/docs/manual/reference/operator/query/gt/' +type: + - Query +encode: single +description: | + Matches values that are greater than a specified value. +arguments: + - + name: value + type: + - Constant diff --git a/generator/config/query-operators/gte.yaml b/generator/config/query-operators/gte.yaml new file mode 100644 index 000000000..6125656c4 --- /dev/null +++ b/generator/config/query-operators/gte.yaml @@ -0,0 +1,15 @@ +# $schema: ../schema.json +name: $gte +category: + - 'Comparison Query Operators' +link: 'https://www.mongodb.com/docs/manual/reference/operator/query/gte/' +type: + - Query +encode: single +description: | + Matches values that are greater than or equal to a specified value. +arguments: + - + name: value + type: + - Constant diff --git a/generator/config/query-operators/in.yaml b/generator/config/query-operators/in.yaml new file mode 100644 index 000000000..53855e0d5 --- /dev/null +++ b/generator/config/query-operators/in.yaml @@ -0,0 +1,15 @@ +# $schema: ../schema.json +name: $in +category: + - 'Comparison Query Operators' +link: 'https://www.mongodb.com/docs/manual/reference/operator/query/in/' +type: + - Query +encode: single +description: | + Matches any of the values specified in an array. +arguments: + - + name: value + type: + - Constant diff --git a/generator/config/query-operators/jsonSchema.yaml b/generator/config/query-operators/jsonSchema.yaml new file mode 100644 index 000000000..1c7080062 --- /dev/null +++ b/generator/config/query-operators/jsonSchema.yaml @@ -0,0 +1,15 @@ +# $schema: ../schema.json +name: $jsonSchema +category: + - 'Evaluation Query Operators' +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 diff --git a/generator/config/query-operators/lt.yaml b/generator/config/query-operators/lt.yaml new file mode 100644 index 000000000..b2430688e --- /dev/null +++ b/generator/config/query-operators/lt.yaml @@ -0,0 +1,15 @@ +# $schema: ../schema.json +name: $lt +category: + - 'Comparison Query Operators' +link: 'https://www.mongodb.com/docs/manual/reference/operator/query/lt/' +type: + - Query +encode: single +description: | + Matches values that are less than a specified value. +arguments: + - + name: value + type: + - Constant diff --git a/generator/config/query-operators/lte.yaml b/generator/config/query-operators/lte.yaml new file mode 100644 index 000000000..35ac93ad9 --- /dev/null +++ b/generator/config/query-operators/lte.yaml @@ -0,0 +1,15 @@ +# $schema: ../schema.json +name: $lte +category: + - 'Comparison Query Operators' +link: 'https://www.mongodb.com/docs/manual/reference/operator/query/lte/' +type: + - Query +encode: single +description: | + Matches values that are less than or equal to a specified value. +arguments: + - + name: value + type: + - Constant diff --git a/generator/config/query-operators/maxDistance.yaml b/generator/config/query-operators/maxDistance.yaml new file mode 100644 index 000000000..31fcdad34 --- /dev/null +++ b/generator/config/query-operators/maxDistance.yaml @@ -0,0 +1,16 @@ +# $schema: ../schema.json +name: $maxDistance +category: + - 'Geospatial Geometry Specifiers' +link: 'https://www.mongodb.com/docs/manual/reference/operator/query/maxDistance/' +type: + - Query +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: + - int + - float diff --git a/generator/config/query-operators/meta.yaml b/generator/config/query-operators/meta.yaml new file mode 100644 index 000000000..c275157e5 --- /dev/null +++ b/generator/config/query-operators/meta.yaml @@ -0,0 +1,10 @@ +# $schema: ../schema.json +name: $meta +category: + - 'Projection Operators' +link: 'https://www.mongodb.com/docs/manual/reference/operator/query/meta/' +type: + - expression +encode: object +description: | + Projects the available per-document metadata. diff --git a/generator/config/query-operators/minDistance.yaml b/generator/config/query-operators/minDistance.yaml new file mode 100644 index 000000000..d39e641dc --- /dev/null +++ b/generator/config/query-operators/minDistance.yaml @@ -0,0 +1,16 @@ +# $schema: ../schema.json +name: $minDistance +category: + - 'Geospatial Geometry Specifiers' +link: 'https://www.mongodb.com/docs/manual/reference/operator/query/minDistance/' +type: + - Query +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 + - float diff --git a/generator/config/query-operators/mod.yaml b/generator/config/query-operators/mod.yaml new file mode 100644 index 000000000..516a6dac5 --- /dev/null +++ b/generator/config/query-operators/mod.yaml @@ -0,0 +1,19 @@ +# $schema: ../schema.json +name: $mod +category: + - 'Evaluation Query Operators' +link: 'https://www.mongodb.com/docs/manual/reference/operator/query/mod/' +type: + - Query +encode: array +description: | + Performs a modulo operation on the value of a field and selects documents with a specified result. +arguments: + - + name: divisor + type: + - int + - + name: remainder + type: + - int diff --git a/generator/config/query-operators/natural.yaml b/generator/config/query-operators/natural.yaml new file mode 100644 index 000000000..91c92c5d2 --- /dev/null +++ b/generator/config/query-operators/natural.yaml @@ -0,0 +1,10 @@ +# $schema: ../schema.json +name: $natural +category: + - 'Miscellaneous Query Operators' +link: 'https://www.mongodb.com/docs/v7.0/reference/operator/meta/natural/' +type: + - expression +encode: object +description: | + A special hint that can be provided via the sort() or hint() methods that can be used to force either a forward or reverse collection scan. diff --git a/generator/config/query-operators/ne.yaml b/generator/config/query-operators/ne.yaml new file mode 100644 index 000000000..b8510c57c --- /dev/null +++ b/generator/config/query-operators/ne.yaml @@ -0,0 +1,15 @@ +# $schema: ../schema.json +name: $ne +category: + - 'Comparison Query Operators' +link: 'https://www.mongodb.com/docs/manual/reference/operator/query/ne/' +type: + - Query +encode: single +description: | + Matches all values that are not equal to a specified value. +arguments: + - + name: value + type: + - Constant diff --git a/generator/config/query-operators/near.yaml b/generator/config/query-operators/near.yaml new file mode 100644 index 000000000..d0687abc9 --- /dev/null +++ b/generator/config/query-operators/near.yaml @@ -0,0 +1,29 @@ +# $schema: ../schema.json +name: $near +category: + - 'Geospatial Query Selectors' +link: 'https://www.mongodb.com/docs/manual/reference/operator/query/near/' +type: + - Query +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 + type: + - Geometry + - + name: maxDistance + type: + - int + 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: + - int + optional: true + description: | + Distance in meters. Limits the results to those documents that are at least the specified distance from the center point. diff --git a/generator/config/query-operators/nearSphere.yaml b/generator/config/query-operators/nearSphere.yaml new file mode 100644 index 000000000..5e86f9f03 --- /dev/null +++ b/generator/config/query-operators/nearSphere.yaml @@ -0,0 +1,29 @@ +# $schema: ../schema.json +name: $nearSphere +category: + - 'Geospatial Query Selectors' +link: 'https://www.mongodb.com/docs/manual/reference/operator/query/nearSphere/' +type: + - Query +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 + type: + - Geometry + - + name: maxDistance + type: + - int + optional: true + description: | + Distance in meters. + - + name: minDistance + type: + - int + optional: true + description: | + Distance in meters. Limits the results to those documents that are at least the specified distance from the center point. diff --git a/generator/config/query-operators/nin.yaml b/generator/config/query-operators/nin.yaml new file mode 100644 index 000000000..adec8b789 --- /dev/null +++ b/generator/config/query-operators/nin.yaml @@ -0,0 +1,15 @@ +# $schema: ../schema.json +name: $nin +category: + - 'Comparison Query Operators' +link: 'https://www.mongodb.com/docs/manual/reference/operator/query/nin/' +type: + - Query +encode: single +description: | + Matches none of the values specified in an array. +arguments: + - + name: value + type: + - Constant diff --git a/generator/config/query-operators/nor.yaml b/generator/config/query-operators/nor.yaml new file mode 100644 index 000000000..440d9f9b6 --- /dev/null +++ b/generator/config/query-operators/nor.yaml @@ -0,0 +1,16 @@ +# $schema: ../schema.json +name: $nor +category: + - 'Logical Query Operators' +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: expression + type: + - Query + variadic: array diff --git a/generator/config/query-operators/not.yaml b/generator/config/query-operators/not.yaml new file mode 100644 index 000000000..f9a3d6779 --- /dev/null +++ b/generator/config/query-operators/not.yaml @@ -0,0 +1,15 @@ +# $schema: ../schema.json +name: $not +category: + - 'Logical Query Operators' +link: 'https://www.mongodb.com/docs/manual/reference/operator/query/not/' +type: + - Query +encode: single +description: | + Inverts the effect of a query expression and returns documents that do not match the query expression. +arguments: + - + name: expression + type: + - Query diff --git a/generator/config/query-operators/or.yaml b/generator/config/query-operators/or.yaml new file mode 100644 index 000000000..c16ba5297 --- /dev/null +++ b/generator/config/query-operators/or.yaml @@ -0,0 +1,16 @@ +# $schema: ../schema.json +name: $or +category: + - 'Logical Query Operators' +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: expression + type: + - Query + variadic: array diff --git a/generator/config/query-operators/polygon.yaml b/generator/config/query-operators/polygon.yaml new file mode 100644 index 000000000..6f2e54c36 --- /dev/null +++ b/generator/config/query-operators/polygon.yaml @@ -0,0 +1,15 @@ +# $schema: ../schema.json +name: $polygon +category: + - 'Geospatial Geometry Specifiers' +link: 'https://www.mongodb.com/docs/manual/reference/operator/query/polygon/' +type: + - Query +encode: single +description: | + Specifies a polygon to using legacy coordinate pairs for $geoWithin queries. The 2d index supports $center. +arguments: + - + name: points + type: + - array diff --git a/generator/config/query-operators/positional.yaml b/generator/config/query-operators/positional.yaml new file mode 100644 index 000000000..da807eb21 --- /dev/null +++ b/generator/config/query-operators/positional.yaml @@ -0,0 +1,10 @@ +# $schema: ../schema.json +name: $ +category: + - 'Projection Operators' +link: 'https://www.mongodb.com/docs/manual/reference/operator/projection/positional/' +type: + - Query +encode: object +description: | + Projects the first element in an array that matches the query condition. diff --git a/generator/config/query-operators/rand.yaml b/generator/config/query-operators/rand.yaml new file mode 100644 index 000000000..d2587119b --- /dev/null +++ b/generator/config/query-operators/rand.yaml @@ -0,0 +1,10 @@ +# $schema: ../schema.json +name: $rand +category: + - 'Miscellaneous Query Operators' +link: 'https://www.mongodb.com/docs/manual/reference/operator/query/rand/' +type: + - expression +encode: object +description: | + Generates a random float between 0 and 1. diff --git a/generator/config/query-operators/regex.yaml b/generator/config/query-operators/regex.yaml new file mode 100644 index 000000000..29a79ae4b --- /dev/null +++ b/generator/config/query-operators/regex.yaml @@ -0,0 +1,15 @@ +# $schema: ../schema.json +name: $regex +category: + - 'Evaluation Query Operators' +link: 'https://www.mongodb.com/docs/manual/reference/operator/query/regex/' +type: + - Query +encode: single +description: | + Selects documents where values match a specified regular expression. +arguments: + - + name: regex + type: + - Regex diff --git a/generator/config/query-operators/size.yaml b/generator/config/query-operators/size.yaml new file mode 100644 index 000000000..2d71416fa --- /dev/null +++ b/generator/config/query-operators/size.yaml @@ -0,0 +1,15 @@ +# $schema: ../schema.json +name: $size +category: + - 'Array Query Operators' +link: 'https://www.mongodb.com/docs/manual/reference/operator/query/size/' +type: + - Query +encode: single +description: | + Selects documents if the array field is a specified size. +arguments: + - + name: value + type: + - int diff --git a/generator/config/query-operators/slice.yaml b/generator/config/query-operators/slice.yaml new file mode 100644 index 000000000..b58a7acce --- /dev/null +++ b/generator/config/query-operators/slice.yaml @@ -0,0 +1,19 @@ +# $schema: ../schema.json +name: $slice +category: + - 'Projection Operators' +link: 'https://www.mongodb.com/docs/manual/reference/operator/query/slice/' +type: + - Query +encode: array +description: | + Limits the number of elements projected from an array. Supports skip and limit slices. +arguments: + - + name: limit + type: + - int + - + name: skip + type: + - int diff --git a/generator/config/query-operators/text.yaml b/generator/config/query-operators/text.yaml new file mode 100644 index 000000000..03df77a2c --- /dev/null +++ b/generator/config/query-operators/text.yaml @@ -0,0 +1,40 @@ +# $schema: ../schema.json +name: $text +category: + - 'Evaluation Query Operators' +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. diff --git a/generator/config/query-operators/type.yaml b/generator/config/query-operators/type.yaml new file mode 100644 index 000000000..3945b8f38 --- /dev/null +++ b/generator/config/query-operators/type.yaml @@ -0,0 +1,18 @@ +# $schema: ../schema.json +name: $type +category: + - 'Element Query Operators' +link: 'https://www.mongodb.com/docs/manual/reference/operator/query/type/' +type: + - Query +encode: single +description: | + Selects documents if a field is of the specified type. +arguments: + - + name: type + type: + - int + - string + - array + - array diff --git a/generator/config/query-operators/where.yaml b/generator/config/query-operators/where.yaml new file mode 100644 index 000000000..120ce2cf0 --- /dev/null +++ b/generator/config/query-operators/where.yaml @@ -0,0 +1,15 @@ +# $schema: ../schema.json +name: $where +category: + - 'Evaluation Query Operators' +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: + - string diff --git a/generator/config/schema.json b/generator/config/schema.json index 422b52c39..0639edac2 100644 --- a/generator/config/schema.json +++ b/generator/config/schema.json @@ -37,11 +37,13 @@ "$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", "type": "string", "enum": [ "array", "object", - "single" + "single", + "group" ] }, "description": { @@ -52,7 +54,7 @@ "$comment": "An optional list of parameters for the operator.", "type": "array", "items": { - "$ref": "#/definitions/Parameter" + "$ref": "#/definitions/Argument" } } }, @@ -67,7 +69,7 @@ ], "title": "Operator" }, - "Parameter": { + "Argument": { "type": "object", "additionalProperties": false, "properties": { @@ -101,8 +103,8 @@ "$comment": "Whether the parameter is variadic or not.", "type": "string", "enum": [ - "list", - "map" + "array", + "object" ] }, "variadicMin": { @@ -116,7 +118,7 @@ "name", "type" ], - "title": "Parameter" + "title": "Argument" } } } diff --git a/generator/config/stages.yaml b/generator/config/stages.yaml deleted file mode 100644 index b973c6db2..000000000 --- a/generator/config/stages.yaml +++ /dev/null @@ -1,33 +0,0 @@ -- name: match - type: stage - args: - - name: query - type: expression -- name: sort - type: stage - args: - # @todo should generate be a map, not a list - - name: sortSpecification - type: [int, object] # should be an enum PHPLIB-1269 - isVariadic: true -- name: limit - type: stage - args: - - name: limit - type: int -- name: group - type: stage - encode: object - args: - - name: _id - type: [expression, "null"] - - name: fields - type: expression - isVariadic: true - variadicMin: 0 -- name: project - type: stage - args: - - name: specifications - type: expression - isVariadic: true diff --git a/generator/src/AbstractGenerator.php b/generator/src/AbstractGenerator.php index 406184e47..a24d8ceb9 100644 --- a/generator/src/AbstractGenerator.php +++ b/generator/src/AbstractGenerator.php @@ -51,7 +51,7 @@ final protected function writeFile(PhpNamespace $namespace): void $classes = $namespace->getClasses(); assert(count($classes) === 1, sprintf('Expected exactly one class in namespace "%s", got %d.', $namespace->getName(), count($classes))); - $filename = $this->rootDir . '/' . $this->getFileName($namespace->getName(), current($classes)->getName()); + $filename = $this->rootDir . $this->getFileName($namespace->getName(), current($classes)->getName()); $dirname = dirname($filename); if (! is_dir($dirname)) { diff --git a/generator/src/Command/GenerateCommand.php b/generator/src/Command/GenerateCommand.php index faa4a13d7..c7439a2a2 100644 --- a/generator/src/Command/GenerateCommand.php +++ b/generator/src/Command/GenerateCommand.php @@ -80,7 +80,7 @@ private function generateOperatorClasses(array $expressions, OutputInterface $ou $definition = new GeneratorDefinition(...$def); foreach ($definition->generators as $generatorClass) { - $output->writeln(sprintf('Generating classes for %s with %s', basename($definition->configFile), $generatorClass)); + $output->writeln(sprintf('Generating classes for %s with %s', basename($definition->configFiles), $generatorClass)); assert(is_a($generatorClass, OperatorGenerator::class, true)); $generator = new $generatorClass($this->rootDir, $expressions); $generator->generate($definition); diff --git a/generator/src/Command/ScrapeCommand.php b/generator/src/Command/ScrapeCommand.php index 5b455eaf0..579c89d52 100644 --- a/generator/src/Command/ScrapeCommand.php +++ b/generator/src/Command/ScrapeCommand.php @@ -182,7 +182,7 @@ private function formatSpec(array $doc): array $spec['category'] = explode(PHP_EOL, $doc['Category']); sort($spec['category']); $spec['link'] = $doc['Link']; - $spec['returnType'] = explode(PHP_EOL, $doc['ReturnType']); + $spec['type'] = explode(PHP_EOL, $doc['ReturnType']); $spec['encode'] = $doc['Encode']; if ($doc['Description']) { @@ -194,18 +194,29 @@ private function formatSpec(array $doc): array assert(isset($arg[$key]), 'Missing Arg' . $key . ' for ' . var_export($doc, true)); } - $parameter = []; - $parameter['name'] = $arg['Name']; - $parameter['type'] = explode(PHP_EOL, $doc['ReturnType']); + // Skip if the argument has no name, which means there is no argument + if ($arg['Name'] === '') { + continue; + } + + $argument = []; + $argument['name'] = $arg['Name']; + $argument['type'] = explode(PHP_EOL, $arg['Type']); if (str_contains($arg['Options'], 'Optional')) { - $parameter['optional'] = true; + $argument['optional'] = true; + } + + if (str_contains($arg['Options'], 'Variadic map')) { + $argument['variadic'] = 'object'; + } elseif (str_contains($arg['Options'], 'Variadic list')) { + $argument['variadic'] = 'array'; } if ($arg['Description']) { - $parameter['description'] = $arg['Description'] . PHP_EOL; + $argument['description'] = $arg['Description'] . PHP_EOL; } - $spec['parameters'][] = $parameter; + $spec['arguments'][] = $argument; } return $spec; @@ -213,7 +224,7 @@ private function formatSpec(array $doc): array private function writeYamlFile(string $dirname, array $data): void { - $yaml = Yaml::dump($data, 3, 4, Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK); + $yaml = Yaml::dump($data, 4, 4, Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK); $dirname = $this->configDir . '/' . $dirname; if (! file_exists($dirname)) { mkdir($dirname, 0755); diff --git a/generator/src/Definition/ArgumentDefinition.php b/generator/src/Definition/ArgumentDefinition.php index bfb5eeef4..9408a4e05 100644 --- a/generator/src/Definition/ArgumentDefinition.php +++ b/generator/src/Definition/ArgumentDefinition.php @@ -12,14 +12,16 @@ final readonly class ArgumentDefinition { + public ?VariadicType $variadic; public ?int $variadicMin; public function __construct( public string $name, - /** @psalm-assert string|list $type */ - public string|array $type, - public bool $isOptional = false, - public bool $isVariadic = false, + /** @psalm-assert list $type */ + public array $type, + public ?string $description = null, + public bool $optional = false, + ?string $variadic = null, ?int $variadicMin = null, ) { if (is_array($type)) { @@ -29,13 +31,16 @@ public function __construct( } } - if (! $isVariadic) { - assert($variadicMin === null); - $this->variadicMin = null; - } elseif ($variadicMin === null) { - $this->variadicMin = $isOptional ? 0 : 1; + if ($variadic) { + $this->variadic = VariadicType::from($variadic); + if ($variadicMin === null) { + $this->variadicMin = $optional ? 0 : 1; + } else { + $this->variadicMin = $variadicMin; + } } else { - $this->variadicMin = $variadicMin; + $this->variadic = null; + $this->variadicMin = null; } } } diff --git a/generator/src/Definition/GeneratorDefinition.php b/generator/src/Definition/GeneratorDefinition.php index 936136f47..f0a09b7bf 100644 --- a/generator/src/Definition/GeneratorDefinition.php +++ b/generator/src/Definition/GeneratorDefinition.php @@ -17,7 +17,7 @@ final readonly class GeneratorDefinition { public function __construct( - public string $configFile, + public string $configFiles, /** @psalm-assert list> */ public array $generators, public string $namespace, diff --git a/generator/src/Definition/OperatorDefinition.php b/generator/src/Definition/OperatorDefinition.php index 3c8b5ae2c..e553863dc 100644 --- a/generator/src/Definition/OperatorDefinition.php +++ b/generator/src/Definition/OperatorDefinition.php @@ -3,29 +3,48 @@ namespace MongoDB\CodeGenerator\Definition; -use function array_map; -use function assert; -use function count; -use function in_array; +use MongoDB\Builder\Encode; +use UnexpectedValueException; + +use function array_merge; use function sprintf; final readonly class OperatorDefinition { + public Encode $encode; /** @var list */ public array $arguments; public function __construct( public string $name, - public ?string $encode = null, - public ?string $type = null, - array $args = [], + public array $category, + public string $link, + string $encode, + public array $type, + public ?string $description = null, + array $arguments = [], ) { - assert($encode || count($args) === 1, sprintf('Operator "%s" has %d arguments. The "encode" parameter must be specified.', $name, count($args))); - assert(in_array($encode, [null, 'array', 'object'], true), sprintf('Operator "%s" expect "encode" value to be "array" or "object". Got "%s".', $name, $encode)); + $this->encode = match ($encode) { + 'single' => Encode::Single, + 'array' => Encode::Array, + 'object' => Encode::Object, + 'empty object' => Encode::Object, + 'group' => Encode::Group, + default => throw new UnexpectedValueException(sprintf('Unexpected "encode" value for operator "%s". Got "%s"', $name, $encode)), + }; + + // Convert arguments to ArgumentDefinition objects + // Optional arguments must be after required arguments + $requiredArgs = $optionalArgs = []; + foreach ($arguments as $arg) { + $arg = new ArgumentDefinition(...$arg); + if ($arg->optional) { + $optionalArgs[] = $arg; + } else { + $requiredArgs[] = $arg; + } + } - $this->arguments = array_map( - fn ($arg): ArgumentDefinition => new ArgumentDefinition(...$arg), - $args, - ); + $this->arguments = array_merge($requiredArgs, $optionalArgs); } } diff --git a/generator/src/Definition/VariadicType.php b/generator/src/Definition/VariadicType.php new file mode 100644 index 000000000..899fe9074 --- /dev/null +++ b/generator/src/Definition/VariadicType.php @@ -0,0 +1,9 @@ + */ - public function read(string $filename): array + public function read(string $dirname): array { - if (array_key_exists($filename, self::$definitions)) { - return self::$definitions[$filename]; + if (array_key_exists($dirname, self::$definitions)) { + return self::$definitions[$dirname]; } - $config = Yaml::parseFile($filename); - assert(is_array($config)); + $finder = new Finder(); + $finder->files()->in($dirname)->name('*.yaml'); $definitions = []; - foreach ($config as $operator) { + foreach ($finder as $file) { + $operator = Yaml::parseFile($file->getPathname()); assert(is_array($operator)); $definitions[] = new OperatorDefinition(...$operator); } - return self::$definitions[$filename] = $definitions; + return self::$definitions[$dirname] = $definitions; } } diff --git a/generator/src/OperatorClassGenerator.php b/generator/src/OperatorClassGenerator.php index 2c65d4075..40830cca4 100644 --- a/generator/src/OperatorClassGenerator.php +++ b/generator/src/OperatorClassGenerator.php @@ -3,14 +3,23 @@ namespace MongoDB\CodeGenerator; +use MongoDB\Builder\Aggregation\AccumulatorInterface; +use MongoDB\Builder\Encode; +use MongoDB\Builder\Optional; +use MongoDB\Builder\Query\QueryInterface; use MongoDB\Builder\Stage\StageInterface; use MongoDB\CodeGenerator\Definition\GeneratorDefinition; use MongoDB\CodeGenerator\Definition\OperatorDefinition; +use MongoDB\CodeGenerator\Definition\VariadicType; use Nette\PhpGenerator\Literal; use Nette\PhpGenerator\PhpNamespace; +use Nette\PhpGenerator\Type; +use RuntimeException; +use Throwable; use function assert; use function interface_exists; +use function rtrim; use function sprintf; /** @@ -21,7 +30,11 @@ class OperatorClassGenerator extends OperatorGenerator public function generate(GeneratorDefinition $definition): void { foreach ($this->getOperators($definition) as $operator) { - $this->writeFile($this->createClass($definition, $operator)); + try { + $this->writeFile($this->createClass($definition, $operator)); + } catch (Throwable $e) { + throw new RuntimeException(sprintf('Failed to generate class for operator "%s"', $operator->name), 0, $e); + } } } @@ -39,8 +52,9 @@ public function createClass(GeneratorDefinition $definition, OperatorDefinition // Expose operator metadata as constants // @todo move to encoder class - $class->addConstant('NAME', '$' . $operator->name); - $class->addConstant('ENCODE', $operator->encode ?? 'single'); + $namespace->addUse('\\' . Encode::class); + $class->addConstant('NAME', $operator->name); + $class->addConstant('ENCODE', $operator->encode); $constuctor = $class->addMethod('__construct'); foreach ($operator->arguments as $argument) { @@ -49,49 +63,62 @@ public function createClass(GeneratorDefinition $definition, OperatorDefinition $namespace->addUse($use); } - // Property - $propertyComment = ''; $property = $class->addProperty($argument->name); - if ($argument->isVariadic) { - $property->setType('array'); - $propertyComment .= '@param list<' . $type->doc . '> ...$' . $argument->name; - } else { - $property->setType($type->native); - } - - $property->setComment($propertyComment); - - // Constructor $constuctorParam = $constuctor->addParameter($argument->name); $constuctorParam->setType($type->native); - if ($argument->isVariadic) { + + if ($argument->variadic) { + $property->setType('array'); $constuctor->setVariadic(); - if ($argument->variadicMin > 0) { + if ($argument->variadic === VariadicType::Array) { + $property->setComment('@param list<' . $type->doc . '> ...$' . $argument->name . rtrim(' ' . $argument->description)); $constuctor->addBody(<<name}) < {$argument->variadicMin}) { - throw new \InvalidArgumentException(\sprintf('Expected at least %d values, got %d.', $argument->variadicMin, \count(\${$argument->name}))); + if (! \array_is_list(\${$argument->name})) { + throw new \InvalidArgumentException('Expected \${$argument->name} arguments to be a list of {$type->doc}, named arguments are not supported'); + } + PHP); + } elseif ($argument->variadic === VariadicType::Object) { + $property->setComment('@param arraydoc . '> ...$' . $argument->name . rtrim(' ' . $argument->description)); + $constuctor->addBody(<<name} as \$key => \$value) { + if (! \is_string(\$key)) { + throw new \InvalidArgumentException('Expected \${$argument->name} arguments to be a map of {$type->doc}, named arguments (:) or array unpacking ...[\'\' => ] must be used'); + } } + PHP); + } + if ($argument->variadicMin !== null) { + $constuctor->addBody(<<name}) < {$argument->variadicMin}) { + throw new \InvalidArgumentException(\sprintf('Expected at least %d values for \${$argument->name}, got %d.', {$argument->variadicMin}, \count(\${$argument->name}))); + } PHP); } - } elseif ($argument->isOptional) { - $constuctorParam->setDefaultValue(new Literal('Optional::Undefined')); - } + } else { + // Non-variadic arguments + $property->setComment('@param ' . $type->doc . ' $' . $argument->name . rtrim(' ' . $argument->description)); + $property->setType($type->native); - $constuctor->addComment('@param ' . $type->doc . ' $' . $argument->name); + if ($argument->optional) { + // We use a special Optional::Undefined type to differentiate between null and undefined + $constuctorParam->setDefaultValue(new Literal('Optional::Undefined')); + } - // List type must be validated with array_is_list() - if ($type->list) { - $constuctor->addBody(<<name}) && ! \array_is_list(\${$argument->name})) { - throw new \InvalidArgumentException('Expected \${$argument->name} argument to be a list, got an associative array.'); + // List type must be validated with array_is_list() + if ($type->list) { + $constuctor->addBody(<<name}) && ! \array_is_list(\${$argument->name})) { + throw new \InvalidArgumentException('Expected \${$argument->name} argument to be a list, got an associative array.'); + } + PHP); } - PHP); } // Set property from constructor argument $constuctor->addBody('$this->' . $argument->name . ' = $' . $argument->name . ';'); + $constuctor->addComment('@param ' . $type->doc . ' $' . $argument->name . rtrim(' ' . $argument->description)); } return $namespace; @@ -102,17 +129,25 @@ public function createClass(GeneratorDefinition $definition, OperatorDefinition */ private function getInterfaces(OperatorDefinition $definition): array { - if ($definition->type === null) { - return []; - } + $interfaces = []; - if ($definition->type === 'stage') { - return ['\\' . StageInterface::class]; - } + foreach ($definition->type as $type) { + if ($definition->type === 'Stage') { + return ['\\' . StageInterface::class]; + } + + if ($definition->type === 'Query') { + return ['\\' . QueryInterface::class]; + } + + if ($definition->type === 'Accumulator') { + return ['\\' . AccumulatorInterface::class]; + } - $interface = $this->getExpressionTypeInterface($definition->type); - assert(interface_exists($interface), sprintf('"%s" is not an interface.', $interface)); + $interfaces[] = $interface = $this->getExpressionTypeInterface($type); + assert(interface_exists($interface), sprintf('"%s" is not an interface.', $interface)); + } - return [$interface]; + return $interfaces; } } diff --git a/generator/src/OperatorFactoryGenerator.php b/generator/src/OperatorFactoryGenerator.php index b7e63594c..80a13f012 100644 --- a/generator/src/OperatorFactoryGenerator.php +++ b/generator/src/OperatorFactoryGenerator.php @@ -5,11 +5,16 @@ use MongoDB\CodeGenerator\Definition\GeneratorDefinition; use MongoDB\CodeGenerator\Definition\OperatorDefinition; +use Nette\PhpGenerator\ClassType; use Nette\PhpGenerator\Literal; use Nette\PhpGenerator\PhpNamespace; +use RuntimeException; +use Throwable; use function implode; use function ltrim; +use function rtrim; +use function sprintf; use function str_replace; use function usort; @@ -33,37 +38,11 @@ private function createFactoryClass(GeneratorDefinition $definition): PhpNamespa usort($operators, fn (OperatorDefinition $a, OperatorDefinition $b) => $a->name <=> $b->name); foreach ($operators as $operator) { - $operatorClassName = '\\' . $definition->namespace . '\\' . $this->getOperatorClassName($definition, $operator); - $namespace->addUse($operatorClassName); - - $method = $class->addMethod($operator->name); - $method->setStatic(); - $args = []; - foreach ($operator->arguments as $argument) { - $type = $this->generateExpressionTypes($argument); - foreach ($type->use as $use) { - $namespace->addUse($use); - } - - $parameter = $method->addParameter($argument->name); - $parameter->setType($type->native); - if ($argument->isVariadic) { - $method->setVariadic(); - $method->addComment('@param ' . $type->doc . ' ...$' . $argument->name); - $args[] = '...$' . $argument->name; - } else { - if ($argument->isOptional) { - $parameter->setDefaultValue(new Literal('Optional::Undefined')); - } - - $method->addComment('@param ' . $type->doc . ' $' . $argument->name); - $args[] = '$' . $argument->name; - } + try { + $this->addMethod($definition, $operator, $namespace, $class); + } catch (Throwable $e) { + throw new RuntimeException(sprintf('Failed to generate class for operator "%s"', $operator->name), 0, $e); } - - $operatorShortClassName = ltrim(str_replace($definition->namespace, '', $operatorClassName), '\\'); - $method->addBody('return new ' . $operatorShortClassName . '(' . implode(', ', $args) . ');'); - $method->setReturnType($operatorClassName); } // Pedantry requires private methods to be at the end @@ -72,4 +51,39 @@ private function createFactoryClass(GeneratorDefinition $definition): PhpNamespa return $namespace; } + + private function addMethod(GeneratorDefinition $definition, OperatorDefinition $operator, PhpNamespace $namespace, ClassType $class): void + { + $operatorClassName = '\\' . $definition->namespace . '\\' . $this->getOperatorClassName($definition, $operator); + $namespace->addUse($operatorClassName); + + $method = $class->addMethod(ltrim($operator->name, '$')); + $method->setStatic(); + $args = []; + foreach ($operator->arguments as $argument) { + $type = $this->generateExpressionTypes($argument); + foreach ($type->use as $use) { + $namespace->addUse($use); + } + + $parameter = $method->addParameter($argument->name); + $parameter->setType($type->native); + if ($argument->variadic) { + $method->setVariadic(); + $method->addComment('@param ' . $type->doc . ' ...$' . $argument->name . rtrim(' ' . $argument->description)); + $args[] = '...$' . $argument->name; + } else { + if ($argument->optional) { + $parameter->setDefaultValue(new Literal('Optional::Undefined')); + } + + $method->addComment('@param ' . $type->doc . ' $' . $argument->name . rtrim(' ' . $argument->description)); + $args[] = '$' . $argument->name; + } + } + + $operatorShortClassName = ltrim(str_replace($definition->namespace, '', $operatorClassName), '\\'); + $method->addBody('return new ' . $operatorShortClassName . '(' . implode(', ', $args) . ');'); + $method->setReturnType($operatorClassName); + } } diff --git a/generator/src/OperatorGenerator.php b/generator/src/OperatorGenerator.php index b1571a313..f00120e0a 100644 --- a/generator/src/OperatorGenerator.php +++ b/generator/src/OperatorGenerator.php @@ -3,8 +3,11 @@ namespace MongoDB\CodeGenerator; +use MongoDB\Builder\Aggregation\AccumulatorInterface; use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Optional; +use MongoDB\Builder\Query\QueryInterface; +use MongoDB\Builder\Stage\StageInterface; use MongoDB\CodeGenerator\Definition\ArgumentDefinition; use MongoDB\CodeGenerator\Definition\ExpressionDefinition; use MongoDB\CodeGenerator\Definition\GeneratorDefinition; @@ -12,13 +15,16 @@ use MongoDB\CodeGenerator\Definition\YamlReader; use Nette\PhpGenerator\Type; +use function array_filter; use function array_key_exists; use function array_merge; use function array_unique; use function assert; use function class_exists; +use function explode; use function in_array; use function interface_exists; +use function ltrim; use function sort; use function sprintf; use function ucfirst; @@ -39,24 +45,43 @@ final public function __construct( abstract public function generate(GeneratorDefinition $definition): void; - /** @return list */ final protected function getOperators(GeneratorDefinition $definition): array { - return $this->yamlReader->read($definition->configFile); + // Remove unsupported operators + return array_filter( + $this->yamlReader->read($definition->configFiles), + fn (OperatorDefinition $operator): bool => ! in_array($operator->name, ['$'], true), + ); } final protected function getOperatorClassName(GeneratorDefinition $definition, OperatorDefinition $operator): string { - return ucfirst($operator->name) . $definition->classNameSuffix; + return ucfirst(ltrim($operator->name, '$')) . $definition->classNameSuffix; } /** @return class-string|string */ final protected function getExpressionTypeInterface(string $type): string { - if ('expression' === $type) { + if ('expression' === $type || 'resolvesToAnything' === $type) { return ExpressionInterface::class; } + if ('Stage' === $type) { + return StageInterface::class; + } + + if ('Accumulator' === $type) { + return AccumulatorInterface::class; + } + + if ('Query' === $type) { + return QueryInterface::class; + } + + // @todo handle generic types object and array + $type = explode('<', $type, 2)[0]; + $type = explode('{', $type, 2)[0]; + // Scalar types if (array_key_exists($type, $this->expressions)) { return $type; @@ -77,7 +102,7 @@ final protected function getExpressionTypeInterface(string $type): string final protected function generateExpressionTypes(ArgumentDefinition $arg): object { $nativeTypes = []; - foreach ((array) $arg->type as $type) { + foreach ($arg->type as $type) { $interface = $this->getExpressionTypeInterface($type); $types = $this->expressions[$interface]->types; @@ -89,6 +114,11 @@ final protected function generateExpressionTypes(ArgumentDefinition $arg): objec $nativeTypes = array_merge($nativeTypes, $types); } + if ($arg->optional) { + $use[] = '\\' . Optional::class; + $nativeTypes[] = Optional::class; + } + $docTypes = $nativeTypes = array_unique($nativeTypes); $listCheck = false; $use = []; @@ -119,12 +149,6 @@ final protected function generateExpressionTypes(ArgumentDefinition $arg): objec } } - if ($arg->isOptional) { - $use[] = '\\' . Optional::class; - $docTypes[] = 'Optional'; - $nativeTypes[] = Optional::class; - } - // mixed can only be used as a standalone type if (in_array('mixed', $nativeTypes, true)) { $nativeTypes = ['mixed']; diff --git a/src/Builder/Aggregation.php b/src/Builder/Aggregation.php index cb7393e0b..fbfbff3b5 100644 --- a/src/Builder/Aggregation.php +++ b/src/Builder/Aggregation.php @@ -6,138 +6,2080 @@ namespace MongoDB\Builder; +use DateTimeInterface; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Document; use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; +use MongoDB\BSON\Serializable; +use MongoDB\Builder\Aggregation\AbsAggregation; +use MongoDB\Builder\Aggregation\AccumulatorAggregation; +use MongoDB\Builder\Aggregation\AcosAggregation; +use MongoDB\Builder\Aggregation\AcoshAggregation; +use MongoDB\Builder\Aggregation\AddAggregation; +use MongoDB\Builder\Aggregation\AddToSetAggregation; +use MongoDB\Builder\Aggregation\AllElementsTrueAggregation; use MongoDB\Builder\Aggregation\AndAggregation; +use MongoDB\Builder\Aggregation\AnyElementTrueAggregation; +use MongoDB\Builder\Aggregation\ArrayElemAtAggregation; +use MongoDB\Builder\Aggregation\ArrayToObjectAggregation; +use MongoDB\Builder\Aggregation\AsinAggregation; +use MongoDB\Builder\Aggregation\AsinhAggregation; +use MongoDB\Builder\Aggregation\Atan2Aggregation; +use MongoDB\Builder\Aggregation\AtanAggregation; +use MongoDB\Builder\Aggregation\AtanhAggregation; +use MongoDB\Builder\Aggregation\AvgAggregation; +use MongoDB\Builder\Aggregation\BinarySizeAggregation; +use MongoDB\Builder\Aggregation\BitAndAggregation; +use MongoDB\Builder\Aggregation\BitNotAggregation; +use MongoDB\Builder\Aggregation\BitOrAggregation; +use MongoDB\Builder\Aggregation\BitXorAggregation; +use MongoDB\Builder\Aggregation\BottomAggregation; +use MongoDB\Builder\Aggregation\BottomNAggregation; +use MongoDB\Builder\Aggregation\BsonSizeAggregation; +use MongoDB\Builder\Aggregation\CeilAggregation; +use MongoDB\Builder\Aggregation\CmpAggregation; +use MongoDB\Builder\Aggregation\ConcatAggregation; +use MongoDB\Builder\Aggregation\ConcatArraysAggregation; +use MongoDB\Builder\Aggregation\CondAggregation; +use MongoDB\Builder\Aggregation\ConvertAggregation; +use MongoDB\Builder\Aggregation\CosAggregation; +use MongoDB\Builder\Aggregation\CoshAggregation; +use MongoDB\Builder\Aggregation\CountAggregation; +use MongoDB\Builder\Aggregation\CovariancePopAggregation; +use MongoDB\Builder\Aggregation\CovarianceSampAggregation; +use MongoDB\Builder\Aggregation\DateAddAggregation; +use MongoDB\Builder\Aggregation\DateDiffAggregation; +use MongoDB\Builder\Aggregation\DateFromPartsAggregation; +use MongoDB\Builder\Aggregation\DateFromStringAggregation; +use MongoDB\Builder\Aggregation\DateSubtractAggregation; +use MongoDB\Builder\Aggregation\DateToPartsAggregation; +use MongoDB\Builder\Aggregation\DateToStringAggregation; +use MongoDB\Builder\Aggregation\DateTruncAggregation; +use MongoDB\Builder\Aggregation\DayOfMonthAggregation; +use MongoDB\Builder\Aggregation\DayOfWeekAggregation; +use MongoDB\Builder\Aggregation\DayOfYearAggregation; +use MongoDB\Builder\Aggregation\DegreesToRadiansAggregation; +use MongoDB\Builder\Aggregation\DenseRankAggregation; +use MongoDB\Builder\Aggregation\DerivativeAggregation; +use MongoDB\Builder\Aggregation\DivideAggregation; +use MongoDB\Builder\Aggregation\DocumentNumberAggregation; use MongoDB\Builder\Aggregation\EqAggregation; +use MongoDB\Builder\Aggregation\ExpAggregation; +use MongoDB\Builder\Aggregation\ExpMovingAvgAggregation; use MongoDB\Builder\Aggregation\FilterAggregation; +use MongoDB\Builder\Aggregation\FirstAggregation; +use MongoDB\Builder\Aggregation\FirstNAggregation; +use MongoDB\Builder\Aggregation\FloorAggregation; +use MongoDB\Builder\Aggregation\FunctionAggregation; +use MongoDB\Builder\Aggregation\GetFieldAggregation; use MongoDB\Builder\Aggregation\GtAggregation; use MongoDB\Builder\Aggregation\GteAggregation; +use MongoDB\Builder\Aggregation\HourAggregation; +use MongoDB\Builder\Aggregation\IfNullAggregation; +use MongoDB\Builder\Aggregation\InAggregation; +use MongoDB\Builder\Aggregation\IndexOfArrayAggregation; +use MongoDB\Builder\Aggregation\IndexOfBytesAggregation; +use MongoDB\Builder\Aggregation\IndexOfCPAggregation; +use MongoDB\Builder\Aggregation\IntegralAggregation; +use MongoDB\Builder\Aggregation\IsArrayAggregation; +use MongoDB\Builder\Aggregation\IsNumberAggregation; +use MongoDB\Builder\Aggregation\IsoDayOfWeekAggregation; +use MongoDB\Builder\Aggregation\IsoWeekAggregation; +use MongoDB\Builder\Aggregation\IsoWeekYearAggregation; +use MongoDB\Builder\Aggregation\LastAggregation; +use MongoDB\Builder\Aggregation\LastNAggregation; +use MongoDB\Builder\Aggregation\LetAggregation; +use MongoDB\Builder\Aggregation\LinearFillAggregation; +use MongoDB\Builder\Aggregation\LiteralAggregation; +use MongoDB\Builder\Aggregation\LnAggregation; +use MongoDB\Builder\Aggregation\LocfAggregation; +use MongoDB\Builder\Aggregation\Log10Aggregation; +use MongoDB\Builder\Aggregation\LogAggregation; use MongoDB\Builder\Aggregation\LtAggregation; +use MongoDB\Builder\Aggregation\LteAggregation; +use MongoDB\Builder\Aggregation\LtrimAggregation; +use MongoDB\Builder\Aggregation\MapAggregation; use MongoDB\Builder\Aggregation\MaxAggregation; +use MongoDB\Builder\Aggregation\MaxNAggregation; +use MongoDB\Builder\Aggregation\MedianAggregation; +use MongoDB\Builder\Aggregation\MergeObjectsAggregation; +use MongoDB\Builder\Aggregation\MetaAggregation; +use MongoDB\Builder\Aggregation\MillisecondAggregation; use MongoDB\Builder\Aggregation\MinAggregation; +use MongoDB\Builder\Aggregation\MinNAggregation; +use MongoDB\Builder\Aggregation\MinuteAggregation; use MongoDB\Builder\Aggregation\ModAggregation; +use MongoDB\Builder\Aggregation\MonthAggregation; +use MongoDB\Builder\Aggregation\MultiplyAggregation; use MongoDB\Builder\Aggregation\NeAggregation; +use MongoDB\Builder\Aggregation\NotAggregation; +use MongoDB\Builder\Aggregation\ObjectToArrayAggregation; +use MongoDB\Builder\Aggregation\OrAggregation; +use MongoDB\Builder\Aggregation\PercentileAggregation; +use MongoDB\Builder\Aggregation\PowAggregation; +use MongoDB\Builder\Aggregation\PushAggregation; +use MongoDB\Builder\Aggregation\RadiansToDegreesAggregation; +use MongoDB\Builder\Aggregation\RandAggregation; +use MongoDB\Builder\Aggregation\RangeAggregation; +use MongoDB\Builder\Aggregation\RankAggregation; +use MongoDB\Builder\Aggregation\ReduceAggregation; +use MongoDB\Builder\Aggregation\RegexFindAggregation; +use MongoDB\Builder\Aggregation\RegexFindAllAggregation; +use MongoDB\Builder\Aggregation\RegexMatchAggregation; +use MongoDB\Builder\Aggregation\ReplaceAllAggregation; +use MongoDB\Builder\Aggregation\ReplaceOneAggregation; +use MongoDB\Builder\Aggregation\ReverseArrayAggregation; +use MongoDB\Builder\Aggregation\RoundAggregation; +use MongoDB\Builder\Aggregation\RtrimAggregation; +use MongoDB\Builder\Aggregation\SampleRateAggregation; +use MongoDB\Builder\Aggregation\SecondAggregation; +use MongoDB\Builder\Aggregation\SetDifferenceAggregation; +use MongoDB\Builder\Aggregation\SetEqualsAggregation; +use MongoDB\Builder\Aggregation\SetFieldAggregation; +use MongoDB\Builder\Aggregation\SetIntersectionAggregation; +use MongoDB\Builder\Aggregation\SetIsSubsetAggregation; +use MongoDB\Builder\Aggregation\SetUnionAggregation; +use MongoDB\Builder\Aggregation\ShiftAggregation; +use MongoDB\Builder\Aggregation\SinAggregation; +use MongoDB\Builder\Aggregation\SinhAggregation; +use MongoDB\Builder\Aggregation\SizeAggregation; +use MongoDB\Builder\Aggregation\SliceAggregation; +use MongoDB\Builder\Aggregation\SortArrayAggregation; +use MongoDB\Builder\Aggregation\SplitAggregation; +use MongoDB\Builder\Aggregation\SqrtAggregation; +use MongoDB\Builder\Aggregation\StdDevPopAggregation; +use MongoDB\Builder\Aggregation\StdDevSampAggregation; +use MongoDB\Builder\Aggregation\StrLenBytesAggregation; +use MongoDB\Builder\Aggregation\StrLenCPAggregation; +use MongoDB\Builder\Aggregation\StrcasecmpAggregation; +use MongoDB\Builder\Aggregation\SubstrAggregation; +use MongoDB\Builder\Aggregation\SubstrBytesAggregation; +use MongoDB\Builder\Aggregation\SubstrCPAggregation; use MongoDB\Builder\Aggregation\SubtractAggregation; use MongoDB\Builder\Aggregation\SumAggregation; +use MongoDB\Builder\Aggregation\SwitchAggregation; +use MongoDB\Builder\Aggregation\TanAggregation; +use MongoDB\Builder\Aggregation\TanhAggregation; +use MongoDB\Builder\Aggregation\ToBoolAggregation; +use MongoDB\Builder\Aggregation\ToDateAggregation; +use MongoDB\Builder\Aggregation\ToDecimalAggregation; +use MongoDB\Builder\Aggregation\ToDoubleAggregation; +use MongoDB\Builder\Aggregation\ToIntAggregation; +use MongoDB\Builder\Aggregation\ToLongAggregation; +use MongoDB\Builder\Aggregation\ToLowerAggregation; +use MongoDB\Builder\Aggregation\ToObjectIdAggregation; +use MongoDB\Builder\Aggregation\ToStringAggregation; +use MongoDB\Builder\Aggregation\ToUpperAggregation; +use MongoDB\Builder\Aggregation\TopAggregation; +use MongoDB\Builder\Aggregation\TopNAggregation; +use MongoDB\Builder\Aggregation\TrimAggregation; +use MongoDB\Builder\Aggregation\TruncAggregation; +use MongoDB\Builder\Aggregation\TsIncrementAggregation; +use MongoDB\Builder\Aggregation\TsSecondAggregation; +use MongoDB\Builder\Aggregation\TypeAggregation; +use MongoDB\Builder\Aggregation\UnsetFieldAggregation; +use MongoDB\Builder\Aggregation\WeekAggregation; +use MongoDB\Builder\Aggregation\YearAggregation; +use MongoDB\Builder\Aggregation\ZipAggregation; use MongoDB\Builder\Expression\ExpressionInterface; +use MongoDB\Builder\Expression\FieldPath; use MongoDB\Builder\Expression\ResolvesToArray; +use MongoDB\Builder\Expression\ResolvesToBinary; use MongoDB\Builder\Expression\ResolvesToBool; +use MongoDB\Builder\Expression\ResolvesToDate; +use MongoDB\Builder\Expression\ResolvesToDecimal; +use MongoDB\Builder\Expression\ResolvesToDouble; +use MongoDB\Builder\Expression\ResolvesToFloat; use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Expression\ResolvesToLong; +use MongoDB\Builder\Expression\ResolvesToNull; +use MongoDB\Builder\Expression\ResolvesToNumber; +use MongoDB\Builder\Expression\ResolvesToObject; +use MongoDB\Builder\Expression\ResolvesToObjectId; use MongoDB\Builder\Expression\ResolvesToString; +use MongoDB\Builder\Expression\ResolvesToTimestamp; use MongoDB\Model\BSONArray; final class Aggregation { /** - * @param ExpressionInterface|mixed ...$expressions + * @param Decimal128|Int64|ResolvesToNumber|float|int $value */ - public static function and(mixed ...$expressions): AndAggregation + public static function abs(Decimal128|Int64|ResolvesToNumber|float|int $value): AbsAggregation { - return new AndAggregation(...$expressions); + return new AbsAggregation($value); } /** - * @param ExpressionInterface|mixed $expression1 - * @param ExpressionInterface|mixed $expression2 + * @param non-empty-string $init 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. + * @param non-empty-string $accumulate 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. + * @param BSONArray|PackedArray|ResolvesToArray|list $accumulateArgs Arguments passed to the accumulate function. You can use accumulateArgs to specify what field value(s) to pass to the accumulate function. + * @param non-empty-string $merge 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. + * @param non-empty-string $lang The language used in the $accumulator code. + * @param BSONArray|Optional|PackedArray|ResolvesToArray|list $initArgs Arguments passed to the init function. + * @param Optional|non-empty-string $finalize Function used to update the result of the accumulation. */ - public static function eq(mixed $expression1, mixed $expression2): EqAggregation + public static function accumulator( + string $init, + string $accumulate, + PackedArray|ResolvesToArray|BSONArray|array $accumulateArgs, + string $merge, + string $lang, + PackedArray|ResolvesToArray|Optional|BSONArray|array $initArgs = Optional::Undefined, + Optional|string $finalize = Optional::Undefined, + ): AccumulatorAggregation { - return new EqAggregation($expression1, $expression2); + return new AccumulatorAggregation($init, $accumulate, $accumulateArgs, $merge, $lang, $initArgs, $finalize); } /** - * @param BSONArray|PackedArray|ResolvesToArray|list $input - * @param ResolvesToBool|bool $cond - * @param Optional|ResolvesToString|non-empty-string $as - * @param Int64|Optional|ResolvesToInt|int $limit + * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $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. */ - public static function filter( - PackedArray|ResolvesToArray|BSONArray|array $input, - ResolvesToBool|bool $cond, - Optional|ResolvesToString|string $as = Optional::Undefined, - Optional|Int64|ResolvesToInt|int $limit = Optional::Undefined, - ): FilterAggregation + public static function acos(Decimal128|Int64|ResolvesToNumber|float|int $expression): AcosAggregation { - return new FilterAggregation($input, $cond, $as, $limit); + return new AcosAggregation($expression); } /** - * @param ExpressionInterface|mixed $expression1 - * @param ExpressionInterface|mixed $expression2 + * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $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. */ - public static function gt(mixed $expression1, mixed $expression2): GtAggregation + public static function acosh(Decimal128|Int64|ResolvesToNumber|float|int $expression): AcoshAggregation { - return new GtAggregation($expression1, $expression2); + return new AcoshAggregation($expression); } /** - * @param ExpressionInterface|mixed $expression1 - * @param ExpressionInterface|mixed $expression2 + * @param DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int ...$expression The arguments can be any valid expression as long as they resolve to either all numbers or to numbers and a date. */ - public static function gte(mixed $expression1, mixed $expression2): GteAggregation + public static function add( + \UTCDateTime|DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|float|int ...$expression, + ): AddAggregation { - return new GteAggregation($expression1, $expression2); + return new AddAggregation(...$expression); } /** - * @param ExpressionInterface|mixed $expression1 - * @param ExpressionInterface|mixed $expression2 + * @param ExpressionInterface|FieldPath|mixed|non-empty-string $expression */ - public static function lt(mixed $expression1, mixed $expression2): LtAggregation + public static function addToSet(mixed $expression): AddToSetAggregation { - return new LtAggregation($expression1, $expression2); + return new AddToSetAggregation($expression); } /** - * @param ExpressionInterface|mixed $expression + * @param BSONArray|PackedArray|ResolvesToArray|list ...$expression */ - public static function max(mixed $expression): MaxAggregation + public static function allElementsTrue( + PackedArray|ResolvesToArray|BSONArray|array ...$expression, + ): AllElementsTrueAggregation { - return new MaxAggregation($expression); + return new AllElementsTrueAggregation(...$expression); } /** - * @param ExpressionInterface|mixed $expression + * @param Decimal128|ExpressionInterface|Int64|ResolvesToBool|ResolvesToNull|ResolvesToNumber|ResolvesToString|bool|float|int|mixed|non-empty-string|null ...$expression */ - public static function min(mixed $expression): MinAggregation + public static function and(mixed ...$expression): AndAggregation { - return new MinAggregation($expression); + return new AndAggregation(...$expression); } /** - * @param ExpressionInterface|mixed $expression1 - * @param ExpressionInterface|mixed $expression2 + * @param BSONArray|PackedArray|ResolvesToArray|list $expression + */ + public static function anyElementTrue( + PackedArray|ResolvesToArray|BSONArray|array $expression, + ): AnyElementTrueAggregation + { + return new AnyElementTrueAggregation($expression); + } + + /** + * @param BSONArray|PackedArray|ResolvesToArray|list $array + * @param Int64|ResolvesToInt|int $idx + */ + public static function arrayElemAt( + PackedArray|ResolvesToArray|BSONArray|array $array, + Int64|ResolvesToInt|int $idx, + ): ArrayElemAtAggregation + { + return new ArrayElemAtAggregation($array, $idx); + } + + /** + * @param BSONArray|PackedArray|ResolvesToArray|list $array + */ + public static function arrayToObject(PackedArray|ResolvesToArray|BSONArray|array $array): ArrayToObjectAggregation + { + return new ArrayToObjectAggregation($array); + } + + /** + * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $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. + */ + public static function asin(Decimal128|Int64|ResolvesToNumber|float|int $expression): AsinAggregation + { + return new AsinAggregation($expression); + } + + /** + * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $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. + */ + public static function asinh(Decimal128|Int64|ResolvesToNumber|float|int $expression): AsinhAggregation + { + return new AsinhAggregation($expression); + } + + /** + * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $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. + */ + public static function atan(Decimal128|Int64|ResolvesToNumber|float|int $expression): AtanAggregation + { + return new AtanAggregation($expression); + } + + /** + * @param Decimal128|Int64|ResolvesToNumber|float|int $y $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. + * @param Decimal128|Int64|ResolvesToNumber|float|int $x + */ + public static function atan2( + Decimal128|Int64|ResolvesToNumber|float|int $y, + Decimal128|Int64|ResolvesToNumber|float|int $x, + ): Atan2Aggregation + { + return new Atan2Aggregation($y, $x); + } + + /** + * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $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. + */ + public static function atanh(Decimal128|Int64|ResolvesToNumber|float|int $expression): AtanhAggregation + { + return new AtanhAggregation($expression); + } + + /** + * @param Decimal128|Int64|ResolvesToNumber|float|int ...$expression + */ + public static function avg(Decimal128|Int64|ResolvesToNumber|float|int ...$expression): AvgAggregation + { + return new AvgAggregation(...$expression); + } + + /** + * @param Binary|ResolvesToBinary|ResolvesToNull|ResolvesToString|non-empty-string|null $expression + */ + public static function binarySize( + Binary|ResolvesToBinary|ResolvesToNull|ResolvesToString|null|string $expression, + ): BinarySizeAggregation + { + return new BinarySizeAggregation($expression); + } + + /** + * @param Int64|ResolvesToInt|ResolvesToLong|int ...$expression + */ + public static function bitAnd(Int64|ResolvesToInt|ResolvesToLong|int ...$expression): BitAndAggregation + { + return new BitAndAggregation(...$expression); + } + + /** + * @param Int64|ResolvesToInt|ResolvesToLong|int $expression + */ + public static function bitNot(Int64|ResolvesToInt|ResolvesToLong|int $expression): BitNotAggregation + { + return new BitNotAggregation($expression); + } + + /** + * @param Int64|ResolvesToInt|ResolvesToLong|int ...$expression + */ + public static function bitOr(Int64|ResolvesToInt|ResolvesToLong|int ...$expression): BitOrAggregation + { + return new BitOrAggregation(...$expression); + } + + public static function bitXor(): BitXorAggregation + { + return new BitXorAggregation(); + } + + /** + * @param array|object $sortBy Specifies the order of results, with syntax similar to $sort. + * @param ExpressionInterface|mixed $output Represents the output for each element in the group and can be any expression. + */ + public static function bottom(array|object $sortBy, mixed $output): BottomAggregation + { + return new BottomAggregation($sortBy, $output); + } + + /** + * @param Int64|ResolvesToInt|int $n 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. + * @param array|object $sortBy Specifies the order of results, with syntax similar to $sort. + * @param ExpressionInterface|mixed $output Represents the output for each element in the group and can be any expression. + */ + public static function bottomN( + Int64|ResolvesToInt|int $n, + array|object $sortBy, + mixed $output, + ): BottomNAggregation + { + return new BottomNAggregation($n, $sortBy, $output); + } + + /** + * @param Document|ResolvesToNull|ResolvesToObject|Serializable|array|null|object $object */ - public static function mod(mixed $expression1, mixed $expression2): ModAggregation + public static function bsonSize(array|null|object $object): BsonSizeAggregation { - return new ModAggregation($expression1, $expression2); + return new BsonSizeAggregation($object); + } + + /** + * @param Decimal128|Int64|ResolvesToNumber|float|int $expression 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. + */ + public static function ceil(Decimal128|Int64|ResolvesToNumber|float|int $expression): CeilAggregation + { + return new CeilAggregation($expression); } /** * @param ExpressionInterface|mixed $expression1 * @param ExpressionInterface|mixed $expression2 */ - public static function ne(mixed $expression1, mixed $expression2): NeAggregation + public static function cmp(mixed $expression1, mixed $expression2): CmpAggregation { - return new NeAggregation($expression1, $expression2); + return new CmpAggregation($expression1, $expression2); + } + + /** + * @param ResolvesToString|non-empty-string ...$expression + */ + public static function concat(ResolvesToString|string ...$expression): ConcatAggregation + { + return new ConcatAggregation(...$expression); + } + + /** + * @param BSONArray|PackedArray|ResolvesToArray|list ...$array + */ + public static function concatArrays( + PackedArray|ResolvesToArray|BSONArray|array ...$array, + ): ConcatArraysAggregation + { + return new ConcatArraysAggregation(...$array); + } + + /** + * @param ResolvesToBool|bool $if + * @param ExpressionInterface|mixed $then + * @param ExpressionInterface|mixed $else + */ + public static function cond(ResolvesToBool|bool $if, mixed $then, mixed $else): CondAggregation + { + return new CondAggregation($if, $then, $else); + } + + /** + * @param ExpressionInterface|mixed $input + * @param Int64|ResolvesToInt|ResolvesToString|int|non-empty-string $to + * @param ExpressionInterface|Optional|mixed $onError 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. + * @param ExpressionInterface|Optional|mixed $onNull 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. + */ + public static function convert( + mixed $input, + Int64|ResolvesToInt|ResolvesToString|int|string $to, + mixed $onError = Optional::Undefined, + mixed $onNull = Optional::Undefined, + ): ConvertAggregation + { + return new ConvertAggregation($input, $to, $onError, $onNull); + } + + /** + * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $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. + */ + public static function cos(Decimal128|Int64|ResolvesToNumber|float|int $expression): CosAggregation + { + return new CosAggregation($expression); + } + + /** + * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $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. + */ + public static function cosh(Decimal128|Int64|ResolvesToNumber|float|int $expression): CoshAggregation + { + return new CoshAggregation($expression); + } + + /** + * @param non-empty-string $field + */ + public static function count(string $field): CountAggregation + { + return new CountAggregation($field); + } + + /** + * @param Decimal128|Int64|ResolvesToNumber|float|int $expression1 + * @param Decimal128|Int64|ResolvesToNumber|float|int $expression2 + */ + public static function covariancePop( + Decimal128|Int64|ResolvesToNumber|float|int $expression1, + Decimal128|Int64|ResolvesToNumber|float|int $expression2, + ): CovariancePopAggregation + { + return new CovariancePopAggregation($expression1, $expression2); + } + + /** + * @param Decimal128|Int64|ResolvesToNumber|float|int $expression1 + * @param Decimal128|Int64|ResolvesToNumber|float|int $expression2 + */ + public static function covarianceSamp( + Decimal128|Int64|ResolvesToNumber|float|int $expression1, + Decimal128|Int64|ResolvesToNumber|float|int $expression2, + ): CovarianceSampAggregation + { + return new CovarianceSampAggregation($expression1, $expression2); + } + + /** + * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $startDate 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. + * @param ResolvesToString|non-empty-string $unit The unit used to measure the amount of time added to the startDate. + * @param Int64|ResolvesToInt|ResolvesToLong|int $amount + * @param Optional|ResolvesToString|non-empty-string $timezone 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. + */ + public static function dateAdd( + \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $startDate, + ResolvesToString|string $unit, + Int64|ResolvesToInt|ResolvesToLong|int $amount, + ResolvesToString|Optional|string $timezone = Optional::Undefined, + ): DateAddAggregation + { + return new DateAddAggregation($startDate, $unit, $amount, $timezone); + } + + /** + * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $startDate The start of the time period. The startDate can be any expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $endDate The end of the time period. The endDate can be any expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param ResolvesToString|non-empty-string $unit The time measurement unit between the startDate and endDate + * @param Optional|ResolvesToString|non-empty-string $timezone 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. + * @param Optional|ResolvesToString|non-empty-string $startOfWeek Used when the unit is equal to week. Defaults to Sunday. The startOfWeek parameter is an expression that resolves to a case insensitive string + */ + public static function dateDiff( + \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $startDate, + \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $endDate, + ResolvesToString|string $unit, + ResolvesToString|Optional|string $timezone = Optional::Undefined, + ResolvesToString|Optional|string $startOfWeek = Optional::Undefined, + ): DateDiffAggregation + { + return new DateDiffAggregation($startDate, $endDate, $unit, $timezone, $startOfWeek); + } + + /** + * @param Decimal128|Int64|ResolvesToNumber|float|int $year Calendar year. Can be any expression that evaluates to a number. + * @param Decimal128|Int64|ResolvesToNumber|float|int $isoWeekYear ISO Week Date Year. Can be any expression that evaluates to a number. + * @param Decimal128|Int64|Optional|ResolvesToNumber|float|int $month Month. Defaults to 1. + * @param Decimal128|Int64|Optional|ResolvesToNumber|float|int $isoWeek Week of year. Defaults to 1. + * @param Decimal128|Int64|Optional|ResolvesToNumber|float|int $day Day of month. Defaults to 1. + * @param Decimal128|Int64|Optional|ResolvesToNumber|float|int $isoDayOfWeek Day of week (Monday 1 - Sunday 7). Defaults to 1. + * @param Decimal128|Int64|Optional|ResolvesToNumber|float|int $hour Hour. Defaults to 0. + * @param Decimal128|Int64|Optional|ResolvesToNumber|float|int $minute Minute. Defaults to 0. + * @param Decimal128|Int64|Optional|ResolvesToNumber|float|int $second Second. Defaults to 0. + * @param Decimal128|Int64|Optional|ResolvesToNumber|float|int $millisecond Millisecond. Defaults to 0. + * @param Optional|ResolvesToString|non-empty-string $timezone 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. + */ + public static function dateFromParts( + Decimal128|Int64|ResolvesToNumber|float|int $year, + Decimal128|Int64|ResolvesToNumber|float|int $isoWeekYear, + Decimal128|Int64|ResolvesToNumber|Optional|float|int $month = Optional::Undefined, + Decimal128|Int64|ResolvesToNumber|Optional|float|int $isoWeek = Optional::Undefined, + Decimal128|Int64|ResolvesToNumber|Optional|float|int $day = Optional::Undefined, + Decimal128|Int64|ResolvesToNumber|Optional|float|int $isoDayOfWeek = Optional::Undefined, + Decimal128|Int64|ResolvesToNumber|Optional|float|int $hour = Optional::Undefined, + Decimal128|Int64|ResolvesToNumber|Optional|float|int $minute = Optional::Undefined, + Decimal128|Int64|ResolvesToNumber|Optional|float|int $second = Optional::Undefined, + Decimal128|Int64|ResolvesToNumber|Optional|float|int $millisecond = Optional::Undefined, + ResolvesToString|Optional|string $timezone = Optional::Undefined, + ): DateFromPartsAggregation + { + return new DateFromPartsAggregation($year, $isoWeekYear, $month, $isoWeek, $day, $isoDayOfWeek, $hour, $minute, $second, $millisecond, $timezone); + } + + /** + * @param ResolvesToString|non-empty-string $dateString The date/time string to convert to a date object. + * @param Optional|ResolvesToString|non-empty-string $format 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. + * @param Optional|ResolvesToString|non-empty-string $timezone The time zone to use to format the date. + * @param ExpressionInterface|Optional|mixed $onError 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. + * @param ExpressionInterface|Optional|mixed $onNull 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. + */ + public static function dateFromString( + ResolvesToString|string $dateString, + ResolvesToString|Optional|string $format = Optional::Undefined, + ResolvesToString|Optional|string $timezone = Optional::Undefined, + mixed $onError = Optional::Undefined, + mixed $onNull = Optional::Undefined, + ): DateFromStringAggregation + { + return new DateFromStringAggregation($dateString, $format, $timezone, $onError, $onNull); + } + + /** + * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $startDate 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. + * @param ResolvesToString|non-empty-string $unit The unit used to measure the amount of time added to the startDate. + * @param Int64|ResolvesToInt|ResolvesToLong|int $amount + * @param Optional|ResolvesToString|non-empty-string $timezone 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. + */ + public static function dateSubtract( + \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $startDate, + ResolvesToString|string $unit, + Int64|ResolvesToInt|ResolvesToLong|int $amount, + ResolvesToString|Optional|string $timezone = Optional::Undefined, + ): DateSubtractAggregation + { + return new DateSubtractAggregation($startDate, $unit, $amount, $timezone); + } + + /** + * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The input date for which to return parts. date can be any expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param Optional|ResolvesToString|non-empty-string $timezone 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. + * @param Optional|bool $iso8601 If set to true, modifies the output document to use ISO week date fields. Defaults to false. + */ + public static function dateToParts( + \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + ResolvesToString|Optional|string $timezone = Optional::Undefined, + Optional|bool $iso8601 = Optional::Undefined, + ): DateToPartsAggregation + { + return new DateToPartsAggregation($date, $timezone, $iso8601); + } + + /** + * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to convert to string. Must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param Optional|ResolvesToString|non-empty-string $format 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. + * @param Optional|ResolvesToString|non-empty-string $timezone The time zone to use to format the date. + * @param ExpressionInterface|Optional|mixed $onNull The value to return if the date is null or missing. + * If unspecified, $dateToString returns null if the date is null or missing. + */ + public static function dateToString( + \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + ResolvesToString|Optional|string $format = Optional::Undefined, + ResolvesToString|Optional|string $timezone = Optional::Undefined, + mixed $onNull = Optional::Undefined, + ): DateToStringAggregation + { + return new DateToStringAggregation($date, $format, $timezone, $onNull); + } + + /** + * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to truncate, specified in UTC. The date can be any expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param ResolvesToString|non-empty-string $unit 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. + * @param Decimal128|Int64|Optional|ResolvesToNumber|float|int $binSize 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. + * @param Optional|ResolvesToString|non-empty-string $timezone 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. + * @param Optional|non-empty-string $startOfWeek The start of the week. Used when + * unit is week. Defaults to Sunday. + */ + public static function dateTrunc( + \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + ResolvesToString|string $unit, + Decimal128|Int64|ResolvesToNumber|Optional|float|int $binSize = Optional::Undefined, + ResolvesToString|Optional|string $timezone = Optional::Undefined, + Optional|string $startOfWeek = Optional::Undefined, + ): DateTruncAggregation + { + return new DateTruncAggregation($date, $unit, $binSize, $timezone, $startOfWeek); + } + + /** + * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param Optional|ResolvesToString|non-empty-string $timezone 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. + */ + public static function dayOfMonth( + \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + ResolvesToString|Optional|string $timezone = Optional::Undefined, + ): DayOfMonthAggregation + { + return new DayOfMonthAggregation($date, $timezone); + } + + /** + * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param Optional|ResolvesToString|non-empty-string $timezone 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. + */ + public static function dayOfWeek( + \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + ResolvesToString|Optional|string $timezone = Optional::Undefined, + ): DayOfWeekAggregation + { + return new DayOfWeekAggregation($date, $timezone); + } + + /** + * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param Optional|ResolvesToString|non-empty-string $timezone 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. + */ + public static function dayOfYear( + \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + ResolvesToString|Optional|string $timezone = Optional::Undefined, + ): DayOfYearAggregation + { + return new DayOfYearAggregation($date, $timezone); + } + + /** + * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $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. + */ + public static function degreesToRadians( + Decimal128|Int64|ResolvesToNumber|float|int $expression, + ): DegreesToRadiansAggregation + { + return new DegreesToRadiansAggregation($expression); + } + + public static function denseRank(): DenseRankAggregation + { + return new DenseRankAggregation(); + } + + /** + * @param DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int $input + * @param Optional|non-empty-string $unit 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. + */ + public static function derivative( + \UTCDateTime|DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|float|int $input, + Optional|string $unit = Optional::Undefined, + ): DerivativeAggregation + { + return new DerivativeAggregation($input, $unit); + } + + /** + * @param Decimal128|Int64|ResolvesToNumber|float|int $dividend The first argument is the dividend, and the second argument is the divisor; i.e. the first argument is divided by the second argument. + * @param Decimal128|Int64|ResolvesToNumber|float|int $divisor + */ + public static function divide( + Decimal128|Int64|ResolvesToNumber|float|int $dividend, + Decimal128|Int64|ResolvesToNumber|float|int $divisor, + ): DivideAggregation + { + return new DivideAggregation($dividend, $divisor); + } + + public static function documentNumber(): DocumentNumberAggregation + { + return new DocumentNumberAggregation(); } /** * @param ExpressionInterface|mixed $expression1 * @param ExpressionInterface|mixed $expression2 */ - public static function subtract(mixed $expression1, mixed $expression2): SubtractAggregation + public static function eq(mixed $expression1, mixed $expression2): EqAggregation { - return new SubtractAggregation($expression1, $expression2); + return new EqAggregation($expression1, $expression2); + } + + /** + * @param Decimal128|Int64|ResolvesToNumber|float|int $exponent + */ + public static function exp(Decimal128|Int64|ResolvesToNumber|float|int $exponent): ExpAggregation + { + return new ExpAggregation($exponent); + } + + /** + * @param Decimal128|Int64|ResolvesToNumber|float|int $input + * @param Int64|Optional|int $N 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: + * @param Int64|Optional|float|int $alpha 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. + */ + public static function expMovingAvg( + Decimal128|Int64|ResolvesToNumber|float|int $input, + Int64|Optional|int $N = Optional::Undefined, + Int64|Optional|float|int $alpha = Optional::Undefined, + ): ExpMovingAvgAggregation + { + return new ExpMovingAvgAggregation($input, $N, $alpha); + } + + /** + * @param BSONArray|PackedArray|ResolvesToArray|list $input + * @param ResolvesToBool|bool $cond 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. + * @param Optional|non-empty-string $as 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. + * @param Int64|Optional|ResolvesToInt|int $limit 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. + */ + public static function filter( + PackedArray|ResolvesToArray|BSONArray|array $input, + ResolvesToBool|bool $cond, + Optional|string $as = Optional::Undefined, + Int64|ResolvesToInt|Optional|int $limit = Optional::Undefined, + ): FilterAggregation + { + return new FilterAggregation($input, $cond, $as, $limit); } /** * @param ExpressionInterface|mixed $expression */ - public static function sum(mixed $expression): SumAggregation + public static function first(mixed $expression): FirstAggregation + { + return new FirstAggregation($expression); + } + + /** + * @param BSONArray|PackedArray|ResolvesToArray|list $input An expression that resolves to the array from which to return n elements. + * @param Int64|ResolvesToInt|int $n An expression that resolves to a positive integer. The integer specifies the number of array elements that $firstN returns. + */ + public static function firstN( + PackedArray|ResolvesToArray|BSONArray|array $input, + Int64|ResolvesToInt|int $n, + ): FirstNAggregation + { + return new FirstNAggregation($input, $n); + } + + /** + * @param Decimal128|Int64|ResolvesToNumber|float|int $expression + */ + public static function floor(Decimal128|Int64|ResolvesToNumber|float|int $expression): FloorAggregation + { + return new FloorAggregation($expression); + } + + /** + * @param non-empty-string $body The function definition. You can specify the function definition as either BSON type Code or String. + * @param BSONArray|PackedArray|list $args Arguments passed to the function body. If the body function does not take an argument, you can specify an empty array [ ]. + * @param non-empty-string $lang + */ + public static function function( + string $body, + PackedArray|BSONArray|array $args, + string $lang, + ): FunctionAggregation + { + return new FunctionAggregation($body, $args, $lang); + } + + /** + * @param non-empty-string $field 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. + * @param ExpressionInterface|Optional|mixed $input 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). + */ + public static function getField(string $field, mixed $input = Optional::Undefined): GetFieldAggregation + { + return new GetFieldAggregation($field, $input); + } + + /** + * @param ExpressionInterface|mixed $expression1 + * @param ExpressionInterface|mixed $expression2 + */ + public static function gt(mixed $expression1, mixed $expression2): GtAggregation + { + return new GtAggregation($expression1, $expression2); + } + + /** + * @param ExpressionInterface|mixed $expression1 + * @param ExpressionInterface|mixed $expression2 + */ + public static function gte(mixed $expression1, mixed $expression2): GteAggregation + { + return new GteAggregation($expression1, $expression2); + } + + /** + * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param Optional|ResolvesToString|non-empty-string $timezone 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. + */ + public static function hour( + \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + ResolvesToString|Optional|string $timezone = Optional::Undefined, + ): HourAggregation + { + return new HourAggregation($date, $timezone); + } + + /** + * @param ExpressionInterface|mixed ...$expression + */ + public static function ifNull(mixed ...$expression): IfNullAggregation + { + return new IfNullAggregation(...$expression); + } + + /** + * @param ExpressionInterface|mixed $expression Any valid expression expression. + * @param BSONArray|PackedArray|ResolvesToArray|list $array Any valid expression that resolves to an array. + */ + public static function in(mixed $expression, PackedArray|ResolvesToArray|BSONArray|array $array): InAggregation + { + return new InAggregation($expression, $array); + } + + /** + * @param ResolvesToString|non-empty-string $array 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. + * @param ExpressionInterface|mixed $search + * @param Int64|Optional|ResolvesToInt|int $start 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. + * @param Int64|Optional|ResolvesToInt|int $end 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. + */ + public static function indexOfArray( + ResolvesToString|string $array, + mixed $search, + Int64|ResolvesToInt|Optional|int $start = Optional::Undefined, + Int64|ResolvesToInt|Optional|int $end = Optional::Undefined, + ): IndexOfArrayAggregation + { + return new IndexOfArrayAggregation($array, $search, $start, $end); + } + + /** + * @param ResolvesToString|non-empty-string $string 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. + * @param ResolvesToString|non-empty-string $substring Can be any valid expression as long as it resolves to a string. + * @param Int64|Optional|ResolvesToInt|int $start 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. + * @param Int64|Optional|ResolvesToInt|int $end 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. + */ + public static function indexOfBytes( + ResolvesToString|string $string, + ResolvesToString|string $substring, + Int64|ResolvesToInt|Optional|int $start = Optional::Undefined, + Int64|ResolvesToInt|Optional|int $end = Optional::Undefined, + ): IndexOfBytesAggregation + { + return new IndexOfBytesAggregation($string, $substring, $start, $end); + } + + /** + * @param ResolvesToString|non-empty-string $string 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. + * @param ResolvesToString|non-empty-string $substring Can be any valid expression as long as it resolves to a string. + * @param Int64|Optional|ResolvesToInt|int $start 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. + * @param Int64|Optional|ResolvesToInt|int $end 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. + */ + public static function indexOfCP( + ResolvesToString|string $string, + ResolvesToString|string $substring, + Int64|ResolvesToInt|Optional|int $start = Optional::Undefined, + Int64|ResolvesToInt|Optional|int $end = Optional::Undefined, + ): IndexOfCPAggregation + { + return new IndexOfCPAggregation($string, $substring, $start, $end); + } + + /** + * @param DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int $input + * @param Optional|ResolvesToString|non-empty-string $unit 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. + */ + public static function integral( + \UTCDateTime|DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|float|int $input, + ResolvesToString|Optional|string $unit = Optional::Undefined, + ): IntegralAggregation + { + return new IntegralAggregation($input, $unit); + } + + /** + * @param ExpressionInterface|mixed ...$expression + */ + public static function isArray(mixed ...$expression): IsArrayAggregation + { + return new IsArrayAggregation(...$expression); + } + + /** + * @param ExpressionInterface|mixed ...$expression + */ + public static function isNumber(mixed ...$expression): IsNumberAggregation + { + return new IsNumberAggregation(...$expression); + } + + /** + * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param Optional|ResolvesToString|non-empty-string $timezone 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. + */ + public static function isoDayOfWeek( + \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + ResolvesToString|Optional|string $timezone = Optional::Undefined, + ): IsoDayOfWeekAggregation + { + return new IsoDayOfWeekAggregation($date, $timezone); + } + + /** + * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param Optional|ResolvesToString|non-empty-string $timezone 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. + */ + public static function isoWeek( + \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + ResolvesToString|Optional|string $timezone = Optional::Undefined, + ): IsoWeekAggregation + { + return new IsoWeekAggregation($date, $timezone); + } + + /** + * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param Optional|ResolvesToString|non-empty-string $timezone 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. + */ + public static function isoWeekYear( + \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + ResolvesToString|Optional|string $timezone = Optional::Undefined, + ): IsoWeekYearAggregation + { + return new IsoWeekYearAggregation($date, $timezone); + } + + /** + * @param ExpressionInterface|mixed $expression + */ + public static function last(mixed $expression): LastAggregation + { + return new LastAggregation($expression); + } + + /** + * @param BSONArray|PackedArray|ResolvesToArray|list $input An expression that resolves to the array from which to return n elements. + * @param Int64|ResolvesToInt|int $n An expression that resolves to a positive integer. The integer specifies the number of array elements that $firstN returns. + */ + public static function lastN( + PackedArray|ResolvesToArray|BSONArray|array $input, + Int64|ResolvesToInt|int $n, + ): LastNAggregation + { + return new LastNAggregation($input, $n); + } + + /** + * @param Document|Serializable|array|object $vars 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. + * @param ExpressionInterface|mixed $in The expression to evaluate. + */ + public static function let(array|object $vars, mixed $in): LetAggregation + { + return new LetAggregation($vars, $in); + } + + /** + * @param Decimal128|Int64|ResolvesToNumber|float|int $expression + */ + public static function linearFill(Decimal128|Int64|ResolvesToNumber|float|int $expression): LinearFillAggregation + { + return new LinearFillAggregation($expression); + } + + /** + * @param mixed $value If the value is an expression, $literal does not evaluate the expression but instead returns the unparsed expression. + */ + public static function literal(mixed $value): LiteralAggregation + { + return new LiteralAggregation($value); + } + + /** + * @param Decimal128|Int64|ResolvesToNumber|float|int $number Any valid expression as long as it resolves to a non-negative number. For more information on expressions, see Expressions. + */ + public static function ln(Decimal128|Int64|ResolvesToNumber|float|int $number): LnAggregation + { + return new LnAggregation($number); + } + + /** + * @param ExpressionInterface|mixed $expression + */ + public static function locf(mixed $expression): LocfAggregation + { + return new LocfAggregation($expression); + } + + /** + * @param Decimal128|Int64|ResolvesToNumber|float|int $number Any valid expression as long as it resolves to a non-negative number. + * @param Decimal128|Int64|ResolvesToNumber|float|int $base Any valid expression as long as it resolves to a positive number greater than 1. + */ + public static function log( + Decimal128|Int64|ResolvesToNumber|float|int $number, + Decimal128|Int64|ResolvesToNumber|float|int $base, + ): LogAggregation + { + return new LogAggregation($number, $base); + } + + /** + * @param Decimal128|Int64|ResolvesToNumber|float|int $number Any valid expression as long as it resolves to a non-negative number. + */ + public static function log10(Decimal128|Int64|ResolvesToNumber|float|int $number): Log10Aggregation + { + return new Log10Aggregation($number); + } + + /** + * @param ExpressionInterface|mixed $expression1 + * @param ExpressionInterface|mixed $expression2 + */ + public static function lt(mixed $expression1, mixed $expression2): LtAggregation + { + return new LtAggregation($expression1, $expression2); + } + + /** + * @param ExpressionInterface|mixed $expression1 + * @param ExpressionInterface|mixed $expression2 + */ + public static function lte(mixed $expression1, mixed $expression2): LteAggregation + { + return new LteAggregation($expression1, $expression2); + } + + /** + * @param ResolvesToString|non-empty-string $input The string to trim. The argument can be any valid expression that resolves to a string. + * @param Optional|ResolvesToString|non-empty-string $chars 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. + */ + public static function ltrim( + ResolvesToString|string $input, + ResolvesToString|Optional|string $chars = Optional::Undefined, + ): LtrimAggregation + { + return new LtrimAggregation($input, $chars); + } + + /** + * @param BSONArray|PackedArray|ResolvesToArray|list $input An expression that resolves to an array. + * @param ExpressionInterface|mixed $in 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. + * @param Optional|ResolvesToString|non-empty-string $as 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. + */ + public static function map( + PackedArray|ResolvesToArray|BSONArray|array $input, + mixed $in, + ResolvesToString|Optional|string $as = Optional::Undefined, + ): MapAggregation + { + return new MapAggregation($input, $in, $as); + } + + /** + * @param ExpressionInterface|mixed ...$expression + */ + public static function max(mixed ...$expression): MaxAggregation + { + return new MaxAggregation(...$expression); + } + + /** + * @param BSONArray|PackedArray|ResolvesToArray|list $input An expression that resolves to the array from which to return the maximal n elements. + * @param Int64|ResolvesToInt|int $n An expression that resolves to a positive integer. The integer specifies the number of array elements that $maxN returns. + */ + public static function maxN( + PackedArray|ResolvesToArray|BSONArray|array $input, + Int64|ResolvesToInt|int $n, + ): MaxNAggregation + { + return new MaxNAggregation($input, $n); + } + + /** + * @param Decimal128|Int64|ResolvesToNumber|float|int $input $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. + * @param non-empty-string $method The method that mongod uses to calculate the 50th percentile value. The method must be 'approximate'. + */ + public static function median( + Decimal128|Int64|ResolvesToNumber|float|int $input, + string $method, + ): MedianAggregation + { + return new MedianAggregation($input, $method); + } + + /** + * @param Document|ResolvesToObject|Serializable|array|object ...$document Any valid expression that resolves to a document. + */ + public static function mergeObjects(array|object ...$document): MergeObjectsAggregation + { + return new MergeObjectsAggregation(...$document); + } + + /** + * @param non-empty-string $keyword + */ + public static function meta(string $keyword): MetaAggregation + { + return new MetaAggregation($keyword); + } + + /** + * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param Optional|ResolvesToString|non-empty-string $timezone 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. + */ + public static function millisecond( + \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + ResolvesToString|Optional|string $timezone = Optional::Undefined, + ): MillisecondAggregation + { + return new MillisecondAggregation($date, $timezone); + } + + /** + * @param ExpressionInterface|mixed ...$expression + */ + public static function min(mixed ...$expression): MinAggregation + { + return new MinAggregation(...$expression); + } + + /** + * @param BSONArray|PackedArray|ResolvesToArray|list $input An expression that resolves to the array from which to return the maximal n elements. + * @param Int64|ResolvesToInt|int $n An expression that resolves to a positive integer. The integer specifies the number of array elements that $maxN returns. + */ + public static function minN( + PackedArray|ResolvesToArray|BSONArray|array $input, + Int64|ResolvesToInt|int $n, + ): MinNAggregation + { + return new MinNAggregation($input, $n); + } + + /** + * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param Optional|ResolvesToString|non-empty-string $timezone 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. + */ + public static function minute( + \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + ResolvesToString|Optional|string $timezone = Optional::Undefined, + ): MinuteAggregation + { + return new MinuteAggregation($date, $timezone); + } + + /** + * @param Decimal128|Int64|ResolvesToNumber|float|int $dividend The first argument is the dividend, and the second argument is the divisor; i.e. first argument is divided by the second argument. + * @param Decimal128|Int64|ResolvesToNumber|float|int $divisor + */ + public static function mod( + Decimal128|Int64|ResolvesToNumber|float|int $dividend, + Decimal128|Int64|ResolvesToNumber|float|int $divisor, + ): ModAggregation + { + return new ModAggregation($dividend, $divisor); + } + + /** + * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param Optional|ResolvesToString|non-empty-string $timezone 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. + */ + public static function month( + \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + ResolvesToString|Optional|string $timezone = Optional::Undefined, + ): MonthAggregation + { + return new MonthAggregation($date, $timezone); + } + + /** + * @param Decimal128|Int64|ResolvesToNumber|float|int ...$expression 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. + */ + public static function multiply(Decimal128|Int64|ResolvesToNumber|float|int ...$expression): MultiplyAggregation + { + return new MultiplyAggregation(...$expression); + } + + /** + * @param ExpressionInterface|mixed $expression1 + * @param ExpressionInterface|mixed $expression2 + */ + public static function ne(mixed $expression1, mixed $expression2): NeAggregation + { + return new NeAggregation($expression1, $expression2); + } + + /** + * @param ExpressionInterface|ResolvesToBool|bool|mixed $expression + */ + public static function not(mixed $expression): NotAggregation + { + return new NotAggregation($expression); + } + + /** + * @param Document|ResolvesToObject|Serializable|array|object $object 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. + */ + public static function objectToArray(array|object $object): ObjectToArrayAggregation + { + return new ObjectToArrayAggregation($object); + } + + /** + * @param ExpressionInterface|ResolvesToBool|bool|mixed ...$expression + */ + public static function or(mixed ...$expression): OrAggregation + { + return new OrAggregation(...$expression); + } + + /** + * @param Decimal128|Int64|ResolvesToNumber|float|int $input $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. + * @param BSONArray|PackedArray|ResolvesToArray|list $p $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. + * @param non-empty-string $method The method that mongod uses to calculate the percentile value. The method must be 'approximate'. + */ + public static function percentile( + Decimal128|Int64|ResolvesToNumber|float|int $input, + PackedArray|ResolvesToArray|BSONArray|array $p, + string $method, + ): PercentileAggregation + { + return new PercentileAggregation($input, $p, $method); + } + + /** + * @param Decimal128|Int64|ResolvesToNumber|float|int $number + * @param Decimal128|Int64|ResolvesToNumber|float|int $exponent + */ + public static function pow( + Decimal128|Int64|ResolvesToNumber|float|int $number, + Decimal128|Int64|ResolvesToNumber|float|int $exponent, + ): PowAggregation + { + return new PowAggregation($number, $exponent); + } + + /** + * @param ExpressionInterface|mixed $expression + */ + public static function push(mixed $expression): PushAggregation + { + return new PushAggregation($expression); + } + + /** + * @param Decimal128|Int64|ResolvesToNumber|float|int $expression + */ + public static function radiansToDegrees( + Decimal128|Int64|ResolvesToNumber|float|int $expression, + ): RadiansToDegreesAggregation + { + return new RadiansToDegreesAggregation($expression); + } + + public static function rand(): RandAggregation + { + return new RandAggregation(); + } + + /** + * @param Int64|ResolvesToInt|int $start An integer that specifies the start of the sequence. Can be any valid expression that resolves to an integer. + * @param Int64|ResolvesToInt|int $end An integer that specifies the exclusive upper limit of the sequence. Can be any valid expression that resolves to an integer. + * @param Int64|Optional|ResolvesToInt|int $step An integer that specifies the increment value. Can be any valid expression that resolves to a non-zero integer. Defaults to 1. + */ + public static function range( + Int64|ResolvesToInt|int $start, + Int64|ResolvesToInt|int $end, + Int64|ResolvesToInt|Optional|int $step = Optional::Undefined, + ): RangeAggregation + { + return new RangeAggregation($start, $end, $step); + } + + public static function rank(): RankAggregation + { + return new RankAggregation(); + } + + /** + * @param BSONArray|PackedArray|ResolvesToArray|list $input 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. + * @param ExpressionInterface|mixed $initialValue The initial cumulative value set before in is applied to the first element of the input array. + * @param ExpressionInterface|mixed $in 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. + */ + public static function reduce( + PackedArray|ResolvesToArray|BSONArray|array $input, + mixed $initialValue, + mixed $in, + ): ReduceAggregation + { + return new ReduceAggregation($input, $initialValue, $in); + } + + /** + * @param ResolvesToString|non-empty-string $input The string on which you wish to apply the regex pattern. Can be a string or any valid expression that resolves to a string. + * @param Regex|ResolvesToString|non-empty-string $regex 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) + * @param Optional|non-empty-string $options + */ + public static function regexFind( + ResolvesToString|string $input, + Regex|ResolvesToString|string $regex, + Optional|string $options = Optional::Undefined, + ): RegexFindAggregation + { + return new RegexFindAggregation($input, $regex, $options); + } + + /** + * @param ResolvesToString|non-empty-string $input The string on which you wish to apply the regex pattern. Can be a string or any valid expression that resolves to a string. + * @param Regex|ResolvesToString|non-empty-string $regex 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) + * @param Optional|non-empty-string $options + */ + public static function regexFindAll( + ResolvesToString|string $input, + Regex|ResolvesToString|string $regex, + Optional|string $options = Optional::Undefined, + ): RegexFindAllAggregation + { + return new RegexFindAllAggregation($input, $regex, $options); + } + + /** + * @param ResolvesToString|non-empty-string $input The string on which you wish to apply the regex pattern. Can be a string or any valid expression that resolves to a string. + * @param Regex|ResolvesToString|non-empty-string $regex 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) + * @param Optional|non-empty-string $options + */ + public static function regexMatch( + ResolvesToString|string $input, + Regex|ResolvesToString|string $regex, + Optional|string $options = Optional::Undefined, + ): RegexMatchAggregation + { + return new RegexMatchAggregation($input, $regex, $options); + } + + /** + * @param ResolvesToNull|ResolvesToString|non-empty-string|null $input 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. + * @param ResolvesToNull|ResolvesToString|non-empty-string|null $find 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. + * @param ResolvesToNull|ResolvesToString|non-empty-string|null $replacement 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. + */ + public static function replaceAll( + ResolvesToNull|ResolvesToString|null|string $input, + ResolvesToNull|ResolvesToString|null|string $find, + ResolvesToNull|ResolvesToString|null|string $replacement, + ): ReplaceAllAggregation + { + return new ReplaceAllAggregation($input, $find, $replacement); + } + + /** + * @param ResolvesToNull|ResolvesToString|non-empty-string|null $input 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. + * @param ResolvesToNull|ResolvesToString|non-empty-string|null $find 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. + * @param ResolvesToNull|ResolvesToString|non-empty-string|null $replacement 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. + */ + public static function replaceOne( + ResolvesToNull|ResolvesToString|null|string $input, + ResolvesToNull|ResolvesToString|null|string $find, + ResolvesToNull|ResolvesToString|null|string $replacement, + ): ReplaceOneAggregation + { + return new ReplaceOneAggregation($input, $find, $replacement); + } + + /** + * @param BSONArray|PackedArray|ResolvesToArray|list $expression The argument can be any valid expression as long as it resolves to an array. + */ + public static function reverseArray( + PackedArray|ResolvesToArray|BSONArray|array $expression, + ): ReverseArrayAggregation + { + return new ReverseArrayAggregation($expression); + } + + /** + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|float|int $number 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. + * @param Int64|Optional|ResolvesToInt|int $place Can be any valid expression that resolves to an integer between -20 and 100, exclusive. + */ + public static function round( + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|float|int $number, + Int64|ResolvesToInt|Optional|int $place = Optional::Undefined, + ): RoundAggregation + { + return new RoundAggregation($number, $place); + } + + /** + * @param ResolvesToString|non-empty-string $input The string to trim. The argument can be any valid expression that resolves to a string. + * @param Optional|ResolvesToString|non-empty-string $chars 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. + */ + public static function rtrim( + ResolvesToString|string $input, + ResolvesToString|Optional|string $chars = Optional::Undefined, + ): RtrimAggregation + { + return new RtrimAggregation($input, $chars); + } + + /** + * @param Int64|ResolvesToFloat|float|int $rate 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. + */ + public static function sampleRate(Int64|ResolvesToFloat|float|int $rate): SampleRateAggregation + { + return new SampleRateAggregation($rate); + } + + /** + * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param Optional|ResolvesToString|non-empty-string $timezone 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. + */ + public static function second( + \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + ResolvesToString|Optional|string $timezone = Optional::Undefined, + ): SecondAggregation + { + return new SecondAggregation($date, $timezone); + } + + /** + * @param BSONArray|PackedArray|ResolvesToArray|list $expression1 The arguments can be any valid expression as long as they each resolve to an array. + * @param BSONArray|PackedArray|ResolvesToArray|list $expression2 The arguments can be any valid expression as long as they each resolve to an array. + */ + public static function setDifference( + PackedArray|ResolvesToArray|BSONArray|array $expression1, + PackedArray|ResolvesToArray|BSONArray|array $expression2, + ): SetDifferenceAggregation + { + return new SetDifferenceAggregation($expression1, $expression2); + } + + /** + * @param BSONArray|PackedArray|ResolvesToArray|list ...$expression + */ + public static function setEquals(PackedArray|ResolvesToArray|BSONArray|array ...$expression): SetEqualsAggregation + { + return new SetEqualsAggregation(...$expression); + } + + /** + * @param ResolvesToString|non-empty-string $field 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. + * @param Document|ResolvesToObject|Serializable|array|object $input Document that contains the field that you want to add or update. input must resolve to an object, missing, null, or undefined. + * @param ExpressionInterface|mixed $value 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. + */ + public static function setField( + ResolvesToString|string $field, + array|object $input, + mixed $value, + ): SetFieldAggregation + { + return new SetFieldAggregation($field, $input, $value); + } + + /** + * @param BSONArray|PackedArray|ResolvesToArray|list ...$expression + */ + public static function setIntersection( + PackedArray|ResolvesToArray|BSONArray|array ...$expression, + ): SetIntersectionAggregation + { + return new SetIntersectionAggregation(...$expression); + } + + /** + * @param BSONArray|PackedArray|ResolvesToArray|list $expression1 + * @param BSONArray|PackedArray|ResolvesToArray|list $expression2 + */ + public static function setIsSubset( + PackedArray|ResolvesToArray|BSONArray|array $expression1, + PackedArray|ResolvesToArray|BSONArray|array $expression2, + ): SetIsSubsetAggregation + { + return new SetIsSubsetAggregation($expression1, $expression2); + } + + /** + * @param BSONArray|PackedArray|ResolvesToArray|list ...$expression + */ + public static function setUnion(PackedArray|ResolvesToArray|BSONArray|array ...$expression): SetUnionAggregation + { + return new SetUnionAggregation(...$expression); + } + + /** + * @param ExpressionInterface|mixed $output Specifies an expression to evaluate and return in the output. + * @param Int64|int $by 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. + * @param ExpressionInterface|mixed $default 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. + */ + public static function shift(mixed $output, Int64|int $by, mixed $default): ShiftAggregation + { + return new ShiftAggregation($output, $by, $default); + } + + /** + * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $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. + */ + public static function sin(Decimal128|Int64|ResolvesToNumber|float|int $expression): SinAggregation + { + return new SinAggregation($expression); + } + + /** + * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $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. + */ + public static function sinh(Decimal128|Int64|ResolvesToNumber|float|int $expression): SinhAggregation + { + return new SinhAggregation($expression); + } + + /** + * @param BSONArray|PackedArray|ResolvesToArray|list $expression The argument for $size can be any expression as long as it resolves to an array. + */ + public static function size(PackedArray|ResolvesToArray|BSONArray|array $expression): SizeAggregation + { + return new SizeAggregation($expression); + } + + /** + * @param BSONArray|PackedArray|ResolvesToArray|list $expression Any valid expression as long as it resolves to an array. + * @param Int64|ResolvesToInt|int $n 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. + * @param Int64|Optional|ResolvesToInt|int $position 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. + */ + public static function slice( + PackedArray|ResolvesToArray|BSONArray|array $expression, + Int64|ResolvesToInt|int $n, + Int64|ResolvesToInt|Optional|int $position = Optional::Undefined, + ): SliceAggregation + { + return new SliceAggregation($expression, $n, $position); + } + + /** + * @param BSONArray|PackedArray|ResolvesToArray|list $input The array to be sorted. + * @param array|object $sortBy The document specifies a sort ordering. + */ + public static function sortArray( + PackedArray|ResolvesToArray|BSONArray|array $input, + array|object $sortBy, + ): SortArrayAggregation + { + return new SortArrayAggregation($input, $sortBy); + } + + /** + * @param ResolvesToString|non-empty-string $string The string to be split. string expression can be any valid expression as long as it resolves to a string. + * @param ResolvesToString|non-empty-string $delimiter The delimiter to use when splitting the string expression. delimiter can be any valid expression as long as it resolves to a string. + */ + public static function split( + ResolvesToString|string $string, + ResolvesToString|string $delimiter, + ): SplitAggregation + { + return new SplitAggregation($string, $delimiter); + } + + /** + * @param Decimal128|Int64|ResolvesToNumber|float|int $number The argument can be any valid expression as long as it resolves to a non-negative number. + */ + public static function sqrt(Decimal128|Int64|ResolvesToNumber|float|int $number): SqrtAggregation + { + return new SqrtAggregation($number); + } + + /** + * @param Decimal128|Int64|ResolvesToNumber|float|int ...$expression + */ + public static function stdDevPop(Decimal128|Int64|ResolvesToNumber|float|int ...$expression): StdDevPopAggregation + { + return new StdDevPopAggregation(...$expression); + } + + /** + * @param Decimal128|Int64|ResolvesToNumber|float|int ...$expression + */ + public static function stdDevSamp( + Decimal128|Int64|ResolvesToNumber|float|int ...$expression, + ): StdDevSampAggregation + { + return new StdDevSampAggregation(...$expression); + } + + /** + * @param ResolvesToString|non-empty-string $expression + */ + public static function strLenBytes(ResolvesToString|string $expression): StrLenBytesAggregation + { + return new StrLenBytesAggregation($expression); + } + + /** + * @param ResolvesToString|non-empty-string $expression + */ + public static function strLenCP(ResolvesToString|string $expression): StrLenCPAggregation + { + return new StrLenCPAggregation($expression); + } + + /** + * @param ResolvesToString|non-empty-string $expression1 + * @param ResolvesToString|non-empty-string $expression2 + */ + public static function strcasecmp( + ResolvesToString|string $expression1, + ResolvesToString|string $expression2, + ): StrcasecmpAggregation + { + return new StrcasecmpAggregation($expression1, $expression2); + } + + /** + * @param ResolvesToString|non-empty-string $string + * @param Int64|ResolvesToInt|int $start If start is a negative number, $substr returns an empty string "". + * @param Int64|ResolvesToInt|int $length If length is a negative number, $substr returns a substring that starts at the specified index and includes the rest of the string. + */ + public static function substr( + ResolvesToString|string $string, + Int64|ResolvesToInt|int $start, + Int64|ResolvesToInt|int $length, + ): SubstrAggregation + { + return new SubstrAggregation($string, $start, $length); + } + + /** + * @param ResolvesToString|non-empty-string $string + * @param Int64|ResolvesToInt|int $start If start is a negative number, $substr returns an empty string "". + * @param Int64|ResolvesToInt|int $length If length is a negative number, $substr returns a substring that starts at the specified index and includes the rest of the string. + */ + public static function substrBytes( + ResolvesToString|string $string, + Int64|ResolvesToInt|int $start, + Int64|ResolvesToInt|int $length, + ): SubstrBytesAggregation + { + return new SubstrBytesAggregation($string, $start, $length); + } + + /** + * @param ResolvesToString|non-empty-string $string + * @param Int64|ResolvesToInt|int $start If start is a negative number, $substr returns an empty string "". + * @param Int64|ResolvesToInt|int $length If length is a negative number, $substr returns a substring that starts at the specified index and includes the rest of the string. + */ + public static function substrCP( + ResolvesToString|string $string, + Int64|ResolvesToInt|int $start, + Int64|ResolvesToInt|int $length, + ): SubstrCPAggregation + { + return new SubstrCPAggregation($string, $start, $length); + } + + /** + * @param DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int $expression1 + * @param DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int $expression2 + */ + public static function subtract( + \UTCDateTime|DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|float|int $expression1, + \UTCDateTime|DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|float|int $expression2, + ): SubtractAggregation + { + return new SubtractAggregation($expression1, $expression2); + } + + /** + * @param Decimal128|Int64|ResolvesToNumber|float|int ...$expression + */ + public static function sum(Decimal128|Int64|ResolvesToNumber|float|int ...$expression): SumAggregation + { + return new SumAggregation(...$expression); + } + + /** + * @param BSONArray|PackedArray|list $branches 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. + * @param ExpressionInterface|Optional|mixed $default 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. + */ + public static function switch( + PackedArray|BSONArray|array $branches, + mixed $default = Optional::Undefined, + ): SwitchAggregation + { + return new SwitchAggregation($branches, $default); + } + + /** + * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $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. + */ + public static function tan(Decimal128|Int64|ResolvesToNumber|float|int $expression): TanAggregation + { + return new TanAggregation($expression); + } + + /** + * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $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. + */ + public static function tanh(Decimal128|Int64|ResolvesToNumber|float|int $expression): TanhAggregation + { + return new TanhAggregation($expression); + } + + /** + * @param ExpressionInterface|mixed $expression + */ + public static function toBool(mixed $expression): ToBoolAggregation + { + return new ToBoolAggregation($expression); + } + + /** + * @param ExpressionInterface|mixed $expression + */ + public static function toDate(mixed $expression): ToDateAggregation + { + return new ToDateAggregation($expression); + } + + /** + * @param ExpressionInterface|mixed $expression + */ + public static function toDecimal(mixed $expression): ToDecimalAggregation + { + return new ToDecimalAggregation($expression); + } + + /** + * @param ExpressionInterface|mixed $expression + */ + public static function toDouble(mixed $expression): ToDoubleAggregation + { + return new ToDoubleAggregation($expression); + } + + /** + * @param ExpressionInterface|mixed $expression + */ + public static function toInt(mixed $expression): ToIntAggregation + { + return new ToIntAggregation($expression); + } + + /** + * @param ExpressionInterface|mixed $expression + */ + public static function toLong(mixed $expression): ToLongAggregation + { + return new ToLongAggregation($expression); + } + + /** + * @param ResolvesToString|non-empty-string $expression + */ + public static function toLower(ResolvesToString|string $expression): ToLowerAggregation + { + return new ToLowerAggregation($expression); + } + + /** + * @param ExpressionInterface|mixed $expression + */ + public static function toObjectId(mixed $expression): ToObjectIdAggregation + { + return new ToObjectIdAggregation($expression); + } + + /** + * @param ExpressionInterface|mixed $expression + */ + public static function toString(mixed $expression): ToStringAggregation + { + return new ToStringAggregation($expression); + } + + /** + * @param ResolvesToString|non-empty-string $expression + */ + public static function toUpper(ResolvesToString|string $expression): ToUpperAggregation + { + return new ToUpperAggregation($expression); + } + + /** + * @param array|object $sortBy Specifies the order of results, with syntax similar to $sort. + * @param ExpressionInterface|mixed $output Represents the output for each element in the group and can be any expression. + */ + public static function top(array|object $sortBy, mixed $output): TopAggregation + { + return new TopAggregation($sortBy, $output); + } + + /** + * @param Int64|ResolvesToInt|int $n 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. + * @param array|object $sortBy Specifies the order of results, with syntax similar to $sort. + * @param ExpressionInterface|mixed $output Represents the output for each element in the group and can be any expression. + */ + public static function topN(Int64|ResolvesToInt|int $n, array|object $sortBy, mixed $output): TopNAggregation + { + return new TopNAggregation($n, $sortBy, $output); + } + + /** + * @param ResolvesToString|non-empty-string $input The string to trim. The argument can be any valid expression that resolves to a string. + * @param Optional|ResolvesToString|non-empty-string $chars 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. + */ + public static function trim( + ResolvesToString|string $input, + ResolvesToString|Optional|string $chars = Optional::Undefined, + ): TrimAggregation + { + return new TrimAggregation($input, $chars); + } + + /** + * @param Decimal128|Int64|ResolvesToNumber|float|int $number 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. + * @param Int64|Optional|ResolvesToInt|int $place Can be any valid expression that resolves to an integer between -20 and 100, exclusive. e.g. -20 < place < 100. Defaults to 0. + */ + public static function trunc( + Decimal128|Int64|ResolvesToNumber|float|int $number, + Int64|ResolvesToInt|Optional|int $place = Optional::Undefined, + ): TruncAggregation + { + return new TruncAggregation($number, $place); + } + + /** + * @param Int64|ResolvesToTimestamp|int $expression + */ + public static function tsIncrement(Int64|ResolvesToTimestamp|int $expression): TsIncrementAggregation + { + return new TsIncrementAggregation($expression); + } + + /** + * @param Int64|ResolvesToTimestamp|int $expression + */ + public static function tsSecond(Int64|ResolvesToTimestamp|int $expression): TsSecondAggregation + { + return new TsSecondAggregation($expression); + } + + /** + * @param ExpressionInterface|mixed $expression + */ + public static function type(mixed $expression): TypeAggregation + { + return new TypeAggregation($expression); + } + + /** + * @param ResolvesToString|non-empty-string $field 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. + * @param Document|ResolvesToObject|Serializable|array|object $input Document that contains the field that you want to add or update. input must resolve to an object, missing, null, or undefined. + */ + public static function unsetField(ResolvesToString|string $field, array|object $input): UnsetFieldAggregation + { + return new UnsetFieldAggregation($field, $input); + } + + /** + * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param Optional|ResolvesToString|non-empty-string $timezone 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. + */ + public static function week( + \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + ResolvesToString|Optional|string $timezone = Optional::Undefined, + ): WeekAggregation + { + return new WeekAggregation($date, $timezone); + } + + /** + * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param Optional|ResolvesToString|non-empty-string $timezone 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. + */ + public static function year( + \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + ResolvesToString|Optional|string $timezone = Optional::Undefined, + ): YearAggregation + { + return new YearAggregation($date, $timezone); + } + + /** + * @param BSONArray|PackedArray|ResolvesToArray|list $inputs 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. + * @param bool $useLongestLength 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. + * @param BSONArray|PackedArray|list $defaults 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. + */ + public static function zip( + PackedArray|ResolvesToArray|BSONArray|array $inputs, + bool $useLongestLength, + PackedArray|BSONArray|array $defaults, + ): ZipAggregation { - return new SumAggregation($expression); + return new ZipAggregation($inputs, $useLongestLength, $defaults); } /** diff --git a/src/Builder/Aggregation/AbsAggregation.php b/src/Builder/Aggregation/AbsAggregation.php new file mode 100644 index 000000000..35940f1c6 --- /dev/null +++ b/src/Builder/Aggregation/AbsAggregation.php @@ -0,0 +1,29 @@ +value = $value; + } +} diff --git a/src/Builder/Aggregation/AccumulatorAggregation.php b/src/Builder/Aggregation/AccumulatorAggregation.php new file mode 100644 index 000000000..bb517d4c4 --- /dev/null +++ b/src/Builder/Aggregation/AccumulatorAggregation.php @@ -0,0 +1,74 @@ + $accumulateArgs Arguments passed to the accumulate function. You can use accumulateArgs to specify what field value(s) to pass to the accumulate function. */ + public PackedArray|ResolvesToArray|BSONArray|array $accumulateArgs; + + /** @param non-empty-string $merge 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. */ + public string $merge; + + /** @param non-empty-string $lang The language used in the $accumulator code. */ + public string $lang; + + /** @param BSONArray|Optional|PackedArray|ResolvesToArray|list $initArgs Arguments passed to the init function. */ + public PackedArray|ResolvesToArray|Optional|BSONArray|array $initArgs; + + /** @param Optional|non-empty-string $finalize Function used to update the result of the accumulation. */ + public Optional|string $finalize; + + /** + * @param non-empty-string $init 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. + * @param non-empty-string $accumulate 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. + * @param BSONArray|PackedArray|ResolvesToArray|list $accumulateArgs Arguments passed to the accumulate function. You can use accumulateArgs to specify what field value(s) to pass to the accumulate function. + * @param non-empty-string $merge 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. + * @param non-empty-string $lang The language used in the $accumulator code. + * @param BSONArray|Optional|PackedArray|ResolvesToArray|list $initArgs Arguments passed to the init function. + * @param Optional|non-empty-string $finalize Function used to update the result of the accumulation. + */ + public function __construct( + string $init, + string $accumulate, + PackedArray|ResolvesToArray|BSONArray|array $accumulateArgs, + string $merge, + string $lang, + PackedArray|ResolvesToArray|Optional|BSONArray|array $initArgs = Optional::Undefined, + Optional|string $finalize = Optional::Undefined, + ) { + $this->init = $init; + $this->accumulate = $accumulate; + if (\is_array($accumulateArgs) && ! \array_is_list($accumulateArgs)) { + throw new \InvalidArgumentException('Expected $accumulateArgs argument to be a list, got an associative array.'); + } + $this->accumulateArgs = $accumulateArgs; + $this->merge = $merge; + $this->lang = $lang; + if (\is_array($initArgs) && ! \array_is_list($initArgs)) { + throw new \InvalidArgumentException('Expected $initArgs argument to be a list, got an associative array.'); + } + $this->initArgs = $initArgs; + $this->finalize = $finalize; + } +} diff --git a/src/Builder/Aggregation/AccumulatorInterface.php b/src/Builder/Aggregation/AccumulatorInterface.php new file mode 100644 index 000000000..b537a636b --- /dev/null +++ b/src/Builder/Aggregation/AccumulatorInterface.php @@ -0,0 +1,11 @@ +expression = $expression; + } +} diff --git a/src/Builder/Aggregation/AcoshAggregation.php b/src/Builder/Aggregation/AcoshAggregation.php new file mode 100644 index 000000000..0afe249c5 --- /dev/null +++ b/src/Builder/Aggregation/AcoshAggregation.php @@ -0,0 +1,37 @@ +expression = $expression; + } +} diff --git a/src/Builder/Aggregation/AddAggregation.php b/src/Builder/Aggregation/AddAggregation.php new file mode 100644 index 000000000..b4038990b --- /dev/null +++ b/src/Builder/Aggregation/AddAggregation.php @@ -0,0 +1,38 @@ + ...$expression The arguments can be any valid expression as long as they resolve to either all numbers or to numbers and a date. */ + public array $expression; + + /** + * @param DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int $expression The arguments can be any valid expression as long as they resolve to either all numbers or to numbers and a date. + */ + public function __construct( + \UTCDateTime|DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|float|int ...$expression, + ) { + if (! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression arguments to be a list of DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int, named arguments are not supported'); + } + if (\count($expression) < 1) { + throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); + } + $this->expression = $expression; + } +} diff --git a/src/Builder/Aggregation/AddToSetAggregation.php b/src/Builder/Aggregation/AddToSetAggregation.php new file mode 100644 index 000000000..7f999c4db --- /dev/null +++ b/src/Builder/Aggregation/AddToSetAggregation.php @@ -0,0 +1,28 @@ +expression = $expression; + } +} diff --git a/src/Builder/Aggregation/Aggregation.php b/src/Builder/Aggregation/Aggregation.php new file mode 100644 index 000000000..7ed2f090a --- /dev/null +++ b/src/Builder/Aggregation/Aggregation.php @@ -0,0 +1,42 @@ +date = $date; + $this->timezone = $timezone; + } +} diff --git a/src/Builder/Aggregation/AllElementsTrueAggregation.php b/src/Builder/Aggregation/AllElementsTrueAggregation.php new file mode 100644 index 000000000..c407a014f --- /dev/null +++ b/src/Builder/Aggregation/AllElementsTrueAggregation.php @@ -0,0 +1,37 @@ +> ...$expression */ + public array $expression; + + /** + * @param BSONArray|PackedArray|ResolvesToArray|list $expression + */ + public function __construct(PackedArray|ResolvesToArray|BSONArray|array ...$expression) + { + if (! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression arguments to be a list of BSONArray|PackedArray|ResolvesToArray|list, named arguments are not supported'); + } + if (\count($expression) < 1) { + throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); + } + $this->expression = $expression; + } +} diff --git a/src/Builder/Aggregation/AndAggregation.php b/src/Builder/Aggregation/AndAggregation.php index 54ca6c46c..2346d3c23 100644 --- a/src/Builder/Aggregation/AndAggregation.php +++ b/src/Builder/Aggregation/AndAggregation.php @@ -6,26 +6,34 @@ namespace MongoDB\Builder\Aggregation; +use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Int64; +use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToBool; +use MongoDB\Builder\Expression\ResolvesToNull; +use MongoDB\Builder\Expression\ResolvesToNumber; +use MongoDB\Builder\Expression\ResolvesToString; class AndAggregation implements ResolvesToBool { public const NAME = '$and'; - public const ENCODE = 'single'; + public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param list ...$expressions */ - public array $expressions; + /** @param list ...$expression */ + public array $expression; /** - * @param ExpressionInterface|mixed $expressions + * @param Decimal128|ExpressionInterface|Int64|ResolvesToBool|ResolvesToNull|ResolvesToNumber|ResolvesToString|bool|float|int|mixed|non-empty-string|null $expression */ - public function __construct(mixed ...$expressions) + public function __construct(mixed ...$expression) { - if (\count($expressions) < 1) { - throw new \InvalidArgumentException(\sprintf('Expected at least %d values, got %d.', 1, \count($expressions))); + if (! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression arguments to be a list of Decimal128|ExpressionInterface|Int64|ResolvesToBool|ResolvesToNull|ResolvesToNumber|ResolvesToString|bool|float|int|mixed|non-empty-string|null, named arguments are not supported'); } - - $this->expressions = $expressions; + if (\count($expression) < 1) { + throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); + } + $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/AnyElementTrueAggregation.php b/src/Builder/Aggregation/AnyElementTrueAggregation.php new file mode 100644 index 000000000..b81d410e0 --- /dev/null +++ b/src/Builder/Aggregation/AnyElementTrueAggregation.php @@ -0,0 +1,34 @@ + $expression */ + public PackedArray|ResolvesToArray|BSONArray|array $expression; + + /** + * @param BSONArray|PackedArray|ResolvesToArray|list $expression + */ + public function __construct(PackedArray|ResolvesToArray|BSONArray|array $expression) + { + if (\is_array($expression) && ! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression argument to be a list, got an associative array.'); + } + $this->expression = $expression; + } +} diff --git a/src/Builder/Aggregation/ArrayElemAtAggregation.php b/src/Builder/Aggregation/ArrayElemAtAggregation.php new file mode 100644 index 000000000..8ab4bdb35 --- /dev/null +++ b/src/Builder/Aggregation/ArrayElemAtAggregation.php @@ -0,0 +1,40 @@ + $array */ + public PackedArray|ResolvesToArray|BSONArray|array $array; + + /** @param Int64|ResolvesToInt|int $idx */ + public Int64|ResolvesToInt|int $idx; + + /** + * @param BSONArray|PackedArray|ResolvesToArray|list $array + * @param Int64|ResolvesToInt|int $idx + */ + public function __construct(PackedArray|ResolvesToArray|BSONArray|array $array, Int64|ResolvesToInt|int $idx) + { + if (\is_array($array) && ! \array_is_list($array)) { + throw new \InvalidArgumentException('Expected $array argument to be a list, got an associative array.'); + } + $this->array = $array; + $this->idx = $idx; + } +} diff --git a/src/Builder/Aggregation/ArrayToObjectAggregation.php b/src/Builder/Aggregation/ArrayToObjectAggregation.php new file mode 100644 index 000000000..dd63a696d --- /dev/null +++ b/src/Builder/Aggregation/ArrayToObjectAggregation.php @@ -0,0 +1,34 @@ + $array */ + public PackedArray|ResolvesToArray|BSONArray|array $array; + + /** + * @param BSONArray|PackedArray|ResolvesToArray|list $array + */ + public function __construct(PackedArray|ResolvesToArray|BSONArray|array $array) + { + if (\is_array($array) && ! \array_is_list($array)) { + throw new \InvalidArgumentException('Expected $array argument to be a list, got an associative array.'); + } + $this->array = $array; + } +} diff --git a/src/Builder/Aggregation/AsinAggregation.php b/src/Builder/Aggregation/AsinAggregation.php new file mode 100644 index 000000000..8a9adb214 --- /dev/null +++ b/src/Builder/Aggregation/AsinAggregation.php @@ -0,0 +1,37 @@ +expression = $expression; + } +} diff --git a/src/Builder/Aggregation/AsinhAggregation.php b/src/Builder/Aggregation/AsinhAggregation.php new file mode 100644 index 000000000..f0794e00d --- /dev/null +++ b/src/Builder/Aggregation/AsinhAggregation.php @@ -0,0 +1,37 @@ +expression = $expression; + } +} diff --git a/src/Builder/Aggregation/Atan2Aggregation.php b/src/Builder/Aggregation/Atan2Aggregation.php new file mode 100644 index 000000000..f0171394d --- /dev/null +++ b/src/Builder/Aggregation/Atan2Aggregation.php @@ -0,0 +1,44 @@ +y = $y; + $this->x = $x; + } +} diff --git a/src/Builder/Aggregation/AtanAggregation.php b/src/Builder/Aggregation/AtanAggregation.php new file mode 100644 index 000000000..bd3e24190 --- /dev/null +++ b/src/Builder/Aggregation/AtanAggregation.php @@ -0,0 +1,37 @@ +expression = $expression; + } +} diff --git a/src/Builder/Aggregation/AtanhAggregation.php b/src/Builder/Aggregation/AtanhAggregation.php new file mode 100644 index 000000000..958d2dccb --- /dev/null +++ b/src/Builder/Aggregation/AtanhAggregation.php @@ -0,0 +1,37 @@ +expression = $expression; + } +} diff --git a/src/Builder/Aggregation/AvgAggregation.php b/src/Builder/Aggregation/AvgAggregation.php new file mode 100644 index 000000000..e6ec239bd --- /dev/null +++ b/src/Builder/Aggregation/AvgAggregation.php @@ -0,0 +1,35 @@ + ...$expression */ + public array $expression; + + /** + * @param Decimal128|Int64|ResolvesToNumber|float|int $expression + */ + public function __construct(Decimal128|Int64|ResolvesToNumber|float|int ...$expression) + { + if (! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression arguments to be a list of Decimal128|Int64|ResolvesToNumber|float|int, named arguments are not supported'); + } + if (\count($expression) < 1) { + throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); + } + $this->expression = $expression; + } +} diff --git a/src/Builder/Aggregation/BinarySizeAggregation.php b/src/Builder/Aggregation/BinarySizeAggregation.php new file mode 100644 index 000000000..1cfa3f00c --- /dev/null +++ b/src/Builder/Aggregation/BinarySizeAggregation.php @@ -0,0 +1,31 @@ +expression = $expression; + } +} diff --git a/src/Builder/Aggregation/BitAndAggregation.php b/src/Builder/Aggregation/BitAndAggregation.php new file mode 100644 index 000000000..a1609c2ff --- /dev/null +++ b/src/Builder/Aggregation/BitAndAggregation.php @@ -0,0 +1,35 @@ + ...$expression */ + public array $expression; + + /** + * @param Int64|ResolvesToInt|ResolvesToLong|int $expression + */ + public function __construct(Int64|ResolvesToInt|ResolvesToLong|int ...$expression) + { + if (! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression arguments to be a list of Int64|ResolvesToInt|ResolvesToLong|int, named arguments are not supported'); + } + if (\count($expression) < 1) { + throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); + } + $this->expression = $expression; + } +} diff --git a/src/Builder/Aggregation/BitNotAggregation.php b/src/Builder/Aggregation/BitNotAggregation.php new file mode 100644 index 000000000..40c99728d --- /dev/null +++ b/src/Builder/Aggregation/BitNotAggregation.php @@ -0,0 +1,29 @@ +expression = $expression; + } +} diff --git a/src/Builder/Aggregation/BitOrAggregation.php b/src/Builder/Aggregation/BitOrAggregation.php new file mode 100644 index 000000000..2ab63df29 --- /dev/null +++ b/src/Builder/Aggregation/BitOrAggregation.php @@ -0,0 +1,35 @@ + ...$expression */ + public array $expression; + + /** + * @param Int64|ResolvesToInt|ResolvesToLong|int $expression + */ + public function __construct(Int64|ResolvesToInt|ResolvesToLong|int ...$expression) + { + if (! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression arguments to be a list of Int64|ResolvesToInt|ResolvesToLong|int, named arguments are not supported'); + } + if (\count($expression) < 1) { + throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); + } + $this->expression = $expression; + } +} diff --git a/src/Builder/Aggregation/BitXorAggregation.php b/src/Builder/Aggregation/BitXorAggregation.php new file mode 100644 index 000000000..bfcc45169 --- /dev/null +++ b/src/Builder/Aggregation/BitXorAggregation.php @@ -0,0 +1,21 @@ +sortBy = $sortBy; + $this->output = $output; + } +} diff --git a/src/Builder/Aggregation/BottomNAggregation.php b/src/Builder/Aggregation/BottomNAggregation.php new file mode 100644 index 000000000..c2f060193 --- /dev/null +++ b/src/Builder/Aggregation/BottomNAggregation.php @@ -0,0 +1,39 @@ +n = $n; + $this->sortBy = $sortBy; + $this->output = $output; + } +} diff --git a/src/Builder/Aggregation/BsonSizeAggregation.php b/src/Builder/Aggregation/BsonSizeAggregation.php new file mode 100644 index 000000000..1d60eb114 --- /dev/null +++ b/src/Builder/Aggregation/BsonSizeAggregation.php @@ -0,0 +1,31 @@ +object = $object; + } +} diff --git a/src/Builder/Aggregation/CeilAggregation.php b/src/Builder/Aggregation/CeilAggregation.php new file mode 100644 index 000000000..6325b94e5 --- /dev/null +++ b/src/Builder/Aggregation/CeilAggregation.php @@ -0,0 +1,30 @@ +expression = $expression; + } +} diff --git a/src/Builder/Aggregation/CmpAggregation.php b/src/Builder/Aggregation/CmpAggregation.php new file mode 100644 index 000000000..96601310b --- /dev/null +++ b/src/Builder/Aggregation/CmpAggregation.php @@ -0,0 +1,33 @@ +expression1 = $expression1; + $this->expression2 = $expression2; + } +} diff --git a/src/Builder/Aggregation/ConcatAggregation.php b/src/Builder/Aggregation/ConcatAggregation.php new file mode 100644 index 000000000..9be7e13f3 --- /dev/null +++ b/src/Builder/Aggregation/ConcatAggregation.php @@ -0,0 +1,33 @@ + ...$expression */ + public array $expression; + + /** + * @param ResolvesToString|non-empty-string $expression + */ + public function __construct(ResolvesToString|string ...$expression) + { + if (! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression arguments to be a list of ResolvesToString|non-empty-string, named arguments are not supported'); + } + if (\count($expression) < 1) { + throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); + } + $this->expression = $expression; + } +} diff --git a/src/Builder/Aggregation/ConcatArraysAggregation.php b/src/Builder/Aggregation/ConcatArraysAggregation.php new file mode 100644 index 000000000..4f37ff61b --- /dev/null +++ b/src/Builder/Aggregation/ConcatArraysAggregation.php @@ -0,0 +1,36 @@ +> ...$array */ + public array $array; + + /** + * @param BSONArray|PackedArray|ResolvesToArray|list $array + */ + public function __construct(PackedArray|ResolvesToArray|BSONArray|array ...$array) + { + if (! \array_is_list($array)) { + throw new \InvalidArgumentException('Expected $array arguments to be a list of BSONArray|PackedArray|ResolvesToArray|list, named arguments are not supported'); + } + if (\count($array) < 1) { + throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $array, got %d.', 1, \count($array))); + } + $this->array = $array; + } +} diff --git a/src/Builder/Aggregation/CondAggregation.php b/src/Builder/Aggregation/CondAggregation.php new file mode 100644 index 000000000..d31e909a4 --- /dev/null +++ b/src/Builder/Aggregation/CondAggregation.php @@ -0,0 +1,38 @@ +if = $if; + $this->then = $then; + $this->else = $else; + } +} diff --git a/src/Builder/Aggregation/ConvertAggregation.php b/src/Builder/Aggregation/ConvertAggregation.php new file mode 100644 index 000000000..555b9be5d --- /dev/null +++ b/src/Builder/Aggregation/ConvertAggregation.php @@ -0,0 +1,58 @@ +input = $input; + $this->to = $to; + $this->onError = $onError; + $this->onNull = $onNull; + } +} diff --git a/src/Builder/Aggregation/CosAggregation.php b/src/Builder/Aggregation/CosAggregation.php new file mode 100644 index 000000000..71e87faaa --- /dev/null +++ b/src/Builder/Aggregation/CosAggregation.php @@ -0,0 +1,35 @@ + resolves to a 128-bit decimal value. + */ + public Decimal128|Int64|ResolvesToNumber|float|int $expression; + + /** + * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $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. + */ + public function __construct(Decimal128|Int64|ResolvesToNumber|float|int $expression) + { + $this->expression = $expression; + } +} diff --git a/src/Builder/Aggregation/CoshAggregation.php b/src/Builder/Aggregation/CoshAggregation.php new file mode 100644 index 000000000..01dff644b --- /dev/null +++ b/src/Builder/Aggregation/CoshAggregation.php @@ -0,0 +1,35 @@ + resolves to a 128-bit decimal value. + */ + public Decimal128|Int64|ResolvesToNumber|float|int $expression; + + /** + * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $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. + */ + public function __construct(Decimal128|Int64|ResolvesToNumber|float|int $expression) + { + $this->expression = $expression; + } +} diff --git a/src/Builder/Aggregation/CountAggregation.php b/src/Builder/Aggregation/CountAggregation.php new file mode 100644 index 000000000..4abf6bc83 --- /dev/null +++ b/src/Builder/Aggregation/CountAggregation.php @@ -0,0 +1,26 @@ +field = $field; + } +} diff --git a/src/Builder/Aggregation/CovariancePopAggregation.php b/src/Builder/Aggregation/CovariancePopAggregation.php new file mode 100644 index 000000000..bb7f25d07 --- /dev/null +++ b/src/Builder/Aggregation/CovariancePopAggregation.php @@ -0,0 +1,38 @@ +expression1 = $expression1; + $this->expression2 = $expression2; + } +} diff --git a/src/Builder/Aggregation/CovarianceSampAggregation.php b/src/Builder/Aggregation/CovarianceSampAggregation.php new file mode 100644 index 000000000..b47025fb7 --- /dev/null +++ b/src/Builder/Aggregation/CovarianceSampAggregation.php @@ -0,0 +1,38 @@ +expression1 = $expression1; + $this->expression2 = $expression2; + } +} diff --git a/src/Builder/Aggregation/DateAddAggregation.php b/src/Builder/Aggregation/DateAddAggregation.php new file mode 100644 index 000000000..b5da10054 --- /dev/null +++ b/src/Builder/Aggregation/DateAddAggregation.php @@ -0,0 +1,55 @@ +startDate = $startDate; + $this->unit = $unit; + $this->amount = $amount; + $this->timezone = $timezone; + } +} diff --git a/src/Builder/Aggregation/DateDiffAggregation.php b/src/Builder/Aggregation/DateDiffAggregation.php new file mode 100644 index 000000000..f41228738 --- /dev/null +++ b/src/Builder/Aggregation/DateDiffAggregation.php @@ -0,0 +1,60 @@ +startDate = $startDate; + $this->endDate = $endDate; + $this->unit = $unit; + $this->timezone = $timezone; + $this->startOfWeek = $startOfWeek; + } +} diff --git a/src/Builder/Aggregation/DateFromPartsAggregation.php b/src/Builder/Aggregation/DateFromPartsAggregation.php new file mode 100644 index 000000000..8caad699f --- /dev/null +++ b/src/Builder/Aggregation/DateFromPartsAggregation.php @@ -0,0 +1,93 @@ +year = $year; + $this->isoWeekYear = $isoWeekYear; + $this->month = $month; + $this->isoWeek = $isoWeek; + $this->day = $day; + $this->isoDayOfWeek = $isoDayOfWeek; + $this->hour = $hour; + $this->minute = $minute; + $this->second = $second; + $this->millisecond = $millisecond; + $this->timezone = $timezone; + } +} diff --git a/src/Builder/Aggregation/DateFromStringAggregation.php b/src/Builder/Aggregation/DateFromStringAggregation.php new file mode 100644 index 000000000..13a27da4c --- /dev/null +++ b/src/Builder/Aggregation/DateFromStringAggregation.php @@ -0,0 +1,67 @@ +dateString = $dateString; + $this->format = $format; + $this->timezone = $timezone; + $this->onError = $onError; + $this->onNull = $onNull; + } +} diff --git a/src/Builder/Aggregation/DateSubtractAggregation.php b/src/Builder/Aggregation/DateSubtractAggregation.php new file mode 100644 index 000000000..0cf1f5054 --- /dev/null +++ b/src/Builder/Aggregation/DateSubtractAggregation.php @@ -0,0 +1,55 @@ +startDate = $startDate; + $this->unit = $unit; + $this->amount = $amount; + $this->timezone = $timezone; + } +} diff --git a/src/Builder/Aggregation/DateToPartsAggregation.php b/src/Builder/Aggregation/DateToPartsAggregation.php new file mode 100644 index 000000000..36b061571 --- /dev/null +++ b/src/Builder/Aggregation/DateToPartsAggregation.php @@ -0,0 +1,48 @@ +date = $date; + $this->timezone = $timezone; + $this->iso8601 = $iso8601; + } +} diff --git a/src/Builder/Aggregation/DateToStringAggregation.php b/src/Builder/Aggregation/DateToStringAggregation.php new file mode 100644 index 000000000..a30c3a864 --- /dev/null +++ b/src/Builder/Aggregation/DateToStringAggregation.php @@ -0,0 +1,62 @@ +date = $date; + $this->format = $format; + $this->timezone = $timezone; + $this->onNull = $onNull; + } +} diff --git a/src/Builder/Aggregation/DateTruncAggregation.php b/src/Builder/Aggregation/DateTruncAggregation.php new file mode 100644 index 000000000..dc94638f0 --- /dev/null +++ b/src/Builder/Aggregation/DateTruncAggregation.php @@ -0,0 +1,73 @@ +date = $date; + $this->unit = $unit; + $this->binSize = $binSize; + $this->timezone = $timezone; + $this->startOfWeek = $startOfWeek; + } +} diff --git a/src/Builder/Aggregation/DayOfMonthAggregation.php b/src/Builder/Aggregation/DayOfMonthAggregation.php new file mode 100644 index 000000000..f96aed2eb --- /dev/null +++ b/src/Builder/Aggregation/DayOfMonthAggregation.php @@ -0,0 +1,42 @@ +date = $date; + $this->timezone = $timezone; + } +} diff --git a/src/Builder/Aggregation/DayOfWeekAggregation.php b/src/Builder/Aggregation/DayOfWeekAggregation.php new file mode 100644 index 000000000..f15e483af --- /dev/null +++ b/src/Builder/Aggregation/DayOfWeekAggregation.php @@ -0,0 +1,42 @@ +date = $date; + $this->timezone = $timezone; + } +} diff --git a/src/Builder/Aggregation/DayOfYearAggregation.php b/src/Builder/Aggregation/DayOfYearAggregation.php new file mode 100644 index 000000000..7354ae143 --- /dev/null +++ b/src/Builder/Aggregation/DayOfYearAggregation.php @@ -0,0 +1,42 @@ +date = $date; + $this->timezone = $timezone; + } +} diff --git a/src/Builder/Aggregation/DegreesToRadiansAggregation.php b/src/Builder/Aggregation/DegreesToRadiansAggregation.php new file mode 100644 index 000000000..3da33e21b --- /dev/null +++ b/src/Builder/Aggregation/DegreesToRadiansAggregation.php @@ -0,0 +1,35 @@ + resolves to a 128-bit decimal value. + */ + public Decimal128|Int64|ResolvesToNumber|float|int $expression; + + /** + * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $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. + */ + public function __construct(Decimal128|Int64|ResolvesToNumber|float|int $expression) + { + $this->expression = $expression; + } +} diff --git a/src/Builder/Aggregation/DenseRankAggregation.php b/src/Builder/Aggregation/DenseRankAggregation.php new file mode 100644 index 000000000..b897c85cd --- /dev/null +++ b/src/Builder/Aggregation/DenseRankAggregation.php @@ -0,0 +1,20 @@ +input = $input; + $this->unit = $unit; + } +} diff --git a/src/Builder/Aggregation/DivideAggregation.php b/src/Builder/Aggregation/DivideAggregation.php new file mode 100644 index 000000000..fc93f97e6 --- /dev/null +++ b/src/Builder/Aggregation/DivideAggregation.php @@ -0,0 +1,37 @@ +dividend = $dividend; + $this->divisor = $divisor; + } +} diff --git a/src/Builder/Aggregation/DocumentNumberAggregation.php b/src/Builder/Aggregation/DocumentNumberAggregation.php new file mode 100644 index 000000000..4ff69d2b5 --- /dev/null +++ b/src/Builder/Aggregation/DocumentNumberAggregation.php @@ -0,0 +1,20 @@ +exponent = $exponent; + } +} diff --git a/src/Builder/Aggregation/ExpMovingAvgAggregation.php b/src/Builder/Aggregation/ExpMovingAvgAggregation.php new file mode 100644 index 000000000..46feb372f --- /dev/null +++ b/src/Builder/Aggregation/ExpMovingAvgAggregation.php @@ -0,0 +1,54 @@ +input = $input; + $this->N = $N; + $this->alpha = $alpha; + } +} diff --git a/src/Builder/Aggregation/FilterAggregation.php b/src/Builder/Aggregation/FilterAggregation.php index d0d0b12d6..8e4f1fb38 100644 --- a/src/Builder/Aggregation/FilterAggregation.php +++ b/src/Builder/Aggregation/FilterAggregation.php @@ -8,35 +8,46 @@ use MongoDB\BSON\Int64; use MongoDB\BSON\PackedArray; +use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToArray; use MongoDB\Builder\Expression\ResolvesToBool; use MongoDB\Builder\Expression\ResolvesToInt; -use MongoDB\Builder\Expression\ResolvesToString; use MongoDB\Builder\Optional; use MongoDB\Model\BSONArray; class FilterAggregation implements ResolvesToArray { public const NAME = '$filter'; - public const ENCODE = 'object'; + public const ENCODE = \MongoDB\Builder\Encode::Object; + /** @param BSONArray|PackedArray|ResolvesToArray|list $input */ public PackedArray|ResolvesToArray|BSONArray|array $input; + + /** @param ResolvesToBool|bool $cond 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. */ public ResolvesToBool|bool $cond; - public Optional|ResolvesToString|string $as; - public Optional|Int64|ResolvesToInt|int $limit; + + /** @param Optional|non-empty-string $as 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. */ + public Optional|string $as; + + /** + * @param Int64|Optional|ResolvesToInt|int $limit 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. + */ + public Int64|ResolvesToInt|Optional|int $limit; /** * @param BSONArray|PackedArray|ResolvesToArray|list $input - * @param ResolvesToBool|bool $cond - * @param Optional|ResolvesToString|non-empty-string $as - * @param Int64|Optional|ResolvesToInt|int $limit + * @param ResolvesToBool|bool $cond 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. + * @param Optional|non-empty-string $as 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. + * @param Int64|Optional|ResolvesToInt|int $limit 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. */ public function __construct( PackedArray|ResolvesToArray|BSONArray|array $input, ResolvesToBool|bool $cond, - Optional|ResolvesToString|string $as = Optional::Undefined, - Optional|Int64|ResolvesToInt|int $limit = Optional::Undefined, + Optional|string $as = Optional::Undefined, + Int64|ResolvesToInt|Optional|int $limit = Optional::Undefined, ) { if (\is_array($input) && ! \array_is_list($input)) { throw new \InvalidArgumentException('Expected $input argument to be a list, got an associative array.'); diff --git a/src/Builder/Aggregation/FirstAggregation.php b/src/Builder/Aggregation/FirstAggregation.php new file mode 100644 index 000000000..446a1be56 --- /dev/null +++ b/src/Builder/Aggregation/FirstAggregation.php @@ -0,0 +1,27 @@ +expression = $expression; + } +} diff --git a/src/Builder/Aggregation/FirstNAggregation.php b/src/Builder/Aggregation/FirstNAggregation.php new file mode 100644 index 000000000..0055a1440 --- /dev/null +++ b/src/Builder/Aggregation/FirstNAggregation.php @@ -0,0 +1,40 @@ + $input An expression that resolves to the array from which to return n elements. */ + public PackedArray|ResolvesToArray|BSONArray|array $input; + + /** @param Int64|ResolvesToInt|int $n An expression that resolves to a positive integer. The integer specifies the number of array elements that $firstN returns. */ + public Int64|ResolvesToInt|int $n; + + /** + * @param BSONArray|PackedArray|ResolvesToArray|list $input An expression that resolves to the array from which to return n elements. + * @param Int64|ResolvesToInt|int $n An expression that resolves to a positive integer. The integer specifies the number of array elements that $firstN returns. + */ + public function __construct(PackedArray|ResolvesToArray|BSONArray|array $input, Int64|ResolvesToInt|int $n) + { + if (\is_array($input) && ! \array_is_list($input)) { + throw new \InvalidArgumentException('Expected $input argument to be a list, got an associative array.'); + } + $this->input = $input; + $this->n = $n; + } +} diff --git a/src/Builder/Aggregation/FloorAggregation.php b/src/Builder/Aggregation/FloorAggregation.php new file mode 100644 index 000000000..ac2c7ba6a --- /dev/null +++ b/src/Builder/Aggregation/FloorAggregation.php @@ -0,0 +1,30 @@ +expression = $expression; + } +} diff --git a/src/Builder/Aggregation/FunctionAggregation.php b/src/Builder/Aggregation/FunctionAggregation.php new file mode 100644 index 000000000..07249496d --- /dev/null +++ b/src/Builder/Aggregation/FunctionAggregation.php @@ -0,0 +1,42 @@ + $args Arguments passed to the function body. If the body function does not take an argument, you can specify an empty array [ ]. */ + public PackedArray|BSONArray|array $args; + + /** @param non-empty-string $lang */ + public string $lang; + + /** + * @param non-empty-string $body The function definition. You can specify the function definition as either BSON type Code or String. + * @param BSONArray|PackedArray|list $args Arguments passed to the function body. If the body function does not take an argument, you can specify an empty array [ ]. + * @param non-empty-string $lang + */ + public function __construct(string $body, PackedArray|BSONArray|array $args, string $lang) + { + $this->body = $body; + if (\is_array($args) && ! \array_is_list($args)) { + throw new \InvalidArgumentException('Expected $args argument to be a list, got an associative array.'); + } + $this->args = $args; + $this->lang = $lang; + } +} diff --git a/src/Builder/Aggregation/GetFieldAggregation.php b/src/Builder/Aggregation/GetFieldAggregation.php new file mode 100644 index 000000000..d104c32e3 --- /dev/null +++ b/src/Builder/Aggregation/GetFieldAggregation.php @@ -0,0 +1,41 @@ +field = $field; + $this->input = $input; + } +} diff --git a/src/Builder/Aggregation/GtAggregation.php b/src/Builder/Aggregation/GtAggregation.php index af8b16a00..94955dfca 100644 --- a/src/Builder/Aggregation/GtAggregation.php +++ b/src/Builder/Aggregation/GtAggregation.php @@ -6,15 +6,19 @@ namespace MongoDB\Builder\Aggregation; +use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToBool; class GtAggregation implements ResolvesToBool { public const NAME = '$gt'; - public const ENCODE = 'array'; + public const ENCODE = \MongoDB\Builder\Encode::Array; + /** @param ExpressionInterface|mixed $expression1 */ public mixed $expression1; + + /** @param ExpressionInterface|mixed $expression2 */ public mixed $expression2; /** diff --git a/src/Builder/Aggregation/GteAggregation.php b/src/Builder/Aggregation/GteAggregation.php index b8933db72..cdd333cc1 100644 --- a/src/Builder/Aggregation/GteAggregation.php +++ b/src/Builder/Aggregation/GteAggregation.php @@ -6,15 +6,19 @@ namespace MongoDB\Builder\Aggregation; +use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToBool; class GteAggregation implements ResolvesToBool { public const NAME = '$gte'; - public const ENCODE = 'array'; + public const ENCODE = \MongoDB\Builder\Encode::Array; + /** @param ExpressionInterface|mixed $expression1 */ public mixed $expression1; + + /** @param ExpressionInterface|mixed $expression2 */ public mixed $expression2; /** diff --git a/src/Builder/Aggregation/HourAggregation.php b/src/Builder/Aggregation/HourAggregation.php new file mode 100644 index 000000000..db0954aa5 --- /dev/null +++ b/src/Builder/Aggregation/HourAggregation.php @@ -0,0 +1,42 @@ +date = $date; + $this->timezone = $timezone; + } +} diff --git a/src/Builder/Aggregation/IfNullAggregation.php b/src/Builder/Aggregation/IfNullAggregation.php new file mode 100644 index 000000000..29ea18c37 --- /dev/null +++ b/src/Builder/Aggregation/IfNullAggregation.php @@ -0,0 +1,33 @@ + ...$expression */ + public array $expression; + + /** + * @param ExpressionInterface|mixed $expression + */ + public function __construct(mixed ...$expression) + { + if (! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression arguments to be a list of ExpressionInterface|mixed, named arguments are not supported'); + } + if (\count($expression) < 1) { + throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); + } + $this->expression = $expression; + } +} diff --git a/src/Builder/Aggregation/InAggregation.php b/src/Builder/Aggregation/InAggregation.php new file mode 100644 index 000000000..b70360f55 --- /dev/null +++ b/src/Builder/Aggregation/InAggregation.php @@ -0,0 +1,39 @@ + $array Any valid expression that resolves to an array. */ + public PackedArray|ResolvesToArray|BSONArray|array $array; + + /** + * @param ExpressionInterface|mixed $expression Any valid expression expression. + * @param BSONArray|PackedArray|ResolvesToArray|list $array Any valid expression that resolves to an array. + */ + public function __construct(mixed $expression, PackedArray|ResolvesToArray|BSONArray|array $array) + { + $this->expression = $expression; + if (\is_array($array) && ! \array_is_list($array)) { + throw new \InvalidArgumentException('Expected $array argument to be a list, got an associative array.'); + } + $this->array = $array; + } +} diff --git a/src/Builder/Aggregation/IndexOfArrayAggregation.php b/src/Builder/Aggregation/IndexOfArrayAggregation.php new file mode 100644 index 000000000..1a52650f1 --- /dev/null +++ b/src/Builder/Aggregation/IndexOfArrayAggregation.php @@ -0,0 +1,64 @@ + 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. + */ + public Int64|ResolvesToInt|Optional|int $end; + + /** + * @param ResolvesToString|non-empty-string $array 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. + * @param ExpressionInterface|mixed $search + * @param Int64|Optional|ResolvesToInt|int $start 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. + * @param Int64|Optional|ResolvesToInt|int $end 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. + */ + public function __construct( + ResolvesToString|string $array, + mixed $search, + Int64|ResolvesToInt|Optional|int $start = Optional::Undefined, + Int64|ResolvesToInt|Optional|int $end = Optional::Undefined, + ) { + $this->array = $array; + $this->search = $search; + $this->start = $start; + $this->end = $end; + } +} diff --git a/src/Builder/Aggregation/IndexOfBytesAggregation.php b/src/Builder/Aggregation/IndexOfBytesAggregation.php new file mode 100644 index 000000000..3348d6da0 --- /dev/null +++ b/src/Builder/Aggregation/IndexOfBytesAggregation.php @@ -0,0 +1,63 @@ + 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. + */ + public Int64|ResolvesToInt|Optional|int $end; + + /** + * @param ResolvesToString|non-empty-string $string 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. + * @param ResolvesToString|non-empty-string $substring Can be any valid expression as long as it resolves to a string. + * @param Int64|Optional|ResolvesToInt|int $start 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. + * @param Int64|Optional|ResolvesToInt|int $end 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. + */ + public function __construct( + ResolvesToString|string $string, + ResolvesToString|string $substring, + Int64|ResolvesToInt|Optional|int $start = Optional::Undefined, + Int64|ResolvesToInt|Optional|int $end = Optional::Undefined, + ) { + $this->string = $string; + $this->substring = $substring; + $this->start = $start; + $this->end = $end; + } +} diff --git a/src/Builder/Aggregation/IndexOfCPAggregation.php b/src/Builder/Aggregation/IndexOfCPAggregation.php new file mode 100644 index 000000000..d106bb95a --- /dev/null +++ b/src/Builder/Aggregation/IndexOfCPAggregation.php @@ -0,0 +1,63 @@ + 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. + */ + public Int64|ResolvesToInt|Optional|int $end; + + /** + * @param ResolvesToString|non-empty-string $string 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. + * @param ResolvesToString|non-empty-string $substring Can be any valid expression as long as it resolves to a string. + * @param Int64|Optional|ResolvesToInt|int $start 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. + * @param Int64|Optional|ResolvesToInt|int $end 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. + */ + public function __construct( + ResolvesToString|string $string, + ResolvesToString|string $substring, + Int64|ResolvesToInt|Optional|int $start = Optional::Undefined, + Int64|ResolvesToInt|Optional|int $end = Optional::Undefined, + ) { + $this->string = $string; + $this->substring = $substring; + $this->start = $start; + $this->end = $end; + } +} diff --git a/src/Builder/Aggregation/IntegralAggregation.php b/src/Builder/Aggregation/IntegralAggregation.php new file mode 100644 index 000000000..8cd60d82d --- /dev/null +++ b/src/Builder/Aggregation/IntegralAggregation.php @@ -0,0 +1,46 @@ +input = $input; + $this->unit = $unit; + } +} diff --git a/src/Builder/Aggregation/IsArrayAggregation.php b/src/Builder/Aggregation/IsArrayAggregation.php new file mode 100644 index 000000000..68845dc3a --- /dev/null +++ b/src/Builder/Aggregation/IsArrayAggregation.php @@ -0,0 +1,34 @@ + ...$expression */ + public array $expression; + + /** + * @param ExpressionInterface|mixed $expression + */ + public function __construct(mixed ...$expression) + { + if (! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression arguments to be a list of ExpressionInterface|mixed, named arguments are not supported'); + } + if (\count($expression) < 1) { + throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); + } + $this->expression = $expression; + } +} diff --git a/src/Builder/Aggregation/IsNumberAggregation.php b/src/Builder/Aggregation/IsNumberAggregation.php new file mode 100644 index 000000000..d4a30de48 --- /dev/null +++ b/src/Builder/Aggregation/IsNumberAggregation.php @@ -0,0 +1,34 @@ + ...$expression */ + public array $expression; + + /** + * @param ExpressionInterface|mixed $expression + */ + public function __construct(mixed ...$expression) + { + if (! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression arguments to be a list of ExpressionInterface|mixed, named arguments are not supported'); + } + if (\count($expression) < 1) { + throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); + } + $this->expression = $expression; + } +} diff --git a/src/Builder/Aggregation/IsoDayOfWeekAggregation.php b/src/Builder/Aggregation/IsoDayOfWeekAggregation.php new file mode 100644 index 000000000..10452f1cd --- /dev/null +++ b/src/Builder/Aggregation/IsoDayOfWeekAggregation.php @@ -0,0 +1,42 @@ +date = $date; + $this->timezone = $timezone; + } +} diff --git a/src/Builder/Aggregation/IsoWeekAggregation.php b/src/Builder/Aggregation/IsoWeekAggregation.php new file mode 100644 index 000000000..93f33ff16 --- /dev/null +++ b/src/Builder/Aggregation/IsoWeekAggregation.php @@ -0,0 +1,42 @@ +date = $date; + $this->timezone = $timezone; + } +} diff --git a/src/Builder/Aggregation/IsoWeekYearAggregation.php b/src/Builder/Aggregation/IsoWeekYearAggregation.php new file mode 100644 index 000000000..d1ff0e89a --- /dev/null +++ b/src/Builder/Aggregation/IsoWeekYearAggregation.php @@ -0,0 +1,42 @@ +date = $date; + $this->timezone = $timezone; + } +} diff --git a/src/Builder/Aggregation/LastAggregation.php b/src/Builder/Aggregation/LastAggregation.php new file mode 100644 index 000000000..666920f47 --- /dev/null +++ b/src/Builder/Aggregation/LastAggregation.php @@ -0,0 +1,27 @@ +expression = $expression; + } +} diff --git a/src/Builder/Aggregation/LastNAggregation.php b/src/Builder/Aggregation/LastNAggregation.php new file mode 100644 index 000000000..30cfdf7f8 --- /dev/null +++ b/src/Builder/Aggregation/LastNAggregation.php @@ -0,0 +1,40 @@ + $input An expression that resolves to the array from which to return n elements. */ + public PackedArray|ResolvesToArray|BSONArray|array $input; + + /** @param Int64|ResolvesToInt|int $n An expression that resolves to a positive integer. The integer specifies the number of array elements that $firstN returns. */ + public Int64|ResolvesToInt|int $n; + + /** + * @param BSONArray|PackedArray|ResolvesToArray|list $input An expression that resolves to the array from which to return n elements. + * @param Int64|ResolvesToInt|int $n An expression that resolves to a positive integer. The integer specifies the number of array elements that $firstN returns. + */ + public function __construct(PackedArray|ResolvesToArray|BSONArray|array $input, Int64|ResolvesToInt|int $n) + { + if (\is_array($input) && ! \array_is_list($input)) { + throw new \InvalidArgumentException('Expected $input argument to be a list, got an associative array.'); + } + $this->input = $input; + $this->n = $n; + } +} diff --git a/src/Builder/Aggregation/LetAggregation.php b/src/Builder/Aggregation/LetAggregation.php new file mode 100644 index 000000000..7c03aaf60 --- /dev/null +++ b/src/Builder/Aggregation/LetAggregation.php @@ -0,0 +1,38 @@ +vars = $vars; + $this->in = $in; + } +} diff --git a/src/Builder/Aggregation/LinearFillAggregation.php b/src/Builder/Aggregation/LinearFillAggregation.php new file mode 100644 index 000000000..e8acb0dd9 --- /dev/null +++ b/src/Builder/Aggregation/LinearFillAggregation.php @@ -0,0 +1,29 @@ +expression = $expression; + } +} diff --git a/src/Builder/Aggregation/LiteralAggregation.php b/src/Builder/Aggregation/LiteralAggregation.php new file mode 100644 index 000000000..6a9e17c8d --- /dev/null +++ b/src/Builder/Aggregation/LiteralAggregation.php @@ -0,0 +1,27 @@ +value = $value; + } +} diff --git a/src/Builder/Aggregation/LnAggregation.php b/src/Builder/Aggregation/LnAggregation.php new file mode 100644 index 000000000..3fe8e5cef --- /dev/null +++ b/src/Builder/Aggregation/LnAggregation.php @@ -0,0 +1,30 @@ +number = $number; + } +} diff --git a/src/Builder/Aggregation/LocfAggregation.php b/src/Builder/Aggregation/LocfAggregation.php new file mode 100644 index 000000000..00edb45b4 --- /dev/null +++ b/src/Builder/Aggregation/LocfAggregation.php @@ -0,0 +1,27 @@ +expression = $expression; + } +} diff --git a/src/Builder/Aggregation/Log10Aggregation.php b/src/Builder/Aggregation/Log10Aggregation.php new file mode 100644 index 000000000..ca81bd837 --- /dev/null +++ b/src/Builder/Aggregation/Log10Aggregation.php @@ -0,0 +1,30 @@ +number = $number; + } +} diff --git a/src/Builder/Aggregation/LogAggregation.php b/src/Builder/Aggregation/LogAggregation.php new file mode 100644 index 000000000..0b566159a --- /dev/null +++ b/src/Builder/Aggregation/LogAggregation.php @@ -0,0 +1,37 @@ +number = $number; + $this->base = $base; + } +} diff --git a/src/Builder/Aggregation/LtAggregation.php b/src/Builder/Aggregation/LtAggregation.php index a135ed169..7ace117ce 100644 --- a/src/Builder/Aggregation/LtAggregation.php +++ b/src/Builder/Aggregation/LtAggregation.php @@ -6,15 +6,19 @@ namespace MongoDB\Builder\Aggregation; +use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToBool; class LtAggregation implements ResolvesToBool { public const NAME = '$lt'; - public const ENCODE = 'array'; + public const ENCODE = \MongoDB\Builder\Encode::Array; + /** @param ExpressionInterface|mixed $expression1 */ public mixed $expression1; + + /** @param ExpressionInterface|mixed $expression2 */ public mixed $expression2; /** diff --git a/src/Builder/Aggregation/LteAggregation.php b/src/Builder/Aggregation/LteAggregation.php new file mode 100644 index 000000000..8ee66f828 --- /dev/null +++ b/src/Builder/Aggregation/LteAggregation.php @@ -0,0 +1,33 @@ +expression1 = $expression1; + $this->expression2 = $expression2; + } +} diff --git a/src/Builder/Aggregation/LtrimAggregation.php b/src/Builder/Aggregation/LtrimAggregation.php new file mode 100644 index 000000000..e40e57291 --- /dev/null +++ b/src/Builder/Aggregation/LtrimAggregation.php @@ -0,0 +1,41 @@ +input = $input; + $this->chars = $chars; + } +} diff --git a/src/Builder/Aggregation/MapAggregation.php b/src/Builder/Aggregation/MapAggregation.php new file mode 100644 index 000000000..152b50a9f --- /dev/null +++ b/src/Builder/Aggregation/MapAggregation.php @@ -0,0 +1,48 @@ + $input An expression that resolves to an array. */ + public PackedArray|ResolvesToArray|BSONArray|array $input; + + /** @param ExpressionInterface|mixed $in 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. */ + public mixed $in; + + /** @param Optional|ResolvesToString|non-empty-string $as 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. */ + public ResolvesToString|Optional|string $as; + + /** + * @param BSONArray|PackedArray|ResolvesToArray|list $input An expression that resolves to an array. + * @param ExpressionInterface|mixed $in 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. + * @param Optional|ResolvesToString|non-empty-string $as 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. + */ + public function __construct( + PackedArray|ResolvesToArray|BSONArray|array $input, + mixed $in, + ResolvesToString|Optional|string $as = Optional::Undefined, + ) { + if (\is_array($input) && ! \array_is_list($input)) { + throw new \InvalidArgumentException('Expected $input argument to be a list, got an associative array.'); + } + $this->input = $input; + $this->in = $in; + $this->as = $as; + } +} diff --git a/src/Builder/Aggregation/MaxAggregation.php b/src/Builder/Aggregation/MaxAggregation.php index 97f0d66bd..ce9dfc999 100644 --- a/src/Builder/Aggregation/MaxAggregation.php +++ b/src/Builder/Aggregation/MaxAggregation.php @@ -6,20 +6,28 @@ namespace MongoDB\Builder\Aggregation; +use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ExpressionInterface; -class MaxAggregation implements ExpressionInterface +class MaxAggregation implements ExpressionInterface, AccumulatorInterface { public const NAME = '$max'; - public const ENCODE = 'single'; + public const ENCODE = \MongoDB\Builder\Encode::Single; - public mixed $expression; + /** @param list ...$expression */ + public array $expression; /** * @param ExpressionInterface|mixed $expression */ - public function __construct(mixed $expression) + public function __construct(mixed ...$expression) { + if (! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression arguments to be a list of ExpressionInterface|mixed, named arguments are not supported'); + } + if (\count($expression) < 1) { + throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); + } $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/MaxNAggregation.php b/src/Builder/Aggregation/MaxNAggregation.php new file mode 100644 index 000000000..1a1c3c809 --- /dev/null +++ b/src/Builder/Aggregation/MaxNAggregation.php @@ -0,0 +1,40 @@ + $input An expression that resolves to the array from which to return the maximal n elements. */ + public PackedArray|ResolvesToArray|BSONArray|array $input; + + /** @param Int64|ResolvesToInt|int $n An expression that resolves to a positive integer. The integer specifies the number of array elements that $maxN returns. */ + public Int64|ResolvesToInt|int $n; + + /** + * @param BSONArray|PackedArray|ResolvesToArray|list $input An expression that resolves to the array from which to return the maximal n elements. + * @param Int64|ResolvesToInt|int $n An expression that resolves to a positive integer. The integer specifies the number of array elements that $maxN returns. + */ + public function __construct(PackedArray|ResolvesToArray|BSONArray|array $input, Int64|ResolvesToInt|int $n) + { + if (\is_array($input) && ! \array_is_list($input)) { + throw new \InvalidArgumentException('Expected $input argument to be a list, got an associative array.'); + } + $this->input = $input; + $this->n = $n; + } +} diff --git a/src/Builder/Aggregation/MedianAggregation.php b/src/Builder/Aggregation/MedianAggregation.php new file mode 100644 index 000000000..0c48bf4b6 --- /dev/null +++ b/src/Builder/Aggregation/MedianAggregation.php @@ -0,0 +1,35 @@ +input = $input; + $this->method = $method; + } +} diff --git a/src/Builder/Aggregation/MergeObjectsAggregation.php b/src/Builder/Aggregation/MergeObjectsAggregation.php new file mode 100644 index 000000000..1a88ba582 --- /dev/null +++ b/src/Builder/Aggregation/MergeObjectsAggregation.php @@ -0,0 +1,35 @@ + ...$document Any valid expression that resolves to a document. */ + public array $document; + + /** + * @param Document|ResolvesToObject|Serializable|array|object $document Any valid expression that resolves to a document. + */ + public function __construct(array|object ...$document) + { + if (! \array_is_list($document)) { + throw new \InvalidArgumentException('Expected $document arguments to be a list of Document|ResolvesToObject|Serializable|array|object, named arguments are not supported'); + } + if (\count($document) < 1) { + throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $document, got %d.', 1, \count($document))); + } + $this->document = $document; + } +} diff --git a/src/Builder/Aggregation/MetaAggregation.php b/src/Builder/Aggregation/MetaAggregation.php new file mode 100644 index 000000000..6d6419712 --- /dev/null +++ b/src/Builder/Aggregation/MetaAggregation.php @@ -0,0 +1,27 @@ +keyword = $keyword; + } +} diff --git a/src/Builder/Aggregation/MillisecondAggregation.php b/src/Builder/Aggregation/MillisecondAggregation.php new file mode 100644 index 000000000..0c48b6966 --- /dev/null +++ b/src/Builder/Aggregation/MillisecondAggregation.php @@ -0,0 +1,42 @@ +date = $date; + $this->timezone = $timezone; + } +} diff --git a/src/Builder/Aggregation/MinAggregation.php b/src/Builder/Aggregation/MinAggregation.php index 43db134af..96d8cf98b 100644 --- a/src/Builder/Aggregation/MinAggregation.php +++ b/src/Builder/Aggregation/MinAggregation.php @@ -6,20 +6,28 @@ namespace MongoDB\Builder\Aggregation; +use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ExpressionInterface; -class MinAggregation implements ExpressionInterface +class MinAggregation implements ExpressionInterface, AccumulatorInterface { public const NAME = '$min'; - public const ENCODE = 'single'; + public const ENCODE = \MongoDB\Builder\Encode::Single; - public mixed $expression; + /** @param list ...$expression */ + public array $expression; /** * @param ExpressionInterface|mixed $expression */ - public function __construct(mixed $expression) + public function __construct(mixed ...$expression) { + if (! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression arguments to be a list of ExpressionInterface|mixed, named arguments are not supported'); + } + if (\count($expression) < 1) { + throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); + } $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/MinNAggregation.php b/src/Builder/Aggregation/MinNAggregation.php new file mode 100644 index 000000000..dac13b6c9 --- /dev/null +++ b/src/Builder/Aggregation/MinNAggregation.php @@ -0,0 +1,40 @@ + $input An expression that resolves to the array from which to return the maximal n elements. */ + public PackedArray|ResolvesToArray|BSONArray|array $input; + + /** @param Int64|ResolvesToInt|int $n An expression that resolves to a positive integer. The integer specifies the number of array elements that $maxN returns. */ + public Int64|ResolvesToInt|int $n; + + /** + * @param BSONArray|PackedArray|ResolvesToArray|list $input An expression that resolves to the array from which to return the maximal n elements. + * @param Int64|ResolvesToInt|int $n An expression that resolves to a positive integer. The integer specifies the number of array elements that $maxN returns. + */ + public function __construct(PackedArray|ResolvesToArray|BSONArray|array $input, Int64|ResolvesToInt|int $n) + { + if (\is_array($input) && ! \array_is_list($input)) { + throw new \InvalidArgumentException('Expected $input argument to be a list, got an associative array.'); + } + $this->input = $input; + $this->n = $n; + } +} diff --git a/src/Builder/Aggregation/MinuteAggregation.php b/src/Builder/Aggregation/MinuteAggregation.php new file mode 100644 index 000000000..d4270fd2c --- /dev/null +++ b/src/Builder/Aggregation/MinuteAggregation.php @@ -0,0 +1,42 @@ +date = $date; + $this->timezone = $timezone; + } +} diff --git a/src/Builder/Aggregation/ModAggregation.php b/src/Builder/Aggregation/ModAggregation.php index 082532895..3ee503864 100644 --- a/src/Builder/Aggregation/ModAggregation.php +++ b/src/Builder/Aggregation/ModAggregation.php @@ -6,23 +6,32 @@ namespace MongoDB\Builder\Aggregation; -use MongoDB\Builder\Expression\ExpressionInterface; +use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Int64; +use MongoDB\Builder\Encode; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Expression\ResolvesToNumber; -class ModAggregation implements ExpressionInterface +class ModAggregation implements ResolvesToInt { public const NAME = '$mod'; - public const ENCODE = 'array'; + public const ENCODE = \MongoDB\Builder\Encode::Array; - public mixed $expression1; - public mixed $expression2; + /** @param Decimal128|Int64|ResolvesToNumber|float|int $dividend The first argument is the dividend, and the second argument is the divisor; i.e. first argument is divided by the second argument. */ + public Decimal128|Int64|ResolvesToNumber|float|int $dividend; + + /** @param Decimal128|Int64|ResolvesToNumber|float|int $divisor */ + public Decimal128|Int64|ResolvesToNumber|float|int $divisor; /** - * @param ExpressionInterface|mixed $expression1 - * @param ExpressionInterface|mixed $expression2 + * @param Decimal128|Int64|ResolvesToNumber|float|int $dividend The first argument is the dividend, and the second argument is the divisor; i.e. first argument is divided by the second argument. + * @param Decimal128|Int64|ResolvesToNumber|float|int $divisor */ - public function __construct(mixed $expression1, mixed $expression2) - { - $this->expression1 = $expression1; - $this->expression2 = $expression2; + public function __construct( + Decimal128|Int64|ResolvesToNumber|float|int $dividend, + Decimal128|Int64|ResolvesToNumber|float|int $divisor, + ) { + $this->dividend = $dividend; + $this->divisor = $divisor; } } diff --git a/src/Builder/Aggregation/MonthAggregation.php b/src/Builder/Aggregation/MonthAggregation.php new file mode 100644 index 000000000..d5bed8d24 --- /dev/null +++ b/src/Builder/Aggregation/MonthAggregation.php @@ -0,0 +1,42 @@ +date = $date; + $this->timezone = $timezone; + } +} diff --git a/src/Builder/Aggregation/MultiplyAggregation.php b/src/Builder/Aggregation/MultiplyAggregation.php new file mode 100644 index 000000000..b84103ab9 --- /dev/null +++ b/src/Builder/Aggregation/MultiplyAggregation.php @@ -0,0 +1,40 @@ + ...$expression 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. + */ + public array $expression; + + /** + * @param Decimal128|Int64|ResolvesToNumber|float|int $expression 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. + */ + public function __construct(Decimal128|Int64|ResolvesToNumber|float|int ...$expression) + { + if (! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression arguments to be a list of Decimal128|Int64|ResolvesToNumber|float|int, named arguments are not supported'); + } + if (\count($expression) < 1) { + throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); + } + $this->expression = $expression; + } +} diff --git a/src/Builder/Aggregation/NeAggregation.php b/src/Builder/Aggregation/NeAggregation.php index c277e8134..759eb597c 100644 --- a/src/Builder/Aggregation/NeAggregation.php +++ b/src/Builder/Aggregation/NeAggregation.php @@ -6,15 +6,19 @@ namespace MongoDB\Builder\Aggregation; +use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToBool; class NeAggregation implements ResolvesToBool { public const NAME = '$ne'; - public const ENCODE = 'array'; + public const ENCODE = \MongoDB\Builder\Encode::Array; + /** @param ExpressionInterface|mixed $expression1 */ public mixed $expression1; + + /** @param ExpressionInterface|mixed $expression2 */ public mixed $expression2; /** diff --git a/src/Builder/Aggregation/NotAggregation.php b/src/Builder/Aggregation/NotAggregation.php new file mode 100644 index 000000000..745e5d09f --- /dev/null +++ b/src/Builder/Aggregation/NotAggregation.php @@ -0,0 +1,28 @@ +expression = $expression; + } +} diff --git a/src/Builder/Aggregation/ObjectToArrayAggregation.php b/src/Builder/Aggregation/ObjectToArrayAggregation.php new file mode 100644 index 000000000..d67503111 --- /dev/null +++ b/src/Builder/Aggregation/ObjectToArrayAggregation.php @@ -0,0 +1,30 @@ +object = $object; + } +} diff --git a/src/Builder/Aggregation/OrAggregation.php b/src/Builder/Aggregation/OrAggregation.php new file mode 100644 index 000000000..4c1ab49a2 --- /dev/null +++ b/src/Builder/Aggregation/OrAggregation.php @@ -0,0 +1,34 @@ + ...$expression */ + public array $expression; + + /** + * @param ExpressionInterface|ResolvesToBool|bool|mixed $expression + */ + public function __construct(mixed ...$expression) + { + if (! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression arguments to be a list of ExpressionInterface|ResolvesToBool|bool|mixed, named arguments are not supported'); + } + if (\count($expression) < 1) { + throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); + } + $this->expression = $expression; + } +} diff --git a/src/Builder/Aggregation/PercentileAggregation.php b/src/Builder/Aggregation/PercentileAggregation.php new file mode 100644 index 000000000..873f2f949 --- /dev/null +++ b/src/Builder/Aggregation/PercentileAggregation.php @@ -0,0 +1,53 @@ + $p $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. + */ + public PackedArray|ResolvesToArray|BSONArray|array $p; + + /** @param non-empty-string $method The method that mongod uses to calculate the percentile value. The method must be 'approximate'. */ + public string $method; + + /** + * @param Decimal128|Int64|ResolvesToNumber|float|int $input $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. + * @param BSONArray|PackedArray|ResolvesToArray|list $p $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. + * @param non-empty-string $method The method that mongod uses to calculate the percentile value. The method must be 'approximate'. + */ + public function __construct( + Decimal128|Int64|ResolvesToNumber|float|int $input, + PackedArray|ResolvesToArray|BSONArray|array $p, + string $method, + ) { + $this->input = $input; + if (\is_array($p) && ! \array_is_list($p)) { + throw new \InvalidArgumentException('Expected $p argument to be a list, got an associative array.'); + } + $this->p = $p; + $this->method = $method; + } +} diff --git a/src/Builder/Aggregation/PowAggregation.php b/src/Builder/Aggregation/PowAggregation.php new file mode 100644 index 000000000..35c4f0452 --- /dev/null +++ b/src/Builder/Aggregation/PowAggregation.php @@ -0,0 +1,36 @@ +number = $number; + $this->exponent = $exponent; + } +} diff --git a/src/Builder/Aggregation/PushAggregation.php b/src/Builder/Aggregation/PushAggregation.php new file mode 100644 index 000000000..2dc109455 --- /dev/null +++ b/src/Builder/Aggregation/PushAggregation.php @@ -0,0 +1,27 @@ +expression = $expression; + } +} diff --git a/src/Builder/Aggregation/RadiansToDegreesAggregation.php b/src/Builder/Aggregation/RadiansToDegreesAggregation.php new file mode 100644 index 000000000..0ea456acc --- /dev/null +++ b/src/Builder/Aggregation/RadiansToDegreesAggregation.php @@ -0,0 +1,31 @@ +expression = $expression; + } +} diff --git a/src/Builder/Aggregation/RandAggregation.php b/src/Builder/Aggregation/RandAggregation.php new file mode 100644 index 000000000..8ba405473 --- /dev/null +++ b/src/Builder/Aggregation/RandAggregation.php @@ -0,0 +1,20 @@ +start = $start; + $this->end = $end; + $this->step = $step; + } +} diff --git a/src/Builder/Aggregation/RankAggregation.php b/src/Builder/Aggregation/RankAggregation.php new file mode 100644 index 000000000..97f1a9b3f --- /dev/null +++ b/src/Builder/Aggregation/RankAggregation.php @@ -0,0 +1,20 @@ + $input 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. + */ + public PackedArray|ResolvesToArray|BSONArray|array $input; + + /** @param ExpressionInterface|mixed $initialValue The initial cumulative value set before in is applied to the first element of the input array. */ + public mixed $initialValue; + + /** + * @param ExpressionInterface|mixed $in 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. + */ + public mixed $in; + + /** + * @param BSONArray|PackedArray|ResolvesToArray|list $input 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. + * @param ExpressionInterface|mixed $initialValue The initial cumulative value set before in is applied to the first element of the input array. + * @param ExpressionInterface|mixed $in 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. + */ + public function __construct(PackedArray|ResolvesToArray|BSONArray|array $input, mixed $initialValue, mixed $in) + { + if (\is_array($input) && ! \array_is_list($input)) { + throw new \InvalidArgumentException('Expected $input argument to be a list, got an associative array.'); + } + $this->input = $input; + $this->initialValue = $initialValue; + $this->in = $in; + } +} diff --git a/src/Builder/Aggregation/RegexFindAggregation.php b/src/Builder/Aggregation/RegexFindAggregation.php new file mode 100644 index 000000000..81900a853 --- /dev/null +++ b/src/Builder/Aggregation/RegexFindAggregation.php @@ -0,0 +1,43 @@ +/. When using the regex //, you can also specify the regex options i and m (but not the s or x options) */ + public Regex|ResolvesToString|string $regex; + + /** @param Optional|non-empty-string $options */ + public Optional|string $options; + + /** + * @param ResolvesToString|non-empty-string $input The string on which you wish to apply the regex pattern. Can be a string or any valid expression that resolves to a string. + * @param Regex|ResolvesToString|non-empty-string $regex 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) + * @param Optional|non-empty-string $options + */ + public function __construct( + ResolvesToString|string $input, + Regex|ResolvesToString|string $regex, + Optional|string $options = Optional::Undefined, + ) { + $this->input = $input; + $this->regex = $regex; + $this->options = $options; + } +} diff --git a/src/Builder/Aggregation/RegexFindAllAggregation.php b/src/Builder/Aggregation/RegexFindAllAggregation.php new file mode 100644 index 000000000..7474b96bd --- /dev/null +++ b/src/Builder/Aggregation/RegexFindAllAggregation.php @@ -0,0 +1,43 @@ +/. When using the regex //, you can also specify the regex options i and m (but not the s or x options) */ + public Regex|ResolvesToString|string $regex; + + /** @param Optional|non-empty-string $options */ + public Optional|string $options; + + /** + * @param ResolvesToString|non-empty-string $input The string on which you wish to apply the regex pattern. Can be a string or any valid expression that resolves to a string. + * @param Regex|ResolvesToString|non-empty-string $regex 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) + * @param Optional|non-empty-string $options + */ + public function __construct( + ResolvesToString|string $input, + Regex|ResolvesToString|string $regex, + Optional|string $options = Optional::Undefined, + ) { + $this->input = $input; + $this->regex = $regex; + $this->options = $options; + } +} diff --git a/src/Builder/Aggregation/RegexMatchAggregation.php b/src/Builder/Aggregation/RegexMatchAggregation.php new file mode 100644 index 000000000..378c6f49f --- /dev/null +++ b/src/Builder/Aggregation/RegexMatchAggregation.php @@ -0,0 +1,43 @@ +/. When using the regex //, you can also specify the regex options i and m (but not the s or x options) */ + public Regex|ResolvesToString|string $regex; + + /** @param Optional|non-empty-string $options */ + public Optional|string $options; + + /** + * @param ResolvesToString|non-empty-string $input The string on which you wish to apply the regex pattern. Can be a string or any valid expression that resolves to a string. + * @param Regex|ResolvesToString|non-empty-string $regex 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) + * @param Optional|non-empty-string $options + */ + public function __construct( + ResolvesToString|string $input, + Regex|ResolvesToString|string $regex, + Optional|string $options = Optional::Undefined, + ) { + $this->input = $input; + $this->regex = $regex; + $this->options = $options; + } +} diff --git a/src/Builder/Aggregation/ReplaceAllAggregation.php b/src/Builder/Aggregation/ReplaceAllAggregation.php new file mode 100644 index 000000000..314f1c204 --- /dev/null +++ b/src/Builder/Aggregation/ReplaceAllAggregation.php @@ -0,0 +1,41 @@ +input = $input; + $this->find = $find; + $this->replacement = $replacement; + } +} diff --git a/src/Builder/Aggregation/ReplaceOneAggregation.php b/src/Builder/Aggregation/ReplaceOneAggregation.php new file mode 100644 index 000000000..6a8bb0017 --- /dev/null +++ b/src/Builder/Aggregation/ReplaceOneAggregation.php @@ -0,0 +1,41 @@ +input = $input; + $this->find = $find; + $this->replacement = $replacement; + } +} diff --git a/src/Builder/Aggregation/ReverseArrayAggregation.php b/src/Builder/Aggregation/ReverseArrayAggregation.php new file mode 100644 index 000000000..63f40e2c2 --- /dev/null +++ b/src/Builder/Aggregation/ReverseArrayAggregation.php @@ -0,0 +1,33 @@ + $expression The argument can be any valid expression as long as it resolves to an array. */ + public PackedArray|ResolvesToArray|BSONArray|array $expression; + + /** + * @param BSONArray|PackedArray|ResolvesToArray|list $expression The argument can be any valid expression as long as it resolves to an array. + */ + public function __construct(PackedArray|ResolvesToArray|BSONArray|array $expression) + { + if (\is_array($expression) && ! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression argument to be a list, got an associative array.'); + } + $this->expression = $expression; + } +} diff --git a/src/Builder/Aggregation/RoundAggregation.php b/src/Builder/Aggregation/RoundAggregation.php new file mode 100644 index 000000000..94f9bfde3 --- /dev/null +++ b/src/Builder/Aggregation/RoundAggregation.php @@ -0,0 +1,44 @@ +number = $number; + $this->place = $place; + } +} diff --git a/src/Builder/Aggregation/RtrimAggregation.php b/src/Builder/Aggregation/RtrimAggregation.php new file mode 100644 index 000000000..5090b8328 --- /dev/null +++ b/src/Builder/Aggregation/RtrimAggregation.php @@ -0,0 +1,41 @@ +input = $input; + $this->chars = $chars; + } +} diff --git a/src/Builder/Aggregation/SampleRateAggregation.php b/src/Builder/Aggregation/SampleRateAggregation.php new file mode 100644 index 000000000..939adc3f8 --- /dev/null +++ b/src/Builder/Aggregation/SampleRateAggregation.php @@ -0,0 +1,33 @@ +rate = $rate; + } +} diff --git a/src/Builder/Aggregation/SecondAggregation.php b/src/Builder/Aggregation/SecondAggregation.php new file mode 100644 index 000000000..0d4c5acc0 --- /dev/null +++ b/src/Builder/Aggregation/SecondAggregation.php @@ -0,0 +1,42 @@ +date = $date; + $this->timezone = $timezone; + } +} diff --git a/src/Builder/Aggregation/SetDifferenceAggregation.php b/src/Builder/Aggregation/SetDifferenceAggregation.php new file mode 100644 index 000000000..ecb3ae016 --- /dev/null +++ b/src/Builder/Aggregation/SetDifferenceAggregation.php @@ -0,0 +1,43 @@ + $expression1 The arguments can be any valid expression as long as they each resolve to an array. */ + public PackedArray|ResolvesToArray|BSONArray|array $expression1; + + /** @param BSONArray|PackedArray|ResolvesToArray|list $expression2 The arguments can be any valid expression as long as they each resolve to an array. */ + public PackedArray|ResolvesToArray|BSONArray|array $expression2; + + /** + * @param BSONArray|PackedArray|ResolvesToArray|list $expression1 The arguments can be any valid expression as long as they each resolve to an array. + * @param BSONArray|PackedArray|ResolvesToArray|list $expression2 The arguments can be any valid expression as long as they each resolve to an array. + */ + public function __construct( + PackedArray|ResolvesToArray|BSONArray|array $expression1, + PackedArray|ResolvesToArray|BSONArray|array $expression2, + ) { + if (\is_array($expression1) && ! \array_is_list($expression1)) { + throw new \InvalidArgumentException('Expected $expression1 argument to be a list, got an associative array.'); + } + $this->expression1 = $expression1; + if (\is_array($expression2) && ! \array_is_list($expression2)) { + throw new \InvalidArgumentException('Expected $expression2 argument to be a list, got an associative array.'); + } + $this->expression2 = $expression2; + } +} diff --git a/src/Builder/Aggregation/SetEqualsAggregation.php b/src/Builder/Aggregation/SetEqualsAggregation.php new file mode 100644 index 000000000..54f45f627 --- /dev/null +++ b/src/Builder/Aggregation/SetEqualsAggregation.php @@ -0,0 +1,37 @@ +> ...$expression */ + public array $expression; + + /** + * @param BSONArray|PackedArray|ResolvesToArray|list $expression + */ + public function __construct(PackedArray|ResolvesToArray|BSONArray|array ...$expression) + { + if (! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression arguments to be a list of BSONArray|PackedArray|ResolvesToArray|list, named arguments are not supported'); + } + if (\count($expression) < 1) { + throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); + } + $this->expression = $expression; + } +} diff --git a/src/Builder/Aggregation/SetFieldAggregation.php b/src/Builder/Aggregation/SetFieldAggregation.php new file mode 100644 index 000000000..980c1c3b9 --- /dev/null +++ b/src/Builder/Aggregation/SetFieldAggregation.php @@ -0,0 +1,45 @@ +field = $field; + $this->input = $input; + $this->value = $value; + } +} diff --git a/src/Builder/Aggregation/SetIntersectionAggregation.php b/src/Builder/Aggregation/SetIntersectionAggregation.php new file mode 100644 index 000000000..dc44856b3 --- /dev/null +++ b/src/Builder/Aggregation/SetIntersectionAggregation.php @@ -0,0 +1,36 @@ +> ...$expression */ + public array $expression; + + /** + * @param BSONArray|PackedArray|ResolvesToArray|list $expression + */ + public function __construct(PackedArray|ResolvesToArray|BSONArray|array ...$expression) + { + if (! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression arguments to be a list of BSONArray|PackedArray|ResolvesToArray|list, named arguments are not supported'); + } + if (\count($expression) < 1) { + throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); + } + $this->expression = $expression; + } +} diff --git a/src/Builder/Aggregation/SetIsSubsetAggregation.php b/src/Builder/Aggregation/SetIsSubsetAggregation.php new file mode 100644 index 000000000..0afa1eb49 --- /dev/null +++ b/src/Builder/Aggregation/SetIsSubsetAggregation.php @@ -0,0 +1,44 @@ + $expression1 */ + public PackedArray|ResolvesToArray|BSONArray|array $expression1; + + /** @param BSONArray|PackedArray|ResolvesToArray|list $expression2 */ + public PackedArray|ResolvesToArray|BSONArray|array $expression2; + + /** + * @param BSONArray|PackedArray|ResolvesToArray|list $expression1 + * @param BSONArray|PackedArray|ResolvesToArray|list $expression2 + */ + public function __construct( + PackedArray|ResolvesToArray|BSONArray|array $expression1, + PackedArray|ResolvesToArray|BSONArray|array $expression2, + ) { + if (\is_array($expression1) && ! \array_is_list($expression1)) { + throw new \InvalidArgumentException('Expected $expression1 argument to be a list, got an associative array.'); + } + $this->expression1 = $expression1; + if (\is_array($expression2) && ! \array_is_list($expression2)) { + throw new \InvalidArgumentException('Expected $expression2 argument to be a list, got an associative array.'); + } + $this->expression2 = $expression2; + } +} diff --git a/src/Builder/Aggregation/SetUnionAggregation.php b/src/Builder/Aggregation/SetUnionAggregation.php new file mode 100644 index 000000000..2e77cfbe3 --- /dev/null +++ b/src/Builder/Aggregation/SetUnionAggregation.php @@ -0,0 +1,36 @@ +> ...$expression */ + public array $expression; + + /** + * @param BSONArray|PackedArray|ResolvesToArray|list $expression + */ + public function __construct(PackedArray|ResolvesToArray|BSONArray|array ...$expression) + { + if (! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression arguments to be a list of BSONArray|PackedArray|ResolvesToArray|list, named arguments are not supported'); + } + if (\count($expression) < 1) { + throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); + } + $this->expression = $expression; + } +} diff --git a/src/Builder/Aggregation/ShiftAggregation.php b/src/Builder/Aggregation/ShiftAggregation.php new file mode 100644 index 000000000..f24d2beb1 --- /dev/null +++ b/src/Builder/Aggregation/ShiftAggregation.php @@ -0,0 +1,54 @@ +output = $output; + $this->by = $by; + $this->default = $default; + } +} diff --git a/src/Builder/Aggregation/SinAggregation.php b/src/Builder/Aggregation/SinAggregation.php new file mode 100644 index 000000000..da4983203 --- /dev/null +++ b/src/Builder/Aggregation/SinAggregation.php @@ -0,0 +1,35 @@ +expression = $expression; + } +} diff --git a/src/Builder/Aggregation/SinhAggregation.php b/src/Builder/Aggregation/SinhAggregation.php new file mode 100644 index 000000000..450f68091 --- /dev/null +++ b/src/Builder/Aggregation/SinhAggregation.php @@ -0,0 +1,35 @@ +expression = $expression; + } +} diff --git a/src/Builder/Aggregation/SizeAggregation.php b/src/Builder/Aggregation/SizeAggregation.php new file mode 100644 index 000000000..fba4805b0 --- /dev/null +++ b/src/Builder/Aggregation/SizeAggregation.php @@ -0,0 +1,34 @@ + $expression The argument for $size can be any expression as long as it resolves to an array. */ + public PackedArray|ResolvesToArray|BSONArray|array $expression; + + /** + * @param BSONArray|PackedArray|ResolvesToArray|list $expression The argument for $size can be any expression as long as it resolves to an array. + */ + public function __construct(PackedArray|ResolvesToArray|BSONArray|array $expression) + { + if (\is_array($expression) && ! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression argument to be a list, got an associative array.'); + } + $this->expression = $expression; + } +} diff --git a/src/Builder/Aggregation/SliceAggregation.php b/src/Builder/Aggregation/SliceAggregation.php new file mode 100644 index 000000000..6757ee320 --- /dev/null +++ b/src/Builder/Aggregation/SliceAggregation.php @@ -0,0 +1,61 @@ + $expression Any valid expression as long as it resolves to an array. */ + public PackedArray|ResolvesToArray|BSONArray|array $expression; + + /** + * @param Int64|ResolvesToInt|int $n 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. + */ + public Int64|ResolvesToInt|int $n; + + /** + * @param Int64|Optional|ResolvesToInt|int $position 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. + */ + public Int64|ResolvesToInt|Optional|int $position; + + /** + * @param BSONArray|PackedArray|ResolvesToArray|list $expression Any valid expression as long as it resolves to an array. + * @param Int64|ResolvesToInt|int $n 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. + * @param Int64|Optional|ResolvesToInt|int $position 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. + */ + public function __construct( + PackedArray|ResolvesToArray|BSONArray|array $expression, + Int64|ResolvesToInt|int $n, + Int64|ResolvesToInt|Optional|int $position = Optional::Undefined, + ) { + if (\is_array($expression) && ! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression argument to be a list, got an associative array.'); + } + $this->expression = $expression; + $this->n = $n; + $this->position = $position; + } +} diff --git a/src/Builder/Aggregation/SortArrayAggregation.php b/src/Builder/Aggregation/SortArrayAggregation.php new file mode 100644 index 000000000..0416eaea7 --- /dev/null +++ b/src/Builder/Aggregation/SortArrayAggregation.php @@ -0,0 +1,38 @@ + $input The array to be sorted. */ + public PackedArray|ResolvesToArray|BSONArray|array $input; + + /** @param array|object $sortBy The document specifies a sort ordering. */ + public array|object $sortBy; + + /** + * @param BSONArray|PackedArray|ResolvesToArray|list $input The array to be sorted. + * @param array|object $sortBy The document specifies a sort ordering. + */ + public function __construct(PackedArray|ResolvesToArray|BSONArray|array $input, array|object $sortBy) + { + if (\is_array($input) && ! \array_is_list($input)) { + throw new \InvalidArgumentException('Expected $input argument to be a list, got an associative array.'); + } + $this->input = $input; + $this->sortBy = $sortBy; + } +} diff --git a/src/Builder/Aggregation/SplitAggregation.php b/src/Builder/Aggregation/SplitAggregation.php new file mode 100644 index 000000000..78edd5b31 --- /dev/null +++ b/src/Builder/Aggregation/SplitAggregation.php @@ -0,0 +1,33 @@ +string = $string; + $this->delimiter = $delimiter; + } +} diff --git a/src/Builder/Aggregation/SqrtAggregation.php b/src/Builder/Aggregation/SqrtAggregation.php new file mode 100644 index 000000000..e056f6f3f --- /dev/null +++ b/src/Builder/Aggregation/SqrtAggregation.php @@ -0,0 +1,30 @@ +number = $number; + } +} diff --git a/src/Builder/Aggregation/StdDevPopAggregation.php b/src/Builder/Aggregation/StdDevPopAggregation.php new file mode 100644 index 000000000..1e7f138d8 --- /dev/null +++ b/src/Builder/Aggregation/StdDevPopAggregation.php @@ -0,0 +1,36 @@ + ...$expression */ + public array $expression; + + /** + * @param Decimal128|Int64|ResolvesToNumber|float|int $expression + */ + public function __construct(Decimal128|Int64|ResolvesToNumber|float|int ...$expression) + { + if (! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression arguments to be a list of Decimal128|Int64|ResolvesToNumber|float|int, named arguments are not supported'); + } + if (\count($expression) < 1) { + throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); + } + $this->expression = $expression; + } +} diff --git a/src/Builder/Aggregation/StdDevSampAggregation.php b/src/Builder/Aggregation/StdDevSampAggregation.php new file mode 100644 index 000000000..d36ebec45 --- /dev/null +++ b/src/Builder/Aggregation/StdDevSampAggregation.php @@ -0,0 +1,36 @@ + ...$expression */ + public array $expression; + + /** + * @param Decimal128|Int64|ResolvesToNumber|float|int $expression + */ + public function __construct(Decimal128|Int64|ResolvesToNumber|float|int ...$expression) + { + if (! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression arguments to be a list of Decimal128|Int64|ResolvesToNumber|float|int, named arguments are not supported'); + } + if (\count($expression) < 1) { + throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); + } + $this->expression = $expression; + } +} diff --git a/src/Builder/Aggregation/StrLenBytesAggregation.php b/src/Builder/Aggregation/StrLenBytesAggregation.php new file mode 100644 index 000000000..6deee6886 --- /dev/null +++ b/src/Builder/Aggregation/StrLenBytesAggregation.php @@ -0,0 +1,28 @@ +expression = $expression; + } +} diff --git a/src/Builder/Aggregation/StrLenCPAggregation.php b/src/Builder/Aggregation/StrLenCPAggregation.php new file mode 100644 index 000000000..ba89704c4 --- /dev/null +++ b/src/Builder/Aggregation/StrLenCPAggregation.php @@ -0,0 +1,28 @@ +expression = $expression; + } +} diff --git a/src/Builder/Aggregation/StrcasecmpAggregation.php b/src/Builder/Aggregation/StrcasecmpAggregation.php new file mode 100644 index 000000000..1bbf70ceb --- /dev/null +++ b/src/Builder/Aggregation/StrcasecmpAggregation.php @@ -0,0 +1,33 @@ +expression1 = $expression1; + $this->expression2 = $expression2; + } +} diff --git a/src/Builder/Aggregation/SubstrAggregation.php b/src/Builder/Aggregation/SubstrAggregation.php new file mode 100644 index 000000000..7c7007d20 --- /dev/null +++ b/src/Builder/Aggregation/SubstrAggregation.php @@ -0,0 +1,42 @@ +string = $string; + $this->start = $start; + $this->length = $length; + } +} diff --git a/src/Builder/Aggregation/SubstrBytesAggregation.php b/src/Builder/Aggregation/SubstrBytesAggregation.php new file mode 100644 index 000000000..99bd39d66 --- /dev/null +++ b/src/Builder/Aggregation/SubstrBytesAggregation.php @@ -0,0 +1,42 @@ +string = $string; + $this->start = $start; + $this->length = $length; + } +} diff --git a/src/Builder/Aggregation/SubstrCPAggregation.php b/src/Builder/Aggregation/SubstrCPAggregation.php new file mode 100644 index 000000000..d62dbbb48 --- /dev/null +++ b/src/Builder/Aggregation/SubstrCPAggregation.php @@ -0,0 +1,42 @@ +string = $string; + $this->start = $start; + $this->length = $length; + } +} diff --git a/src/Builder/Aggregation/SubtractAggregation.php b/src/Builder/Aggregation/SubtractAggregation.php index b3d2581ed..7db3b36e0 100644 --- a/src/Builder/Aggregation/SubtractAggregation.php +++ b/src/Builder/Aggregation/SubtractAggregation.php @@ -6,22 +6,32 @@ namespace MongoDB\Builder\Aggregation; -use MongoDB\Builder\Expression\ExpressionInterface; +use DateTimeInterface; +use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Int64; +use MongoDB\Builder\Encode; +use MongoDB\Builder\Expression\ResolvesToDate; +use MongoDB\Builder\Expression\ResolvesToNumber; -class SubtractAggregation implements ExpressionInterface +class SubtractAggregation implements ResolvesToNumber, ResolvesToDate { public const NAME = '$subtract'; - public const ENCODE = 'array'; + public const ENCODE = \MongoDB\Builder\Encode::Array; - public mixed $expression1; - public mixed $expression2; + /** @param DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int $expression1 */ + public \UTCDateTime|DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|float|int $expression1; + + /** @param DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int $expression2 */ + public \UTCDateTime|DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|float|int $expression2; /** - * @param ExpressionInterface|mixed $expression1 - * @param ExpressionInterface|mixed $expression2 + * @param DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int $expression1 + * @param DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int $expression2 */ - public function __construct(mixed $expression1, mixed $expression2) - { + public function __construct( + \UTCDateTime|DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|float|int $expression1, + \UTCDateTime|DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|float|int $expression2, + ) { $this->expression1 = $expression1; $this->expression2 = $expression2; } diff --git a/src/Builder/Aggregation/SumAggregation.php b/src/Builder/Aggregation/SumAggregation.php index 2a4e232c1..7354f7a20 100644 --- a/src/Builder/Aggregation/SumAggregation.php +++ b/src/Builder/Aggregation/SumAggregation.php @@ -6,21 +6,30 @@ namespace MongoDB\Builder\Aggregation; -use MongoDB\Builder\Expression\ExpressionInterface; -use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Int64; +use MongoDB\Builder\Encode; +use MongoDB\Builder\Expression\ResolvesToNumber; -class SumAggregation implements ResolvesToInt +class SumAggregation implements ResolvesToNumber, AccumulatorInterface { public const NAME = '$sum'; - public const ENCODE = 'single'; + public const ENCODE = \MongoDB\Builder\Encode::Single; - public mixed $expression; + /** @param list ...$expression */ + public array $expression; /** - * @param ExpressionInterface|mixed $expression + * @param Decimal128|Int64|ResolvesToNumber|float|int $expression */ - public function __construct(mixed $expression) + public function __construct(Decimal128|Int64|ResolvesToNumber|float|int ...$expression) { + if (! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression arguments to be a list of Decimal128|Int64|ResolvesToNumber|float|int, named arguments are not supported'); + } + if (\count($expression) < 1) { + throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); + } $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/SwitchAggregation.php b/src/Builder/Aggregation/SwitchAggregation.php new file mode 100644 index 000000000..a5491d7a5 --- /dev/null +++ b/src/Builder/Aggregation/SwitchAggregation.php @@ -0,0 +1,50 @@ + $branches 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. + */ + public PackedArray|BSONArray|array $branches; + + /** + * @param ExpressionInterface|Optional|mixed $default 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. + */ + public mixed $default; + + /** + * @param BSONArray|PackedArray|list $branches 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. + * @param ExpressionInterface|Optional|mixed $default 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. + */ + public function __construct(PackedArray|BSONArray|array $branches, mixed $default = Optional::Undefined) + { + if (\is_array($branches) && ! \array_is_list($branches)) { + throw new \InvalidArgumentException('Expected $branches argument to be a list, got an associative array.'); + } + $this->branches = $branches; + $this->default = $default; + } +} diff --git a/src/Builder/Aggregation/TanAggregation.php b/src/Builder/Aggregation/TanAggregation.php new file mode 100644 index 000000000..0c41ddfde --- /dev/null +++ b/src/Builder/Aggregation/TanAggregation.php @@ -0,0 +1,35 @@ +expression = $expression; + } +} diff --git a/src/Builder/Aggregation/TanhAggregation.php b/src/Builder/Aggregation/TanhAggregation.php new file mode 100644 index 000000000..501a1f1a8 --- /dev/null +++ b/src/Builder/Aggregation/TanhAggregation.php @@ -0,0 +1,35 @@ +expression = $expression; + } +} diff --git a/src/Builder/Aggregation/ToBoolAggregation.php b/src/Builder/Aggregation/ToBoolAggregation.php new file mode 100644 index 000000000..bf400965a --- /dev/null +++ b/src/Builder/Aggregation/ToBoolAggregation.php @@ -0,0 +1,28 @@ +expression = $expression; + } +} diff --git a/src/Builder/Aggregation/ToDateAggregation.php b/src/Builder/Aggregation/ToDateAggregation.php new file mode 100644 index 000000000..394754eaa --- /dev/null +++ b/src/Builder/Aggregation/ToDateAggregation.php @@ -0,0 +1,28 @@ +expression = $expression; + } +} diff --git a/src/Builder/Aggregation/ToDecimalAggregation.php b/src/Builder/Aggregation/ToDecimalAggregation.php new file mode 100644 index 000000000..590b65071 --- /dev/null +++ b/src/Builder/Aggregation/ToDecimalAggregation.php @@ -0,0 +1,28 @@ +expression = $expression; + } +} diff --git a/src/Builder/Aggregation/ToDoubleAggregation.php b/src/Builder/Aggregation/ToDoubleAggregation.php new file mode 100644 index 000000000..c3ed692f8 --- /dev/null +++ b/src/Builder/Aggregation/ToDoubleAggregation.php @@ -0,0 +1,28 @@ +expression = $expression; + } +} diff --git a/src/Builder/Aggregation/ToIntAggregation.php b/src/Builder/Aggregation/ToIntAggregation.php new file mode 100644 index 000000000..35782c8b2 --- /dev/null +++ b/src/Builder/Aggregation/ToIntAggregation.php @@ -0,0 +1,28 @@ +expression = $expression; + } +} diff --git a/src/Builder/Aggregation/ToLongAggregation.php b/src/Builder/Aggregation/ToLongAggregation.php new file mode 100644 index 000000000..a53f20ee7 --- /dev/null +++ b/src/Builder/Aggregation/ToLongAggregation.php @@ -0,0 +1,28 @@ +expression = $expression; + } +} diff --git a/src/Builder/Aggregation/ToLowerAggregation.php b/src/Builder/Aggregation/ToLowerAggregation.php new file mode 100644 index 000000000..0dc3c9dd5 --- /dev/null +++ b/src/Builder/Aggregation/ToLowerAggregation.php @@ -0,0 +1,27 @@ +expression = $expression; + } +} diff --git a/src/Builder/Aggregation/ToObjectIdAggregation.php b/src/Builder/Aggregation/ToObjectIdAggregation.php new file mode 100644 index 000000000..ae40bee36 --- /dev/null +++ b/src/Builder/Aggregation/ToObjectIdAggregation.php @@ -0,0 +1,28 @@ +expression = $expression; + } +} diff --git a/src/Builder/Aggregation/ToStringAggregation.php b/src/Builder/Aggregation/ToStringAggregation.php new file mode 100644 index 000000000..f4bcf0930 --- /dev/null +++ b/src/Builder/Aggregation/ToStringAggregation.php @@ -0,0 +1,28 @@ +expression = $expression; + } +} diff --git a/src/Builder/Aggregation/ToUpperAggregation.php b/src/Builder/Aggregation/ToUpperAggregation.php new file mode 100644 index 000000000..284f992d1 --- /dev/null +++ b/src/Builder/Aggregation/ToUpperAggregation.php @@ -0,0 +1,27 @@ +expression = $expression; + } +} diff --git a/src/Builder/Aggregation/TopAggregation.php b/src/Builder/Aggregation/TopAggregation.php new file mode 100644 index 000000000..441a8e482 --- /dev/null +++ b/src/Builder/Aggregation/TopAggregation.php @@ -0,0 +1,32 @@ +sortBy = $sortBy; + $this->output = $output; + } +} diff --git a/src/Builder/Aggregation/TopNAggregation.php b/src/Builder/Aggregation/TopNAggregation.php new file mode 100644 index 000000000..65edb0869 --- /dev/null +++ b/src/Builder/Aggregation/TopNAggregation.php @@ -0,0 +1,39 @@ +n = $n; + $this->sortBy = $sortBy; + $this->output = $output; + } +} diff --git a/src/Builder/Aggregation/TrimAggregation.php b/src/Builder/Aggregation/TrimAggregation.php new file mode 100644 index 000000000..b5e80e409 --- /dev/null +++ b/src/Builder/Aggregation/TrimAggregation.php @@ -0,0 +1,41 @@ +input = $input; + $this->chars = $chars; + } +} diff --git a/src/Builder/Aggregation/TruncAggregation.php b/src/Builder/Aggregation/TruncAggregation.php new file mode 100644 index 000000000..59f78d590 --- /dev/null +++ b/src/Builder/Aggregation/TruncAggregation.php @@ -0,0 +1,43 @@ +number = $number; + $this->place = $place; + } +} diff --git a/src/Builder/Aggregation/TsIncrementAggregation.php b/src/Builder/Aggregation/TsIncrementAggregation.php new file mode 100644 index 000000000..f2dbb2392 --- /dev/null +++ b/src/Builder/Aggregation/TsIncrementAggregation.php @@ -0,0 +1,29 @@ +expression = $expression; + } +} diff --git a/src/Builder/Aggregation/TsSecondAggregation.php b/src/Builder/Aggregation/TsSecondAggregation.php new file mode 100644 index 000000000..ea1438ec2 --- /dev/null +++ b/src/Builder/Aggregation/TsSecondAggregation.php @@ -0,0 +1,29 @@ +expression = $expression; + } +} diff --git a/src/Builder/Aggregation/TypeAggregation.php b/src/Builder/Aggregation/TypeAggregation.php new file mode 100644 index 000000000..c12dbd00e --- /dev/null +++ b/src/Builder/Aggregation/TypeAggregation.php @@ -0,0 +1,28 @@ +expression = $expression; + } +} diff --git a/src/Builder/Aggregation/UnsetFieldAggregation.php b/src/Builder/Aggregation/UnsetFieldAggregation.php new file mode 100644 index 000000000..cb99bddc9 --- /dev/null +++ b/src/Builder/Aggregation/UnsetFieldAggregation.php @@ -0,0 +1,35 @@ +field = $field; + $this->input = $input; + } +} diff --git a/src/Builder/Aggregation/WeekAggregation.php b/src/Builder/Aggregation/WeekAggregation.php new file mode 100644 index 000000000..17a9d3f57 --- /dev/null +++ b/src/Builder/Aggregation/WeekAggregation.php @@ -0,0 +1,42 @@ +date = $date; + $this->timezone = $timezone; + } +} diff --git a/src/Builder/Aggregation/YearAggregation.php b/src/Builder/Aggregation/YearAggregation.php new file mode 100644 index 000000000..f46f51581 --- /dev/null +++ b/src/Builder/Aggregation/YearAggregation.php @@ -0,0 +1,42 @@ +date = $date; + $this->timezone = $timezone; + } +} diff --git a/src/Builder/Aggregation/ZipAggregation.php b/src/Builder/Aggregation/ZipAggregation.php new file mode 100644 index 000000000..949026abe --- /dev/null +++ b/src/Builder/Aggregation/ZipAggregation.php @@ -0,0 +1,65 @@ + $inputs 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. + */ + public PackedArray|ResolvesToArray|BSONArray|array $inputs; + + /** + * @param bool $useLongestLength 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. + */ + public bool $useLongestLength; + + /** + * @param BSONArray|PackedArray|list $defaults 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. + */ + public PackedArray|BSONArray|array $defaults; + + /** + * @param BSONArray|PackedArray|ResolvesToArray|list $inputs 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. + * @param bool $useLongestLength 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. + * @param BSONArray|PackedArray|list $defaults 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. + */ + public function __construct( + PackedArray|ResolvesToArray|BSONArray|array $inputs, + bool $useLongestLength, + PackedArray|BSONArray|array $defaults, + ) { + if (\is_array($inputs) && ! \array_is_list($inputs)) { + throw new \InvalidArgumentException('Expected $inputs argument to be a list, got an associative array.'); + } + $this->inputs = $inputs; + $this->useLongestLength = $useLongestLength; + if (\is_array($defaults) && ! \array_is_list($defaults)) { + throw new \InvalidArgumentException('Expected $defaults argument to be a list, got an associative array.'); + } + $this->defaults = $defaults; + } +} diff --git a/src/Builder/BuilderEncoder.php b/src/Builder/BuilderEncoder.php index 61b618b04..44ae72968 100644 --- a/src/Builder/BuilderEncoder.php +++ b/src/Builder/BuilderEncoder.php @@ -63,17 +63,6 @@ public function encode($value): stdClass|array|string return '$$' . $value->expression; } - if ($value instanceof GroupStage) { - $result = new stdClass(); - $result->_id = $this->encodeIfSupported($value->_id); - // Specific: fields are encoded as a map of properties to their values at the top level as _id - foreach ($value->fields ?? [] as $key => $val) { - $result->{$key} = $this->encodeIfSupported($val); - } - - return $this->wrap($value, $result); - } - if ($value instanceof ProjectStage) { $result = new stdClass(); // Specific: fields are encoded as a map of properties to their values at the top level as _id @@ -84,10 +73,6 @@ public function encode($value): stdClass|array|string return $this->wrap($value, $result); } - if ($value instanceof SortStage) { - return $this->wrap($value, (object) $value->sortSpecification); - } - if ($value instanceof OrQuery) { $result = []; foreach ($value->query as $query) { @@ -115,14 +100,17 @@ public function encode($value): stdClass|array|string // The generic but incomplete encoding code switch ($value::ENCODE) { - case 'single': + case Encode::Single: return $this->encodeAsSingle($value); - case 'array': + case Encode::Array: return $this->encodeAsArray($value); - case 'object': + case Encode::Object: return $this->encodeAsObject($value); + + case Encode::Group: + return $this->encodeAsGroup($value); } throw new LogicException(sprintf('Class "%s" does not have a valid ENCODE constant.', $value::class)); @@ -166,6 +154,18 @@ private function encodeAsSingle(ExpressionInterface|StageInterface $value): stdC return $this->wrap($value, $result); } + private function encodeAsGroup(ExpressionInterface|StageInterface $value): stdClass + { + $result = new stdClass(); + $result->_id = $this->encodeIfSupported($value->_id); + // Specific: fields are encoded as a map of properties to their values at the top level as _id + foreach ($value->fields ?? [] as $key => $val) { + $result->{$key} = $this->encodeIfSupported($val); + } + + return $this->wrap($value, $result); + } + private function wrap(ExpressionInterface|StageInterface $value, mixed $result): stdClass { $object = new stdClass(); diff --git a/src/Builder/Encode.php b/src/Builder/Encode.php new file mode 100644 index 000000000..6a2752938 --- /dev/null +++ b/src/Builder/Encode.php @@ -0,0 +1,12 @@ +expression = $expression; + } +} diff --git a/src/Builder/Expression/DoubleFieldPath.php b/src/Builder/Expression/DoubleFieldPath.php new file mode 100644 index 000000000..509ee6db9 --- /dev/null +++ b/src/Builder/Expression/DoubleFieldPath.php @@ -0,0 +1,17 @@ +expression = $expression; + } +} diff --git a/src/Builder/Expression/LongFieldPath.php b/src/Builder/Expression/LongFieldPath.php new file mode 100644 index 000000000..38f49b49f --- /dev/null +++ b/src/Builder/Expression/LongFieldPath.php @@ -0,0 +1,17 @@ +expression = $expression; + } +} diff --git a/src/Builder/Expression/ObjectIdFieldPath.php b/src/Builder/Expression/ObjectIdFieldPath.php new file mode 100644 index 000000000..9c3728451 --- /dev/null +++ b/src/Builder/Expression/ObjectIdFieldPath.php @@ -0,0 +1,17 @@ +expression = $expression; + } +} diff --git a/src/Builder/Expression/ResolvesToBinary.php b/src/Builder/Expression/ResolvesToBinary.php new file mode 100644 index 000000000..14b505a83 --- /dev/null +++ b/src/Builder/Expression/ResolvesToBinary.php @@ -0,0 +1,11 @@ +expression = $expression; + } +} diff --git a/src/Builder/Query.php b/src/Builder/Query.php index 4d829cd9d..58afd1de7 100644 --- a/src/Builder/Query.php +++ b/src/Builder/Query.php @@ -6,23 +6,167 @@ namespace MongoDB\Builder; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Document; +use MongoDB\BSON\Int64; +use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; +use MongoDB\BSON\Serializable; use MongoDB\Builder\Expression\ExpressionInterface; -use MongoDB\Builder\Expression\ResolvesToBool; +use MongoDB\Builder\Query\AllQuery; use MongoDB\Builder\Query\AndQuery; +use MongoDB\Builder\Query\BitsAllClearQuery; +use MongoDB\Builder\Query\BitsAllSetQuery; +use MongoDB\Builder\Query\BitsAnyClearQuery; +use MongoDB\Builder\Query\BitsAnySetQuery; +use MongoDB\Builder\Query\BoxQuery; +use MongoDB\Builder\Query\CenterQuery; +use MongoDB\Builder\Query\CenterSphereQuery; +use MongoDB\Builder\Query\CommentQuery; +use MongoDB\Builder\Query\ElemMatchQuery; +use MongoDB\Builder\Query\EqQuery; +use MongoDB\Builder\Query\ExistsQuery; use MongoDB\Builder\Query\ExprQuery; +use MongoDB\Builder\Query\GeoIntersectsQuery; +use MongoDB\Builder\Query\GeoWithinQuery; +use MongoDB\Builder\Query\GeometryQuery; use MongoDB\Builder\Query\GtQuery; use MongoDB\Builder\Query\GteQuery; +use MongoDB\Builder\Query\InQuery; +use MongoDB\Builder\Query\JsonSchemaQuery; use MongoDB\Builder\Query\LtQuery; +use MongoDB\Builder\Query\LteQuery; +use MongoDB\Builder\Query\MaxDistanceQuery; +use MongoDB\Builder\Query\MetaQuery; +use MongoDB\Builder\Query\MinDistanceQuery; +use MongoDB\Builder\Query\ModQuery; +use MongoDB\Builder\Query\NaturalQuery; +use MongoDB\Builder\Query\NeQuery; +use MongoDB\Builder\Query\NearQuery; +use MongoDB\Builder\Query\NearSphereQuery; +use MongoDB\Builder\Query\NinQuery; +use MongoDB\Builder\Query\NorQuery; +use MongoDB\Builder\Query\NotQuery; use MongoDB\Builder\Query\OrQuery; +use MongoDB\Builder\Query\PolygonQuery; +use MongoDB\Builder\Query\QueryInterface; +use MongoDB\Builder\Query\RandQuery; +use MongoDB\Builder\Query\RegexQuery; +use MongoDB\Builder\Query\SizeQuery; +use MongoDB\Builder\Query\SliceQuery; +use MongoDB\Builder\Query\TextQuery; +use MongoDB\Builder\Query\TypeQuery; +use MongoDB\Builder\Query\WhereQuery; +use MongoDB\Model\BSONArray; final class Query { /** - * @param ResolvesToBool|bool ...$query + * @param mixed ...$value */ - public static function and(ResolvesToBool|bool ...$query): AndQuery + public static function all(mixed ...$value): AllQuery { - return new AndQuery(...$query); + return new AllQuery(...$value); + } + + /** + * @param QueryInterface|array|object ...$expression + */ + public static function and(array|object ...$expression): AndQuery + { + return new AndQuery(...$expression); + } + + /** + * @param BSONArray|Binary|Int64|PackedArray|int|list|non-empty-string $bitmask + */ + public static function bitsAllClear( + Binary|Int64|PackedArray|BSONArray|array|int|string $bitmask, + ): BitsAllClearQuery + { + return new BitsAllClearQuery($bitmask); + } + + /** + * @param BSONArray|Binary|Int64|PackedArray|int|list|non-empty-string $bitmask + */ + public static function bitsAllSet(Binary|Int64|PackedArray|BSONArray|array|int|string $bitmask): BitsAllSetQuery + { + return new BitsAllSetQuery($bitmask); + } + + /** + * @param BSONArray|Binary|Int64|PackedArray|int|list|non-empty-string $bitmask + */ + public static function bitsAnyClear( + Binary|Int64|PackedArray|BSONArray|array|int|string $bitmask, + ): BitsAnyClearQuery + { + return new BitsAnyClearQuery($bitmask); + } + + /** + * @param BSONArray|Binary|Int64|PackedArray|int|list|non-empty-string $bitmask + */ + public static function bitsAnySet(Binary|Int64|PackedArray|BSONArray|array|int|string $bitmask): BitsAnySetQuery + { + return new BitsAnySetQuery($bitmask); + } + + /** + * @param BSONArray|PackedArray|list $value + */ + public static function box(PackedArray|BSONArray|array $value): BoxQuery + { + return new BoxQuery($value); + } + + /** + * @param BSONArray|PackedArray|list $value + */ + public static function center(PackedArray|BSONArray|array $value): CenterQuery + { + return new CenterQuery($value); + } + + /** + * @param BSONArray|PackedArray|list $value + */ + public static function centerSphere(PackedArray|BSONArray|array $value): CenterSphereQuery + { + return new CenterSphereQuery($value); + } + + /** + * @param non-empty-string $comment + */ + public static function comment(string $comment): CommentQuery + { + return new CommentQuery($comment); + } + + /** + * @param Document|Serializable|array|object $queries + */ + public static function elemMatch(array|object $queries): ElemMatchQuery + { + return new ElemMatchQuery($queries); + } + + /** + * @param mixed $value + */ + public static function eq(mixed $value): EqQuery + { + return new EqQuery($value); + } + + /** + * @param bool $exists + */ + public static function exists(bool $exists): ExistsQuery + { + return new ExistsQuery($exists); } /** @@ -34,7 +178,37 @@ public static function expr(mixed $expression): ExprQuery } /** - * @param ExpressionInterface|mixed $value + * @param array|object $geometry + */ + public static function geoIntersects(array|object $geometry): GeoIntersectsQuery + { + return new GeoIntersectsQuery($geometry); + } + + /** + * @param array|object $geometry + */ + public static function geoWithin(array|object $geometry): GeoWithinQuery + { + return new GeoWithinQuery($geometry); + } + + /** + * @param non-empty-string $type + * @param BSONArray|PackedArray|list $coordinates + * @param Document|Serializable|array|object $crs + */ + public static function geometry( + string $type, + PackedArray|BSONArray|array $coordinates, + array|object $crs, + ): GeometryQuery + { + return new GeometryQuery($type, $coordinates, $crs); + } + + /** + * @param mixed $value */ public static function gt(mixed $value): GtQuery { @@ -42,7 +216,7 @@ public static function gt(mixed $value): GtQuery } /** - * @param ExpressionInterface|mixed $value + * @param mixed $value */ public static function gte(mixed $value): GteQuery { @@ -50,7 +224,23 @@ public static function gte(mixed $value): GteQuery } /** - * @param ExpressionInterface|mixed $value + * @param mixed $value + */ + public static function in(mixed $value): InQuery + { + return new InQuery($value); + } + + /** + * @param Document|Serializable|array|object $schema + */ + public static function jsonSchema(array|object $schema): JsonSchemaQuery + { + return new JsonSchemaQuery($schema); + } + + /** + * @param mixed $value */ public static function lt(mixed $value): LtQuery { @@ -58,11 +248,186 @@ public static function lt(mixed $value): LtQuery } /** - * @param ExpressionInterface|mixed ...$query + * @param mixed $value + */ + public static function lte(mixed $value): LteQuery + { + return new LteQuery($value); + } + + /** + * @param Int64|float|int $value + */ + public static function maxDistance(Int64|float|int $value): MaxDistanceQuery + { + return new MaxDistanceQuery($value); + } + + public static function meta(): MetaQuery + { + return new MetaQuery(); + } + + /** + * @param Int64|float|int $value + */ + public static function minDistance(Int64|float|int $value): MinDistanceQuery + { + return new MinDistanceQuery($value); + } + + /** + * @param Int64|int $divisor + * @param Int64|int $remainder + */ + public static function mod(Int64|int $divisor, Int64|int $remainder): ModQuery + { + return new ModQuery($divisor, $remainder); + } + + public static function natural(): NaturalQuery + { + return new NaturalQuery(); + } + + /** + * @param mixed $value + */ + public static function ne(mixed $value): NeQuery + { + return new NeQuery($value); + } + + /** + * @param array|object $geometry + * @param Int64|Optional|int $maxDistance Distance in meters. Limits the results to those documents that are at most the specified distance from the center point. + * @param Int64|Optional|int $minDistance Distance in meters. Limits the results to those documents that are at least the specified distance from the center point. + */ + public static function near( + array|object $geometry, + Int64|Optional|int $maxDistance = Optional::Undefined, + Int64|Optional|int $minDistance = Optional::Undefined, + ): NearQuery + { + return new NearQuery($geometry, $maxDistance, $minDistance); + } + + /** + * @param array|object $geometry + * @param Int64|Optional|int $maxDistance Distance in meters. + * @param Int64|Optional|int $minDistance Distance in meters. Limits the results to those documents that are at least the specified distance from the center point. + */ + public static function nearSphere( + array|object $geometry, + Int64|Optional|int $maxDistance = Optional::Undefined, + Int64|Optional|int $minDistance = Optional::Undefined, + ): NearSphereQuery + { + return new NearSphereQuery($geometry, $maxDistance, $minDistance); + } + + /** + * @param mixed $value + */ + public static function nin(mixed $value): NinQuery + { + return new NinQuery($value); + } + + /** + * @param QueryInterface|array|object ...$expression + */ + public static function nor(array|object ...$expression): NorQuery + { + return new NorQuery(...$expression); + } + + /** + * @param QueryInterface|array|object $expression + */ + public static function not(array|object $expression): NotQuery + { + return new NotQuery($expression); + } + + /** + * @param QueryInterface|array|object ...$expression + */ + public static function or(array|object ...$expression): OrQuery + { + return new OrQuery(...$expression); + } + + /** + * @param BSONArray|PackedArray|list $points + */ + public static function polygon(PackedArray|BSONArray|array $points): PolygonQuery + { + return new PolygonQuery($points); + } + + public static function rand(): RandQuery + { + return new RandQuery(); + } + + /** + * @param Regex $regex + */ + public static function regex(Regex $regex): RegexQuery + { + return new RegexQuery($regex); + } + + /** + * @param Int64|int $value + */ + public static function size(Int64|int $value): SizeQuery + { + return new SizeQuery($value); + } + + /** + * @param Int64|int $limit + * @param Int64|int $skip + */ + public static function slice(Int64|int $limit, Int64|int $skip): SliceQuery + { + return new SliceQuery($limit, $skip); + } + + /** + * @param non-empty-string $search 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. + * @param Optional|non-empty-string $language 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. + * @param Optional|bool $caseSensitive 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. + * @param Optional|bool $diacriticSensitive 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. + */ + public static function text( + string $search, + Optional|string $language = Optional::Undefined, + Optional|bool $caseSensitive = Optional::Undefined, + Optional|bool $diacriticSensitive = Optional::Undefined, + ): TextQuery + { + return new TextQuery($search, $language, $caseSensitive, $diacriticSensitive); + } + + /** + * @param BSONArray|Int64|PackedArray|int|list|non-empty-string $type + */ + public static function type(Int64|PackedArray|BSONArray|array|int|string $type): TypeQuery + { + return new TypeQuery($type); + } + + /** + * @param non-empty-string $function */ - public static function or(mixed ...$query): OrQuery + public static function where(string $function): WhereQuery { - return new OrQuery(...$query); + return new WhereQuery($function); } /** diff --git a/src/Builder/Query/AllQuery.php b/src/Builder/Query/AllQuery.php new file mode 100644 index 000000000..4f06933cf --- /dev/null +++ b/src/Builder/Query/AllQuery.php @@ -0,0 +1,32 @@ + ...$value */ + public array $value; + + /** + * @param mixed $value + */ + public function __construct(mixed ...$value) + { + if (! \array_is_list($value)) { + throw new \InvalidArgumentException('Expected $value arguments to be a list of mixed, named arguments are not supported'); + } + if (\count($value) < 1) { + throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $value, got %d.', 1, \count($value))); + } + $this->value = $value; + } +} diff --git a/src/Builder/Query/AndQuery.php b/src/Builder/Query/AndQuery.php index e572f7036..33b241566 100644 --- a/src/Builder/Query/AndQuery.php +++ b/src/Builder/Query/AndQuery.php @@ -6,25 +6,27 @@ namespace MongoDB\Builder\Query; -use MongoDB\Builder\Expression\ResolvesToBool; +use MongoDB\Builder\Encode; -class AndQuery implements ResolvesToBool +class AndQuery implements QueryInterface { public const NAME = '$and'; - public const ENCODE = 'single'; + public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param list ...$query */ - public array $query; + /** @param list ...$expression */ + public array $expression; /** - * @param ResolvesToBool|bool $query + * @param QueryInterface|array|object $expression */ - public function __construct(ResolvesToBool|bool ...$query) + public function __construct(array|object ...$expression) { - if (\count($query) < 1) { - throw new \InvalidArgumentException(\sprintf('Expected at least %d values, got %d.', 1, \count($query))); + if (! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression arguments to be a list of QueryInterface|array|object, named arguments are not supported'); } - - $this->query = $query; + if (\count($expression) < 1) { + throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); + } + $this->expression = $expression; } } diff --git a/src/Builder/Query/BitsAllClearQuery.php b/src/Builder/Query/BitsAllClearQuery.php new file mode 100644 index 000000000..3bda4c52b --- /dev/null +++ b/src/Builder/Query/BitsAllClearQuery.php @@ -0,0 +1,34 @@ +|non-empty-string $bitmask */ + public Binary|Int64|PackedArray|BSONArray|array|int|string $bitmask; + + /** + * @param BSONArray|Binary|Int64|PackedArray|int|list|non-empty-string $bitmask + */ + public function __construct(Binary|Int64|PackedArray|BSONArray|array|int|string $bitmask) + { + if (\is_array($bitmask) && ! \array_is_list($bitmask)) { + throw new \InvalidArgumentException('Expected $bitmask argument to be a list, got an associative array.'); + } + $this->bitmask = $bitmask; + } +} diff --git a/src/Builder/Query/BitsAllSetQuery.php b/src/Builder/Query/BitsAllSetQuery.php new file mode 100644 index 000000000..bb1fd5cbf --- /dev/null +++ b/src/Builder/Query/BitsAllSetQuery.php @@ -0,0 +1,34 @@ +|non-empty-string $bitmask */ + public Binary|Int64|PackedArray|BSONArray|array|int|string $bitmask; + + /** + * @param BSONArray|Binary|Int64|PackedArray|int|list|non-empty-string $bitmask + */ + public function __construct(Binary|Int64|PackedArray|BSONArray|array|int|string $bitmask) + { + if (\is_array($bitmask) && ! \array_is_list($bitmask)) { + throw new \InvalidArgumentException('Expected $bitmask argument to be a list, got an associative array.'); + } + $this->bitmask = $bitmask; + } +} diff --git a/src/Builder/Query/BitsAnyClearQuery.php b/src/Builder/Query/BitsAnyClearQuery.php new file mode 100644 index 000000000..7acc906d2 --- /dev/null +++ b/src/Builder/Query/BitsAnyClearQuery.php @@ -0,0 +1,34 @@ +|non-empty-string $bitmask */ + public Binary|Int64|PackedArray|BSONArray|array|int|string $bitmask; + + /** + * @param BSONArray|Binary|Int64|PackedArray|int|list|non-empty-string $bitmask + */ + public function __construct(Binary|Int64|PackedArray|BSONArray|array|int|string $bitmask) + { + if (\is_array($bitmask) && ! \array_is_list($bitmask)) { + throw new \InvalidArgumentException('Expected $bitmask argument to be a list, got an associative array.'); + } + $this->bitmask = $bitmask; + } +} diff --git a/src/Builder/Query/BitsAnySetQuery.php b/src/Builder/Query/BitsAnySetQuery.php new file mode 100644 index 000000000..8bfc971cc --- /dev/null +++ b/src/Builder/Query/BitsAnySetQuery.php @@ -0,0 +1,34 @@ +|non-empty-string $bitmask */ + public Binary|Int64|PackedArray|BSONArray|array|int|string $bitmask; + + /** + * @param BSONArray|Binary|Int64|PackedArray|int|list|non-empty-string $bitmask + */ + public function __construct(Binary|Int64|PackedArray|BSONArray|array|int|string $bitmask) + { + if (\is_array($bitmask) && ! \array_is_list($bitmask)) { + throw new \InvalidArgumentException('Expected $bitmask argument to be a list, got an associative array.'); + } + $this->bitmask = $bitmask; + } +} diff --git a/src/Builder/Query/BoxQuery.php b/src/Builder/Query/BoxQuery.php new file mode 100644 index 000000000..febce3623 --- /dev/null +++ b/src/Builder/Query/BoxQuery.php @@ -0,0 +1,32 @@ + $value */ + public PackedArray|BSONArray|array $value; + + /** + * @param BSONArray|PackedArray|list $value + */ + public function __construct(PackedArray|BSONArray|array $value) + { + if (\is_array($value) && ! \array_is_list($value)) { + throw new \InvalidArgumentException('Expected $value argument to be a list, got an associative array.'); + } + $this->value = $value; + } +} diff --git a/src/Builder/Query/CenterQuery.php b/src/Builder/Query/CenterQuery.php new file mode 100644 index 000000000..3818b4d2a --- /dev/null +++ b/src/Builder/Query/CenterQuery.php @@ -0,0 +1,32 @@ + $value */ + public PackedArray|BSONArray|array $value; + + /** + * @param BSONArray|PackedArray|list $value + */ + public function __construct(PackedArray|BSONArray|array $value) + { + if (\is_array($value) && ! \array_is_list($value)) { + throw new \InvalidArgumentException('Expected $value argument to be a list, got an associative array.'); + } + $this->value = $value; + } +} diff --git a/src/Builder/Query/CenterSphereQuery.php b/src/Builder/Query/CenterSphereQuery.php new file mode 100644 index 000000000..4ca66cbd7 --- /dev/null +++ b/src/Builder/Query/CenterSphereQuery.php @@ -0,0 +1,32 @@ + $value */ + public PackedArray|BSONArray|array $value; + + /** + * @param BSONArray|PackedArray|list $value + */ + public function __construct(PackedArray|BSONArray|array $value) + { + if (\is_array($value) && ! \array_is_list($value)) { + throw new \InvalidArgumentException('Expected $value argument to be a list, got an associative array.'); + } + $this->value = $value; + } +} diff --git a/src/Builder/Query/CommentQuery.php b/src/Builder/Query/CommentQuery.php new file mode 100644 index 000000000..978c68151 --- /dev/null +++ b/src/Builder/Query/CommentQuery.php @@ -0,0 +1,27 @@ +comment = $comment; + } +} diff --git a/src/Builder/Query/ElemMatchQuery.php b/src/Builder/Query/ElemMatchQuery.php new file mode 100644 index 000000000..c3c21f014 --- /dev/null +++ b/src/Builder/Query/ElemMatchQuery.php @@ -0,0 +1,28 @@ +queries = $queries; + } +} diff --git a/src/Builder/Query/EqQuery.php b/src/Builder/Query/EqQuery.php new file mode 100644 index 000000000..1715a6809 --- /dev/null +++ b/src/Builder/Query/EqQuery.php @@ -0,0 +1,26 @@ +value = $value; + } +} diff --git a/src/Builder/Query/ExistsQuery.php b/src/Builder/Query/ExistsQuery.php new file mode 100644 index 000000000..ee047828d --- /dev/null +++ b/src/Builder/Query/ExistsQuery.php @@ -0,0 +1,26 @@ +exists = $exists; + } +} diff --git a/src/Builder/Query/ExprQuery.php b/src/Builder/Query/ExprQuery.php index 810652b9c..fa2ca1781 100644 --- a/src/Builder/Query/ExprQuery.php +++ b/src/Builder/Query/ExprQuery.php @@ -6,13 +6,15 @@ namespace MongoDB\Builder\Query; +use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ExpressionInterface; -class ExprQuery implements ExpressionInterface +class ExprQuery implements QueryInterface { public const NAME = '$expr'; - public const ENCODE = 'single'; + public const ENCODE = \MongoDB\Builder\Encode::Single; + /** @param ExpressionInterface|mixed $expression */ public mixed $expression; /** diff --git a/src/Builder/Query/GeoIntersectsQuery.php b/src/Builder/Query/GeoIntersectsQuery.php new file mode 100644 index 000000000..5f3dc9474 --- /dev/null +++ b/src/Builder/Query/GeoIntersectsQuery.php @@ -0,0 +1,26 @@ +geometry = $geometry; + } +} diff --git a/src/Builder/Query/GeoWithinQuery.php b/src/Builder/Query/GeoWithinQuery.php new file mode 100644 index 000000000..3815ca29f --- /dev/null +++ b/src/Builder/Query/GeoWithinQuery.php @@ -0,0 +1,26 @@ +geometry = $geometry; + } +} diff --git a/src/Builder/Query/GeometryQuery.php b/src/Builder/Query/GeometryQuery.php new file mode 100644 index 000000000..1441a37dc --- /dev/null +++ b/src/Builder/Query/GeometryQuery.php @@ -0,0 +1,44 @@ + $coordinates */ + public PackedArray|BSONArray|array $coordinates; + + /** @param Document|Serializable|array|object $crs */ + public array|object $crs; + + /** + * @param non-empty-string $type + * @param BSONArray|PackedArray|list $coordinates + * @param Document|Serializable|array|object $crs + */ + public function __construct(string $type, PackedArray|BSONArray|array $coordinates, array|object $crs) + { + $this->type = $type; + if (\is_array($coordinates) && ! \array_is_list($coordinates)) { + throw new \InvalidArgumentException('Expected $coordinates argument to be a list, got an associative array.'); + } + $this->coordinates = $coordinates; + $this->crs = $crs; + } +} diff --git a/src/Builder/Query/GtQuery.php b/src/Builder/Query/GtQuery.php index 58c558aed..c43c6eeb3 100644 --- a/src/Builder/Query/GtQuery.php +++ b/src/Builder/Query/GtQuery.php @@ -6,18 +6,18 @@ namespace MongoDB\Builder\Query; -use MongoDB\Builder\Expression\ExpressionInterface; -use MongoDB\Builder\Expression\ResolvesToBool; +use MongoDB\Builder\Encode; -class GtQuery implements ResolvesToBool +class GtQuery implements QueryInterface { public const NAME = '$gt'; - public const ENCODE = 'single'; + public const ENCODE = \MongoDB\Builder\Encode::Single; + /** @param mixed $value */ public mixed $value; /** - * @param ExpressionInterface|mixed $value + * @param mixed $value */ public function __construct(mixed $value) { diff --git a/src/Builder/Query/GteQuery.php b/src/Builder/Query/GteQuery.php index 130a56bd4..57be997a5 100644 --- a/src/Builder/Query/GteQuery.php +++ b/src/Builder/Query/GteQuery.php @@ -6,18 +6,18 @@ namespace MongoDB\Builder\Query; -use MongoDB\Builder\Expression\ExpressionInterface; -use MongoDB\Builder\Expression\ResolvesToBool; +use MongoDB\Builder\Encode; -class GteQuery implements ResolvesToBool +class GteQuery implements QueryInterface { public const NAME = '$gte'; - public const ENCODE = 'single'; + public const ENCODE = \MongoDB\Builder\Encode::Single; + /** @param mixed $value */ public mixed $value; /** - * @param ExpressionInterface|mixed $value + * @param mixed $value */ public function __construct(mixed $value) { diff --git a/src/Builder/Query/InQuery.php b/src/Builder/Query/InQuery.php new file mode 100644 index 000000000..88ea165a1 --- /dev/null +++ b/src/Builder/Query/InQuery.php @@ -0,0 +1,26 @@ +value = $value; + } +} diff --git a/src/Builder/Query/JsonSchemaQuery.php b/src/Builder/Query/JsonSchemaQuery.php new file mode 100644 index 000000000..9a9ac54d2 --- /dev/null +++ b/src/Builder/Query/JsonSchemaQuery.php @@ -0,0 +1,28 @@ +schema = $schema; + } +} diff --git a/src/Builder/Query/LtQuery.php b/src/Builder/Query/LtQuery.php index 621fd7d26..b6c2c92fc 100644 --- a/src/Builder/Query/LtQuery.php +++ b/src/Builder/Query/LtQuery.php @@ -6,18 +6,18 @@ namespace MongoDB\Builder\Query; -use MongoDB\Builder\Expression\ExpressionInterface; -use MongoDB\Builder\Expression\ResolvesToBool; +use MongoDB\Builder\Encode; -class LtQuery implements ResolvesToBool +class LtQuery implements QueryInterface { public const NAME = '$lt'; - public const ENCODE = 'single'; + public const ENCODE = \MongoDB\Builder\Encode::Single; + /** @param mixed $value */ public mixed $value; /** - * @param ExpressionInterface|mixed $value + * @param mixed $value */ public function __construct(mixed $value) { diff --git a/src/Builder/Query/LteQuery.php b/src/Builder/Query/LteQuery.php new file mode 100644 index 000000000..b14fba3ed --- /dev/null +++ b/src/Builder/Query/LteQuery.php @@ -0,0 +1,26 @@ +value = $value; + } +} diff --git a/src/Builder/Query/MaxDistanceQuery.php b/src/Builder/Query/MaxDistanceQuery.php new file mode 100644 index 000000000..5341852f0 --- /dev/null +++ b/src/Builder/Query/MaxDistanceQuery.php @@ -0,0 +1,27 @@ +value = $value; + } +} diff --git a/src/Builder/Query/MetaQuery.php b/src/Builder/Query/MetaQuery.php new file mode 100644 index 000000000..6586ad448 --- /dev/null +++ b/src/Builder/Query/MetaQuery.php @@ -0,0 +1,20 @@ +value = $value; + } +} diff --git a/src/Builder/Query/ModQuery.php b/src/Builder/Query/ModQuery.php new file mode 100644 index 000000000..5560af79c --- /dev/null +++ b/src/Builder/Query/ModQuery.php @@ -0,0 +1,32 @@ +divisor = $divisor; + $this->remainder = $remainder; + } +} diff --git a/src/Builder/Query/NaturalQuery.php b/src/Builder/Query/NaturalQuery.php new file mode 100644 index 000000000..c7b008680 --- /dev/null +++ b/src/Builder/Query/NaturalQuery.php @@ -0,0 +1,20 @@ +value = $value; + } +} diff --git a/src/Builder/Query/NearQuery.php b/src/Builder/Query/NearQuery.php new file mode 100644 index 000000000..e385f82ac --- /dev/null +++ b/src/Builder/Query/NearQuery.php @@ -0,0 +1,41 @@ +geometry = $geometry; + $this->maxDistance = $maxDistance; + $this->minDistance = $minDistance; + } +} diff --git a/src/Builder/Query/NearSphereQuery.php b/src/Builder/Query/NearSphereQuery.php new file mode 100644 index 000000000..1e2764104 --- /dev/null +++ b/src/Builder/Query/NearSphereQuery.php @@ -0,0 +1,41 @@ +geometry = $geometry; + $this->maxDistance = $maxDistance; + $this->minDistance = $minDistance; + } +} diff --git a/src/Builder/Query/NinQuery.php b/src/Builder/Query/NinQuery.php new file mode 100644 index 000000000..6eae4ee26 --- /dev/null +++ b/src/Builder/Query/NinQuery.php @@ -0,0 +1,26 @@ +value = $value; + } +} diff --git a/src/Builder/Query/NorQuery.php b/src/Builder/Query/NorQuery.php new file mode 100644 index 000000000..eabf24b67 --- /dev/null +++ b/src/Builder/Query/NorQuery.php @@ -0,0 +1,32 @@ + ...$expression */ + public array $expression; + + /** + * @param QueryInterface|array|object $expression + */ + public function __construct(array|object ...$expression) + { + if (! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression arguments to be a list of QueryInterface|array|object, named arguments are not supported'); + } + if (\count($expression) < 1) { + throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); + } + $this->expression = $expression; + } +} diff --git a/src/Builder/Query/NotQuery.php b/src/Builder/Query/NotQuery.php new file mode 100644 index 000000000..84a3ad0d6 --- /dev/null +++ b/src/Builder/Query/NotQuery.php @@ -0,0 +1,26 @@ +expression = $expression; + } +} diff --git a/src/Builder/Query/OrQuery.php b/src/Builder/Query/OrQuery.php index 5149b7cbc..9d0acad82 100644 --- a/src/Builder/Query/OrQuery.php +++ b/src/Builder/Query/OrQuery.php @@ -6,26 +6,27 @@ namespace MongoDB\Builder\Query; -use MongoDB\Builder\Expression\ExpressionInterface; -use MongoDB\Builder\Expression\ResolvesToBool; +use MongoDB\Builder\Encode; -class OrQuery implements ResolvesToBool +class OrQuery implements QueryInterface { public const NAME = '$or'; - public const ENCODE = 'single'; + public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param list ...$query */ - public array $query; + /** @param list ...$expression */ + public array $expression; /** - * @param ExpressionInterface|mixed $query + * @param QueryInterface|array|object $expression */ - public function __construct(mixed ...$query) + public function __construct(array|object ...$expression) { - if (\count($query) < 1) { - throw new \InvalidArgumentException(\sprintf('Expected at least %d values, got %d.', 1, \count($query))); + if (! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression arguments to be a list of QueryInterface|array|object, named arguments are not supported'); } - - $this->query = $query; + if (\count($expression) < 1) { + throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); + } + $this->expression = $expression; } } diff --git a/src/Builder/Query/PolygonQuery.php b/src/Builder/Query/PolygonQuery.php new file mode 100644 index 000000000..bacb2ec38 --- /dev/null +++ b/src/Builder/Query/PolygonQuery.php @@ -0,0 +1,32 @@ + $points */ + public PackedArray|BSONArray|array $points; + + /** + * @param BSONArray|PackedArray|list $points + */ + public function __construct(PackedArray|BSONArray|array $points) + { + if (\is_array($points) && ! \array_is_list($points)) { + throw new \InvalidArgumentException('Expected $points argument to be a list, got an associative array.'); + } + $this->points = $points; + } +} diff --git a/src/Builder/Query/Query.php b/src/Builder/Query/Query.php new file mode 100644 index 000000000..06643c99f --- /dev/null +++ b/src/Builder/Query/Query.php @@ -0,0 +1,26 @@ +geometry = $geometry; + } +} diff --git a/src/Builder/Query/QueryInterface.php b/src/Builder/Query/QueryInterface.php new file mode 100644 index 000000000..72b0862ac --- /dev/null +++ b/src/Builder/Query/QueryInterface.php @@ -0,0 +1,11 @@ +regex = $regex; + } +} diff --git a/src/Builder/Query/SizeQuery.php b/src/Builder/Query/SizeQuery.php new file mode 100644 index 000000000..8fafaa4f4 --- /dev/null +++ b/src/Builder/Query/SizeQuery.php @@ -0,0 +1,27 @@ +value = $value; + } +} diff --git a/src/Builder/Query/SliceQuery.php b/src/Builder/Query/SliceQuery.php new file mode 100644 index 000000000..8cf104d5f --- /dev/null +++ b/src/Builder/Query/SliceQuery.php @@ -0,0 +1,32 @@ +limit = $limit; + $this->skip = $skip; + } +} diff --git a/src/Builder/Query/TextQuery.php b/src/Builder/Query/TextQuery.php new file mode 100644 index 000000000..ab7b82e5a --- /dev/null +++ b/src/Builder/Query/TextQuery.php @@ -0,0 +1,54 @@ +search = $search; + $this->language = $language; + $this->caseSensitive = $caseSensitive; + $this->diacriticSensitive = $diacriticSensitive; + } +} diff --git a/src/Builder/Query/TypeQuery.php b/src/Builder/Query/TypeQuery.php new file mode 100644 index 000000000..a1177bafd --- /dev/null +++ b/src/Builder/Query/TypeQuery.php @@ -0,0 +1,33 @@ +|non-empty-string $type */ + public Int64|PackedArray|BSONArray|array|int|string $type; + + /** + * @param BSONArray|Int64|PackedArray|int|list|non-empty-string $type + */ + public function __construct(Int64|PackedArray|BSONArray|array|int|string $type) + { + if (\is_array($type) && ! \array_is_list($type)) { + throw new \InvalidArgumentException('Expected $type argument to be a list, got an associative array.'); + } + $this->type = $type; + } +} diff --git a/src/Builder/Query/WhereQuery.php b/src/Builder/Query/WhereQuery.php new file mode 100644 index 000000000..5b169201e --- /dev/null +++ b/src/Builder/Query/WhereQuery.php @@ -0,0 +1,26 @@ +function = $function; + } +} diff --git a/src/Builder/Stage.php b/src/Builder/Stage.php index 7466925bd..4f561ba9a 100644 --- a/src/Builder/Stage.php +++ b/src/Builder/Stage.php @@ -6,25 +6,288 @@ namespace MongoDB\Builder; +use MongoDB\BSON\Decimal128; use MongoDB\BSON\Document; use MongoDB\BSON\Int64; +use MongoDB\BSON\PackedArray; use MongoDB\BSON\Serializable; +use MongoDB\Builder\Aggregation\AccumulatorInterface; +use MongoDB\Builder\Expression\ArrayFieldPath; use MongoDB\Builder\Expression\ExpressionInterface; +use MongoDB\Builder\Expression\FieldPath; +use MongoDB\Builder\Expression\ResolvesToArray; +use MongoDB\Builder\Expression\ResolvesToObject; +use MongoDB\Builder\Query\QueryInterface; +use MongoDB\Builder\Stage\AddFieldsStage; +use MongoDB\Builder\Stage\BucketAutoStage; +use MongoDB\Builder\Stage\BucketStage; +use MongoDB\Builder\Stage\ChangeStreamSplitLargeEventStage; +use MongoDB\Builder\Stage\ChangeStreamStage; +use MongoDB\Builder\Stage\CollStatsStage; +use MongoDB\Builder\Stage\CountStage; +use MongoDB\Builder\Stage\CurrentOpStage; +use MongoDB\Builder\Stage\DensifyStage; +use MongoDB\Builder\Stage\DocumentsStage; +use MongoDB\Builder\Stage\FacetStage; +use MongoDB\Builder\Stage\FillStage; +use MongoDB\Builder\Stage\GeoNearStage; +use MongoDB\Builder\Stage\GraphLookupStage; use MongoDB\Builder\Stage\GroupStage; +use MongoDB\Builder\Stage\IndexStatsStage; use MongoDB\Builder\Stage\LimitStage; +use MongoDB\Builder\Stage\ListLocalSessionsStage; +use MongoDB\Builder\Stage\ListSampledQueriesStage; +use MongoDB\Builder\Stage\ListSearchIndexesStage; +use MongoDB\Builder\Stage\ListSessionsStage; +use MongoDB\Builder\Stage\LookupStage; use MongoDB\Builder\Stage\MatchStage; +use MongoDB\Builder\Stage\MergeStage; +use MongoDB\Builder\Stage\OutStage; +use MongoDB\Builder\Stage\PlanCacheStatsStage; use MongoDB\Builder\Stage\ProjectStage; +use MongoDB\Builder\Stage\RedactStage; +use MongoDB\Builder\Stage\ReplaceRootStage; +use MongoDB\Builder\Stage\ReplaceWithStage; +use MongoDB\Builder\Stage\SampleStage; +use MongoDB\Builder\Stage\SearchMetaStage; +use MongoDB\Builder\Stage\SearchStage; +use MongoDB\Builder\Stage\SetStage; +use MongoDB\Builder\Stage\SetWindowFieldsStage; +use MongoDB\Builder\Stage\ShardedDataDistributionStage; +use MongoDB\Builder\Stage\SkipStage; +use MongoDB\Builder\Stage\SortByCountStage; use MongoDB\Builder\Stage\SortStage; +use MongoDB\Builder\Stage\UnionWithStage; +use MongoDB\Builder\Stage\UnsetStage; +use MongoDB\Builder\Stage\UnwindStage; +use MongoDB\Model\BSONArray; final class Stage { /** - * @param ExpressionInterface|mixed|null $_id - * @param ExpressionInterface|mixed ...$fields + * @param ExpressionInterface|mixed ...$expression Specify the name of each field to add and set its value to an aggregation expression or an empty object. */ - public static function group(mixed $_id, mixed ...$fields): GroupStage + public static function addFields(mixed ...$expression): AddFieldsStage { - return new GroupStage($_id, ...$fields); + return new AddFieldsStage(...$expression); + } + + /** + * @param ExpressionInterface|FieldPath|mixed|non-empty-string $groupBy 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. + * @param BSONArray|PackedArray|list $boundaries 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: + * @param ExpressionInterface|Optional|mixed $default 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. + * @param Document|Optional|Serializable|array|object $output 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. + */ + public static function bucket( + mixed $groupBy, + PackedArray|BSONArray|array $boundaries, + mixed $default = Optional::Undefined, + array|object $output = Optional::Undefined, + ): BucketStage + { + return new BucketStage($groupBy, $boundaries, $default, $output); + } + + /** + * @param ExpressionInterface|mixed $groupBy An expression to group documents by. To specify a field path, prefix the field name with a dollar sign $ and enclose it in quotes. + * @param Int64|int $buckets A positive 32-bit integer that specifies the number of buckets into which input documents are grouped. + * @param Document|Optional|Serializable|array|object $output 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. + * @param Optional|non-empty-string $granularity 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. + */ + public static function bucketAuto( + mixed $groupBy, + Int64|int $buckets, + array|object $output = Optional::Undefined, + Optional|string $granularity = Optional::Undefined, + ): BucketAutoStage + { + return new BucketAutoStage($groupBy, $buckets, $output, $granularity); + } + + /** + * @param Optional|bool $allChangesForCluster A flag indicating whether the stream should report all changes that occur on the deployment, aside from those on internal databases or collections. + * @param Optional|non-empty-string $fullDocument Specifies whether change notifications include a copy of the full document when modified by update operations. + * @param Optional|non-empty-string $fullDocumentBeforeChange 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. + * @param Int64|Optional|int $resumeAfter Specifies a resume token as the logical starting point for the change stream. Cannot be used with startAfter or startAtOperationTime fields. + * @param Optional|bool $showExpandedEvents Specifies whether to include additional change events, such as such as DDL and index operations. + * New in version 6.0. + * @param Document|Optional|Serializable|array|object $startAfter Specifies a resume token as the logical starting point for the change stream. Cannot be used with resumeAfter or startAtOperationTime fields. + * @param Optional|int $startAtOperationTime Specifies a time as the logical starting point for the change stream. Cannot be used with resumeAfter or startAfter fields. + */ + public static function changeStream( + Optional|bool $allChangesForCluster = Optional::Undefined, + Optional|string $fullDocument = Optional::Undefined, + Optional|string $fullDocumentBeforeChange = Optional::Undefined, + Int64|Optional|int $resumeAfter = Optional::Undefined, + Optional|bool $showExpandedEvents = Optional::Undefined, + array|object $startAfter = Optional::Undefined, + Optional|int $startAtOperationTime = Optional::Undefined, + ): ChangeStreamStage + { + return new ChangeStreamStage($allChangesForCluster, $fullDocument, $fullDocumentBeforeChange, $resumeAfter, $showExpandedEvents, $startAfter, $startAtOperationTime); + } + + public static function changeStreamSplitLargeEvent(): ChangeStreamSplitLargeEventStage + { + return new ChangeStreamSplitLargeEventStage(); + } + + /** + * @param Document|Serializable|array|object $config + */ + public static function collStats(array|object $config): CollStatsStage + { + return new CollStatsStage($config); + } + + /** + * @param non-empty-string $field + */ + public static function count(string $field): CountStage + { + return new CountStage($field); + } + + public static function currentOp(): CurrentOpStage + { + return new CurrentOpStage(); + } + + /** + * @param FieldPath|non-empty-string $field 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. + * @param array|object $range Specification for range based densification. + * @param BSONArray|Optional|PackedArray|list $partitionByFields The field(s) that will be used as the partition keys. + */ + public static function densify( + FieldPath|string $field, + array|object $range, + PackedArray|Optional|BSONArray|array $partitionByFields = Optional::Undefined, + ): DensifyStage + { + return new DensifyStage($field, $range, $partitionByFields); + } + + /** + * @param BSONArray|PackedArray|ResolvesToArray|list $documents $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. + */ + public static function documents(PackedArray|ResolvesToArray|BSONArray|array $documents): DocumentsStage + { + return new DocumentsStage($documents); + } + + /** + * @param Pipeline|array ...$facet + */ + public static function facet(Pipeline|array ...$facet): FacetStage + { + return new FacetStage(...$facet); + } + + /** + * @param Document|Serializable|array|object $output 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. + * @param Document|Optional|Serializable|array|non-empty-string|object $partitionBy 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. + * @param BSONArray|Optional|PackedArray|list $partitionByFields 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. + * @param Optional|array|object $sortBy Specifies the field or fields to sort the documents within each partition. Uses the same syntax as the $sort stage. + */ + public static function fill( + array|object $output, + array|object|string $partitionBy = Optional::Undefined, + PackedArray|Optional|BSONArray|array $partitionByFields = Optional::Undefined, + array|object $sortBy = Optional::Undefined, + ): FillStage + { + return new FillStage($output, $partitionBy, $partitionByFields, $sortBy); + } + + /** + * @param non-empty-string $distanceField The output field that contains the calculated distance. To specify a field within an embedded document, use dot notation. + * @param array|object $near The point for which to find the closest documents. + * @param Decimal128|Int64|Optional|float|int $distanceMultiplier 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. + * @param Optional|non-empty-string $includeLocs 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. + * @param Optional|non-empty-string $key Specify the geospatial indexed field to use when calculating the distance. + * @param Decimal128|Int64|Optional|float|int $maxDistance 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. + * @param Decimal128|Int64|Optional|float|int $minDistance 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. + * @param Optional|QueryInterface|array|object $query imits 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. + * @param Optional|bool $spherical 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. + */ + public static function geoNear( + string $distanceField, + array|object $near, + Decimal128|Int64|Optional|float|int $distanceMultiplier = Optional::Undefined, + Optional|string $includeLocs = Optional::Undefined, + Optional|string $key = Optional::Undefined, + Decimal128|Int64|Optional|float|int $maxDistance = Optional::Undefined, + Decimal128|Int64|Optional|float|int $minDistance = Optional::Undefined, + array|object $query = Optional::Undefined, + Optional|bool $spherical = Optional::Undefined, + ): GeoNearStage + { + return new GeoNearStage($distanceField, $near, $distanceMultiplier, $includeLocs, $key, $maxDistance, $minDistance, $query, $spherical); + } + + /** + * @param non-empty-string $from 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. + * @param BSONArray|ExpressionInterface|PackedArray|list|mixed $startWith 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. + * @param non-empty-string $connectFromField 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. + * @param non-empty-string $connectToField Field name in other documents against which to match the value of the field specified by the connectFromField parameter. + * @param non-empty-string $as Name of the array field added to each output document. Contains the documents traversed in the $graphLookup stage to reach the document. + * @param Int64|Optional|int $maxDepth Non-negative integral number specifying the maximum recursion depth. + * @param Optional|non-empty-string $depthField 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. + * @param Optional|QueryInterface|array|object $restrictSearchWithMatch A document specifying additional conditions for the recursive search. The syntax is identical to query filter syntax. + */ + public static function graphLookup( + string $from, + mixed $startWith, + string $connectFromField, + string $connectToField, + string $as, + Int64|Optional|int $maxDepth = Optional::Undefined, + Optional|string $depthField = Optional::Undefined, + array|object $restrictSearchWithMatch = Optional::Undefined, + ): GraphLookupStage + { + return new GraphLookupStage($from, $startWith, $connectFromField, $connectToField, $as, $maxDepth, $depthField, $restrictSearchWithMatch); + } + + /** + * @param ExpressionInterface|mixed $_id 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. + * @param AccumulatorInterface ...$field Computed using the accumulator operators. + */ + public static function group(mixed $_id, AccumulatorInterface ...$field): GroupStage + { + return new GroupStage($_id, ...$field); + } + + public static function indexStats(): IndexStatsStage + { + return new IndexStatsStage(); } /** @@ -36,27 +299,253 @@ public static function limit(Int64|int $limit): LimitStage } /** - * @param ExpressionInterface|mixed $query + * @param BSONArray|Optional|PackedArray|list $users 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. + * @param Optional|bool $allUsers Returns all sessions for all users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster. + */ + public static function listLocalSessions( + PackedArray|Optional|BSONArray|array $users = Optional::Undefined, + Optional|bool $allUsers = Optional::Undefined, + ): ListLocalSessionsStage + { + return new ListLocalSessionsStage($users, $allUsers); + } + + /** + * @param Optional|non-empty-string $namespace + */ + public static function listSampledQueries( + Optional|string $namespace = Optional::Undefined, + ): ListSampledQueriesStage + { + return new ListSampledQueriesStage($namespace); + } + + /** + * @param Optional|non-empty-string $id The id of the index to return information about. + * @param Optional|non-empty-string $name The name of the index to return information about. + */ + public static function listSearchIndexes( + Optional|string $id = Optional::Undefined, + Optional|string $name = Optional::Undefined, + ): ListSearchIndexesStage + { + return new ListSearchIndexesStage($id, $name); + } + + /** + * @param BSONArray|Optional|PackedArray|list $users 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. + * @param Optional|bool $allUsers Returns all sessions for all users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster. + */ + public static function listSessions( + PackedArray|Optional|BSONArray|array $users = Optional::Undefined, + Optional|bool $allUsers = Optional::Undefined, + ): ListSessionsStage + { + return new ListSessionsStage($users, $allUsers); + } + + /** + * @param non-empty-string $as 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. + * @param Optional|non-empty-string $from 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. + * @param Optional|non-empty-string $localField 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. + * @param Optional|non-empty-string $foreignField 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. + * @param Document|Optional|Serializable|array|object $let 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. + * @param Optional|Pipeline|array $pipeline 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 $mergestage. 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. + */ + public static function lookup( + string $as, + Optional|string $from = Optional::Undefined, + Optional|string $localField = Optional::Undefined, + Optional|string $foreignField = Optional::Undefined, + array|object $let = Optional::Undefined, + Optional|Pipeline|array $pipeline = Optional::Undefined, + ): LookupStage + { + return new LookupStage($as, $from, $localField, $foreignField, $let, $pipeline); + } + + /** + * @param QueryInterface|array|object ...$query + */ + public static function match(array|object ...$query): MatchStage + { + return new MatchStage(...$query); + } + + /** + * @param array|non-empty-string|object $into The output collection. + * @param BSONArray|Optional|PackedArray|list|non-empty-string $on 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. + * @param Document|Optional|Serializable|array|object $let Specifies variables for use in the whenMatched pipeline. + * @param Optional|non-empty-string $whenMatched 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). + * @param Optional|non-empty-string $whenNotMatched The behavior of $merge if a result document does not match an existing document in the out collection. + */ + public static function merge( + array|object|string $into, + PackedArray|Optional|BSONArray|array|string $on = Optional::Undefined, + array|object $let = Optional::Undefined, + Optional|string $whenMatched = Optional::Undefined, + Optional|string $whenNotMatched = Optional::Undefined, + ): MergeStage + { + return new MergeStage($into, $on, $let, $whenMatched, $whenNotMatched); + } + + /** + * @param non-empty-string $db Target collection name to write documents from $out to. + * @param non-empty-string $coll Target database name to write documents from $out to. + * @param Document|Serializable|array|object $timeseries If set, the aggregation stage will use these options to create or replace a time-series collection in the given namespace. + */ + public static function out(string $db, string $coll, array|object $timeseries): OutStage + { + return new OutStage($db, $coll, $timeseries); + } + + public static function planCacheStats(): PlanCacheStatsStage + { + return new PlanCacheStatsStage(); + } + + /** + * @param ExpressionInterface|Int64|bool|int|mixed ...$specification + */ + public static function project(mixed ...$specification): ProjectStage + { + return new ProjectStage(...$specification); + } + + /** + * @param ExpressionInterface|mixed $expression + */ + public static function redact(mixed $expression): RedactStage + { + return new RedactStage($expression); + } + + /** + * @param Document|ResolvesToObject|Serializable|array|object $newRoot + */ + public static function replaceRoot(array|object $newRoot): ReplaceRootStage + { + return new ReplaceRootStage($newRoot); + } + + /** + * @param Document|ResolvesToObject|Serializable|array|object $expression + */ + public static function replaceWith(array|object $expression): ReplaceWithStage + { + return new ReplaceWithStage($expression); + } + + /** + * @param Int64|int $size The number of documents to randomly select. + */ + public static function sample(Int64|int $size): SampleStage + { + return new SampleStage($size); + } + + /** + * @param Document|Serializable|array|object $search + */ + public static function search(array|object $search): SearchStage + { + return new SearchStage($search); + } + + /** + * @param Document|Serializable|array|object $meta + */ + public static function searchMeta(array|object $meta): SearchMetaStage + { + return new SearchMetaStage($meta); + } + + /** + * @param ExpressionInterface|mixed ...$field + */ + public static function set(mixed ...$field): SetStage + { + return new SetStage(...$field); + } + + /** + * @param ExpressionInterface|mixed $partitionBy 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. + * @param array|object $sortBy Specifies the field(s) to sort the documents by in the partition. Uses the same syntax as the $sort stage. Default is no sorting. + * @param Document|Serializable|array|object $output 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. + * @param Optional|array|object $window Specifies the window boundaries and parameters. Window boundaries are inclusive. Default is an unbounded window, which includes all documents in the partition. + */ + public static function setWindowFields( + mixed $partitionBy, + array|object $sortBy, + array|object $output, + array|object $window = Optional::Undefined, + ): SetWindowFieldsStage + { + return new SetWindowFieldsStage($partitionBy, $sortBy, $output, $window); + } + + public static function shardedDataDistribution(): ShardedDataDistributionStage + { + return new ShardedDataDistributionStage(); + } + + /** + * @param Int64|int $skip + */ + public static function skip(Int64|int $skip): SkipStage + { + return new SkipStage($skip); + } + + /** + * @param array|object $sort + */ + public static function sort(array|object $sort): SortStage + { + return new SortStage($sort); + } + + /** + * @param ExpressionInterface|mixed $expression + */ + public static function sortByCount(mixed $expression): SortByCountStage + { + return new SortByCountStage($expression); + } + + /** + * @param non-empty-string $coll The collection or view whose pipeline results you wish to include in the result set. + * @param Optional|Pipeline|array $pipeline 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. */ - public static function match(mixed $query): MatchStage + public static function unionWith( + string $coll, + Optional|Pipeline|array $pipeline = Optional::Undefined, + ): UnionWithStage { - return new MatchStage($query); + return new UnionWithStage($coll, $pipeline); } /** - * @param ExpressionInterface|mixed ...$specifications + * @param FieldPath|non-empty-string ...$field */ - public static function project(mixed ...$specifications): ProjectStage + public static function unset(FieldPath|string ...$field): UnsetStage { - return new ProjectStage(...$specifications); + return new UnsetStage(...$field); } /** - * @param Document|Int64|Serializable|array|int|object ...$sortSpecification + * @param ArrayFieldPath|non-empty-string $field */ - public static function sort(array|int|object ...$sortSpecification): SortStage + public static function unwind(ArrayFieldPath|string $field): UnwindStage { - return new SortStage(...$sortSpecification); + return new UnwindStage($field); } /** diff --git a/src/Builder/Stage/AddFieldsStage.php b/src/Builder/Stage/AddFieldsStage.php new file mode 100644 index 000000000..69650465b --- /dev/null +++ b/src/Builder/Stage/AddFieldsStage.php @@ -0,0 +1,35 @@ + ...$expression Specify the name of each field to add and set its value to an aggregation expression or an empty object. */ + public array $expression; + + /** + * @param ExpressionInterface|mixed $expression Specify the name of each field to add and set its value to an aggregation expression or an empty object. + */ + public function __construct(mixed ...$expression) + { + foreach($expression as $key => $value) { + if (! \is_string($key)) { + throw new \InvalidArgumentException('Expected $expression arguments to be a map of ExpressionInterface|mixed, named arguments (:) or array unpacking ...[\'\' => ] must be used'); + } + } + if (\count($expression) < 1) { + throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); + } + $this->expression = $expression; + } +} diff --git a/src/Builder/Stage/BucketAutoStage.php b/src/Builder/Stage/BucketAutoStage.php new file mode 100644 index 000000000..dca89e9fc --- /dev/null +++ b/src/Builder/Stage/BucketAutoStage.php @@ -0,0 +1,58 @@ +groupBy = $groupBy; + $this->buckets = $buckets; + $this->output = $output; + $this->granularity = $granularity; + } +} diff --git a/src/Builder/Stage/BucketStage.php b/src/Builder/Stage/BucketStage.php new file mode 100644 index 000000000..6adcb06d0 --- /dev/null +++ b/src/Builder/Stage/BucketStage.php @@ -0,0 +1,77 @@ + $boundaries 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: + */ + public PackedArray|BSONArray|array $boundaries; + + /** + * @param ExpressionInterface|Optional|mixed $default 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. + */ + public mixed $default; + + /** + * @param Document|Optional|Serializable|array|object $output 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. + */ + public array|object $output; + + /** + * @param ExpressionInterface|FieldPath|mixed|non-empty-string $groupBy 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. + * @param BSONArray|PackedArray|list $boundaries 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: + * @param ExpressionInterface|Optional|mixed $default 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. + * @param Document|Optional|Serializable|array|object $output 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. + */ + public function __construct( + mixed $groupBy, + PackedArray|BSONArray|array $boundaries, + mixed $default = Optional::Undefined, + array|object $output = Optional::Undefined, + ) { + $this->groupBy = $groupBy; + if (\is_array($boundaries) && ! \array_is_list($boundaries)) { + throw new \InvalidArgumentException('Expected $boundaries argument to be a list, got an associative array.'); + } + $this->boundaries = $boundaries; + $this->default = $default; + $this->output = $output; + } +} diff --git a/src/Builder/Stage/ChangeStreamSplitLargeEventStage.php b/src/Builder/Stage/ChangeStreamSplitLargeEventStage.php new file mode 100644 index 000000000..3bb6633e9 --- /dev/null +++ b/src/Builder/Stage/ChangeStreamSplitLargeEventStage.php @@ -0,0 +1,19 @@ +allChangesForCluster = $allChangesForCluster; + $this->fullDocument = $fullDocument; + $this->fullDocumentBeforeChange = $fullDocumentBeforeChange; + $this->resumeAfter = $resumeAfter; + $this->showExpandedEvents = $showExpandedEvents; + $this->startAfter = $startAfter; + $this->startAtOperationTime = $startAtOperationTime; + } +} diff --git a/src/Builder/Stage/CollStatsStage.php b/src/Builder/Stage/CollStatsStage.php new file mode 100644 index 000000000..92d2920ec --- /dev/null +++ b/src/Builder/Stage/CollStatsStage.php @@ -0,0 +1,28 @@ +config = $config; + } +} diff --git a/src/Builder/Stage/CountStage.php b/src/Builder/Stage/CountStage.php new file mode 100644 index 000000000..4165f92f1 --- /dev/null +++ b/src/Builder/Stage/CountStage.php @@ -0,0 +1,26 @@ +field = $field; + } +} diff --git a/src/Builder/Stage/CurrentOpStage.php b/src/Builder/Stage/CurrentOpStage.php new file mode 100644 index 000000000..b61f1998c --- /dev/null +++ b/src/Builder/Stage/CurrentOpStage.php @@ -0,0 +1,19 @@ + in an embedded document or in an array, use dot notation. + */ + public FieldPath|string $field; + + /** @param array|object $range Specification for range based densification. */ + public array|object $range; + + /** @param BSONArray|Optional|PackedArray|list $partitionByFields The field(s) that will be used as the partition keys. */ + public PackedArray|Optional|BSONArray|array $partitionByFields; + + /** + * @param FieldPath|non-empty-string $field 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. + * @param array|object $range Specification for range based densification. + * @param BSONArray|Optional|PackedArray|list $partitionByFields The field(s) that will be used as the partition keys. + */ + public function __construct( + FieldPath|string $field, + array|object $range, + PackedArray|Optional|BSONArray|array $partitionByFields = Optional::Undefined, + ) { + $this->field = $field; + $this->range = $range; + if (\is_array($partitionByFields) && ! \array_is_list($partitionByFields)) { + throw new \InvalidArgumentException('Expected $partitionByFields argument to be a list, got an associative array.'); + } + $this->partitionByFields = $partitionByFields; + } +} diff --git a/src/Builder/Stage/DocumentsStage.php b/src/Builder/Stage/DocumentsStage.php new file mode 100644 index 000000000..9b374ef3f --- /dev/null +++ b/src/Builder/Stage/DocumentsStage.php @@ -0,0 +1,43 @@ + $documents $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. + */ + public PackedArray|ResolvesToArray|BSONArray|array $documents; + + /** + * @param BSONArray|PackedArray|ResolvesToArray|list $documents $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. + */ + public function __construct(PackedArray|ResolvesToArray|BSONArray|array $documents) + { + if (\is_array($documents) && ! \array_is_list($documents)) { + throw new \InvalidArgumentException('Expected $documents argument to be a list, got an associative array.'); + } + $this->documents = $documents; + } +} diff --git a/src/Builder/Stage/FacetStage.php b/src/Builder/Stage/FacetStage.php new file mode 100644 index 000000000..78b21efac --- /dev/null +++ b/src/Builder/Stage/FacetStage.php @@ -0,0 +1,35 @@ + ...$facet */ + public array $facet; + + /** + * @param Pipeline|array $facet + */ + public function __construct(Pipeline|array ...$facet) + { + foreach($facet as $key => $value) { + if (! \is_string($key)) { + throw new \InvalidArgumentException('Expected $facet arguments to be a map of Pipeline|array, named arguments (:) or array unpacking ...[\'\' => ] must be used'); + } + } + if (\count($facet) < 1) { + throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $facet, got %d.', 1, \count($facet))); + } + $this->facet = $facet; + } +} diff --git a/src/Builder/Stage/FillStage.php b/src/Builder/Stage/FillStage.php new file mode 100644 index 000000000..6acc797ba --- /dev/null +++ b/src/Builder/Stage/FillStage.php @@ -0,0 +1,70 @@ + $partitionByFields 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. + */ + public PackedArray|Optional|BSONArray|array $partitionByFields; + + /** @param Optional|array|object $sortBy Specifies the field or fields to sort the documents within each partition. Uses the same syntax as the $sort stage. */ + public array|object $sortBy; + + /** + * @param Document|Serializable|array|object $output 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. + * @param Document|Optional|Serializable|array|non-empty-string|object $partitionBy 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. + * @param BSONArray|Optional|PackedArray|list $partitionByFields 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. + * @param Optional|array|object $sortBy Specifies the field or fields to sort the documents within each partition. Uses the same syntax as the $sort stage. + */ + public function __construct( + array|object $output, + array|object|string $partitionBy = Optional::Undefined, + PackedArray|Optional|BSONArray|array $partitionByFields = Optional::Undefined, + array|object $sortBy = Optional::Undefined, + ) { + $this->output = $output; + $this->partitionBy = $partitionBy; + if (\is_array($partitionByFields) && ! \array_is_list($partitionByFields)) { + throw new \InvalidArgumentException('Expected $partitionByFields argument to be a list, got an associative array.'); + } + $this->partitionByFields = $partitionByFields; + $this->sortBy = $sortBy; + } +} diff --git a/src/Builder/Stage/GeoNearStage.php b/src/Builder/Stage/GeoNearStage.php new file mode 100644 index 000000000..f69b3be62 --- /dev/null +++ b/src/Builder/Stage/GeoNearStage.php @@ -0,0 +1,99 @@ +distanceField = $distanceField; + $this->near = $near; + $this->distanceMultiplier = $distanceMultiplier; + $this->includeLocs = $includeLocs; + $this->key = $key; + $this->maxDistance = $maxDistance; + $this->minDistance = $minDistance; + $this->query = $query; + $this->spherical = $spherical; + } +} diff --git a/src/Builder/Stage/GraphLookupStage.php b/src/Builder/Stage/GraphLookupStage.php new file mode 100644 index 000000000..d13980a4f --- /dev/null +++ b/src/Builder/Stage/GraphLookupStage.php @@ -0,0 +1,82 @@ +|mixed $startWith 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. */ + public mixed $startWith; + + /** @param non-empty-string $connectFromField 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. */ + public string $connectFromField; + + /** @param non-empty-string $connectToField Field name in other documents against which to match the value of the field specified by the connectFromField parameter. */ + public string $connectToField; + + /** @param non-empty-string $as Name of the array field added to each output document. Contains the documents traversed in the $graphLookup stage to reach the document. */ + public string $as; + + /** @param Int64|Optional|int $maxDepth Non-negative integral number specifying the maximum recursion depth. */ + public Int64|Optional|int $maxDepth; + + /** @param Optional|non-empty-string $depthField 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. */ + public Optional|string $depthField; + + /** @param Optional|QueryInterface|array|object $restrictSearchWithMatch A document specifying additional conditions for the recursive search. The syntax is identical to query filter syntax. */ + public array|object $restrictSearchWithMatch; + + /** + * @param non-empty-string $from 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. + * @param BSONArray|ExpressionInterface|PackedArray|list|mixed $startWith 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. + * @param non-empty-string $connectFromField 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. + * @param non-empty-string $connectToField Field name in other documents against which to match the value of the field specified by the connectFromField parameter. + * @param non-empty-string $as Name of the array field added to each output document. Contains the documents traversed in the $graphLookup stage to reach the document. + * @param Int64|Optional|int $maxDepth Non-negative integral number specifying the maximum recursion depth. + * @param Optional|non-empty-string $depthField 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. + * @param Optional|QueryInterface|array|object $restrictSearchWithMatch A document specifying additional conditions for the recursive search. The syntax is identical to query filter syntax. + */ + public function __construct( + string $from, + mixed $startWith, + string $connectFromField, + string $connectToField, + string $as, + Int64|Optional|int $maxDepth = Optional::Undefined, + Optional|string $depthField = Optional::Undefined, + array|object $restrictSearchWithMatch = Optional::Undefined, + ) { + $this->from = $from; + if (\is_array($startWith) && ! \array_is_list($startWith)) { + throw new \InvalidArgumentException('Expected $startWith argument to be a list, got an associative array.'); + } + $this->startWith = $startWith; + $this->connectFromField = $connectFromField; + $this->connectToField = $connectToField; + $this->as = $as; + $this->maxDepth = $maxDepth; + $this->depthField = $depthField; + $this->restrictSearchWithMatch = $restrictSearchWithMatch; + } +} diff --git a/src/Builder/Stage/GroupStage.php b/src/Builder/Stage/GroupStage.php index 395dee6ed..12a226abb 100644 --- a/src/Builder/Stage/GroupStage.php +++ b/src/Builder/Stage/GroupStage.php @@ -6,25 +6,36 @@ namespace MongoDB\Builder\Stage; +use MongoDB\Builder\Aggregation\AccumulatorInterface; +use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ExpressionInterface; class GroupStage implements StageInterface { public const NAME = '$group'; - public const ENCODE = 'object'; + public const ENCODE = \MongoDB\Builder\Encode::Group; + /** @param ExpressionInterface|mixed $_id 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. */ public mixed $_id; - /** @param list ...$fields */ - public array $fields; + /** @param array ...$field Computed using the accumulator operators. */ + public array $field; /** - * @param ExpressionInterface|mixed|null $_id - * @param ExpressionInterface|mixed $fields + * @param ExpressionInterface|mixed $_id 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. + * @param AccumulatorInterface $field Computed using the accumulator operators. */ - public function __construct(mixed $_id, mixed ...$fields) + public function __construct(mixed $_id, AccumulatorInterface ...$field) { $this->_id = $_id; - $this->fields = $fields; + foreach($field as $key => $value) { + if (! \is_string($key)) { + throw new \InvalidArgumentException('Expected $field arguments to be a map of AccumulatorInterface, named arguments (:) or array unpacking ...[\'\' => ] must be used'); + } + } + if (\count($field) < 1) { + throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $field, got %d.', 1, \count($field))); + } + $this->field = $field; } } diff --git a/src/Builder/Stage/IndexStatsStage.php b/src/Builder/Stage/IndexStatsStage.php new file mode 100644 index 000000000..66d133f39 --- /dev/null +++ b/src/Builder/Stage/IndexStatsStage.php @@ -0,0 +1,19 @@ + $users 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. */ + public PackedArray|Optional|BSONArray|array $users; + + /** @param Optional|bool $allUsers Returns all sessions for all users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster. */ + public Optional|bool $allUsers; + + /** + * @param BSONArray|Optional|PackedArray|list $users 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. + * @param Optional|bool $allUsers Returns all sessions for all users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster. + */ + public function __construct( + PackedArray|Optional|BSONArray|array $users = Optional::Undefined, + Optional|bool $allUsers = Optional::Undefined, + ) { + if (\is_array($users) && ! \array_is_list($users)) { + throw new \InvalidArgumentException('Expected $users argument to be a list, got an associative array.'); + } + $this->users = $users; + $this->allUsers = $allUsers; + } +} diff --git a/src/Builder/Stage/ListSampledQueriesStage.php b/src/Builder/Stage/ListSampledQueriesStage.php new file mode 100644 index 000000000..460f43867 --- /dev/null +++ b/src/Builder/Stage/ListSampledQueriesStage.php @@ -0,0 +1,27 @@ +namespace = $namespace; + } +} diff --git a/src/Builder/Stage/ListSearchIndexesStage.php b/src/Builder/Stage/ListSearchIndexesStage.php new file mode 100644 index 000000000..94d5ef8b5 --- /dev/null +++ b/src/Builder/Stage/ListSearchIndexesStage.php @@ -0,0 +1,34 @@ +id = $id; + $this->name = $name; + } +} diff --git a/src/Builder/Stage/ListSessionsStage.php b/src/Builder/Stage/ListSessionsStage.php new file mode 100644 index 000000000..b09eaa7a4 --- /dev/null +++ b/src/Builder/Stage/ListSessionsStage.php @@ -0,0 +1,40 @@ + $users 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. */ + public PackedArray|Optional|BSONArray|array $users; + + /** @param Optional|bool $allUsers Returns all sessions for all users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster. */ + public Optional|bool $allUsers; + + /** + * @param BSONArray|Optional|PackedArray|list $users 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. + * @param Optional|bool $allUsers Returns all sessions for all users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster. + */ + public function __construct( + PackedArray|Optional|BSONArray|array $users = Optional::Undefined, + Optional|bool $allUsers = Optional::Undefined, + ) { + if (\is_array($users) && ! \array_is_list($users)) { + throw new \InvalidArgumentException('Expected $users argument to be a list, got an associative array.'); + } + $this->users = $users; + $this->allUsers = $allUsers; + } +} diff --git a/src/Builder/Stage/LookupStage.php b/src/Builder/Stage/LookupStage.php new file mode 100644 index 000000000..06ab5c185 --- /dev/null +++ b/src/Builder/Stage/LookupStage.php @@ -0,0 +1,73 @@ +as = $as; + $this->from = $from; + $this->localField = $localField; + $this->foreignField = $foreignField; + $this->let = $let; + $this->pipeline = $pipeline; + } +} diff --git a/src/Builder/Stage/MatchStage.php b/src/Builder/Stage/MatchStage.php index b17041c11..387ba5817 100644 --- a/src/Builder/Stage/MatchStage.php +++ b/src/Builder/Stage/MatchStage.php @@ -6,20 +6,30 @@ namespace MongoDB\Builder\Stage; -use MongoDB\Builder\Expression\ExpressionInterface; +use MongoDB\Builder\Encode; +use MongoDB\Builder\Query\QueryInterface; class MatchStage implements StageInterface { public const NAME = '$match'; - public const ENCODE = 'single'; + public const ENCODE = \MongoDB\Builder\Encode::Single; - public mixed $query; + /** @param array ...$query */ + public array $query; /** - * @param ExpressionInterface|mixed $query + * @param QueryInterface|array|object $query */ - public function __construct(mixed $query) + public function __construct(array|object ...$query) { + foreach($query as $key => $value) { + if (! \is_string($key)) { + throw new \InvalidArgumentException('Expected $query arguments to be a map of QueryInterface|array|object, named arguments (:) or array unpacking ...[\'\' => ] must be used'); + } + } + if (\count($query) < 1) { + throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $query, got %d.', 1, \count($query))); + } $this->query = $query; } } diff --git a/src/Builder/Stage/MergeStage.php b/src/Builder/Stage/MergeStage.php new file mode 100644 index 000000000..47bb952dd --- /dev/null +++ b/src/Builder/Stage/MergeStage.php @@ -0,0 +1,60 @@ +|non-empty-string $on 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. */ + public PackedArray|Optional|BSONArray|array|string $on; + + /** @param Document|Optional|Serializable|array|object $let Specifies variables for use in the whenMatched pipeline. */ + public array|object $let; + + /** @param Optional|non-empty-string $whenMatched 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). */ + public Optional|string $whenMatched; + + /** @param Optional|non-empty-string $whenNotMatched The behavior of $merge if a result document does not match an existing document in the out collection. */ + public Optional|string $whenNotMatched; + + /** + * @param array|non-empty-string|object $into The output collection. + * @param BSONArray|Optional|PackedArray|list|non-empty-string $on 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. + * @param Document|Optional|Serializable|array|object $let Specifies variables for use in the whenMatched pipeline. + * @param Optional|non-empty-string $whenMatched 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). + * @param Optional|non-empty-string $whenNotMatched The behavior of $merge if a result document does not match an existing document in the out collection. + */ + public function __construct( + array|object|string $into, + PackedArray|Optional|BSONArray|array|string $on = Optional::Undefined, + array|object $let = Optional::Undefined, + Optional|string $whenMatched = Optional::Undefined, + Optional|string $whenNotMatched = Optional::Undefined, + ) { + $this->into = $into; + if (\is_array($on) && ! \array_is_list($on)) { + throw new \InvalidArgumentException('Expected $on argument to be a list, got an associative array.'); + } + $this->on = $on; + $this->let = $let; + $this->whenMatched = $whenMatched; + $this->whenNotMatched = $whenNotMatched; + } +} diff --git a/src/Builder/Stage/OutStage.php b/src/Builder/Stage/OutStage.php new file mode 100644 index 000000000..45a865704 --- /dev/null +++ b/src/Builder/Stage/OutStage.php @@ -0,0 +1,38 @@ +db = $db; + $this->coll = $coll; + $this->timeseries = $timeseries; + } +} diff --git a/src/Builder/Stage/PlanCacheStatsStage.php b/src/Builder/Stage/PlanCacheStatsStage.php new file mode 100644 index 000000000..77c93b237 --- /dev/null +++ b/src/Builder/Stage/PlanCacheStatsStage.php @@ -0,0 +1,19 @@ + ...$specifications */ - public array $specifications; + /** @param array ...$specification */ + public array $specification; /** - * @param ExpressionInterface|mixed $specifications + * @param ExpressionInterface|Int64|bool|int|mixed $specification */ - public function __construct(mixed ...$specifications) + public function __construct(mixed ...$specification) { - if (\count($specifications) < 1) { - throw new \InvalidArgumentException(\sprintf('Expected at least %d values, got %d.', 1, \count($specifications))); + foreach($specification as $key => $value) { + if (! \is_string($key)) { + throw new \InvalidArgumentException('Expected $specification arguments to be a map of ExpressionInterface|Int64|bool|int|mixed, named arguments (:) or array unpacking ...[\'\' => ] must be used'); + } } - - $this->specifications = $specifications; + if (\count($specification) < 1) { + throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $specification, got %d.', 1, \count($specification))); + } + $this->specification = $specification; } } diff --git a/src/Builder/Stage/RedactStage.php b/src/Builder/Stage/RedactStage.php new file mode 100644 index 000000000..46a0a57e9 --- /dev/null +++ b/src/Builder/Stage/RedactStage.php @@ -0,0 +1,27 @@ +expression = $expression; + } +} diff --git a/src/Builder/Stage/ReplaceRootStage.php b/src/Builder/Stage/ReplaceRootStage.php new file mode 100644 index 000000000..17b03de82 --- /dev/null +++ b/src/Builder/Stage/ReplaceRootStage.php @@ -0,0 +1,29 @@ +newRoot = $newRoot; + } +} diff --git a/src/Builder/Stage/ReplaceWithStage.php b/src/Builder/Stage/ReplaceWithStage.php new file mode 100644 index 000000000..ddb1dff89 --- /dev/null +++ b/src/Builder/Stage/ReplaceWithStage.php @@ -0,0 +1,29 @@ +expression = $expression; + } +} diff --git a/src/Builder/Stage/SampleStage.php b/src/Builder/Stage/SampleStage.php new file mode 100644 index 000000000..9cb198bc7 --- /dev/null +++ b/src/Builder/Stage/SampleStage.php @@ -0,0 +1,27 @@ +size = $size; + } +} diff --git a/src/Builder/Stage/SearchMetaStage.php b/src/Builder/Stage/SearchMetaStage.php new file mode 100644 index 000000000..f92461a07 --- /dev/null +++ b/src/Builder/Stage/SearchMetaStage.php @@ -0,0 +1,28 @@ +meta = $meta; + } +} diff --git a/src/Builder/Stage/SearchStage.php b/src/Builder/Stage/SearchStage.php new file mode 100644 index 000000000..3ade54d85 --- /dev/null +++ b/src/Builder/Stage/SearchStage.php @@ -0,0 +1,28 @@ +search = $search; + } +} diff --git a/src/Builder/Stage/SetStage.php b/src/Builder/Stage/SetStage.php new file mode 100644 index 000000000..b8fc4aaaf --- /dev/null +++ b/src/Builder/Stage/SetStage.php @@ -0,0 +1,35 @@ + ...$field */ + public array $field; + + /** + * @param ExpressionInterface|mixed $field + */ + public function __construct(mixed ...$field) + { + foreach($field as $key => $value) { + if (! \is_string($key)) { + throw new \InvalidArgumentException('Expected $field arguments to be a map of ExpressionInterface|mixed, named arguments (:) or array unpacking ...[\'\' => ] must be used'); + } + } + if (\count($field) < 1) { + throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $field, got %d.', 1, \count($field))); + } + $this->field = $field; + } +} diff --git a/src/Builder/Stage/SetWindowFieldsStage.php b/src/Builder/Stage/SetWindowFieldsStage.php new file mode 100644 index 000000000..07e2783df --- /dev/null +++ b/src/Builder/Stage/SetWindowFieldsStage.php @@ -0,0 +1,53 @@ +partitionBy = $partitionBy; + $this->sortBy = $sortBy; + $this->output = $output; + $this->window = $window; + } +} diff --git a/src/Builder/Stage/ShardedDataDistributionStage.php b/src/Builder/Stage/ShardedDataDistributionStage.php new file mode 100644 index 000000000..26ff6169d --- /dev/null +++ b/src/Builder/Stage/ShardedDataDistributionStage.php @@ -0,0 +1,19 @@ +skip = $skip; + } +} diff --git a/src/Builder/Stage/SortByCountStage.php b/src/Builder/Stage/SortByCountStage.php new file mode 100644 index 000000000..6ffe48c8c --- /dev/null +++ b/src/Builder/Stage/SortByCountStage.php @@ -0,0 +1,27 @@ +expression = $expression; + } +} diff --git a/src/Builder/Stage/SortStage.php b/src/Builder/Stage/SortStage.php index 814d5cf3c..1a9396f05 100644 --- a/src/Builder/Stage/SortStage.php +++ b/src/Builder/Stage/SortStage.php @@ -6,27 +6,21 @@ namespace MongoDB\Builder\Stage; -use MongoDB\BSON\Document; -use MongoDB\BSON\Int64; -use MongoDB\BSON\Serializable; +use MongoDB\Builder\Encode; class SortStage implements StageInterface { public const NAME = '$sort'; - public const ENCODE = 'single'; + public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param list ...$sortSpecification */ - public array $sortSpecification; + /** @param array|object $sort */ + public array|object $sort; /** - * @param Document|Int64|Serializable|array|int|object $sortSpecification + * @param array|object $sort */ - public function __construct(array|int|object ...$sortSpecification) + public function __construct(array|object $sort) { - if (\count($sortSpecification) < 1) { - throw new \InvalidArgumentException(\sprintf('Expected at least %d values, got %d.', 1, \count($sortSpecification))); - } - - $this->sortSpecification = $sortSpecification; + $this->sort = $sort; } } diff --git a/src/Builder/Stage/Stage.php b/src/Builder/Stage/Stage.php new file mode 100644 index 000000000..0eec5bf01 --- /dev/null +++ b/src/Builder/Stage/Stage.php @@ -0,0 +1,30 @@ +expression = $expression; + } +} diff --git a/src/Builder/Stage/UnionWithStage.php b/src/Builder/Stage/UnionWithStage.php new file mode 100644 index 000000000..79aec35c8 --- /dev/null +++ b/src/Builder/Stage/UnionWithStage.php @@ -0,0 +1,37 @@ +coll = $coll; + $this->pipeline = $pipeline; + } +} diff --git a/src/Builder/Stage/UnsetStage.php b/src/Builder/Stage/UnsetStage.php new file mode 100644 index 000000000..5cc4bcc16 --- /dev/null +++ b/src/Builder/Stage/UnsetStage.php @@ -0,0 +1,33 @@ + ...$field */ + public array $field; + + /** + * @param FieldPath|non-empty-string $field + */ + public function __construct(FieldPath|string ...$field) + { + if (! \array_is_list($field)) { + throw new \InvalidArgumentException('Expected $field arguments to be a list of FieldPath|non-empty-string, named arguments are not supported'); + } + if (\count($field) < 1) { + throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $field, got %d.', 1, \count($field))); + } + $this->field = $field; + } +} diff --git a/src/Builder/Stage/UnwindStage.php b/src/Builder/Stage/UnwindStage.php new file mode 100644 index 000000000..749fd7f94 --- /dev/null +++ b/src/Builder/Stage/UnwindStage.php @@ -0,0 +1,27 @@ +field = $field; + } +} diff --git a/tests/Builder/BuilderEncoderTest.php b/tests/Builder/BuilderEncoderTest.php index 224a19631..c26083c51 100644 --- a/tests/Builder/BuilderEncoderTest.php +++ b/tests/Builder/BuilderEncoderTest.php @@ -43,7 +43,7 @@ public function testPipeline(): void public function testSort(): void { $pipeline = new Pipeline( - Stage::sort(...['age' => -1, 'posts' => 1]), + Stage::sort((object) ['age' => -1, 'posts' => 1]), ); $expected = [ From b3c6279edf32fc352bd33a2d42e5ac1e3c86717d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Thu, 5 Oct 2023 11:17:14 +0200 Subject: [PATCH 03/37] Add @no-named-argument to list variadic --- generator/src/OperatorClassGenerator.php | 8 +++++--- src/Builder/Aggregation/AddAggregation.php | 5 ++++- src/Builder/Aggregation/AllElementsTrueAggregation.php | 5 ++++- src/Builder/Aggregation/AndAggregation.php | 5 ++++- src/Builder/Aggregation/AvgAggregation.php | 5 ++++- src/Builder/Aggregation/BitAndAggregation.php | 5 ++++- src/Builder/Aggregation/BitOrAggregation.php | 5 ++++- src/Builder/Aggregation/ConcatAggregation.php | 5 ++++- src/Builder/Aggregation/ConcatArraysAggregation.php | 5 ++++- src/Builder/Aggregation/IfNullAggregation.php | 5 ++++- src/Builder/Aggregation/IsArrayAggregation.php | 5 ++++- src/Builder/Aggregation/IsNumberAggregation.php | 5 ++++- src/Builder/Aggregation/MaxAggregation.php | 5 ++++- src/Builder/Aggregation/MergeObjectsAggregation.php | 5 ++++- src/Builder/Aggregation/MinAggregation.php | 5 ++++- src/Builder/Aggregation/MultiplyAggregation.php | 1 + src/Builder/Aggregation/OrAggregation.php | 5 ++++- src/Builder/Aggregation/SetEqualsAggregation.php | 5 ++++- src/Builder/Aggregation/SetIntersectionAggregation.php | 5 ++++- src/Builder/Aggregation/SetUnionAggregation.php | 5 ++++- src/Builder/Aggregation/StdDevPopAggregation.php | 5 ++++- src/Builder/Aggregation/StdDevSampAggregation.php | 5 ++++- src/Builder/Aggregation/SumAggregation.php | 5 ++++- src/Builder/Query/AllQuery.php | 5 ++++- src/Builder/Query/AndQuery.php | 5 ++++- src/Builder/Query/NorQuery.php | 5 ++++- src/Builder/Query/OrQuery.php | 5 ++++- src/Builder/Stage/UnsetStage.php | 5 ++++- 28 files changed, 110 insertions(+), 29 deletions(-) diff --git a/generator/src/OperatorClassGenerator.php b/generator/src/OperatorClassGenerator.php index 40830cca4..c017967f7 100644 --- a/generator/src/OperatorClassGenerator.php +++ b/generator/src/OperatorClassGenerator.php @@ -72,14 +72,16 @@ public function createClass(GeneratorDefinition $definition, OperatorDefinition $constuctor->setVariadic(); if ($argument->variadic === VariadicType::Array) { - $property->setComment('@param list<' . $type->doc . '> ...$' . $argument->name . rtrim(' ' . $argument->description)); + // @see https://psalm.dev/docs/running_psalm/issues/NamedArgumentNotAllowed/ + $property->addComment('@no-named-arguments'); + $property->addComment('@param list<' . $type->doc . '> ...$' . $argument->name . rtrim(' ' . $argument->description)); $constuctor->addBody(<<name})) { throw new \InvalidArgumentException('Expected \${$argument->name} arguments to be a list of {$type->doc}, named arguments are not supported'); } PHP); } elseif ($argument->variadic === VariadicType::Object) { - $property->setComment('@param arraydoc . '> ...$' . $argument->name . rtrim(' ' . $argument->description)); + $property->addComment('@param arraydoc . '> ...$' . $argument->name . rtrim(' ' . $argument->description)); $constuctor->addBody(<<name} as \$key => \$value) { if (! \is_string(\$key)) { @@ -98,7 +100,7 @@ public function createClass(GeneratorDefinition $definition, OperatorDefinition } } else { // Non-variadic arguments - $property->setComment('@param ' . $type->doc . ' $' . $argument->name . rtrim(' ' . $argument->description)); + $property->addComment('@param ' . $type->doc . ' $' . $argument->name . rtrim(' ' . $argument->description)); $property->setType($type->native); if ($argument->optional) { diff --git a/src/Builder/Aggregation/AddAggregation.php b/src/Builder/Aggregation/AddAggregation.php index b4038990b..ca6ab4104 100644 --- a/src/Builder/Aggregation/AddAggregation.php +++ b/src/Builder/Aggregation/AddAggregation.php @@ -18,7 +18,10 @@ class AddAggregation implements ResolvesToNumber, ResolvesToDate public const NAME = '$add'; public const ENCODE = \MongoDB\Builder\Encode::Array; - /** @param list ...$expression The arguments can be any valid expression as long as they resolve to either all numbers or to numbers and a date. */ + /** + * @no-named-arguments + * @param list ...$expression The arguments can be any valid expression as long as they resolve to either all numbers or to numbers and a date. + */ public array $expression; /** diff --git a/src/Builder/Aggregation/AllElementsTrueAggregation.php b/src/Builder/Aggregation/AllElementsTrueAggregation.php index c407a014f..9c48cfc51 100644 --- a/src/Builder/Aggregation/AllElementsTrueAggregation.php +++ b/src/Builder/Aggregation/AllElementsTrueAggregation.php @@ -18,7 +18,10 @@ class AllElementsTrueAggregation implements ResolvesToBool public const NAME = '$allElementsTrue'; public const ENCODE = \MongoDB\Builder\Encode::Array; - /** @param list> ...$expression */ + /** + * @no-named-arguments + * @param list> ...$expression + */ public array $expression; /** diff --git a/src/Builder/Aggregation/AndAggregation.php b/src/Builder/Aggregation/AndAggregation.php index 2346d3c23..60ceb4ce5 100644 --- a/src/Builder/Aggregation/AndAggregation.php +++ b/src/Builder/Aggregation/AndAggregation.php @@ -20,7 +20,10 @@ class AndAggregation implements ResolvesToBool public const NAME = '$and'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param list ...$expression */ + /** + * @no-named-arguments + * @param list ...$expression + */ public array $expression; /** diff --git a/src/Builder/Aggregation/AvgAggregation.php b/src/Builder/Aggregation/AvgAggregation.php index e6ec239bd..ac0a85440 100644 --- a/src/Builder/Aggregation/AvgAggregation.php +++ b/src/Builder/Aggregation/AvgAggregation.php @@ -16,7 +16,10 @@ class AvgAggregation implements ResolvesToNumber, AccumulatorInterface public const NAME = '$avg'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param list ...$expression */ + /** + * @no-named-arguments + * @param list ...$expression + */ public array $expression; /** diff --git a/src/Builder/Aggregation/BitAndAggregation.php b/src/Builder/Aggregation/BitAndAggregation.php index a1609c2ff..9a7a40d0a 100644 --- a/src/Builder/Aggregation/BitAndAggregation.php +++ b/src/Builder/Aggregation/BitAndAggregation.php @@ -16,7 +16,10 @@ class BitAndAggregation implements ResolvesToInt, ResolvesToLong public const NAME = '$bitAnd'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param list ...$expression */ + /** + * @no-named-arguments + * @param list ...$expression + */ public array $expression; /** diff --git a/src/Builder/Aggregation/BitOrAggregation.php b/src/Builder/Aggregation/BitOrAggregation.php index 2ab63df29..7b627ac29 100644 --- a/src/Builder/Aggregation/BitOrAggregation.php +++ b/src/Builder/Aggregation/BitOrAggregation.php @@ -16,7 +16,10 @@ class BitOrAggregation implements ResolvesToInt, ResolvesToLong public const NAME = '$bitOr'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param list ...$expression */ + /** + * @no-named-arguments + * @param list ...$expression + */ public array $expression; /** diff --git a/src/Builder/Aggregation/ConcatAggregation.php b/src/Builder/Aggregation/ConcatAggregation.php index 9be7e13f3..283de6443 100644 --- a/src/Builder/Aggregation/ConcatAggregation.php +++ b/src/Builder/Aggregation/ConcatAggregation.php @@ -14,7 +14,10 @@ class ConcatAggregation implements ResolvesToString public const NAME = '$concat'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param list ...$expression */ + /** + * @no-named-arguments + * @param list ...$expression + */ public array $expression; /** diff --git a/src/Builder/Aggregation/ConcatArraysAggregation.php b/src/Builder/Aggregation/ConcatArraysAggregation.php index 4f37ff61b..932db7aed 100644 --- a/src/Builder/Aggregation/ConcatArraysAggregation.php +++ b/src/Builder/Aggregation/ConcatArraysAggregation.php @@ -17,7 +17,10 @@ class ConcatArraysAggregation implements ResolvesToArray public const NAME = '$concatArrays'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param list> ...$array */ + /** + * @no-named-arguments + * @param list> ...$array + */ public array $array; /** diff --git a/src/Builder/Aggregation/IfNullAggregation.php b/src/Builder/Aggregation/IfNullAggregation.php index 29ea18c37..1e3b86bbe 100644 --- a/src/Builder/Aggregation/IfNullAggregation.php +++ b/src/Builder/Aggregation/IfNullAggregation.php @@ -14,7 +14,10 @@ class IfNullAggregation implements ExpressionInterface public const NAME = '$ifNull'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param list ...$expression */ + /** + * @no-named-arguments + * @param list ...$expression + */ public array $expression; /** diff --git a/src/Builder/Aggregation/IsArrayAggregation.php b/src/Builder/Aggregation/IsArrayAggregation.php index 68845dc3a..89f59970d 100644 --- a/src/Builder/Aggregation/IsArrayAggregation.php +++ b/src/Builder/Aggregation/IsArrayAggregation.php @@ -15,7 +15,10 @@ class IsArrayAggregation implements ResolvesToBool public const NAME = '$isArray'; public const ENCODE = \MongoDB\Builder\Encode::Array; - /** @param list ...$expression */ + /** + * @no-named-arguments + * @param list ...$expression + */ public array $expression; /** diff --git a/src/Builder/Aggregation/IsNumberAggregation.php b/src/Builder/Aggregation/IsNumberAggregation.php index d4a30de48..77efe8405 100644 --- a/src/Builder/Aggregation/IsNumberAggregation.php +++ b/src/Builder/Aggregation/IsNumberAggregation.php @@ -15,7 +15,10 @@ class IsNumberAggregation implements ResolvesToBool public const NAME = '$isNumber'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param list ...$expression */ + /** + * @no-named-arguments + * @param list ...$expression + */ public array $expression; /** diff --git a/src/Builder/Aggregation/MaxAggregation.php b/src/Builder/Aggregation/MaxAggregation.php index ce9dfc999..04cdd7a66 100644 --- a/src/Builder/Aggregation/MaxAggregation.php +++ b/src/Builder/Aggregation/MaxAggregation.php @@ -14,7 +14,10 @@ class MaxAggregation implements ExpressionInterface, AccumulatorInterface public const NAME = '$max'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param list ...$expression */ + /** + * @no-named-arguments + * @param list ...$expression + */ public array $expression; /** diff --git a/src/Builder/Aggregation/MergeObjectsAggregation.php b/src/Builder/Aggregation/MergeObjectsAggregation.php index 1a88ba582..5c3500713 100644 --- a/src/Builder/Aggregation/MergeObjectsAggregation.php +++ b/src/Builder/Aggregation/MergeObjectsAggregation.php @@ -16,7 +16,10 @@ class MergeObjectsAggregation implements AccumulatorInterface public const NAME = '$mergeObjects'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param list ...$document Any valid expression that resolves to a document. */ + /** + * @no-named-arguments + * @param list ...$document Any valid expression that resolves to a document. + */ public array $document; /** diff --git a/src/Builder/Aggregation/MinAggregation.php b/src/Builder/Aggregation/MinAggregation.php index 96d8cf98b..da2264afb 100644 --- a/src/Builder/Aggregation/MinAggregation.php +++ b/src/Builder/Aggregation/MinAggregation.php @@ -14,7 +14,10 @@ class MinAggregation implements ExpressionInterface, AccumulatorInterface public const NAME = '$min'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param list ...$expression */ + /** + * @no-named-arguments + * @param list ...$expression + */ public array $expression; /** diff --git a/src/Builder/Aggregation/MultiplyAggregation.php b/src/Builder/Aggregation/MultiplyAggregation.php index b84103ab9..4f52e271c 100644 --- a/src/Builder/Aggregation/MultiplyAggregation.php +++ b/src/Builder/Aggregation/MultiplyAggregation.php @@ -18,6 +18,7 @@ class MultiplyAggregation implements ResolvesToDecimal public const ENCODE = \MongoDB\Builder\Encode::Single; /** + * @no-named-arguments * @param list ...$expression 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. */ diff --git a/src/Builder/Aggregation/OrAggregation.php b/src/Builder/Aggregation/OrAggregation.php index 4c1ab49a2..39b1c77ae 100644 --- a/src/Builder/Aggregation/OrAggregation.php +++ b/src/Builder/Aggregation/OrAggregation.php @@ -15,7 +15,10 @@ class OrAggregation implements ResolvesToBool public const NAME = '$or'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param list ...$expression */ + /** + * @no-named-arguments + * @param list ...$expression + */ public array $expression; /** diff --git a/src/Builder/Aggregation/SetEqualsAggregation.php b/src/Builder/Aggregation/SetEqualsAggregation.php index 54f45f627..31656a50c 100644 --- a/src/Builder/Aggregation/SetEqualsAggregation.php +++ b/src/Builder/Aggregation/SetEqualsAggregation.php @@ -18,7 +18,10 @@ class SetEqualsAggregation implements ResolvesToBool public const NAME = '$setEquals'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param list> ...$expression */ + /** + * @no-named-arguments + * @param list> ...$expression + */ public array $expression; /** diff --git a/src/Builder/Aggregation/SetIntersectionAggregation.php b/src/Builder/Aggregation/SetIntersectionAggregation.php index dc44856b3..8297631f4 100644 --- a/src/Builder/Aggregation/SetIntersectionAggregation.php +++ b/src/Builder/Aggregation/SetIntersectionAggregation.php @@ -17,7 +17,10 @@ class SetIntersectionAggregation implements ResolvesToArray public const NAME = '$setIntersection'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param list> ...$expression */ + /** + * @no-named-arguments + * @param list> ...$expression + */ public array $expression; /** diff --git a/src/Builder/Aggregation/SetUnionAggregation.php b/src/Builder/Aggregation/SetUnionAggregation.php index 2e77cfbe3..4379b2a33 100644 --- a/src/Builder/Aggregation/SetUnionAggregation.php +++ b/src/Builder/Aggregation/SetUnionAggregation.php @@ -17,7 +17,10 @@ class SetUnionAggregation implements ResolvesToArray public const NAME = '$setUnion'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param list> ...$expression */ + /** + * @no-named-arguments + * @param list> ...$expression + */ public array $expression; /** diff --git a/src/Builder/Aggregation/StdDevPopAggregation.php b/src/Builder/Aggregation/StdDevPopAggregation.php index 1e7f138d8..86ff24ebb 100644 --- a/src/Builder/Aggregation/StdDevPopAggregation.php +++ b/src/Builder/Aggregation/StdDevPopAggregation.php @@ -17,7 +17,10 @@ class StdDevPopAggregation implements ResolvesToDouble, AccumulatorInterface public const NAME = '$stdDevPop'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param list ...$expression */ + /** + * @no-named-arguments + * @param list ...$expression + */ public array $expression; /** diff --git a/src/Builder/Aggregation/StdDevSampAggregation.php b/src/Builder/Aggregation/StdDevSampAggregation.php index d36ebec45..8a85bb4d1 100644 --- a/src/Builder/Aggregation/StdDevSampAggregation.php +++ b/src/Builder/Aggregation/StdDevSampAggregation.php @@ -17,7 +17,10 @@ class StdDevSampAggregation implements ResolvesToDouble, AccumulatorInterface public const NAME = '$stdDevSamp'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param list ...$expression */ + /** + * @no-named-arguments + * @param list ...$expression + */ public array $expression; /** diff --git a/src/Builder/Aggregation/SumAggregation.php b/src/Builder/Aggregation/SumAggregation.php index 7354f7a20..86a3e74e3 100644 --- a/src/Builder/Aggregation/SumAggregation.php +++ b/src/Builder/Aggregation/SumAggregation.php @@ -16,7 +16,10 @@ class SumAggregation implements ResolvesToNumber, AccumulatorInterface public const NAME = '$sum'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param list ...$expression */ + /** + * @no-named-arguments + * @param list ...$expression + */ public array $expression; /** diff --git a/src/Builder/Query/AllQuery.php b/src/Builder/Query/AllQuery.php index 4f06933cf..c89a12a6b 100644 --- a/src/Builder/Query/AllQuery.php +++ b/src/Builder/Query/AllQuery.php @@ -13,7 +13,10 @@ class AllQuery implements QueryInterface public const NAME = '$all'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param list ...$value */ + /** + * @no-named-arguments + * @param list ...$value + */ public array $value; /** diff --git a/src/Builder/Query/AndQuery.php b/src/Builder/Query/AndQuery.php index 33b241566..0bac412ae 100644 --- a/src/Builder/Query/AndQuery.php +++ b/src/Builder/Query/AndQuery.php @@ -13,7 +13,10 @@ class AndQuery implements QueryInterface public const NAME = '$and'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param list ...$expression */ + /** + * @no-named-arguments + * @param list ...$expression + */ public array $expression; /** diff --git a/src/Builder/Query/NorQuery.php b/src/Builder/Query/NorQuery.php index eabf24b67..74e11249d 100644 --- a/src/Builder/Query/NorQuery.php +++ b/src/Builder/Query/NorQuery.php @@ -13,7 +13,10 @@ class NorQuery implements QueryInterface public const NAME = '$nor'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param list ...$expression */ + /** + * @no-named-arguments + * @param list ...$expression + */ public array $expression; /** diff --git a/src/Builder/Query/OrQuery.php b/src/Builder/Query/OrQuery.php index 9d0acad82..b4effdf2b 100644 --- a/src/Builder/Query/OrQuery.php +++ b/src/Builder/Query/OrQuery.php @@ -13,7 +13,10 @@ class OrQuery implements QueryInterface public const NAME = '$or'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param list ...$expression */ + /** + * @no-named-arguments + * @param list ...$expression + */ public array $expression; /** diff --git a/src/Builder/Stage/UnsetStage.php b/src/Builder/Stage/UnsetStage.php index 5cc4bcc16..952c7907d 100644 --- a/src/Builder/Stage/UnsetStage.php +++ b/src/Builder/Stage/UnsetStage.php @@ -14,7 +14,10 @@ class UnsetStage implements StageInterface public const NAME = '$unset'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param list ...$field */ + /** + * @no-named-arguments + * @param list ...$field + */ public array $field; /** From 59f360cac74a0e67756de2a8eeb9a2563f15db77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Thu, 5 Oct 2023 17:48:39 +0200 Subject: [PATCH 04/37] Improve typing for variadics --- .../config/aggregation-stages/match.yaml | 1 - generator/config/aggregation.md | 34 ------ generator/config/expressions.php | 22 ++-- generator/src/OperatorClassGenerator.php | 29 ++--- src/Builder/Aggregation.php | 54 +++++---- src/Builder/Aggregation/AddAggregation.php | 8 +- .../AllElementsTrueAggregation.php | 8 +- src/Builder/Aggregation/AndAggregation.php | 8 +- src/Builder/Aggregation/AvgAggregation.php | 8 +- src/Builder/Aggregation/BitAndAggregation.php | 8 +- src/Builder/Aggregation/BitOrAggregation.php | 8 +- src/Builder/Aggregation/BottomAggregation.php | 9 +- .../Aggregation/BottomNAggregation.php | 9 +- .../Aggregation/BsonSizeAggregation.php | 9 +- src/Builder/Aggregation/ConcatAggregation.php | 8 +- .../Aggregation/ConcatArraysAggregation.php | 8 +- src/Builder/Aggregation/IfNullAggregation.php | 8 +- .../Aggregation/IsArrayAggregation.php | 8 +- .../Aggregation/IsNumberAggregation.php | 8 +- src/Builder/Aggregation/LetAggregation.php | 9 +- src/Builder/Aggregation/MaxAggregation.php | 8 +- .../Aggregation/MergeObjectsAggregation.php | 13 ++- src/Builder/Aggregation/MinAggregation.php | 8 +- .../Aggregation/MultiplyAggregation.php | 8 +- .../Aggregation/ObjectToArrayAggregation.php | 9 +- src/Builder/Aggregation/OrAggregation.php | 8 +- .../Aggregation/SetEqualsAggregation.php | 8 +- .../Aggregation/SetFieldAggregation.php | 14 ++- .../SetIntersectionAggregation.php | 8 +- .../Aggregation/SetUnionAggregation.php | 8 +- .../Aggregation/SortArrayAggregation.php | 9 +- .../Aggregation/StdDevPopAggregation.php | 8 +- .../Aggregation/StdDevSampAggregation.php | 8 +- src/Builder/Aggregation/SumAggregation.php | 8 +- src/Builder/Aggregation/TopAggregation.php | 9 +- src/Builder/Aggregation/TopNAggregation.php | 9 +- .../Aggregation/UnsetFieldAggregation.php | 13 ++- src/Builder/BuilderEncoder.php | 81 +++++++------- src/Builder/Query.php | 45 ++++---- src/Builder/Query/AllQuery.php | 8 +- src/Builder/Query/AndQuery.php | 13 ++- src/Builder/Query/ElemMatchQuery.php | 9 +- src/Builder/Query/GeoIntersectsQuery.php | 9 +- src/Builder/Query/GeoWithinQuery.php | 9 +- src/Builder/Query/GeometryQuery.php | 14 ++- src/Builder/Query/JsonSchemaQuery.php | 9 +- src/Builder/Query/NearQuery.php | 9 +- src/Builder/Query/NearSphereQuery.php | 9 +- src/Builder/Query/NorQuery.php | 13 ++- src/Builder/Query/NotQuery.php | 9 +- src/Builder/Query/OrQuery.php | 13 ++- src/Builder/Stage.php | 103 +++++++++--------- src/Builder/Stage/AddFieldsStage.php | 14 ++- src/Builder/Stage/BucketAutoStage.php | 9 +- src/Builder/Stage/BucketStage.php | 9 +- src/Builder/Stage/ChangeStreamStage.php | 9 +- src/Builder/Stage/CollStatsStage.php | 9 +- src/Builder/Stage/DensifyStage.php | 9 +- src/Builder/Stage/FacetStage.php | 14 ++- src/Builder/Stage/FillStage.php | 25 +++-- src/Builder/Stage/GeoNearStage.php | 17 +-- src/Builder/Stage/GraphLookupStage.php | 9 +- src/Builder/Stage/GroupStage.php | 14 ++- src/Builder/Stage/LookupStage.php | 9 +- src/Builder/Stage/MatchStage.php | 17 +-- src/Builder/Stage/MergeStage.php | 17 +-- src/Builder/Stage/OutStage.php | 9 +- src/Builder/Stage/ProjectStage.php | 14 ++- src/Builder/Stage/ReplaceRootStage.php | 9 +- src/Builder/Stage/ReplaceWithStage.php | 9 +- src/Builder/Stage/SearchMetaStage.php | 9 +- src/Builder/Stage/SearchStage.php | 9 +- src/Builder/Stage/SetStage.php | 14 ++- src/Builder/Stage/SetWindowFieldsStage.php | 25 +++-- src/Builder/Stage/SortStage.php | 9 +- src/Builder/Stage/UnsetStage.php | 8 +- tests/Builder/BuilderEncoderTest.php | 24 ++-- 77 files changed, 564 insertions(+), 529 deletions(-) delete mode 100644 generator/config/aggregation.md diff --git a/generator/config/aggregation-stages/match.yaml b/generator/config/aggregation-stages/match.yaml index fad43935d..34812e307 100644 --- a/generator/config/aggregation-stages/match.yaml +++ b/generator/config/aggregation-stages/match.yaml @@ -13,4 +13,3 @@ arguments: name: query type: - Query - variadic: object diff --git a/generator/config/aggregation.md b/generator/config/aggregation.md deleted file mode 100644 index 11920554b..000000000 --- a/generator/config/aggregation.md +++ /dev/null @@ -1,34 +0,0 @@ -Name -Description -$abs -Returns the absolute value of a number. -$add -Adds numbers to return the sum, or adds numbers and a date to return a new date. If adding numbers and a date, treats the numbers as milliseconds. Accepts any number of argument expressions, but at most, one expression can resolve to a date. -$ceil -Returns the smallest integer greater than or equal to the specified number. -$divide -Returns the result of dividing the first number by the second. Accepts two argument expressions. -$exp -Raises e to the specified exponent. -$floor -Returns the largest integer less than or equal to the specified number. -$ln -Calculates the natural log of a number. -$log -Calculates the log of a number in the specified base. -$log10 -Calculates the log base 10 of a number. -$mod -Returns the remainder of the first number divided by the second. Accepts two argument expressions. -$multiply -Multiplies numbers to return the product. Accepts any number of argument expressions. -$pow -Raises a number to the specified exponent. -$round -Rounds a number to to a whole integer or to a specified decimal place. -$sqrt -Calculates the square root. -$subtract -Returns the result of subtracting the second value from the first. If the two values are numbers, return the difference. If the two values are dates, return the difference in milliseconds. If the two values are a date and a number in milliseconds, return the resulting date. Accepts two argument expressions. If the two values are a date and a number, specify the date argument first as it is not meaningful to subtract a date from a number. -$trunc -Truncates a number to a whole integer or to a specified decimal place. diff --git a/generator/config/expressions.php b/generator/config/expressions.php index d1f70c144..84e0e0427 100644 --- a/generator/config/expressions.php +++ b/generator/config/expressions.php @@ -32,13 +32,13 @@ function typeFieldPath(string $resolvesTo): array 'number' => ['scalar' => true, 'types' => ['int', BSON\Int64::class, 'float', BSON\Decimal128::class]], 'string' => ['scalar' => true, 'types' => ['string']], 'bool' => ['scalar' => true, 'types' => ['bool']], - 'object' => ['scalar' => true, 'types' => ['array', 'object', BSON\Document::class, BSON\Serializable::class]], + 'object' => ['scalar' => true, 'types' => ['array', stdClass::class, BSON\Document::class, BSON\Serializable::class]], 'Regex' => ['scalar' => true, 'types' => [BSON\Regex::class]], 'Constant' => ['scalar' => true, 'types' => ['mixed']], 'Binary' => ['scalar' => true, 'types' => ['string', BSON\Binary::class]], AccumulatorInterface::class => ['scalar' => true, 'types' => [AccumulatorInterface::class]], - QueryInterface::class => ['scalar' => true, 'types' => [QueryInterface::class, 'array', 'object']], + QueryInterface::class => ['scalar' => true, 'types' => [QueryInterface::class, 'array', stdClass::class]], // @todo merge this types 'list' => ['scalar' => true, 'types' => ['list', BSONArray::class, BSON\PackedArray::class]], @@ -50,17 +50,17 @@ function typeFieldPath(string $resolvesTo): array 'FullDocumentBeforeChange' => ['scalar' => true, 'types' => ['string']], 'AccumulatorPercentile' => ['scalar' => true, 'types' => ['string']], 'Timestamp' => ['scalar' => true, 'types' => ['int']], - 'CollStats' => ['scalar' => true, 'types' => ['object', 'array']], - 'Range' => ['scalar' => true, 'types' => ['object', 'array']], - 'FillOut' => ['scalar' => true, 'types' => ['object', 'array']], + 'CollStats' => ['scalar' => true, 'types' => [stdClass::class, 'array']], + 'Range' => ['scalar' => true, 'types' => [stdClass::class, 'array']], + 'FillOut' => ['scalar' => true, 'types' => [stdClass::class, 'array']], 'WhenMatched' => ['scalar' => true, 'types' => ['string']], 'WhenNotMatched' => ['scalar' => true, 'types' => ['string']], - 'OutCollection' => ['scalar' => true, 'types' => ['string', 'object', 'array']], + 'OutCollection' => ['scalar' => true, 'types' => ['string', stdClass::class, 'array']], 'Pipeline' => ['scalar' => true, 'types' => [Pipeline::class, 'array']], - 'SortSpec' => ['scalar' => true, 'types' => ['object', 'array']], - 'Window' => ['scalar' => true, 'types' => ['object', 'array']], - 'GeoPoint' => ['scalar' => true, 'types' => ['object', 'array']], - 'Geometry' => ['scalar' => true, 'types' => ['object', 'array']], + 'SortSpec' => ['scalar' => true, 'types' => [stdClass::class, 'array']], + 'Window' => ['scalar' => true, 'types' => [stdClass::class, 'array']], + 'GeoPoint' => ['scalar' => true, 'types' => [stdClass::class, 'array']], + 'Geometry' => ['scalar' => true, 'types' => [stdClass::class, 'array']], // Use Interface suffix to avoid confusion with MongoDB\Builder\Expression factory class ExpressionInterface::class => [ @@ -126,7 +126,7 @@ function typeFieldPath(string $resolvesTo): array ObjectIdFieldPath::class => typeFieldPath(ResolvesToObjectId::class), ResolvesToObject::class => [ 'implements' => [ExpressionInterface::class], - 'types' => ['array', 'object', BSON\Document::class, BSON\Serializable::class], + 'types' => ['array', stdClass::class, BSON\Document::class, BSON\Serializable::class], ], ObjectFieldPath::class => typeFieldPath(ResolvesToObject::class), ResolvesToNull::class => [ diff --git a/generator/src/OperatorClassGenerator.php b/generator/src/OperatorClassGenerator.php index c017967f7..9db7a2edd 100644 --- a/generator/src/OperatorClassGenerator.php +++ b/generator/src/OperatorClassGenerator.php @@ -5,7 +5,6 @@ use MongoDB\Builder\Aggregation\AccumulatorInterface; use MongoDB\Builder\Encode; -use MongoDB\Builder\Optional; use MongoDB\Builder\Query\QueryInterface; use MongoDB\Builder\Stage\StageInterface; use MongoDB\CodeGenerator\Definition\GeneratorDefinition; @@ -13,8 +12,8 @@ use MongoDB\CodeGenerator\Definition\VariadicType; use Nette\PhpGenerator\Literal; use Nette\PhpGenerator\PhpNamespace; -use Nette\PhpGenerator\Type; use RuntimeException; +use stdClass; use Throwable; use function assert; @@ -68,10 +67,19 @@ public function createClass(GeneratorDefinition $definition, OperatorDefinition $constuctorParam->setType($type->native); if ($argument->variadic) { - $property->setType('array'); $constuctor->setVariadic(); + $constuctor->addComment('@param ' . $type->doc . ' ...$' . $argument->name . rtrim(' ' . $argument->description)); + + if ($argument->variadicMin !== null) { + $constuctor->addBody(<<name}) < {$argument->variadicMin}) { + throw new \InvalidArgumentException(\sprintf('Expected at least %d values for \${$argument->name}, got %d.', {$argument->variadicMin}, \count(\${$argument->name}))); + } + PHP); + } if ($argument->variadic === VariadicType::Array) { + $property->setType('array'); // @see https://psalm.dev/docs/running_psalm/issues/NamedArgumentNotAllowed/ $property->addComment('@no-named-arguments'); $property->addComment('@param list<' . $type->doc . '> ...$' . $argument->name . rtrim(' ' . $argument->description)); @@ -81,27 +89,23 @@ public function createClass(GeneratorDefinition $definition, OperatorDefinition } PHP); } elseif ($argument->variadic === VariadicType::Object) { - $property->addComment('@param arraydoc . '> ...$' . $argument->name . rtrim(' ' . $argument->description)); + $namespace->addUse(stdClass::class); + $property->setType(stdClass::class); + $property->addComment('@param stdClass<' . $type->doc . '> ...$' . $argument->name . rtrim(' ' . $argument->description)); $constuctor->addBody(<<name} as \$key => \$value) { if (! \is_string(\$key)) { throw new \InvalidArgumentException('Expected \${$argument->name} arguments to be a map of {$type->doc}, named arguments (:) or array unpacking ...[\'\' => ] must be used'); } } - PHP); - } - - if ($argument->variadicMin !== null) { - $constuctor->addBody(<<name}) < {$argument->variadicMin}) { - throw new \InvalidArgumentException(\sprintf('Expected at least %d values for \${$argument->name}, got %d.', {$argument->variadicMin}, \count(\${$argument->name}))); - } + \${$argument->name} = (object) \${$argument->name}; PHP); } } else { // Non-variadic arguments $property->addComment('@param ' . $type->doc . ' $' . $argument->name . rtrim(' ' . $argument->description)); $property->setType($type->native); + $constuctor->addComment('@param ' . $type->doc . ' $' . $argument->name . rtrim(' ' . $argument->description)); if ($argument->optional) { // We use a special Optional::Undefined type to differentiate between null and undefined @@ -120,7 +124,6 @@ public function createClass(GeneratorDefinition $definition, OperatorDefinition // Set property from constructor argument $constuctor->addBody('$this->' . $argument->name . ' = $' . $argument->name . ';'); - $constuctor->addComment('@param ' . $type->doc . ' $' . $argument->name . rtrim(' ' . $argument->description)); } return $namespace; diff --git a/src/Builder/Aggregation.php b/src/Builder/Aggregation.php index fbfbff3b5..b14f2049c 100644 --- a/src/Builder/Aggregation.php +++ b/src/Builder/Aggregation.php @@ -203,6 +203,7 @@ use MongoDB\Builder\Expression\ResolvesToString; use MongoDB\Builder\Expression\ResolvesToTimestamp; use MongoDB\Model\BSONArray; +use stdClass; final class Aggregation { @@ -424,22 +425,22 @@ public static function bitXor(): BitXorAggregation } /** - * @param array|object $sortBy Specifies the order of results, with syntax similar to $sort. + * @param array|stdClass $sortBy Specifies the order of results, with syntax similar to $sort. * @param ExpressionInterface|mixed $output Represents the output for each element in the group and can be any expression. */ - public static function bottom(array|object $sortBy, mixed $output): BottomAggregation + public static function bottom(stdClass|array $sortBy, mixed $output): BottomAggregation { return new BottomAggregation($sortBy, $output); } /** * @param Int64|ResolvesToInt|int $n 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. - * @param array|object $sortBy Specifies the order of results, with syntax similar to $sort. + * @param array|stdClass $sortBy Specifies the order of results, with syntax similar to $sort. * @param ExpressionInterface|mixed $output Represents the output for each element in the group and can be any expression. */ public static function bottomN( Int64|ResolvesToInt|int $n, - array|object $sortBy, + stdClass|array $sortBy, mixed $output, ): BottomNAggregation { @@ -447,9 +448,11 @@ public static function bottomN( } /** - * @param Document|ResolvesToNull|ResolvesToObject|Serializable|array|null|object $object + * @param Document|ResolvesToNull|ResolvesToObject|Serializable|array|null|stdClass $object */ - public static function bsonSize(array|null|object $object): BsonSizeAggregation + public static function bsonSize( + Document|Serializable|ResolvesToNull|ResolvesToObject|stdClass|array|null $object, + ): BsonSizeAggregation { return new BsonSizeAggregation($object); } @@ -1100,11 +1103,11 @@ public static function lastN( } /** - * @param Document|Serializable|array|object $vars 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. + * @param Document|Serializable|array|stdClass $vars 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. * @param ExpressionInterface|mixed $in The expression to evaluate. */ - public static function let(array|object $vars, mixed $in): LetAggregation + public static function let(Document|Serializable|stdClass|array $vars, mixed $in): LetAggregation { return new LetAggregation($vars, $in); } @@ -1240,9 +1243,11 @@ public static function median( } /** - * @param Document|ResolvesToObject|Serializable|array|object ...$document Any valid expression that resolves to a document. + * @param Document|ResolvesToObject|Serializable|array|stdClass ...$document Any valid expression that resolves to a document. */ - public static function mergeObjects(array|object ...$document): MergeObjectsAggregation + public static function mergeObjects( + Document|Serializable|ResolvesToObject|stdClass|array ...$document, + ): MergeObjectsAggregation { return new MergeObjectsAggregation(...$document); } @@ -1350,9 +1355,11 @@ public static function not(mixed $expression): NotAggregation } /** - * @param Document|ResolvesToObject|Serializable|array|object $object 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. + * @param Document|ResolvesToObject|Serializable|array|stdClass $object 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. */ - public static function objectToArray(array|object $object): ObjectToArrayAggregation + public static function objectToArray( + Document|Serializable|ResolvesToObject|stdClass|array $object, + ): ObjectToArrayAggregation { return new ObjectToArrayAggregation($object); } @@ -1603,13 +1610,13 @@ public static function setEquals(PackedArray|ResolvesToArray|BSONArray|array ... /** * @param ResolvesToString|non-empty-string $field 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. - * @param Document|ResolvesToObject|Serializable|array|object $input Document that contains the field that you want to add or update. input must resolve to an object, missing, null, or undefined. + * @param Document|ResolvesToObject|Serializable|array|stdClass $input Document that contains the field that you want to add or update. input must resolve to an object, missing, null, or undefined. * @param ExpressionInterface|mixed $value 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. */ public static function setField( ResolvesToString|string $field, - array|object $input, + Document|Serializable|ResolvesToObject|stdClass|array $input, mixed $value, ): SetFieldAggregation { @@ -1708,11 +1715,11 @@ public static function slice( /** * @param BSONArray|PackedArray|ResolvesToArray|list $input The array to be sorted. - * @param array|object $sortBy The document specifies a sort ordering. + * @param array|stdClass $sortBy The document specifies a sort ordering. */ public static function sortArray( PackedArray|ResolvesToArray|BSONArray|array $input, - array|object $sortBy, + stdClass|array $sortBy, ): SortArrayAggregation { return new SortArrayAggregation($input, $sortBy); @@ -1961,20 +1968,20 @@ public static function toUpper(ResolvesToString|string $expression): ToUpperAggr } /** - * @param array|object $sortBy Specifies the order of results, with syntax similar to $sort. + * @param array|stdClass $sortBy Specifies the order of results, with syntax similar to $sort. * @param ExpressionInterface|mixed $output Represents the output for each element in the group and can be any expression. */ - public static function top(array|object $sortBy, mixed $output): TopAggregation + public static function top(stdClass|array $sortBy, mixed $output): TopAggregation { return new TopAggregation($sortBy, $output); } /** * @param Int64|ResolvesToInt|int $n 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. - * @param array|object $sortBy Specifies the order of results, with syntax similar to $sort. + * @param array|stdClass $sortBy Specifies the order of results, with syntax similar to $sort. * @param ExpressionInterface|mixed $output Represents the output for each element in the group and can be any expression. */ - public static function topN(Int64|ResolvesToInt|int $n, array|object $sortBy, mixed $output): TopNAggregation + public static function topN(Int64|ResolvesToInt|int $n, stdClass|array $sortBy, mixed $output): TopNAggregation { return new TopNAggregation($n, $sortBy, $output); } @@ -2032,9 +2039,12 @@ public static function type(mixed $expression): TypeAggregation /** * @param ResolvesToString|non-empty-string $field 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. - * @param Document|ResolvesToObject|Serializable|array|object $input Document that contains the field that you want to add or update. input must resolve to an object, missing, null, or undefined. + * @param Document|ResolvesToObject|Serializable|array|stdClass $input Document that contains the field that you want to add or update. input must resolve to an object, missing, null, or undefined. */ - public static function unsetField(ResolvesToString|string $field, array|object $input): UnsetFieldAggregation + public static function unsetField( + ResolvesToString|string $field, + Document|Serializable|ResolvesToObject|stdClass|array $input, + ): UnsetFieldAggregation { return new UnsetFieldAggregation($field, $input); } diff --git a/src/Builder/Aggregation/AddAggregation.php b/src/Builder/Aggregation/AddAggregation.php index ca6ab4104..bd0d356a6 100644 --- a/src/Builder/Aggregation/AddAggregation.php +++ b/src/Builder/Aggregation/AddAggregation.php @@ -25,17 +25,17 @@ class AddAggregation implements ResolvesToNumber, ResolvesToDate public array $expression; /** - * @param DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int $expression The arguments can be any valid expression as long as they resolve to either all numbers or to numbers and a date. + * @param DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int ...$expression The arguments can be any valid expression as long as they resolve to either all numbers or to numbers and a date. */ public function __construct( \UTCDateTime|DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|float|int ...$expression, ) { - if (! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression arguments to be a list of DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int, named arguments are not supported'); - } if (\count($expression) < 1) { throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); } + if (! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression arguments to be a list of DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int, named arguments are not supported'); + } $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/AllElementsTrueAggregation.php b/src/Builder/Aggregation/AllElementsTrueAggregation.php index 9c48cfc51..633071a5e 100644 --- a/src/Builder/Aggregation/AllElementsTrueAggregation.php +++ b/src/Builder/Aggregation/AllElementsTrueAggregation.php @@ -25,16 +25,16 @@ class AllElementsTrueAggregation implements ResolvesToBool public array $expression; /** - * @param BSONArray|PackedArray|ResolvesToArray|list $expression + * @param BSONArray|PackedArray|ResolvesToArray|list ...$expression */ public function __construct(PackedArray|ResolvesToArray|BSONArray|array ...$expression) { - if (! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression arguments to be a list of BSONArray|PackedArray|ResolvesToArray|list, named arguments are not supported'); - } if (\count($expression) < 1) { throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); } + if (! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression arguments to be a list of BSONArray|PackedArray|ResolvesToArray|list, named arguments are not supported'); + } $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/AndAggregation.php b/src/Builder/Aggregation/AndAggregation.php index 60ceb4ce5..ae462a689 100644 --- a/src/Builder/Aggregation/AndAggregation.php +++ b/src/Builder/Aggregation/AndAggregation.php @@ -27,16 +27,16 @@ class AndAggregation implements ResolvesToBool public array $expression; /** - * @param Decimal128|ExpressionInterface|Int64|ResolvesToBool|ResolvesToNull|ResolvesToNumber|ResolvesToString|bool|float|int|mixed|non-empty-string|null $expression + * @param Decimal128|ExpressionInterface|Int64|ResolvesToBool|ResolvesToNull|ResolvesToNumber|ResolvesToString|bool|float|int|mixed|non-empty-string|null ...$expression */ public function __construct(mixed ...$expression) { - if (! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression arguments to be a list of Decimal128|ExpressionInterface|Int64|ResolvesToBool|ResolvesToNull|ResolvesToNumber|ResolvesToString|bool|float|int|mixed|non-empty-string|null, named arguments are not supported'); - } if (\count($expression) < 1) { throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); } + if (! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression arguments to be a list of Decimal128|ExpressionInterface|Int64|ResolvesToBool|ResolvesToNull|ResolvesToNumber|ResolvesToString|bool|float|int|mixed|non-empty-string|null, named arguments are not supported'); + } $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/AvgAggregation.php b/src/Builder/Aggregation/AvgAggregation.php index ac0a85440..728ac4066 100644 --- a/src/Builder/Aggregation/AvgAggregation.php +++ b/src/Builder/Aggregation/AvgAggregation.php @@ -23,16 +23,16 @@ class AvgAggregation implements ResolvesToNumber, AccumulatorInterface public array $expression; /** - * @param Decimal128|Int64|ResolvesToNumber|float|int $expression + * @param Decimal128|Int64|ResolvesToNumber|float|int ...$expression */ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int ...$expression) { - if (! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression arguments to be a list of Decimal128|Int64|ResolvesToNumber|float|int, named arguments are not supported'); - } if (\count($expression) < 1) { throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); } + if (! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression arguments to be a list of Decimal128|Int64|ResolvesToNumber|float|int, named arguments are not supported'); + } $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/BitAndAggregation.php b/src/Builder/Aggregation/BitAndAggregation.php index 9a7a40d0a..dd4931dcc 100644 --- a/src/Builder/Aggregation/BitAndAggregation.php +++ b/src/Builder/Aggregation/BitAndAggregation.php @@ -23,16 +23,16 @@ class BitAndAggregation implements ResolvesToInt, ResolvesToLong public array $expression; /** - * @param Int64|ResolvesToInt|ResolvesToLong|int $expression + * @param Int64|ResolvesToInt|ResolvesToLong|int ...$expression */ public function __construct(Int64|ResolvesToInt|ResolvesToLong|int ...$expression) { - if (! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression arguments to be a list of Int64|ResolvesToInt|ResolvesToLong|int, named arguments are not supported'); - } if (\count($expression) < 1) { throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); } + if (! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression arguments to be a list of Int64|ResolvesToInt|ResolvesToLong|int, named arguments are not supported'); + } $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/BitOrAggregation.php b/src/Builder/Aggregation/BitOrAggregation.php index 7b627ac29..df35fae7b 100644 --- a/src/Builder/Aggregation/BitOrAggregation.php +++ b/src/Builder/Aggregation/BitOrAggregation.php @@ -23,16 +23,16 @@ class BitOrAggregation implements ResolvesToInt, ResolvesToLong public array $expression; /** - * @param Int64|ResolvesToInt|ResolvesToLong|int $expression + * @param Int64|ResolvesToInt|ResolvesToLong|int ...$expression */ public function __construct(Int64|ResolvesToInt|ResolvesToLong|int ...$expression) { - if (! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression arguments to be a list of Int64|ResolvesToInt|ResolvesToLong|int, named arguments are not supported'); - } if (\count($expression) < 1) { throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); } + if (! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression arguments to be a list of Int64|ResolvesToInt|ResolvesToLong|int, named arguments are not supported'); + } $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/BottomAggregation.php b/src/Builder/Aggregation/BottomAggregation.php index 8b3a526e2..a62f2c9e1 100644 --- a/src/Builder/Aggregation/BottomAggregation.php +++ b/src/Builder/Aggregation/BottomAggregation.php @@ -8,23 +8,24 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ExpressionInterface; +use stdClass; class BottomAggregation implements AccumulatorInterface { public const NAME = '$bottom'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param array|object $sortBy Specifies the order of results, with syntax similar to $sort. */ - public array|object $sortBy; + /** @param array|stdClass $sortBy Specifies the order of results, with syntax similar to $sort. */ + public stdClass|array $sortBy; /** @param ExpressionInterface|mixed $output Represents the output for each element in the group and can be any expression. */ public mixed $output; /** - * @param array|object $sortBy Specifies the order of results, with syntax similar to $sort. + * @param array|stdClass $sortBy Specifies the order of results, with syntax similar to $sort. * @param ExpressionInterface|mixed $output Represents the output for each element in the group and can be any expression. */ - public function __construct(array|object $sortBy, mixed $output) + public function __construct(stdClass|array $sortBy, mixed $output) { $this->sortBy = $sortBy; $this->output = $output; diff --git a/src/Builder/Aggregation/BottomNAggregation.php b/src/Builder/Aggregation/BottomNAggregation.php index c2f060193..96324246d 100644 --- a/src/Builder/Aggregation/BottomNAggregation.php +++ b/src/Builder/Aggregation/BottomNAggregation.php @@ -10,6 +10,7 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToInt; +use stdClass; class BottomNAggregation implements AccumulatorInterface { @@ -19,18 +20,18 @@ class BottomNAggregation implements AccumulatorInterface /** @param Int64|ResolvesToInt|int $n 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. */ public Int64|ResolvesToInt|int $n; - /** @param array|object $sortBy Specifies the order of results, with syntax similar to $sort. */ - public array|object $sortBy; + /** @param array|stdClass $sortBy Specifies the order of results, with syntax similar to $sort. */ + public stdClass|array $sortBy; /** @param ExpressionInterface|mixed $output Represents the output for each element in the group and can be any expression. */ public mixed $output; /** * @param Int64|ResolvesToInt|int $n 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. - * @param array|object $sortBy Specifies the order of results, with syntax similar to $sort. + * @param array|stdClass $sortBy Specifies the order of results, with syntax similar to $sort. * @param ExpressionInterface|mixed $output Represents the output for each element in the group and can be any expression. */ - public function __construct(Int64|ResolvesToInt|int $n, array|object $sortBy, mixed $output) + public function __construct(Int64|ResolvesToInt|int $n, stdClass|array $sortBy, mixed $output) { $this->n = $n; $this->sortBy = $sortBy; diff --git a/src/Builder/Aggregation/BsonSizeAggregation.php b/src/Builder/Aggregation/BsonSizeAggregation.php index 1d60eb114..55045aa19 100644 --- a/src/Builder/Aggregation/BsonSizeAggregation.php +++ b/src/Builder/Aggregation/BsonSizeAggregation.php @@ -12,19 +12,20 @@ use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Expression\ResolvesToNull; use MongoDB\Builder\Expression\ResolvesToObject; +use stdClass; class BsonSizeAggregation implements ResolvesToInt { public const NAME = '$bsonSize'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param Document|ResolvesToNull|ResolvesToObject|Serializable|array|null|object $object */ - public array|null|object $object; + /** @param Document|ResolvesToNull|ResolvesToObject|Serializable|array|null|stdClass $object */ + public Document|Serializable|ResolvesToNull|ResolvesToObject|stdClass|array|null $object; /** - * @param Document|ResolvesToNull|ResolvesToObject|Serializable|array|null|object $object + * @param Document|ResolvesToNull|ResolvesToObject|Serializable|array|null|stdClass $object */ - public function __construct(array|null|object $object) + public function __construct(Document|Serializable|ResolvesToNull|ResolvesToObject|stdClass|array|null $object) { $this->object = $object; } diff --git a/src/Builder/Aggregation/ConcatAggregation.php b/src/Builder/Aggregation/ConcatAggregation.php index 283de6443..bbc895a27 100644 --- a/src/Builder/Aggregation/ConcatAggregation.php +++ b/src/Builder/Aggregation/ConcatAggregation.php @@ -21,16 +21,16 @@ class ConcatAggregation implements ResolvesToString public array $expression; /** - * @param ResolvesToString|non-empty-string $expression + * @param ResolvesToString|non-empty-string ...$expression */ public function __construct(ResolvesToString|string ...$expression) { - if (! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression arguments to be a list of ResolvesToString|non-empty-string, named arguments are not supported'); - } if (\count($expression) < 1) { throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); } + if (! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression arguments to be a list of ResolvesToString|non-empty-string, named arguments are not supported'); + } $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/ConcatArraysAggregation.php b/src/Builder/Aggregation/ConcatArraysAggregation.php index 932db7aed..9fedd47ca 100644 --- a/src/Builder/Aggregation/ConcatArraysAggregation.php +++ b/src/Builder/Aggregation/ConcatArraysAggregation.php @@ -24,16 +24,16 @@ class ConcatArraysAggregation implements ResolvesToArray public array $array; /** - * @param BSONArray|PackedArray|ResolvesToArray|list $array + * @param BSONArray|PackedArray|ResolvesToArray|list ...$array */ public function __construct(PackedArray|ResolvesToArray|BSONArray|array ...$array) { - if (! \array_is_list($array)) { - throw new \InvalidArgumentException('Expected $array arguments to be a list of BSONArray|PackedArray|ResolvesToArray|list, named arguments are not supported'); - } if (\count($array) < 1) { throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $array, got %d.', 1, \count($array))); } + if (! \array_is_list($array)) { + throw new \InvalidArgumentException('Expected $array arguments to be a list of BSONArray|PackedArray|ResolvesToArray|list, named arguments are not supported'); + } $this->array = $array; } } diff --git a/src/Builder/Aggregation/IfNullAggregation.php b/src/Builder/Aggregation/IfNullAggregation.php index 1e3b86bbe..77ea80227 100644 --- a/src/Builder/Aggregation/IfNullAggregation.php +++ b/src/Builder/Aggregation/IfNullAggregation.php @@ -21,16 +21,16 @@ class IfNullAggregation implements ExpressionInterface public array $expression; /** - * @param ExpressionInterface|mixed $expression + * @param ExpressionInterface|mixed ...$expression */ public function __construct(mixed ...$expression) { - if (! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression arguments to be a list of ExpressionInterface|mixed, named arguments are not supported'); - } if (\count($expression) < 1) { throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); } + if (! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression arguments to be a list of ExpressionInterface|mixed, named arguments are not supported'); + } $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/IsArrayAggregation.php b/src/Builder/Aggregation/IsArrayAggregation.php index 89f59970d..fbd922602 100644 --- a/src/Builder/Aggregation/IsArrayAggregation.php +++ b/src/Builder/Aggregation/IsArrayAggregation.php @@ -22,16 +22,16 @@ class IsArrayAggregation implements ResolvesToBool public array $expression; /** - * @param ExpressionInterface|mixed $expression + * @param ExpressionInterface|mixed ...$expression */ public function __construct(mixed ...$expression) { - if (! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression arguments to be a list of ExpressionInterface|mixed, named arguments are not supported'); - } if (\count($expression) < 1) { throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); } + if (! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression arguments to be a list of ExpressionInterface|mixed, named arguments are not supported'); + } $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/IsNumberAggregation.php b/src/Builder/Aggregation/IsNumberAggregation.php index 77efe8405..691cbad8f 100644 --- a/src/Builder/Aggregation/IsNumberAggregation.php +++ b/src/Builder/Aggregation/IsNumberAggregation.php @@ -22,16 +22,16 @@ class IsNumberAggregation implements ResolvesToBool public array $expression; /** - * @param ExpressionInterface|mixed $expression + * @param ExpressionInterface|mixed ...$expression */ public function __construct(mixed ...$expression) { - if (! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression arguments to be a list of ExpressionInterface|mixed, named arguments are not supported'); - } if (\count($expression) < 1) { throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); } + if (! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression arguments to be a list of ExpressionInterface|mixed, named arguments are not supported'); + } $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/LetAggregation.php b/src/Builder/Aggregation/LetAggregation.php index 7c03aaf60..b76f78d98 100644 --- a/src/Builder/Aggregation/LetAggregation.php +++ b/src/Builder/Aggregation/LetAggregation.php @@ -10,6 +10,7 @@ use MongoDB\BSON\Serializable; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ExpressionInterface; +use stdClass; class LetAggregation implements ExpressionInterface { @@ -17,20 +18,20 @@ class LetAggregation implements ExpressionInterface public const ENCODE = \MongoDB\Builder\Encode::Object; /** - * @param Document|Serializable|array|object $vars 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. + * @param Document|Serializable|array|stdClass $vars 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. */ - public array|object $vars; + public Document|Serializable|stdClass|array $vars; /** @param ExpressionInterface|mixed $in The expression to evaluate. */ public mixed $in; /** - * @param Document|Serializable|array|object $vars 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. + * @param Document|Serializable|array|stdClass $vars 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. * @param ExpressionInterface|mixed $in The expression to evaluate. */ - public function __construct(array|object $vars, mixed $in) + public function __construct(Document|Serializable|stdClass|array $vars, mixed $in) { $this->vars = $vars; $this->in = $in; diff --git a/src/Builder/Aggregation/MaxAggregation.php b/src/Builder/Aggregation/MaxAggregation.php index 04cdd7a66..e4d9499f1 100644 --- a/src/Builder/Aggregation/MaxAggregation.php +++ b/src/Builder/Aggregation/MaxAggregation.php @@ -21,16 +21,16 @@ class MaxAggregation implements ExpressionInterface, AccumulatorInterface public array $expression; /** - * @param ExpressionInterface|mixed $expression + * @param ExpressionInterface|mixed ...$expression */ public function __construct(mixed ...$expression) { - if (! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression arguments to be a list of ExpressionInterface|mixed, named arguments are not supported'); - } if (\count($expression) < 1) { throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); } + if (! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression arguments to be a list of ExpressionInterface|mixed, named arguments are not supported'); + } $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/MergeObjectsAggregation.php b/src/Builder/Aggregation/MergeObjectsAggregation.php index 5c3500713..d477093c4 100644 --- a/src/Builder/Aggregation/MergeObjectsAggregation.php +++ b/src/Builder/Aggregation/MergeObjectsAggregation.php @@ -10,6 +10,7 @@ use MongoDB\BSON\Serializable; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToObject; +use stdClass; class MergeObjectsAggregation implements AccumulatorInterface { @@ -18,21 +19,21 @@ class MergeObjectsAggregation implements AccumulatorInterface /** * @no-named-arguments - * @param list ...$document Any valid expression that resolves to a document. + * @param list ...$document Any valid expression that resolves to a document. */ public array $document; /** - * @param Document|ResolvesToObject|Serializable|array|object $document Any valid expression that resolves to a document. + * @param Document|ResolvesToObject|Serializable|array|stdClass ...$document Any valid expression that resolves to a document. */ - public function __construct(array|object ...$document) + public function __construct(Document|Serializable|ResolvesToObject|stdClass|array ...$document) { - if (! \array_is_list($document)) { - throw new \InvalidArgumentException('Expected $document arguments to be a list of Document|ResolvesToObject|Serializable|array|object, named arguments are not supported'); - } if (\count($document) < 1) { throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $document, got %d.', 1, \count($document))); } + if (! \array_is_list($document)) { + throw new \InvalidArgumentException('Expected $document arguments to be a list of Document|ResolvesToObject|Serializable|array|stdClass, named arguments are not supported'); + } $this->document = $document; } } diff --git a/src/Builder/Aggregation/MinAggregation.php b/src/Builder/Aggregation/MinAggregation.php index da2264afb..9ddddd256 100644 --- a/src/Builder/Aggregation/MinAggregation.php +++ b/src/Builder/Aggregation/MinAggregation.php @@ -21,16 +21,16 @@ class MinAggregation implements ExpressionInterface, AccumulatorInterface public array $expression; /** - * @param ExpressionInterface|mixed $expression + * @param ExpressionInterface|mixed ...$expression */ public function __construct(mixed ...$expression) { - if (! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression arguments to be a list of ExpressionInterface|mixed, named arguments are not supported'); - } if (\count($expression) < 1) { throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); } + if (! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression arguments to be a list of ExpressionInterface|mixed, named arguments are not supported'); + } $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/MultiplyAggregation.php b/src/Builder/Aggregation/MultiplyAggregation.php index 4f52e271c..b831e8524 100644 --- a/src/Builder/Aggregation/MultiplyAggregation.php +++ b/src/Builder/Aggregation/MultiplyAggregation.php @@ -25,17 +25,17 @@ class MultiplyAggregation implements ResolvesToDecimal public array $expression; /** - * @param Decimal128|Int64|ResolvesToNumber|float|int $expression The arguments can be any valid expression as long as they resolve to numbers. + * @param Decimal128|Int64|ResolvesToNumber|float|int ...$expression 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. */ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int ...$expression) { - if (! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression arguments to be a list of Decimal128|Int64|ResolvesToNumber|float|int, named arguments are not supported'); - } if (\count($expression) < 1) { throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); } + if (! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression arguments to be a list of Decimal128|Int64|ResolvesToNumber|float|int, named arguments are not supported'); + } $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/ObjectToArrayAggregation.php b/src/Builder/Aggregation/ObjectToArrayAggregation.php index d67503111..275b5a926 100644 --- a/src/Builder/Aggregation/ObjectToArrayAggregation.php +++ b/src/Builder/Aggregation/ObjectToArrayAggregation.php @@ -11,19 +11,20 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToArray; use MongoDB\Builder\Expression\ResolvesToObject; +use stdClass; class ObjectToArrayAggregation implements ResolvesToArray { public const NAME = '$objectToArray'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param Document|ResolvesToObject|Serializable|array|object $object 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. */ - public array|object $object; + /** @param Document|ResolvesToObject|Serializable|array|stdClass $object 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. */ + public Document|Serializable|ResolvesToObject|stdClass|array $object; /** - * @param Document|ResolvesToObject|Serializable|array|object $object 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. + * @param Document|ResolvesToObject|Serializable|array|stdClass $object 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. */ - public function __construct(array|object $object) + public function __construct(Document|Serializable|ResolvesToObject|stdClass|array $object) { $this->object = $object; } diff --git a/src/Builder/Aggregation/OrAggregation.php b/src/Builder/Aggregation/OrAggregation.php index 39b1c77ae..704c4670e 100644 --- a/src/Builder/Aggregation/OrAggregation.php +++ b/src/Builder/Aggregation/OrAggregation.php @@ -22,16 +22,16 @@ class OrAggregation implements ResolvesToBool public array $expression; /** - * @param ExpressionInterface|ResolvesToBool|bool|mixed $expression + * @param ExpressionInterface|ResolvesToBool|bool|mixed ...$expression */ public function __construct(mixed ...$expression) { - if (! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression arguments to be a list of ExpressionInterface|ResolvesToBool|bool|mixed, named arguments are not supported'); - } if (\count($expression) < 1) { throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); } + if (! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression arguments to be a list of ExpressionInterface|ResolvesToBool|bool|mixed, named arguments are not supported'); + } $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/SetEqualsAggregation.php b/src/Builder/Aggregation/SetEqualsAggregation.php index 31656a50c..8f3846592 100644 --- a/src/Builder/Aggregation/SetEqualsAggregation.php +++ b/src/Builder/Aggregation/SetEqualsAggregation.php @@ -25,16 +25,16 @@ class SetEqualsAggregation implements ResolvesToBool public array $expression; /** - * @param BSONArray|PackedArray|ResolvesToArray|list $expression + * @param BSONArray|PackedArray|ResolvesToArray|list ...$expression */ public function __construct(PackedArray|ResolvesToArray|BSONArray|array ...$expression) { - if (! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression arguments to be a list of BSONArray|PackedArray|ResolvesToArray|list, named arguments are not supported'); - } if (\count($expression) < 1) { throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); } + if (! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression arguments to be a list of BSONArray|PackedArray|ResolvesToArray|list, named arguments are not supported'); + } $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/SetFieldAggregation.php b/src/Builder/Aggregation/SetFieldAggregation.php index 980c1c3b9..278b32ea9 100644 --- a/src/Builder/Aggregation/SetFieldAggregation.php +++ b/src/Builder/Aggregation/SetFieldAggregation.php @@ -12,6 +12,7 @@ use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToObject; use MongoDB\Builder\Expression\ResolvesToString; +use stdClass; class SetFieldAggregation implements ResolvesToObject { @@ -21,8 +22,8 @@ class SetFieldAggregation implements ResolvesToObject /** @param ResolvesToString|non-empty-string $field 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. */ public ResolvesToString|string $field; - /** @param Document|ResolvesToObject|Serializable|array|object $input Document that contains the field that you want to add or update. input must resolve to an object, missing, null, or undefined. */ - public array|object $input; + /** @param Document|ResolvesToObject|Serializable|array|stdClass $input Document that contains the field that you want to add or update. input must resolve to an object, missing, null, or undefined. */ + public Document|Serializable|ResolvesToObject|stdClass|array $input; /** * @param ExpressionInterface|mixed $value The value that you want to assign to field. value can be any valid expression. @@ -32,12 +33,15 @@ class SetFieldAggregation implements ResolvesToObject /** * @param ResolvesToString|non-empty-string $field 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. - * @param Document|ResolvesToObject|Serializable|array|object $input Document that contains the field that you want to add or update. input must resolve to an object, missing, null, or undefined. + * @param Document|ResolvesToObject|Serializable|array|stdClass $input Document that contains the field that you want to add or update. input must resolve to an object, missing, null, or undefined. * @param ExpressionInterface|mixed $value 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. */ - public function __construct(ResolvesToString|string $field, array|object $input, mixed $value) - { + public function __construct( + ResolvesToString|string $field, + Document|Serializable|ResolvesToObject|stdClass|array $input, + mixed $value, + ) { $this->field = $field; $this->input = $input; $this->value = $value; diff --git a/src/Builder/Aggregation/SetIntersectionAggregation.php b/src/Builder/Aggregation/SetIntersectionAggregation.php index 8297631f4..90c97c0ba 100644 --- a/src/Builder/Aggregation/SetIntersectionAggregation.php +++ b/src/Builder/Aggregation/SetIntersectionAggregation.php @@ -24,16 +24,16 @@ class SetIntersectionAggregation implements ResolvesToArray public array $expression; /** - * @param BSONArray|PackedArray|ResolvesToArray|list $expression + * @param BSONArray|PackedArray|ResolvesToArray|list ...$expression */ public function __construct(PackedArray|ResolvesToArray|BSONArray|array ...$expression) { - if (! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression arguments to be a list of BSONArray|PackedArray|ResolvesToArray|list, named arguments are not supported'); - } if (\count($expression) < 1) { throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); } + if (! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression arguments to be a list of BSONArray|PackedArray|ResolvesToArray|list, named arguments are not supported'); + } $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/SetUnionAggregation.php b/src/Builder/Aggregation/SetUnionAggregation.php index 4379b2a33..8084f3c5f 100644 --- a/src/Builder/Aggregation/SetUnionAggregation.php +++ b/src/Builder/Aggregation/SetUnionAggregation.php @@ -24,16 +24,16 @@ class SetUnionAggregation implements ResolvesToArray public array $expression; /** - * @param BSONArray|PackedArray|ResolvesToArray|list $expression + * @param BSONArray|PackedArray|ResolvesToArray|list ...$expression */ public function __construct(PackedArray|ResolvesToArray|BSONArray|array ...$expression) { - if (! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression arguments to be a list of BSONArray|PackedArray|ResolvesToArray|list, named arguments are not supported'); - } if (\count($expression) < 1) { throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); } + if (! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression arguments to be a list of BSONArray|PackedArray|ResolvesToArray|list, named arguments are not supported'); + } $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/SortArrayAggregation.php b/src/Builder/Aggregation/SortArrayAggregation.php index 0416eaea7..c1e8d4845 100644 --- a/src/Builder/Aggregation/SortArrayAggregation.php +++ b/src/Builder/Aggregation/SortArrayAggregation.php @@ -11,6 +11,7 @@ use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToArray; use MongoDB\Model\BSONArray; +use stdClass; class SortArrayAggregation implements ResolvesToArray { @@ -20,14 +21,14 @@ class SortArrayAggregation implements ResolvesToArray /** @param BSONArray|PackedArray|ResolvesToArray|list $input The array to be sorted. */ public PackedArray|ResolvesToArray|BSONArray|array $input; - /** @param array|object $sortBy The document specifies a sort ordering. */ - public array|object $sortBy; + /** @param array|stdClass $sortBy The document specifies a sort ordering. */ + public stdClass|array $sortBy; /** * @param BSONArray|PackedArray|ResolvesToArray|list $input The array to be sorted. - * @param array|object $sortBy The document specifies a sort ordering. + * @param array|stdClass $sortBy The document specifies a sort ordering. */ - public function __construct(PackedArray|ResolvesToArray|BSONArray|array $input, array|object $sortBy) + public function __construct(PackedArray|ResolvesToArray|BSONArray|array $input, stdClass|array $sortBy) { if (\is_array($input) && ! \array_is_list($input)) { throw new \InvalidArgumentException('Expected $input argument to be a list, got an associative array.'); diff --git a/src/Builder/Aggregation/StdDevPopAggregation.php b/src/Builder/Aggregation/StdDevPopAggregation.php index 86ff24ebb..6c552a832 100644 --- a/src/Builder/Aggregation/StdDevPopAggregation.php +++ b/src/Builder/Aggregation/StdDevPopAggregation.php @@ -24,16 +24,16 @@ class StdDevPopAggregation implements ResolvesToDouble, AccumulatorInterface public array $expression; /** - * @param Decimal128|Int64|ResolvesToNumber|float|int $expression + * @param Decimal128|Int64|ResolvesToNumber|float|int ...$expression */ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int ...$expression) { - if (! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression arguments to be a list of Decimal128|Int64|ResolvesToNumber|float|int, named arguments are not supported'); - } if (\count($expression) < 1) { throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); } + if (! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression arguments to be a list of Decimal128|Int64|ResolvesToNumber|float|int, named arguments are not supported'); + } $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/StdDevSampAggregation.php b/src/Builder/Aggregation/StdDevSampAggregation.php index 8a85bb4d1..9877d210e 100644 --- a/src/Builder/Aggregation/StdDevSampAggregation.php +++ b/src/Builder/Aggregation/StdDevSampAggregation.php @@ -24,16 +24,16 @@ class StdDevSampAggregation implements ResolvesToDouble, AccumulatorInterface public array $expression; /** - * @param Decimal128|Int64|ResolvesToNumber|float|int $expression + * @param Decimal128|Int64|ResolvesToNumber|float|int ...$expression */ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int ...$expression) { - if (! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression arguments to be a list of Decimal128|Int64|ResolvesToNumber|float|int, named arguments are not supported'); - } if (\count($expression) < 1) { throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); } + if (! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression arguments to be a list of Decimal128|Int64|ResolvesToNumber|float|int, named arguments are not supported'); + } $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/SumAggregation.php b/src/Builder/Aggregation/SumAggregation.php index 86a3e74e3..c80f12850 100644 --- a/src/Builder/Aggregation/SumAggregation.php +++ b/src/Builder/Aggregation/SumAggregation.php @@ -23,16 +23,16 @@ class SumAggregation implements ResolvesToNumber, AccumulatorInterface public array $expression; /** - * @param Decimal128|Int64|ResolvesToNumber|float|int $expression + * @param Decimal128|Int64|ResolvesToNumber|float|int ...$expression */ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int ...$expression) { - if (! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression arguments to be a list of Decimal128|Int64|ResolvesToNumber|float|int, named arguments are not supported'); - } if (\count($expression) < 1) { throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); } + if (! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression arguments to be a list of Decimal128|Int64|ResolvesToNumber|float|int, named arguments are not supported'); + } $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/TopAggregation.php b/src/Builder/Aggregation/TopAggregation.php index 441a8e482..ac3f4a1cb 100644 --- a/src/Builder/Aggregation/TopAggregation.php +++ b/src/Builder/Aggregation/TopAggregation.php @@ -8,23 +8,24 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ExpressionInterface; +use stdClass; class TopAggregation implements AccumulatorInterface { public const NAME = '$top'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param array|object $sortBy Specifies the order of results, with syntax similar to $sort. */ - public array|object $sortBy; + /** @param array|stdClass $sortBy Specifies the order of results, with syntax similar to $sort. */ + public stdClass|array $sortBy; /** @param ExpressionInterface|mixed $output Represents the output for each element in the group and can be any expression. */ public mixed $output; /** - * @param array|object $sortBy Specifies the order of results, with syntax similar to $sort. + * @param array|stdClass $sortBy Specifies the order of results, with syntax similar to $sort. * @param ExpressionInterface|mixed $output Represents the output for each element in the group and can be any expression. */ - public function __construct(array|object $sortBy, mixed $output) + public function __construct(stdClass|array $sortBy, mixed $output) { $this->sortBy = $sortBy; $this->output = $output; diff --git a/src/Builder/Aggregation/TopNAggregation.php b/src/Builder/Aggregation/TopNAggregation.php index 65edb0869..86b0365f3 100644 --- a/src/Builder/Aggregation/TopNAggregation.php +++ b/src/Builder/Aggregation/TopNAggregation.php @@ -10,6 +10,7 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToInt; +use stdClass; class TopNAggregation implements AccumulatorInterface { @@ -19,18 +20,18 @@ class TopNAggregation implements AccumulatorInterface /** @param Int64|ResolvesToInt|int $n 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. */ public Int64|ResolvesToInt|int $n; - /** @param array|object $sortBy Specifies the order of results, with syntax similar to $sort. */ - public array|object $sortBy; + /** @param array|stdClass $sortBy Specifies the order of results, with syntax similar to $sort. */ + public stdClass|array $sortBy; /** @param ExpressionInterface|mixed $output Represents the output for each element in the group and can be any expression. */ public mixed $output; /** * @param Int64|ResolvesToInt|int $n 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. - * @param array|object $sortBy Specifies the order of results, with syntax similar to $sort. + * @param array|stdClass $sortBy Specifies the order of results, with syntax similar to $sort. * @param ExpressionInterface|mixed $output Represents the output for each element in the group and can be any expression. */ - public function __construct(Int64|ResolvesToInt|int $n, array|object $sortBy, mixed $output) + public function __construct(Int64|ResolvesToInt|int $n, stdClass|array $sortBy, mixed $output) { $this->n = $n; $this->sortBy = $sortBy; diff --git a/src/Builder/Aggregation/UnsetFieldAggregation.php b/src/Builder/Aggregation/UnsetFieldAggregation.php index cb99bddc9..e67719165 100644 --- a/src/Builder/Aggregation/UnsetFieldAggregation.php +++ b/src/Builder/Aggregation/UnsetFieldAggregation.php @@ -11,6 +11,7 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToObject; use MongoDB\Builder\Expression\ResolvesToString; +use stdClass; class UnsetFieldAggregation implements ResolvesToObject { @@ -20,15 +21,17 @@ class UnsetFieldAggregation implements ResolvesToObject /** @param ResolvesToString|non-empty-string $field 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. */ public ResolvesToString|string $field; - /** @param Document|ResolvesToObject|Serializable|array|object $input Document that contains the field that you want to add or update. input must resolve to an object, missing, null, or undefined. */ - public array|object $input; + /** @param Document|ResolvesToObject|Serializable|array|stdClass $input Document that contains the field that you want to add or update. input must resolve to an object, missing, null, or undefined. */ + public Document|Serializable|ResolvesToObject|stdClass|array $input; /** * @param ResolvesToString|non-empty-string $field 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. - * @param Document|ResolvesToObject|Serializable|array|object $input Document that contains the field that you want to add or update. input must resolve to an object, missing, null, or undefined. + * @param Document|ResolvesToObject|Serializable|array|stdClass $input Document that contains the field that you want to add or update. input must resolve to an object, missing, null, or undefined. */ - public function __construct(ResolvesToString|string $field, array|object $input) - { + public function __construct( + ResolvesToString|string $field, + Document|Serializable|ResolvesToObject|stdClass|array $input, + ) { $this->field = $field; $this->input = $input; } diff --git a/src/Builder/BuilderEncoder.php b/src/Builder/BuilderEncoder.php index 44ae72968..f4cd4ecf5 100644 --- a/src/Builder/BuilderEncoder.php +++ b/src/Builder/BuilderEncoder.php @@ -6,18 +6,15 @@ use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\FieldPath; use MongoDB\Builder\Expression\Variable; -use MongoDB\Builder\Query\OrQuery; +use MongoDB\Builder\Query\QueryInterface; use MongoDB\Builder\Stage\GroupStage; use MongoDB\Builder\Stage\ProjectStage; -use MongoDB\Builder\Stage\SortStage; use MongoDB\Builder\Stage\StageInterface; use MongoDB\Codec\EncodeIfSupported; use MongoDB\Codec\Encoder; use MongoDB\Exception\UnsupportedValueException; use stdClass; -use function array_is_list; -use function array_merge; use function get_object_vars; use function is_array; use function sprintf; @@ -32,7 +29,10 @@ class BuilderEncoder implements Encoder */ public function canEncode($value): bool { - return $value instanceof Pipeline || $value instanceof StageInterface || $value instanceof ExpressionInterface; + return $value instanceof Pipeline + || $value instanceof StageInterface + || $value instanceof ExpressionInterface + || $value instanceof QueryInterface; } /** @@ -73,31 +73,6 @@ public function encode($value): stdClass|array|string return $this->wrap($value, $result); } - if ($value instanceof OrQuery) { - $result = []; - foreach ($value->query as $query) { - $encodedQuery = new stdClass(); - foreach ($query as $field => $expression) { - // Specific: $or queries are encoded as a list of expressions - // We need to merge query expressions into a single object - if (is_array($expression) && array_is_list($expression)) { - $mergedExpressions = []; - foreach ($expression as $expr) { - $mergedExpressions = array_merge($mergedExpressions, (array) $this->encodeIfSupported($expr)); - } - - $encodedQuery->{$field} = (object) $mergedExpressions; - } else { - $encodedQuery->{$field} = $this->encodeIfSupported($expression); - } - } - - $result[] = $encodedQuery; - } - - return $this->wrap($value, $result); - } - // The generic but incomplete encoding code switch ($value::ENCODE) { case Encode::Single: @@ -116,24 +91,24 @@ public function encode($value): stdClass|array|string throw new LogicException(sprintf('Class "%s" does not have a valid ENCODE constant.', $value::class)); } - private function encodeAsArray(ExpressionInterface|StageInterface $value): stdClass + private function encodeAsArray(ExpressionInterface|StageInterface|QueryInterface $value): stdClass { $result = []; /** @var mixed $val */ foreach (get_object_vars($value) as $val) { - $result[] = $this->encodeIfSupported($val); + $result[] = $this->recursiveEncode($val); } return $this->wrap($value, $result); } - private function encodeAsObject(ExpressionInterface|StageInterface $value): stdClass + private function encodeAsObject(ExpressionInterface|StageInterface|QueryInterface $value): stdClass { $result = new stdClass(); /** @var mixed $val */ foreach (get_object_vars($value) as $key => $val) { /** @var mixed $val */ - $val = $this->encodeIfSupported($val); + $val = $this->recursiveEncode($val); if ($val !== Optional::Undefined) { $result->{$key} = $val; } @@ -142,31 +117,53 @@ private function encodeAsObject(ExpressionInterface|StageInterface $value): stdC return $this->wrap($value, $result); } - private function encodeAsSingle(ExpressionInterface|StageInterface $value): stdClass + private function encodeAsSingle(ExpressionInterface|StageInterface|QueryInterface $value): stdClass { $result = []; /** @var mixed $val */ foreach (get_object_vars($value) as $val) { - $result = $this->encodeIfSupported($val); + $result = $this->recursiveEncode($val); break; } return $this->wrap($value, $result); } - private function encodeAsGroup(ExpressionInterface|StageInterface $value): stdClass + /** + * $group stage have a specific encoding because the _id argument is required and others are variadic + */ + private function encodeAsGroup(GroupStage $value): stdClass { $result = new stdClass(); - $result->_id = $this->encodeIfSupported($value->_id); - // Specific: fields are encoded as a map of properties to their values at the top level as _id - foreach ($value->fields ?? [] as $key => $val) { - $result->{$key} = $this->encodeIfSupported($val); + $result->_id = $this->recursiveEncode($value->_id); + // Specific to $group: fields are encoded as a map of properties to their values at the top level as _id + foreach ($value->field ?? [] as $key => $val) { + $result->{$key} = $this->recursiveEncode($val); } return $this->wrap($value, $result); } - private function wrap(ExpressionInterface|StageInterface $value, mixed $result): stdClass + private function recursiveEncode(mixed $value): mixed + { + if (is_array($value)) { + foreach ($value as $key => $val) { + $value[$key] = $this->recursiveEncode($val); + } + + return $value; + } + + if ($value instanceof stdClass) { + foreach (get_object_vars($value) as $key => $val) { + $value->{$key} = $this->recursiveEncode($val); + } + } + + return $this->encodeIfSupported($value); + } + + private function wrap(ExpressionInterface|StageInterface|QueryInterface $value, mixed $result): stdClass { $object = new stdClass(); $object->{$value::NAME} = $result; diff --git a/src/Builder/Query.php b/src/Builder/Query.php index 58afd1de7..1d0ac016b 100644 --- a/src/Builder/Query.php +++ b/src/Builder/Query.php @@ -58,6 +58,7 @@ use MongoDB\Builder\Query\TypeQuery; use MongoDB\Builder\Query\WhereQuery; use MongoDB\Model\BSONArray; +use stdClass; final class Query { @@ -70,9 +71,9 @@ public static function all(mixed ...$value): AllQuery } /** - * @param QueryInterface|array|object ...$expression + * @param QueryInterface|array|stdClass ...$expression */ - public static function and(array|object ...$expression): AndQuery + public static function and(QueryInterface|stdClass|array ...$expression): AndQuery { return new AndQuery(...$expression); } @@ -146,9 +147,9 @@ public static function comment(string $comment): CommentQuery } /** - * @param Document|Serializable|array|object $queries + * @param Document|Serializable|array|stdClass $queries */ - public static function elemMatch(array|object $queries): ElemMatchQuery + public static function elemMatch(Document|Serializable|stdClass|array $queries): ElemMatchQuery { return new ElemMatchQuery($queries); } @@ -178,17 +179,17 @@ public static function expr(mixed $expression): ExprQuery } /** - * @param array|object $geometry + * @param array|stdClass $geometry */ - public static function geoIntersects(array|object $geometry): GeoIntersectsQuery + public static function geoIntersects(stdClass|array $geometry): GeoIntersectsQuery { return new GeoIntersectsQuery($geometry); } /** - * @param array|object $geometry + * @param array|stdClass $geometry */ - public static function geoWithin(array|object $geometry): GeoWithinQuery + public static function geoWithin(stdClass|array $geometry): GeoWithinQuery { return new GeoWithinQuery($geometry); } @@ -196,12 +197,12 @@ public static function geoWithin(array|object $geometry): GeoWithinQuery /** * @param non-empty-string $type * @param BSONArray|PackedArray|list $coordinates - * @param Document|Serializable|array|object $crs + * @param Document|Serializable|array|stdClass $crs */ public static function geometry( string $type, PackedArray|BSONArray|array $coordinates, - array|object $crs, + Document|Serializable|stdClass|array $crs, ): GeometryQuery { return new GeometryQuery($type, $coordinates, $crs); @@ -232,9 +233,9 @@ public static function in(mixed $value): InQuery } /** - * @param Document|Serializable|array|object $schema + * @param Document|Serializable|array|stdClass $schema */ - public static function jsonSchema(array|object $schema): JsonSchemaQuery + public static function jsonSchema(Document|Serializable|stdClass|array $schema): JsonSchemaQuery { return new JsonSchemaQuery($schema); } @@ -299,12 +300,12 @@ public static function ne(mixed $value): NeQuery } /** - * @param array|object $geometry + * @param array|stdClass $geometry * @param Int64|Optional|int $maxDistance Distance in meters. Limits the results to those documents that are at most the specified distance from the center point. * @param Int64|Optional|int $minDistance Distance in meters. Limits the results to those documents that are at least the specified distance from the center point. */ public static function near( - array|object $geometry, + stdClass|array $geometry, Int64|Optional|int $maxDistance = Optional::Undefined, Int64|Optional|int $minDistance = Optional::Undefined, ): NearQuery @@ -313,12 +314,12 @@ public static function near( } /** - * @param array|object $geometry + * @param array|stdClass $geometry * @param Int64|Optional|int $maxDistance Distance in meters. * @param Int64|Optional|int $minDistance Distance in meters. Limits the results to those documents that are at least the specified distance from the center point. */ public static function nearSphere( - array|object $geometry, + stdClass|array $geometry, Int64|Optional|int $maxDistance = Optional::Undefined, Int64|Optional|int $minDistance = Optional::Undefined, ): NearSphereQuery @@ -335,25 +336,25 @@ public static function nin(mixed $value): NinQuery } /** - * @param QueryInterface|array|object ...$expression + * @param QueryInterface|array|stdClass ...$expression */ - public static function nor(array|object ...$expression): NorQuery + public static function nor(QueryInterface|stdClass|array ...$expression): NorQuery { return new NorQuery(...$expression); } /** - * @param QueryInterface|array|object $expression + * @param QueryInterface|array|stdClass $expression */ - public static function not(array|object $expression): NotQuery + public static function not(QueryInterface|stdClass|array $expression): NotQuery { return new NotQuery($expression); } /** - * @param QueryInterface|array|object ...$expression + * @param QueryInterface|array|stdClass ...$expression */ - public static function or(array|object ...$expression): OrQuery + public static function or(QueryInterface|stdClass|array ...$expression): OrQuery { return new OrQuery(...$expression); } diff --git a/src/Builder/Query/AllQuery.php b/src/Builder/Query/AllQuery.php index c89a12a6b..7ad4d6486 100644 --- a/src/Builder/Query/AllQuery.php +++ b/src/Builder/Query/AllQuery.php @@ -20,16 +20,16 @@ class AllQuery implements QueryInterface public array $value; /** - * @param mixed $value + * @param mixed ...$value */ public function __construct(mixed ...$value) { - if (! \array_is_list($value)) { - throw new \InvalidArgumentException('Expected $value arguments to be a list of mixed, named arguments are not supported'); - } if (\count($value) < 1) { throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $value, got %d.', 1, \count($value))); } + if (! \array_is_list($value)) { + throw new \InvalidArgumentException('Expected $value arguments to be a list of mixed, named arguments are not supported'); + } $this->value = $value; } } diff --git a/src/Builder/Query/AndQuery.php b/src/Builder/Query/AndQuery.php index 0bac412ae..988fec753 100644 --- a/src/Builder/Query/AndQuery.php +++ b/src/Builder/Query/AndQuery.php @@ -7,6 +7,7 @@ namespace MongoDB\Builder\Query; use MongoDB\Builder\Encode; +use stdClass; class AndQuery implements QueryInterface { @@ -15,21 +16,21 @@ class AndQuery implements QueryInterface /** * @no-named-arguments - * @param list ...$expression + * @param list ...$expression */ public array $expression; /** - * @param QueryInterface|array|object $expression + * @param QueryInterface|array|stdClass ...$expression */ - public function __construct(array|object ...$expression) + public function __construct(QueryInterface|stdClass|array ...$expression) { - if (! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression arguments to be a list of QueryInterface|array|object, named arguments are not supported'); - } if (\count($expression) < 1) { throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); } + if (! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression arguments to be a list of QueryInterface|array|stdClass, named arguments are not supported'); + } $this->expression = $expression; } } diff --git a/src/Builder/Query/ElemMatchQuery.php b/src/Builder/Query/ElemMatchQuery.php index c3c21f014..0fe3ea391 100644 --- a/src/Builder/Query/ElemMatchQuery.php +++ b/src/Builder/Query/ElemMatchQuery.php @@ -9,19 +9,20 @@ use MongoDB\BSON\Document; use MongoDB\BSON\Serializable; use MongoDB\Builder\Encode; +use stdClass; class ElemMatchQuery implements QueryInterface { public const NAME = '$elemMatch'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param Document|Serializable|array|object $queries */ - public array|object $queries; + /** @param Document|Serializable|array|stdClass $queries */ + public Document|Serializable|stdClass|array $queries; /** - * @param Document|Serializable|array|object $queries + * @param Document|Serializable|array|stdClass $queries */ - public function __construct(array|object $queries) + public function __construct(Document|Serializable|stdClass|array $queries) { $this->queries = $queries; } diff --git a/src/Builder/Query/GeoIntersectsQuery.php b/src/Builder/Query/GeoIntersectsQuery.php index 5f3dc9474..9a2b41a6e 100644 --- a/src/Builder/Query/GeoIntersectsQuery.php +++ b/src/Builder/Query/GeoIntersectsQuery.php @@ -7,19 +7,20 @@ namespace MongoDB\Builder\Query; use MongoDB\Builder\Encode; +use stdClass; class GeoIntersectsQuery implements QueryInterface { public const NAME = '$geoIntersects'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param array|object $geometry */ - public array|object $geometry; + /** @param array|stdClass $geometry */ + public stdClass|array $geometry; /** - * @param array|object $geometry + * @param array|stdClass $geometry */ - public function __construct(array|object $geometry) + public function __construct(stdClass|array $geometry) { $this->geometry = $geometry; } diff --git a/src/Builder/Query/GeoWithinQuery.php b/src/Builder/Query/GeoWithinQuery.php index 3815ca29f..85a80a272 100644 --- a/src/Builder/Query/GeoWithinQuery.php +++ b/src/Builder/Query/GeoWithinQuery.php @@ -7,19 +7,20 @@ namespace MongoDB\Builder\Query; use MongoDB\Builder\Encode; +use stdClass; class GeoWithinQuery implements QueryInterface { public const NAME = '$geoWithin'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param array|object $geometry */ - public array|object $geometry; + /** @param array|stdClass $geometry */ + public stdClass|array $geometry; /** - * @param array|object $geometry + * @param array|stdClass $geometry */ - public function __construct(array|object $geometry) + public function __construct(stdClass|array $geometry) { $this->geometry = $geometry; } diff --git a/src/Builder/Query/GeometryQuery.php b/src/Builder/Query/GeometryQuery.php index 1441a37dc..eebc715bb 100644 --- a/src/Builder/Query/GeometryQuery.php +++ b/src/Builder/Query/GeometryQuery.php @@ -12,6 +12,7 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Model\BSONArray; +use stdClass; class GeometryQuery implements ExpressionInterface { @@ -24,16 +25,19 @@ class GeometryQuery implements ExpressionInterface /** @param BSONArray|PackedArray|list $coordinates */ public PackedArray|BSONArray|array $coordinates; - /** @param Document|Serializable|array|object $crs */ - public array|object $crs; + /** @param Document|Serializable|array|stdClass $crs */ + public Document|Serializable|stdClass|array $crs; /** * @param non-empty-string $type * @param BSONArray|PackedArray|list $coordinates - * @param Document|Serializable|array|object $crs + * @param Document|Serializable|array|stdClass $crs */ - public function __construct(string $type, PackedArray|BSONArray|array $coordinates, array|object $crs) - { + public function __construct( + string $type, + PackedArray|BSONArray|array $coordinates, + Document|Serializable|stdClass|array $crs, + ) { $this->type = $type; if (\is_array($coordinates) && ! \array_is_list($coordinates)) { throw new \InvalidArgumentException('Expected $coordinates argument to be a list, got an associative array.'); diff --git a/src/Builder/Query/JsonSchemaQuery.php b/src/Builder/Query/JsonSchemaQuery.php index 9a9ac54d2..145bafc9c 100644 --- a/src/Builder/Query/JsonSchemaQuery.php +++ b/src/Builder/Query/JsonSchemaQuery.php @@ -9,19 +9,20 @@ use MongoDB\BSON\Document; use MongoDB\BSON\Serializable; use MongoDB\Builder\Encode; +use stdClass; class JsonSchemaQuery implements QueryInterface { public const NAME = '$jsonSchema'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param Document|Serializable|array|object $schema */ - public array|object $schema; + /** @param Document|Serializable|array|stdClass $schema */ + public Document|Serializable|stdClass|array $schema; /** - * @param Document|Serializable|array|object $schema + * @param Document|Serializable|array|stdClass $schema */ - public function __construct(array|object $schema) + public function __construct(Document|Serializable|stdClass|array $schema) { $this->schema = $schema; } diff --git a/src/Builder/Query/NearQuery.php b/src/Builder/Query/NearQuery.php index e385f82ac..0cdf53988 100644 --- a/src/Builder/Query/NearQuery.php +++ b/src/Builder/Query/NearQuery.php @@ -9,14 +9,15 @@ use MongoDB\BSON\Int64; use MongoDB\Builder\Encode; use MongoDB\Builder\Optional; +use stdClass; class NearQuery implements QueryInterface { public const NAME = '$near'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param array|object $geometry */ - public array|object $geometry; + /** @param array|stdClass $geometry */ + public stdClass|array $geometry; /** @param Int64|Optional|int $maxDistance Distance in meters. Limits the results to those documents that are at most the specified distance from the center point. */ public Int64|Optional|int $maxDistance; @@ -25,12 +26,12 @@ class NearQuery implements QueryInterface public Int64|Optional|int $minDistance; /** - * @param array|object $geometry + * @param array|stdClass $geometry * @param Int64|Optional|int $maxDistance Distance in meters. Limits the results to those documents that are at most the specified distance from the center point. * @param Int64|Optional|int $minDistance Distance in meters. Limits the results to those documents that are at least the specified distance from the center point. */ public function __construct( - array|object $geometry, + stdClass|array $geometry, Int64|Optional|int $maxDistance = Optional::Undefined, Int64|Optional|int $minDistance = Optional::Undefined, ) { diff --git a/src/Builder/Query/NearSphereQuery.php b/src/Builder/Query/NearSphereQuery.php index 1e2764104..e8f83e70c 100644 --- a/src/Builder/Query/NearSphereQuery.php +++ b/src/Builder/Query/NearSphereQuery.php @@ -9,14 +9,15 @@ use MongoDB\BSON\Int64; use MongoDB\Builder\Encode; use MongoDB\Builder\Optional; +use stdClass; class NearSphereQuery implements QueryInterface { public const NAME = '$nearSphere'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param array|object $geometry */ - public array|object $geometry; + /** @param array|stdClass $geometry */ + public stdClass|array $geometry; /** @param Int64|Optional|int $maxDistance Distance in meters. */ public Int64|Optional|int $maxDistance; @@ -25,12 +26,12 @@ class NearSphereQuery implements QueryInterface public Int64|Optional|int $minDistance; /** - * @param array|object $geometry + * @param array|stdClass $geometry * @param Int64|Optional|int $maxDistance Distance in meters. * @param Int64|Optional|int $minDistance Distance in meters. Limits the results to those documents that are at least the specified distance from the center point. */ public function __construct( - array|object $geometry, + stdClass|array $geometry, Int64|Optional|int $maxDistance = Optional::Undefined, Int64|Optional|int $minDistance = Optional::Undefined, ) { diff --git a/src/Builder/Query/NorQuery.php b/src/Builder/Query/NorQuery.php index 74e11249d..e296df466 100644 --- a/src/Builder/Query/NorQuery.php +++ b/src/Builder/Query/NorQuery.php @@ -7,6 +7,7 @@ namespace MongoDB\Builder\Query; use MongoDB\Builder\Encode; +use stdClass; class NorQuery implements QueryInterface { @@ -15,21 +16,21 @@ class NorQuery implements QueryInterface /** * @no-named-arguments - * @param list ...$expression + * @param list ...$expression */ public array $expression; /** - * @param QueryInterface|array|object $expression + * @param QueryInterface|array|stdClass ...$expression */ - public function __construct(array|object ...$expression) + public function __construct(QueryInterface|stdClass|array ...$expression) { - if (! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression arguments to be a list of QueryInterface|array|object, named arguments are not supported'); - } if (\count($expression) < 1) { throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); } + if (! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression arguments to be a list of QueryInterface|array|stdClass, named arguments are not supported'); + } $this->expression = $expression; } } diff --git a/src/Builder/Query/NotQuery.php b/src/Builder/Query/NotQuery.php index 84a3ad0d6..3f723f919 100644 --- a/src/Builder/Query/NotQuery.php +++ b/src/Builder/Query/NotQuery.php @@ -7,19 +7,20 @@ namespace MongoDB\Builder\Query; use MongoDB\Builder\Encode; +use stdClass; class NotQuery implements QueryInterface { public const NAME = '$not'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param QueryInterface|array|object $expression */ - public array|object $expression; + /** @param QueryInterface|array|stdClass $expression */ + public QueryInterface|stdClass|array $expression; /** - * @param QueryInterface|array|object $expression + * @param QueryInterface|array|stdClass $expression */ - public function __construct(array|object $expression) + public function __construct(QueryInterface|stdClass|array $expression) { $this->expression = $expression; } diff --git a/src/Builder/Query/OrQuery.php b/src/Builder/Query/OrQuery.php index b4effdf2b..02af84ce7 100644 --- a/src/Builder/Query/OrQuery.php +++ b/src/Builder/Query/OrQuery.php @@ -7,6 +7,7 @@ namespace MongoDB\Builder\Query; use MongoDB\Builder\Encode; +use stdClass; class OrQuery implements QueryInterface { @@ -15,21 +16,21 @@ class OrQuery implements QueryInterface /** * @no-named-arguments - * @param list ...$expression + * @param list ...$expression */ public array $expression; /** - * @param QueryInterface|array|object $expression + * @param QueryInterface|array|stdClass ...$expression */ - public function __construct(array|object ...$expression) + public function __construct(QueryInterface|stdClass|array ...$expression) { - if (! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression arguments to be a list of QueryInterface|array|object, named arguments are not supported'); - } if (\count($expression) < 1) { throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); } + if (! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression arguments to be a list of QueryInterface|array|stdClass, named arguments are not supported'); + } $this->expression = $expression; } } diff --git a/src/Builder/Stage.php b/src/Builder/Stage.php index 4f561ba9a..d080e72bd 100644 --- a/src/Builder/Stage.php +++ b/src/Builder/Stage.php @@ -61,6 +61,7 @@ use MongoDB\Builder\Stage\UnsetStage; use MongoDB\Builder\Stage\UnwindStage; use MongoDB\Model\BSONArray; +use stdClass; final class Stage { @@ -81,7 +82,7 @@ public static function addFields(mixed ...$expression): AddFieldsStage * 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. - * @param Document|Optional|Serializable|array|object $output 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. + * @param Document|Optional|Serializable|array|stdClass $output 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. */ @@ -89,7 +90,7 @@ public static function bucket( mixed $groupBy, PackedArray|BSONArray|array $boundaries, mixed $default = Optional::Undefined, - array|object $output = Optional::Undefined, + Document|Serializable|Optional|stdClass|array $output = Optional::Undefined, ): BucketStage { return new BucketStage($groupBy, $boundaries, $default, $output); @@ -98,7 +99,7 @@ public static function bucket( /** * @param ExpressionInterface|mixed $groupBy An expression to group documents by. To specify a field path, prefix the field name with a dollar sign $ and enclose it in quotes. * @param Int64|int $buckets A positive 32-bit integer that specifies the number of buckets into which input documents are grouped. - * @param Document|Optional|Serializable|array|object $output 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. + * @param Document|Optional|Serializable|array|stdClass $output 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. * @param Optional|non-empty-string $granularity 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. @@ -106,7 +107,7 @@ public static function bucket( public static function bucketAuto( mixed $groupBy, Int64|int $buckets, - array|object $output = Optional::Undefined, + Document|Serializable|Optional|stdClass|array $output = Optional::Undefined, Optional|string $granularity = Optional::Undefined, ): BucketAutoStage { @@ -120,7 +121,7 @@ public static function bucketAuto( * @param Int64|Optional|int $resumeAfter Specifies a resume token as the logical starting point for the change stream. Cannot be used with startAfter or startAtOperationTime fields. * @param Optional|bool $showExpandedEvents Specifies whether to include additional change events, such as such as DDL and index operations. * New in version 6.0. - * @param Document|Optional|Serializable|array|object $startAfter Specifies a resume token as the logical starting point for the change stream. Cannot be used with resumeAfter or startAtOperationTime fields. + * @param Document|Optional|Serializable|array|stdClass $startAfter Specifies a resume token as the logical starting point for the change stream. Cannot be used with resumeAfter or startAtOperationTime fields. * @param Optional|int $startAtOperationTime Specifies a time as the logical starting point for the change stream. Cannot be used with resumeAfter or startAfter fields. */ public static function changeStream( @@ -129,7 +130,7 @@ public static function changeStream( Optional|string $fullDocumentBeforeChange = Optional::Undefined, Int64|Optional|int $resumeAfter = Optional::Undefined, Optional|bool $showExpandedEvents = Optional::Undefined, - array|object $startAfter = Optional::Undefined, + Document|Serializable|Optional|stdClass|array $startAfter = Optional::Undefined, Optional|int $startAtOperationTime = Optional::Undefined, ): ChangeStreamStage { @@ -142,9 +143,9 @@ public static function changeStreamSplitLargeEvent(): ChangeStreamSplitLargeEven } /** - * @param Document|Serializable|array|object $config + * @param Document|Serializable|array|stdClass $config */ - public static function collStats(array|object $config): CollStatsStage + public static function collStats(Document|Serializable|stdClass|array $config): CollStatsStage { return new CollStatsStage($config); } @@ -166,12 +167,12 @@ public static function currentOp(): CurrentOpStage * @param FieldPath|non-empty-string $field 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. - * @param array|object $range Specification for range based densification. + * @param array|stdClass $range Specification for range based densification. * @param BSONArray|Optional|PackedArray|list $partitionByFields The field(s) that will be used as the partition keys. */ public static function densify( FieldPath|string $field, - array|object $range, + stdClass|array $range, PackedArray|Optional|BSONArray|array $partitionByFields = Optional::Undefined, ): DensifyStage { @@ -199,21 +200,21 @@ public static function facet(Pipeline|array ...$facet): FacetStage } /** - * @param Document|Serializable|array|object $output Specifies an object containing each field for which to fill missing values. You can specify multiple fields in the output object. + * @param Document|Serializable|array|stdClass $output 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. - * @param Document|Optional|Serializable|array|non-empty-string|object $partitionBy Specifies an expression to group the documents. In the $fill stage, a group of documents is known as a partition. + * @param Document|Optional|Serializable|array|non-empty-string|stdClass $partitionBy 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. * @param BSONArray|Optional|PackedArray|list $partitionByFields 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. - * @param Optional|array|object $sortBy Specifies the field or fields to sort the documents within each partition. Uses the same syntax as the $sort stage. + * @param Optional|array|stdClass $sortBy Specifies the field or fields to sort the documents within each partition. Uses the same syntax as the $sort stage. */ public static function fill( - array|object $output, - array|object|string $partitionBy = Optional::Undefined, + Document|Serializable|stdClass|array $output, + Document|Serializable|Optional|stdClass|array|string $partitionBy = Optional::Undefined, PackedArray|Optional|BSONArray|array $partitionByFields = Optional::Undefined, - array|object $sortBy = Optional::Undefined, + Optional|stdClass|array $sortBy = Optional::Undefined, ): FillStage { return new FillStage($output, $partitionBy, $partitionByFields, $sortBy); @@ -221,7 +222,7 @@ public static function fill( /** * @param non-empty-string $distanceField The output field that contains the calculated distance. To specify a field within an embedded document, use dot notation. - * @param array|object $near The point for which to find the closest documents. + * @param array|stdClass $near The point for which to find the closest documents. * @param Decimal128|Int64|Optional|float|int $distanceMultiplier 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. * @param Optional|non-empty-string $includeLocs 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. * @param Optional|non-empty-string $key Specify the geospatial indexed field to use when calculating the distance. @@ -229,7 +230,7 @@ public static function fill( * Specify the distance in meters if the specified point is GeoJSON and in radians if the specified point is legacy coordinate pairs. * @param Decimal128|Int64|Optional|float|int $minDistance 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. - * @param Optional|QueryInterface|array|object $query imits the results to the documents that match the query. The query syntax is the usual MongoDB read operation query syntax. + * @param Optional|QueryInterface|array|stdClass $query imits 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. * @param Optional|bool $spherical Determines how MongoDB calculates the distance between two points: * - When true, MongoDB uses $nearSphere semantics and calculates distances using spherical geometry. @@ -238,13 +239,13 @@ public static function fill( */ public static function geoNear( string $distanceField, - array|object $near, + stdClass|array $near, Decimal128|Int64|Optional|float|int $distanceMultiplier = Optional::Undefined, Optional|string $includeLocs = Optional::Undefined, Optional|string $key = Optional::Undefined, Decimal128|Int64|Optional|float|int $maxDistance = Optional::Undefined, Decimal128|Int64|Optional|float|int $minDistance = Optional::Undefined, - array|object $query = Optional::Undefined, + Optional|QueryInterface|stdClass|array $query = Optional::Undefined, Optional|bool $spherical = Optional::Undefined, ): GeoNearStage { @@ -260,7 +261,7 @@ public static function geoNear( * @param non-empty-string $as Name of the array field added to each output document. Contains the documents traversed in the $graphLookup stage to reach the document. * @param Int64|Optional|int $maxDepth Non-negative integral number specifying the maximum recursion depth. * @param Optional|non-empty-string $depthField 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. - * @param Optional|QueryInterface|array|object $restrictSearchWithMatch A document specifying additional conditions for the recursive search. The syntax is identical to query filter syntax. + * @param Optional|QueryInterface|array|stdClass $restrictSearchWithMatch A document specifying additional conditions for the recursive search. The syntax is identical to query filter syntax. */ public static function graphLookup( string $from, @@ -270,7 +271,7 @@ public static function graphLookup( string $as, Int64|Optional|int $maxDepth = Optional::Undefined, Optional|string $depthField = Optional::Undefined, - array|object $restrictSearchWithMatch = Optional::Undefined, + Optional|QueryInterface|stdClass|array $restrictSearchWithMatch = Optional::Undefined, ): GraphLookupStage { return new GraphLookupStage($from, $startWith, $connectFromField, $connectToField, $as, $maxDepth, $depthField, $restrictSearchWithMatch); @@ -351,7 +352,7 @@ public static function listSessions( * Starting in MongoDB 5.1, the collection specified in the from parameter can be sharded. * @param Optional|non-empty-string $localField 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. * @param Optional|non-empty-string $foreignField 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. - * @param Document|Optional|Serializable|array|object $let 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. + * @param Document|Optional|Serializable|array|stdClass $let 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. * @param Optional|Pipeline|array $pipeline 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 $mergestage. 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. @@ -361,7 +362,7 @@ public static function lookup( Optional|string $from = Optional::Undefined, Optional|string $localField = Optional::Undefined, Optional|string $foreignField = Optional::Undefined, - array|object $let = Optional::Undefined, + Document|Serializable|Optional|stdClass|array $let = Optional::Undefined, Optional|Pipeline|array $pipeline = Optional::Undefined, ): LookupStage { @@ -369,24 +370,24 @@ public static function lookup( } /** - * @param QueryInterface|array|object ...$query + * @param QueryInterface|array|stdClass $query */ - public static function match(array|object ...$query): MatchStage + public static function match(QueryInterface|stdClass|array $query): MatchStage { - return new MatchStage(...$query); + return new MatchStage($query); } /** - * @param array|non-empty-string|object $into The output collection. + * @param array|non-empty-string|stdClass $into The output collection. * @param BSONArray|Optional|PackedArray|list|non-empty-string $on 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. - * @param Document|Optional|Serializable|array|object $let Specifies variables for use in the whenMatched pipeline. + * @param Document|Optional|Serializable|array|stdClass $let Specifies variables for use in the whenMatched pipeline. * @param Optional|non-empty-string $whenMatched 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). * @param Optional|non-empty-string $whenNotMatched The behavior of $merge if a result document does not match an existing document in the out collection. */ public static function merge( - array|object|string $into, + stdClass|array|string $into, PackedArray|Optional|BSONArray|array|string $on = Optional::Undefined, - array|object $let = Optional::Undefined, + Document|Serializable|Optional|stdClass|array $let = Optional::Undefined, Optional|string $whenMatched = Optional::Undefined, Optional|string $whenNotMatched = Optional::Undefined, ): MergeStage @@ -397,9 +398,9 @@ public static function merge( /** * @param non-empty-string $db Target collection name to write documents from $out to. * @param non-empty-string $coll Target database name to write documents from $out to. - * @param Document|Serializable|array|object $timeseries If set, the aggregation stage will use these options to create or replace a time-series collection in the given namespace. + * @param Document|Serializable|array|stdClass $timeseries If set, the aggregation stage will use these options to create or replace a time-series collection in the given namespace. */ - public static function out(string $db, string $coll, array|object $timeseries): OutStage + public static function out(string $db, string $coll, Document|Serializable|stdClass|array $timeseries): OutStage { return new OutStage($db, $coll, $timeseries); } @@ -426,17 +427,21 @@ public static function redact(mixed $expression): RedactStage } /** - * @param Document|ResolvesToObject|Serializable|array|object $newRoot + * @param Document|ResolvesToObject|Serializable|array|stdClass $newRoot */ - public static function replaceRoot(array|object $newRoot): ReplaceRootStage + public static function replaceRoot( + Document|Serializable|ResolvesToObject|stdClass|array $newRoot, + ): ReplaceRootStage { return new ReplaceRootStage($newRoot); } /** - * @param Document|ResolvesToObject|Serializable|array|object $expression + * @param Document|ResolvesToObject|Serializable|array|stdClass $expression */ - public static function replaceWith(array|object $expression): ReplaceWithStage + public static function replaceWith( + Document|Serializable|ResolvesToObject|stdClass|array $expression, + ): ReplaceWithStage { return new ReplaceWithStage($expression); } @@ -450,17 +455,17 @@ public static function sample(Int64|int $size): SampleStage } /** - * @param Document|Serializable|array|object $search + * @param Document|Serializable|array|stdClass $search */ - public static function search(array|object $search): SearchStage + public static function search(Document|Serializable|stdClass|array $search): SearchStage { return new SearchStage($search); } /** - * @param Document|Serializable|array|object $meta + * @param Document|Serializable|array|stdClass $meta */ - public static function searchMeta(array|object $meta): SearchMetaStage + public static function searchMeta(Document|Serializable|stdClass|array $meta): SearchMetaStage { return new SearchMetaStage($meta); } @@ -475,16 +480,16 @@ public static function set(mixed ...$field): SetStage /** * @param ExpressionInterface|mixed $partitionBy 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. - * @param array|object $sortBy Specifies the field(s) to sort the documents by in the partition. Uses the same syntax as the $sort stage. Default is no sorting. - * @param Document|Serializable|array|object $output 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. + * @param array|stdClass $sortBy Specifies the field(s) to sort the documents by in the partition. Uses the same syntax as the $sort stage. Default is no sorting. + * @param Document|Serializable|array|stdClass $output 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. - * @param Optional|array|object $window Specifies the window boundaries and parameters. Window boundaries are inclusive. Default is an unbounded window, which includes all documents in the partition. + * @param Optional|array|stdClass $window Specifies the window boundaries and parameters. Window boundaries are inclusive. Default is an unbounded window, which includes all documents in the partition. */ public static function setWindowFields( mixed $partitionBy, - array|object $sortBy, - array|object $output, - array|object $window = Optional::Undefined, + stdClass|array $sortBy, + Document|Serializable|stdClass|array $output, + Optional|stdClass|array $window = Optional::Undefined, ): SetWindowFieldsStage { return new SetWindowFieldsStage($partitionBy, $sortBy, $output, $window); @@ -504,9 +509,9 @@ public static function skip(Int64|int $skip): SkipStage } /** - * @param array|object $sort + * @param array|stdClass $sort */ - public static function sort(array|object $sort): SortStage + public static function sort(stdClass|array $sort): SortStage { return new SortStage($sort); } diff --git a/src/Builder/Stage/AddFieldsStage.php b/src/Builder/Stage/AddFieldsStage.php index 69650465b..557520cce 100644 --- a/src/Builder/Stage/AddFieldsStage.php +++ b/src/Builder/Stage/AddFieldsStage.php @@ -8,28 +8,30 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ExpressionInterface; +use stdClass; class AddFieldsStage implements StageInterface { public const NAME = '$addFields'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param array ...$expression Specify the name of each field to add and set its value to an aggregation expression or an empty object. */ - public array $expression; + /** @param stdClass ...$expression Specify the name of each field to add and set its value to an aggregation expression or an empty object. */ + public stdClass $expression; /** - * @param ExpressionInterface|mixed $expression Specify the name of each field to add and set its value to an aggregation expression or an empty object. + * @param ExpressionInterface|mixed ...$expression Specify the name of each field to add and set its value to an aggregation expression or an empty object. */ public function __construct(mixed ...$expression) { + if (\count($expression) < 1) { + throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); + } foreach($expression as $key => $value) { if (! \is_string($key)) { throw new \InvalidArgumentException('Expected $expression arguments to be a map of ExpressionInterface|mixed, named arguments (:) or array unpacking ...[\'\' => ] must be used'); } } - if (\count($expression) < 1) { - throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); - } + $expression = (object) $expression; $this->expression = $expression; } } diff --git a/src/Builder/Stage/BucketAutoStage.php b/src/Builder/Stage/BucketAutoStage.php index dca89e9fc..3bfba51b4 100644 --- a/src/Builder/Stage/BucketAutoStage.php +++ b/src/Builder/Stage/BucketAutoStage.php @@ -12,6 +12,7 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Optional; +use stdClass; class BucketAutoStage implements StageInterface { @@ -25,10 +26,10 @@ class BucketAutoStage implements StageInterface public Int64|int $buckets; /** - * @param Document|Optional|Serializable|array|object $output 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. + * @param Document|Optional|Serializable|array|stdClass $output 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. */ - public array|object $output; + public Document|Serializable|Optional|stdClass|array $output; /** * @param Optional|non-empty-string $granularity 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. @@ -39,7 +40,7 @@ class BucketAutoStage implements StageInterface /** * @param ExpressionInterface|mixed $groupBy An expression to group documents by. To specify a field path, prefix the field name with a dollar sign $ and enclose it in quotes. * @param Int64|int $buckets A positive 32-bit integer that specifies the number of buckets into which input documents are grouped. - * @param Document|Optional|Serializable|array|object $output 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. + * @param Document|Optional|Serializable|array|stdClass $output 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. * @param Optional|non-empty-string $granularity 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. @@ -47,7 +48,7 @@ class BucketAutoStage implements StageInterface public function __construct( mixed $groupBy, Int64|int $buckets, - array|object $output = Optional::Undefined, + Document|Serializable|Optional|stdClass|array $output = Optional::Undefined, Optional|string $granularity = Optional::Undefined, ) { $this->groupBy = $groupBy; diff --git a/src/Builder/Stage/BucketStage.php b/src/Builder/Stage/BucketStage.php index 6adcb06d0..17b5b3bea 100644 --- a/src/Builder/Stage/BucketStage.php +++ b/src/Builder/Stage/BucketStage.php @@ -14,6 +14,7 @@ use MongoDB\Builder\Expression\FieldPath; use MongoDB\Builder\Optional; use MongoDB\Model\BSONArray; +use stdClass; class BucketStage implements StageInterface { @@ -41,11 +42,11 @@ class BucketStage implements StageInterface public mixed $default; /** - * @param Document|Optional|Serializable|array|object $output 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. + * @param Document|Optional|Serializable|array|stdClass $output 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. */ - public array|object $output; + public Document|Serializable|Optional|stdClass|array $output; /** * @param ExpressionInterface|FieldPath|mixed|non-empty-string $groupBy An expression to group documents by. To specify a field path, prefix the field name with a dollar sign $ and enclose it in quotes. @@ -56,7 +57,7 @@ class BucketStage implements StageInterface * 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. - * @param Document|Optional|Serializable|array|object $output 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. + * @param Document|Optional|Serializable|array|stdClass $output 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. */ @@ -64,7 +65,7 @@ public function __construct( mixed $groupBy, PackedArray|BSONArray|array $boundaries, mixed $default = Optional::Undefined, - array|object $output = Optional::Undefined, + Document|Serializable|Optional|stdClass|array $output = Optional::Undefined, ) { $this->groupBy = $groupBy; if (\is_array($boundaries) && ! \array_is_list($boundaries)) { diff --git a/src/Builder/Stage/ChangeStreamStage.php b/src/Builder/Stage/ChangeStreamStage.php index b25642af4..7db401969 100644 --- a/src/Builder/Stage/ChangeStreamStage.php +++ b/src/Builder/Stage/ChangeStreamStage.php @@ -11,6 +11,7 @@ use MongoDB\BSON\Serializable; use MongoDB\Builder\Encode; use MongoDB\Builder\Optional; +use stdClass; class ChangeStreamStage implements StageInterface { @@ -35,8 +36,8 @@ class ChangeStreamStage implements StageInterface */ public Optional|bool $showExpandedEvents; - /** @param Document|Optional|Serializable|array|object $startAfter Specifies a resume token as the logical starting point for the change stream. Cannot be used with resumeAfter or startAtOperationTime fields. */ - public array|object $startAfter; + /** @param Document|Optional|Serializable|array|stdClass $startAfter Specifies a resume token as the logical starting point for the change stream. Cannot be used with resumeAfter or startAtOperationTime fields. */ + public Document|Serializable|Optional|stdClass|array $startAfter; /** @param Optional|int $startAtOperationTime Specifies a time as the logical starting point for the change stream. Cannot be used with resumeAfter or startAfter fields. */ public Optional|int $startAtOperationTime; @@ -48,7 +49,7 @@ class ChangeStreamStage implements StageInterface * @param Int64|Optional|int $resumeAfter Specifies a resume token as the logical starting point for the change stream. Cannot be used with startAfter or startAtOperationTime fields. * @param Optional|bool $showExpandedEvents Specifies whether to include additional change events, such as such as DDL and index operations. * New in version 6.0. - * @param Document|Optional|Serializable|array|object $startAfter Specifies a resume token as the logical starting point for the change stream. Cannot be used with resumeAfter or startAtOperationTime fields. + * @param Document|Optional|Serializable|array|stdClass $startAfter Specifies a resume token as the logical starting point for the change stream. Cannot be used with resumeAfter or startAtOperationTime fields. * @param Optional|int $startAtOperationTime Specifies a time as the logical starting point for the change stream. Cannot be used with resumeAfter or startAfter fields. */ public function __construct( @@ -57,7 +58,7 @@ public function __construct( Optional|string $fullDocumentBeforeChange = Optional::Undefined, Int64|Optional|int $resumeAfter = Optional::Undefined, Optional|bool $showExpandedEvents = Optional::Undefined, - array|object $startAfter = Optional::Undefined, + Document|Serializable|Optional|stdClass|array $startAfter = Optional::Undefined, Optional|int $startAtOperationTime = Optional::Undefined, ) { $this->allChangesForCluster = $allChangesForCluster; diff --git a/src/Builder/Stage/CollStatsStage.php b/src/Builder/Stage/CollStatsStage.php index 92d2920ec..a007ed629 100644 --- a/src/Builder/Stage/CollStatsStage.php +++ b/src/Builder/Stage/CollStatsStage.php @@ -9,19 +9,20 @@ use MongoDB\BSON\Document; use MongoDB\BSON\Serializable; use MongoDB\Builder\Encode; +use stdClass; class CollStatsStage implements StageInterface { public const NAME = '$collStats'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param Document|Serializable|array|object $config */ - public array|object $config; + /** @param Document|Serializable|array|stdClass $config */ + public Document|Serializable|stdClass|array $config; /** - * @param Document|Serializable|array|object $config + * @param Document|Serializable|array|stdClass $config */ - public function __construct(array|object $config) + public function __construct(Document|Serializable|stdClass|array $config) { $this->config = $config; } diff --git a/src/Builder/Stage/DensifyStage.php b/src/Builder/Stage/DensifyStage.php index 4a46160bd..6868106aa 100644 --- a/src/Builder/Stage/DensifyStage.php +++ b/src/Builder/Stage/DensifyStage.php @@ -12,6 +12,7 @@ use MongoDB\Builder\Expression\FieldPath; use MongoDB\Builder\Optional; use MongoDB\Model\BSONArray; +use stdClass; class DensifyStage implements StageInterface { @@ -25,8 +26,8 @@ class DensifyStage implements StageInterface */ public FieldPath|string $field; - /** @param array|object $range Specification for range based densification. */ - public array|object $range; + /** @param array|stdClass $range Specification for range based densification. */ + public stdClass|array $range; /** @param BSONArray|Optional|PackedArray|list $partitionByFields The field(s) that will be used as the partition keys. */ public PackedArray|Optional|BSONArray|array $partitionByFields; @@ -35,12 +36,12 @@ class DensifyStage implements StageInterface * @param FieldPath|non-empty-string $field 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. - * @param array|object $range Specification for range based densification. + * @param array|stdClass $range Specification for range based densification. * @param BSONArray|Optional|PackedArray|list $partitionByFields The field(s) that will be used as the partition keys. */ public function __construct( FieldPath|string $field, - array|object $range, + stdClass|array $range, PackedArray|Optional|BSONArray|array $partitionByFields = Optional::Undefined, ) { $this->field = $field; diff --git a/src/Builder/Stage/FacetStage.php b/src/Builder/Stage/FacetStage.php index 78b21efac..88d4e2d6e 100644 --- a/src/Builder/Stage/FacetStage.php +++ b/src/Builder/Stage/FacetStage.php @@ -8,28 +8,30 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Pipeline; +use stdClass; class FacetStage implements StageInterface { public const NAME = '$facet'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param array ...$facet */ - public array $facet; + /** @param stdClass ...$facet */ + public stdClass $facet; /** - * @param Pipeline|array $facet + * @param Pipeline|array ...$facet */ public function __construct(Pipeline|array ...$facet) { + if (\count($facet) < 1) { + throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $facet, got %d.', 1, \count($facet))); + } foreach($facet as $key => $value) { if (! \is_string($key)) { throw new \InvalidArgumentException('Expected $facet arguments to be a map of Pipeline|array, named arguments (:) or array unpacking ...[\'\' => ] must be used'); } } - if (\count($facet) < 1) { - throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $facet, got %d.', 1, \count($facet))); - } + $facet = (object) $facet; $this->facet = $facet; } } diff --git a/src/Builder/Stage/FillStage.php b/src/Builder/Stage/FillStage.php index 6acc797ba..df285e3ee 100644 --- a/src/Builder/Stage/FillStage.php +++ b/src/Builder/Stage/FillStage.php @@ -13,6 +13,7 @@ use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Optional; use MongoDB\Model\BSONArray; +use stdClass; class FillStage implements StageInterface { @@ -20,17 +21,17 @@ class FillStage implements StageInterface public const ENCODE = \MongoDB\Builder\Encode::Object; /** - * @param Document|Serializable|array|object $output Specifies an object containing each field for which to fill missing values. You can specify multiple fields in the output object. + * @param Document|Serializable|array|stdClass $output 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. */ - public array|object $output; + public Document|Serializable|stdClass|array $output; /** - * @param Document|Optional|Serializable|array|non-empty-string|object $partitionBy Specifies an expression to group the documents. In the $fill stage, a group of documents is known as a partition. + * @param Document|Optional|Serializable|array|non-empty-string|stdClass $partitionBy 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. */ - public array|object|string $partitionBy; + public Document|Serializable|Optional|stdClass|array|string $partitionBy; /** * @param BSONArray|Optional|PackedArray|list $partitionByFields 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. @@ -39,25 +40,25 @@ class FillStage implements StageInterface */ public PackedArray|Optional|BSONArray|array $partitionByFields; - /** @param Optional|array|object $sortBy Specifies the field or fields to sort the documents within each partition. Uses the same syntax as the $sort stage. */ - public array|object $sortBy; + /** @param Optional|array|stdClass $sortBy Specifies the field or fields to sort the documents within each partition. Uses the same syntax as the $sort stage. */ + public Optional|stdClass|array $sortBy; /** - * @param Document|Serializable|array|object $output Specifies an object containing each field for which to fill missing values. You can specify multiple fields in the output object. + * @param Document|Serializable|array|stdClass $output 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. - * @param Document|Optional|Serializable|array|non-empty-string|object $partitionBy Specifies an expression to group the documents. In the $fill stage, a group of documents is known as a partition. + * @param Document|Optional|Serializable|array|non-empty-string|stdClass $partitionBy 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. * @param BSONArray|Optional|PackedArray|list $partitionByFields 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. - * @param Optional|array|object $sortBy Specifies the field or fields to sort the documents within each partition. Uses the same syntax as the $sort stage. + * @param Optional|array|stdClass $sortBy Specifies the field or fields to sort the documents within each partition. Uses the same syntax as the $sort stage. */ public function __construct( - array|object $output, - array|object|string $partitionBy = Optional::Undefined, + Document|Serializable|stdClass|array $output, + Document|Serializable|Optional|stdClass|array|string $partitionBy = Optional::Undefined, PackedArray|Optional|BSONArray|array $partitionByFields = Optional::Undefined, - array|object $sortBy = Optional::Undefined, + Optional|stdClass|array $sortBy = Optional::Undefined, ) { $this->output = $output; $this->partitionBy = $partitionBy; diff --git a/src/Builder/Stage/GeoNearStage.php b/src/Builder/Stage/GeoNearStage.php index f69b3be62..b1e9ac7b1 100644 --- a/src/Builder/Stage/GeoNearStage.php +++ b/src/Builder/Stage/GeoNearStage.php @@ -11,6 +11,7 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Optional; use MongoDB\Builder\Query\QueryInterface; +use stdClass; class GeoNearStage implements StageInterface { @@ -20,8 +21,8 @@ class GeoNearStage implements StageInterface /** @param non-empty-string $distanceField The output field that contains the calculated distance. To specify a field within an embedded document, use dot notation. */ public string $distanceField; - /** @param array|object $near The point for which to find the closest documents. */ - public array|object $near; + /** @param array|stdClass $near The point for which to find the closest documents. */ + public stdClass|array $near; /** @param Decimal128|Int64|Optional|float|int $distanceMultiplier 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. */ public Decimal128|Int64|Optional|float|int $distanceMultiplier; @@ -45,10 +46,10 @@ class GeoNearStage implements StageInterface public Decimal128|Int64|Optional|float|int $minDistance; /** - * @param Optional|QueryInterface|array|object $query imits the results to the documents that match the query. The query syntax is the usual MongoDB read operation query syntax. + * @param Optional|QueryInterface|array|stdClass $query imits 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. */ - public array|object $query; + public Optional|QueryInterface|stdClass|array $query; /** * @param Optional|bool $spherical Determines how MongoDB calculates the distance between two points: @@ -60,7 +61,7 @@ class GeoNearStage implements StageInterface /** * @param non-empty-string $distanceField The output field that contains the calculated distance. To specify a field within an embedded document, use dot notation. - * @param array|object $near The point for which to find the closest documents. + * @param array|stdClass $near The point for which to find the closest documents. * @param Decimal128|Int64|Optional|float|int $distanceMultiplier 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. * @param Optional|non-empty-string $includeLocs 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. * @param Optional|non-empty-string $key Specify the geospatial indexed field to use when calculating the distance. @@ -68,7 +69,7 @@ class GeoNearStage implements StageInterface * Specify the distance in meters if the specified point is GeoJSON and in radians if the specified point is legacy coordinate pairs. * @param Decimal128|Int64|Optional|float|int $minDistance 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. - * @param Optional|QueryInterface|array|object $query imits the results to the documents that match the query. The query syntax is the usual MongoDB read operation query syntax. + * @param Optional|QueryInterface|array|stdClass $query imits 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. * @param Optional|bool $spherical Determines how MongoDB calculates the distance between two points: * - When true, MongoDB uses $nearSphere semantics and calculates distances using spherical geometry. @@ -77,13 +78,13 @@ class GeoNearStage implements StageInterface */ public function __construct( string $distanceField, - array|object $near, + stdClass|array $near, Decimal128|Int64|Optional|float|int $distanceMultiplier = Optional::Undefined, Optional|string $includeLocs = Optional::Undefined, Optional|string $key = Optional::Undefined, Decimal128|Int64|Optional|float|int $maxDistance = Optional::Undefined, Decimal128|Int64|Optional|float|int $minDistance = Optional::Undefined, - array|object $query = Optional::Undefined, + Optional|QueryInterface|stdClass|array $query = Optional::Undefined, Optional|bool $spherical = Optional::Undefined, ) { $this->distanceField = $distanceField; diff --git a/src/Builder/Stage/GraphLookupStage.php b/src/Builder/Stage/GraphLookupStage.php index d13980a4f..d66ea99fc 100644 --- a/src/Builder/Stage/GraphLookupStage.php +++ b/src/Builder/Stage/GraphLookupStage.php @@ -13,6 +13,7 @@ use MongoDB\Builder\Optional; use MongoDB\Builder\Query\QueryInterface; use MongoDB\Model\BSONArray; +use stdClass; class GraphLookupStage implements StageInterface { @@ -43,8 +44,8 @@ class GraphLookupStage implements StageInterface /** @param Optional|non-empty-string $depthField 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. */ public Optional|string $depthField; - /** @param Optional|QueryInterface|array|object $restrictSearchWithMatch A document specifying additional conditions for the recursive search. The syntax is identical to query filter syntax. */ - public array|object $restrictSearchWithMatch; + /** @param Optional|QueryInterface|array|stdClass $restrictSearchWithMatch A document specifying additional conditions for the recursive search. The syntax is identical to query filter syntax. */ + public Optional|QueryInterface|stdClass|array $restrictSearchWithMatch; /** * @param non-empty-string $from 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. @@ -55,7 +56,7 @@ class GraphLookupStage implements StageInterface * @param non-empty-string $as Name of the array field added to each output document. Contains the documents traversed in the $graphLookup stage to reach the document. * @param Int64|Optional|int $maxDepth Non-negative integral number specifying the maximum recursion depth. * @param Optional|non-empty-string $depthField 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. - * @param Optional|QueryInterface|array|object $restrictSearchWithMatch A document specifying additional conditions for the recursive search. The syntax is identical to query filter syntax. + * @param Optional|QueryInterface|array|stdClass $restrictSearchWithMatch A document specifying additional conditions for the recursive search. The syntax is identical to query filter syntax. */ public function __construct( string $from, @@ -65,7 +66,7 @@ public function __construct( string $as, Int64|Optional|int $maxDepth = Optional::Undefined, Optional|string $depthField = Optional::Undefined, - array|object $restrictSearchWithMatch = Optional::Undefined, + Optional|QueryInterface|stdClass|array $restrictSearchWithMatch = Optional::Undefined, ) { $this->from = $from; if (\is_array($startWith) && ! \array_is_list($startWith)) { diff --git a/src/Builder/Stage/GroupStage.php b/src/Builder/Stage/GroupStage.php index 12a226abb..88270a438 100644 --- a/src/Builder/Stage/GroupStage.php +++ b/src/Builder/Stage/GroupStage.php @@ -9,6 +9,7 @@ use MongoDB\Builder\Aggregation\AccumulatorInterface; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ExpressionInterface; +use stdClass; class GroupStage implements StageInterface { @@ -18,24 +19,25 @@ class GroupStage implements StageInterface /** @param ExpressionInterface|mixed $_id 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. */ public mixed $_id; - /** @param array ...$field Computed using the accumulator operators. */ - public array $field; + /** @param stdClass ...$field Computed using the accumulator operators. */ + public stdClass $field; /** * @param ExpressionInterface|mixed $_id 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. - * @param AccumulatorInterface $field Computed using the accumulator operators. + * @param AccumulatorInterface ...$field Computed using the accumulator operators. */ public function __construct(mixed $_id, AccumulatorInterface ...$field) { $this->_id = $_id; + if (\count($field) < 1) { + throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $field, got %d.', 1, \count($field))); + } foreach($field as $key => $value) { if (! \is_string($key)) { throw new \InvalidArgumentException('Expected $field arguments to be a map of AccumulatorInterface, named arguments (:) or array unpacking ...[\'\' => ] must be used'); } } - if (\count($field) < 1) { - throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $field, got %d.', 1, \count($field))); - } + $field = (object) $field; $this->field = $field; } } diff --git a/src/Builder/Stage/LookupStage.php b/src/Builder/Stage/LookupStage.php index 06ab5c185..9081626b3 100644 --- a/src/Builder/Stage/LookupStage.php +++ b/src/Builder/Stage/LookupStage.php @@ -11,6 +11,7 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Optional; use MongoDB\Builder\Pipeline; +use stdClass; class LookupStage implements StageInterface { @@ -33,8 +34,8 @@ class LookupStage implements StageInterface /** @param Optional|non-empty-string $foreignField 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. */ public Optional|string $foreignField; - /** @param Document|Optional|Serializable|array|object $let 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. */ - public array|object $let; + /** @param Document|Optional|Serializable|array|stdClass $let 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. */ + public Document|Serializable|Optional|stdClass|array $let; /** * @param Optional|Pipeline|array $pipeline 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 []. @@ -50,7 +51,7 @@ class LookupStage implements StageInterface * Starting in MongoDB 5.1, the collection specified in the from parameter can be sharded. * @param Optional|non-empty-string $localField 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. * @param Optional|non-empty-string $foreignField 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. - * @param Document|Optional|Serializable|array|object $let 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. + * @param Document|Optional|Serializable|array|stdClass $let 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. * @param Optional|Pipeline|array $pipeline 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 $mergestage. 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. @@ -60,7 +61,7 @@ public function __construct( Optional|string $from = Optional::Undefined, Optional|string $localField = Optional::Undefined, Optional|string $foreignField = Optional::Undefined, - array|object $let = Optional::Undefined, + Document|Serializable|Optional|stdClass|array $let = Optional::Undefined, Optional|Pipeline|array $pipeline = Optional::Undefined, ) { $this->as = $as; diff --git a/src/Builder/Stage/MatchStage.php b/src/Builder/Stage/MatchStage.php index 387ba5817..f0a952768 100644 --- a/src/Builder/Stage/MatchStage.php +++ b/src/Builder/Stage/MatchStage.php @@ -8,28 +8,21 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Query\QueryInterface; +use stdClass; class MatchStage implements StageInterface { public const NAME = '$match'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param array ...$query */ - public array $query; + /** @param QueryInterface|array|stdClass $query */ + public QueryInterface|stdClass|array $query; /** - * @param QueryInterface|array|object $query + * @param QueryInterface|array|stdClass $query */ - public function __construct(array|object ...$query) + public function __construct(QueryInterface|stdClass|array $query) { - foreach($query as $key => $value) { - if (! \is_string($key)) { - throw new \InvalidArgumentException('Expected $query arguments to be a map of QueryInterface|array|object, named arguments (:) or array unpacking ...[\'\' => ] must be used'); - } - } - if (\count($query) < 1) { - throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $query, got %d.', 1, \count($query))); - } $this->query = $query; } } diff --git a/src/Builder/Stage/MergeStage.php b/src/Builder/Stage/MergeStage.php index 47bb952dd..b3efc8fc2 100644 --- a/src/Builder/Stage/MergeStage.php +++ b/src/Builder/Stage/MergeStage.php @@ -13,20 +13,21 @@ use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Optional; use MongoDB\Model\BSONArray; +use stdClass; class MergeStage implements StageInterface { public const NAME = '$merge'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param array|non-empty-string|object $into The output collection. */ - public array|object|string $into; + /** @param array|non-empty-string|stdClass $into The output collection. */ + public stdClass|array|string $into; /** @param BSONArray|Optional|PackedArray|list|non-empty-string $on 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. */ public PackedArray|Optional|BSONArray|array|string $on; - /** @param Document|Optional|Serializable|array|object $let Specifies variables for use in the whenMatched pipeline. */ - public array|object $let; + /** @param Document|Optional|Serializable|array|stdClass $let Specifies variables for use in the whenMatched pipeline. */ + public Document|Serializable|Optional|stdClass|array $let; /** @param Optional|non-empty-string $whenMatched 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). */ public Optional|string $whenMatched; @@ -35,16 +36,16 @@ class MergeStage implements StageInterface public Optional|string $whenNotMatched; /** - * @param array|non-empty-string|object $into The output collection. + * @param array|non-empty-string|stdClass $into The output collection. * @param BSONArray|Optional|PackedArray|list|non-empty-string $on 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. - * @param Document|Optional|Serializable|array|object $let Specifies variables for use in the whenMatched pipeline. + * @param Document|Optional|Serializable|array|stdClass $let Specifies variables for use in the whenMatched pipeline. * @param Optional|non-empty-string $whenMatched 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). * @param Optional|non-empty-string $whenNotMatched The behavior of $merge if a result document does not match an existing document in the out collection. */ public function __construct( - array|object|string $into, + stdClass|array|string $into, PackedArray|Optional|BSONArray|array|string $on = Optional::Undefined, - array|object $let = Optional::Undefined, + Document|Serializable|Optional|stdClass|array $let = Optional::Undefined, Optional|string $whenMatched = Optional::Undefined, Optional|string $whenNotMatched = Optional::Undefined, ) { diff --git a/src/Builder/Stage/OutStage.php b/src/Builder/Stage/OutStage.php index 45a865704..00b562e7d 100644 --- a/src/Builder/Stage/OutStage.php +++ b/src/Builder/Stage/OutStage.php @@ -9,6 +9,7 @@ use MongoDB\BSON\Document; use MongoDB\BSON\Serializable; use MongoDB\Builder\Encode; +use stdClass; class OutStage implements StageInterface { @@ -21,15 +22,15 @@ class OutStage implements StageInterface /** @param non-empty-string $coll Target database name to write documents from $out to. */ public string $coll; - /** @param Document|Serializable|array|object $timeseries If set, the aggregation stage will use these options to create or replace a time-series collection in the given namespace. */ - public array|object $timeseries; + /** @param Document|Serializable|array|stdClass $timeseries If set, the aggregation stage will use these options to create or replace a time-series collection in the given namespace. */ + public Document|Serializable|stdClass|array $timeseries; /** * @param non-empty-string $db Target collection name to write documents from $out to. * @param non-empty-string $coll Target database name to write documents from $out to. - * @param Document|Serializable|array|object $timeseries If set, the aggregation stage will use these options to create or replace a time-series collection in the given namespace. + * @param Document|Serializable|array|stdClass $timeseries If set, the aggregation stage will use these options to create or replace a time-series collection in the given namespace. */ - public function __construct(string $db, string $coll, array|object $timeseries) + public function __construct(string $db, string $coll, Document|Serializable|stdClass|array $timeseries) { $this->db = $db; $this->coll = $coll; diff --git a/src/Builder/Stage/ProjectStage.php b/src/Builder/Stage/ProjectStage.php index 6bf35ae39..e8950186f 100644 --- a/src/Builder/Stage/ProjectStage.php +++ b/src/Builder/Stage/ProjectStage.php @@ -9,28 +9,30 @@ use MongoDB\BSON\Int64; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ExpressionInterface; +use stdClass; class ProjectStage implements StageInterface { public const NAME = '$project'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param array ...$specification */ - public array $specification; + /** @param stdClass ...$specification */ + public stdClass $specification; /** - * @param ExpressionInterface|Int64|bool|int|mixed $specification + * @param ExpressionInterface|Int64|bool|int|mixed ...$specification */ public function __construct(mixed ...$specification) { + if (\count($specification) < 1) { + throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $specification, got %d.', 1, \count($specification))); + } foreach($specification as $key => $value) { if (! \is_string($key)) { throw new \InvalidArgumentException('Expected $specification arguments to be a map of ExpressionInterface|Int64|bool|int|mixed, named arguments (:) or array unpacking ...[\'\' => ] must be used'); } } - if (\count($specification) < 1) { - throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $specification, got %d.', 1, \count($specification))); - } + $specification = (object) $specification; $this->specification = $specification; } } diff --git a/src/Builder/Stage/ReplaceRootStage.php b/src/Builder/Stage/ReplaceRootStage.php index 17b03de82..88f9fcce2 100644 --- a/src/Builder/Stage/ReplaceRootStage.php +++ b/src/Builder/Stage/ReplaceRootStage.php @@ -10,19 +10,20 @@ use MongoDB\BSON\Serializable; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToObject; +use stdClass; class ReplaceRootStage implements StageInterface { public const NAME = '$replaceRoot'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param Document|ResolvesToObject|Serializable|array|object $newRoot */ - public array|object $newRoot; + /** @param Document|ResolvesToObject|Serializable|array|stdClass $newRoot */ + public Document|Serializable|ResolvesToObject|stdClass|array $newRoot; /** - * @param Document|ResolvesToObject|Serializable|array|object $newRoot + * @param Document|ResolvesToObject|Serializable|array|stdClass $newRoot */ - public function __construct(array|object $newRoot) + public function __construct(Document|Serializable|ResolvesToObject|stdClass|array $newRoot) { $this->newRoot = $newRoot; } diff --git a/src/Builder/Stage/ReplaceWithStage.php b/src/Builder/Stage/ReplaceWithStage.php index ddb1dff89..0bbad13d7 100644 --- a/src/Builder/Stage/ReplaceWithStage.php +++ b/src/Builder/Stage/ReplaceWithStage.php @@ -10,19 +10,20 @@ use MongoDB\BSON\Serializable; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToObject; +use stdClass; class ReplaceWithStage implements StageInterface { public const NAME = '$replaceWith'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param Document|ResolvesToObject|Serializable|array|object $expression */ - public array|object $expression; + /** @param Document|ResolvesToObject|Serializable|array|stdClass $expression */ + public Document|Serializable|ResolvesToObject|stdClass|array $expression; /** - * @param Document|ResolvesToObject|Serializable|array|object $expression + * @param Document|ResolvesToObject|Serializable|array|stdClass $expression */ - public function __construct(array|object $expression) + public function __construct(Document|Serializable|ResolvesToObject|stdClass|array $expression) { $this->expression = $expression; } diff --git a/src/Builder/Stage/SearchMetaStage.php b/src/Builder/Stage/SearchMetaStage.php index f92461a07..548d2855d 100644 --- a/src/Builder/Stage/SearchMetaStage.php +++ b/src/Builder/Stage/SearchMetaStage.php @@ -9,19 +9,20 @@ use MongoDB\BSON\Document; use MongoDB\BSON\Serializable; use MongoDB\Builder\Encode; +use stdClass; class SearchMetaStage implements StageInterface { public const NAME = '$searchMeta'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param Document|Serializable|array|object $meta */ - public array|object $meta; + /** @param Document|Serializable|array|stdClass $meta */ + public Document|Serializable|stdClass|array $meta; /** - * @param Document|Serializable|array|object $meta + * @param Document|Serializable|array|stdClass $meta */ - public function __construct(array|object $meta) + public function __construct(Document|Serializable|stdClass|array $meta) { $this->meta = $meta; } diff --git a/src/Builder/Stage/SearchStage.php b/src/Builder/Stage/SearchStage.php index 3ade54d85..cbc019618 100644 --- a/src/Builder/Stage/SearchStage.php +++ b/src/Builder/Stage/SearchStage.php @@ -9,19 +9,20 @@ use MongoDB\BSON\Document; use MongoDB\BSON\Serializable; use MongoDB\Builder\Encode; +use stdClass; class SearchStage implements StageInterface { public const NAME = '$search'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param Document|Serializable|array|object $search */ - public array|object $search; + /** @param Document|Serializable|array|stdClass $search */ + public Document|Serializable|stdClass|array $search; /** - * @param Document|Serializable|array|object $search + * @param Document|Serializable|array|stdClass $search */ - public function __construct(array|object $search) + public function __construct(Document|Serializable|stdClass|array $search) { $this->search = $search; } diff --git a/src/Builder/Stage/SetStage.php b/src/Builder/Stage/SetStage.php index b8fc4aaaf..e3e6a9275 100644 --- a/src/Builder/Stage/SetStage.php +++ b/src/Builder/Stage/SetStage.php @@ -8,28 +8,30 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ExpressionInterface; +use stdClass; class SetStage implements StageInterface { public const NAME = '$set'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param array ...$field */ - public array $field; + /** @param stdClass ...$field */ + public stdClass $field; /** - * @param ExpressionInterface|mixed $field + * @param ExpressionInterface|mixed ...$field */ public function __construct(mixed ...$field) { + if (\count($field) < 1) { + throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $field, got %d.', 1, \count($field))); + } foreach($field as $key => $value) { if (! \is_string($key)) { throw new \InvalidArgumentException('Expected $field arguments to be a map of ExpressionInterface|mixed, named arguments (:) or array unpacking ...[\'\' => ] must be used'); } } - if (\count($field) < 1) { - throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $field, got %d.', 1, \count($field))); - } + $field = (object) $field; $this->field = $field; } } diff --git a/src/Builder/Stage/SetWindowFieldsStage.php b/src/Builder/Stage/SetWindowFieldsStage.php index 07e2783df..b370b1ebf 100644 --- a/src/Builder/Stage/SetWindowFieldsStage.php +++ b/src/Builder/Stage/SetWindowFieldsStage.php @@ -11,6 +11,7 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Optional; +use stdClass; class SetWindowFieldsStage implements StageInterface { @@ -20,30 +21,30 @@ class SetWindowFieldsStage implements StageInterface /** @param ExpressionInterface|mixed $partitionBy 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. */ public mixed $partitionBy; - /** @param array|object $sortBy Specifies the field(s) to sort the documents by in the partition. Uses the same syntax as the $sort stage. Default is no sorting. */ - public array|object $sortBy; + /** @param array|stdClass $sortBy Specifies the field(s) to sort the documents by in the partition. Uses the same syntax as the $sort stage. Default is no sorting. */ + public stdClass|array $sortBy; /** - * @param Document|Serializable|array|object $output 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. + * @param Document|Serializable|array|stdClass $output 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. */ - public array|object $output; + public Document|Serializable|stdClass|array $output; - /** @param Optional|array|object $window Specifies the window boundaries and parameters. Window boundaries are inclusive. Default is an unbounded window, which includes all documents in the partition. */ - public array|object $window; + /** @param Optional|array|stdClass $window Specifies the window boundaries and parameters. Window boundaries are inclusive. Default is an unbounded window, which includes all documents in the partition. */ + public Optional|stdClass|array $window; /** * @param ExpressionInterface|mixed $partitionBy 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. - * @param array|object $sortBy Specifies the field(s) to sort the documents by in the partition. Uses the same syntax as the $sort stage. Default is no sorting. - * @param Document|Serializable|array|object $output 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. + * @param array|stdClass $sortBy Specifies the field(s) to sort the documents by in the partition. Uses the same syntax as the $sort stage. Default is no sorting. + * @param Document|Serializable|array|stdClass $output 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. - * @param Optional|array|object $window Specifies the window boundaries and parameters. Window boundaries are inclusive. Default is an unbounded window, which includes all documents in the partition. + * @param Optional|array|stdClass $window Specifies the window boundaries and parameters. Window boundaries are inclusive. Default is an unbounded window, which includes all documents in the partition. */ public function __construct( mixed $partitionBy, - array|object $sortBy, - array|object $output, - array|object $window = Optional::Undefined, + stdClass|array $sortBy, + Document|Serializable|stdClass|array $output, + Optional|stdClass|array $window = Optional::Undefined, ) { $this->partitionBy = $partitionBy; $this->sortBy = $sortBy; diff --git a/src/Builder/Stage/SortStage.php b/src/Builder/Stage/SortStage.php index 1a9396f05..558f57bcf 100644 --- a/src/Builder/Stage/SortStage.php +++ b/src/Builder/Stage/SortStage.php @@ -7,19 +7,20 @@ namespace MongoDB\Builder\Stage; use MongoDB\Builder\Encode; +use stdClass; class SortStage implements StageInterface { public const NAME = '$sort'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param array|object $sort */ - public array|object $sort; + /** @param array|stdClass $sort */ + public stdClass|array $sort; /** - * @param array|object $sort + * @param array|stdClass $sort */ - public function __construct(array|object $sort) + public function __construct(stdClass|array $sort) { $this->sort = $sort; } diff --git a/src/Builder/Stage/UnsetStage.php b/src/Builder/Stage/UnsetStage.php index 952c7907d..715b6bccb 100644 --- a/src/Builder/Stage/UnsetStage.php +++ b/src/Builder/Stage/UnsetStage.php @@ -21,16 +21,16 @@ class UnsetStage implements StageInterface public array $field; /** - * @param FieldPath|non-empty-string $field + * @param FieldPath|non-empty-string ...$field */ public function __construct(FieldPath|string ...$field) { - if (! \array_is_list($field)) { - throw new \InvalidArgumentException('Expected $field arguments to be a list of FieldPath|non-empty-string, named arguments are not supported'); - } if (\count($field) < 1) { throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $field, got %d.', 1, \count($field))); } + if (! \array_is_list($field)) { + throw new \InvalidArgumentException('Expected $field arguments to be a list of FieldPath|non-empty-string, named arguments are not supported'); + } $this->field = $field; } } diff --git a/tests/Builder/BuilderEncoderTest.php b/tests/Builder/BuilderEncoderTest.php index c26083c51..cc604b407 100644 --- a/tests/Builder/BuilderEncoderTest.php +++ b/tests/Builder/BuilderEncoderTest.php @@ -15,6 +15,7 @@ use function array_merge; use function array_walk; use function is_array; +use function var_export; /** * @todo This annotation is not enough as this PHP file needs to use named arguments, that can't compile on PHP 7.4 @@ -57,21 +58,24 @@ public function testSort(): void public function testPerformCount(): void { $pipeline = new Pipeline( - Stage::match(Query::or( - ['score' => [Query::gt(70), Query::lt(90)]], - ['views' => Query::gte(1000)], - )), - Stage::group(...[ - '_id' => null, - 'count' => Aggregation::sum(1), - ]), + Stage::match( + Query::or( + (object) ['score' => [Query::gt(70), Query::lt(90)]], + (object) ['views' => Query::gte(1000)], + ), + ), + Stage::group( + _id: null, + count: Aggregation::sum(1), + ), ); $expected = [ [ '$match' => [ '$or' => [ - ['score' => ['$gt' => 70, '$lt' => 90]], + // same as ['score' => ['$gt' => 70, '$lt' => 90]], + ['score' => [['$gt' => 70], ['$lt' => 90]]], ['views' => ['$gte' => 1000]], ], ], @@ -141,7 +145,7 @@ private static function assertSamePipeline(array $expected, Pipeline $pipeline): self::objectify($expected); - self::assertEquals($expected, $actual); + self::assertEquals($expected, $actual, var_export($actual, true)); } /** From 64ee28ecdc7f67ecd9e27d1aa0d2b5f18e17947c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Thu, 5 Oct 2023 17:54:36 +0200 Subject: [PATCH 05/37] Add link and description to classes and factory --- generator/config/expressions.php | 3 +- generator/src/OperatorClassGenerator.php | 2 + generator/src/OperatorFactoryGenerator.php | 2 + src/Builder/Aggregation.php | 654 +++++++++++++++++- src/Builder/Aggregation/AbsAggregation.php | 5 + .../Aggregation/AccumulatorAggregation.php | 6 + src/Builder/Aggregation/AcosAggregation.php | 5 + src/Builder/Aggregation/AcoshAggregation.php | 5 + src/Builder/Aggregation/AddAggregation.php | 8 +- .../Aggregation/AddToSetAggregation.php | 6 + .../AllElementsTrueAggregation.php | 5 + src/Builder/Aggregation/AndAggregation.php | 5 + .../Aggregation/AnyElementTrueAggregation.php | 5 + .../Aggregation/ArrayElemAtAggregation.php | 5 + .../Aggregation/ArrayToObjectAggregation.php | 5 + src/Builder/Aggregation/AsinAggregation.php | 5 + src/Builder/Aggregation/AsinhAggregation.php | 5 + src/Builder/Aggregation/Atan2Aggregation.php | 5 + src/Builder/Aggregation/AtanAggregation.php | 5 + src/Builder/Aggregation/AtanhAggregation.php | 5 + src/Builder/Aggregation/AvgAggregation.php | 6 + .../Aggregation/BinarySizeAggregation.php | 5 + src/Builder/Aggregation/BitAndAggregation.php | 6 + src/Builder/Aggregation/BitNotAggregation.php | 6 + src/Builder/Aggregation/BitOrAggregation.php | 6 + src/Builder/Aggregation/BitXorAggregation.php | 6 + src/Builder/Aggregation/BottomAggregation.php | 8 + .../Aggregation/BottomNAggregation.php | 7 + .../Aggregation/BsonSizeAggregation.php | 5 + src/Builder/Aggregation/CeilAggregation.php | 5 + src/Builder/Aggregation/CmpAggregation.php | 5 + src/Builder/Aggregation/ConcatAggregation.php | 5 + .../Aggregation/ConcatArraysAggregation.php | 5 + src/Builder/Aggregation/CondAggregation.php | 5 + .../Aggregation/ConvertAggregation.php | 6 + src/Builder/Aggregation/CosAggregation.php | 5 + src/Builder/Aggregation/CoshAggregation.php | 5 + src/Builder/Aggregation/CountAggregation.php | 7 + .../Aggregation/CovariancePopAggregation.php | 6 + .../Aggregation/CovarianceSampAggregation.php | 6 + .../Aggregation/DateAddAggregation.php | 10 +- .../Aggregation/DateDiffAggregation.php | 14 +- .../Aggregation/DateFromPartsAggregation.php | 5 + .../Aggregation/DateFromStringAggregation.php | 5 + .../Aggregation/DateSubtractAggregation.php | 10 +- .../Aggregation/DateToPartsAggregation.php | 10 +- .../Aggregation/DateToStringAggregation.php | 10 +- .../Aggregation/DateTruncAggregation.php | 10 +- .../Aggregation/DayOfMonthAggregation.php | 10 +- .../Aggregation/DayOfWeekAggregation.php | 10 +- .../Aggregation/DayOfYearAggregation.php | 10 +- .../DegreesToRadiansAggregation.php | 5 + .../Aggregation/DenseRankAggregation.php | 6 + .../Aggregation/DerivativeAggregation.php | 11 +- src/Builder/Aggregation/DivideAggregation.php | 5 + .../Aggregation/DocumentNumberAggregation.php | 6 + src/Builder/Aggregation/EqAggregation.php | 5 + src/Builder/Aggregation/ExpAggregation.php | 5 + .../Aggregation/ExpMovingAvgAggregation.php | 6 + src/Builder/Aggregation/FilterAggregation.php | 5 + src/Builder/Aggregation/FirstAggregation.php | 6 + src/Builder/Aggregation/FirstNAggregation.php | 5 + src/Builder/Aggregation/FloorAggregation.php | 5 + .../Aggregation/FunctionAggregation.php | 6 + .../Aggregation/GetFieldAggregation.php | 6 + src/Builder/Aggregation/GtAggregation.php | 5 + src/Builder/Aggregation/GteAggregation.php | 5 + src/Builder/Aggregation/HourAggregation.php | 10 +- src/Builder/Aggregation/IfNullAggregation.php | 5 + src/Builder/Aggregation/InAggregation.php | 5 + .../Aggregation/IndexOfArrayAggregation.php | 5 + .../Aggregation/IndexOfBytesAggregation.php | 5 + .../Aggregation/IndexOfCPAggregation.php | 5 + .../Aggregation/IntegralAggregation.php | 11 +- .../Aggregation/IsArrayAggregation.php | 5 + .../Aggregation/IsNumberAggregation.php | 7 + .../Aggregation/IsoDayOfWeekAggregation.php | 10 +- .../Aggregation/IsoWeekAggregation.php | 10 +- .../Aggregation/IsoWeekYearAggregation.php | 10 +- src/Builder/Aggregation/LastAggregation.php | 6 + src/Builder/Aggregation/LastNAggregation.php | 5 + src/Builder/Aggregation/LetAggregation.php | 6 + .../Aggregation/LinearFillAggregation.php | 7 + .../Aggregation/LiteralAggregation.php | 5 + src/Builder/Aggregation/LnAggregation.php | 6 + src/Builder/Aggregation/LocfAggregation.php | 7 + src/Builder/Aggregation/Log10Aggregation.php | 5 + src/Builder/Aggregation/LogAggregation.php | 5 + src/Builder/Aggregation/LtAggregation.php | 5 + src/Builder/Aggregation/LteAggregation.php | 5 + src/Builder/Aggregation/LtrimAggregation.php | 6 + src/Builder/Aggregation/MapAggregation.php | 5 + src/Builder/Aggregation/MaxAggregation.php | 6 + src/Builder/Aggregation/MaxNAggregation.php | 5 + src/Builder/Aggregation/MedianAggregation.php | 10 + .../Aggregation/MergeObjectsAggregation.php | 5 + src/Builder/Aggregation/MetaAggregation.php | 5 + .../Aggregation/MillisecondAggregation.php | 10 +- src/Builder/Aggregation/MinAggregation.php | 6 + src/Builder/Aggregation/MinNAggregation.php | 5 + src/Builder/Aggregation/MinuteAggregation.php | 10 +- src/Builder/Aggregation/ModAggregation.php | 5 + src/Builder/Aggregation/MonthAggregation.php | 10 +- .../Aggregation/MultiplyAggregation.php | 5 + src/Builder/Aggregation/NeAggregation.php | 5 + src/Builder/Aggregation/NotAggregation.php | 5 + .../Aggregation/ObjectToArrayAggregation.php | 5 + src/Builder/Aggregation/OrAggregation.php | 5 + .../Aggregation/PercentileAggregation.php | 13 + src/Builder/Aggregation/PowAggregation.php | 5 + src/Builder/Aggregation/PushAggregation.php | 6 + .../RadiansToDegreesAggregation.php | 5 + src/Builder/Aggregation/RandAggregation.php | 5 + src/Builder/Aggregation/RangeAggregation.php | 5 + src/Builder/Aggregation/RankAggregation.php | 6 + src/Builder/Aggregation/ReduceAggregation.php | 5 + .../Aggregation/RegexFindAggregation.php | 6 + .../Aggregation/RegexFindAllAggregation.php | 6 + .../Aggregation/RegexMatchAggregation.php | 6 + .../Aggregation/ReplaceAllAggregation.php | 7 + .../Aggregation/ReplaceOneAggregation.php | 6 + .../Aggregation/ReverseArrayAggregation.php | 5 + src/Builder/Aggregation/RoundAggregation.php | 5 + src/Builder/Aggregation/RtrimAggregation.php | 5 + .../Aggregation/SampleRateAggregation.php | 5 + src/Builder/Aggregation/SecondAggregation.php | 10 +- .../Aggregation/SetDifferenceAggregation.php | 5 + .../Aggregation/SetEqualsAggregation.php | 5 + .../Aggregation/SetFieldAggregation.php | 6 + .../SetIntersectionAggregation.php | 5 + .../Aggregation/SetIsSubsetAggregation.php | 5 + .../Aggregation/SetUnionAggregation.php | 5 + src/Builder/Aggregation/ShiftAggregation.php | 6 + src/Builder/Aggregation/SinAggregation.php | 5 + src/Builder/Aggregation/SinhAggregation.php | 5 + src/Builder/Aggregation/SizeAggregation.php | 5 + src/Builder/Aggregation/SliceAggregation.php | 5 + .../Aggregation/SortArrayAggregation.php | 5 + src/Builder/Aggregation/SplitAggregation.php | 5 + src/Builder/Aggregation/SqrtAggregation.php | 5 + .../Aggregation/StdDevPopAggregation.php | 7 + .../Aggregation/StdDevSampAggregation.php | 7 + .../Aggregation/StrLenBytesAggregation.php | 5 + .../Aggregation/StrLenCPAggregation.php | 5 + .../Aggregation/StrcasecmpAggregation.php | 5 + src/Builder/Aggregation/SubstrAggregation.php | 5 + .../Aggregation/SubstrBytesAggregation.php | 5 + .../Aggregation/SubstrCPAggregation.php | 5 + .../Aggregation/SubtractAggregation.php | 14 +- src/Builder/Aggregation/SumAggregation.php | 6 + src/Builder/Aggregation/SwitchAggregation.php | 5 + src/Builder/Aggregation/TanAggregation.php | 5 + src/Builder/Aggregation/TanhAggregation.php | 5 + src/Builder/Aggregation/ToBoolAggregation.php | 6 + src/Builder/Aggregation/ToDateAggregation.php | 6 + .../Aggregation/ToDecimalAggregation.php | 6 + .../Aggregation/ToDoubleAggregation.php | 6 + src/Builder/Aggregation/ToIntAggregation.php | 6 + src/Builder/Aggregation/ToLongAggregation.php | 6 + .../Aggregation/ToLowerAggregation.php | 5 + .../Aggregation/ToObjectIdAggregation.php | 6 + .../Aggregation/ToStringAggregation.php | 6 + .../Aggregation/ToUpperAggregation.php | 5 + src/Builder/Aggregation/TopAggregation.php | 8 + src/Builder/Aggregation/TopNAggregation.php | 8 + src/Builder/Aggregation/TrimAggregation.php | 6 + src/Builder/Aggregation/TruncAggregation.php | 5 + .../Aggregation/TsIncrementAggregation.php | 6 + .../Aggregation/TsSecondAggregation.php | 6 + src/Builder/Aggregation/TypeAggregation.php | 5 + .../Aggregation/UnsetFieldAggregation.php | 6 + src/Builder/Aggregation/WeekAggregation.php | 10 +- src/Builder/Aggregation/YearAggregation.php | 10 +- src/Builder/Aggregation/ZipAggregation.php | 5 + src/Builder/Query.php | 135 ++++ src/Builder/Query/AllQuery.php | 5 + src/Builder/Query/AndQuery.php | 5 + src/Builder/Query/BitsAllClearQuery.php | 5 + src/Builder/Query/BitsAllSetQuery.php | 5 + src/Builder/Query/BitsAnyClearQuery.php | 5 + src/Builder/Query/BitsAnySetQuery.php | 5 + src/Builder/Query/BoxQuery.php | 5 + src/Builder/Query/CenterQuery.php | 5 + src/Builder/Query/CenterSphereQuery.php | 5 + src/Builder/Query/CommentQuery.php | 5 + src/Builder/Query/ElemMatchQuery.php | 5 + src/Builder/Query/EqQuery.php | 5 + src/Builder/Query/ExistsQuery.php | 5 + src/Builder/Query/ExprQuery.php | 5 + src/Builder/Query/GeoIntersectsQuery.php | 5 + src/Builder/Query/GeoWithinQuery.php | 5 + src/Builder/Query/GeometryQuery.php | 5 + src/Builder/Query/GtQuery.php | 5 + src/Builder/Query/GteQuery.php | 5 + src/Builder/Query/InQuery.php | 5 + src/Builder/Query/JsonSchemaQuery.php | 5 + src/Builder/Query/LtQuery.php | 5 + src/Builder/Query/LteQuery.php | 5 + src/Builder/Query/MaxDistanceQuery.php | 5 + src/Builder/Query/MetaQuery.php | 5 + src/Builder/Query/MinDistanceQuery.php | 5 + src/Builder/Query/ModQuery.php | 5 + src/Builder/Query/NaturalQuery.php | 5 + src/Builder/Query/NeQuery.php | 5 + src/Builder/Query/NearQuery.php | 5 + src/Builder/Query/NearSphereQuery.php | 5 + src/Builder/Query/NinQuery.php | 5 + src/Builder/Query/NorQuery.php | 5 + src/Builder/Query/NotQuery.php | 5 + src/Builder/Query/OrQuery.php | 5 + src/Builder/Query/PolygonQuery.php | 5 + src/Builder/Query/RandQuery.php | 5 + src/Builder/Query/RegexQuery.php | 5 + src/Builder/Query/SizeQuery.php | 5 + src/Builder/Query/SliceQuery.php | 5 + src/Builder/Query/TextQuery.php | 5 + src/Builder/Query/TypeQuery.php | 5 + src/Builder/Query/WhereQuery.php | 5 + src/Builder/Stage.php | 147 ++++ src/Builder/Stage/AddFieldsStage.php | 5 + src/Builder/Stage/BucketAutoStage.php | 5 + src/Builder/Stage/BucketStage.php | 5 + .../ChangeStreamSplitLargeEventStage.php | 6 + src/Builder/Stage/ChangeStreamStage.php | 5 + src/Builder/Stage/CollStatsStage.php | 5 + src/Builder/Stage/CountStage.php | 6 + src/Builder/Stage/CurrentOpStage.php | 5 + src/Builder/Stage/DensifyStage.php | 5 + src/Builder/Stage/DocumentsStage.php | 5 + src/Builder/Stage/FacetStage.php | 5 + src/Builder/Stage/FillStage.php | 5 + src/Builder/Stage/GeoNearStage.php | 5 + src/Builder/Stage/GraphLookupStage.php | 5 + src/Builder/Stage/GroupStage.php | 5 + src/Builder/Stage/IndexStatsStage.php | 5 + src/Builder/Stage/LimitStage.php | 5 + src/Builder/Stage/ListLocalSessionsStage.php | 5 + src/Builder/Stage/ListSampledQueriesStage.php | 5 + src/Builder/Stage/ListSearchIndexesStage.php | 5 + src/Builder/Stage/ListSessionsStage.php | 5 + src/Builder/Stage/LookupStage.php | 5 + src/Builder/Stage/MatchStage.php | 5 + src/Builder/Stage/MergeStage.php | 6 + src/Builder/Stage/OutStage.php | 5 + src/Builder/Stage/PlanCacheStatsStage.php | 5 + src/Builder/Stage/ProjectStage.php | 5 + src/Builder/Stage/RedactStage.php | 5 + src/Builder/Stage/ReplaceRootStage.php | 5 + src/Builder/Stage/ReplaceWithStage.php | 6 + src/Builder/Stage/SampleStage.php | 5 + src/Builder/Stage/SearchMetaStage.php | 6 + src/Builder/Stage/SearchStage.php | 6 + src/Builder/Stage/SetStage.php | 6 + src/Builder/Stage/SetWindowFieldsStage.php | 6 + .../Stage/ShardedDataDistributionStage.php | 6 + src/Builder/Stage/SkipStage.php | 5 + src/Builder/Stage/SortByCountStage.php | 5 + src/Builder/Stage/SortStage.php | 5 + src/Builder/Stage/UnionWithStage.php | 6 + src/Builder/Stage/UnsetStage.php | 6 + src/Builder/Stage/UnwindStage.php | 5 + 261 files changed, 2358 insertions(+), 75 deletions(-) diff --git a/generator/config/expressions.php b/generator/config/expressions.php index 84e0e0427..54a0a198c 100644 --- a/generator/config/expressions.php +++ b/generator/config/expressions.php @@ -4,6 +4,7 @@ namespace MongoDB\Builder\Expression; +use DateTimeInterface; use MongoDB\BSON; use MongoDB\Builder\Aggregation\AccumulatorInterface; use MongoDB\Builder\Pipeline; @@ -111,7 +112,7 @@ function typeFieldPath(string $resolvesTo): array BoolFieldPath::class => typeFieldPath(ResolvesToBool::class), ResolvesToDate::class => [ 'implements' => [ExpressionInterface::class], - 'types' => ['DateTimeInterface', 'UTCDateTime'], + 'types' => [DateTimeInterface::class, BSON\UTCDateTime::class], ], DateFieldPath::class => typeFieldPath(ResolvesToDate::class), ResolvesToTimestamp::class => [ diff --git a/generator/src/OperatorClassGenerator.php b/generator/src/OperatorClassGenerator.php index 9db7a2edd..7d386fc61 100644 --- a/generator/src/OperatorClassGenerator.php +++ b/generator/src/OperatorClassGenerator.php @@ -52,6 +52,8 @@ public function createClass(GeneratorDefinition $definition, OperatorDefinition // Expose operator metadata as constants // @todo move to encoder class $namespace->addUse('\\' . Encode::class); + $class->addComment($operator->description); + $class->addComment('@see '.$operator->link); $class->addConstant('NAME', $operator->name); $class->addConstant('ENCODE', $operator->encode); diff --git a/generator/src/OperatorFactoryGenerator.php b/generator/src/OperatorFactoryGenerator.php index 80a13f012..96d47afb2 100644 --- a/generator/src/OperatorFactoryGenerator.php +++ b/generator/src/OperatorFactoryGenerator.php @@ -59,6 +59,8 @@ private function addMethod(GeneratorDefinition $definition, OperatorDefinition $ $method = $class->addMethod(ltrim($operator->name, '$')); $method->setStatic(); + $method->addComment($operator->description); + $method->addComment('@see ' . $operator->link); $args = []; foreach ($operator->arguments as $argument) { $type = $this->generateExpressionTypes($argument); diff --git a/src/Builder/Aggregation.php b/src/Builder/Aggregation.php index b14f2049c..cdd3438d3 100644 --- a/src/Builder/Aggregation.php +++ b/src/Builder/Aggregation.php @@ -15,6 +15,7 @@ use MongoDB\BSON\PackedArray; use MongoDB\BSON\Regex; use MongoDB\BSON\Serializable; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Aggregation\AbsAggregation; use MongoDB\Builder\Aggregation\AccumulatorAggregation; use MongoDB\Builder\Aggregation\AcosAggregation; @@ -208,6 +209,9 @@ final class Aggregation { /** + * Returns the absolute value of a number. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/abs/ * @param Decimal128|Int64|ResolvesToNumber|float|int $value */ public static function abs(Decimal128|Int64|ResolvesToNumber|float|int $value): AbsAggregation @@ -216,6 +220,10 @@ public static function abs(Decimal128|Int64|ResolvesToNumber|float|int $value): } /** + * Defines a custom accumulator function. + * New in version 4.4. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/accumulator/ * @param non-empty-string $init 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. * @param non-empty-string $accumulate 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. * @param BSONArray|PackedArray|ResolvesToArray|list $accumulateArgs Arguments passed to the accumulate function. You can use accumulateArgs to specify what field value(s) to pass to the accumulate function. @@ -238,6 +246,9 @@ public static function accumulator( } /** + * Returns the inverse cosine (arc cosine) of a value in radians. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/acos/ * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $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. @@ -248,6 +259,9 @@ public static function acos(Decimal128|Int64|ResolvesToNumber|float|int $express } /** + * Returns the inverse hyperbolic cosine (hyperbolic arc cosine) of a value in radians. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/acosh/ * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $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. @@ -258,16 +272,23 @@ public static function acosh(Decimal128|Int64|ResolvesToNumber|float|int $expres } /** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/add/ * @param DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int ...$expression The arguments can be any valid expression as long as they resolve to either all numbers or to numbers and a date. */ public static function add( - \UTCDateTime|DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|float|int ...$expression, + DateTimeInterface|Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int ...$expression, ): AddAggregation { return new AddAggregation(...$expression); } /** + * Returns an array of unique expression values for each group. Order of the array elements is undefined. + * Changed in version 5.0: Available in the $setWindowFields stage. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/addToSet/ * @param ExpressionInterface|FieldPath|mixed|non-empty-string $expression */ public static function addToSet(mixed $expression): AddToSetAggregation @@ -276,6 +297,9 @@ public static function addToSet(mixed $expression): AddToSetAggregation } /** + * Returns true if no element of a set evaluates to false, otherwise, returns false. Accepts a single argument expression. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/allElementsTrue/ * @param BSONArray|PackedArray|ResolvesToArray|list ...$expression */ public static function allElementsTrue( @@ -286,6 +310,9 @@ public static function allElementsTrue( } /** + * Returns true only when all its expressions evaluate to true. Accepts any number of argument expressions. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/and/ * @param Decimal128|ExpressionInterface|Int64|ResolvesToBool|ResolvesToNull|ResolvesToNumber|ResolvesToString|bool|float|int|mixed|non-empty-string|null ...$expression */ public static function and(mixed ...$expression): AndAggregation @@ -294,6 +321,9 @@ public static function and(mixed ...$expression): AndAggregation } /** + * Returns true if any elements of a set evaluate to true; otherwise, returns false. Accepts a single argument expression. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/anyElementTrue/ * @param BSONArray|PackedArray|ResolvesToArray|list $expression */ public static function anyElementTrue( @@ -304,6 +334,9 @@ public static function anyElementTrue( } /** + * Returns the element at the specified array index. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/arrayElemAt/ * @param BSONArray|PackedArray|ResolvesToArray|list $array * @param Int64|ResolvesToInt|int $idx */ @@ -316,6 +349,9 @@ public static function arrayElemAt( } /** + * Converts an array of key value pairs to a document. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/arrayToObject/ * @param BSONArray|PackedArray|ResolvesToArray|list $array */ public static function arrayToObject(PackedArray|ResolvesToArray|BSONArray|array $array): ArrayToObjectAggregation @@ -324,6 +360,9 @@ public static function arrayToObject(PackedArray|ResolvesToArray|BSONArray|array } /** + * Returns the inverse sin (arc sine) of a value in radians. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/asin/ * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $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. @@ -334,6 +373,9 @@ public static function asin(Decimal128|Int64|ResolvesToNumber|float|int $express } /** + * Returns the inverse hyperbolic sine (hyperbolic arc sine) of a value in radians. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/asinh/ * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $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. @@ -344,6 +386,9 @@ public static function asinh(Decimal128|Int64|ResolvesToNumber|float|int $expres } /** + * Returns the inverse tangent (arc tangent) of a value in radians. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/atan/ * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $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. @@ -354,6 +399,9 @@ public static function atan(Decimal128|Int64|ResolvesToNumber|float|int $express } /** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/atan2/ * @param Decimal128|Int64|ResolvesToNumber|float|int $y $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. @@ -368,6 +416,9 @@ public static function atan2( } /** + * Returns the inverse hyperbolic tangent (hyperbolic arc tangent) of a value in radians. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/atanh/ * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $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. @@ -378,6 +429,10 @@ public static function atanh(Decimal128|Int64|ResolvesToNumber|float|int $expres } /** + * Returns an average of numerical values. Ignores non-numeric values. + * Changed in version 5.0: Available in the $setWindowFields stage. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/avg/ * @param Decimal128|Int64|ResolvesToNumber|float|int ...$expression */ public static function avg(Decimal128|Int64|ResolvesToNumber|float|int ...$expression): AvgAggregation @@ -386,6 +441,9 @@ public static function avg(Decimal128|Int64|ResolvesToNumber|float|int ...$expre } /** + * Returns the size of a given string or binary data value's content in bytes. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/binarySize/ * @param Binary|ResolvesToBinary|ResolvesToNull|ResolvesToString|non-empty-string|null $expression */ public static function binarySize( @@ -396,6 +454,10 @@ public static function binarySize( } /** + * Returns the result of a bitwise and operation on an array of int or long values. + * New in version 6.3. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitAnd/ * @param Int64|ResolvesToInt|ResolvesToLong|int ...$expression */ public static function bitAnd(Int64|ResolvesToInt|ResolvesToLong|int ...$expression): BitAndAggregation @@ -404,6 +466,10 @@ public static function bitAnd(Int64|ResolvesToInt|ResolvesToLong|int ...$express } /** + * 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 version 6.3. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitNot/ * @param Int64|ResolvesToInt|ResolvesToLong|int $expression */ public static function bitNot(Int64|ResolvesToInt|ResolvesToLong|int $expression): BitNotAggregation @@ -412,6 +478,10 @@ public static function bitNot(Int64|ResolvesToInt|ResolvesToLong|int $expression } /** + * Returns the result of a bitwise or operation on an array of int or long values. + * New in version 6.3. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitOr/ * @param Int64|ResolvesToInt|ResolvesToLong|int ...$expression */ public static function bitOr(Int64|ResolvesToInt|ResolvesToLong|int ...$expression): BitOrAggregation @@ -419,12 +489,24 @@ public static function bitOr(Int64|ResolvesToInt|ResolvesToLong|int ...$expressi return new BitOrAggregation(...$expression); } + /** + * Returns the result of a bitwise xor (exclusive or) operation on an array of int and long values. + * New in version 6.3. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitXor/ + */ public static function bitXor(): BitXorAggregation { return new BitXorAggregation(); } /** + * Returns the bottom element within a group according to the specified sort order. + * New in version 5.2. + * + * Available in the $group and $setWindowFields stages. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/bottom/ * @param array|stdClass $sortBy Specifies the order of results, with syntax similar to $sort. * @param ExpressionInterface|mixed $output Represents the output for each element in the group and can be any expression. */ @@ -434,6 +516,11 @@ public static function bottom(stdClass|array $sortBy, mixed $output): BottomAggr } /** + * Returns an aggregation of the bottom n elements within a group, according to the specified sort order. If the group contains fewer than n elements, $bottomN returns all elements in the group. + * New in version 5.2. + * Available in the $group and $setWindowFields stages. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/bottomN/ * @param Int64|ResolvesToInt|int $n 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. * @param array|stdClass $sortBy Specifies the order of results, with syntax similar to $sort. * @param ExpressionInterface|mixed $output Represents the output for each element in the group and can be any expression. @@ -448,6 +535,9 @@ public static function bottomN( } /** + * Returns the size in bytes of a given document (i.e. bsontype Object) when encoded as BSON. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/bsonSize/ * @param Document|ResolvesToNull|ResolvesToObject|Serializable|array|null|stdClass $object */ public static function bsonSize( @@ -458,6 +548,9 @@ public static function bsonSize( } /** + * Returns the smallest integer greater than or equal to the specified number. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/ceil/ * @param Decimal128|Int64|ResolvesToNumber|float|int $expression 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. */ public static function ceil(Decimal128|Int64|ResolvesToNumber|float|int $expression): CeilAggregation @@ -466,6 +559,9 @@ public static function ceil(Decimal128|Int64|ResolvesToNumber|float|int $express } /** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/cmp/ * @param ExpressionInterface|mixed $expression1 * @param ExpressionInterface|mixed $expression2 */ @@ -475,6 +571,9 @@ public static function cmp(mixed $expression1, mixed $expression2): CmpAggregati } /** + * Concatenates any number of strings. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/concat/ * @param ResolvesToString|non-empty-string ...$expression */ public static function concat(ResolvesToString|string ...$expression): ConcatAggregation @@ -483,6 +582,9 @@ public static function concat(ResolvesToString|string ...$expression): ConcatAgg } /** + * Concatenates arrays to return the concatenated array. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/concatArrays/ * @param BSONArray|PackedArray|ResolvesToArray|list ...$array */ public static function concatArrays( @@ -493,6 +595,9 @@ public static function concatArrays( } /** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/cond/ * @param ResolvesToBool|bool $if * @param ExpressionInterface|mixed $then * @param ExpressionInterface|mixed $else @@ -503,6 +608,10 @@ public static function cond(ResolvesToBool|bool $if, mixed $then, mixed $else): } /** + * Converts a value to a specified type. + * New in version 4.0. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/convert/ * @param ExpressionInterface|mixed $input * @param Int64|ResolvesToInt|ResolvesToString|int|non-empty-string $to * @param ExpressionInterface|Optional|mixed $onError The value to return on encountering an error during conversion, including unsupported type conversions. The arguments can be any valid expression. @@ -521,6 +630,9 @@ public static function convert( } /** + * Returns the cosine of a value that is measured in radians. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/cos/ * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $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. */ @@ -530,6 +642,9 @@ public static function cos(Decimal128|Int64|ResolvesToNumber|float|int $expressi } /** + * Returns the hyperbolic cosine of a value that is measured in radians. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/cosh/ * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $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. */ @@ -539,6 +654,11 @@ public static function cosh(Decimal128|Int64|ResolvesToNumber|float|int $express } /** + * Returns the number of documents in the group or window. + * Distinct from the $count pipeline stage. + * New in version 5.0. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/count/ * @param non-empty-string $field */ public static function count(string $field): CountAggregation @@ -547,6 +667,10 @@ public static function count(string $field): CountAggregation } /** + * Returns the population covariance of two numeric expressions. + * New in version 5.0. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/covariancePop/ * @param Decimal128|Int64|ResolvesToNumber|float|int $expression1 * @param Decimal128|Int64|ResolvesToNumber|float|int $expression2 */ @@ -559,6 +683,10 @@ public static function covariancePop( } /** + * Returns the sample covariance of two numeric expressions. + * New in version 5.0. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/covarianceSamp/ * @param Decimal128|Int64|ResolvesToNumber|float|int $expression1 * @param Decimal128|Int64|ResolvesToNumber|float|int $expression2 */ @@ -571,13 +699,16 @@ public static function covarianceSamp( } /** + * Adds a number of time units to a date object. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateAdd/ * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $startDate 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. * @param ResolvesToString|non-empty-string $unit The unit used to measure the amount of time added to the startDate. * @param Int64|ResolvesToInt|ResolvesToLong|int $amount * @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public static function dateAdd( - \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $startDate, + DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $startDate, ResolvesToString|string $unit, Int64|ResolvesToInt|ResolvesToLong|int $amount, ResolvesToString|Optional|string $timezone = Optional::Undefined, @@ -587,6 +718,9 @@ public static function dateAdd( } /** + * Returns the difference between two dates. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateDiff/ * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $startDate The start of the time period. The startDate can be any expression that resolves to a Date, a Timestamp, or an ObjectID. * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $endDate The end of the time period. The endDate can be any expression that resolves to a Date, a Timestamp, or an ObjectID. * @param ResolvesToString|non-empty-string $unit The time measurement unit between the startDate and endDate @@ -594,8 +728,8 @@ public static function dateAdd( * @param Optional|ResolvesToString|non-empty-string $startOfWeek Used when the unit is equal to week. Defaults to Sunday. The startOfWeek parameter is an expression that resolves to a case insensitive string */ public static function dateDiff( - \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $startDate, - \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $endDate, + DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $startDate, + DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $endDate, ResolvesToString|string $unit, ResolvesToString|Optional|string $timezone = Optional::Undefined, ResolvesToString|Optional|string $startOfWeek = Optional::Undefined, @@ -605,6 +739,9 @@ public static function dateDiff( } /** + * Constructs a BSON Date object given the date's constituent parts. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateFromParts/ * @param Decimal128|Int64|ResolvesToNumber|float|int $year Calendar year. Can be any expression that evaluates to a number. * @param Decimal128|Int64|ResolvesToNumber|float|int $isoWeekYear ISO Week Date Year. Can be any expression that evaluates to a number. * @param Decimal128|Int64|Optional|ResolvesToNumber|float|int $month Month. Defaults to 1. @@ -635,6 +772,9 @@ public static function dateFromParts( } /** + * Converts a date/time string to a date object. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateFromString/ * @param ResolvesToString|non-empty-string $dateString The date/time string to convert to a date object. * @param Optional|ResolvesToString|non-empty-string $format 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. @@ -656,13 +796,16 @@ public static function dateFromString( } /** + * Subtracts a number of time units from a date object. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateSubtract/ * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $startDate 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. * @param ResolvesToString|non-empty-string $unit The unit used to measure the amount of time added to the startDate. * @param Int64|ResolvesToInt|ResolvesToLong|int $amount * @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public static function dateSubtract( - \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $startDate, + DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $startDate, ResolvesToString|string $unit, Int64|ResolvesToInt|ResolvesToLong|int $amount, ResolvesToString|Optional|string $timezone = Optional::Undefined, @@ -672,12 +815,15 @@ public static function dateSubtract( } /** + * Returns a document containing the constituent parts of a date. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateToParts/ * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The input date for which to return parts. date can be any expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|non-empty-string $timezone 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. * @param Optional|bool $iso8601 If set to true, modifies the output document to use ISO week date fields. Defaults to false. */ public static function dateToParts( - \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|Optional|string $timezone = Optional::Undefined, Optional|bool $iso8601 = Optional::Undefined, ): DateToPartsAggregation @@ -686,6 +832,9 @@ public static function dateToParts( } /** + * Returns the date as a formatted string. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateToString/ * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to convert to string. Must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|non-empty-string $format 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. @@ -694,7 +843,7 @@ public static function dateToParts( * If unspecified, $dateToString returns null if the date is null or missing. */ public static function dateToString( - \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|Optional|string $format = Optional::Undefined, ResolvesToString|Optional|string $timezone = Optional::Undefined, mixed $onNull = Optional::Undefined, @@ -704,6 +853,9 @@ public static function dateToString( } /** + * Truncates a date. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateTrunc/ * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to truncate, specified in UTC. The date can be any expression that resolves to a Date, a Timestamp, or an ObjectID. * @param ResolvesToString|non-empty-string $unit 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. @@ -714,7 +866,7 @@ public static function dateToString( * unit is week. Defaults to Sunday. */ public static function dateTrunc( - \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|string $unit, Decimal128|Int64|ResolvesToNumber|Optional|float|int $binSize = Optional::Undefined, ResolvesToString|Optional|string $timezone = Optional::Undefined, @@ -725,11 +877,14 @@ public static function dateTrunc( } /** + * Returns the day of the month for a date as a number between 1 and 31. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/dayOfMonth/ * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public static function dayOfMonth( - \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|Optional|string $timezone = Optional::Undefined, ): DayOfMonthAggregation { @@ -737,11 +892,14 @@ public static function dayOfMonth( } /** + * Returns the day of the week for a date as a number between 1 (Sunday) and 7 (Saturday). + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/dayOfWeek/ * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public static function dayOfWeek( - \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|Optional|string $timezone = Optional::Undefined, ): DayOfWeekAggregation { @@ -749,11 +907,14 @@ public static function dayOfWeek( } /** + * Returns the day of the year for a date as a number between 1 and 366 (leap year). + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/dayOfYear/ * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public static function dayOfYear( - \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|Optional|string $timezone = Optional::Undefined, ): DayOfYearAggregation { @@ -761,6 +922,9 @@ public static function dayOfYear( } /** + * Converts a value from degrees to radians. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/degreesToRadians/ * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $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. */ @@ -771,18 +935,28 @@ public static function degreesToRadians( return new DegreesToRadiansAggregation($expression); } + /** + * 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 version 5.0. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/denseRank/ + */ public static function denseRank(): DenseRankAggregation { return new DenseRankAggregation(); } /** + * Returns the average rate of change within the specified window. + * New in version 5.0. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/derivative/ * @param DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int $input * @param Optional|non-empty-string $unit 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. */ public static function derivative( - \UTCDateTime|DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|float|int $input, + DateTimeInterface|Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int $input, Optional|string $unit = Optional::Undefined, ): DerivativeAggregation { @@ -790,6 +964,9 @@ public static function derivative( } /** + * Returns the result of dividing the first number by the second. Accepts two argument expressions. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/divide/ * @param Decimal128|Int64|ResolvesToNumber|float|int $dividend The first argument is the dividend, and the second argument is the divisor; i.e. the first argument is divided by the second argument. * @param Decimal128|Int64|ResolvesToNumber|float|int $divisor */ @@ -801,12 +978,21 @@ public static function divide( return new DivideAggregation($dividend, $divisor); } + /** + * 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 version 5.0. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/documentNumber/ + */ public static function documentNumber(): DocumentNumberAggregation { return new DocumentNumberAggregation(); } /** + * Returns true if the values are equivalent. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/eq/ * @param ExpressionInterface|mixed $expression1 * @param ExpressionInterface|mixed $expression2 */ @@ -816,6 +1002,9 @@ public static function eq(mixed $expression1, mixed $expression2): EqAggregation } /** + * Raises e to the specified exponent. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/exp/ * @param Decimal128|Int64|ResolvesToNumber|float|int $exponent */ public static function exp(Decimal128|Int64|ResolvesToNumber|float|int $exponent): ExpAggregation @@ -824,6 +1013,10 @@ public static function exp(Decimal128|Int64|ResolvesToNumber|float|int $exponent } /** + * Returns the exponential moving average for the numeric expression. + * New in version 5.0. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/expMovingAvg/ * @param Decimal128|Int64|ResolvesToNumber|float|int $input * @param Int64|Optional|int $N 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. @@ -841,6 +1034,9 @@ public static function expMovingAvg( } /** + * Selects a subset of the array to return an array with only the elements that match the filter condition. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/filter/ * @param BSONArray|PackedArray|ResolvesToArray|list $input * @param ResolvesToBool|bool $cond 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. * @param Optional|non-empty-string $as 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. @@ -858,6 +1054,10 @@ public static function filter( } /** + * Returns the result of an expression for the first document in a group or window. + * Changed in version 5.0: Available in the $setWindowFields stage. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/first/ * @param ExpressionInterface|mixed $expression */ public static function first(mixed $expression): FirstAggregation @@ -866,6 +1066,9 @@ public static function first(mixed $expression): FirstAggregation } /** + * Returns a specified number of elements from the beginning of an array. Distinct from the $firstN accumulator. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/firstN-array-element/ * @param BSONArray|PackedArray|ResolvesToArray|list $input An expression that resolves to the array from which to return n elements. * @param Int64|ResolvesToInt|int $n An expression that resolves to a positive integer. The integer specifies the number of array elements that $firstN returns. */ @@ -878,6 +1081,9 @@ public static function firstN( } /** + * Returns the largest integer less than or equal to the specified number. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/floor/ * @param Decimal128|Int64|ResolvesToNumber|float|int $expression */ public static function floor(Decimal128|Int64|ResolvesToNumber|float|int $expression): FloorAggregation @@ -886,6 +1092,10 @@ public static function floor(Decimal128|Int64|ResolvesToNumber|float|int $expres } /** + * Defines a custom function. + * New in version 4.4. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/function/ * @param non-empty-string $body The function definition. You can specify the function definition as either BSON type Code or String. * @param BSONArray|PackedArray|list $args Arguments passed to the function body. If the body function does not take an argument, you can specify an empty array [ ]. * @param non-empty-string $lang @@ -900,6 +1110,10 @@ public static function function( } /** + * 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 version 5.0. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/getField/ * @param non-empty-string $field 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. * @param ExpressionInterface|Optional|mixed $input Default: $$CURRENT @@ -911,6 +1125,9 @@ public static function getField(string $field, mixed $input = Optional::Undefine } /** + * Returns true if the first value is greater than the second. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/gt/ * @param ExpressionInterface|mixed $expression1 * @param ExpressionInterface|mixed $expression2 */ @@ -920,6 +1137,9 @@ public static function gt(mixed $expression1, mixed $expression2): GtAggregation } /** + * Returns true if the first value is greater than or equal to the second. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/gte/ * @param ExpressionInterface|mixed $expression1 * @param ExpressionInterface|mixed $expression2 */ @@ -929,11 +1149,14 @@ public static function gte(mixed $expression1, mixed $expression2): GteAggregati } /** + * Returns the hour for a date as a number between 0 and 23. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/hour/ * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public static function hour( - \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|Optional|string $timezone = Optional::Undefined, ): HourAggregation { @@ -941,6 +1164,9 @@ public static function hour( } /** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/ifNull/ * @param ExpressionInterface|mixed ...$expression */ public static function ifNull(mixed ...$expression): IfNullAggregation @@ -949,6 +1175,9 @@ public static function ifNull(mixed ...$expression): IfNullAggregation } /** + * Returns a boolean indicating whether a specified value is in an array. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/in/ * @param ExpressionInterface|mixed $expression Any valid expression expression. * @param BSONArray|PackedArray|ResolvesToArray|list $array Any valid expression that resolves to an array. */ @@ -958,6 +1187,9 @@ public static function in(mixed $expression, PackedArray|ResolvesToArray|BSONArr } /** + * Searches an array for an occurrence of a specified value and returns the array index of the first occurrence. Array indexes start at zero. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/indexOfArray/ * @param ResolvesToString|non-empty-string $array 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. @@ -978,6 +1210,9 @@ public static function indexOfArray( } /** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/indexOfBytes/ * @param ResolvesToString|non-empty-string $string 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. @@ -998,6 +1233,9 @@ public static function indexOfBytes( } /** + * 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 + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/indexOfCP/ * @param ResolvesToString|non-empty-string $string 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. @@ -1018,12 +1256,16 @@ public static function indexOfCP( } /** + * Returns the approximation of the area under a curve. + * New in version 5.0. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/integral/ * @param DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int $input * @param Optional|ResolvesToString|non-empty-string $unit 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. */ public static function integral( - \UTCDateTime|DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|float|int $input, + DateTimeInterface|Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int $input, ResolvesToString|Optional|string $unit = Optional::Undefined, ): IntegralAggregation { @@ -1031,6 +1273,9 @@ public static function integral( } /** + * Determines if the operand is an array. Returns a boolean. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/isArray/ * @param ExpressionInterface|mixed ...$expression */ public static function isArray(mixed ...$expression): IsArrayAggregation @@ -1039,6 +1284,11 @@ public static function isArray(mixed ...$expression): IsArrayAggregation } /** + * Returns boolean true if the specified expression resolves to an integer, decimal, double, or long. + * Returns boolean false if the expression resolves to any other BSON type, null, or a missing field. + * New in version 4.4. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/isNumber/ * @param ExpressionInterface|mixed ...$expression */ public static function isNumber(mixed ...$expression): IsNumberAggregation @@ -1047,11 +1297,14 @@ public static function isNumber(mixed ...$expression): IsNumberAggregation } /** + * Returns the weekday number in ISO 8601 format, ranging from 1 (for Monday) to 7 (for Sunday). + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/isoDayOfWeek/ * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public static function isoDayOfWeek( - \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|Optional|string $timezone = Optional::Undefined, ): IsoDayOfWeekAggregation { @@ -1059,11 +1312,14 @@ public static function isoDayOfWeek( } /** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/isoWeek/ * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public static function isoWeek( - \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|Optional|string $timezone = Optional::Undefined, ): IsoWeekAggregation { @@ -1071,11 +1327,14 @@ public static function isoWeek( } /** + * 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). + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/isoWeekYear/ * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public static function isoWeekYear( - \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|Optional|string $timezone = Optional::Undefined, ): IsoWeekYearAggregation { @@ -1083,6 +1342,10 @@ public static function isoWeekYear( } /** + * Returns the result of an expression for the last document in a group or window. + * Changed in version 5.0: Available in the $setWindowFields stage. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/last/ * @param ExpressionInterface|mixed $expression */ public static function last(mixed $expression): LastAggregation @@ -1091,6 +1354,9 @@ public static function last(mixed $expression): LastAggregation } /** + * Returns a specified number of elements from the end of an array. Distinct from the $lastN accumulator. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/lastN/ * @param BSONArray|PackedArray|ResolvesToArray|list $input An expression that resolves to the array from which to return n elements. * @param Int64|ResolvesToInt|int $n An expression that resolves to a positive integer. The integer specifies the number of array elements that $firstN returns. */ @@ -1103,6 +1369,10 @@ public static function lastN( } /** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/let/ * @param Document|Serializable|array|stdClass $vars 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. * @param ExpressionInterface|mixed $in The expression to evaluate. @@ -1113,6 +1383,11 @@ public static function let(Document|Serializable|stdClass|array $vars, mixed $in } /** + * Fills null and missing fields in a window using linear interpolation based on surrounding field values. + * Available in the $setWindowFields stage. + * New in version 5.3. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/linearFill/ * @param Decimal128|Int64|ResolvesToNumber|float|int $expression */ public static function linearFill(Decimal128|Int64|ResolvesToNumber|float|int $expression): LinearFillAggregation @@ -1121,6 +1396,9 @@ public static function linearFill(Decimal128|Int64|ResolvesToNumber|float|int $e } /** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/literal/ * @param mixed $value If the value is an expression, $literal does not evaluate the expression but instead returns the unparsed expression. */ public static function literal(mixed $value): LiteralAggregation @@ -1129,6 +1407,10 @@ public static function literal(mixed $value): LiteralAggregation } /** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/ln/ * @param Decimal128|Int64|ResolvesToNumber|float|int $number Any valid expression as long as it resolves to a non-negative number. For more information on expressions, see Expressions. */ public static function ln(Decimal128|Int64|ResolvesToNumber|float|int $number): LnAggregation @@ -1137,6 +1419,11 @@ public static function ln(Decimal128|Int64|ResolvesToNumber|float|int $number): } /** + * Last observation carried forward. Sets values for null and missing fields in a window to the last non-null value for the field. + * Available in the $setWindowFields stage. + * New in version 5.2. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/locf/ * @param ExpressionInterface|mixed $expression */ public static function locf(mixed $expression): LocfAggregation @@ -1145,6 +1432,9 @@ public static function locf(mixed $expression): LocfAggregation } /** + * Calculates the log of a number in the specified base. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/log/ * @param Decimal128|Int64|ResolvesToNumber|float|int $number Any valid expression as long as it resolves to a non-negative number. * @param Decimal128|Int64|ResolvesToNumber|float|int $base Any valid expression as long as it resolves to a positive number greater than 1. */ @@ -1157,6 +1447,9 @@ public static function log( } /** + * Calculates the log base 10 of a number. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/log10/ * @param Decimal128|Int64|ResolvesToNumber|float|int $number Any valid expression as long as it resolves to a non-negative number. */ public static function log10(Decimal128|Int64|ResolvesToNumber|float|int $number): Log10Aggregation @@ -1165,6 +1458,9 @@ public static function log10(Decimal128|Int64|ResolvesToNumber|float|int $number } /** + * Returns true if the first value is less than the second. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/lt/ * @param ExpressionInterface|mixed $expression1 * @param ExpressionInterface|mixed $expression2 */ @@ -1174,6 +1470,9 @@ public static function lt(mixed $expression1, mixed $expression2): LtAggregation } /** + * Returns true if the first value is less than or equal to the second. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/lte/ * @param ExpressionInterface|mixed $expression1 * @param ExpressionInterface|mixed $expression2 */ @@ -1183,6 +1482,10 @@ public static function lte(mixed $expression1, mixed $expression2): LteAggregati } /** + * Removes whitespace or the specified characters from the beginning of a string. + * New in version 4.0. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/ltrim/ * @param ResolvesToString|non-empty-string $input The string to trim. The argument can be any valid expression that resolves to a string. * @param Optional|ResolvesToString|non-empty-string $chars 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. @@ -1197,6 +1500,9 @@ public static function ltrim( } /** + * Applies a subexpression to each element of an array and returns the array of resulting values in order. Accepts named parameters. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/map/ * @param BSONArray|PackedArray|ResolvesToArray|list $input An expression that resolves to an array. * @param ExpressionInterface|mixed $in 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. * @param Optional|ResolvesToString|non-empty-string $as 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. @@ -1211,6 +1517,10 @@ public static function map( } /** + * Returns the maximum value that results from applying an expression to each document. + * Changed in version 5.0: Available in the $setWindowFields stage. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/max/ * @param ExpressionInterface|mixed ...$expression */ public static function max(mixed ...$expression): MaxAggregation @@ -1219,6 +1529,9 @@ public static function max(mixed ...$expression): MaxAggregation } /** + * Returns the n largest values in an array. Distinct from the $maxN accumulator. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/maxN-array-element/ * @param BSONArray|PackedArray|ResolvesToArray|list $input An expression that resolves to the array from which to return the maximal n elements. * @param Int64|ResolvesToInt|int $n An expression that resolves to a positive integer. The integer specifies the number of array elements that $maxN returns. */ @@ -1231,6 +1544,14 @@ public static function maxN( } /** + * Returns an approximation of the median, the 50th percentile, as a scalar value. + * New in version 7.0. + * This operator is available as an accumulator in these stages: + * $group + * $setWindowFields + * It is also available as an aggregation expression. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/median/ * @param Decimal128|Int64|ResolvesToNumber|float|int $input $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. * @param non-empty-string $method The method that mongod uses to calculate the 50th percentile value. The method must be 'approximate'. */ @@ -1243,6 +1564,9 @@ public static function median( } /** + * Combines multiple documents into a single document. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/mergeObjects/ * @param Document|ResolvesToObject|Serializable|array|stdClass ...$document Any valid expression that resolves to a document. */ public static function mergeObjects( @@ -1253,6 +1577,9 @@ public static function mergeObjects( } /** + * Access available per-document metadata related to the aggregation operation. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/meta/ * @param non-empty-string $keyword */ public static function meta(string $keyword): MetaAggregation @@ -1261,11 +1588,14 @@ public static function meta(string $keyword): MetaAggregation } /** + * Returns the milliseconds of a date as a number between 0 and 999. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/millisecond/ * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public static function millisecond( - \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|Optional|string $timezone = Optional::Undefined, ): MillisecondAggregation { @@ -1273,6 +1603,10 @@ public static function millisecond( } /** + * Returns the minimum value that results from applying an expression to each document. + * Changed in version 5.0: Available in the $setWindowFields stage. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/min/ * @param ExpressionInterface|mixed ...$expression */ public static function min(mixed ...$expression): MinAggregation @@ -1281,6 +1615,9 @@ public static function min(mixed ...$expression): MinAggregation } /** + * Returns the n smallest values in an array. Distinct from the $minN accumulator. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/minN-array-element/ * @param BSONArray|PackedArray|ResolvesToArray|list $input An expression that resolves to the array from which to return the maximal n elements. * @param Int64|ResolvesToInt|int $n An expression that resolves to a positive integer. The integer specifies the number of array elements that $maxN returns. */ @@ -1293,11 +1630,14 @@ public static function minN( } /** + * Returns the minute for a date as a number between 0 and 59. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/minute/ * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public static function minute( - \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|Optional|string $timezone = Optional::Undefined, ): MinuteAggregation { @@ -1305,6 +1645,9 @@ public static function minute( } /** + * Returns the remainder of the first number divided by the second. Accepts two argument expressions. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/mod/ * @param Decimal128|Int64|ResolvesToNumber|float|int $dividend The first argument is the dividend, and the second argument is the divisor; i.e. first argument is divided by the second argument. * @param Decimal128|Int64|ResolvesToNumber|float|int $divisor */ @@ -1317,11 +1660,14 @@ public static function mod( } /** + * Returns the month for a date as a number between 1 (January) and 12 (December). + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/month/ * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public static function month( - \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|Optional|string $timezone = Optional::Undefined, ): MonthAggregation { @@ -1329,6 +1675,9 @@ public static function month( } /** + * Multiplies numbers to return the product. Accepts any number of argument expressions. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/multiply/ * @param Decimal128|Int64|ResolvesToNumber|float|int ...$expression 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. */ @@ -1338,6 +1687,9 @@ public static function multiply(Decimal128|Int64|ResolvesToNumber|float|int ...$ } /** + * Returns true if the values are not equivalent. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/ne/ * @param ExpressionInterface|mixed $expression1 * @param ExpressionInterface|mixed $expression2 */ @@ -1347,6 +1699,9 @@ public static function ne(mixed $expression1, mixed $expression2): NeAggregation } /** + * Returns the boolean value that is the opposite of its argument expression. Accepts a single argument expression. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/not/ * @param ExpressionInterface|ResolvesToBool|bool|mixed $expression */ public static function not(mixed $expression): NotAggregation @@ -1355,6 +1710,9 @@ public static function not(mixed $expression): NotAggregation } /** + * Converts a document to an array of documents representing key-value pairs. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/objectToArray/ * @param Document|ResolvesToObject|Serializable|array|stdClass $object 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. */ public static function objectToArray( @@ -1365,6 +1723,9 @@ public static function objectToArray( } /** + * Returns true when any of its expressions evaluates to true. Accepts any number of argument expressions. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/or/ * @param ExpressionInterface|ResolvesToBool|bool|mixed ...$expression */ public static function or(mixed ...$expression): OrAggregation @@ -1373,6 +1734,17 @@ public static function or(mixed ...$expression): OrAggregation } /** + * Returns an array of scalar values that correspond to specified percentile values. + * New in version 7.0. + * + * This operator is available as an accumulator in these stages: + * $group + * + * $setWindowFields + * + * It is also available as an aggregation expression. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/percentile/ * @param Decimal128|Int64|ResolvesToNumber|float|int $input $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. * @param BSONArray|PackedArray|ResolvesToArray|list $p $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. @@ -1388,6 +1760,9 @@ public static function percentile( } /** + * Raises a number to the specified exponent. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/pow/ * @param Decimal128|Int64|ResolvesToNumber|float|int $number * @param Decimal128|Int64|ResolvesToNumber|float|int $exponent */ @@ -1400,6 +1775,10 @@ public static function pow( } /** + * Returns an array of values that result from applying an expression to each document. + * Changed in version 5.0: Available in the $setWindowFields stage. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/push/ * @param ExpressionInterface|mixed $expression */ public static function push(mixed $expression): PushAggregation @@ -1408,6 +1787,9 @@ public static function push(mixed $expression): PushAggregation } /** + * Converts a value from radians to degrees. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/radiansToDegrees/ * @param Decimal128|Int64|ResolvesToNumber|float|int $expression */ public static function radiansToDegrees( @@ -1417,12 +1799,20 @@ public static function radiansToDegrees( return new RadiansToDegreesAggregation($expression); } + /** + * Returns a random float between 0 and 1 + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/rand/ + */ public static function rand(): RandAggregation { return new RandAggregation(); } /** + * Outputs an array containing a sequence of integers according to user-defined inputs. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/range/ * @param Int64|ResolvesToInt|int $start An integer that specifies the start of the sequence. Can be any valid expression that resolves to an integer. * @param Int64|ResolvesToInt|int $end An integer that specifies the exclusive upper limit of the sequence. Can be any valid expression that resolves to an integer. * @param Int64|Optional|ResolvesToInt|int $step An integer that specifies the increment value. Can be any valid expression that resolves to a non-zero integer. Defaults to 1. @@ -1436,12 +1826,21 @@ public static function range( return new RangeAggregation($start, $end, $step); } + /** + * Returns the document position (known as the rank) relative to other documents in the $setWindowFields stage partition. + * New in version 5.0. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/rank/ + */ public static function rank(): RankAggregation { return new RankAggregation(); } /** + * Applies an expression to each element in an array and combines them into a single value. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/reduce/ * @param BSONArray|PackedArray|ResolvesToArray|list $input 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. @@ -1461,6 +1860,10 @@ public static function reduce( } /** + * Applies a regular expression (regex) to a string and returns information on the first matched substring. + * New in version 4.2. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/regexFind/ * @param ResolvesToString|non-empty-string $input The string on which you wish to apply the regex pattern. Can be a string or any valid expression that resolves to a string. * @param Regex|ResolvesToString|non-empty-string $regex 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) * @param Optional|non-empty-string $options @@ -1475,6 +1878,10 @@ public static function regexFind( } /** + * Applies a regular expression (regex) to a string and returns information on the all matched substrings. + * New in version 4.2. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/regexFindAll/ * @param ResolvesToString|non-empty-string $input The string on which you wish to apply the regex pattern. Can be a string or any valid expression that resolves to a string. * @param Regex|ResolvesToString|non-empty-string $regex 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) * @param Optional|non-empty-string $options @@ -1489,6 +1896,10 @@ public static function regexFindAll( } /** + * Applies a regular expression (regex) to a string and returns a boolean that indicates if a match is found or not. + * New in version 4.2. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/regexMatch/ * @param ResolvesToString|non-empty-string $input The string on which you wish to apply the regex pattern. Can be a string or any valid expression that resolves to a string. * @param Regex|ResolvesToString|non-empty-string $regex 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) * @param Optional|non-empty-string $options @@ -1503,6 +1914,11 @@ public static function regexMatch( } /** + * Replaces all instances of a search string in an input string with a replacement string. + * $replaceAll is both case-sensitive and diacritic-sensitive, and ignores any collation present on a collection. + * New in version 4.4. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceAll/ * @param ResolvesToNull|ResolvesToString|non-empty-string|null $input 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. * @param ResolvesToNull|ResolvesToString|non-empty-string|null $find 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. * @param ResolvesToNull|ResolvesToString|non-empty-string|null $replacement 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. @@ -1517,6 +1933,10 @@ public static function replaceAll( } /** + * Replaces the first instance of a matched string in a given input. + * New in version 4.4. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceOne/ * @param ResolvesToNull|ResolvesToString|non-empty-string|null $input 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. * @param ResolvesToNull|ResolvesToString|non-empty-string|null $find 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. * @param ResolvesToNull|ResolvesToString|non-empty-string|null $replacement 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. @@ -1531,6 +1951,9 @@ public static function replaceOne( } /** + * Returns an array with the elements in reverse order. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/reverseArray/ * @param BSONArray|PackedArray|ResolvesToArray|list $expression The argument can be any valid expression as long as it resolves to an array. */ public static function reverseArray( @@ -1541,6 +1964,9 @@ public static function reverseArray( } /** + * Rounds a number to to a whole integer or to a specified decimal place. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/round/ * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|float|int $number 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. * @param Int64|Optional|ResolvesToInt|int $place Can be any valid expression that resolves to an integer between -20 and 100, exclusive. @@ -1554,6 +1980,9 @@ public static function round( } /** + * Removes whitespace characters, including null, or the specified characters from the end of a string. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/rtrim/ * @param ResolvesToString|non-empty-string $input The string to trim. The argument can be any valid expression that resolves to a string. * @param Optional|ResolvesToString|non-empty-string $chars 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. @@ -1568,6 +1997,9 @@ public static function rtrim( } /** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/sampleRate/ * @param Int64|ResolvesToFloat|float|int $rate 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. */ @@ -1577,11 +2009,14 @@ public static function sampleRate(Int64|ResolvesToFloat|float|int $rate): Sample } /** + * Returns the seconds for a date as a number between 0 and 60 (leap seconds). + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/second/ * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public static function second( - \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|Optional|string $timezone = Optional::Undefined, ): SecondAggregation { @@ -1589,6 +2024,9 @@ public static function second( } /** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/setDifference/ * @param BSONArray|PackedArray|ResolvesToArray|list $expression1 The arguments can be any valid expression as long as they each resolve to an array. * @param BSONArray|PackedArray|ResolvesToArray|list $expression2 The arguments can be any valid expression as long as they each resolve to an array. */ @@ -1601,6 +2039,9 @@ public static function setDifference( } /** + * Returns true if the input sets have the same distinct elements. Accepts two or more argument expressions. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/setEquals/ * @param BSONArray|PackedArray|ResolvesToArray|list ...$expression */ public static function setEquals(PackedArray|ResolvesToArray|BSONArray|array ...$expression): SetEqualsAggregation @@ -1609,6 +2050,10 @@ public static function setEquals(PackedArray|ResolvesToArray|BSONArray|array ... } /** + * 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 version 5.0. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/setField/ * @param ResolvesToString|non-empty-string $field 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. * @param Document|ResolvesToObject|Serializable|array|stdClass $input Document that contains the field that you want to add or update. input must resolve to an object, missing, null, or undefined. * @param ExpressionInterface|mixed $value The value that you want to assign to field. value can be any valid expression. @@ -1624,6 +2069,9 @@ public static function setField( } /** + * Returns a set with elements that appear in all of the input sets. Accepts any number of argument expressions. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/setIntersection/ * @param BSONArray|PackedArray|ResolvesToArray|list ...$expression */ public static function setIntersection( @@ -1634,6 +2082,9 @@ public static function setIntersection( } /** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/setIsSubset/ * @param BSONArray|PackedArray|ResolvesToArray|list $expression1 * @param BSONArray|PackedArray|ResolvesToArray|list $expression2 */ @@ -1646,6 +2097,9 @@ public static function setIsSubset( } /** + * Returns a set with elements that appear in any of the input sets. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/setUnion/ * @param BSONArray|PackedArray|ResolvesToArray|list ...$expression */ public static function setUnion(PackedArray|ResolvesToArray|BSONArray|array ...$expression): SetUnionAggregation @@ -1654,6 +2108,10 @@ public static function setUnion(PackedArray|ResolvesToArray|BSONArray|array ...$ } /** + * 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 version 5.0. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/shift/ * @param ExpressionInterface|mixed $output Specifies an expression to evaluate and return in the output. * @param Int64|int $by Specifies an integer with a numeric document position relative to the current document in the output. * For example: @@ -1670,6 +2128,9 @@ public static function shift(mixed $output, Int64|int $by, mixed $default): Shif } /** + * Returns the sine of a value that is measured in radians. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/sin/ * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $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. */ @@ -1679,6 +2140,9 @@ public static function sin(Decimal128|Int64|ResolvesToNumber|float|int $expressi } /** + * Returns the hyperbolic sine of a value that is measured in radians. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/sinh/ * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $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. */ @@ -1688,6 +2152,9 @@ public static function sinh(Decimal128|Int64|ResolvesToNumber|float|int $express } /** + * Returns the number of elements in the array. Accepts a single expression as argument. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/size/ * @param BSONArray|PackedArray|ResolvesToArray|list $expression The argument for $size can be any expression as long as it resolves to an array. */ public static function size(PackedArray|ResolvesToArray|BSONArray|array $expression): SizeAggregation @@ -1696,6 +2163,9 @@ public static function size(PackedArray|ResolvesToArray|BSONArray|array $express } /** + * Returns a subset of an array. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/slice/ * @param BSONArray|PackedArray|ResolvesToArray|list $expression Any valid expression as long as it resolves to an array. * @param Int64|ResolvesToInt|int $n 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. @@ -1714,6 +2184,9 @@ public static function slice( } /** + * Sorts the elements of an array. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/sortArray/ * @param BSONArray|PackedArray|ResolvesToArray|list $input The array to be sorted. * @param array|stdClass $sortBy The document specifies a sort ordering. */ @@ -1726,6 +2199,9 @@ public static function sortArray( } /** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/split/ * @param ResolvesToString|non-empty-string $string The string to be split. string expression can be any valid expression as long as it resolves to a string. * @param ResolvesToString|non-empty-string $delimiter The delimiter to use when splitting the string expression. delimiter can be any valid expression as long as it resolves to a string. */ @@ -1738,6 +2214,9 @@ public static function split( } /** + * Calculates the square root. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/sqrt/ * @param Decimal128|Int64|ResolvesToNumber|float|int $number The argument can be any valid expression as long as it resolves to a non-negative number. */ public static function sqrt(Decimal128|Int64|ResolvesToNumber|float|int $number): SqrtAggregation @@ -1746,6 +2225,11 @@ public static function sqrt(Decimal128|Int64|ResolvesToNumber|float|int $number) } /** + * Calculates the population standard deviation of the input values. Use if the values encompass the entire population of data you want to represent and do not wish to generalize about a larger population. $stdDevPop ignores non-numeric values. + * If the values represent only a sample of a population of data from which to generalize about the population, use $stdDevSamp instead. + * Changed in version 5.0: Available in the $setWindowFields stage. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/stdDevPop/ * @param Decimal128|Int64|ResolvesToNumber|float|int ...$expression */ public static function stdDevPop(Decimal128|Int64|ResolvesToNumber|float|int ...$expression): StdDevPopAggregation @@ -1754,6 +2238,11 @@ public static function stdDevPop(Decimal128|Int64|ResolvesToNumber|float|int ... } /** + * Calculates the sample standard deviation of the input values. Use if the values encompass a sample of a population of data from which to generalize about the population. $stdDevSamp ignores non-numeric values. + * If the values represent the entire population of data or you do not wish to generalize about a larger population, use $stdDevPop instead. + * Changed in version 5.0: Available in the $setWindowFields stage. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/stdDevSamp/ * @param Decimal128|Int64|ResolvesToNumber|float|int ...$expression */ public static function stdDevSamp( @@ -1764,6 +2253,9 @@ public static function stdDevSamp( } /** + * Returns the number of UTF-8 encoded bytes in a string. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/strLenBytes/ * @param ResolvesToString|non-empty-string $expression */ public static function strLenBytes(ResolvesToString|string $expression): StrLenBytesAggregation @@ -1772,6 +2264,9 @@ public static function strLenBytes(ResolvesToString|string $expression): StrLenB } /** + * Returns the number of UTF-8 code points in a string. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/strLenCP/ * @param ResolvesToString|non-empty-string $expression */ public static function strLenCP(ResolvesToString|string $expression): StrLenCPAggregation @@ -1780,6 +2275,9 @@ public static function strLenCP(ResolvesToString|string $expression): StrLenCPAg } /** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/strcasecmp/ * @param ResolvesToString|non-empty-string $expression1 * @param ResolvesToString|non-empty-string $expression2 */ @@ -1792,6 +2290,9 @@ public static function strcasecmp( } /** + * Deprecated. Use $substrBytes or $substrCP. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/substr/ * @param ResolvesToString|non-empty-string $string * @param Int64|ResolvesToInt|int $start If start is a negative number, $substr returns an empty string "". * @param Int64|ResolvesToInt|int $length If length is a negative number, $substr returns a substring that starts at the specified index and includes the rest of the string. @@ -1806,6 +2307,9 @@ public static function substr( } /** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/substrBytes/ * @param ResolvesToString|non-empty-string $string * @param Int64|ResolvesToInt|int $start If start is a negative number, $substr returns an empty string "". * @param Int64|ResolvesToInt|int $length If length is a negative number, $substr returns a substring that starts at the specified index and includes the rest of the string. @@ -1820,6 +2324,9 @@ public static function substrBytes( } /** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/substrCP/ * @param ResolvesToString|non-empty-string $string * @param Int64|ResolvesToInt|int $start If start is a negative number, $substr returns an empty string "". * @param Int64|ResolvesToInt|int $length If length is a negative number, $substr returns a substring that starts at the specified index and includes the rest of the string. @@ -1834,18 +2341,25 @@ public static function substrCP( } /** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/subtract/ * @param DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int $expression1 * @param DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int $expression2 */ public static function subtract( - \UTCDateTime|DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|float|int $expression1, - \UTCDateTime|DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|float|int $expression2, + DateTimeInterface|Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int $expression1, + DateTimeInterface|Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int $expression2, ): SubtractAggregation { return new SubtractAggregation($expression1, $expression2); } /** + * Returns a sum of numerical values. Ignores non-numeric values. + * Changed in version 5.0: Available in the $setWindowFields stage. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/sum/ * @param Decimal128|Int64|ResolvesToNumber|float|int ...$expression */ public static function sum(Decimal128|Int64|ResolvesToNumber|float|int ...$expression): SumAggregation @@ -1854,6 +2368,9 @@ public static function sum(Decimal128|Int64|ResolvesToNumber|float|int ...$expre } /** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/switch/ * @param BSONArray|PackedArray|list $branches 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. @@ -1870,6 +2387,9 @@ public static function switch( } /** + * Returns the tangent of a value that is measured in radians. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/tan/ * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $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. */ @@ -1879,6 +2399,9 @@ public static function tan(Decimal128|Int64|ResolvesToNumber|float|int $expressi } /** + * Returns the hyperbolic tangent of a value that is measured in radians. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/tanh/ * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $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. */ @@ -1888,6 +2411,10 @@ public static function tanh(Decimal128|Int64|ResolvesToNumber|float|int $express } /** + * Converts value to a boolean. + * New in version 4.0. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toBool/ * @param ExpressionInterface|mixed $expression */ public static function toBool(mixed $expression): ToBoolAggregation @@ -1896,6 +2423,10 @@ public static function toBool(mixed $expression): ToBoolAggregation } /** + * Converts value to a Date. + * New in version 4.0. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toDate/ * @param ExpressionInterface|mixed $expression */ public static function toDate(mixed $expression): ToDateAggregation @@ -1904,6 +2435,10 @@ public static function toDate(mixed $expression): ToDateAggregation } /** + * Converts value to a Decimal128. + * New in version 4.0. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toDecimal/ * @param ExpressionInterface|mixed $expression */ public static function toDecimal(mixed $expression): ToDecimalAggregation @@ -1912,6 +2447,10 @@ public static function toDecimal(mixed $expression): ToDecimalAggregation } /** + * Converts value to a double. + * New in version 4.0. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toDouble/ * @param ExpressionInterface|mixed $expression */ public static function toDouble(mixed $expression): ToDoubleAggregation @@ -1920,6 +2459,10 @@ public static function toDouble(mixed $expression): ToDoubleAggregation } /** + * Converts value to an integer. + * New in version 4.0. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toInt/ * @param ExpressionInterface|mixed $expression */ public static function toInt(mixed $expression): ToIntAggregation @@ -1928,6 +2471,10 @@ public static function toInt(mixed $expression): ToIntAggregation } /** + * Converts value to a long. + * New in version 4.0. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toLong/ * @param ExpressionInterface|mixed $expression */ public static function toLong(mixed $expression): ToLongAggregation @@ -1936,6 +2483,9 @@ public static function toLong(mixed $expression): ToLongAggregation } /** + * Converts a string to lowercase. Accepts a single argument expression. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toLower/ * @param ResolvesToString|non-empty-string $expression */ public static function toLower(ResolvesToString|string $expression): ToLowerAggregation @@ -1944,6 +2494,10 @@ public static function toLower(ResolvesToString|string $expression): ToLowerAggr } /** + * Converts value to an ObjectId. + * New in version 4.0. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toObjectId/ * @param ExpressionInterface|mixed $expression */ public static function toObjectId(mixed $expression): ToObjectIdAggregation @@ -1952,6 +2506,10 @@ public static function toObjectId(mixed $expression): ToObjectIdAggregation } /** + * Converts value to a string. + * New in version 4.0. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toString/ * @param ExpressionInterface|mixed $expression */ public static function toString(mixed $expression): ToStringAggregation @@ -1960,6 +2518,9 @@ public static function toString(mixed $expression): ToStringAggregation } /** + * Converts a string to uppercase. Accepts a single argument expression. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toUpper/ * @param ResolvesToString|non-empty-string $expression */ public static function toUpper(ResolvesToString|string $expression): ToUpperAggregation @@ -1968,6 +2529,12 @@ public static function toUpper(ResolvesToString|string $expression): ToUpperAggr } /** + * Returns the top element within a group according to the specified sort order. + * New in version 5.2. + * + * Available in the $group and $setWindowFields stages. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/top/ * @param array|stdClass $sortBy Specifies the order of results, with syntax similar to $sort. * @param ExpressionInterface|mixed $output Represents the output for each element in the group and can be any expression. */ @@ -1977,6 +2544,12 @@ public static function top(stdClass|array $sortBy, mixed $output): TopAggregatio } /** + * Returns an aggregation of the top n fields within a group, according to the specified sort order. + * New in version 5.2. + * + * Available in the $group and $setWindowFields stages. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/topN/ * @param Int64|ResolvesToInt|int $n 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. * @param array|stdClass $sortBy Specifies the order of results, with syntax similar to $sort. * @param ExpressionInterface|mixed $output Represents the output for each element in the group and can be any expression. @@ -1987,6 +2560,10 @@ public static function topN(Int64|ResolvesToInt|int $n, stdClass|array $sortBy, } /** + * Removes whitespace or the specified characters from the beginning and end of a string. + * New in version 4.0. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/trim/ * @param ResolvesToString|non-empty-string $input The string to trim. The argument can be any valid expression that resolves to a string. * @param Optional|ResolvesToString|non-empty-string $chars 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. @@ -2001,6 +2578,9 @@ public static function trim( } /** + * Truncates a number to a whole integer or to a specified decimal place. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/trunc/ * @param Decimal128|Int64|ResolvesToNumber|float|int $number 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. * @param Int64|Optional|ResolvesToInt|int $place Can be any valid expression that resolves to an integer between -20 and 100, exclusive. e.g. -20 < place < 100. Defaults to 0. @@ -2014,6 +2594,10 @@ public static function trunc( } /** + * Returns the incrementing ordinal from a timestamp as a long. + * New in version 5.1. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/tsIncrement/ * @param Int64|ResolvesToTimestamp|int $expression */ public static function tsIncrement(Int64|ResolvesToTimestamp|int $expression): TsIncrementAggregation @@ -2022,6 +2606,10 @@ public static function tsIncrement(Int64|ResolvesToTimestamp|int $expression): T } /** + * Returns the seconds from a timestamp as a long. + * New in version 5.1. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/tsSecond/ * @param Int64|ResolvesToTimestamp|int $expression */ public static function tsSecond(Int64|ResolvesToTimestamp|int $expression): TsSecondAggregation @@ -2030,6 +2618,9 @@ public static function tsSecond(Int64|ResolvesToTimestamp|int $expression): TsSe } /** + * Return the BSON data type of the field. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/type/ * @param ExpressionInterface|mixed $expression */ public static function type(mixed $expression): TypeAggregation @@ -2038,6 +2629,10 @@ public static function type(mixed $expression): TypeAggregation } /** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/unsetField/ * @param ResolvesToString|non-empty-string $field 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. * @param Document|ResolvesToObject|Serializable|array|stdClass $input Document that contains the field that you want to add or update. input must resolve to an object, missing, null, or undefined. */ @@ -2050,11 +2645,14 @@ public static function unsetField( } /** + * 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). + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/week/ * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public static function week( - \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|Optional|string $timezone = Optional::Undefined, ): WeekAggregation { @@ -2062,11 +2660,14 @@ public static function week( } /** + * Returns the year for a date as a number (e.g. 2014). + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/year/ * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public static function year( - \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|Optional|string $timezone = Optional::Undefined, ): YearAggregation { @@ -2074,6 +2675,9 @@ public static function year( } /** + * Merge two arrays together. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/zip/ * @param BSONArray|PackedArray|ResolvesToArray|list $inputs 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. diff --git a/src/Builder/Aggregation/AbsAggregation.php b/src/Builder/Aggregation/AbsAggregation.php index 35940f1c6..0632f071e 100644 --- a/src/Builder/Aggregation/AbsAggregation.php +++ b/src/Builder/Aggregation/AbsAggregation.php @@ -11,6 +11,11 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToNumber; +/** + * Returns the absolute value of a number. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/abs/ + */ class AbsAggregation implements ResolvesToNumber { public const NAME = '$abs'; diff --git a/src/Builder/Aggregation/AccumulatorAggregation.php b/src/Builder/Aggregation/AccumulatorAggregation.php index bb517d4c4..0385b514a 100644 --- a/src/Builder/Aggregation/AccumulatorAggregation.php +++ b/src/Builder/Aggregation/AccumulatorAggregation.php @@ -13,6 +13,12 @@ use MongoDB\Builder\Optional; use MongoDB\Model\BSONArray; +/** + * Defines a custom accumulator function. + * New in version 4.4. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/accumulator/ + */ class AccumulatorAggregation implements AccumulatorInterface { public const NAME = '$accumulator'; diff --git a/src/Builder/Aggregation/AcosAggregation.php b/src/Builder/Aggregation/AcosAggregation.php index 56f67de4c..256bf4bb4 100644 --- a/src/Builder/Aggregation/AcosAggregation.php +++ b/src/Builder/Aggregation/AcosAggregation.php @@ -13,6 +13,11 @@ use MongoDB\Builder\Expression\ResolvesToDouble; use MongoDB\Builder\Expression\ResolvesToNumber; +/** + * Returns the inverse cosine (arc cosine) of a value in radians. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/acos/ + */ class AcosAggregation implements ResolvesToDouble, ResolvesToDecimal { public const NAME = '$acos'; diff --git a/src/Builder/Aggregation/AcoshAggregation.php b/src/Builder/Aggregation/AcoshAggregation.php index 0afe249c5..2b54ba690 100644 --- a/src/Builder/Aggregation/AcoshAggregation.php +++ b/src/Builder/Aggregation/AcoshAggregation.php @@ -13,6 +13,11 @@ use MongoDB\Builder\Expression\ResolvesToDouble; use MongoDB\Builder\Expression\ResolvesToNumber; +/** + * Returns the inverse hyperbolic cosine (hyperbolic arc cosine) of a value in radians. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/acosh/ + */ class AcoshAggregation implements ResolvesToDouble, ResolvesToDecimal { public const NAME = '$acosh'; diff --git a/src/Builder/Aggregation/AddAggregation.php b/src/Builder/Aggregation/AddAggregation.php index bd0d356a6..37889074d 100644 --- a/src/Builder/Aggregation/AddAggregation.php +++ b/src/Builder/Aggregation/AddAggregation.php @@ -9,10 +9,16 @@ use DateTimeInterface; use MongoDB\BSON\Decimal128; use MongoDB\BSON\Int64; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToDate; use MongoDB\Builder\Expression\ResolvesToNumber; +/** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/add/ + */ class AddAggregation implements ResolvesToNumber, ResolvesToDate { public const NAME = '$add'; @@ -28,7 +34,7 @@ class AddAggregation implements ResolvesToNumber, ResolvesToDate * @param DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int ...$expression The arguments can be any valid expression as long as they resolve to either all numbers or to numbers and a date. */ public function __construct( - \UTCDateTime|DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|float|int ...$expression, + DateTimeInterface|Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int ...$expression, ) { if (\count($expression) < 1) { throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); diff --git a/src/Builder/Aggregation/AddToSetAggregation.php b/src/Builder/Aggregation/AddToSetAggregation.php index 7f999c4db..ede4a02ab 100644 --- a/src/Builder/Aggregation/AddToSetAggregation.php +++ b/src/Builder/Aggregation/AddToSetAggregation.php @@ -10,6 +10,12 @@ use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\FieldPath; +/** + * Returns an array of unique expression values for each group. Order of the array elements is undefined. + * Changed in version 5.0: Available in the $setWindowFields stage. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/addToSet/ + */ class AddToSetAggregation implements AccumulatorInterface { public const NAME = '$addToSet'; diff --git a/src/Builder/Aggregation/AllElementsTrueAggregation.php b/src/Builder/Aggregation/AllElementsTrueAggregation.php index 633071a5e..05f4d8581 100644 --- a/src/Builder/Aggregation/AllElementsTrueAggregation.php +++ b/src/Builder/Aggregation/AllElementsTrueAggregation.php @@ -13,6 +13,11 @@ use MongoDB\Builder\Expression\ResolvesToBool; use MongoDB\Model\BSONArray; +/** + * Returns true if no element of a set evaluates to false, otherwise, returns false. Accepts a single argument expression. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/allElementsTrue/ + */ class AllElementsTrueAggregation implements ResolvesToBool { public const NAME = '$allElementsTrue'; diff --git a/src/Builder/Aggregation/AndAggregation.php b/src/Builder/Aggregation/AndAggregation.php index ae462a689..994062df0 100644 --- a/src/Builder/Aggregation/AndAggregation.php +++ b/src/Builder/Aggregation/AndAggregation.php @@ -15,6 +15,11 @@ use MongoDB\Builder\Expression\ResolvesToNumber; use MongoDB\Builder\Expression\ResolvesToString; +/** + * Returns true only when all its expressions evaluate to true. Accepts any number of argument expressions. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/and/ + */ class AndAggregation implements ResolvesToBool { public const NAME = '$and'; diff --git a/src/Builder/Aggregation/AnyElementTrueAggregation.php b/src/Builder/Aggregation/AnyElementTrueAggregation.php index b81d410e0..070266a95 100644 --- a/src/Builder/Aggregation/AnyElementTrueAggregation.php +++ b/src/Builder/Aggregation/AnyElementTrueAggregation.php @@ -13,6 +13,11 @@ use MongoDB\Builder\Expression\ResolvesToBool; use MongoDB\Model\BSONArray; +/** + * Returns true if any elements of a set evaluate to true; otherwise, returns false. Accepts a single argument expression. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/anyElementTrue/ + */ class AnyElementTrueAggregation implements ResolvesToBool { public const NAME = '$anyElementTrue'; diff --git a/src/Builder/Aggregation/ArrayElemAtAggregation.php b/src/Builder/Aggregation/ArrayElemAtAggregation.php index 8ab4bdb35..08d9d4d00 100644 --- a/src/Builder/Aggregation/ArrayElemAtAggregation.php +++ b/src/Builder/Aggregation/ArrayElemAtAggregation.php @@ -14,6 +14,11 @@ use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Model\BSONArray; +/** + * Returns the element at the specified array index. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/arrayElemAt/ + */ class ArrayElemAtAggregation implements ExpressionInterface { public const NAME = '$arrayElemAt'; diff --git a/src/Builder/Aggregation/ArrayToObjectAggregation.php b/src/Builder/Aggregation/ArrayToObjectAggregation.php index dd63a696d..33acea0ab 100644 --- a/src/Builder/Aggregation/ArrayToObjectAggregation.php +++ b/src/Builder/Aggregation/ArrayToObjectAggregation.php @@ -13,6 +13,11 @@ use MongoDB\Builder\Expression\ResolvesToObject; use MongoDB\Model\BSONArray; +/** + * Converts an array of key value pairs to a document. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/arrayToObject/ + */ class ArrayToObjectAggregation implements ResolvesToObject { public const NAME = '$arrayToObject'; diff --git a/src/Builder/Aggregation/AsinAggregation.php b/src/Builder/Aggregation/AsinAggregation.php index 8a9adb214..c7e61661a 100644 --- a/src/Builder/Aggregation/AsinAggregation.php +++ b/src/Builder/Aggregation/AsinAggregation.php @@ -13,6 +13,11 @@ use MongoDB\Builder\Expression\ResolvesToDouble; use MongoDB\Builder\Expression\ResolvesToNumber; +/** + * Returns the inverse sin (arc sine) of a value in radians. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/asin/ + */ class AsinAggregation implements ResolvesToDouble, ResolvesToDecimal { public const NAME = '$asin'; diff --git a/src/Builder/Aggregation/AsinhAggregation.php b/src/Builder/Aggregation/AsinhAggregation.php index f0794e00d..9a7b51893 100644 --- a/src/Builder/Aggregation/AsinhAggregation.php +++ b/src/Builder/Aggregation/AsinhAggregation.php @@ -13,6 +13,11 @@ use MongoDB\Builder\Expression\ResolvesToDouble; use MongoDB\Builder\Expression\ResolvesToNumber; +/** + * Returns the inverse hyperbolic sine (hyperbolic arc sine) of a value in radians. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/asinh/ + */ class AsinhAggregation implements ResolvesToDouble, ResolvesToDecimal { public const NAME = '$asinh'; diff --git a/src/Builder/Aggregation/Atan2Aggregation.php b/src/Builder/Aggregation/Atan2Aggregation.php index f0171394d..e6174b865 100644 --- a/src/Builder/Aggregation/Atan2Aggregation.php +++ b/src/Builder/Aggregation/Atan2Aggregation.php @@ -13,6 +13,11 @@ use MongoDB\Builder\Expression\ResolvesToDouble; use MongoDB\Builder\Expression\ResolvesToNumber; +/** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/atan2/ + */ class Atan2Aggregation implements ResolvesToDouble, ResolvesToDecimal { public const NAME = '$atan2'; diff --git a/src/Builder/Aggregation/AtanAggregation.php b/src/Builder/Aggregation/AtanAggregation.php index bd3e24190..69757ea20 100644 --- a/src/Builder/Aggregation/AtanAggregation.php +++ b/src/Builder/Aggregation/AtanAggregation.php @@ -13,6 +13,11 @@ use MongoDB\Builder\Expression\ResolvesToDouble; use MongoDB\Builder\Expression\ResolvesToNumber; +/** + * Returns the inverse tangent (arc tangent) of a value in radians. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/atan/ + */ class AtanAggregation implements ResolvesToDouble, ResolvesToDecimal { public const NAME = '$atan'; diff --git a/src/Builder/Aggregation/AtanhAggregation.php b/src/Builder/Aggregation/AtanhAggregation.php index 958d2dccb..a82897aa6 100644 --- a/src/Builder/Aggregation/AtanhAggregation.php +++ b/src/Builder/Aggregation/AtanhAggregation.php @@ -13,6 +13,11 @@ use MongoDB\Builder\Expression\ResolvesToDouble; use MongoDB\Builder\Expression\ResolvesToNumber; +/** + * Returns the inverse hyperbolic tangent (hyperbolic arc tangent) of a value in radians. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/atanh/ + */ class AtanhAggregation implements ResolvesToDouble, ResolvesToDecimal { public const NAME = '$atanh'; diff --git a/src/Builder/Aggregation/AvgAggregation.php b/src/Builder/Aggregation/AvgAggregation.php index 728ac4066..71a1ca957 100644 --- a/src/Builder/Aggregation/AvgAggregation.php +++ b/src/Builder/Aggregation/AvgAggregation.php @@ -11,6 +11,12 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToNumber; +/** + * Returns an average of numerical values. Ignores non-numeric values. + * Changed in version 5.0: Available in the $setWindowFields stage. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/avg/ + */ class AvgAggregation implements ResolvesToNumber, AccumulatorInterface { public const NAME = '$avg'; diff --git a/src/Builder/Aggregation/BinarySizeAggregation.php b/src/Builder/Aggregation/BinarySizeAggregation.php index 1cfa3f00c..17dc0443b 100644 --- a/src/Builder/Aggregation/BinarySizeAggregation.php +++ b/src/Builder/Aggregation/BinarySizeAggregation.php @@ -13,6 +13,11 @@ use MongoDB\Builder\Expression\ResolvesToNull; use MongoDB\Builder\Expression\ResolvesToString; +/** + * Returns the size of a given string or binary data value's content in bytes. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/binarySize/ + */ class BinarySizeAggregation implements ResolvesToInt { public const NAME = '$binarySize'; diff --git a/src/Builder/Aggregation/BitAndAggregation.php b/src/Builder/Aggregation/BitAndAggregation.php index dd4931dcc..8c56abda3 100644 --- a/src/Builder/Aggregation/BitAndAggregation.php +++ b/src/Builder/Aggregation/BitAndAggregation.php @@ -11,6 +11,12 @@ use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Expression\ResolvesToLong; +/** + * Returns the result of a bitwise and operation on an array of int or long values. + * New in version 6.3. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitAnd/ + */ class BitAndAggregation implements ResolvesToInt, ResolvesToLong { public const NAME = '$bitAnd'; diff --git a/src/Builder/Aggregation/BitNotAggregation.php b/src/Builder/Aggregation/BitNotAggregation.php index 40c99728d..8997c25bf 100644 --- a/src/Builder/Aggregation/BitNotAggregation.php +++ b/src/Builder/Aggregation/BitNotAggregation.php @@ -11,6 +11,12 @@ use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Expression\ResolvesToLong; +/** + * 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 version 6.3. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitNot/ + */ class BitNotAggregation implements ResolvesToInt, ResolvesToLong { public const NAME = '$bitNot'; diff --git a/src/Builder/Aggregation/BitOrAggregation.php b/src/Builder/Aggregation/BitOrAggregation.php index df35fae7b..47bf61af2 100644 --- a/src/Builder/Aggregation/BitOrAggregation.php +++ b/src/Builder/Aggregation/BitOrAggregation.php @@ -11,6 +11,12 @@ use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Expression\ResolvesToLong; +/** + * Returns the result of a bitwise or operation on an array of int or long values. + * New in version 6.3. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitOr/ + */ class BitOrAggregation implements ResolvesToInt, ResolvesToLong { public const NAME = '$bitOr'; diff --git a/src/Builder/Aggregation/BitXorAggregation.php b/src/Builder/Aggregation/BitXorAggregation.php index bfcc45169..00f7a8840 100644 --- a/src/Builder/Aggregation/BitXorAggregation.php +++ b/src/Builder/Aggregation/BitXorAggregation.php @@ -10,6 +10,12 @@ use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Expression\ResolvesToLong; +/** + * Returns the result of a bitwise xor (exclusive or) operation on an array of int and long values. + * New in version 6.3. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitXor/ + */ class BitXorAggregation implements ResolvesToInt, ResolvesToLong { public const NAME = '$bitXor'; diff --git a/src/Builder/Aggregation/BottomAggregation.php b/src/Builder/Aggregation/BottomAggregation.php index a62f2c9e1..4938ec732 100644 --- a/src/Builder/Aggregation/BottomAggregation.php +++ b/src/Builder/Aggregation/BottomAggregation.php @@ -10,6 +10,14 @@ use MongoDB\Builder\Expression\ExpressionInterface; use stdClass; +/** + * Returns the bottom element within a group according to the specified sort order. + * New in version 5.2. + * + * Available in the $group and $setWindowFields stages. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/bottom/ + */ class BottomAggregation implements AccumulatorInterface { public const NAME = '$bottom'; diff --git a/src/Builder/Aggregation/BottomNAggregation.php b/src/Builder/Aggregation/BottomNAggregation.php index 96324246d..99678051b 100644 --- a/src/Builder/Aggregation/BottomNAggregation.php +++ b/src/Builder/Aggregation/BottomNAggregation.php @@ -12,6 +12,13 @@ use MongoDB\Builder\Expression\ResolvesToInt; use stdClass; +/** + * Returns an aggregation of the bottom n elements within a group, according to the specified sort order. If the group contains fewer than n elements, $bottomN returns all elements in the group. + * New in version 5.2. + * Available in the $group and $setWindowFields stages. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/bottomN/ + */ class BottomNAggregation implements AccumulatorInterface { public const NAME = '$bottomN'; diff --git a/src/Builder/Aggregation/BsonSizeAggregation.php b/src/Builder/Aggregation/BsonSizeAggregation.php index 55045aa19..a4bdc9407 100644 --- a/src/Builder/Aggregation/BsonSizeAggregation.php +++ b/src/Builder/Aggregation/BsonSizeAggregation.php @@ -14,6 +14,11 @@ use MongoDB\Builder\Expression\ResolvesToObject; use stdClass; +/** + * Returns the size in bytes of a given document (i.e. bsontype Object) when encoded as BSON. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/bsonSize/ + */ class BsonSizeAggregation implements ResolvesToInt { public const NAME = '$bsonSize'; diff --git a/src/Builder/Aggregation/CeilAggregation.php b/src/Builder/Aggregation/CeilAggregation.php index 6325b94e5..1c0e29596 100644 --- a/src/Builder/Aggregation/CeilAggregation.php +++ b/src/Builder/Aggregation/CeilAggregation.php @@ -12,6 +12,11 @@ use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Expression\ResolvesToNumber; +/** + * Returns the smallest integer greater than or equal to the specified number. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/ceil/ + */ class CeilAggregation implements ResolvesToInt { public const NAME = '$ceil'; diff --git a/src/Builder/Aggregation/CmpAggregation.php b/src/Builder/Aggregation/CmpAggregation.php index 96601310b..e620d9c18 100644 --- a/src/Builder/Aggregation/CmpAggregation.php +++ b/src/Builder/Aggregation/CmpAggregation.php @@ -10,6 +10,11 @@ use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToInt; +/** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/cmp/ + */ class CmpAggregation implements ResolvesToInt { public const NAME = '$cmp'; diff --git a/src/Builder/Aggregation/ConcatAggregation.php b/src/Builder/Aggregation/ConcatAggregation.php index bbc895a27..5c978ea79 100644 --- a/src/Builder/Aggregation/ConcatAggregation.php +++ b/src/Builder/Aggregation/ConcatAggregation.php @@ -9,6 +9,11 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToString; +/** + * Concatenates any number of strings. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/concat/ + */ class ConcatAggregation implements ResolvesToString { public const NAME = '$concat'; diff --git a/src/Builder/Aggregation/ConcatArraysAggregation.php b/src/Builder/Aggregation/ConcatArraysAggregation.php index 9fedd47ca..f0b66e7a5 100644 --- a/src/Builder/Aggregation/ConcatArraysAggregation.php +++ b/src/Builder/Aggregation/ConcatArraysAggregation.php @@ -12,6 +12,11 @@ use MongoDB\Builder\Expression\ResolvesToArray; use MongoDB\Model\BSONArray; +/** + * Concatenates arrays to return the concatenated array. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/concatArrays/ + */ class ConcatArraysAggregation implements ResolvesToArray { public const NAME = '$concatArrays'; diff --git a/src/Builder/Aggregation/CondAggregation.php b/src/Builder/Aggregation/CondAggregation.php index d31e909a4..cbc9a0ea2 100644 --- a/src/Builder/Aggregation/CondAggregation.php +++ b/src/Builder/Aggregation/CondAggregation.php @@ -10,6 +10,11 @@ use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToBool; +/** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/cond/ + */ class CondAggregation implements ExpressionInterface { public const NAME = '$cond'; diff --git a/src/Builder/Aggregation/ConvertAggregation.php b/src/Builder/Aggregation/ConvertAggregation.php index 555b9be5d..add9a80e7 100644 --- a/src/Builder/Aggregation/ConvertAggregation.php +++ b/src/Builder/Aggregation/ConvertAggregation.php @@ -13,6 +13,12 @@ use MongoDB\Builder\Expression\ResolvesToString; use MongoDB\Builder\Optional; +/** + * Converts a value to a specified type. + * New in version 4.0. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/convert/ + */ class ConvertAggregation implements ExpressionInterface { public const NAME = '$convert'; diff --git a/src/Builder/Aggregation/CosAggregation.php b/src/Builder/Aggregation/CosAggregation.php index 71e87faaa..96a057687 100644 --- a/src/Builder/Aggregation/CosAggregation.php +++ b/src/Builder/Aggregation/CosAggregation.php @@ -13,6 +13,11 @@ use MongoDB\Builder\Expression\ResolvesToDouble; use MongoDB\Builder\Expression\ResolvesToNumber; +/** + * Returns the cosine of a value that is measured in radians. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/cos/ + */ class CosAggregation implements ResolvesToDouble, ResolvesToDecimal { public const NAME = '$cos'; diff --git a/src/Builder/Aggregation/CoshAggregation.php b/src/Builder/Aggregation/CoshAggregation.php index 01dff644b..db7fbcc5a 100644 --- a/src/Builder/Aggregation/CoshAggregation.php +++ b/src/Builder/Aggregation/CoshAggregation.php @@ -13,6 +13,11 @@ use MongoDB\Builder\Expression\ResolvesToDouble; use MongoDB\Builder\Expression\ResolvesToNumber; +/** + * Returns the hyperbolic cosine of a value that is measured in radians. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/cosh/ + */ class CoshAggregation implements ResolvesToDouble, ResolvesToDecimal { public const NAME = '$cosh'; diff --git a/src/Builder/Aggregation/CountAggregation.php b/src/Builder/Aggregation/CountAggregation.php index 4abf6bc83..1ff53e097 100644 --- a/src/Builder/Aggregation/CountAggregation.php +++ b/src/Builder/Aggregation/CountAggregation.php @@ -8,6 +8,13 @@ use MongoDB\Builder\Encode; +/** + * Returns the number of documents in the group or window. + * Distinct from the $count pipeline stage. + * New in version 5.0. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/count/ + */ class CountAggregation implements AccumulatorInterface { public const NAME = '$count'; diff --git a/src/Builder/Aggregation/CovariancePopAggregation.php b/src/Builder/Aggregation/CovariancePopAggregation.php index bb7f25d07..1f3afdff3 100644 --- a/src/Builder/Aggregation/CovariancePopAggregation.php +++ b/src/Builder/Aggregation/CovariancePopAggregation.php @@ -13,6 +13,12 @@ use MongoDB\Builder\Expression\ResolvesToDouble; use MongoDB\Builder\Expression\ResolvesToNumber; +/** + * Returns the population covariance of two numeric expressions. + * New in version 5.0. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/covariancePop/ + */ class CovariancePopAggregation implements ResolvesToDouble, ResolvesToDecimal { public const NAME = '$covariancePop'; diff --git a/src/Builder/Aggregation/CovarianceSampAggregation.php b/src/Builder/Aggregation/CovarianceSampAggregation.php index b47025fb7..d76a38f7c 100644 --- a/src/Builder/Aggregation/CovarianceSampAggregation.php +++ b/src/Builder/Aggregation/CovarianceSampAggregation.php @@ -13,6 +13,12 @@ use MongoDB\Builder\Expression\ResolvesToDouble; use MongoDB\Builder\Expression\ResolvesToNumber; +/** + * Returns the sample covariance of two numeric expressions. + * New in version 5.0. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/covarianceSamp/ + */ class CovarianceSampAggregation implements ResolvesToDouble, ResolvesToDecimal { public const NAME = '$covarianceSamp'; diff --git a/src/Builder/Aggregation/DateAddAggregation.php b/src/Builder/Aggregation/DateAddAggregation.php index b5da10054..8f81ec0c1 100644 --- a/src/Builder/Aggregation/DateAddAggregation.php +++ b/src/Builder/Aggregation/DateAddAggregation.php @@ -9,6 +9,7 @@ use DateTimeInterface; use MongoDB\BSON\Int64; use MongoDB\BSON\ObjectId; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToDate; use MongoDB\Builder\Expression\ResolvesToInt; @@ -18,13 +19,18 @@ use MongoDB\Builder\Expression\ResolvesToTimestamp; use MongoDB\Builder\Optional; +/** + * Adds a number of time units to a date object. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateAdd/ + */ class DateAddAggregation implements ResolvesToDate { public const NAME = '$dateAdd'; public const ENCODE = \MongoDB\Builder\Encode::Object; /** @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $startDate 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. */ - public \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $startDate; + public DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $startDate; /** @param ResolvesToString|non-empty-string $unit The unit used to measure the amount of time added to the startDate. */ public ResolvesToString|string $unit; @@ -42,7 +48,7 @@ class DateAddAggregation implements ResolvesToDate * @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public function __construct( - \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $startDate, + DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $startDate, ResolvesToString|string $unit, Int64|ResolvesToInt|ResolvesToLong|int $amount, ResolvesToString|Optional|string $timezone = Optional::Undefined, diff --git a/src/Builder/Aggregation/DateDiffAggregation.php b/src/Builder/Aggregation/DateDiffAggregation.php index f41228738..85fc37174 100644 --- a/src/Builder/Aggregation/DateDiffAggregation.php +++ b/src/Builder/Aggregation/DateDiffAggregation.php @@ -9,6 +9,7 @@ use DateTimeInterface; use MongoDB\BSON\Int64; use MongoDB\BSON\ObjectId; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToDate; use MongoDB\Builder\Expression\ResolvesToInt; @@ -17,16 +18,21 @@ use MongoDB\Builder\Expression\ResolvesToTimestamp; use MongoDB\Builder\Optional; +/** + * Returns the difference between two dates. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateDiff/ + */ class DateDiffAggregation implements ResolvesToInt { public const NAME = '$dateDiff'; public const ENCODE = \MongoDB\Builder\Encode::Object; /** @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $startDate The start of the time period. The startDate can be any expression that resolves to a Date, a Timestamp, or an ObjectID. */ - public \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $startDate; + public DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $startDate; /** @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $endDate The end of the time period. The endDate can be any expression that resolves to a Date, a Timestamp, or an ObjectID. */ - public \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $endDate; + public DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $endDate; /** @param ResolvesToString|non-empty-string $unit The time measurement unit between the startDate and endDate */ public ResolvesToString|string $unit; @@ -45,8 +51,8 @@ class DateDiffAggregation implements ResolvesToInt * @param Optional|ResolvesToString|non-empty-string $startOfWeek Used when the unit is equal to week. Defaults to Sunday. The startOfWeek parameter is an expression that resolves to a case insensitive string */ public function __construct( - \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $startDate, - \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $endDate, + DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $startDate, + DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $endDate, ResolvesToString|string $unit, ResolvesToString|Optional|string $timezone = Optional::Undefined, ResolvesToString|Optional|string $startOfWeek = Optional::Undefined, diff --git a/src/Builder/Aggregation/DateFromPartsAggregation.php b/src/Builder/Aggregation/DateFromPartsAggregation.php index 8caad699f..7874a0bd4 100644 --- a/src/Builder/Aggregation/DateFromPartsAggregation.php +++ b/src/Builder/Aggregation/DateFromPartsAggregation.php @@ -14,6 +14,11 @@ use MongoDB\Builder\Expression\ResolvesToString; use MongoDB\Builder\Optional; +/** + * Constructs a BSON Date object given the date's constituent parts. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateFromParts/ + */ class DateFromPartsAggregation implements ResolvesToDate { public const NAME = '$dateFromParts'; diff --git a/src/Builder/Aggregation/DateFromStringAggregation.php b/src/Builder/Aggregation/DateFromStringAggregation.php index 13a27da4c..2d892a5cb 100644 --- a/src/Builder/Aggregation/DateFromStringAggregation.php +++ b/src/Builder/Aggregation/DateFromStringAggregation.php @@ -12,6 +12,11 @@ use MongoDB\Builder\Expression\ResolvesToString; use MongoDB\Builder\Optional; +/** + * Converts a date/time string to a date object. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateFromString/ + */ class DateFromStringAggregation implements ResolvesToDate { public const NAME = '$dateFromString'; diff --git a/src/Builder/Aggregation/DateSubtractAggregation.php b/src/Builder/Aggregation/DateSubtractAggregation.php index 0cf1f5054..c3f777779 100644 --- a/src/Builder/Aggregation/DateSubtractAggregation.php +++ b/src/Builder/Aggregation/DateSubtractAggregation.php @@ -9,6 +9,7 @@ use DateTimeInterface; use MongoDB\BSON\Int64; use MongoDB\BSON\ObjectId; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToDate; use MongoDB\Builder\Expression\ResolvesToInt; @@ -18,13 +19,18 @@ use MongoDB\Builder\Expression\ResolvesToTimestamp; use MongoDB\Builder\Optional; +/** + * Subtracts a number of time units from a date object. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateSubtract/ + */ class DateSubtractAggregation implements ResolvesToDate { public const NAME = '$dateSubtract'; public const ENCODE = \MongoDB\Builder\Encode::Object; /** @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $startDate 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. */ - public \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $startDate; + public DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $startDate; /** @param ResolvesToString|non-empty-string $unit The unit used to measure the amount of time added to the startDate. */ public ResolvesToString|string $unit; @@ -42,7 +48,7 @@ class DateSubtractAggregation implements ResolvesToDate * @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public function __construct( - \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $startDate, + DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $startDate, ResolvesToString|string $unit, Int64|ResolvesToInt|ResolvesToLong|int $amount, ResolvesToString|Optional|string $timezone = Optional::Undefined, diff --git a/src/Builder/Aggregation/DateToPartsAggregation.php b/src/Builder/Aggregation/DateToPartsAggregation.php index 36b061571..80b8a94e2 100644 --- a/src/Builder/Aggregation/DateToPartsAggregation.php +++ b/src/Builder/Aggregation/DateToPartsAggregation.php @@ -9,6 +9,7 @@ use DateTimeInterface; use MongoDB\BSON\Int64; use MongoDB\BSON\ObjectId; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToDate; use MongoDB\Builder\Expression\ResolvesToObject; @@ -17,13 +18,18 @@ use MongoDB\Builder\Expression\ResolvesToTimestamp; use MongoDB\Builder\Optional; +/** + * Returns a document containing the constituent parts of a date. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateToParts/ + */ class DateToPartsAggregation implements ResolvesToObject { public const NAME = '$dateToParts'; public const ENCODE = \MongoDB\Builder\Encode::Object; /** @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The input date for which to return parts. date can be any expression that resolves to a Date, a Timestamp, or an ObjectID. */ - public \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; + public DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; /** @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public ResolvesToString|Optional|string $timezone; @@ -37,7 +43,7 @@ class DateToPartsAggregation implements ResolvesToObject * @param Optional|bool $iso8601 If set to true, modifies the output document to use ISO week date fields. Defaults to false. */ public function __construct( - \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|Optional|string $timezone = Optional::Undefined, Optional|bool $iso8601 = Optional::Undefined, ) { diff --git a/src/Builder/Aggregation/DateToStringAggregation.php b/src/Builder/Aggregation/DateToStringAggregation.php index a30c3a864..a7f45388d 100644 --- a/src/Builder/Aggregation/DateToStringAggregation.php +++ b/src/Builder/Aggregation/DateToStringAggregation.php @@ -9,6 +9,7 @@ use DateTimeInterface; use MongoDB\BSON\Int64; use MongoDB\BSON\ObjectId; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToDate; @@ -17,13 +18,18 @@ use MongoDB\Builder\Expression\ResolvesToTimestamp; use MongoDB\Builder\Optional; +/** + * Returns the date as a formatted string. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateToString/ + */ class DateToStringAggregation implements ResolvesToString { public const NAME = '$dateToString'; public const ENCODE = \MongoDB\Builder\Encode::Object; /** @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to convert to string. Must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ - public \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; + public DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; /** * @param Optional|ResolvesToString|non-empty-string $format 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. @@ -49,7 +55,7 @@ class DateToStringAggregation implements ResolvesToString * If unspecified, $dateToString returns null if the date is null or missing. */ public function __construct( - \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|Optional|string $format = Optional::Undefined, ResolvesToString|Optional|string $timezone = Optional::Undefined, mixed $onNull = Optional::Undefined, diff --git a/src/Builder/Aggregation/DateTruncAggregation.php b/src/Builder/Aggregation/DateTruncAggregation.php index dc94638f0..bbe9d2cd5 100644 --- a/src/Builder/Aggregation/DateTruncAggregation.php +++ b/src/Builder/Aggregation/DateTruncAggregation.php @@ -10,6 +10,7 @@ use MongoDB\BSON\Decimal128; use MongoDB\BSON\Int64; use MongoDB\BSON\ObjectId; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToDate; use MongoDB\Builder\Expression\ResolvesToNumber; @@ -18,13 +19,18 @@ use MongoDB\Builder\Expression\ResolvesToTimestamp; use MongoDB\Builder\Optional; +/** + * Truncates a date. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateTrunc/ + */ class DateTruncAggregation implements ResolvesToDate { public const NAME = '$dateTrunc'; public const ENCODE = \MongoDB\Builder\Encode::Object; /** @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to truncate, specified in UTC. The date can be any expression that resolves to a Date, a Timestamp, or an ObjectID. */ - public \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; + public DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; /** * @param ResolvesToString|non-empty-string $unit The unit of time, specified as an expression that must resolve to one of these strings: year, quarter, week, month, day, hour, minute, second. @@ -58,7 +64,7 @@ class DateTruncAggregation implements ResolvesToDate * unit is week. Defaults to Sunday. */ public function __construct( - \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|string $unit, Decimal128|Int64|ResolvesToNumber|Optional|float|int $binSize = Optional::Undefined, ResolvesToString|Optional|string $timezone = Optional::Undefined, diff --git a/src/Builder/Aggregation/DayOfMonthAggregation.php b/src/Builder/Aggregation/DayOfMonthAggregation.php index f96aed2eb..d99eceffc 100644 --- a/src/Builder/Aggregation/DayOfMonthAggregation.php +++ b/src/Builder/Aggregation/DayOfMonthAggregation.php @@ -9,6 +9,7 @@ use DateTimeInterface; use MongoDB\BSON\Int64; use MongoDB\BSON\ObjectId; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToDate; use MongoDB\Builder\Expression\ResolvesToInt; @@ -17,13 +18,18 @@ use MongoDB\Builder\Expression\ResolvesToTimestamp; use MongoDB\Builder\Optional; +/** + * Returns the day of the month for a date as a number between 1 and 31. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/dayOfMonth/ + */ class DayOfMonthAggregation implements ResolvesToInt { public const NAME = '$dayOfMonth'; public const ENCODE = \MongoDB\Builder\Encode::Object; /** @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ - public \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; + public DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; /** @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public ResolvesToString|Optional|string $timezone; @@ -33,7 +39,7 @@ class DayOfMonthAggregation implements ResolvesToInt * @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public function __construct( - \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|Optional|string $timezone = Optional::Undefined, ) { $this->date = $date; diff --git a/src/Builder/Aggregation/DayOfWeekAggregation.php b/src/Builder/Aggregation/DayOfWeekAggregation.php index f15e483af..97f6f51ad 100644 --- a/src/Builder/Aggregation/DayOfWeekAggregation.php +++ b/src/Builder/Aggregation/DayOfWeekAggregation.php @@ -9,6 +9,7 @@ use DateTimeInterface; use MongoDB\BSON\Int64; use MongoDB\BSON\ObjectId; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToDate; use MongoDB\Builder\Expression\ResolvesToInt; @@ -17,13 +18,18 @@ use MongoDB\Builder\Expression\ResolvesToTimestamp; use MongoDB\Builder\Optional; +/** + * Returns the day of the week for a date as a number between 1 (Sunday) and 7 (Saturday). + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/dayOfWeek/ + */ class DayOfWeekAggregation implements ResolvesToInt { public const NAME = '$dayOfWeek'; public const ENCODE = \MongoDB\Builder\Encode::Object; /** @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ - public \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; + public DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; /** @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public ResolvesToString|Optional|string $timezone; @@ -33,7 +39,7 @@ class DayOfWeekAggregation implements ResolvesToInt * @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public function __construct( - \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|Optional|string $timezone = Optional::Undefined, ) { $this->date = $date; diff --git a/src/Builder/Aggregation/DayOfYearAggregation.php b/src/Builder/Aggregation/DayOfYearAggregation.php index 7354ae143..7a952016b 100644 --- a/src/Builder/Aggregation/DayOfYearAggregation.php +++ b/src/Builder/Aggregation/DayOfYearAggregation.php @@ -9,6 +9,7 @@ use DateTimeInterface; use MongoDB\BSON\Int64; use MongoDB\BSON\ObjectId; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToDate; use MongoDB\Builder\Expression\ResolvesToInt; @@ -17,13 +18,18 @@ use MongoDB\Builder\Expression\ResolvesToTimestamp; use MongoDB\Builder\Optional; +/** + * Returns the day of the year for a date as a number between 1 and 366 (leap year). + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/dayOfYear/ + */ class DayOfYearAggregation implements ResolvesToInt { public const NAME = '$dayOfYear'; public const ENCODE = \MongoDB\Builder\Encode::Object; /** @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ - public \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; + public DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; /** @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public ResolvesToString|Optional|string $timezone; @@ -33,7 +39,7 @@ class DayOfYearAggregation implements ResolvesToInt * @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public function __construct( - \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|Optional|string $timezone = Optional::Undefined, ) { $this->date = $date; diff --git a/src/Builder/Aggregation/DegreesToRadiansAggregation.php b/src/Builder/Aggregation/DegreesToRadiansAggregation.php index 3da33e21b..37a4df5b4 100644 --- a/src/Builder/Aggregation/DegreesToRadiansAggregation.php +++ b/src/Builder/Aggregation/DegreesToRadiansAggregation.php @@ -13,6 +13,11 @@ use MongoDB\Builder\Expression\ResolvesToDouble; use MongoDB\Builder\Expression\ResolvesToNumber; +/** + * Converts a value from degrees to radians. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/degreesToRadians/ + */ class DegreesToRadiansAggregation implements ResolvesToDouble, ResolvesToDecimal { public const NAME = '$degreesToRadians'; diff --git a/src/Builder/Aggregation/DenseRankAggregation.php b/src/Builder/Aggregation/DenseRankAggregation.php index b897c85cd..1578f7dc2 100644 --- a/src/Builder/Aggregation/DenseRankAggregation.php +++ b/src/Builder/Aggregation/DenseRankAggregation.php @@ -9,6 +9,12 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToInt; +/** + * 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 version 5.0. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/denseRank/ + */ class DenseRankAggregation implements ResolvesToInt { public const NAME = '$denseRank'; diff --git a/src/Builder/Aggregation/DerivativeAggregation.php b/src/Builder/Aggregation/DerivativeAggregation.php index 7cf999562..14e41a1f7 100644 --- a/src/Builder/Aggregation/DerivativeAggregation.php +++ b/src/Builder/Aggregation/DerivativeAggregation.php @@ -9,19 +9,26 @@ use DateTimeInterface; use MongoDB\BSON\Decimal128; use MongoDB\BSON\Int64; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToDate; use MongoDB\Builder\Expression\ResolvesToDouble; use MongoDB\Builder\Expression\ResolvesToNumber; use MongoDB\Builder\Optional; +/** + * Returns the average rate of change within the specified window. + * New in version 5.0. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/derivative/ + */ class DerivativeAggregation implements ResolvesToDouble { public const NAME = '$derivative'; public const ENCODE = \MongoDB\Builder\Encode::Object; /** @param DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int $input */ - public \UTCDateTime|DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|float|int $input; + public DateTimeInterface|Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int $input; /** * @param Optional|non-empty-string $unit A string that specifies the time unit. Use one of these strings: "week", "day","hour", "minute", "second", "millisecond". @@ -35,7 +42,7 @@ class DerivativeAggregation implements ResolvesToDouble * 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. */ public function __construct( - \UTCDateTime|DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|float|int $input, + DateTimeInterface|Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int $input, Optional|string $unit = Optional::Undefined, ) { $this->input = $input; diff --git a/src/Builder/Aggregation/DivideAggregation.php b/src/Builder/Aggregation/DivideAggregation.php index fc93f97e6..612c4e7c8 100644 --- a/src/Builder/Aggregation/DivideAggregation.php +++ b/src/Builder/Aggregation/DivideAggregation.php @@ -12,6 +12,11 @@ use MongoDB\Builder\Expression\ResolvesToDouble; use MongoDB\Builder\Expression\ResolvesToNumber; +/** + * Returns the result of dividing the first number by the second. Accepts two argument expressions. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/divide/ + */ class DivideAggregation implements ResolvesToDouble { public const NAME = '$divide'; diff --git a/src/Builder/Aggregation/DocumentNumberAggregation.php b/src/Builder/Aggregation/DocumentNumberAggregation.php index 4ff69d2b5..23d990792 100644 --- a/src/Builder/Aggregation/DocumentNumberAggregation.php +++ b/src/Builder/Aggregation/DocumentNumberAggregation.php @@ -9,6 +9,12 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToInt; +/** + * 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 version 5.0. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/documentNumber/ + */ class DocumentNumberAggregation implements ResolvesToInt { public const NAME = '$documentNumber'; diff --git a/src/Builder/Aggregation/EqAggregation.php b/src/Builder/Aggregation/EqAggregation.php index 84cbfa044..d6b5fd594 100644 --- a/src/Builder/Aggregation/EqAggregation.php +++ b/src/Builder/Aggregation/EqAggregation.php @@ -10,6 +10,11 @@ use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToBool; +/** + * Returns true if the values are equivalent. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/eq/ + */ class EqAggregation implements ResolvesToBool { public const NAME = '$eq'; diff --git a/src/Builder/Aggregation/ExpAggregation.php b/src/Builder/Aggregation/ExpAggregation.php index e762340c8..b319ea281 100644 --- a/src/Builder/Aggregation/ExpAggregation.php +++ b/src/Builder/Aggregation/ExpAggregation.php @@ -12,6 +12,11 @@ use MongoDB\Builder\Expression\ResolvesToDouble; use MongoDB\Builder\Expression\ResolvesToNumber; +/** + * Raises e to the specified exponent. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/exp/ + */ class ExpAggregation implements ResolvesToDouble { public const NAME = '$exp'; diff --git a/src/Builder/Aggregation/ExpMovingAvgAggregation.php b/src/Builder/Aggregation/ExpMovingAvgAggregation.php index 46feb372f..6571c5fe6 100644 --- a/src/Builder/Aggregation/ExpMovingAvgAggregation.php +++ b/src/Builder/Aggregation/ExpMovingAvgAggregation.php @@ -13,6 +13,12 @@ use MongoDB\Builder\Expression\ResolvesToNumber; use MongoDB\Builder\Optional; +/** + * Returns the exponential moving average for the numeric expression. + * New in version 5.0. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/expMovingAvg/ + */ class ExpMovingAvgAggregation implements ResolvesToDouble { public const NAME = '$expMovingAvg'; diff --git a/src/Builder/Aggregation/FilterAggregation.php b/src/Builder/Aggregation/FilterAggregation.php index 8e4f1fb38..86cfb4e19 100644 --- a/src/Builder/Aggregation/FilterAggregation.php +++ b/src/Builder/Aggregation/FilterAggregation.php @@ -16,6 +16,11 @@ use MongoDB\Builder\Optional; use MongoDB\Model\BSONArray; +/** + * Selects a subset of the array to return an array with only the elements that match the filter condition. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/filter/ + */ class FilterAggregation implements ResolvesToArray { public const NAME = '$filter'; diff --git a/src/Builder/Aggregation/FirstAggregation.php b/src/Builder/Aggregation/FirstAggregation.php index 446a1be56..ab1f4477e 100644 --- a/src/Builder/Aggregation/FirstAggregation.php +++ b/src/Builder/Aggregation/FirstAggregation.php @@ -9,6 +9,12 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ExpressionInterface; +/** + * Returns the result of an expression for the first document in a group or window. + * Changed in version 5.0: Available in the $setWindowFields stage. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/first/ + */ class FirstAggregation implements ExpressionInterface, AccumulatorInterface { public const NAME = '$first'; diff --git a/src/Builder/Aggregation/FirstNAggregation.php b/src/Builder/Aggregation/FirstNAggregation.php index 0055a1440..d0e19b345 100644 --- a/src/Builder/Aggregation/FirstNAggregation.php +++ b/src/Builder/Aggregation/FirstNAggregation.php @@ -14,6 +14,11 @@ use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Model\BSONArray; +/** + * Returns a specified number of elements from the beginning of an array. Distinct from the $firstN accumulator. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/firstN-array-element/ + */ class FirstNAggregation implements AccumulatorInterface { public const NAME = '$firstN'; diff --git a/src/Builder/Aggregation/FloorAggregation.php b/src/Builder/Aggregation/FloorAggregation.php index ac2c7ba6a..679726e58 100644 --- a/src/Builder/Aggregation/FloorAggregation.php +++ b/src/Builder/Aggregation/FloorAggregation.php @@ -12,6 +12,11 @@ use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Expression\ResolvesToNumber; +/** + * Returns the largest integer less than or equal to the specified number. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/floor/ + */ class FloorAggregation implements ResolvesToInt { public const NAME = '$floor'; diff --git a/src/Builder/Aggregation/FunctionAggregation.php b/src/Builder/Aggregation/FunctionAggregation.php index 07249496d..66509b181 100644 --- a/src/Builder/Aggregation/FunctionAggregation.php +++ b/src/Builder/Aggregation/FunctionAggregation.php @@ -11,6 +11,12 @@ use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Model\BSONArray; +/** + * Defines a custom function. + * New in version 4.4. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/function/ + */ class FunctionAggregation implements ExpressionInterface { public const NAME = '$function'; diff --git a/src/Builder/Aggregation/GetFieldAggregation.php b/src/Builder/Aggregation/GetFieldAggregation.php index d104c32e3..dfe8fda27 100644 --- a/src/Builder/Aggregation/GetFieldAggregation.php +++ b/src/Builder/Aggregation/GetFieldAggregation.php @@ -10,6 +10,12 @@ use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Optional; +/** + * 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 version 5.0. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/getField/ + */ class GetFieldAggregation implements ExpressionInterface { public const NAME = '$getField'; diff --git a/src/Builder/Aggregation/GtAggregation.php b/src/Builder/Aggregation/GtAggregation.php index 94955dfca..7615df4a8 100644 --- a/src/Builder/Aggregation/GtAggregation.php +++ b/src/Builder/Aggregation/GtAggregation.php @@ -10,6 +10,11 @@ use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToBool; +/** + * Returns true if the first value is greater than the second. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/gt/ + */ class GtAggregation implements ResolvesToBool { public const NAME = '$gt'; diff --git a/src/Builder/Aggregation/GteAggregation.php b/src/Builder/Aggregation/GteAggregation.php index cdd333cc1..05f9049a9 100644 --- a/src/Builder/Aggregation/GteAggregation.php +++ b/src/Builder/Aggregation/GteAggregation.php @@ -10,6 +10,11 @@ use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToBool; +/** + * Returns true if the first value is greater than or equal to the second. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/gte/ + */ class GteAggregation implements ResolvesToBool { public const NAME = '$gte'; diff --git a/src/Builder/Aggregation/HourAggregation.php b/src/Builder/Aggregation/HourAggregation.php index db0954aa5..be068fbbb 100644 --- a/src/Builder/Aggregation/HourAggregation.php +++ b/src/Builder/Aggregation/HourAggregation.php @@ -9,6 +9,7 @@ use DateTimeInterface; use MongoDB\BSON\Int64; use MongoDB\BSON\ObjectId; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToDate; use MongoDB\Builder\Expression\ResolvesToInt; @@ -17,13 +18,18 @@ use MongoDB\Builder\Expression\ResolvesToTimestamp; use MongoDB\Builder\Optional; +/** + * Returns the hour for a date as a number between 0 and 23. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/hour/ + */ class HourAggregation implements ResolvesToInt { public const NAME = '$hour'; public const ENCODE = \MongoDB\Builder\Encode::Object; /** @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ - public \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; + public DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; /** @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public ResolvesToString|Optional|string $timezone; @@ -33,7 +39,7 @@ class HourAggregation implements ResolvesToInt * @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public function __construct( - \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|Optional|string $timezone = Optional::Undefined, ) { $this->date = $date; diff --git a/src/Builder/Aggregation/IfNullAggregation.php b/src/Builder/Aggregation/IfNullAggregation.php index 77ea80227..b38d9defd 100644 --- a/src/Builder/Aggregation/IfNullAggregation.php +++ b/src/Builder/Aggregation/IfNullAggregation.php @@ -9,6 +9,11 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ExpressionInterface; +/** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/ifNull/ + */ class IfNullAggregation implements ExpressionInterface { public const NAME = '$ifNull'; diff --git a/src/Builder/Aggregation/InAggregation.php b/src/Builder/Aggregation/InAggregation.php index b70360f55..907723a6e 100644 --- a/src/Builder/Aggregation/InAggregation.php +++ b/src/Builder/Aggregation/InAggregation.php @@ -13,6 +13,11 @@ use MongoDB\Builder\Expression\ResolvesToBool; use MongoDB\Model\BSONArray; +/** + * Returns a boolean indicating whether a specified value is in an array. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/in/ + */ class InAggregation implements ResolvesToBool { public const NAME = '$in'; diff --git a/src/Builder/Aggregation/IndexOfArrayAggregation.php b/src/Builder/Aggregation/IndexOfArrayAggregation.php index 1a52650f1..4cfc36de6 100644 --- a/src/Builder/Aggregation/IndexOfArrayAggregation.php +++ b/src/Builder/Aggregation/IndexOfArrayAggregation.php @@ -13,6 +13,11 @@ use MongoDB\Builder\Expression\ResolvesToString; use MongoDB\Builder\Optional; +/** + * Searches an array for an occurrence of a specified value and returns the array index of the first occurrence. Array indexes start at zero. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/indexOfArray/ + */ class IndexOfArrayAggregation implements ResolvesToInt { public const NAME = '$indexOfArray'; diff --git a/src/Builder/Aggregation/IndexOfBytesAggregation.php b/src/Builder/Aggregation/IndexOfBytesAggregation.php index 3348d6da0..05dafd4be 100644 --- a/src/Builder/Aggregation/IndexOfBytesAggregation.php +++ b/src/Builder/Aggregation/IndexOfBytesAggregation.php @@ -12,6 +12,11 @@ use MongoDB\Builder\Expression\ResolvesToString; use MongoDB\Builder\Optional; +/** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/indexOfBytes/ + */ class IndexOfBytesAggregation implements ResolvesToInt { public const NAME = '$indexOfBytes'; diff --git a/src/Builder/Aggregation/IndexOfCPAggregation.php b/src/Builder/Aggregation/IndexOfCPAggregation.php index d106bb95a..81a1c4ba7 100644 --- a/src/Builder/Aggregation/IndexOfCPAggregation.php +++ b/src/Builder/Aggregation/IndexOfCPAggregation.php @@ -12,6 +12,11 @@ use MongoDB\Builder\Expression\ResolvesToString; use MongoDB\Builder\Optional; +/** + * 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 + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/indexOfCP/ + */ class IndexOfCPAggregation implements ResolvesToInt { public const NAME = '$indexOfCP'; diff --git a/src/Builder/Aggregation/IntegralAggregation.php b/src/Builder/Aggregation/IntegralAggregation.php index 8cd60d82d..831c1db9c 100644 --- a/src/Builder/Aggregation/IntegralAggregation.php +++ b/src/Builder/Aggregation/IntegralAggregation.php @@ -9,6 +9,7 @@ use DateTimeInterface; use MongoDB\BSON\Decimal128; use MongoDB\BSON\Int64; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToDate; use MongoDB\Builder\Expression\ResolvesToDecimal; @@ -17,13 +18,19 @@ use MongoDB\Builder\Expression\ResolvesToString; use MongoDB\Builder\Optional; +/** + * Returns the approximation of the area under a curve. + * New in version 5.0. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/integral/ + */ class IntegralAggregation implements ResolvesToDouble, ResolvesToDecimal { public const NAME = '$integral'; public const ENCODE = \MongoDB\Builder\Encode::Object; /** @param DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int $input */ - public \UTCDateTime|DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|float|int $input; + public DateTimeInterface|Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int $input; /** * @param Optional|ResolvesToString|non-empty-string $unit A string that specifies the time unit. Use one of these strings: "week", "day","hour", "minute", "second", "millisecond". @@ -37,7 +44,7 @@ class IntegralAggregation implements ResolvesToDouble, ResolvesToDecimal * 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. */ public function __construct( - \UTCDateTime|DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|float|int $input, + DateTimeInterface|Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int $input, ResolvesToString|Optional|string $unit = Optional::Undefined, ) { $this->input = $input; diff --git a/src/Builder/Aggregation/IsArrayAggregation.php b/src/Builder/Aggregation/IsArrayAggregation.php index fbd922602..ca40129d6 100644 --- a/src/Builder/Aggregation/IsArrayAggregation.php +++ b/src/Builder/Aggregation/IsArrayAggregation.php @@ -10,6 +10,11 @@ use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToBool; +/** + * Determines if the operand is an array. Returns a boolean. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/isArray/ + */ class IsArrayAggregation implements ResolvesToBool { public const NAME = '$isArray'; diff --git a/src/Builder/Aggregation/IsNumberAggregation.php b/src/Builder/Aggregation/IsNumberAggregation.php index 691cbad8f..3e8ea7d0d 100644 --- a/src/Builder/Aggregation/IsNumberAggregation.php +++ b/src/Builder/Aggregation/IsNumberAggregation.php @@ -10,6 +10,13 @@ use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToBool; +/** + * Returns boolean true if the specified expression resolves to an integer, decimal, double, or long. + * Returns boolean false if the expression resolves to any other BSON type, null, or a missing field. + * New in version 4.4. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/isNumber/ + */ class IsNumberAggregation implements ResolvesToBool { public const NAME = '$isNumber'; diff --git a/src/Builder/Aggregation/IsoDayOfWeekAggregation.php b/src/Builder/Aggregation/IsoDayOfWeekAggregation.php index 10452f1cd..45fc7d1c5 100644 --- a/src/Builder/Aggregation/IsoDayOfWeekAggregation.php +++ b/src/Builder/Aggregation/IsoDayOfWeekAggregation.php @@ -9,6 +9,7 @@ use DateTimeInterface; use MongoDB\BSON\Int64; use MongoDB\BSON\ObjectId; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToDate; use MongoDB\Builder\Expression\ResolvesToInt; @@ -17,13 +18,18 @@ use MongoDB\Builder\Expression\ResolvesToTimestamp; use MongoDB\Builder\Optional; +/** + * Returns the weekday number in ISO 8601 format, ranging from 1 (for Monday) to 7 (for Sunday). + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/isoDayOfWeek/ + */ class IsoDayOfWeekAggregation implements ResolvesToInt { public const NAME = '$isoDayOfWeek'; public const ENCODE = \MongoDB\Builder\Encode::Object; /** @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ - public \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; + public DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; /** @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public ResolvesToString|Optional|string $timezone; @@ -33,7 +39,7 @@ class IsoDayOfWeekAggregation implements ResolvesToInt * @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public function __construct( - \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|Optional|string $timezone = Optional::Undefined, ) { $this->date = $date; diff --git a/src/Builder/Aggregation/IsoWeekAggregation.php b/src/Builder/Aggregation/IsoWeekAggregation.php index 93f33ff16..518ff9075 100644 --- a/src/Builder/Aggregation/IsoWeekAggregation.php +++ b/src/Builder/Aggregation/IsoWeekAggregation.php @@ -9,6 +9,7 @@ use DateTimeInterface; use MongoDB\BSON\Int64; use MongoDB\BSON\ObjectId; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToDate; use MongoDB\Builder\Expression\ResolvesToInt; @@ -17,13 +18,18 @@ use MongoDB\Builder\Expression\ResolvesToTimestamp; use MongoDB\Builder\Optional; +/** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/isoWeek/ + */ class IsoWeekAggregation implements ResolvesToInt { public const NAME = '$isoWeek'; public const ENCODE = \MongoDB\Builder\Encode::Object; /** @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ - public \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; + public DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; /** @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public ResolvesToString|Optional|string $timezone; @@ -33,7 +39,7 @@ class IsoWeekAggregation implements ResolvesToInt * @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public function __construct( - \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|Optional|string $timezone = Optional::Undefined, ) { $this->date = $date; diff --git a/src/Builder/Aggregation/IsoWeekYearAggregation.php b/src/Builder/Aggregation/IsoWeekYearAggregation.php index d1ff0e89a..730b39cb3 100644 --- a/src/Builder/Aggregation/IsoWeekYearAggregation.php +++ b/src/Builder/Aggregation/IsoWeekYearAggregation.php @@ -9,6 +9,7 @@ use DateTimeInterface; use MongoDB\BSON\Int64; use MongoDB\BSON\ObjectId; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToDate; use MongoDB\Builder\Expression\ResolvesToInt; @@ -17,13 +18,18 @@ use MongoDB\Builder\Expression\ResolvesToTimestamp; use MongoDB\Builder\Optional; +/** + * 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). + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/isoWeekYear/ + */ class IsoWeekYearAggregation implements ResolvesToInt { public const NAME = '$isoWeekYear'; public const ENCODE = \MongoDB\Builder\Encode::Object; /** @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ - public \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; + public DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; /** @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public ResolvesToString|Optional|string $timezone; @@ -33,7 +39,7 @@ class IsoWeekYearAggregation implements ResolvesToInt * @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public function __construct( - \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|Optional|string $timezone = Optional::Undefined, ) { $this->date = $date; diff --git a/src/Builder/Aggregation/LastAggregation.php b/src/Builder/Aggregation/LastAggregation.php index 666920f47..fc173461e 100644 --- a/src/Builder/Aggregation/LastAggregation.php +++ b/src/Builder/Aggregation/LastAggregation.php @@ -9,6 +9,12 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ExpressionInterface; +/** + * Returns the result of an expression for the last document in a group or window. + * Changed in version 5.0: Available in the $setWindowFields stage. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/last/ + */ class LastAggregation implements ExpressionInterface, AccumulatorInterface { public const NAME = '$last'; diff --git a/src/Builder/Aggregation/LastNAggregation.php b/src/Builder/Aggregation/LastNAggregation.php index 30cfdf7f8..02e582ea4 100644 --- a/src/Builder/Aggregation/LastNAggregation.php +++ b/src/Builder/Aggregation/LastNAggregation.php @@ -14,6 +14,11 @@ use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Model\BSONArray; +/** + * Returns a specified number of elements from the end of an array. Distinct from the $lastN accumulator. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/lastN/ + */ class LastNAggregation implements ResolvesToArray { public const NAME = '$lastN'; diff --git a/src/Builder/Aggregation/LetAggregation.php b/src/Builder/Aggregation/LetAggregation.php index b76f78d98..f0899f33f 100644 --- a/src/Builder/Aggregation/LetAggregation.php +++ b/src/Builder/Aggregation/LetAggregation.php @@ -12,6 +12,12 @@ use MongoDB\Builder\Expression\ExpressionInterface; use stdClass; +/** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/let/ + */ class LetAggregation implements ExpressionInterface { public const NAME = '$let'; diff --git a/src/Builder/Aggregation/LinearFillAggregation.php b/src/Builder/Aggregation/LinearFillAggregation.php index e8acb0dd9..875eff33b 100644 --- a/src/Builder/Aggregation/LinearFillAggregation.php +++ b/src/Builder/Aggregation/LinearFillAggregation.php @@ -11,6 +11,13 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToNumber; +/** + * Fills null and missing fields in a window using linear interpolation based on surrounding field values. + * Available in the $setWindowFields stage. + * New in version 5.3. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/linearFill/ + */ class LinearFillAggregation implements ResolvesToNumber { public const NAME = '$linearFill'; diff --git a/src/Builder/Aggregation/LiteralAggregation.php b/src/Builder/Aggregation/LiteralAggregation.php index 6a9e17c8d..722637a76 100644 --- a/src/Builder/Aggregation/LiteralAggregation.php +++ b/src/Builder/Aggregation/LiteralAggregation.php @@ -9,6 +9,11 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ExpressionInterface; +/** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/literal/ + */ class LiteralAggregation implements ExpressionInterface { public const NAME = '$literal'; diff --git a/src/Builder/Aggregation/LnAggregation.php b/src/Builder/Aggregation/LnAggregation.php index 3fe8e5cef..eb146c22a 100644 --- a/src/Builder/Aggregation/LnAggregation.php +++ b/src/Builder/Aggregation/LnAggregation.php @@ -12,6 +12,12 @@ use MongoDB\Builder\Expression\ResolvesToDouble; use MongoDB\Builder\Expression\ResolvesToNumber; +/** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/ln/ + */ class LnAggregation implements ResolvesToDouble { public const NAME = '$ln'; diff --git a/src/Builder/Aggregation/LocfAggregation.php b/src/Builder/Aggregation/LocfAggregation.php index 00edb45b4..05df29310 100644 --- a/src/Builder/Aggregation/LocfAggregation.php +++ b/src/Builder/Aggregation/LocfAggregation.php @@ -9,6 +9,13 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ExpressionInterface; +/** + * Last observation carried forward. Sets values for null and missing fields in a window to the last non-null value for the field. + * Available in the $setWindowFields stage. + * New in version 5.2. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/locf/ + */ class LocfAggregation implements ExpressionInterface { public const NAME = '$locf'; diff --git a/src/Builder/Aggregation/Log10Aggregation.php b/src/Builder/Aggregation/Log10Aggregation.php index ca81bd837..fd7c1499b 100644 --- a/src/Builder/Aggregation/Log10Aggregation.php +++ b/src/Builder/Aggregation/Log10Aggregation.php @@ -12,6 +12,11 @@ use MongoDB\Builder\Expression\ResolvesToDouble; use MongoDB\Builder\Expression\ResolvesToNumber; +/** + * Calculates the log base 10 of a number. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/log10/ + */ class Log10Aggregation implements ResolvesToDouble { public const NAME = '$log10'; diff --git a/src/Builder/Aggregation/LogAggregation.php b/src/Builder/Aggregation/LogAggregation.php index 0b566159a..374d556bc 100644 --- a/src/Builder/Aggregation/LogAggregation.php +++ b/src/Builder/Aggregation/LogAggregation.php @@ -12,6 +12,11 @@ use MongoDB\Builder\Expression\ResolvesToDouble; use MongoDB\Builder\Expression\ResolvesToNumber; +/** + * Calculates the log of a number in the specified base. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/log/ + */ class LogAggregation implements ResolvesToDouble { public const NAME = '$log'; diff --git a/src/Builder/Aggregation/LtAggregation.php b/src/Builder/Aggregation/LtAggregation.php index 7ace117ce..b248153b6 100644 --- a/src/Builder/Aggregation/LtAggregation.php +++ b/src/Builder/Aggregation/LtAggregation.php @@ -10,6 +10,11 @@ use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToBool; +/** + * Returns true if the first value is less than the second. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/lt/ + */ class LtAggregation implements ResolvesToBool { public const NAME = '$lt'; diff --git a/src/Builder/Aggregation/LteAggregation.php b/src/Builder/Aggregation/LteAggregation.php index 8ee66f828..430dca7c3 100644 --- a/src/Builder/Aggregation/LteAggregation.php +++ b/src/Builder/Aggregation/LteAggregation.php @@ -10,6 +10,11 @@ use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToBool; +/** + * Returns true if the first value is less than or equal to the second. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/lte/ + */ class LteAggregation implements ResolvesToBool { public const NAME = '$lte'; diff --git a/src/Builder/Aggregation/LtrimAggregation.php b/src/Builder/Aggregation/LtrimAggregation.php index e40e57291..4e2429954 100644 --- a/src/Builder/Aggregation/LtrimAggregation.php +++ b/src/Builder/Aggregation/LtrimAggregation.php @@ -10,6 +10,12 @@ use MongoDB\Builder\Expression\ResolvesToString; use MongoDB\Builder\Optional; +/** + * Removes whitespace or the specified characters from the beginning of a string. + * New in version 4.0. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/ltrim/ + */ class LtrimAggregation implements ResolvesToString { public const NAME = '$ltrim'; diff --git a/src/Builder/Aggregation/MapAggregation.php b/src/Builder/Aggregation/MapAggregation.php index 152b50a9f..02d08ca1d 100644 --- a/src/Builder/Aggregation/MapAggregation.php +++ b/src/Builder/Aggregation/MapAggregation.php @@ -14,6 +14,11 @@ use MongoDB\Builder\Optional; use MongoDB\Model\BSONArray; +/** + * Applies a subexpression to each element of an array and returns the array of resulting values in order. Accepts named parameters. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/map/ + */ class MapAggregation implements ResolvesToArray { public const NAME = '$map'; diff --git a/src/Builder/Aggregation/MaxAggregation.php b/src/Builder/Aggregation/MaxAggregation.php index e4d9499f1..80dd4e934 100644 --- a/src/Builder/Aggregation/MaxAggregation.php +++ b/src/Builder/Aggregation/MaxAggregation.php @@ -9,6 +9,12 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ExpressionInterface; +/** + * Returns the maximum value that results from applying an expression to each document. + * Changed in version 5.0: Available in the $setWindowFields stage. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/max/ + */ class MaxAggregation implements ExpressionInterface, AccumulatorInterface { public const NAME = '$max'; diff --git a/src/Builder/Aggregation/MaxNAggregation.php b/src/Builder/Aggregation/MaxNAggregation.php index 1a1c3c809..4f8f610dc 100644 --- a/src/Builder/Aggregation/MaxNAggregation.php +++ b/src/Builder/Aggregation/MaxNAggregation.php @@ -14,6 +14,11 @@ use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Model\BSONArray; +/** + * Returns the n largest values in an array. Distinct from the $maxN accumulator. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/maxN-array-element/ + */ class MaxNAggregation implements ResolvesToArray { public const NAME = '$maxN'; diff --git a/src/Builder/Aggregation/MedianAggregation.php b/src/Builder/Aggregation/MedianAggregation.php index 0c48bf4b6..eabe80284 100644 --- a/src/Builder/Aggregation/MedianAggregation.php +++ b/src/Builder/Aggregation/MedianAggregation.php @@ -12,6 +12,16 @@ use MongoDB\Builder\Expression\ResolvesToDouble; use MongoDB\Builder\Expression\ResolvesToNumber; +/** + * Returns an approximation of the median, the 50th percentile, as a scalar value. + * New in version 7.0. + * This operator is available as an accumulator in these stages: + * $group + * $setWindowFields + * It is also available as an aggregation expression. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/median/ + */ class MedianAggregation implements ResolvesToDouble, AccumulatorInterface { public const NAME = '$median'; diff --git a/src/Builder/Aggregation/MergeObjectsAggregation.php b/src/Builder/Aggregation/MergeObjectsAggregation.php index d477093c4..b6dbe737d 100644 --- a/src/Builder/Aggregation/MergeObjectsAggregation.php +++ b/src/Builder/Aggregation/MergeObjectsAggregation.php @@ -12,6 +12,11 @@ use MongoDB\Builder\Expression\ResolvesToObject; use stdClass; +/** + * Combines multiple documents into a single document. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/mergeObjects/ + */ class MergeObjectsAggregation implements AccumulatorInterface { public const NAME = '$mergeObjects'; diff --git a/src/Builder/Aggregation/MetaAggregation.php b/src/Builder/Aggregation/MetaAggregation.php index 6d6419712..99bc2a0e9 100644 --- a/src/Builder/Aggregation/MetaAggregation.php +++ b/src/Builder/Aggregation/MetaAggregation.php @@ -9,6 +9,11 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToDecimal; +/** + * Access available per-document metadata related to the aggregation operation. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/meta/ + */ class MetaAggregation implements ResolvesToDecimal { public const NAME = '$meta'; diff --git a/src/Builder/Aggregation/MillisecondAggregation.php b/src/Builder/Aggregation/MillisecondAggregation.php index 0c48b6966..09d213c09 100644 --- a/src/Builder/Aggregation/MillisecondAggregation.php +++ b/src/Builder/Aggregation/MillisecondAggregation.php @@ -9,6 +9,7 @@ use DateTimeInterface; use MongoDB\BSON\Int64; use MongoDB\BSON\ObjectId; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToDate; use MongoDB\Builder\Expression\ResolvesToInt; @@ -17,13 +18,18 @@ use MongoDB\Builder\Expression\ResolvesToTimestamp; use MongoDB\Builder\Optional; +/** + * Returns the milliseconds of a date as a number between 0 and 999. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/millisecond/ + */ class MillisecondAggregation implements ResolvesToInt { public const NAME = '$millisecond'; public const ENCODE = \MongoDB\Builder\Encode::Object; /** @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ - public \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; + public DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; /** @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public ResolvesToString|Optional|string $timezone; @@ -33,7 +39,7 @@ class MillisecondAggregation implements ResolvesToInt * @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public function __construct( - \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|Optional|string $timezone = Optional::Undefined, ) { $this->date = $date; diff --git a/src/Builder/Aggregation/MinAggregation.php b/src/Builder/Aggregation/MinAggregation.php index 9ddddd256..36e4f4da4 100644 --- a/src/Builder/Aggregation/MinAggregation.php +++ b/src/Builder/Aggregation/MinAggregation.php @@ -9,6 +9,12 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ExpressionInterface; +/** + * Returns the minimum value that results from applying an expression to each document. + * Changed in version 5.0: Available in the $setWindowFields stage. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/min/ + */ class MinAggregation implements ExpressionInterface, AccumulatorInterface { public const NAME = '$min'; diff --git a/src/Builder/Aggregation/MinNAggregation.php b/src/Builder/Aggregation/MinNAggregation.php index dac13b6c9..9413ae941 100644 --- a/src/Builder/Aggregation/MinNAggregation.php +++ b/src/Builder/Aggregation/MinNAggregation.php @@ -14,6 +14,11 @@ use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Model\BSONArray; +/** + * Returns the n smallest values in an array. Distinct from the $minN accumulator. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/minN-array-element/ + */ class MinNAggregation implements ResolvesToArray { public const NAME = '$minN'; diff --git a/src/Builder/Aggregation/MinuteAggregation.php b/src/Builder/Aggregation/MinuteAggregation.php index d4270fd2c..cb82f54a6 100644 --- a/src/Builder/Aggregation/MinuteAggregation.php +++ b/src/Builder/Aggregation/MinuteAggregation.php @@ -9,6 +9,7 @@ use DateTimeInterface; use MongoDB\BSON\Int64; use MongoDB\BSON\ObjectId; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToDate; use MongoDB\Builder\Expression\ResolvesToInt; @@ -17,13 +18,18 @@ use MongoDB\Builder\Expression\ResolvesToTimestamp; use MongoDB\Builder\Optional; +/** + * Returns the minute for a date as a number between 0 and 59. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/minute/ + */ class MinuteAggregation implements ResolvesToInt { public const NAME = '$minute'; public const ENCODE = \MongoDB\Builder\Encode::Object; /** @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ - public \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; + public DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; /** @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public ResolvesToString|Optional|string $timezone; @@ -33,7 +39,7 @@ class MinuteAggregation implements ResolvesToInt * @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public function __construct( - \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|Optional|string $timezone = Optional::Undefined, ) { $this->date = $date; diff --git a/src/Builder/Aggregation/ModAggregation.php b/src/Builder/Aggregation/ModAggregation.php index 3ee503864..52cf6bde9 100644 --- a/src/Builder/Aggregation/ModAggregation.php +++ b/src/Builder/Aggregation/ModAggregation.php @@ -12,6 +12,11 @@ use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Expression\ResolvesToNumber; +/** + * Returns the remainder of the first number divided by the second. Accepts two argument expressions. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/mod/ + */ class ModAggregation implements ResolvesToInt { public const NAME = '$mod'; diff --git a/src/Builder/Aggregation/MonthAggregation.php b/src/Builder/Aggregation/MonthAggregation.php index d5bed8d24..3ef8a3569 100644 --- a/src/Builder/Aggregation/MonthAggregation.php +++ b/src/Builder/Aggregation/MonthAggregation.php @@ -9,6 +9,7 @@ use DateTimeInterface; use MongoDB\BSON\Int64; use MongoDB\BSON\ObjectId; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToDate; use MongoDB\Builder\Expression\ResolvesToInt; @@ -17,13 +18,18 @@ use MongoDB\Builder\Expression\ResolvesToTimestamp; use MongoDB\Builder\Optional; +/** + * Returns the month for a date as a number between 1 (January) and 12 (December). + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/month/ + */ class MonthAggregation implements ResolvesToInt { public const NAME = '$month'; public const ENCODE = \MongoDB\Builder\Encode::Object; /** @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ - public \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; + public DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; /** @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public ResolvesToString|Optional|string $timezone; @@ -33,7 +39,7 @@ class MonthAggregation implements ResolvesToInt * @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public function __construct( - \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|Optional|string $timezone = Optional::Undefined, ) { $this->date = $date; diff --git a/src/Builder/Aggregation/MultiplyAggregation.php b/src/Builder/Aggregation/MultiplyAggregation.php index b831e8524..01854f4aa 100644 --- a/src/Builder/Aggregation/MultiplyAggregation.php +++ b/src/Builder/Aggregation/MultiplyAggregation.php @@ -12,6 +12,11 @@ use MongoDB\Builder\Expression\ResolvesToDecimal; use MongoDB\Builder\Expression\ResolvesToNumber; +/** + * Multiplies numbers to return the product. Accepts any number of argument expressions. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/multiply/ + */ class MultiplyAggregation implements ResolvesToDecimal { public const NAME = '$multiply'; diff --git a/src/Builder/Aggregation/NeAggregation.php b/src/Builder/Aggregation/NeAggregation.php index 759eb597c..50224149c 100644 --- a/src/Builder/Aggregation/NeAggregation.php +++ b/src/Builder/Aggregation/NeAggregation.php @@ -10,6 +10,11 @@ use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToBool; +/** + * Returns true if the values are not equivalent. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/ne/ + */ class NeAggregation implements ResolvesToBool { public const NAME = '$ne'; diff --git a/src/Builder/Aggregation/NotAggregation.php b/src/Builder/Aggregation/NotAggregation.php index 745e5d09f..dbc43c497 100644 --- a/src/Builder/Aggregation/NotAggregation.php +++ b/src/Builder/Aggregation/NotAggregation.php @@ -10,6 +10,11 @@ use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToBool; +/** + * Returns the boolean value that is the opposite of its argument expression. Accepts a single argument expression. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/not/ + */ class NotAggregation implements ResolvesToBool { public const NAME = '$not'; diff --git a/src/Builder/Aggregation/ObjectToArrayAggregation.php b/src/Builder/Aggregation/ObjectToArrayAggregation.php index 275b5a926..d5afafc6f 100644 --- a/src/Builder/Aggregation/ObjectToArrayAggregation.php +++ b/src/Builder/Aggregation/ObjectToArrayAggregation.php @@ -13,6 +13,11 @@ use MongoDB\Builder\Expression\ResolvesToObject; use stdClass; +/** + * Converts a document to an array of documents representing key-value pairs. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/objectToArray/ + */ class ObjectToArrayAggregation implements ResolvesToArray { public const NAME = '$objectToArray'; diff --git a/src/Builder/Aggregation/OrAggregation.php b/src/Builder/Aggregation/OrAggregation.php index 704c4670e..767ae251f 100644 --- a/src/Builder/Aggregation/OrAggregation.php +++ b/src/Builder/Aggregation/OrAggregation.php @@ -10,6 +10,11 @@ use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToBool; +/** + * Returns true when any of its expressions evaluates to true. Accepts any number of argument expressions. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/or/ + */ class OrAggregation implements ResolvesToBool { public const NAME = '$or'; diff --git a/src/Builder/Aggregation/PercentileAggregation.php b/src/Builder/Aggregation/PercentileAggregation.php index 873f2f949..38640844d 100644 --- a/src/Builder/Aggregation/PercentileAggregation.php +++ b/src/Builder/Aggregation/PercentileAggregation.php @@ -15,6 +15,19 @@ use MongoDB\Builder\Expression\ResolvesToNumber; use MongoDB\Model\BSONArray; +/** + * Returns an array of scalar values that correspond to specified percentile values. + * New in version 7.0. + * + * This operator is available as an accumulator in these stages: + * $group + * + * $setWindowFields + * + * It is also available as an aggregation expression. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/percentile/ + */ class PercentileAggregation implements ResolvesToArray, AccumulatorInterface { public const NAME = '$percentile'; diff --git a/src/Builder/Aggregation/PowAggregation.php b/src/Builder/Aggregation/PowAggregation.php index 35c4f0452..e576e87f6 100644 --- a/src/Builder/Aggregation/PowAggregation.php +++ b/src/Builder/Aggregation/PowAggregation.php @@ -11,6 +11,11 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToNumber; +/** + * Raises a number to the specified exponent. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/pow/ + */ class PowAggregation implements ResolvesToNumber { public const NAME = '$pow'; diff --git a/src/Builder/Aggregation/PushAggregation.php b/src/Builder/Aggregation/PushAggregation.php index 2dc109455..0c0a0ab5d 100644 --- a/src/Builder/Aggregation/PushAggregation.php +++ b/src/Builder/Aggregation/PushAggregation.php @@ -9,6 +9,12 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ExpressionInterface; +/** + * Returns an array of values that result from applying an expression to each document. + * Changed in version 5.0: Available in the $setWindowFields stage. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/push/ + */ class PushAggregation implements AccumulatorInterface { public const NAME = '$push'; diff --git a/src/Builder/Aggregation/RadiansToDegreesAggregation.php b/src/Builder/Aggregation/RadiansToDegreesAggregation.php index 0ea456acc..b79658a79 100644 --- a/src/Builder/Aggregation/RadiansToDegreesAggregation.php +++ b/src/Builder/Aggregation/RadiansToDegreesAggregation.php @@ -13,6 +13,11 @@ use MongoDB\Builder\Expression\ResolvesToDouble; use MongoDB\Builder\Expression\ResolvesToNumber; +/** + * Converts a value from radians to degrees. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/radiansToDegrees/ + */ class RadiansToDegreesAggregation implements ResolvesToDouble, ResolvesToDecimal { public const NAME = '$radiansToDegrees'; diff --git a/src/Builder/Aggregation/RandAggregation.php b/src/Builder/Aggregation/RandAggregation.php index 8ba405473..8b55e32d2 100644 --- a/src/Builder/Aggregation/RandAggregation.php +++ b/src/Builder/Aggregation/RandAggregation.php @@ -9,6 +9,11 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToFloat; +/** + * Returns a random float between 0 and 1 + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/rand/ + */ class RandAggregation implements ResolvesToFloat { public const NAME = '$rand'; diff --git a/src/Builder/Aggregation/RangeAggregation.php b/src/Builder/Aggregation/RangeAggregation.php index f0ec3a44f..4f31ebafb 100644 --- a/src/Builder/Aggregation/RangeAggregation.php +++ b/src/Builder/Aggregation/RangeAggregation.php @@ -12,6 +12,11 @@ use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Optional; +/** + * Outputs an array containing a sequence of integers according to user-defined inputs. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/range/ + */ class RangeAggregation implements ResolvesToArray { public const NAME = '$range'; diff --git a/src/Builder/Aggregation/RankAggregation.php b/src/Builder/Aggregation/RankAggregation.php index 97f1a9b3f..f851022da 100644 --- a/src/Builder/Aggregation/RankAggregation.php +++ b/src/Builder/Aggregation/RankAggregation.php @@ -9,6 +9,12 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToInt; +/** + * Returns the document position (known as the rank) relative to other documents in the $setWindowFields stage partition. + * New in version 5.0. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/rank/ + */ class RankAggregation implements ResolvesToInt { public const NAME = '$rank'; diff --git a/src/Builder/Aggregation/ReduceAggregation.php b/src/Builder/Aggregation/ReduceAggregation.php index 1c4a06a05..0f9caa72f 100644 --- a/src/Builder/Aggregation/ReduceAggregation.php +++ b/src/Builder/Aggregation/ReduceAggregation.php @@ -12,6 +12,11 @@ use MongoDB\Builder\Expression\ResolvesToArray; use MongoDB\Model\BSONArray; +/** + * Applies an expression to each element in an array and combines them into a single value. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/reduce/ + */ class ReduceAggregation implements ExpressionInterface { public const NAME = '$reduce'; diff --git a/src/Builder/Aggregation/RegexFindAggregation.php b/src/Builder/Aggregation/RegexFindAggregation.php index 81900a853..73e749cb6 100644 --- a/src/Builder/Aggregation/RegexFindAggregation.php +++ b/src/Builder/Aggregation/RegexFindAggregation.php @@ -12,6 +12,12 @@ use MongoDB\Builder\Expression\ResolvesToString; use MongoDB\Builder\Optional; +/** + * Applies a regular expression (regex) to a string and returns information on the first matched substring. + * New in version 4.2. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/regexFind/ + */ class RegexFindAggregation implements ResolvesToObject { public const NAME = '$regexFind'; diff --git a/src/Builder/Aggregation/RegexFindAllAggregation.php b/src/Builder/Aggregation/RegexFindAllAggregation.php index 7474b96bd..e6f763b33 100644 --- a/src/Builder/Aggregation/RegexFindAllAggregation.php +++ b/src/Builder/Aggregation/RegexFindAllAggregation.php @@ -12,6 +12,12 @@ use MongoDB\Builder\Expression\ResolvesToString; use MongoDB\Builder\Optional; +/** + * Applies a regular expression (regex) to a string and returns information on the all matched substrings. + * New in version 4.2. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/regexFindAll/ + */ class RegexFindAllAggregation implements ResolvesToArray { public const NAME = '$regexFindAll'; diff --git a/src/Builder/Aggregation/RegexMatchAggregation.php b/src/Builder/Aggregation/RegexMatchAggregation.php index 378c6f49f..10a3132ba 100644 --- a/src/Builder/Aggregation/RegexMatchAggregation.php +++ b/src/Builder/Aggregation/RegexMatchAggregation.php @@ -12,6 +12,12 @@ use MongoDB\Builder\Expression\ResolvesToString; use MongoDB\Builder\Optional; +/** + * Applies a regular expression (regex) to a string and returns a boolean that indicates if a match is found or not. + * New in version 4.2. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/regexMatch/ + */ class RegexMatchAggregation implements ResolvesToBool { public const NAME = '$regexMatch'; diff --git a/src/Builder/Aggregation/ReplaceAllAggregation.php b/src/Builder/Aggregation/ReplaceAllAggregation.php index 314f1c204..4da4108ed 100644 --- a/src/Builder/Aggregation/ReplaceAllAggregation.php +++ b/src/Builder/Aggregation/ReplaceAllAggregation.php @@ -10,6 +10,13 @@ use MongoDB\Builder\Expression\ResolvesToNull; use MongoDB\Builder\Expression\ResolvesToString; +/** + * Replaces all instances of a search string in an input string with a replacement string. + * $replaceAll is both case-sensitive and diacritic-sensitive, and ignores any collation present on a collection. + * New in version 4.4. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceAll/ + */ class ReplaceAllAggregation implements ResolvesToString { public const NAME = '$replaceAll'; diff --git a/src/Builder/Aggregation/ReplaceOneAggregation.php b/src/Builder/Aggregation/ReplaceOneAggregation.php index 6a8bb0017..20063d5ef 100644 --- a/src/Builder/Aggregation/ReplaceOneAggregation.php +++ b/src/Builder/Aggregation/ReplaceOneAggregation.php @@ -10,6 +10,12 @@ use MongoDB\Builder\Expression\ResolvesToNull; use MongoDB\Builder\Expression\ResolvesToString; +/** + * Replaces the first instance of a matched string in a given input. + * New in version 4.4. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceOne/ + */ class ReplaceOneAggregation implements ResolvesToString { public const NAME = '$replaceOne'; diff --git a/src/Builder/Aggregation/ReverseArrayAggregation.php b/src/Builder/Aggregation/ReverseArrayAggregation.php index 63f40e2c2..15d7f4e74 100644 --- a/src/Builder/Aggregation/ReverseArrayAggregation.php +++ b/src/Builder/Aggregation/ReverseArrayAggregation.php @@ -12,6 +12,11 @@ use MongoDB\Builder\Expression\ResolvesToArray; use MongoDB\Model\BSONArray; +/** + * Returns an array with the elements in reverse order. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/reverseArray/ + */ class ReverseArrayAggregation implements ResolvesToArray { public const NAME = '$reverseArray'; diff --git a/src/Builder/Aggregation/RoundAggregation.php b/src/Builder/Aggregation/RoundAggregation.php index 94f9bfde3..8e164c30a 100644 --- a/src/Builder/Aggregation/RoundAggregation.php +++ b/src/Builder/Aggregation/RoundAggregation.php @@ -15,6 +15,11 @@ use MongoDB\Builder\Expression\ResolvesToLong; use MongoDB\Builder\Optional; +/** + * Rounds a number to to a whole integer or to a specified decimal place. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/round/ + */ class RoundAggregation implements ResolvesToInt, ResolvesToDouble, ResolvesToDecimal, ResolvesToLong { public const NAME = '$round'; diff --git a/src/Builder/Aggregation/RtrimAggregation.php b/src/Builder/Aggregation/RtrimAggregation.php index 5090b8328..03bd1c7e4 100644 --- a/src/Builder/Aggregation/RtrimAggregation.php +++ b/src/Builder/Aggregation/RtrimAggregation.php @@ -10,6 +10,11 @@ use MongoDB\Builder\Expression\ResolvesToString; use MongoDB\Builder\Optional; +/** + * Removes whitespace characters, including null, or the specified characters from the end of a string. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/rtrim/ + */ class RtrimAggregation implements ResolvesToString { public const NAME = '$rtrim'; diff --git a/src/Builder/Aggregation/SampleRateAggregation.php b/src/Builder/Aggregation/SampleRateAggregation.php index 939adc3f8..9cc7ddd46 100644 --- a/src/Builder/Aggregation/SampleRateAggregation.php +++ b/src/Builder/Aggregation/SampleRateAggregation.php @@ -11,6 +11,11 @@ use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToFloat; +/** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/sampleRate/ + */ class SampleRateAggregation implements ExpressionInterface { public const NAME = '$sampleRate'; diff --git a/src/Builder/Aggregation/SecondAggregation.php b/src/Builder/Aggregation/SecondAggregation.php index 0d4c5acc0..068957878 100644 --- a/src/Builder/Aggregation/SecondAggregation.php +++ b/src/Builder/Aggregation/SecondAggregation.php @@ -9,6 +9,7 @@ use DateTimeInterface; use MongoDB\BSON\Int64; use MongoDB\BSON\ObjectId; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToDate; use MongoDB\Builder\Expression\ResolvesToInt; @@ -17,13 +18,18 @@ use MongoDB\Builder\Expression\ResolvesToTimestamp; use MongoDB\Builder\Optional; +/** + * Returns the seconds for a date as a number between 0 and 60 (leap seconds). + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/second/ + */ class SecondAggregation implements ResolvesToInt { public const NAME = '$second'; public const ENCODE = \MongoDB\Builder\Encode::Object; /** @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ - public \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; + public DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; /** @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public ResolvesToString|Optional|string $timezone; @@ -33,7 +39,7 @@ class SecondAggregation implements ResolvesToInt * @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public function __construct( - \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|Optional|string $timezone = Optional::Undefined, ) { $this->date = $date; diff --git a/src/Builder/Aggregation/SetDifferenceAggregation.php b/src/Builder/Aggregation/SetDifferenceAggregation.php index ecb3ae016..b4fd3eb27 100644 --- a/src/Builder/Aggregation/SetDifferenceAggregation.php +++ b/src/Builder/Aggregation/SetDifferenceAggregation.php @@ -12,6 +12,11 @@ use MongoDB\Builder\Expression\ResolvesToArray; use MongoDB\Model\BSONArray; +/** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/setDifference/ + */ class SetDifferenceAggregation implements ResolvesToArray { public const NAME = '$setDifference'; diff --git a/src/Builder/Aggregation/SetEqualsAggregation.php b/src/Builder/Aggregation/SetEqualsAggregation.php index 8f3846592..b9f50ab8b 100644 --- a/src/Builder/Aggregation/SetEqualsAggregation.php +++ b/src/Builder/Aggregation/SetEqualsAggregation.php @@ -13,6 +13,11 @@ use MongoDB\Builder\Expression\ResolvesToBool; use MongoDB\Model\BSONArray; +/** + * Returns true if the input sets have the same distinct elements. Accepts two or more argument expressions. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/setEquals/ + */ class SetEqualsAggregation implements ResolvesToBool { public const NAME = '$setEquals'; diff --git a/src/Builder/Aggregation/SetFieldAggregation.php b/src/Builder/Aggregation/SetFieldAggregation.php index 278b32ea9..8484fa2ac 100644 --- a/src/Builder/Aggregation/SetFieldAggregation.php +++ b/src/Builder/Aggregation/SetFieldAggregation.php @@ -14,6 +14,12 @@ use MongoDB\Builder\Expression\ResolvesToString; use stdClass; +/** + * 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 version 5.0. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/setField/ + */ class SetFieldAggregation implements ResolvesToObject { public const NAME = '$setField'; diff --git a/src/Builder/Aggregation/SetIntersectionAggregation.php b/src/Builder/Aggregation/SetIntersectionAggregation.php index 90c97c0ba..8c3b702a1 100644 --- a/src/Builder/Aggregation/SetIntersectionAggregation.php +++ b/src/Builder/Aggregation/SetIntersectionAggregation.php @@ -12,6 +12,11 @@ use MongoDB\Builder\Expression\ResolvesToArray; use MongoDB\Model\BSONArray; +/** + * Returns a set with elements that appear in all of the input sets. Accepts any number of argument expressions. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/setIntersection/ + */ class SetIntersectionAggregation implements ResolvesToArray { public const NAME = '$setIntersection'; diff --git a/src/Builder/Aggregation/SetIsSubsetAggregation.php b/src/Builder/Aggregation/SetIsSubsetAggregation.php index 0afa1eb49..6897159a4 100644 --- a/src/Builder/Aggregation/SetIsSubsetAggregation.php +++ b/src/Builder/Aggregation/SetIsSubsetAggregation.php @@ -13,6 +13,11 @@ use MongoDB\Builder\Expression\ResolvesToBool; use MongoDB\Model\BSONArray; +/** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/setIsSubset/ + */ class SetIsSubsetAggregation implements ResolvesToBool { public const NAME = '$setIsSubset'; diff --git a/src/Builder/Aggregation/SetUnionAggregation.php b/src/Builder/Aggregation/SetUnionAggregation.php index 8084f3c5f..ec7904b9d 100644 --- a/src/Builder/Aggregation/SetUnionAggregation.php +++ b/src/Builder/Aggregation/SetUnionAggregation.php @@ -12,6 +12,11 @@ use MongoDB\Builder\Expression\ResolvesToArray; use MongoDB\Model\BSONArray; +/** + * Returns a set with elements that appear in any of the input sets. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/setUnion/ + */ class SetUnionAggregation implements ResolvesToArray { public const NAME = '$setUnion'; diff --git a/src/Builder/Aggregation/ShiftAggregation.php b/src/Builder/Aggregation/ShiftAggregation.php index f24d2beb1..705f117a5 100644 --- a/src/Builder/Aggregation/ShiftAggregation.php +++ b/src/Builder/Aggregation/ShiftAggregation.php @@ -10,6 +10,12 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ExpressionInterface; +/** + * 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 version 5.0. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/shift/ + */ class ShiftAggregation implements ExpressionInterface { public const NAME = '$shift'; diff --git a/src/Builder/Aggregation/SinAggregation.php b/src/Builder/Aggregation/SinAggregation.php index da4983203..59b59711c 100644 --- a/src/Builder/Aggregation/SinAggregation.php +++ b/src/Builder/Aggregation/SinAggregation.php @@ -13,6 +13,11 @@ use MongoDB\Builder\Expression\ResolvesToDouble; use MongoDB\Builder\Expression\ResolvesToNumber; +/** + * Returns the sine of a value that is measured in radians. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/sin/ + */ class SinAggregation implements ResolvesToDouble, ResolvesToDecimal { public const NAME = '$sin'; diff --git a/src/Builder/Aggregation/SinhAggregation.php b/src/Builder/Aggregation/SinhAggregation.php index 450f68091..480a9b321 100644 --- a/src/Builder/Aggregation/SinhAggregation.php +++ b/src/Builder/Aggregation/SinhAggregation.php @@ -13,6 +13,11 @@ use MongoDB\Builder\Expression\ResolvesToDouble; use MongoDB\Builder\Expression\ResolvesToNumber; +/** + * Returns the hyperbolic sine of a value that is measured in radians. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/sinh/ + */ class SinhAggregation implements ResolvesToDouble, ResolvesToDecimal { public const NAME = '$sinh'; diff --git a/src/Builder/Aggregation/SizeAggregation.php b/src/Builder/Aggregation/SizeAggregation.php index fba4805b0..d05c21518 100644 --- a/src/Builder/Aggregation/SizeAggregation.php +++ b/src/Builder/Aggregation/SizeAggregation.php @@ -13,6 +13,11 @@ use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Model\BSONArray; +/** + * Returns the number of elements in the array. Accepts a single expression as argument. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/size/ + */ class SizeAggregation implements ResolvesToInt { public const NAME = '$size'; diff --git a/src/Builder/Aggregation/SliceAggregation.php b/src/Builder/Aggregation/SliceAggregation.php index 6757ee320..4b843821d 100644 --- a/src/Builder/Aggregation/SliceAggregation.php +++ b/src/Builder/Aggregation/SliceAggregation.php @@ -15,6 +15,11 @@ use MongoDB\Builder\Optional; use MongoDB\Model\BSONArray; +/** + * Returns a subset of an array. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/slice/ + */ class SliceAggregation implements ResolvesToArray { public const NAME = '$slice'; diff --git a/src/Builder/Aggregation/SortArrayAggregation.php b/src/Builder/Aggregation/SortArrayAggregation.php index c1e8d4845..6d65bc3c0 100644 --- a/src/Builder/Aggregation/SortArrayAggregation.php +++ b/src/Builder/Aggregation/SortArrayAggregation.php @@ -13,6 +13,11 @@ use MongoDB\Model\BSONArray; use stdClass; +/** + * Sorts the elements of an array. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/sortArray/ + */ class SortArrayAggregation implements ResolvesToArray { public const NAME = '$sortArray'; diff --git a/src/Builder/Aggregation/SplitAggregation.php b/src/Builder/Aggregation/SplitAggregation.php index 78edd5b31..a8fd48b10 100644 --- a/src/Builder/Aggregation/SplitAggregation.php +++ b/src/Builder/Aggregation/SplitAggregation.php @@ -10,6 +10,11 @@ use MongoDB\Builder\Expression\ResolvesToArray; use MongoDB\Builder\Expression\ResolvesToString; +/** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/split/ + */ class SplitAggregation implements ResolvesToArray { public const NAME = '$split'; diff --git a/src/Builder/Aggregation/SqrtAggregation.php b/src/Builder/Aggregation/SqrtAggregation.php index e056f6f3f..b819efe0a 100644 --- a/src/Builder/Aggregation/SqrtAggregation.php +++ b/src/Builder/Aggregation/SqrtAggregation.php @@ -12,6 +12,11 @@ use MongoDB\Builder\Expression\ResolvesToDouble; use MongoDB\Builder\Expression\ResolvesToNumber; +/** + * Calculates the square root. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/sqrt/ + */ class SqrtAggregation implements ResolvesToDouble { public const NAME = '$sqrt'; diff --git a/src/Builder/Aggregation/StdDevPopAggregation.php b/src/Builder/Aggregation/StdDevPopAggregation.php index 6c552a832..166ec3631 100644 --- a/src/Builder/Aggregation/StdDevPopAggregation.php +++ b/src/Builder/Aggregation/StdDevPopAggregation.php @@ -12,6 +12,13 @@ use MongoDB\Builder\Expression\ResolvesToDouble; use MongoDB\Builder\Expression\ResolvesToNumber; +/** + * Calculates the population standard deviation of the input values. Use if the values encompass the entire population of data you want to represent and do not wish to generalize about a larger population. $stdDevPop ignores non-numeric values. + * If the values represent only a sample of a population of data from which to generalize about the population, use $stdDevSamp instead. + * Changed in version 5.0: Available in the $setWindowFields stage. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/stdDevPop/ + */ class StdDevPopAggregation implements ResolvesToDouble, AccumulatorInterface { public const NAME = '$stdDevPop'; diff --git a/src/Builder/Aggregation/StdDevSampAggregation.php b/src/Builder/Aggregation/StdDevSampAggregation.php index 9877d210e..8787ca07c 100644 --- a/src/Builder/Aggregation/StdDevSampAggregation.php +++ b/src/Builder/Aggregation/StdDevSampAggregation.php @@ -12,6 +12,13 @@ use MongoDB\Builder\Expression\ResolvesToDouble; use MongoDB\Builder\Expression\ResolvesToNumber; +/** + * Calculates the sample standard deviation of the input values. Use if the values encompass a sample of a population of data from which to generalize about the population. $stdDevSamp ignores non-numeric values. + * If the values represent the entire population of data or you do not wish to generalize about a larger population, use $stdDevPop instead. + * Changed in version 5.0: Available in the $setWindowFields stage. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/stdDevSamp/ + */ class StdDevSampAggregation implements ResolvesToDouble, AccumulatorInterface { public const NAME = '$stdDevSamp'; diff --git a/src/Builder/Aggregation/StrLenBytesAggregation.php b/src/Builder/Aggregation/StrLenBytesAggregation.php index 6deee6886..2568a2c15 100644 --- a/src/Builder/Aggregation/StrLenBytesAggregation.php +++ b/src/Builder/Aggregation/StrLenBytesAggregation.php @@ -10,6 +10,11 @@ use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Expression\ResolvesToString; +/** + * Returns the number of UTF-8 encoded bytes in a string. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/strLenBytes/ + */ class StrLenBytesAggregation implements ResolvesToInt { public const NAME = '$strLenBytes'; diff --git a/src/Builder/Aggregation/StrLenCPAggregation.php b/src/Builder/Aggregation/StrLenCPAggregation.php index ba89704c4..0377fd374 100644 --- a/src/Builder/Aggregation/StrLenCPAggregation.php +++ b/src/Builder/Aggregation/StrLenCPAggregation.php @@ -10,6 +10,11 @@ use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Expression\ResolvesToString; +/** + * Returns the number of UTF-8 code points in a string. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/strLenCP/ + */ class StrLenCPAggregation implements ResolvesToInt { public const NAME = '$strLenCP'; diff --git a/src/Builder/Aggregation/StrcasecmpAggregation.php b/src/Builder/Aggregation/StrcasecmpAggregation.php index 1bbf70ceb..3567c8b57 100644 --- a/src/Builder/Aggregation/StrcasecmpAggregation.php +++ b/src/Builder/Aggregation/StrcasecmpAggregation.php @@ -10,6 +10,11 @@ use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Expression\ResolvesToString; +/** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/strcasecmp/ + */ class StrcasecmpAggregation implements ResolvesToInt { public const NAME = '$strcasecmp'; diff --git a/src/Builder/Aggregation/SubstrAggregation.php b/src/Builder/Aggregation/SubstrAggregation.php index 7c7007d20..ea3517378 100644 --- a/src/Builder/Aggregation/SubstrAggregation.php +++ b/src/Builder/Aggregation/SubstrAggregation.php @@ -11,6 +11,11 @@ use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Expression\ResolvesToString; +/** + * Deprecated. Use $substrBytes or $substrCP. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/substr/ + */ class SubstrAggregation implements ResolvesToString { public const NAME = '$substr'; diff --git a/src/Builder/Aggregation/SubstrBytesAggregation.php b/src/Builder/Aggregation/SubstrBytesAggregation.php index 99bd39d66..0fdd73906 100644 --- a/src/Builder/Aggregation/SubstrBytesAggregation.php +++ b/src/Builder/Aggregation/SubstrBytesAggregation.php @@ -11,6 +11,11 @@ use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Expression\ResolvesToString; +/** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/substrBytes/ + */ class SubstrBytesAggregation implements ResolvesToString { public const NAME = '$substrBytes'; diff --git a/src/Builder/Aggregation/SubstrCPAggregation.php b/src/Builder/Aggregation/SubstrCPAggregation.php index d62dbbb48..ef4a764f5 100644 --- a/src/Builder/Aggregation/SubstrCPAggregation.php +++ b/src/Builder/Aggregation/SubstrCPAggregation.php @@ -11,6 +11,11 @@ use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Expression\ResolvesToString; +/** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/substrCP/ + */ class SubstrCPAggregation implements ResolvesToString { public const NAME = '$substrCP'; diff --git a/src/Builder/Aggregation/SubtractAggregation.php b/src/Builder/Aggregation/SubtractAggregation.php index 7db3b36e0..cbc834f58 100644 --- a/src/Builder/Aggregation/SubtractAggregation.php +++ b/src/Builder/Aggregation/SubtractAggregation.php @@ -9,28 +9,34 @@ use DateTimeInterface; use MongoDB\BSON\Decimal128; use MongoDB\BSON\Int64; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToDate; use MongoDB\Builder\Expression\ResolvesToNumber; +/** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/subtract/ + */ class SubtractAggregation implements ResolvesToNumber, ResolvesToDate { public const NAME = '$subtract'; public const ENCODE = \MongoDB\Builder\Encode::Array; /** @param DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int $expression1 */ - public \UTCDateTime|DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|float|int $expression1; + public DateTimeInterface|Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int $expression1; /** @param DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int $expression2 */ - public \UTCDateTime|DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|float|int $expression2; + public DateTimeInterface|Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int $expression2; /** * @param DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int $expression1 * @param DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int $expression2 */ public function __construct( - \UTCDateTime|DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|float|int $expression1, - \UTCDateTime|DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|float|int $expression2, + DateTimeInterface|Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int $expression1, + DateTimeInterface|Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int $expression2, ) { $this->expression1 = $expression1; $this->expression2 = $expression2; diff --git a/src/Builder/Aggregation/SumAggregation.php b/src/Builder/Aggregation/SumAggregation.php index c80f12850..d1d04b8f2 100644 --- a/src/Builder/Aggregation/SumAggregation.php +++ b/src/Builder/Aggregation/SumAggregation.php @@ -11,6 +11,12 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToNumber; +/** + * Returns a sum of numerical values. Ignores non-numeric values. + * Changed in version 5.0: Available in the $setWindowFields stage. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/sum/ + */ class SumAggregation implements ResolvesToNumber, AccumulatorInterface { public const NAME = '$sum'; diff --git a/src/Builder/Aggregation/SwitchAggregation.php b/src/Builder/Aggregation/SwitchAggregation.php index a5491d7a5..8624ede48 100644 --- a/src/Builder/Aggregation/SwitchAggregation.php +++ b/src/Builder/Aggregation/SwitchAggregation.php @@ -12,6 +12,11 @@ use MongoDB\Builder\Optional; use MongoDB\Model\BSONArray; +/** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/switch/ + */ class SwitchAggregation implements ExpressionInterface { public const NAME = '$switch'; diff --git a/src/Builder/Aggregation/TanAggregation.php b/src/Builder/Aggregation/TanAggregation.php index 0c41ddfde..5d355f615 100644 --- a/src/Builder/Aggregation/TanAggregation.php +++ b/src/Builder/Aggregation/TanAggregation.php @@ -13,6 +13,11 @@ use MongoDB\Builder\Expression\ResolvesToDouble; use MongoDB\Builder\Expression\ResolvesToNumber; +/** + * Returns the tangent of a value that is measured in radians. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/tan/ + */ class TanAggregation implements ResolvesToDouble, ResolvesToDecimal { public const NAME = '$tan'; diff --git a/src/Builder/Aggregation/TanhAggregation.php b/src/Builder/Aggregation/TanhAggregation.php index 501a1f1a8..1ab3680b2 100644 --- a/src/Builder/Aggregation/TanhAggregation.php +++ b/src/Builder/Aggregation/TanhAggregation.php @@ -13,6 +13,11 @@ use MongoDB\Builder\Expression\ResolvesToDouble; use MongoDB\Builder\Expression\ResolvesToNumber; +/** + * Returns the hyperbolic tangent of a value that is measured in radians. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/tanh/ + */ class TanhAggregation implements ResolvesToDouble, ResolvesToDecimal { public const NAME = '$tanh'; diff --git a/src/Builder/Aggregation/ToBoolAggregation.php b/src/Builder/Aggregation/ToBoolAggregation.php index bf400965a..4e2889a5f 100644 --- a/src/Builder/Aggregation/ToBoolAggregation.php +++ b/src/Builder/Aggregation/ToBoolAggregation.php @@ -10,6 +10,12 @@ use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToBool; +/** + * Converts value to a boolean. + * New in version 4.0. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toBool/ + */ class ToBoolAggregation implements ResolvesToBool { public const NAME = '$toBool'; diff --git a/src/Builder/Aggregation/ToDateAggregation.php b/src/Builder/Aggregation/ToDateAggregation.php index 394754eaa..f3022884b 100644 --- a/src/Builder/Aggregation/ToDateAggregation.php +++ b/src/Builder/Aggregation/ToDateAggregation.php @@ -10,6 +10,12 @@ use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToDate; +/** + * Converts value to a Date. + * New in version 4.0. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toDate/ + */ class ToDateAggregation implements ResolvesToDate { public const NAME = '$toDate'; diff --git a/src/Builder/Aggregation/ToDecimalAggregation.php b/src/Builder/Aggregation/ToDecimalAggregation.php index 590b65071..608a34604 100644 --- a/src/Builder/Aggregation/ToDecimalAggregation.php +++ b/src/Builder/Aggregation/ToDecimalAggregation.php @@ -10,6 +10,12 @@ use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToDecimal; +/** + * Converts value to a Decimal128. + * New in version 4.0. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toDecimal/ + */ class ToDecimalAggregation implements ResolvesToDecimal { public const NAME = '$toDecimal'; diff --git a/src/Builder/Aggregation/ToDoubleAggregation.php b/src/Builder/Aggregation/ToDoubleAggregation.php index c3ed692f8..7ed811274 100644 --- a/src/Builder/Aggregation/ToDoubleAggregation.php +++ b/src/Builder/Aggregation/ToDoubleAggregation.php @@ -10,6 +10,12 @@ use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToDouble; +/** + * Converts value to a double. + * New in version 4.0. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toDouble/ + */ class ToDoubleAggregation implements ResolvesToDouble { public const NAME = '$toDouble'; diff --git a/src/Builder/Aggregation/ToIntAggregation.php b/src/Builder/Aggregation/ToIntAggregation.php index 35782c8b2..c13fdbecc 100644 --- a/src/Builder/Aggregation/ToIntAggregation.php +++ b/src/Builder/Aggregation/ToIntAggregation.php @@ -10,6 +10,12 @@ use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToInt; +/** + * Converts value to an integer. + * New in version 4.0. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toInt/ + */ class ToIntAggregation implements ResolvesToInt { public const NAME = '$toInt'; diff --git a/src/Builder/Aggregation/ToLongAggregation.php b/src/Builder/Aggregation/ToLongAggregation.php index a53f20ee7..72a1079c9 100644 --- a/src/Builder/Aggregation/ToLongAggregation.php +++ b/src/Builder/Aggregation/ToLongAggregation.php @@ -10,6 +10,12 @@ use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToLong; +/** + * Converts value to a long. + * New in version 4.0. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toLong/ + */ class ToLongAggregation implements ResolvesToLong { public const NAME = '$toLong'; diff --git a/src/Builder/Aggregation/ToLowerAggregation.php b/src/Builder/Aggregation/ToLowerAggregation.php index 0dc3c9dd5..213f6b19f 100644 --- a/src/Builder/Aggregation/ToLowerAggregation.php +++ b/src/Builder/Aggregation/ToLowerAggregation.php @@ -9,6 +9,11 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToString; +/** + * Converts a string to lowercase. Accepts a single argument expression. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toLower/ + */ class ToLowerAggregation implements ResolvesToString { public const NAME = '$toLower'; diff --git a/src/Builder/Aggregation/ToObjectIdAggregation.php b/src/Builder/Aggregation/ToObjectIdAggregation.php index ae40bee36..d09242270 100644 --- a/src/Builder/Aggregation/ToObjectIdAggregation.php +++ b/src/Builder/Aggregation/ToObjectIdAggregation.php @@ -10,6 +10,12 @@ use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToObjectId; +/** + * Converts value to an ObjectId. + * New in version 4.0. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toObjectId/ + */ class ToObjectIdAggregation implements ResolvesToObjectId { public const NAME = '$toObjectId'; diff --git a/src/Builder/Aggregation/ToStringAggregation.php b/src/Builder/Aggregation/ToStringAggregation.php index f4bcf0930..533d3efcf 100644 --- a/src/Builder/Aggregation/ToStringAggregation.php +++ b/src/Builder/Aggregation/ToStringAggregation.php @@ -10,6 +10,12 @@ use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToString; +/** + * Converts value to a string. + * New in version 4.0. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toString/ + */ class ToStringAggregation implements ResolvesToString { public const NAME = '$toString'; diff --git a/src/Builder/Aggregation/ToUpperAggregation.php b/src/Builder/Aggregation/ToUpperAggregation.php index 284f992d1..f7152ff74 100644 --- a/src/Builder/Aggregation/ToUpperAggregation.php +++ b/src/Builder/Aggregation/ToUpperAggregation.php @@ -9,6 +9,11 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToString; +/** + * Converts a string to uppercase. Accepts a single argument expression. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toUpper/ + */ class ToUpperAggregation implements ResolvesToString { public const NAME = '$toUpper'; diff --git a/src/Builder/Aggregation/TopAggregation.php b/src/Builder/Aggregation/TopAggregation.php index ac3f4a1cb..d82450393 100644 --- a/src/Builder/Aggregation/TopAggregation.php +++ b/src/Builder/Aggregation/TopAggregation.php @@ -10,6 +10,14 @@ use MongoDB\Builder\Expression\ExpressionInterface; use stdClass; +/** + * Returns the top element within a group according to the specified sort order. + * New in version 5.2. + * + * Available in the $group and $setWindowFields stages. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/top/ + */ class TopAggregation implements AccumulatorInterface { public const NAME = '$top'; diff --git a/src/Builder/Aggregation/TopNAggregation.php b/src/Builder/Aggregation/TopNAggregation.php index 86b0365f3..148927e69 100644 --- a/src/Builder/Aggregation/TopNAggregation.php +++ b/src/Builder/Aggregation/TopNAggregation.php @@ -12,6 +12,14 @@ use MongoDB\Builder\Expression\ResolvesToInt; use stdClass; +/** + * Returns an aggregation of the top n fields within a group, according to the specified sort order. + * New in version 5.2. + * + * Available in the $group and $setWindowFields stages. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/topN/ + */ class TopNAggregation implements AccumulatorInterface { public const NAME = '$topN'; diff --git a/src/Builder/Aggregation/TrimAggregation.php b/src/Builder/Aggregation/TrimAggregation.php index b5e80e409..a695f6db3 100644 --- a/src/Builder/Aggregation/TrimAggregation.php +++ b/src/Builder/Aggregation/TrimAggregation.php @@ -10,6 +10,12 @@ use MongoDB\Builder\Expression\ResolvesToString; use MongoDB\Builder\Optional; +/** + * Removes whitespace or the specified characters from the beginning and end of a string. + * New in version 4.0. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/trim/ + */ class TrimAggregation implements ResolvesToString { public const NAME = '$trim'; diff --git a/src/Builder/Aggregation/TruncAggregation.php b/src/Builder/Aggregation/TruncAggregation.php index 59f78d590..8844f851a 100644 --- a/src/Builder/Aggregation/TruncAggregation.php +++ b/src/Builder/Aggregation/TruncAggregation.php @@ -14,6 +14,11 @@ use MongoDB\Builder\Expression\ResolvesToString; use MongoDB\Builder\Optional; +/** + * Truncates a number to a whole integer or to a specified decimal place. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/trunc/ + */ class TruncAggregation implements ResolvesToString { public const NAME = '$trunc'; diff --git a/src/Builder/Aggregation/TsIncrementAggregation.php b/src/Builder/Aggregation/TsIncrementAggregation.php index f2dbb2392..488b48c69 100644 --- a/src/Builder/Aggregation/TsIncrementAggregation.php +++ b/src/Builder/Aggregation/TsIncrementAggregation.php @@ -11,6 +11,12 @@ use MongoDB\Builder\Expression\ResolvesToLong; use MongoDB\Builder\Expression\ResolvesToTimestamp; +/** + * Returns the incrementing ordinal from a timestamp as a long. + * New in version 5.1. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/tsIncrement/ + */ class TsIncrementAggregation implements ResolvesToLong { public const NAME = '$tsIncrement'; diff --git a/src/Builder/Aggregation/TsSecondAggregation.php b/src/Builder/Aggregation/TsSecondAggregation.php index ea1438ec2..3b2dfed36 100644 --- a/src/Builder/Aggregation/TsSecondAggregation.php +++ b/src/Builder/Aggregation/TsSecondAggregation.php @@ -11,6 +11,12 @@ use MongoDB\Builder\Expression\ResolvesToLong; use MongoDB\Builder\Expression\ResolvesToTimestamp; +/** + * Returns the seconds from a timestamp as a long. + * New in version 5.1. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/tsSecond/ + */ class TsSecondAggregation implements ResolvesToLong { public const NAME = '$tsSecond'; diff --git a/src/Builder/Aggregation/TypeAggregation.php b/src/Builder/Aggregation/TypeAggregation.php index c12dbd00e..2d5a1958e 100644 --- a/src/Builder/Aggregation/TypeAggregation.php +++ b/src/Builder/Aggregation/TypeAggregation.php @@ -10,6 +10,11 @@ use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToString; +/** + * Return the BSON data type of the field. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/type/ + */ class TypeAggregation implements ResolvesToString { public const NAME = '$type'; diff --git a/src/Builder/Aggregation/UnsetFieldAggregation.php b/src/Builder/Aggregation/UnsetFieldAggregation.php index e67719165..db0210731 100644 --- a/src/Builder/Aggregation/UnsetFieldAggregation.php +++ b/src/Builder/Aggregation/UnsetFieldAggregation.php @@ -13,6 +13,12 @@ use MongoDB\Builder\Expression\ResolvesToString; use stdClass; +/** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/unsetField/ + */ class UnsetFieldAggregation implements ResolvesToObject { public const NAME = '$unsetField'; diff --git a/src/Builder/Aggregation/WeekAggregation.php b/src/Builder/Aggregation/WeekAggregation.php index 17a9d3f57..f67e5fe78 100644 --- a/src/Builder/Aggregation/WeekAggregation.php +++ b/src/Builder/Aggregation/WeekAggregation.php @@ -9,6 +9,7 @@ use DateTimeInterface; use MongoDB\BSON\Int64; use MongoDB\BSON\ObjectId; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToDate; use MongoDB\Builder\Expression\ResolvesToInt; @@ -17,13 +18,18 @@ use MongoDB\Builder\Expression\ResolvesToTimestamp; use MongoDB\Builder\Optional; +/** + * 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). + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/week/ + */ class WeekAggregation implements ResolvesToInt { public const NAME = '$week'; public const ENCODE = \MongoDB\Builder\Encode::Object; /** @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ - public \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; + public DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; /** @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public ResolvesToString|Optional|string $timezone; @@ -33,7 +39,7 @@ class WeekAggregation implements ResolvesToInt * @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public function __construct( - \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|Optional|string $timezone = Optional::Undefined, ) { $this->date = $date; diff --git a/src/Builder/Aggregation/YearAggregation.php b/src/Builder/Aggregation/YearAggregation.php index f46f51581..c63909766 100644 --- a/src/Builder/Aggregation/YearAggregation.php +++ b/src/Builder/Aggregation/YearAggregation.php @@ -9,6 +9,7 @@ use DateTimeInterface; use MongoDB\BSON\Int64; use MongoDB\BSON\ObjectId; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToDate; use MongoDB\Builder\Expression\ResolvesToInt; @@ -17,13 +18,18 @@ use MongoDB\Builder\Expression\ResolvesToTimestamp; use MongoDB\Builder\Optional; +/** + * Returns the year for a date as a number (e.g. 2014). + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/year/ + */ class YearAggregation implements ResolvesToInt { public const NAME = '$year'; public const ENCODE = \MongoDB\Builder\Encode::Object; /** @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ - public \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; + public DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; /** @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public ResolvesToString|Optional|string $timezone; @@ -33,7 +39,7 @@ class YearAggregation implements ResolvesToInt * @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public function __construct( - \UTCDateTime|DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|Optional|string $timezone = Optional::Undefined, ) { $this->date = $date; diff --git a/src/Builder/Aggregation/ZipAggregation.php b/src/Builder/Aggregation/ZipAggregation.php index 949026abe..faa466442 100644 --- a/src/Builder/Aggregation/ZipAggregation.php +++ b/src/Builder/Aggregation/ZipAggregation.php @@ -12,6 +12,11 @@ use MongoDB\Builder\Expression\ResolvesToArray; use MongoDB\Model\BSONArray; +/** + * Merge two arrays together. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/zip/ + */ class ZipAggregation implements ResolvesToArray { public const NAME = '$zip'; diff --git a/src/Builder/Query.php b/src/Builder/Query.php index 1d0ac016b..1efa74fb5 100644 --- a/src/Builder/Query.php +++ b/src/Builder/Query.php @@ -63,6 +63,9 @@ final class Query { /** + * Matches arrays that contain all elements specified in the query. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/all/ * @param mixed ...$value */ public static function all(mixed ...$value): AllQuery @@ -71,6 +74,9 @@ public static function all(mixed ...$value): AllQuery } /** + * Joins query clauses with a logical AND returns all documents that match the conditions of both clauses. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/and/ * @param QueryInterface|array|stdClass ...$expression */ public static function and(QueryInterface|stdClass|array ...$expression): AndQuery @@ -79,6 +85,9 @@ public static function and(QueryInterface|stdClass|array ...$expression): AndQue } /** + * Matches numeric or binary values in which a set of bit positions all have a value of 0. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/bitsAllClear/ * @param BSONArray|Binary|Int64|PackedArray|int|list|non-empty-string $bitmask */ public static function bitsAllClear( @@ -89,6 +98,9 @@ public static function bitsAllClear( } /** + * Matches numeric or binary values in which a set of bit positions all have a value of 1. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/bitsAllSet/ * @param BSONArray|Binary|Int64|PackedArray|int|list|non-empty-string $bitmask */ public static function bitsAllSet(Binary|Int64|PackedArray|BSONArray|array|int|string $bitmask): BitsAllSetQuery @@ -97,6 +109,9 @@ public static function bitsAllSet(Binary|Int64|PackedArray|BSONArray|array|int|s } /** + * Matches numeric or binary values in which any bit from a set of bit positions has a value of 0. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/bitsAnyClear/ * @param BSONArray|Binary|Int64|PackedArray|int|list|non-empty-string $bitmask */ public static function bitsAnyClear( @@ -107,6 +122,9 @@ public static function bitsAnyClear( } /** + * Matches numeric or binary values in which any bit from a set of bit positions has a value of 1. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/bitsAnySet/ * @param BSONArray|Binary|Int64|PackedArray|int|list|non-empty-string $bitmask */ public static function bitsAnySet(Binary|Int64|PackedArray|BSONArray|array|int|string $bitmask): BitsAnySetQuery @@ -115,6 +133,9 @@ public static function bitsAnySet(Binary|Int64|PackedArray|BSONArray|array|int|s } /** + * Specifies a rectangular box using legacy coordinate pairs for $geoWithin queries. The 2d index supports $box. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/box/ * @param BSONArray|PackedArray|list $value */ public static function box(PackedArray|BSONArray|array $value): BoxQuery @@ -123,6 +144,9 @@ public static function box(PackedArray|BSONArray|array $value): BoxQuery } /** + * Specifies a circle using legacy coordinate pairs to $geoWithin queries when using planar geometry. The 2d index supports $center. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/center/ * @param BSONArray|PackedArray|list $value */ public static function center(PackedArray|BSONArray|array $value): CenterQuery @@ -131,6 +155,9 @@ public static function center(PackedArray|BSONArray|array $value): CenterQuery } /** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/centerSphere/ * @param BSONArray|PackedArray|list $value */ public static function centerSphere(PackedArray|BSONArray|array $value): CenterSphereQuery @@ -139,6 +166,9 @@ public static function centerSphere(PackedArray|BSONArray|array $value): CenterS } /** + * Adds a comment to a query predicate. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/comment/ * @param non-empty-string $comment */ public static function comment(string $comment): CommentQuery @@ -147,6 +177,9 @@ public static function comment(string $comment): CommentQuery } /** + * Projects the first element in an array that matches the specified $elemMatch condition. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/elemMatch/ * @param Document|Serializable|array|stdClass $queries */ public static function elemMatch(Document|Serializable|stdClass|array $queries): ElemMatchQuery @@ -155,6 +188,9 @@ public static function elemMatch(Document|Serializable|stdClass|array $queries): } /** + * Matches values that are equal to a specified value. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/eq/ * @param mixed $value */ public static function eq(mixed $value): EqQuery @@ -163,6 +199,9 @@ public static function eq(mixed $value): EqQuery } /** + * Matches documents that have the specified field. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/exists/ * @param bool $exists */ public static function exists(bool $exists): ExistsQuery @@ -171,6 +210,9 @@ public static function exists(bool $exists): ExistsQuery } /** + * Allows use of aggregation expressions within the query language. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/expr/ * @param ExpressionInterface|mixed $expression */ public static function expr(mixed $expression): ExprQuery @@ -179,6 +221,9 @@ public static function expr(mixed $expression): ExprQuery } /** + * Selects geometries that intersect with a GeoJSON geometry. The 2dsphere index supports $geoIntersects. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/geoIntersects/ * @param array|stdClass $geometry */ public static function geoIntersects(stdClass|array $geometry): GeoIntersectsQuery @@ -187,6 +232,9 @@ public static function geoIntersects(stdClass|array $geometry): GeoIntersectsQue } /** + * Selects geometries within a bounding GeoJSON geometry. The 2dsphere and 2d indexes support $geoWithin. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/geoWithin/ * @param array|stdClass $geometry */ public static function geoWithin(stdClass|array $geometry): GeoWithinQuery @@ -195,6 +243,9 @@ public static function geoWithin(stdClass|array $geometry): GeoWithinQuery } /** + * Specifies a geometry in GeoJSON format to geospatial query operators. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/geometry/ * @param non-empty-string $type * @param BSONArray|PackedArray|list $coordinates * @param Document|Serializable|array|stdClass $crs @@ -209,6 +260,9 @@ public static function geometry( } /** + * Matches values that are greater than a specified value. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/gt/ * @param mixed $value */ public static function gt(mixed $value): GtQuery @@ -217,6 +271,9 @@ public static function gt(mixed $value): GtQuery } /** + * Matches values that are greater than or equal to a specified value. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/gte/ * @param mixed $value */ public static function gte(mixed $value): GteQuery @@ -225,6 +282,9 @@ public static function gte(mixed $value): GteQuery } /** + * Matches any of the values specified in an array. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/in/ * @param mixed $value */ public static function in(mixed $value): InQuery @@ -233,6 +293,9 @@ public static function in(mixed $value): InQuery } /** + * Validate documents against the given JSON Schema. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/jsonSchema/ * @param Document|Serializable|array|stdClass $schema */ public static function jsonSchema(Document|Serializable|stdClass|array $schema): JsonSchemaQuery @@ -241,6 +304,9 @@ public static function jsonSchema(Document|Serializable|stdClass|array $schema): } /** + * Matches values that are less than a specified value. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/lt/ * @param mixed $value */ public static function lt(mixed $value): LtQuery @@ -249,6 +315,9 @@ public static function lt(mixed $value): LtQuery } /** + * Matches values that are less than or equal to a specified value. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/lte/ * @param mixed $value */ public static function lte(mixed $value): LteQuery @@ -257,6 +326,9 @@ public static function lte(mixed $value): LteQuery } /** + * Specifies a maximum distance to limit the results of $near and $nearSphere queries. The 2dsphere and 2d indexes support $maxDistance. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/maxDistance/ * @param Int64|float|int $value */ public static function maxDistance(Int64|float|int $value): MaxDistanceQuery @@ -264,12 +336,20 @@ public static function maxDistance(Int64|float|int $value): MaxDistanceQuery return new MaxDistanceQuery($value); } + /** + * Projects the available per-document metadata. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/meta/ + */ public static function meta(): MetaQuery { return new MetaQuery(); } /** + * Specifies a minimum distance to limit the results of $near and $nearSphere queries. For use with 2dsphere index only. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/minDistance/ * @param Int64|float|int $value */ public static function minDistance(Int64|float|int $value): MinDistanceQuery @@ -278,6 +358,9 @@ public static function minDistance(Int64|float|int $value): MinDistanceQuery } /** + * Performs a modulo operation on the value of a field and selects documents with a specified result. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/mod/ * @param Int64|int $divisor * @param Int64|int $remainder */ @@ -286,12 +369,20 @@ public static function mod(Int64|int $divisor, Int64|int $remainder): ModQuery return new ModQuery($divisor, $remainder); } + /** + * A special hint that can be provided via the sort() or hint() methods that can be used to force either a forward or reverse collection scan. + * + * @see https://www.mongodb.com/docs/v7.0/reference/operator/meta/natural/ + */ public static function natural(): NaturalQuery { return new NaturalQuery(); } /** + * Matches all values that are not equal to a specified value. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/ne/ * @param mixed $value */ public static function ne(mixed $value): NeQuery @@ -300,6 +391,9 @@ public static function ne(mixed $value): NeQuery } /** + * Returns geospatial objects in proximity to a point. Requires a geospatial index. The 2dsphere and 2d indexes support $near. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/near/ * @param array|stdClass $geometry * @param Int64|Optional|int $maxDistance Distance in meters. Limits the results to those documents that are at most the specified distance from the center point. * @param Int64|Optional|int $minDistance Distance in meters. Limits the results to those documents that are at least the specified distance from the center point. @@ -314,6 +408,9 @@ public static function near( } /** + * Returns geospatial objects in proximity to a point on a sphere. Requires a geospatial index. The 2dsphere and 2d indexes support $nearSphere. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/nearSphere/ * @param array|stdClass $geometry * @param Int64|Optional|int $maxDistance Distance in meters. * @param Int64|Optional|int $minDistance Distance in meters. Limits the results to those documents that are at least the specified distance from the center point. @@ -328,6 +425,9 @@ public static function nearSphere( } /** + * Matches none of the values specified in an array. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/nin/ * @param mixed $value */ public static function nin(mixed $value): NinQuery @@ -336,6 +436,9 @@ public static function nin(mixed $value): NinQuery } /** + * Joins query clauses with a logical NOR returns all documents that fail to match both clauses. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/nor/ * @param QueryInterface|array|stdClass ...$expression */ public static function nor(QueryInterface|stdClass|array ...$expression): NorQuery @@ -344,6 +447,9 @@ public static function nor(QueryInterface|stdClass|array ...$expression): NorQue } /** + * Inverts the effect of a query expression and returns documents that do not match the query expression. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/not/ * @param QueryInterface|array|stdClass $expression */ public static function not(QueryInterface|stdClass|array $expression): NotQuery @@ -352,6 +458,9 @@ public static function not(QueryInterface|stdClass|array $expression): NotQuery } /** + * Joins query clauses with a logical OR returns all documents that match the conditions of either clause. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/or/ * @param QueryInterface|array|stdClass ...$expression */ public static function or(QueryInterface|stdClass|array ...$expression): OrQuery @@ -360,6 +469,9 @@ public static function or(QueryInterface|stdClass|array ...$expression): OrQuery } /** + * Specifies a polygon to using legacy coordinate pairs for $geoWithin queries. The 2d index supports $center. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/polygon/ * @param BSONArray|PackedArray|list $points */ public static function polygon(PackedArray|BSONArray|array $points): PolygonQuery @@ -367,12 +479,20 @@ public static function polygon(PackedArray|BSONArray|array $points): PolygonQuer return new PolygonQuery($points); } + /** + * Generates a random float between 0 and 1. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/rand/ + */ public static function rand(): RandQuery { return new RandQuery(); } /** + * Selects documents where values match a specified regular expression. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/regex/ * @param Regex $regex */ public static function regex(Regex $regex): RegexQuery @@ -381,6 +501,9 @@ public static function regex(Regex $regex): RegexQuery } /** + * Selects documents if the array field is a specified size. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/size/ * @param Int64|int $value */ public static function size(Int64|int $value): SizeQuery @@ -389,6 +512,9 @@ public static function size(Int64|int $value): SizeQuery } /** + * Limits the number of elements projected from an array. Supports skip and limit slices. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/slice/ * @param Int64|int $limit * @param Int64|int $skip */ @@ -398,6 +524,9 @@ public static function slice(Int64|int $limit, Int64|int $skip): SliceQuery } /** + * Performs text search. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/text/ * @param non-empty-string $search 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. * @param Optional|non-empty-string $language 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. @@ -416,6 +545,9 @@ public static function text( } /** + * Selects documents if a field is of the specified type. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/type/ * @param BSONArray|Int64|PackedArray|int|list|non-empty-string $type */ public static function type(Int64|PackedArray|BSONArray|array|int|string $type): TypeQuery @@ -424,6 +556,9 @@ public static function type(Int64|PackedArray|BSONArray|array|int|string $type): } /** + * Matches documents that satisfy a JavaScript expression. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/where/ * @param non-empty-string $function */ public static function where(string $function): WhereQuery diff --git a/src/Builder/Query/AllQuery.php b/src/Builder/Query/AllQuery.php index 7ad4d6486..01ff7bb28 100644 --- a/src/Builder/Query/AllQuery.php +++ b/src/Builder/Query/AllQuery.php @@ -8,6 +8,11 @@ use MongoDB\Builder\Encode; +/** + * Matches arrays that contain all elements specified in the query. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/all/ + */ class AllQuery implements QueryInterface { public const NAME = '$all'; diff --git a/src/Builder/Query/AndQuery.php b/src/Builder/Query/AndQuery.php index 988fec753..39d3489d9 100644 --- a/src/Builder/Query/AndQuery.php +++ b/src/Builder/Query/AndQuery.php @@ -9,6 +9,11 @@ use MongoDB\Builder\Encode; use stdClass; +/** + * Joins query clauses with a logical AND returns all documents that match the conditions of both clauses. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/and/ + */ class AndQuery implements QueryInterface { public const NAME = '$and'; diff --git a/src/Builder/Query/BitsAllClearQuery.php b/src/Builder/Query/BitsAllClearQuery.php index 3bda4c52b..be4b0a0fb 100644 --- a/src/Builder/Query/BitsAllClearQuery.php +++ b/src/Builder/Query/BitsAllClearQuery.php @@ -13,6 +13,11 @@ use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Model\BSONArray; +/** + * Matches numeric or binary values in which a set of bit positions all have a value of 0. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/bitsAllClear/ + */ class BitsAllClearQuery implements QueryInterface { public const NAME = '$bitsAllClear'; diff --git a/src/Builder/Query/BitsAllSetQuery.php b/src/Builder/Query/BitsAllSetQuery.php index bb1fd5cbf..275b2c23d 100644 --- a/src/Builder/Query/BitsAllSetQuery.php +++ b/src/Builder/Query/BitsAllSetQuery.php @@ -13,6 +13,11 @@ use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Model\BSONArray; +/** + * Matches numeric or binary values in which a set of bit positions all have a value of 1. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/bitsAllSet/ + */ class BitsAllSetQuery implements QueryInterface { public const NAME = '$bitsAllSet'; diff --git a/src/Builder/Query/BitsAnyClearQuery.php b/src/Builder/Query/BitsAnyClearQuery.php index 7acc906d2..38b1e77e5 100644 --- a/src/Builder/Query/BitsAnyClearQuery.php +++ b/src/Builder/Query/BitsAnyClearQuery.php @@ -13,6 +13,11 @@ use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Model\BSONArray; +/** + * Matches numeric or binary values in which any bit from a set of bit positions has a value of 0. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/bitsAnyClear/ + */ class BitsAnyClearQuery implements QueryInterface { public const NAME = '$bitsAnyClear'; diff --git a/src/Builder/Query/BitsAnySetQuery.php b/src/Builder/Query/BitsAnySetQuery.php index 8bfc971cc..3f0f2f9e0 100644 --- a/src/Builder/Query/BitsAnySetQuery.php +++ b/src/Builder/Query/BitsAnySetQuery.php @@ -13,6 +13,11 @@ use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Model\BSONArray; +/** + * Matches numeric or binary values in which any bit from a set of bit positions has a value of 1. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/bitsAnySet/ + */ class BitsAnySetQuery implements QueryInterface { public const NAME = '$bitsAnySet'; diff --git a/src/Builder/Query/BoxQuery.php b/src/Builder/Query/BoxQuery.php index febce3623..e05d9af79 100644 --- a/src/Builder/Query/BoxQuery.php +++ b/src/Builder/Query/BoxQuery.php @@ -11,6 +11,11 @@ use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Model\BSONArray; +/** + * Specifies a rectangular box using legacy coordinate pairs for $geoWithin queries. The 2d index supports $box. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/box/ + */ class BoxQuery implements QueryInterface { public const NAME = '$box'; diff --git a/src/Builder/Query/CenterQuery.php b/src/Builder/Query/CenterQuery.php index 3818b4d2a..18239aaf9 100644 --- a/src/Builder/Query/CenterQuery.php +++ b/src/Builder/Query/CenterQuery.php @@ -11,6 +11,11 @@ use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Model\BSONArray; +/** + * Specifies a circle using legacy coordinate pairs to $geoWithin queries when using planar geometry. The 2d index supports $center. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/center/ + */ class CenterQuery implements QueryInterface { public const NAME = '$center'; diff --git a/src/Builder/Query/CenterSphereQuery.php b/src/Builder/Query/CenterSphereQuery.php index 4ca66cbd7..421ea406d 100644 --- a/src/Builder/Query/CenterSphereQuery.php +++ b/src/Builder/Query/CenterSphereQuery.php @@ -11,6 +11,11 @@ use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Model\BSONArray; +/** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/centerSphere/ + */ class CenterSphereQuery implements QueryInterface { public const NAME = '$centerSphere'; diff --git a/src/Builder/Query/CommentQuery.php b/src/Builder/Query/CommentQuery.php index 978c68151..bb0a98ccb 100644 --- a/src/Builder/Query/CommentQuery.php +++ b/src/Builder/Query/CommentQuery.php @@ -9,6 +9,11 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ExpressionInterface; +/** + * Adds a comment to a query predicate. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/comment/ + */ class CommentQuery implements ExpressionInterface { public const NAME = '$comment'; diff --git a/src/Builder/Query/ElemMatchQuery.php b/src/Builder/Query/ElemMatchQuery.php index 0fe3ea391..e308e254b 100644 --- a/src/Builder/Query/ElemMatchQuery.php +++ b/src/Builder/Query/ElemMatchQuery.php @@ -11,6 +11,11 @@ use MongoDB\Builder\Encode; use stdClass; +/** + * Projects the first element in an array that matches the specified $elemMatch condition. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/elemMatch/ + */ class ElemMatchQuery implements QueryInterface { public const NAME = '$elemMatch'; diff --git a/src/Builder/Query/EqQuery.php b/src/Builder/Query/EqQuery.php index 1715a6809..d2652687c 100644 --- a/src/Builder/Query/EqQuery.php +++ b/src/Builder/Query/EqQuery.php @@ -8,6 +8,11 @@ use MongoDB\Builder\Encode; +/** + * Matches values that are equal to a specified value. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/eq/ + */ class EqQuery implements QueryInterface { public const NAME = '$eq'; diff --git a/src/Builder/Query/ExistsQuery.php b/src/Builder/Query/ExistsQuery.php index ee047828d..e3d8c2912 100644 --- a/src/Builder/Query/ExistsQuery.php +++ b/src/Builder/Query/ExistsQuery.php @@ -8,6 +8,11 @@ use MongoDB\Builder\Encode; +/** + * Matches documents that have the specified field. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/exists/ + */ class ExistsQuery implements QueryInterface { public const NAME = '$exists'; diff --git a/src/Builder/Query/ExprQuery.php b/src/Builder/Query/ExprQuery.php index fa2ca1781..7061dcf26 100644 --- a/src/Builder/Query/ExprQuery.php +++ b/src/Builder/Query/ExprQuery.php @@ -9,6 +9,11 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ExpressionInterface; +/** + * Allows use of aggregation expressions within the query language. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/expr/ + */ class ExprQuery implements QueryInterface { public const NAME = '$expr'; diff --git a/src/Builder/Query/GeoIntersectsQuery.php b/src/Builder/Query/GeoIntersectsQuery.php index 9a2b41a6e..770b11294 100644 --- a/src/Builder/Query/GeoIntersectsQuery.php +++ b/src/Builder/Query/GeoIntersectsQuery.php @@ -9,6 +9,11 @@ use MongoDB\Builder\Encode; use stdClass; +/** + * Selects geometries that intersect with a GeoJSON geometry. The 2dsphere index supports $geoIntersects. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/geoIntersects/ + */ class GeoIntersectsQuery implements QueryInterface { public const NAME = '$geoIntersects'; diff --git a/src/Builder/Query/GeoWithinQuery.php b/src/Builder/Query/GeoWithinQuery.php index 85a80a272..6fe9005f0 100644 --- a/src/Builder/Query/GeoWithinQuery.php +++ b/src/Builder/Query/GeoWithinQuery.php @@ -9,6 +9,11 @@ use MongoDB\Builder\Encode; use stdClass; +/** + * Selects geometries within a bounding GeoJSON geometry. The 2dsphere and 2d indexes support $geoWithin. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/geoWithin/ + */ class GeoWithinQuery implements QueryInterface { public const NAME = '$geoWithin'; diff --git a/src/Builder/Query/GeometryQuery.php b/src/Builder/Query/GeometryQuery.php index eebc715bb..bfcbe4b62 100644 --- a/src/Builder/Query/GeometryQuery.php +++ b/src/Builder/Query/GeometryQuery.php @@ -14,6 +14,11 @@ use MongoDB\Model\BSONArray; use stdClass; +/** + * Specifies a geometry in GeoJSON format to geospatial query operators. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/geometry/ + */ class GeometryQuery implements ExpressionInterface { public const NAME = '$geometry'; diff --git a/src/Builder/Query/GtQuery.php b/src/Builder/Query/GtQuery.php index c43c6eeb3..0d97be526 100644 --- a/src/Builder/Query/GtQuery.php +++ b/src/Builder/Query/GtQuery.php @@ -8,6 +8,11 @@ use MongoDB\Builder\Encode; +/** + * Matches values that are greater than a specified value. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/gt/ + */ class GtQuery implements QueryInterface { public const NAME = '$gt'; diff --git a/src/Builder/Query/GteQuery.php b/src/Builder/Query/GteQuery.php index 57be997a5..a221f982e 100644 --- a/src/Builder/Query/GteQuery.php +++ b/src/Builder/Query/GteQuery.php @@ -8,6 +8,11 @@ use MongoDB\Builder\Encode; +/** + * Matches values that are greater than or equal to a specified value. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/gte/ + */ class GteQuery implements QueryInterface { public const NAME = '$gte'; diff --git a/src/Builder/Query/InQuery.php b/src/Builder/Query/InQuery.php index 88ea165a1..7b2bba176 100644 --- a/src/Builder/Query/InQuery.php +++ b/src/Builder/Query/InQuery.php @@ -8,6 +8,11 @@ use MongoDB\Builder\Encode; +/** + * Matches any of the values specified in an array. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/in/ + */ class InQuery implements QueryInterface { public const NAME = '$in'; diff --git a/src/Builder/Query/JsonSchemaQuery.php b/src/Builder/Query/JsonSchemaQuery.php index 145bafc9c..02e1c0456 100644 --- a/src/Builder/Query/JsonSchemaQuery.php +++ b/src/Builder/Query/JsonSchemaQuery.php @@ -11,6 +11,11 @@ use MongoDB\Builder\Encode; use stdClass; +/** + * Validate documents against the given JSON Schema. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/jsonSchema/ + */ class JsonSchemaQuery implements QueryInterface { public const NAME = '$jsonSchema'; diff --git a/src/Builder/Query/LtQuery.php b/src/Builder/Query/LtQuery.php index b6c2c92fc..11bac4894 100644 --- a/src/Builder/Query/LtQuery.php +++ b/src/Builder/Query/LtQuery.php @@ -8,6 +8,11 @@ use MongoDB\Builder\Encode; +/** + * Matches values that are less than a specified value. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/lt/ + */ class LtQuery implements QueryInterface { public const NAME = '$lt'; diff --git a/src/Builder/Query/LteQuery.php b/src/Builder/Query/LteQuery.php index b14fba3ed..7442e616d 100644 --- a/src/Builder/Query/LteQuery.php +++ b/src/Builder/Query/LteQuery.php @@ -8,6 +8,11 @@ use MongoDB\Builder\Encode; +/** + * Matches values that are less than or equal to a specified value. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/lte/ + */ class LteQuery implements QueryInterface { public const NAME = '$lte'; diff --git a/src/Builder/Query/MaxDistanceQuery.php b/src/Builder/Query/MaxDistanceQuery.php index 5341852f0..514c7dc2b 100644 --- a/src/Builder/Query/MaxDistanceQuery.php +++ b/src/Builder/Query/MaxDistanceQuery.php @@ -9,6 +9,11 @@ use MongoDB\BSON\Int64; use MongoDB\Builder\Encode; +/** + * Specifies a maximum distance to limit the results of $near and $nearSphere queries. The 2dsphere and 2d indexes support $maxDistance. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/maxDistance/ + */ class MaxDistanceQuery implements QueryInterface { public const NAME = '$maxDistance'; diff --git a/src/Builder/Query/MetaQuery.php b/src/Builder/Query/MetaQuery.php index 6586ad448..70ead0e6e 100644 --- a/src/Builder/Query/MetaQuery.php +++ b/src/Builder/Query/MetaQuery.php @@ -9,6 +9,11 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ExpressionInterface; +/** + * Projects the available per-document metadata. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/meta/ + */ class MetaQuery implements ExpressionInterface { public const NAME = '$meta'; diff --git a/src/Builder/Query/MinDistanceQuery.php b/src/Builder/Query/MinDistanceQuery.php index 0ce01b197..c2bca0700 100644 --- a/src/Builder/Query/MinDistanceQuery.php +++ b/src/Builder/Query/MinDistanceQuery.php @@ -9,6 +9,11 @@ use MongoDB\BSON\Int64; use MongoDB\Builder\Encode; +/** + * Specifies a minimum distance to limit the results of $near and $nearSphere queries. For use with 2dsphere index only. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/minDistance/ + */ class MinDistanceQuery implements QueryInterface { public const NAME = '$minDistance'; diff --git a/src/Builder/Query/ModQuery.php b/src/Builder/Query/ModQuery.php index 5560af79c..db99ab172 100644 --- a/src/Builder/Query/ModQuery.php +++ b/src/Builder/Query/ModQuery.php @@ -9,6 +9,11 @@ use MongoDB\BSON\Int64; use MongoDB\Builder\Encode; +/** + * Performs a modulo operation on the value of a field and selects documents with a specified result. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/mod/ + */ class ModQuery implements QueryInterface { public const NAME = '$mod'; diff --git a/src/Builder/Query/NaturalQuery.php b/src/Builder/Query/NaturalQuery.php index c7b008680..12e470b60 100644 --- a/src/Builder/Query/NaturalQuery.php +++ b/src/Builder/Query/NaturalQuery.php @@ -9,6 +9,11 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ExpressionInterface; +/** + * A special hint that can be provided via the sort() or hint() methods that can be used to force either a forward or reverse collection scan. + * + * @see https://www.mongodb.com/docs/v7.0/reference/operator/meta/natural/ + */ class NaturalQuery implements ExpressionInterface { public const NAME = '$natural'; diff --git a/src/Builder/Query/NeQuery.php b/src/Builder/Query/NeQuery.php index c1e84bdbb..4b28a192a 100644 --- a/src/Builder/Query/NeQuery.php +++ b/src/Builder/Query/NeQuery.php @@ -8,6 +8,11 @@ use MongoDB\Builder\Encode; +/** + * Matches all values that are not equal to a specified value. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/ne/ + */ class NeQuery implements QueryInterface { public const NAME = '$ne'; diff --git a/src/Builder/Query/NearQuery.php b/src/Builder/Query/NearQuery.php index 0cdf53988..1a1581923 100644 --- a/src/Builder/Query/NearQuery.php +++ b/src/Builder/Query/NearQuery.php @@ -11,6 +11,11 @@ use MongoDB\Builder\Optional; use stdClass; +/** + * Returns geospatial objects in proximity to a point. Requires a geospatial index. The 2dsphere and 2d indexes support $near. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/near/ + */ class NearQuery implements QueryInterface { public const NAME = '$near'; diff --git a/src/Builder/Query/NearSphereQuery.php b/src/Builder/Query/NearSphereQuery.php index e8f83e70c..b181b19bb 100644 --- a/src/Builder/Query/NearSphereQuery.php +++ b/src/Builder/Query/NearSphereQuery.php @@ -11,6 +11,11 @@ use MongoDB\Builder\Optional; use stdClass; +/** + * Returns geospatial objects in proximity to a point on a sphere. Requires a geospatial index. The 2dsphere and 2d indexes support $nearSphere. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/nearSphere/ + */ class NearSphereQuery implements QueryInterface { public const NAME = '$nearSphere'; diff --git a/src/Builder/Query/NinQuery.php b/src/Builder/Query/NinQuery.php index 6eae4ee26..2f1243ea5 100644 --- a/src/Builder/Query/NinQuery.php +++ b/src/Builder/Query/NinQuery.php @@ -8,6 +8,11 @@ use MongoDB\Builder\Encode; +/** + * Matches none of the values specified in an array. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/nin/ + */ class NinQuery implements QueryInterface { public const NAME = '$nin'; diff --git a/src/Builder/Query/NorQuery.php b/src/Builder/Query/NorQuery.php index e296df466..aa4833a33 100644 --- a/src/Builder/Query/NorQuery.php +++ b/src/Builder/Query/NorQuery.php @@ -9,6 +9,11 @@ use MongoDB\Builder\Encode; use stdClass; +/** + * Joins query clauses with a logical NOR returns all documents that fail to match both clauses. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/nor/ + */ class NorQuery implements QueryInterface { public const NAME = '$nor'; diff --git a/src/Builder/Query/NotQuery.php b/src/Builder/Query/NotQuery.php index 3f723f919..032fc8009 100644 --- a/src/Builder/Query/NotQuery.php +++ b/src/Builder/Query/NotQuery.php @@ -9,6 +9,11 @@ use MongoDB\Builder\Encode; use stdClass; +/** + * Inverts the effect of a query expression and returns documents that do not match the query expression. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/not/ + */ class NotQuery implements QueryInterface { public const NAME = '$not'; diff --git a/src/Builder/Query/OrQuery.php b/src/Builder/Query/OrQuery.php index 02af84ce7..3ca1f990c 100644 --- a/src/Builder/Query/OrQuery.php +++ b/src/Builder/Query/OrQuery.php @@ -9,6 +9,11 @@ use MongoDB\Builder\Encode; use stdClass; +/** + * Joins query clauses with a logical OR returns all documents that match the conditions of either clause. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/or/ + */ class OrQuery implements QueryInterface { public const NAME = '$or'; diff --git a/src/Builder/Query/PolygonQuery.php b/src/Builder/Query/PolygonQuery.php index bacb2ec38..ad742dc12 100644 --- a/src/Builder/Query/PolygonQuery.php +++ b/src/Builder/Query/PolygonQuery.php @@ -11,6 +11,11 @@ use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Model\BSONArray; +/** + * Specifies a polygon to using legacy coordinate pairs for $geoWithin queries. The 2d index supports $center. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/polygon/ + */ class PolygonQuery implements QueryInterface { public const NAME = '$polygon'; diff --git a/src/Builder/Query/RandQuery.php b/src/Builder/Query/RandQuery.php index af2b33104..37fe25fce 100644 --- a/src/Builder/Query/RandQuery.php +++ b/src/Builder/Query/RandQuery.php @@ -9,6 +9,11 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ExpressionInterface; +/** + * Generates a random float between 0 and 1. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/rand/ + */ class RandQuery implements ExpressionInterface { public const NAME = '$rand'; diff --git a/src/Builder/Query/RegexQuery.php b/src/Builder/Query/RegexQuery.php index 5647acd70..72daaf5be 100644 --- a/src/Builder/Query/RegexQuery.php +++ b/src/Builder/Query/RegexQuery.php @@ -9,6 +9,11 @@ use MongoDB\BSON\Regex; use MongoDB\Builder\Encode; +/** + * Selects documents where values match a specified regular expression. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/regex/ + */ class RegexQuery implements QueryInterface { public const NAME = '$regex'; diff --git a/src/Builder/Query/SizeQuery.php b/src/Builder/Query/SizeQuery.php index 8fafaa4f4..226a8cd18 100644 --- a/src/Builder/Query/SizeQuery.php +++ b/src/Builder/Query/SizeQuery.php @@ -9,6 +9,11 @@ use MongoDB\BSON\Int64; use MongoDB\Builder\Encode; +/** + * Selects documents if the array field is a specified size. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/size/ + */ class SizeQuery implements QueryInterface { public const NAME = '$size'; diff --git a/src/Builder/Query/SliceQuery.php b/src/Builder/Query/SliceQuery.php index 8cf104d5f..afa4801ef 100644 --- a/src/Builder/Query/SliceQuery.php +++ b/src/Builder/Query/SliceQuery.php @@ -9,6 +9,11 @@ use MongoDB\BSON\Int64; use MongoDB\Builder\Encode; +/** + * Limits the number of elements projected from an array. Supports skip and limit slices. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/slice/ + */ class SliceQuery implements QueryInterface { public const NAME = '$slice'; diff --git a/src/Builder/Query/TextQuery.php b/src/Builder/Query/TextQuery.php index ab7b82e5a..416f2ca65 100644 --- a/src/Builder/Query/TextQuery.php +++ b/src/Builder/Query/TextQuery.php @@ -9,6 +9,11 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Optional; +/** + * Performs text search. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/text/ + */ class TextQuery implements QueryInterface { public const NAME = '$text'; diff --git a/src/Builder/Query/TypeQuery.php b/src/Builder/Query/TypeQuery.php index a1177bafd..fa8bdc060 100644 --- a/src/Builder/Query/TypeQuery.php +++ b/src/Builder/Query/TypeQuery.php @@ -12,6 +12,11 @@ use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Model\BSONArray; +/** + * Selects documents if a field is of the specified type. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/type/ + */ class TypeQuery implements QueryInterface { public const NAME = '$type'; diff --git a/src/Builder/Query/WhereQuery.php b/src/Builder/Query/WhereQuery.php index 5b169201e..20b6c2890 100644 --- a/src/Builder/Query/WhereQuery.php +++ b/src/Builder/Query/WhereQuery.php @@ -8,6 +8,11 @@ use MongoDB\Builder\Encode; +/** + * Matches documents that satisfy a JavaScript expression. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/where/ + */ class WhereQuery implements QueryInterface { public const NAME = '$where'; diff --git a/src/Builder/Stage.php b/src/Builder/Stage.php index d080e72bd..aee98d3c4 100644 --- a/src/Builder/Stage.php +++ b/src/Builder/Stage.php @@ -66,6 +66,9 @@ final class Stage { /** + * Adds new fields to documents. Outputs documents that contain all existing fields from the input documents and newly added fields. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/addFields/ * @param ExpressionInterface|mixed ...$expression Specify the name of each field to add and set its value to an aggregation expression or an empty object. */ public static function addFields(mixed ...$expression): AddFieldsStage @@ -74,6 +77,9 @@ public static function addFields(mixed ...$expression): AddFieldsStage } /** + * Categorizes incoming documents into groups, called buckets, based on a specified expression and bucket boundaries. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/bucket/ * @param ExpressionInterface|FieldPath|mixed|non-empty-string $groupBy 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. * @param BSONArray|PackedArray|list $boundaries 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. @@ -97,6 +103,9 @@ public static function bucket( } /** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/bucketAuto/ * @param ExpressionInterface|mixed $groupBy An expression to group documents by. To specify a field path, prefix the field name with a dollar sign $ and enclose it in quotes. * @param Int64|int $buckets A positive 32-bit integer that specifies the number of buckets into which input documents are grouped. * @param Document|Optional|Serializable|array|stdClass $output 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. @@ -115,6 +124,9 @@ public static function bucketAuto( } /** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/changeStream/ * @param Optional|bool $allChangesForCluster A flag indicating whether the stream should report all changes that occur on the deployment, aside from those on internal databases or collections. * @param Optional|non-empty-string $fullDocument Specifies whether change notifications include a copy of the full document when modified by update operations. * @param Optional|non-empty-string $fullDocumentBeforeChange 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. @@ -137,12 +149,21 @@ public static function changeStream( return new ChangeStreamStage($allChangesForCluster, $fullDocument, $fullDocumentBeforeChange, $resumeAfter, $showExpandedEvents, $startAfter, $startAtOperationTime); } + /** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/changeStreamSplitLargeEvent/ + */ public static function changeStreamSplitLargeEvent(): ChangeStreamSplitLargeEventStage { return new ChangeStreamSplitLargeEventStage(); } /** + * Returns statistics regarding a collection or view. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/collStats/ * @param Document|Serializable|array|stdClass $config */ public static function collStats(Document|Serializable|stdClass|array $config): CollStatsStage @@ -151,6 +172,10 @@ public static function collStats(Document|Serializable|stdClass|array $config): } /** + * Returns a count of the number of documents at this stage of the aggregation pipeline. + * Distinct from the $count aggregation accumulator. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/count/ * @param non-empty-string $field */ public static function count(string $field): CountStage @@ -158,12 +183,20 @@ public static function count(string $field): CountStage return new CountStage($field); } + /** + * Returns information on active and/or dormant operations for the MongoDB deployment. To run, use the db.aggregate() method. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/currentOp/ + */ public static function currentOp(): CurrentOpStage { return new CurrentOpStage(); } /** + * Creates new documents in a sequence of documents where certain values in a field are missing. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/densify/ * @param FieldPath|non-empty-string $field 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. @@ -180,6 +213,9 @@ public static function densify( } /** + * Returns literal documents from input values. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/documents/ * @param BSONArray|PackedArray|ResolvesToArray|list $documents $documents accepts any valid expression that resolves to an array of objects. This includes: * - system variables, such as $$NOW or $$SEARCH_META * - $let expressions @@ -192,6 +228,9 @@ public static function documents(PackedArray|ResolvesToArray|BSONArray|array $do } /** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/facet/ * @param Pipeline|array ...$facet */ public static function facet(Pipeline|array ...$facet): FacetStage @@ -200,6 +239,9 @@ public static function facet(Pipeline|array ...$facet): FacetStage } /** + * Populates null and missing field values within documents. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/fill/ * @param Document|Serializable|array|stdClass $output 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. * @param Document|Optional|Serializable|array|non-empty-string|stdClass $partitionBy Specifies an expression to group the documents. In the $fill stage, a group of documents is known as a partition. @@ -221,6 +263,9 @@ public static function fill( } /** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/geoNear/ * @param non-empty-string $distanceField The output field that contains the calculated distance. To specify a field within an embedded document, use dot notation. * @param array|stdClass $near The point for which to find the closest documents. * @param Decimal128|Int64|Optional|float|int $distanceMultiplier 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. @@ -253,6 +298,9 @@ public static function geoNear( } /** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/graphLookup/ * @param non-empty-string $from 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. * @param BSONArray|ExpressionInterface|PackedArray|list|mixed $startWith 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. @@ -278,6 +326,9 @@ public static function graphLookup( } /** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/group/ * @param ExpressionInterface|mixed $_id 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. * @param AccumulatorInterface ...$field Computed using the accumulator operators. */ @@ -286,12 +337,20 @@ public static function group(mixed $_id, AccumulatorInterface ...$field): GroupS return new GroupStage($_id, ...$field); } + /** + * Returns statistics regarding the use of each index for the collection. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/indexStats/ + */ public static function indexStats(): IndexStatsStage { return new IndexStatsStage(); } /** + * 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). + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/limit/ * @param Int64|int $limit */ public static function limit(Int64|int $limit): LimitStage @@ -300,6 +359,9 @@ public static function limit(Int64|int $limit): LimitStage } /** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/listLocalSessions/ * @param BSONArray|Optional|PackedArray|list $users 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. * @param Optional|bool $allUsers Returns all sessions for all users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster. */ @@ -312,6 +374,9 @@ public static function listLocalSessions( } /** + * Lists sampled queries for all collections or a specific collection. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSampledQueries/ * @param Optional|non-empty-string $namespace */ public static function listSampledQueries( @@ -322,6 +387,9 @@ public static function listSampledQueries( } /** + * Returns information about existing Atlas Search indexes on a specified collection. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSearchIndexes/ * @param Optional|non-empty-string $id The id of the index to return information about. * @param Optional|non-empty-string $name The name of the index to return information about. */ @@ -334,6 +402,9 @@ public static function listSearchIndexes( } /** + * Lists all sessions that have been active long enough to propagate to the system.sessions collection. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSessions/ * @param BSONArray|Optional|PackedArray|list $users 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. * @param Optional|bool $allUsers Returns all sessions for all users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster. */ @@ -346,6 +417,9 @@ public static function listSessions( } /** + * Performs a left outer join to another collection in the same database to filter in documents from the "joined" collection for processing. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/lookup/ * @param non-empty-string $as 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. * @param Optional|non-empty-string $from 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. @@ -370,6 +444,9 @@ public static function lookup( } /** + * 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). + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/match/ * @param QueryInterface|array|stdClass $query */ public static function match(QueryInterface|stdClass|array $query): MatchStage @@ -378,6 +455,10 @@ public static function match(QueryInterface|stdClass|array $query): MatchStage } /** + * 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 version 4.2. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/ * @param array|non-empty-string|stdClass $into The output collection. * @param BSONArray|Optional|PackedArray|list|non-empty-string $on 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. * @param Document|Optional|Serializable|array|stdClass $let Specifies variables for use in the whenMatched pipeline. @@ -396,6 +477,9 @@ public static function merge( } /** + * Writes the resulting documents of the aggregation pipeline to a collection. To use the $out stage, it must be the last stage in the pipeline. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/out/ * @param non-empty-string $db Target collection name to write documents from $out to. * @param non-empty-string $coll Target database name to write documents from $out to. * @param Document|Serializable|array|stdClass $timeseries If set, the aggregation stage will use these options to create or replace a time-series collection in the given namespace. @@ -405,12 +489,20 @@ public static function out(string $db, string $coll, Document|Serializable|stdCl return new OutStage($db, $coll, $timeseries); } + /** + * Returns plan cache information for a collection. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/planCacheStats/ + */ public static function planCacheStats(): PlanCacheStatsStage { return new PlanCacheStatsStage(); } /** + * Reshapes each document in the stream, such as by adding new fields or removing existing fields. For each input document, outputs one document. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/project/ * @param ExpressionInterface|Int64|bool|int|mixed ...$specification */ public static function project(mixed ...$specification): ProjectStage @@ -419,6 +511,9 @@ public static function project(mixed ...$specification): ProjectStage } /** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/redact/ * @param ExpressionInterface|mixed $expression */ public static function redact(mixed $expression): RedactStage @@ -427,6 +522,9 @@ public static function redact(mixed $expression): RedactStage } /** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceRoot/ * @param Document|ResolvesToObject|Serializable|array|stdClass $newRoot */ public static function replaceRoot( @@ -437,6 +535,10 @@ public static function replaceRoot( } /** + * Replaces a document with the specified embedded document. The operation replaces all existing fields in the input document, including the _id field. Specify a document embedded in the input document to promote the embedded document to the top level. + * Alias for $replaceRoot. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceWith/ * @param Document|ResolvesToObject|Serializable|array|stdClass $expression */ public static function replaceWith( @@ -447,6 +549,9 @@ public static function replaceWith( } /** + * Randomly selects the specified number of documents from its input. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/sample/ * @param Int64|int $size The number of documents to randomly select. */ public static function sample(Int64|int $size): SampleStage @@ -455,6 +560,10 @@ public static function sample(Int64|int $size): SampleStage } /** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/search/ * @param Document|Serializable|array|stdClass $search */ public static function search(Document|Serializable|stdClass|array $search): SearchStage @@ -463,6 +572,10 @@ public static function search(Document|Serializable|stdClass|array $search): Sea } /** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/searchMeta/ * @param Document|Serializable|array|stdClass $meta */ public static function searchMeta(Document|Serializable|stdClass|array $meta): SearchMetaStage @@ -471,6 +584,10 @@ public static function searchMeta(Document|Serializable|stdClass|array $meta): S } /** + * Adds new fields to documents. Outputs documents that contain all existing fields from the input documents and newly added fields. + * Alias for $addFields. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/set/ * @param ExpressionInterface|mixed ...$field */ public static function set(mixed ...$field): SetStage @@ -479,6 +596,10 @@ public static function set(mixed ...$field): SetStage } /** + * Groups documents into windows and applies one or more operators to the documents in each window. + * New in version 5.0. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/setWindowFields/ * @param ExpressionInterface|mixed $partitionBy 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. * @param array|stdClass $sortBy Specifies the field(s) to sort the documents by in the partition. Uses the same syntax as the $sort stage. Default is no sorting. * @param Document|Serializable|array|stdClass $output 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. @@ -495,12 +616,21 @@ public static function setWindowFields( return new SetWindowFieldsStage($partitionBy, $sortBy, $output, $window); } + /** + * Provides data and size distribution information on sharded collections. + * New in version 6.0.3. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/shardedDataDistribution/ + */ public static function shardedDataDistribution(): ShardedDataDistributionStage { return new ShardedDataDistributionStage(); } /** + * 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). + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/skip/ * @param Int64|int $skip */ public static function skip(Int64|int $skip): SkipStage @@ -509,6 +639,9 @@ public static function skip(Int64|int $skip): SkipStage } /** + * Reorders the document stream by a specified sort key. Only the order changes; the documents remain unmodified. For each input document, outputs one document. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/sort/ * @param array|stdClass $sort */ public static function sort(stdClass|array $sort): SortStage @@ -517,6 +650,9 @@ public static function sort(stdClass|array $sort): SortStage } /** + * Groups incoming documents based on the value of a specified expression, then computes the count of documents in each distinct group. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/sortByCount/ * @param ExpressionInterface|mixed $expression */ public static function sortByCount(mixed $expression): SortByCountStage @@ -525,6 +661,10 @@ public static function sortByCount(mixed $expression): SortByCountStage } /** + * Performs a union of two collections; i.e. combines pipeline results from two collections into a single result set. + * New in version 4.4. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/unionWith/ * @param non-empty-string $coll The collection or view whose pipeline results you wish to include in the result set. * @param Optional|Pipeline|array $pipeline 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. @@ -538,6 +678,10 @@ public static function unionWith( } /** + * Removes or excludes fields from documents. + * Alias for $project stage that removes or excludes fields. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/unset/ * @param FieldPath|non-empty-string ...$field */ public static function unset(FieldPath|string ...$field): UnsetStage @@ -546,6 +690,9 @@ public static function unset(FieldPath|string ...$field): UnsetStage } /** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/unwind/ * @param ArrayFieldPath|non-empty-string $field */ public static function unwind(ArrayFieldPath|string $field): UnwindStage diff --git a/src/Builder/Stage/AddFieldsStage.php b/src/Builder/Stage/AddFieldsStage.php index 557520cce..2c5354bb7 100644 --- a/src/Builder/Stage/AddFieldsStage.php +++ b/src/Builder/Stage/AddFieldsStage.php @@ -10,6 +10,11 @@ use MongoDB\Builder\Expression\ExpressionInterface; use stdClass; +/** + * Adds new fields to documents. Outputs documents that contain all existing fields from the input documents and newly added fields. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/addFields/ + */ class AddFieldsStage implements StageInterface { public const NAME = '$addFields'; diff --git a/src/Builder/Stage/BucketAutoStage.php b/src/Builder/Stage/BucketAutoStage.php index 3bfba51b4..92715edb7 100644 --- a/src/Builder/Stage/BucketAutoStage.php +++ b/src/Builder/Stage/BucketAutoStage.php @@ -14,6 +14,11 @@ use MongoDB\Builder\Optional; use stdClass; +/** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/bucketAuto/ + */ class BucketAutoStage implements StageInterface { public const NAME = '$bucketAuto'; diff --git a/src/Builder/Stage/BucketStage.php b/src/Builder/Stage/BucketStage.php index 17b5b3bea..b122c3988 100644 --- a/src/Builder/Stage/BucketStage.php +++ b/src/Builder/Stage/BucketStage.php @@ -16,6 +16,11 @@ use MongoDB\Model\BSONArray; use stdClass; +/** + * Categorizes incoming documents into groups, called buckets, based on a specified expression and bucket boundaries. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/bucket/ + */ class BucketStage implements StageInterface { public const NAME = '$bucket'; diff --git a/src/Builder/Stage/ChangeStreamSplitLargeEventStage.php b/src/Builder/Stage/ChangeStreamSplitLargeEventStage.php index 3bb6633e9..f637003c2 100644 --- a/src/Builder/Stage/ChangeStreamSplitLargeEventStage.php +++ b/src/Builder/Stage/ChangeStreamSplitLargeEventStage.php @@ -8,6 +8,12 @@ use MongoDB\Builder\Encode; +/** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/changeStreamSplitLargeEvent/ + */ class ChangeStreamSplitLargeEventStage implements StageInterface { public const NAME = '$changeStreamSplitLargeEvent'; diff --git a/src/Builder/Stage/ChangeStreamStage.php b/src/Builder/Stage/ChangeStreamStage.php index 7db401969..4df1d9dd5 100644 --- a/src/Builder/Stage/ChangeStreamStage.php +++ b/src/Builder/Stage/ChangeStreamStage.php @@ -13,6 +13,11 @@ use MongoDB\Builder\Optional; use stdClass; +/** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/changeStream/ + */ class ChangeStreamStage implements StageInterface { public const NAME = '$changeStream'; diff --git a/src/Builder/Stage/CollStatsStage.php b/src/Builder/Stage/CollStatsStage.php index a007ed629..e67831004 100644 --- a/src/Builder/Stage/CollStatsStage.php +++ b/src/Builder/Stage/CollStatsStage.php @@ -11,6 +11,11 @@ use MongoDB\Builder\Encode; use stdClass; +/** + * Returns statistics regarding a collection or view. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/collStats/ + */ class CollStatsStage implements StageInterface { public const NAME = '$collStats'; diff --git a/src/Builder/Stage/CountStage.php b/src/Builder/Stage/CountStage.php index 4165f92f1..c930acf05 100644 --- a/src/Builder/Stage/CountStage.php +++ b/src/Builder/Stage/CountStage.php @@ -8,6 +8,12 @@ use MongoDB\Builder\Encode; +/** + * Returns a count of the number of documents at this stage of the aggregation pipeline. + * Distinct from the $count aggregation accumulator. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/count/ + */ class CountStage implements StageInterface { public const NAME = '$count'; diff --git a/src/Builder/Stage/CurrentOpStage.php b/src/Builder/Stage/CurrentOpStage.php index b61f1998c..3e8fe3ca1 100644 --- a/src/Builder/Stage/CurrentOpStage.php +++ b/src/Builder/Stage/CurrentOpStage.php @@ -8,6 +8,11 @@ use MongoDB\Builder\Encode; +/** + * Returns information on active and/or dormant operations for the MongoDB deployment. To run, use the db.aggregate() method. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/currentOp/ + */ class CurrentOpStage implements StageInterface { public const NAME = '$currentOp'; diff --git a/src/Builder/Stage/DensifyStage.php b/src/Builder/Stage/DensifyStage.php index 6868106aa..5074cf4a8 100644 --- a/src/Builder/Stage/DensifyStage.php +++ b/src/Builder/Stage/DensifyStage.php @@ -14,6 +14,11 @@ use MongoDB\Model\BSONArray; use stdClass; +/** + * Creates new documents in a sequence of documents where certain values in a field are missing. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/densify/ + */ class DensifyStage implements StageInterface { public const NAME = '$densify'; diff --git a/src/Builder/Stage/DocumentsStage.php b/src/Builder/Stage/DocumentsStage.php index 9b374ef3f..682503632 100644 --- a/src/Builder/Stage/DocumentsStage.php +++ b/src/Builder/Stage/DocumentsStage.php @@ -12,6 +12,11 @@ use MongoDB\Builder\Expression\ResolvesToArray; use MongoDB\Model\BSONArray; +/** + * Returns literal documents from input values. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/documents/ + */ class DocumentsStage implements StageInterface { public const NAME = '$documents'; diff --git a/src/Builder/Stage/FacetStage.php b/src/Builder/Stage/FacetStage.php index 88d4e2d6e..2fa1e86ad 100644 --- a/src/Builder/Stage/FacetStage.php +++ b/src/Builder/Stage/FacetStage.php @@ -10,6 +10,11 @@ use MongoDB\Builder\Pipeline; use stdClass; +/** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/facet/ + */ class FacetStage implements StageInterface { public const NAME = '$facet'; diff --git a/src/Builder/Stage/FillStage.php b/src/Builder/Stage/FillStage.php index df285e3ee..ed7ec11f2 100644 --- a/src/Builder/Stage/FillStage.php +++ b/src/Builder/Stage/FillStage.php @@ -15,6 +15,11 @@ use MongoDB\Model\BSONArray; use stdClass; +/** + * Populates null and missing field values within documents. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/fill/ + */ class FillStage implements StageInterface { public const NAME = '$fill'; diff --git a/src/Builder/Stage/GeoNearStage.php b/src/Builder/Stage/GeoNearStage.php index b1e9ac7b1..810d736ba 100644 --- a/src/Builder/Stage/GeoNearStage.php +++ b/src/Builder/Stage/GeoNearStage.php @@ -13,6 +13,11 @@ use MongoDB\Builder\Query\QueryInterface; use stdClass; +/** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/geoNear/ + */ class GeoNearStage implements StageInterface { public const NAME = '$geoNear'; diff --git a/src/Builder/Stage/GraphLookupStage.php b/src/Builder/Stage/GraphLookupStage.php index d66ea99fc..1f2c3e156 100644 --- a/src/Builder/Stage/GraphLookupStage.php +++ b/src/Builder/Stage/GraphLookupStage.php @@ -15,6 +15,11 @@ use MongoDB\Model\BSONArray; use stdClass; +/** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/graphLookup/ + */ class GraphLookupStage implements StageInterface { public const NAME = '$graphLookup'; diff --git a/src/Builder/Stage/GroupStage.php b/src/Builder/Stage/GroupStage.php index 88270a438..dc3c40339 100644 --- a/src/Builder/Stage/GroupStage.php +++ b/src/Builder/Stage/GroupStage.php @@ -11,6 +11,11 @@ use MongoDB\Builder\Expression\ExpressionInterface; use stdClass; +/** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/group/ + */ class GroupStage implements StageInterface { public const NAME = '$group'; diff --git a/src/Builder/Stage/IndexStatsStage.php b/src/Builder/Stage/IndexStatsStage.php index 66d133f39..e13515d69 100644 --- a/src/Builder/Stage/IndexStatsStage.php +++ b/src/Builder/Stage/IndexStatsStage.php @@ -8,6 +8,11 @@ use MongoDB\Builder\Encode; +/** + * Returns statistics regarding the use of each index for the collection. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/indexStats/ + */ class IndexStatsStage implements StageInterface { public const NAME = '$indexStats'; diff --git a/src/Builder/Stage/LimitStage.php b/src/Builder/Stage/LimitStage.php index e135d3eda..9050d2d1f 100644 --- a/src/Builder/Stage/LimitStage.php +++ b/src/Builder/Stage/LimitStage.php @@ -9,6 +9,11 @@ use MongoDB\BSON\Int64; use MongoDB\Builder\Encode; +/** + * 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). + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/limit/ + */ class LimitStage implements StageInterface { public const NAME = '$limit'; diff --git a/src/Builder/Stage/ListLocalSessionsStage.php b/src/Builder/Stage/ListLocalSessionsStage.php index 2ac22068d..aace2ab7a 100644 --- a/src/Builder/Stage/ListLocalSessionsStage.php +++ b/src/Builder/Stage/ListLocalSessionsStage.php @@ -12,6 +12,11 @@ use MongoDB\Builder\Optional; use MongoDB\Model\BSONArray; +/** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/listLocalSessions/ + */ class ListLocalSessionsStage implements StageInterface { public const NAME = '$listLocalSessions'; diff --git a/src/Builder/Stage/ListSampledQueriesStage.php b/src/Builder/Stage/ListSampledQueriesStage.php index 460f43867..466a7eeaf 100644 --- a/src/Builder/Stage/ListSampledQueriesStage.php +++ b/src/Builder/Stage/ListSampledQueriesStage.php @@ -9,6 +9,11 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Optional; +/** + * Lists sampled queries for all collections or a specific collection. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSampledQueries/ + */ class ListSampledQueriesStage implements StageInterface { public const NAME = '$listSampledQueries'; diff --git a/src/Builder/Stage/ListSearchIndexesStage.php b/src/Builder/Stage/ListSearchIndexesStage.php index 94d5ef8b5..473a426d1 100644 --- a/src/Builder/Stage/ListSearchIndexesStage.php +++ b/src/Builder/Stage/ListSearchIndexesStage.php @@ -9,6 +9,11 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Optional; +/** + * Returns information about existing Atlas Search indexes on a specified collection. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSearchIndexes/ + */ class ListSearchIndexesStage implements StageInterface { public const NAME = '$listSearchIndexes'; diff --git a/src/Builder/Stage/ListSessionsStage.php b/src/Builder/Stage/ListSessionsStage.php index b09eaa7a4..00396493c 100644 --- a/src/Builder/Stage/ListSessionsStage.php +++ b/src/Builder/Stage/ListSessionsStage.php @@ -12,6 +12,11 @@ use MongoDB\Builder\Optional; use MongoDB\Model\BSONArray; +/** + * Lists all sessions that have been active long enough to propagate to the system.sessions collection. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSessions/ + */ class ListSessionsStage implements StageInterface { public const NAME = '$listSessions'; diff --git a/src/Builder/Stage/LookupStage.php b/src/Builder/Stage/LookupStage.php index 9081626b3..0daf0946f 100644 --- a/src/Builder/Stage/LookupStage.php +++ b/src/Builder/Stage/LookupStage.php @@ -13,6 +13,11 @@ use MongoDB\Builder\Pipeline; use stdClass; +/** + * Performs a left outer join to another collection in the same database to filter in documents from the "joined" collection for processing. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/lookup/ + */ class LookupStage implements StageInterface { public const NAME = '$lookup'; diff --git a/src/Builder/Stage/MatchStage.php b/src/Builder/Stage/MatchStage.php index f0a952768..1f48a44fa 100644 --- a/src/Builder/Stage/MatchStage.php +++ b/src/Builder/Stage/MatchStage.php @@ -10,6 +10,11 @@ use MongoDB\Builder\Query\QueryInterface; use stdClass; +/** + * 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). + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/match/ + */ class MatchStage implements StageInterface { public const NAME = '$match'; diff --git a/src/Builder/Stage/MergeStage.php b/src/Builder/Stage/MergeStage.php index b3efc8fc2..925fb4955 100644 --- a/src/Builder/Stage/MergeStage.php +++ b/src/Builder/Stage/MergeStage.php @@ -15,6 +15,12 @@ use MongoDB\Model\BSONArray; use stdClass; +/** + * 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 version 4.2. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/ + */ class MergeStage implements StageInterface { public const NAME = '$merge'; diff --git a/src/Builder/Stage/OutStage.php b/src/Builder/Stage/OutStage.php index 00b562e7d..b6cfc7e12 100644 --- a/src/Builder/Stage/OutStage.php +++ b/src/Builder/Stage/OutStage.php @@ -11,6 +11,11 @@ use MongoDB\Builder\Encode; use stdClass; +/** + * Writes the resulting documents of the aggregation pipeline to a collection. To use the $out stage, it must be the last stage in the pipeline. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/out/ + */ class OutStage implements StageInterface { public const NAME = '$out'; diff --git a/src/Builder/Stage/PlanCacheStatsStage.php b/src/Builder/Stage/PlanCacheStatsStage.php index 77c93b237..b6b1987ea 100644 --- a/src/Builder/Stage/PlanCacheStatsStage.php +++ b/src/Builder/Stage/PlanCacheStatsStage.php @@ -8,6 +8,11 @@ use MongoDB\Builder\Encode; +/** + * Returns plan cache information for a collection. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/planCacheStats/ + */ class PlanCacheStatsStage implements StageInterface { public const NAME = '$planCacheStats'; diff --git a/src/Builder/Stage/ProjectStage.php b/src/Builder/Stage/ProjectStage.php index e8950186f..cf1424ba2 100644 --- a/src/Builder/Stage/ProjectStage.php +++ b/src/Builder/Stage/ProjectStage.php @@ -11,6 +11,11 @@ use MongoDB\Builder\Expression\ExpressionInterface; use stdClass; +/** + * Reshapes each document in the stream, such as by adding new fields or removing existing fields. For each input document, outputs one document. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/project/ + */ class ProjectStage implements StageInterface { public const NAME = '$project'; diff --git a/src/Builder/Stage/RedactStage.php b/src/Builder/Stage/RedactStage.php index 46a0a57e9..4fc132687 100644 --- a/src/Builder/Stage/RedactStage.php +++ b/src/Builder/Stage/RedactStage.php @@ -9,6 +9,11 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ExpressionInterface; +/** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/redact/ + */ class RedactStage implements StageInterface { public const NAME = '$redact'; diff --git a/src/Builder/Stage/ReplaceRootStage.php b/src/Builder/Stage/ReplaceRootStage.php index 88f9fcce2..004a40a4d 100644 --- a/src/Builder/Stage/ReplaceRootStage.php +++ b/src/Builder/Stage/ReplaceRootStage.php @@ -12,6 +12,11 @@ use MongoDB\Builder\Expression\ResolvesToObject; use stdClass; +/** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceRoot/ + */ class ReplaceRootStage implements StageInterface { public const NAME = '$replaceRoot'; diff --git a/src/Builder/Stage/ReplaceWithStage.php b/src/Builder/Stage/ReplaceWithStage.php index 0bbad13d7..e05786856 100644 --- a/src/Builder/Stage/ReplaceWithStage.php +++ b/src/Builder/Stage/ReplaceWithStage.php @@ -12,6 +12,12 @@ use MongoDB\Builder\Expression\ResolvesToObject; use stdClass; +/** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceWith/ + */ class ReplaceWithStage implements StageInterface { public const NAME = '$replaceWith'; diff --git a/src/Builder/Stage/SampleStage.php b/src/Builder/Stage/SampleStage.php index 9cb198bc7..0729e420f 100644 --- a/src/Builder/Stage/SampleStage.php +++ b/src/Builder/Stage/SampleStage.php @@ -9,6 +9,11 @@ use MongoDB\BSON\Int64; use MongoDB\Builder\Encode; +/** + * Randomly selects the specified number of documents from its input. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/sample/ + */ class SampleStage implements StageInterface { public const NAME = '$sample'; diff --git a/src/Builder/Stage/SearchMetaStage.php b/src/Builder/Stage/SearchMetaStage.php index 548d2855d..66b1ccf3b 100644 --- a/src/Builder/Stage/SearchMetaStage.php +++ b/src/Builder/Stage/SearchMetaStage.php @@ -11,6 +11,12 @@ use MongoDB\Builder\Encode; use stdClass; +/** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/searchMeta/ + */ class SearchMetaStage implements StageInterface { public const NAME = '$searchMeta'; diff --git a/src/Builder/Stage/SearchStage.php b/src/Builder/Stage/SearchStage.php index cbc019618..cc5f92002 100644 --- a/src/Builder/Stage/SearchStage.php +++ b/src/Builder/Stage/SearchStage.php @@ -11,6 +11,12 @@ use MongoDB\Builder\Encode; use stdClass; +/** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/search/ + */ class SearchStage implements StageInterface { public const NAME = '$search'; diff --git a/src/Builder/Stage/SetStage.php b/src/Builder/Stage/SetStage.php index e3e6a9275..38a60cdf8 100644 --- a/src/Builder/Stage/SetStage.php +++ b/src/Builder/Stage/SetStage.php @@ -10,6 +10,12 @@ use MongoDB\Builder\Expression\ExpressionInterface; use stdClass; +/** + * Adds new fields to documents. Outputs documents that contain all existing fields from the input documents and newly added fields. + * Alias for $addFields. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/set/ + */ class SetStage implements StageInterface { public const NAME = '$set'; diff --git a/src/Builder/Stage/SetWindowFieldsStage.php b/src/Builder/Stage/SetWindowFieldsStage.php index b370b1ebf..bf9cc59cc 100644 --- a/src/Builder/Stage/SetWindowFieldsStage.php +++ b/src/Builder/Stage/SetWindowFieldsStage.php @@ -13,6 +13,12 @@ use MongoDB\Builder\Optional; use stdClass; +/** + * Groups documents into windows and applies one or more operators to the documents in each window. + * New in version 5.0. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/setWindowFields/ + */ class SetWindowFieldsStage implements StageInterface { public const NAME = '$setWindowFields'; diff --git a/src/Builder/Stage/ShardedDataDistributionStage.php b/src/Builder/Stage/ShardedDataDistributionStage.php index 26ff6169d..f8b15e596 100644 --- a/src/Builder/Stage/ShardedDataDistributionStage.php +++ b/src/Builder/Stage/ShardedDataDistributionStage.php @@ -8,6 +8,12 @@ use MongoDB\Builder\Encode; +/** + * Provides data and size distribution information on sharded collections. + * New in version 6.0.3. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/shardedDataDistribution/ + */ class ShardedDataDistributionStage implements StageInterface { public const NAME = '$shardedDataDistribution'; diff --git a/src/Builder/Stage/SkipStage.php b/src/Builder/Stage/SkipStage.php index a43c01a3a..79038b5b7 100644 --- a/src/Builder/Stage/SkipStage.php +++ b/src/Builder/Stage/SkipStage.php @@ -9,6 +9,11 @@ use MongoDB\BSON\Int64; use MongoDB\Builder\Encode; +/** + * 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). + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/skip/ + */ class SkipStage implements StageInterface { public const NAME = '$skip'; diff --git a/src/Builder/Stage/SortByCountStage.php b/src/Builder/Stage/SortByCountStage.php index 6ffe48c8c..47d51f92d 100644 --- a/src/Builder/Stage/SortByCountStage.php +++ b/src/Builder/Stage/SortByCountStage.php @@ -9,6 +9,11 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ExpressionInterface; +/** + * Groups incoming documents based on the value of a specified expression, then computes the count of documents in each distinct group. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/sortByCount/ + */ class SortByCountStage implements StageInterface { public const NAME = '$sortByCount'; diff --git a/src/Builder/Stage/SortStage.php b/src/Builder/Stage/SortStage.php index 558f57bcf..d3d970457 100644 --- a/src/Builder/Stage/SortStage.php +++ b/src/Builder/Stage/SortStage.php @@ -9,6 +9,11 @@ use MongoDB\Builder\Encode; use stdClass; +/** + * Reorders the document stream by a specified sort key. Only the order changes; the documents remain unmodified. For each input document, outputs one document. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/sort/ + */ class SortStage implements StageInterface { public const NAME = '$sort'; diff --git a/src/Builder/Stage/UnionWithStage.php b/src/Builder/Stage/UnionWithStage.php index 79aec35c8..62ce3cede 100644 --- a/src/Builder/Stage/UnionWithStage.php +++ b/src/Builder/Stage/UnionWithStage.php @@ -10,6 +10,12 @@ use MongoDB\Builder\Optional; use MongoDB\Builder\Pipeline; +/** + * Performs a union of two collections; i.e. combines pipeline results from two collections into a single result set. + * New in version 4.4. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/unionWith/ + */ class UnionWithStage implements StageInterface { public const NAME = '$unionWith'; diff --git a/src/Builder/Stage/UnsetStage.php b/src/Builder/Stage/UnsetStage.php index 715b6bccb..1e4af5329 100644 --- a/src/Builder/Stage/UnsetStage.php +++ b/src/Builder/Stage/UnsetStage.php @@ -9,6 +9,12 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\FieldPath; +/** + * Removes or excludes fields from documents. + * Alias for $project stage that removes or excludes fields. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/unset/ + */ class UnsetStage implements StageInterface { public const NAME = '$unset'; diff --git a/src/Builder/Stage/UnwindStage.php b/src/Builder/Stage/UnwindStage.php index 749fd7f94..daadc8099 100644 --- a/src/Builder/Stage/UnwindStage.php +++ b/src/Builder/Stage/UnwindStage.php @@ -9,6 +9,11 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ArrayFieldPath; +/** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/unwind/ + */ class UnwindStage implements StageInterface { public const NAME = '$unwind'; From 05c5ee589d26c2d0a2a635b9dddbde2ffb7dc842 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Thu, 5 Oct 2023 17:56:00 +0200 Subject: [PATCH 06/37] Temporary disable benchmarks and old PHP version from CI --- .github/workflows/benchmark.yml | 3 ++- .github/workflows/tests.yml | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 053d5776f..386ceb95c 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -5,7 +5,7 @@ on: branches: - "v*.*" - "master" - - "feature/*" + #- "feature/*" paths-ignore: - "docs/**" push: @@ -15,6 +15,7 @@ on: - "feature/*" paths-ignore: - "docs/**" + - "generator/**" env: PHP_VERSION: "8.2" diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 8698e7459..b47747736 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -27,8 +27,8 @@ jobs: os: - "ubuntu-20.04" php-version: - - "7.4" - - "8.0" + #- "7.4" + #- "8.0" - "8.1" - "8.2" mongodb-version: From 83aa77ab0ff653abf59612aabba5e932f5bc68a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Thu, 5 Oct 2023 19:59:27 +0200 Subject: [PATCH 07/37] Fix & encoding --- src/Builder/BuilderEncoder.php | 20 +++++++------------- tests/Builder/BuilderEncoderTest.php | 3 ++- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/Builder/BuilderEncoder.php b/src/Builder/BuilderEncoder.php index f4cd4ecf5..70613b166 100644 --- a/src/Builder/BuilderEncoder.php +++ b/src/Builder/BuilderEncoder.php @@ -8,7 +8,6 @@ use MongoDB\Builder\Expression\Variable; use MongoDB\Builder\Query\QueryInterface; use MongoDB\Builder\Stage\GroupStage; -use MongoDB\Builder\Stage\ProjectStage; use MongoDB\Builder\Stage\StageInterface; use MongoDB\Codec\EncodeIfSupported; use MongoDB\Codec\Encoder; @@ -63,16 +62,6 @@ public function encode($value): stdClass|array|string return '$$' . $value->expression; } - if ($value instanceof ProjectStage) { - $result = new stdClass(); - // Specific: fields are encoded as a map of properties to their values at the top level as _id - foreach ($value->specifications as $key => $val) { - $result->{$key} = $this->encodeIfSupported($val); - } - - return $this->wrap($value, $result); - } - // The generic but incomplete encoding code switch ($value::ENCODE) { case Encode::Single: @@ -117,10 +106,12 @@ private function encodeAsObject(ExpressionInterface|StageInterface|QueryInterfac return $this->wrap($value, $result); } + /** + * Get the unique property of the operator as value + */ private function encodeAsSingle(ExpressionInterface|StageInterface|QueryInterface $value): stdClass { $result = []; - /** @var mixed $val */ foreach (get_object_vars($value) as $val) { $result = $this->recursiveEncode($val); break; @@ -136,7 +127,7 @@ private function encodeAsGroup(GroupStage $value): stdClass { $result = new stdClass(); $result->_id = $this->recursiveEncode($value->_id); - // Specific to $group: fields are encoded as a map of properties to their values at the top level as _id + foreach ($value->field ?? [] as $key => $val) { $result->{$key} = $this->recursiveEncode($val); } @@ -144,6 +135,9 @@ private function encodeAsGroup(GroupStage $value): stdClass return $this->wrap($value, $result); } + /** + * Nested arrays and objects must be encoded recursively. + */ private function recursiveEncode(mixed $value): mixed { if (is_array($value)) { diff --git a/tests/Builder/BuilderEncoderTest.php b/tests/Builder/BuilderEncoderTest.php index cc604b407..df94d7b6d 100644 --- a/tests/Builder/BuilderEncoderTest.php +++ b/tests/Builder/BuilderEncoderTest.php @@ -83,7 +83,8 @@ public function testPerformCount(): void [ '$group' => [ '_id' => null, - 'count' => ['$sum' => 1], + // same as 'count' => ['$sum' => 1], + 'count' => ['$sum' => [1]], ], ], ]; From 9a36d1709b06de944a59657ef712011cc624b962 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Thu, 5 Oct 2023 22:42:01 +0200 Subject: [PATCH 08/37] Fix schema --- .idea/jsonSchemas.xml | 27 +++++++++++++++++++++++++++ generator/config/schema.json | 21 ++++++++++----------- 2 files changed, 37 insertions(+), 11 deletions(-) create mode 100644 .idea/jsonSchemas.xml diff --git a/.idea/jsonSchemas.xml b/.idea/jsonSchemas.xml new file mode 100644 index 000000000..dcae88975 --- /dev/null +++ b/.idea/jsonSchemas.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + diff --git a/generator/config/schema.json b/generator/config/schema.json index 0639edac2..2ee5c2f9b 100644 --- a/generator/config/schema.json +++ b/generator/config/schema.json @@ -26,7 +26,7 @@ "https" ] }, - "returnType": { + "type": { "type": "array", "items": { "type": "string" @@ -50,8 +50,8 @@ "$comment": "The description of the argument from MongoDB's documentation.", "type": "string" }, - "parameters": { - "$comment": "An optional list of parameters for the operator.", + "arguments": { + "$comment": "An optional list of arguments for the operator.", "type": "array", "items": { "$ref": "#/definitions/Argument" @@ -64,8 +64,8 @@ "encode", "link", "name", - "parameters", - "returnType" + "arguments", + "type" ], "title": "Operator" }, @@ -77,7 +77,7 @@ "type": "string", "pattern": "^[a-z][a-zA-Z0-9]+$" }, - "returnType": { + "type": { "type": "array", "items": { "type": "string" @@ -88,19 +88,19 @@ "type": "string" }, "optional": { - "$comment": "Whether the parameter is optional or not.", + "$comment": "Whether the argument is optional or not.", "type": "boolean" }, "valueMin": { - "$comment": "The minimum value for a numeric parameter.", + "$comment": "The minimum value for a numeric argument.", "type": "number" }, "valueMax": { - "$comment": "The minimum value for a numeric parameter.", + "$comment": "The minimum value for a numeric argument.", "type": "number" }, "variadic": { - "$comment": "Whether the parameter is variadic or not.", + "$comment": "Whether the argument is variadic or not.", "type": "string", "enum": [ "array", @@ -114,7 +114,6 @@ } }, "required": [ - "description", "name", "type" ], From c0de34d51f368b007dee3d4fbf0976627f6a1bf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Thu, 5 Oct 2023 23:26:12 +0200 Subject: [PATCH 09/37] Introduce MongoDB\object() function --- src/functions.php | 12 ++++++++++++ tests/Builder/BuilderEncoderTest.php | 16 ++++++++-------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/functions.php b/src/functions.php index 95c85380b..4f438ab45 100644 --- a/src/functions.php +++ b/src/functions.php @@ -34,6 +34,7 @@ use Psr\Log\LoggerInterface; use ReflectionClass; use ReflectionException; +use stdClass; use function array_is_list; use function array_key_first; @@ -58,6 +59,17 @@ function add_logger(LoggerInterface $logger): void PsrLogAdapter::addLogger($logger); } +/** + * Create a new stdClass instance with the provided properties. + * + * @psalm-suppress MoreSpecificReturnType + * @psalm-suppress LessSpecificReturnStatement + */ +function object(mixed ...$values): stdClass +{ + return (object) $values; +} + /** * Unregisters a PSR-3 logger. * diff --git a/tests/Builder/BuilderEncoderTest.php b/tests/Builder/BuilderEncoderTest.php index df94d7b6d..b3dee19e3 100644 --- a/tests/Builder/BuilderEncoderTest.php +++ b/tests/Builder/BuilderEncoderTest.php @@ -15,6 +15,7 @@ use function array_merge; use function array_walk; use function is_array; +use function MongoDB\object; use function var_export; /** @@ -27,8 +28,7 @@ class BuilderEncoderTest extends TestCase public function testPipeline(): void { $pipeline = new Pipeline( - // @todo array is accepted by the stage class, but we expect an object. The driver accepts both. - Stage::match((object) ['author' => 'dave']), + Stage::match(object(author: 'dave')), Stage::limit(1), ); @@ -44,7 +44,7 @@ public function testPipeline(): void public function testSort(): void { $pipeline = new Pipeline( - Stage::sort((object) ['age' => -1, 'posts' => 1]), + Stage::sort(object(age: -1, posts: 1)), ); $expected = [ @@ -60,8 +60,8 @@ public function testPerformCount(): void $pipeline = new Pipeline( Stage::match( Query::or( - (object) ['score' => [Query::gt(70), Query::lt(90)]], - (object) ['views' => Query::gte(1000)], + object(score: [Query::gt(70), Query::lt(90)]), + object(views: Query::gte(1000)), ), ), Stage::group( @@ -99,14 +99,14 @@ public function testPerformCount(): void public function testAggregationFilter(array $limit, array $expectedLimit): void { $pipeline = new Pipeline( - Stage::project(...[ - 'items' => Aggregation::filter( + Stage::project( + items: Aggregation::filter( Expression::arrayFieldPath('items'), Aggregation::gte(Expression::variable('item.price'), 100), 'item', ...$limit, ), - ]), + ), ); $expected = [ From 70f8671e3f4ba9dac2343f1be2346adb340e30f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Fri, 6 Oct 2023 00:03:51 +0200 Subject: [PATCH 10/37] Fix single encoding + optional value in array --- .../config/aggregation-operators/bitXor.yaml | 7 +++++ generator/config/aggregation-stages/out.yaml | 3 ++- .../src/Definition/OperatorDefinition.php | 9 ++++++- src/Builder/Aggregation.php | 5 ++-- src/Builder/Aggregation/BitXorAggregation.php | 19 ++++++++++++- src/Builder/BuilderEncoder.php | 16 +++++++---- src/Builder/Stage.php | 8 ++++-- src/Builder/Stage/OutStage.php | 16 ++++++----- tests/Builder/BuilderEncoderTest.php | 27 +++++++++++++++++++ 9 files changed, 92 insertions(+), 18 deletions(-) diff --git a/generator/config/aggregation-operators/bitXor.yaml b/generator/config/aggregation-operators/bitXor.yaml index 4aca36e01..70a3a275b 100644 --- a/generator/config/aggregation-operators/bitXor.yaml +++ b/generator/config/aggregation-operators/bitXor.yaml @@ -10,3 +10,10 @@ encode: single description: | Returns the result of a bitwise xor (exclusive or) operation on an array of int and long values. New in version 6.3. +arguments: + - + name: expression + type: + - resolvesToInt + - resolvesToLong + variadic: array diff --git a/generator/config/aggregation-stages/out.yaml b/generator/config/aggregation-stages/out.yaml index 3d439c9f5..06ad86099 100644 --- a/generator/config/aggregation-stages/out.yaml +++ b/generator/config/aggregation-stages/out.yaml @@ -5,7 +5,7 @@ category: link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/out/' type: - Stage -encode: single +encode: object 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: @@ -25,5 +25,6 @@ arguments: name: timeseries type: - object + optional: true description: | If set, the aggregation stage will use these options to create or replace a time-series collection in the given namespace. diff --git a/generator/src/Definition/OperatorDefinition.php b/generator/src/Definition/OperatorDefinition.php index e553863dc..16b6d13d7 100644 --- a/generator/src/Definition/OperatorDefinition.php +++ b/generator/src/Definition/OperatorDefinition.php @@ -7,6 +7,8 @@ use UnexpectedValueException; use function array_merge; +use function assert; +use function count; use function sprintf; final readonly class OperatorDefinition @@ -28,7 +30,6 @@ public function __construct( 'single' => Encode::Single, 'array' => Encode::Array, 'object' => Encode::Object, - 'empty object' => Encode::Object, 'group' => Encode::Group, default => throw new UnexpectedValueException(sprintf('Unexpected "encode" value for operator "%s". Got "%s"', $name, $encode)), }; @@ -45,6 +46,12 @@ public function __construct( } } + // "single" encode operators must have one required argument + if ($this->encode === Encode::Single) { + assert(count($requiredArgs) === 1, sprintf('Single encode operator "%s" must have one argument', $name)); + assert(count($optionalArgs) === 0, sprintf('Single encode operator "%s" argument cannot be optional', $name)); + } + $this->arguments = array_merge($requiredArgs, $optionalArgs); } } diff --git a/src/Builder/Aggregation.php b/src/Builder/Aggregation.php index cdd3438d3..b0a4a7e51 100644 --- a/src/Builder/Aggregation.php +++ b/src/Builder/Aggregation.php @@ -494,10 +494,11 @@ public static function bitOr(Int64|ResolvesToInt|ResolvesToLong|int ...$expressi * New in version 6.3. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitXor/ + * @param Int64|ResolvesToInt|ResolvesToLong|int ...$expression */ - public static function bitXor(): BitXorAggregation + public static function bitXor(Int64|ResolvesToInt|ResolvesToLong|int ...$expression): BitXorAggregation { - return new BitXorAggregation(); + return new BitXorAggregation(...$expression); } /** diff --git a/src/Builder/Aggregation/BitXorAggregation.php b/src/Builder/Aggregation/BitXorAggregation.php index 00f7a8840..883171fcc 100644 --- a/src/Builder/Aggregation/BitXorAggregation.php +++ b/src/Builder/Aggregation/BitXorAggregation.php @@ -6,6 +6,7 @@ namespace MongoDB\Builder\Aggregation; +use MongoDB\BSON\Int64; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Expression\ResolvesToLong; @@ -21,7 +22,23 @@ class BitXorAggregation implements ResolvesToInt, ResolvesToLong public const NAME = '$bitXor'; public const ENCODE = \MongoDB\Builder\Encode::Single; - public function __construct() + /** + * @no-named-arguments + * @param list ...$expression + */ + public array $expression; + + /** + * @param Int64|ResolvesToInt|ResolvesToLong|int ...$expression + */ + public function __construct(Int64|ResolvesToInt|ResolvesToLong|int ...$expression) { + if (\count($expression) < 1) { + throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); + } + if (! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression arguments to be a list of Int64|ResolvesToInt|ResolvesToLong|int, named arguments are not supported'); + } + $this->expression = $expression; } } diff --git a/src/Builder/BuilderEncoder.php b/src/Builder/BuilderEncoder.php index 70613b166..c77d8a99c 100644 --- a/src/Builder/BuilderEncoder.php +++ b/src/Builder/BuilderEncoder.php @@ -85,6 +85,12 @@ private function encodeAsArray(ExpressionInterface|StageInterface|QueryInterface $result = []; /** @var mixed $val */ foreach (get_object_vars($value) as $val) { + // Skip optional arguments. + // $slice operator has the optional argument in the middle of the array + if ($val === Optional::Undefined) { + continue; + } + $result[] = $this->recursiveEncode($val); } @@ -94,13 +100,13 @@ private function encodeAsArray(ExpressionInterface|StageInterface|QueryInterface private function encodeAsObject(ExpressionInterface|StageInterface|QueryInterface $value): stdClass { $result = new stdClass(); - /** @var mixed $val */ foreach (get_object_vars($value) as $key => $val) { - /** @var mixed $val */ - $val = $this->recursiveEncode($val); - if ($val !== Optional::Undefined) { - $result->{$key} = $val; + // Skip optional arguments. If they have a default value, it is resolved by the server. + if ($val === Optional::Undefined) { + continue; } + + $result->{$key} = $this->recursiveEncode($val); } return $this->wrap($value, $result); diff --git a/src/Builder/Stage.php b/src/Builder/Stage.php index aee98d3c4..8c35c9e41 100644 --- a/src/Builder/Stage.php +++ b/src/Builder/Stage.php @@ -482,9 +482,13 @@ public static function merge( * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/out/ * @param non-empty-string $db Target collection name to write documents from $out to. * @param non-empty-string $coll Target database name to write documents from $out to. - * @param Document|Serializable|array|stdClass $timeseries If set, the aggregation stage will use these options to create or replace a time-series collection in the given namespace. + * @param Document|Optional|Serializable|array|stdClass $timeseries If set, the aggregation stage will use these options to create or replace a time-series collection in the given namespace. */ - public static function out(string $db, string $coll, Document|Serializable|stdClass|array $timeseries): OutStage + public static function out( + string $db, + string $coll, + Document|Serializable|Optional|stdClass|array $timeseries = Optional::Undefined, + ): OutStage { return new OutStage($db, $coll, $timeseries); } diff --git a/src/Builder/Stage/OutStage.php b/src/Builder/Stage/OutStage.php index b6cfc7e12..a25328b80 100644 --- a/src/Builder/Stage/OutStage.php +++ b/src/Builder/Stage/OutStage.php @@ -9,6 +9,7 @@ use MongoDB\BSON\Document; use MongoDB\BSON\Serializable; use MongoDB\Builder\Encode; +use MongoDB\Builder\Optional; use stdClass; /** @@ -19,7 +20,7 @@ class OutStage implements StageInterface { public const NAME = '$out'; - public const ENCODE = \MongoDB\Builder\Encode::Single; + public const ENCODE = \MongoDB\Builder\Encode::Object; /** @param non-empty-string $db Target collection name to write documents from $out to. */ public string $db; @@ -27,16 +28,19 @@ class OutStage implements StageInterface /** @param non-empty-string $coll Target database name to write documents from $out to. */ public string $coll; - /** @param Document|Serializable|array|stdClass $timeseries If set, the aggregation stage will use these options to create or replace a time-series collection in the given namespace. */ - public Document|Serializable|stdClass|array $timeseries; + /** @param Document|Optional|Serializable|array|stdClass $timeseries If set, the aggregation stage will use these options to create or replace a time-series collection in the given namespace. */ + public Document|Serializable|Optional|stdClass|array $timeseries; /** * @param non-empty-string $db Target collection name to write documents from $out to. * @param non-empty-string $coll Target database name to write documents from $out to. - * @param Document|Serializable|array|stdClass $timeseries If set, the aggregation stage will use these options to create or replace a time-series collection in the given namespace. + * @param Document|Optional|Serializable|array|stdClass $timeseries If set, the aggregation stage will use these options to create or replace a time-series collection in the given namespace. */ - public function __construct(string $db, string $coll, Document|Serializable|stdClass|array $timeseries) - { + public function __construct( + string $db, + string $coll, + Document|Serializable|Optional|stdClass|array $timeseries = Optional::Undefined, + ) { $this->db = $db; $this->coll = $coll; $this->timeseries = $timeseries; diff --git a/tests/Builder/BuilderEncoderTest.php b/tests/Builder/BuilderEncoderTest.php index b3dee19e3..77f5c367f 100644 --- a/tests/Builder/BuilderEncoderTest.php +++ b/tests/Builder/BuilderEncoderTest.php @@ -139,6 +139,33 @@ public static function provideAggregationFilterLimit(): Generator ]; } + /** @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/slice/#example */ + public function testSlice(): void + { + $pipeline = new Pipeline( + Stage::project( + name: 1, + threeFavorites: Aggregation::slice( + Expression::arrayFieldPath('items'), + n: 3, + ), + ), + ); + + $expected = [ + [ + '$project' => [ + 'name' => 1, + 'threeFavorites' => [ + '$slice' => ['$items', 3], + ], + ], + ], + ]; + + $this->assertSamePipeline($expected, $pipeline); + } + private static function assertSamePipeline(array $expected, Pipeline $pipeline): void { $codec = new BuilderEncoder(); From 38c77502606ef5eb33af4dba374ff917952306d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Fri, 6 Oct 2023 00:41:29 +0200 Subject: [PATCH 11/37] Fix psalm + accumulator --- examples/aggregation-builder.php | 8 +++- generator/src/Command/ScrapeCommand.php | 12 +----- generator/src/OperatorClassGenerator.php | 7 ++-- psalm.xml.dist | 2 +- src/Builder/Aggregation/AddAggregation.php | 6 +-- src/Builder/Aggregation/Aggregation.php | 42 ------------------- .../AllElementsTrueAggregation.php | 6 +-- src/Builder/Aggregation/AndAggregation.php | 6 +-- src/Builder/Aggregation/AvgAggregation.php | 6 +-- src/Builder/Aggregation/BitAndAggregation.php | 6 +-- src/Builder/Aggregation/BitOrAggregation.php | 6 +-- src/Builder/Aggregation/BitXorAggregation.php | 6 +-- src/Builder/Aggregation/ConcatAggregation.php | 6 +-- .../Aggregation/ConcatArraysAggregation.php | 6 +-- src/Builder/Aggregation/IfNullAggregation.php | 6 +-- .../Aggregation/IsArrayAggregation.php | 6 +-- .../Aggregation/IsNumberAggregation.php | 6 +-- src/Builder/Aggregation/MaxAggregation.php | 6 +-- .../Aggregation/MergeObjectsAggregation.php | 6 +-- src/Builder/Aggregation/MinAggregation.php | 6 +-- .../Aggregation/MultiplyAggregation.php | 2 +- src/Builder/Aggregation/OrAggregation.php | 6 +-- .../Aggregation/SetEqualsAggregation.php | 6 +-- .../SetIntersectionAggregation.php | 6 +-- .../Aggregation/SetUnionAggregation.php | 6 +-- .../Aggregation/StdDevPopAggregation.php | 6 +-- .../Aggregation/StdDevSampAggregation.php | 6 +-- src/Builder/Aggregation/SumAggregation.php | 6 +-- src/Builder/BuilderEncoder.php | 19 +++++++-- src/Builder/Query/AllQuery.php | 6 +-- src/Builder/Query/AndQuery.php | 6 +-- src/Builder/Query/NorQuery.php | 6 +-- src/Builder/Query/OrQuery.php | 6 +-- src/Builder/Query/Query.php | 26 ------------ src/Builder/Stage/Stage.php | 30 ------------- src/Builder/Stage/UnsetStage.php | 6 +-- 36 files changed, 82 insertions(+), 228 deletions(-) delete mode 100644 src/Builder/Aggregation/Aggregation.php delete mode 100644 src/Builder/Query/Query.php delete mode 100644 src/Builder/Stage/Stage.php diff --git a/examples/aggregation-builder.php b/examples/aggregation-builder.php index 5f7505db5..16077921e 100644 --- a/examples/aggregation-builder.php +++ b/examples/aggregation-builder.php @@ -14,8 +14,10 @@ use MongoDB\Builder\Stage; use MongoDB\Client; +use function array_is_list; use function assert; use function getenv; +use function is_array; use function is_object; use function MongoDB\BSON\fromPHP; use function MongoDB\BSON\toRelaxedExtendedJSON; @@ -48,7 +50,7 @@ function toJSON(object $document): string totalCount: Aggregation::sum(1), evenCount: Aggregation::sum( Aggregation::mod( - Expression::fieldPath('randomValue'), + Expression::numberFieldPath('randomValue'), 2, ), ), @@ -56,7 +58,7 @@ function toJSON(object $document): string Aggregation::subtract( 1, Aggregation::mod( - Expression::fieldPath('randomValue'), + Expression::numberFieldPath('randomValue'), 2, ), ), @@ -74,6 +76,8 @@ function toJSON(object $document): string $encoder = new BuilderEncoder(); $pipeline = $encoder->encode($pipeline); +assert(is_array($pipeline) && array_is_list($pipeline)); + $cursor = $collection->aggregate($pipeline); foreach ($cursor as $document) { diff --git a/generator/src/Command/ScrapeCommand.php b/generator/src/Command/ScrapeCommand.php index 579c89d52..7532e09e8 100644 --- a/generator/src/Command/ScrapeCommand.php +++ b/generator/src/Command/ScrapeCommand.php @@ -160,17 +160,7 @@ private function getTableData(Crawler $crawler, string $tabName): array return $docs; } - /** - * @param array{ - * Name: string, - * Category: string, - * Description: string, - * Link: string, - * ReturnType: string, - * Encode: string, - * Args: array{ Name: string, Type: string, Options: string, Description: string } - * } $doc - */ + /** @param array{Name:string,Category:string,Description:string,Link:string,ReturnType:string,Encode:string,Args:array{Name:string,Type:string,Options:string,Description:string}} $doc */ private function formatSpec(array $doc): array { foreach (['Name', 'Category', 'Description', 'Link', 'ReturnType', 'Encode', 'Args'] as $key) { diff --git a/generator/src/OperatorClassGenerator.php b/generator/src/OperatorClassGenerator.php index 7d386fc61..1ce64a97b 100644 --- a/generator/src/OperatorClassGenerator.php +++ b/generator/src/OperatorClassGenerator.php @@ -53,7 +53,7 @@ public function createClass(GeneratorDefinition $definition, OperatorDefinition // @todo move to encoder class $namespace->addUse('\\' . Encode::class); $class->addComment($operator->description); - $class->addComment('@see '.$operator->link); + $class->addComment('@see ' . $operator->link); $class->addConstant('NAME', $operator->name); $class->addConstant('ENCODE', $operator->encode); @@ -82,9 +82,10 @@ public function createClass(GeneratorDefinition $definition, OperatorDefinition if ($argument->variadic === VariadicType::Array) { $property->setType('array'); - // @see https://psalm.dev/docs/running_psalm/issues/NamedArgumentNotAllowed/ - $property->addComment('@no-named-arguments'); $property->addComment('@param list<' . $type->doc . '> ...$' . $argument->name . rtrim(' ' . $argument->description)); + // Warn that named arguments are not supported + // @see https://psalm.dev/docs/running_psalm/issues/NamedArgumentNotAllowed/ + $constuctor->addComment('@no-named-arguments'); $constuctor->addBody(<<name})) { throw new \InvalidArgumentException('Expected \${$argument->name} arguments to be a list of {$type->doc}, named arguments are not supported'); diff --git a/psalm.xml.dist b/psalm.xml.dist index 380d4e853..1803c00f4 100644 --- a/psalm.xml.dist +++ b/psalm.xml.dist @@ -1,6 +1,6 @@ ...$expression The arguments can be any valid expression as long as they resolve to either all numbers or to numbers and a date. - */ + /** @param list ...$expression The arguments can be any valid expression as long as they resolve to either all numbers or to numbers and a date. */ public array $expression; /** * @param DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int ...$expression The arguments can be any valid expression as long as they resolve to either all numbers or to numbers and a date. + * @no-named-arguments */ public function __construct( DateTimeInterface|Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int ...$expression, diff --git a/src/Builder/Aggregation/Aggregation.php b/src/Builder/Aggregation/Aggregation.php deleted file mode 100644 index 7ed2f090a..000000000 --- a/src/Builder/Aggregation/Aggregation.php +++ /dev/null @@ -1,42 +0,0 @@ -date = $date; - $this->timezone = $timezone; - } -} diff --git a/src/Builder/Aggregation/AllElementsTrueAggregation.php b/src/Builder/Aggregation/AllElementsTrueAggregation.php index 05f4d8581..d30c03f53 100644 --- a/src/Builder/Aggregation/AllElementsTrueAggregation.php +++ b/src/Builder/Aggregation/AllElementsTrueAggregation.php @@ -23,14 +23,12 @@ class AllElementsTrueAggregation implements ResolvesToBool public const NAME = '$allElementsTrue'; public const ENCODE = \MongoDB\Builder\Encode::Array; - /** - * @no-named-arguments - * @param list> ...$expression - */ + /** @param list> ...$expression */ public array $expression; /** * @param BSONArray|PackedArray|ResolvesToArray|list ...$expression + * @no-named-arguments */ public function __construct(PackedArray|ResolvesToArray|BSONArray|array ...$expression) { diff --git a/src/Builder/Aggregation/AndAggregation.php b/src/Builder/Aggregation/AndAggregation.php index 994062df0..a004a6db6 100644 --- a/src/Builder/Aggregation/AndAggregation.php +++ b/src/Builder/Aggregation/AndAggregation.php @@ -25,14 +25,12 @@ class AndAggregation implements ResolvesToBool public const NAME = '$and'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** - * @no-named-arguments - * @param list ...$expression - */ + /** @param list ...$expression */ public array $expression; /** * @param Decimal128|ExpressionInterface|Int64|ResolvesToBool|ResolvesToNull|ResolvesToNumber|ResolvesToString|bool|float|int|mixed|non-empty-string|null ...$expression + * @no-named-arguments */ public function __construct(mixed ...$expression) { diff --git a/src/Builder/Aggregation/AvgAggregation.php b/src/Builder/Aggregation/AvgAggregation.php index 71a1ca957..8a0535215 100644 --- a/src/Builder/Aggregation/AvgAggregation.php +++ b/src/Builder/Aggregation/AvgAggregation.php @@ -22,14 +22,12 @@ class AvgAggregation implements ResolvesToNumber, AccumulatorInterface public const NAME = '$avg'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** - * @no-named-arguments - * @param list ...$expression - */ + /** @param list ...$expression */ public array $expression; /** * @param Decimal128|Int64|ResolvesToNumber|float|int ...$expression + * @no-named-arguments */ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int ...$expression) { diff --git a/src/Builder/Aggregation/BitAndAggregation.php b/src/Builder/Aggregation/BitAndAggregation.php index 8c56abda3..dd9d73918 100644 --- a/src/Builder/Aggregation/BitAndAggregation.php +++ b/src/Builder/Aggregation/BitAndAggregation.php @@ -22,14 +22,12 @@ class BitAndAggregation implements ResolvesToInt, ResolvesToLong public const NAME = '$bitAnd'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** - * @no-named-arguments - * @param list ...$expression - */ + /** @param list ...$expression */ public array $expression; /** * @param Int64|ResolvesToInt|ResolvesToLong|int ...$expression + * @no-named-arguments */ public function __construct(Int64|ResolvesToInt|ResolvesToLong|int ...$expression) { diff --git a/src/Builder/Aggregation/BitOrAggregation.php b/src/Builder/Aggregation/BitOrAggregation.php index 47bf61af2..b0fa1ed1b 100644 --- a/src/Builder/Aggregation/BitOrAggregation.php +++ b/src/Builder/Aggregation/BitOrAggregation.php @@ -22,14 +22,12 @@ class BitOrAggregation implements ResolvesToInt, ResolvesToLong public const NAME = '$bitOr'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** - * @no-named-arguments - * @param list ...$expression - */ + /** @param list ...$expression */ public array $expression; /** * @param Int64|ResolvesToInt|ResolvesToLong|int ...$expression + * @no-named-arguments */ public function __construct(Int64|ResolvesToInt|ResolvesToLong|int ...$expression) { diff --git a/src/Builder/Aggregation/BitXorAggregation.php b/src/Builder/Aggregation/BitXorAggregation.php index 883171fcc..130f58d3d 100644 --- a/src/Builder/Aggregation/BitXorAggregation.php +++ b/src/Builder/Aggregation/BitXorAggregation.php @@ -22,14 +22,12 @@ class BitXorAggregation implements ResolvesToInt, ResolvesToLong public const NAME = '$bitXor'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** - * @no-named-arguments - * @param list ...$expression - */ + /** @param list ...$expression */ public array $expression; /** * @param Int64|ResolvesToInt|ResolvesToLong|int ...$expression + * @no-named-arguments */ public function __construct(Int64|ResolvesToInt|ResolvesToLong|int ...$expression) { diff --git a/src/Builder/Aggregation/ConcatAggregation.php b/src/Builder/Aggregation/ConcatAggregation.php index 5c978ea79..b9cb94bb3 100644 --- a/src/Builder/Aggregation/ConcatAggregation.php +++ b/src/Builder/Aggregation/ConcatAggregation.php @@ -19,14 +19,12 @@ class ConcatAggregation implements ResolvesToString public const NAME = '$concat'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** - * @no-named-arguments - * @param list ...$expression - */ + /** @param list ...$expression */ public array $expression; /** * @param ResolvesToString|non-empty-string ...$expression + * @no-named-arguments */ public function __construct(ResolvesToString|string ...$expression) { diff --git a/src/Builder/Aggregation/ConcatArraysAggregation.php b/src/Builder/Aggregation/ConcatArraysAggregation.php index f0b66e7a5..f1fe60b30 100644 --- a/src/Builder/Aggregation/ConcatArraysAggregation.php +++ b/src/Builder/Aggregation/ConcatArraysAggregation.php @@ -22,14 +22,12 @@ class ConcatArraysAggregation implements ResolvesToArray public const NAME = '$concatArrays'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** - * @no-named-arguments - * @param list> ...$array - */ + /** @param list> ...$array */ public array $array; /** * @param BSONArray|PackedArray|ResolvesToArray|list ...$array + * @no-named-arguments */ public function __construct(PackedArray|ResolvesToArray|BSONArray|array ...$array) { diff --git a/src/Builder/Aggregation/IfNullAggregation.php b/src/Builder/Aggregation/IfNullAggregation.php index b38d9defd..2cf306191 100644 --- a/src/Builder/Aggregation/IfNullAggregation.php +++ b/src/Builder/Aggregation/IfNullAggregation.php @@ -19,14 +19,12 @@ class IfNullAggregation implements ExpressionInterface public const NAME = '$ifNull'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** - * @no-named-arguments - * @param list ...$expression - */ + /** @param list ...$expression */ public array $expression; /** * @param ExpressionInterface|mixed ...$expression + * @no-named-arguments */ public function __construct(mixed ...$expression) { diff --git a/src/Builder/Aggregation/IsArrayAggregation.php b/src/Builder/Aggregation/IsArrayAggregation.php index ca40129d6..f10c40b3c 100644 --- a/src/Builder/Aggregation/IsArrayAggregation.php +++ b/src/Builder/Aggregation/IsArrayAggregation.php @@ -20,14 +20,12 @@ class IsArrayAggregation implements ResolvesToBool public const NAME = '$isArray'; public const ENCODE = \MongoDB\Builder\Encode::Array; - /** - * @no-named-arguments - * @param list ...$expression - */ + /** @param list ...$expression */ public array $expression; /** * @param ExpressionInterface|mixed ...$expression + * @no-named-arguments */ public function __construct(mixed ...$expression) { diff --git a/src/Builder/Aggregation/IsNumberAggregation.php b/src/Builder/Aggregation/IsNumberAggregation.php index 3e8ea7d0d..b741bd1af 100644 --- a/src/Builder/Aggregation/IsNumberAggregation.php +++ b/src/Builder/Aggregation/IsNumberAggregation.php @@ -22,14 +22,12 @@ class IsNumberAggregation implements ResolvesToBool public const NAME = '$isNumber'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** - * @no-named-arguments - * @param list ...$expression - */ + /** @param list ...$expression */ public array $expression; /** * @param ExpressionInterface|mixed ...$expression + * @no-named-arguments */ public function __construct(mixed ...$expression) { diff --git a/src/Builder/Aggregation/MaxAggregation.php b/src/Builder/Aggregation/MaxAggregation.php index 80dd4e934..41a7a9eb0 100644 --- a/src/Builder/Aggregation/MaxAggregation.php +++ b/src/Builder/Aggregation/MaxAggregation.php @@ -20,14 +20,12 @@ class MaxAggregation implements ExpressionInterface, AccumulatorInterface public const NAME = '$max'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** - * @no-named-arguments - * @param list ...$expression - */ + /** @param list ...$expression */ public array $expression; /** * @param ExpressionInterface|mixed ...$expression + * @no-named-arguments */ public function __construct(mixed ...$expression) { diff --git a/src/Builder/Aggregation/MergeObjectsAggregation.php b/src/Builder/Aggregation/MergeObjectsAggregation.php index b6dbe737d..7a70f1033 100644 --- a/src/Builder/Aggregation/MergeObjectsAggregation.php +++ b/src/Builder/Aggregation/MergeObjectsAggregation.php @@ -22,14 +22,12 @@ class MergeObjectsAggregation implements AccumulatorInterface public const NAME = '$mergeObjects'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** - * @no-named-arguments - * @param list ...$document Any valid expression that resolves to a document. - */ + /** @param list ...$document Any valid expression that resolves to a document. */ public array $document; /** * @param Document|ResolvesToObject|Serializable|array|stdClass ...$document Any valid expression that resolves to a document. + * @no-named-arguments */ public function __construct(Document|Serializable|ResolvesToObject|stdClass|array ...$document) { diff --git a/src/Builder/Aggregation/MinAggregation.php b/src/Builder/Aggregation/MinAggregation.php index 36e4f4da4..cc32841dd 100644 --- a/src/Builder/Aggregation/MinAggregation.php +++ b/src/Builder/Aggregation/MinAggregation.php @@ -20,14 +20,12 @@ class MinAggregation implements ExpressionInterface, AccumulatorInterface public const NAME = '$min'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** - * @no-named-arguments - * @param list ...$expression - */ + /** @param list ...$expression */ public array $expression; /** * @param ExpressionInterface|mixed ...$expression + * @no-named-arguments */ public function __construct(mixed ...$expression) { diff --git a/src/Builder/Aggregation/MultiplyAggregation.php b/src/Builder/Aggregation/MultiplyAggregation.php index 01854f4aa..e21243682 100644 --- a/src/Builder/Aggregation/MultiplyAggregation.php +++ b/src/Builder/Aggregation/MultiplyAggregation.php @@ -23,7 +23,6 @@ class MultiplyAggregation implements ResolvesToDecimal public const ENCODE = \MongoDB\Builder\Encode::Single; /** - * @no-named-arguments * @param list ...$expression 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. */ @@ -32,6 +31,7 @@ class MultiplyAggregation implements ResolvesToDecimal /** * @param Decimal128|Int64|ResolvesToNumber|float|int ...$expression 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. + * @no-named-arguments */ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int ...$expression) { diff --git a/src/Builder/Aggregation/OrAggregation.php b/src/Builder/Aggregation/OrAggregation.php index 767ae251f..2f865c63d 100644 --- a/src/Builder/Aggregation/OrAggregation.php +++ b/src/Builder/Aggregation/OrAggregation.php @@ -20,14 +20,12 @@ class OrAggregation implements ResolvesToBool public const NAME = '$or'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** - * @no-named-arguments - * @param list ...$expression - */ + /** @param list ...$expression */ public array $expression; /** * @param ExpressionInterface|ResolvesToBool|bool|mixed ...$expression + * @no-named-arguments */ public function __construct(mixed ...$expression) { diff --git a/src/Builder/Aggregation/SetEqualsAggregation.php b/src/Builder/Aggregation/SetEqualsAggregation.php index b9f50ab8b..fb6318168 100644 --- a/src/Builder/Aggregation/SetEqualsAggregation.php +++ b/src/Builder/Aggregation/SetEqualsAggregation.php @@ -23,14 +23,12 @@ class SetEqualsAggregation implements ResolvesToBool public const NAME = '$setEquals'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** - * @no-named-arguments - * @param list> ...$expression - */ + /** @param list> ...$expression */ public array $expression; /** * @param BSONArray|PackedArray|ResolvesToArray|list ...$expression + * @no-named-arguments */ public function __construct(PackedArray|ResolvesToArray|BSONArray|array ...$expression) { diff --git a/src/Builder/Aggregation/SetIntersectionAggregation.php b/src/Builder/Aggregation/SetIntersectionAggregation.php index 8c3b702a1..cd7d54a32 100644 --- a/src/Builder/Aggregation/SetIntersectionAggregation.php +++ b/src/Builder/Aggregation/SetIntersectionAggregation.php @@ -22,14 +22,12 @@ class SetIntersectionAggregation implements ResolvesToArray public const NAME = '$setIntersection'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** - * @no-named-arguments - * @param list> ...$expression - */ + /** @param list> ...$expression */ public array $expression; /** * @param BSONArray|PackedArray|ResolvesToArray|list ...$expression + * @no-named-arguments */ public function __construct(PackedArray|ResolvesToArray|BSONArray|array ...$expression) { diff --git a/src/Builder/Aggregation/SetUnionAggregation.php b/src/Builder/Aggregation/SetUnionAggregation.php index ec7904b9d..4822dece7 100644 --- a/src/Builder/Aggregation/SetUnionAggregation.php +++ b/src/Builder/Aggregation/SetUnionAggregation.php @@ -22,14 +22,12 @@ class SetUnionAggregation implements ResolvesToArray public const NAME = '$setUnion'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** - * @no-named-arguments - * @param list> ...$expression - */ + /** @param list> ...$expression */ public array $expression; /** * @param BSONArray|PackedArray|ResolvesToArray|list ...$expression + * @no-named-arguments */ public function __construct(PackedArray|ResolvesToArray|BSONArray|array ...$expression) { diff --git a/src/Builder/Aggregation/StdDevPopAggregation.php b/src/Builder/Aggregation/StdDevPopAggregation.php index 166ec3631..357a3f047 100644 --- a/src/Builder/Aggregation/StdDevPopAggregation.php +++ b/src/Builder/Aggregation/StdDevPopAggregation.php @@ -24,14 +24,12 @@ class StdDevPopAggregation implements ResolvesToDouble, AccumulatorInterface public const NAME = '$stdDevPop'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** - * @no-named-arguments - * @param list ...$expression - */ + /** @param list ...$expression */ public array $expression; /** * @param Decimal128|Int64|ResolvesToNumber|float|int ...$expression + * @no-named-arguments */ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int ...$expression) { diff --git a/src/Builder/Aggregation/StdDevSampAggregation.php b/src/Builder/Aggregation/StdDevSampAggregation.php index 8787ca07c..044b2189e 100644 --- a/src/Builder/Aggregation/StdDevSampAggregation.php +++ b/src/Builder/Aggregation/StdDevSampAggregation.php @@ -24,14 +24,12 @@ class StdDevSampAggregation implements ResolvesToDouble, AccumulatorInterface public const NAME = '$stdDevSamp'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** - * @no-named-arguments - * @param list ...$expression - */ + /** @param list ...$expression */ public array $expression; /** * @param Decimal128|Int64|ResolvesToNumber|float|int ...$expression + * @no-named-arguments */ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int ...$expression) { diff --git a/src/Builder/Aggregation/SumAggregation.php b/src/Builder/Aggregation/SumAggregation.php index d1d04b8f2..10d4fbc19 100644 --- a/src/Builder/Aggregation/SumAggregation.php +++ b/src/Builder/Aggregation/SumAggregation.php @@ -22,14 +22,12 @@ class SumAggregation implements ResolvesToNumber, AccumulatorInterface public const NAME = '$sum'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** - * @no-named-arguments - * @param list ...$expression - */ + /** @param list ...$expression */ public array $expression; /** * @param Decimal128|Int64|ResolvesToNumber|float|int ...$expression + * @no-named-arguments */ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int ...$expression) { diff --git a/src/Builder/BuilderEncoder.php b/src/Builder/BuilderEncoder.php index c77d8a99c..7a33bb629 100644 --- a/src/Builder/BuilderEncoder.php +++ b/src/Builder/BuilderEncoder.php @@ -3,6 +3,7 @@ namespace MongoDB\Builder; use LogicException; +use MongoDB\Builder\Aggregation\AccumulatorInterface; use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\FieldPath; use MongoDB\Builder\Expression\Variable; @@ -14,6 +15,9 @@ use MongoDB\Exception\UnsupportedValueException; use stdClass; +use function array_key_first; +use function assert; +use function count; use function get_object_vars; use function is_array; use function sprintf; @@ -74,6 +78,8 @@ public function encode($value): stdClass|array|string return $this->encodeAsObject($value); case Encode::Group: + assert($value instanceof GroupStage); + return $this->encodeAsGroup($value); } @@ -117,13 +123,18 @@ private function encodeAsObject(ExpressionInterface|StageInterface|QueryInterfac */ private function encodeAsSingle(ExpressionInterface|StageInterface|QueryInterface $value): stdClass { - $result = []; foreach (get_object_vars($value) as $val) { $result = $this->recursiveEncode($val); - break; + + // The $sum accumulator is a unary operator + if ($value instanceof AccumulatorInterface && is_array($result) && count($result) === 1 && array_key_first($result) === 0) { + $result = $result[0]; + } + + return $this->wrap($value, $result); } - return $this->wrap($value, $result); + throw new LogicException(sprintf('Class "%s" does not have a single property.', $value::class)); } /** @@ -134,7 +145,7 @@ private function encodeAsGroup(GroupStage $value): stdClass $result = new stdClass(); $result->_id = $this->recursiveEncode($value->_id); - foreach ($value->field ?? [] as $key => $val) { + foreach (get_object_vars($value->field) as $key => $val) { $result->{$key} = $this->recursiveEncode($val); } diff --git a/src/Builder/Query/AllQuery.php b/src/Builder/Query/AllQuery.php index 01ff7bb28..bb41104ff 100644 --- a/src/Builder/Query/AllQuery.php +++ b/src/Builder/Query/AllQuery.php @@ -18,14 +18,12 @@ class AllQuery implements QueryInterface public const NAME = '$all'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** - * @no-named-arguments - * @param list ...$value - */ + /** @param list ...$value */ public array $value; /** * @param mixed ...$value + * @no-named-arguments */ public function __construct(mixed ...$value) { diff --git a/src/Builder/Query/AndQuery.php b/src/Builder/Query/AndQuery.php index 39d3489d9..dee936236 100644 --- a/src/Builder/Query/AndQuery.php +++ b/src/Builder/Query/AndQuery.php @@ -19,14 +19,12 @@ class AndQuery implements QueryInterface public const NAME = '$and'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** - * @no-named-arguments - * @param list ...$expression - */ + /** @param list ...$expression */ public array $expression; /** * @param QueryInterface|array|stdClass ...$expression + * @no-named-arguments */ public function __construct(QueryInterface|stdClass|array ...$expression) { diff --git a/src/Builder/Query/NorQuery.php b/src/Builder/Query/NorQuery.php index aa4833a33..2644a3032 100644 --- a/src/Builder/Query/NorQuery.php +++ b/src/Builder/Query/NorQuery.php @@ -19,14 +19,12 @@ class NorQuery implements QueryInterface public const NAME = '$nor'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** - * @no-named-arguments - * @param list ...$expression - */ + /** @param list ...$expression */ public array $expression; /** * @param QueryInterface|array|stdClass ...$expression + * @no-named-arguments */ public function __construct(QueryInterface|stdClass|array ...$expression) { diff --git a/src/Builder/Query/OrQuery.php b/src/Builder/Query/OrQuery.php index 3ca1f990c..082f7db31 100644 --- a/src/Builder/Query/OrQuery.php +++ b/src/Builder/Query/OrQuery.php @@ -19,14 +19,12 @@ class OrQuery implements QueryInterface public const NAME = '$or'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** - * @no-named-arguments - * @param list ...$expression - */ + /** @param list ...$expression */ public array $expression; /** * @param QueryInterface|array|stdClass ...$expression + * @no-named-arguments */ public function __construct(QueryInterface|stdClass|array ...$expression) { diff --git a/src/Builder/Query/Query.php b/src/Builder/Query/Query.php deleted file mode 100644 index 06643c99f..000000000 --- a/src/Builder/Query/Query.php +++ /dev/null @@ -1,26 +0,0 @@ -geometry = $geometry; - } -} diff --git a/src/Builder/Stage/Stage.php b/src/Builder/Stage/Stage.php deleted file mode 100644 index 0eec5bf01..000000000 --- a/src/Builder/Stage/Stage.php +++ /dev/null @@ -1,30 +0,0 @@ -expression = $expression; - } -} diff --git a/src/Builder/Stage/UnsetStage.php b/src/Builder/Stage/UnsetStage.php index 1e4af5329..0dfb5edc4 100644 --- a/src/Builder/Stage/UnsetStage.php +++ b/src/Builder/Stage/UnsetStage.php @@ -20,14 +20,12 @@ class UnsetStage implements StageInterface public const NAME = '$unset'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** - * @no-named-arguments - * @param list ...$field - */ + /** @param list ...$field */ public array $field; /** * @param FieldPath|non-empty-string ...$field + * @no-named-arguments */ public function __construct(FieldPath|string ...$field) { From 5733833c7274800da8b3f0bc09ae6ab857b766c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Fri, 6 Oct 2023 08:53:44 +0200 Subject: [PATCH 12/37] Case insensitive sort of methods --- generator/src/OperatorFactoryGenerator.php | 3 +- src/Builder/Aggregation.php | 76 +++++++++++----------- src/Builder/Query.php | 22 +++---- 3 files changed, 51 insertions(+), 50 deletions(-) diff --git a/generator/src/OperatorFactoryGenerator.php b/generator/src/OperatorFactoryGenerator.php index 96d47afb2..38cdc832b 100644 --- a/generator/src/OperatorFactoryGenerator.php +++ b/generator/src/OperatorFactoryGenerator.php @@ -16,6 +16,7 @@ use function rtrim; use function sprintf; use function str_replace; +use function strcasecmp; use function usort; final class OperatorFactoryGenerator extends OperatorGenerator @@ -35,7 +36,7 @@ private function createFactoryClass(GeneratorDefinition $definition): PhpNamespa // Pedantry requires methods to be ordered alphabetically $operators = $this->getOperators($definition); - usort($operators, fn (OperatorDefinition $a, OperatorDefinition $b) => $a->name <=> $b->name); + usort($operators, fn (OperatorDefinition $a, OperatorDefinition $b) => strcasecmp($a->name, $b->name)); foreach ($operators as $operator) { try { diff --git a/src/Builder/Aggregation.php b/src/Builder/Aggregation.php index b0a4a7e51..23c33de4a 100644 --- a/src/Builder/Aggregation.php +++ b/src/Builder/Aggregation.php @@ -2253,6 +2253,21 @@ public static function stdDevSamp( return new StdDevSampAggregation(...$expression); } + /** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/strcasecmp/ + * @param ResolvesToString|non-empty-string $expression1 + * @param ResolvesToString|non-empty-string $expression2 + */ + public static function strcasecmp( + ResolvesToString|string $expression1, + ResolvesToString|string $expression2, + ): StrcasecmpAggregation + { + return new StrcasecmpAggregation($expression1, $expression2); + } + /** * Returns the number of UTF-8 encoded bytes in a string. * @@ -2275,21 +2290,6 @@ public static function strLenCP(ResolvesToString|string $expression): StrLenCPAg return new StrLenCPAggregation($expression); } - /** - * 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. - * - * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/strcasecmp/ - * @param ResolvesToString|non-empty-string $expression1 - * @param ResolvesToString|non-empty-string $expression2 - */ - public static function strcasecmp( - ResolvesToString|string $expression1, - ResolvesToString|string $expression2, - ): StrcasecmpAggregation - { - return new StrcasecmpAggregation($expression1, $expression2); - } - /** * Deprecated. Use $substrBytes or $substrCP. * @@ -2506,29 +2506,6 @@ public static function toObjectId(mixed $expression): ToObjectIdAggregation return new ToObjectIdAggregation($expression); } - /** - * Converts value to a string. - * New in version 4.0. - * - * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toString/ - * @param ExpressionInterface|mixed $expression - */ - public static function toString(mixed $expression): ToStringAggregation - { - return new ToStringAggregation($expression); - } - - /** - * Converts a string to uppercase. Accepts a single argument expression. - * - * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toUpper/ - * @param ResolvesToString|non-empty-string $expression - */ - public static function toUpper(ResolvesToString|string $expression): ToUpperAggregation - { - return new ToUpperAggregation($expression); - } - /** * Returns the top element within a group according to the specified sort order. * New in version 5.2. @@ -2560,6 +2537,29 @@ public static function topN(Int64|ResolvesToInt|int $n, stdClass|array $sortBy, return new TopNAggregation($n, $sortBy, $output); } + /** + * Converts value to a string. + * New in version 4.0. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toString/ + * @param ExpressionInterface|mixed $expression + */ + public static function toString(mixed $expression): ToStringAggregation + { + return new ToStringAggregation($expression); + } + + /** + * Converts a string to uppercase. Accepts a single argument expression. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toUpper/ + * @param ResolvesToString|non-empty-string $expression + */ + public static function toUpper(ResolvesToString|string $expression): ToUpperAggregation + { + return new ToUpperAggregation($expression); + } + /** * Removes whitespace or the specified characters from the beginning and end of a string. * New in version 4.0. diff --git a/src/Builder/Query.php b/src/Builder/Query.php index 1efa74fb5..adfa20704 100644 --- a/src/Builder/Query.php +++ b/src/Builder/Query.php @@ -231,17 +231,6 @@ public static function geoIntersects(stdClass|array $geometry): GeoIntersectsQue return new GeoIntersectsQuery($geometry); } - /** - * Selects geometries within a bounding GeoJSON geometry. The 2dsphere and 2d indexes support $geoWithin. - * - * @see https://www.mongodb.com/docs/manual/reference/operator/query/geoWithin/ - * @param array|stdClass $geometry - */ - public static function geoWithin(stdClass|array $geometry): GeoWithinQuery - { - return new GeoWithinQuery($geometry); - } - /** * Specifies a geometry in GeoJSON format to geospatial query operators. * @@ -259,6 +248,17 @@ public static function geometry( return new GeometryQuery($type, $coordinates, $crs); } + /** + * Selects geometries within a bounding GeoJSON geometry. The 2dsphere and 2d indexes support $geoWithin. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/query/geoWithin/ + * @param array|stdClass $geometry + */ + public static function geoWithin(stdClass|array $geometry): GeoWithinQuery + { + return new GeoWithinQuery($geometry); + } + /** * Matches values that are greater than a specified value. * From 6faa7f8ea5e2b944ece5dfaa90ed66bed13e5e6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Fri, 6 Oct 2023 08:56:16 +0200 Subject: [PATCH 13/37] Fix $sum accumulator test --- tests/Builder/BuilderEncoderTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/Builder/BuilderEncoderTest.php b/tests/Builder/BuilderEncoderTest.php index 77f5c367f..1142b119f 100644 --- a/tests/Builder/BuilderEncoderTest.php +++ b/tests/Builder/BuilderEncoderTest.php @@ -83,8 +83,7 @@ public function testPerformCount(): void [ '$group' => [ '_id' => null, - // same as 'count' => ['$sum' => 1], - 'count' => ['$sum' => [1]], + 'count' => ['$sum' => 1], ], ], ]; From 27c9f21b67b1e8db7b9dcc00b38384556f25750b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Fri, 6 Oct 2023 09:03:11 +0200 Subject: [PATCH 14/37] Ignore psalm issues --- psalm-baseline.xml | 101 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 94 insertions(+), 7 deletions(-) diff --git a/psalm-baseline.xml b/psalm-baseline.xml index a06fddc08..cac6e7790 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,5 +1,5 @@ - + decrypt($document->encryptedField)]]> @@ -46,6 +46,33 @@ stdClass + + + $array + $document + $expression + $expression + $expression + $expression + $expression + $expression + $expression + $expression + $expression + $expression + $expression + $expression + $expression + $expression + $expression + $expression + $expression + $expression + $expression + $expression + $expression + + EncodeIfSupported @@ -57,17 +84,63 @@ $encoded[] - $expr - $expression - $field - $key - $key - $query + $result $result $result[] $val $val + $val + $val + $val + $value[$key] + + + + + $expression + $expression + $expression + $value + + + + + $field + + + + + $value + + $expression + + + + + $facet + + + + + $field + + + + + $value + + + $specification + + + + + $value + + + $field + @@ -75,6 +148,9 @@ + + __toString + @@ -88,6 +164,9 @@ + + __toString + $options @@ -104,6 +183,11 @@ + + + __toString + + @@ -210,6 +294,9 @@ + + __toString + $key From 502ed6bedcb7129c262a270e63482be1b3acd666 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Fri, 6 Oct 2023 09:31:40 +0200 Subject: [PATCH 15/37] Improve doc for object function --- src/functions.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/functions.php b/src/functions.php index 4f438ab45..6394c7114 100644 --- a/src/functions.php +++ b/src/functions.php @@ -61,6 +61,11 @@ function add_logger(LoggerInterface $logger): void /** * Create a new stdClass instance with the provided properties. + * Use named arguments to specify the property names. + * object( property1: value1, property2: value2 ) + * + * If property names contain a dot or a dollar characters, use array unpacking syntax. + * object( ...[ 'author.name' => 1, 'array.$' => 1 ] ) * * @psalm-suppress MoreSpecificReturnType * @psalm-suppress LessSpecificReturnStatement From 3f175e7d9db8c0ca94f50b423512275a7a9aaffd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Fri, 6 Oct 2023 09:39:03 +0200 Subject: [PATCH 16/37] Fix methods order --- src/Builder/BuilderEncoder.php | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/Builder/BuilderEncoder.php b/src/Builder/BuilderEncoder.php index 7a33bb629..bbcd20780 100644 --- a/src/Builder/BuilderEncoder.php +++ b/src/Builder/BuilderEncoder.php @@ -86,6 +86,9 @@ public function encode($value): stdClass|array|string throw new LogicException(sprintf('Class "%s" does not have a valid ENCODE constant.', $value::class)); } + /** + * Encode the value as an array of properties, in the order they are defined in the class. + */ private function encodeAsArray(ExpressionInterface|StageInterface|QueryInterface $value): stdClass { $result = []; @@ -103,6 +106,21 @@ private function encodeAsArray(ExpressionInterface|StageInterface|QueryInterface return $this->wrap($value, $result); } + /** + * $group stage have a specific encoding because the _id argument is required and others are variadic + */ + private function encodeAsGroup(GroupStage $value): stdClass + { + $result = new stdClass(); + $result->_id = $this->recursiveEncode($value->_id); + + foreach (get_object_vars($value->field) as $key => $val) { + $result->{$key} = $this->recursiveEncode($val); + } + + return $this->wrap($value, $result); + } + private function encodeAsObject(ExpressionInterface|StageInterface|QueryInterface $value): stdClass { $result = new stdClass(); @@ -137,21 +155,6 @@ private function encodeAsSingle(ExpressionInterface|StageInterface|QueryInterfac throw new LogicException(sprintf('Class "%s" does not have a single property.', $value::class)); } - /** - * $group stage have a specific encoding because the _id argument is required and others are variadic - */ - private function encodeAsGroup(GroupStage $value): stdClass - { - $result = new stdClass(); - $result->_id = $this->recursiveEncode($value->_id); - - foreach (get_object_vars($value->field) as $key => $val) { - $result->{$key} = $this->recursiveEncode($val); - } - - return $this->wrap($value, $result); - } - /** * Nested arrays and objects must be encoded recursively. */ From d89d024582df51a425155174660c72e74992cdf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Fri, 6 Oct 2023 13:57:53 +0200 Subject: [PATCH 17/37] Remove tests on PHP 8.0 --- .github/workflows/benchmark.yml | 1 - .github/workflows/tests.yml | 10 +++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml index 386ceb95c..9306bfb27 100644 --- a/.github/workflows/benchmark.yml +++ b/.github/workflows/benchmark.yml @@ -5,7 +5,6 @@ on: branches: - "v*.*" - "master" - #- "feature/*" paths-ignore: - "docs/**" push: diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index b47747736..7ef1471d8 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -39,27 +39,27 @@ jobs: - "server" include: - os: "ubuntu-20.04" - php-version: "8.0" + php-version: "8.1" mongodb-version: "6.0" driver-version: "mongodb/mongo-php-driver@master" topology: "replica_set" - os: "ubuntu-20.04" - php-version: "8.0" + php-version: "8.1" mongodb-version: "6.0" driver-version: "mongodb/mongo-php-driver@master" topology: "sharded_cluster" - os: "ubuntu-20.04" - php-version: "8.0" + php-version: "8.1" mongodb-version: "5.0" driver-version: "mongodb/mongo-php-driver@master" topology: "server" - os: "ubuntu-20.04" - php-version: "8.0" + php-version: "8.1" mongodb-version: "4.4" driver-version: "mongodb/mongo-php-driver@master" topology: "replica_set" - os: "ubuntu-20.04" - php-version: "8.0" + php-version: "8.1" mongodb-version: "4.4" driver-version: "mongodb/mongo-php-driver@master" topology: "sharded_cluster" From 2129f88e1d39853b11ecd7845fc5856a767fba41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Fri, 6 Oct 2023 14:06:28 +0200 Subject: [PATCH 18/37] Rename mixed to any and remove incorrect generic type from list --- .../config/aggregation-operators/literal.yaml | 2 +- generator/config/expressions.php | 3 +- generator/config/query-operators/all.yaml | 2 +- generator/config/query-operators/eq.yaml | 2 +- generator/config/query-operators/gt.yaml | 2 +- generator/config/query-operators/gte.yaml | 2 +- generator/config/query-operators/in.yaml | 2 +- generator/config/query-operators/lt.yaml | 2 +- generator/config/query-operators/lte.yaml | 2 +- generator/config/query-operators/ne.yaml | 2 +- generator/config/query-operators/nin.yaml | 2 +- generator/src/OperatorGenerator.php | 2 +- src/Builder/Aggregation.php | 62 +++++++++---------- .../Aggregation/AccumulatorAggregation.php | 8 +-- .../AllElementsTrueAggregation.php | 6 +- .../Aggregation/AnyElementTrueAggregation.php | 4 +- .../Aggregation/ArrayElemAtAggregation.php | 4 +- .../Aggregation/ArrayToObjectAggregation.php | 4 +- .../Aggregation/ConcatArraysAggregation.php | 6 +- src/Builder/Aggregation/FilterAggregation.php | 4 +- src/Builder/Aggregation/FirstNAggregation.php | 4 +- .../Aggregation/FunctionAggregation.php | 4 +- src/Builder/Aggregation/InAggregation.php | 4 +- src/Builder/Aggregation/LastNAggregation.php | 4 +- src/Builder/Aggregation/MapAggregation.php | 4 +- src/Builder/Aggregation/MaxNAggregation.php | 4 +- src/Builder/Aggregation/MinNAggregation.php | 4 +- .../Aggregation/PercentileAggregation.php | 4 +- src/Builder/Aggregation/ReduceAggregation.php | 4 +- .../Aggregation/ReverseArrayAggregation.php | 4 +- .../Aggregation/SetDifferenceAggregation.php | 8 +-- .../Aggregation/SetEqualsAggregation.php | 6 +- .../SetIntersectionAggregation.php | 6 +- .../Aggregation/SetIsSubsetAggregation.php | 8 +-- .../Aggregation/SetUnionAggregation.php | 6 +- src/Builder/Aggregation/SizeAggregation.php | 4 +- src/Builder/Aggregation/SliceAggregation.php | 4 +- .../Aggregation/SortArrayAggregation.php | 4 +- src/Builder/Aggregation/SwitchAggregation.php | 4 +- src/Builder/Aggregation/ZipAggregation.php | 8 +-- src/Builder/Query.php | 28 ++++----- src/Builder/Query/BitsAllClearQuery.php | 4 +- src/Builder/Query/BitsAllSetQuery.php | 4 +- src/Builder/Query/BitsAnyClearQuery.php | 4 +- src/Builder/Query/BitsAnySetQuery.php | 4 +- src/Builder/Query/BoxQuery.php | 4 +- src/Builder/Query/CenterQuery.php | 4 +- src/Builder/Query/CenterSphereQuery.php | 4 +- src/Builder/Query/GeometryQuery.php | 4 +- src/Builder/Query/InQuery.php | 14 +++-- src/Builder/Query/NinQuery.php | 14 +++-- src/Builder/Query/PolygonQuery.php | 4 +- src/Builder/Query/TypeQuery.php | 4 +- src/Builder/Stage.php | 16 ++--- src/Builder/Stage/BucketStage.php | 4 +- src/Builder/Stage/DensifyStage.php | 4 +- src/Builder/Stage/DocumentsStage.php | 4 +- src/Builder/Stage/FillStage.php | 4 +- src/Builder/Stage/GraphLookupStage.php | 4 +- src/Builder/Stage/ListLocalSessionsStage.php | 4 +- src/Builder/Stage/ListSessionsStage.php | 4 +- src/Builder/Stage/MergeStage.php | 4 +- 62 files changed, 188 insertions(+), 177 deletions(-) diff --git a/generator/config/aggregation-operators/literal.yaml b/generator/config/aggregation-operators/literal.yaml index 3ec2d79c9..e7ae6ff5b 100644 --- a/generator/config/aggregation-operators/literal.yaml +++ b/generator/config/aggregation-operators/literal.yaml @@ -12,6 +12,6 @@ arguments: - name: value type: - - mixed + - 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/expressions.php b/generator/config/expressions.php index 54a0a198c..f1b6d1c60 100644 --- a/generator/config/expressions.php +++ b/generator/config/expressions.php @@ -24,7 +24,7 @@ function typeFieldPath(string $resolvesTo): array } return [ - 'mixed' => ['scalar' => true, 'types' => ['mixed']], + 'any' => ['scalar' => true, 'types' => ['mixed']], 'null' => ['scalar' => true, 'types' => ['null']], 'int' => ['scalar' => true, 'types' => ['int', BSON\Int64::class]], 'double' => ['scalar' => true, 'types' => ['int', BSON\Int64::class, 'float']], @@ -35,7 +35,6 @@ function typeFieldPath(string $resolvesTo): array 'bool' => ['scalar' => true, 'types' => ['bool']], 'object' => ['scalar' => true, 'types' => ['array', stdClass::class, BSON\Document::class, BSON\Serializable::class]], 'Regex' => ['scalar' => true, 'types' => [BSON\Regex::class]], - 'Constant' => ['scalar' => true, 'types' => ['mixed']], 'Binary' => ['scalar' => true, 'types' => ['string', BSON\Binary::class]], AccumulatorInterface::class => ['scalar' => true, 'types' => [AccumulatorInterface::class]], diff --git a/generator/config/query-operators/all.yaml b/generator/config/query-operators/all.yaml index 3235e1046..24c7983aa 100644 --- a/generator/config/query-operators/all.yaml +++ b/generator/config/query-operators/all.yaml @@ -12,5 +12,5 @@ arguments: - name: value type: - - mixed + - any variadic: array diff --git a/generator/config/query-operators/eq.yaml b/generator/config/query-operators/eq.yaml index 44343af19..537ad8fce 100644 --- a/generator/config/query-operators/eq.yaml +++ b/generator/config/query-operators/eq.yaml @@ -12,4 +12,4 @@ arguments: - name: value type: - - Constant + - any diff --git a/generator/config/query-operators/gt.yaml b/generator/config/query-operators/gt.yaml index 4043d7d57..247933a61 100644 --- a/generator/config/query-operators/gt.yaml +++ b/generator/config/query-operators/gt.yaml @@ -12,4 +12,4 @@ arguments: - name: value type: - - Constant + - any diff --git a/generator/config/query-operators/gte.yaml b/generator/config/query-operators/gte.yaml index 6125656c4..4de2132ca 100644 --- a/generator/config/query-operators/gte.yaml +++ b/generator/config/query-operators/gte.yaml @@ -12,4 +12,4 @@ arguments: - name: value type: - - Constant + - any diff --git a/generator/config/query-operators/in.yaml b/generator/config/query-operators/in.yaml index 53855e0d5..67d1d989a 100644 --- a/generator/config/query-operators/in.yaml +++ b/generator/config/query-operators/in.yaml @@ -12,4 +12,4 @@ arguments: - name: value type: - - Constant + - array diff --git a/generator/config/query-operators/lt.yaml b/generator/config/query-operators/lt.yaml index b2430688e..5e45606f3 100644 --- a/generator/config/query-operators/lt.yaml +++ b/generator/config/query-operators/lt.yaml @@ -12,4 +12,4 @@ arguments: - name: value type: - - Constant + - any diff --git a/generator/config/query-operators/lte.yaml b/generator/config/query-operators/lte.yaml index 35ac93ad9..aee5b71d6 100644 --- a/generator/config/query-operators/lte.yaml +++ b/generator/config/query-operators/lte.yaml @@ -12,4 +12,4 @@ arguments: - name: value type: - - Constant + - any diff --git a/generator/config/query-operators/ne.yaml b/generator/config/query-operators/ne.yaml index b8510c57c..73697c030 100644 --- a/generator/config/query-operators/ne.yaml +++ b/generator/config/query-operators/ne.yaml @@ -12,4 +12,4 @@ arguments: - name: value type: - - Constant + - any diff --git a/generator/config/query-operators/nin.yaml b/generator/config/query-operators/nin.yaml index adec8b789..695e740ca 100644 --- a/generator/config/query-operators/nin.yaml +++ b/generator/config/query-operators/nin.yaml @@ -12,4 +12,4 @@ arguments: - name: value type: - - Constant + - array diff --git a/generator/src/OperatorGenerator.php b/generator/src/OperatorGenerator.php index f00120e0a..cfab6e463 100644 --- a/generator/src/OperatorGenerator.php +++ b/generator/src/OperatorGenerator.php @@ -129,7 +129,7 @@ final protected function generateExpressionTypes(ArgumentDefinition $arg): objec $listCheck = true; $nativeTypes[$key] = 'array'; // @todo allow to specify the type of the elements in the list - $docTypes[$key] = 'list'; + $docTypes[$key] = 'list'; $use[] = '\\' . ExpressionInterface::class; continue; } diff --git a/src/Builder/Aggregation.php b/src/Builder/Aggregation.php index 23c33de4a..20e7dd95e 100644 --- a/src/Builder/Aggregation.php +++ b/src/Builder/Aggregation.php @@ -226,10 +226,10 @@ public static function abs(Decimal128|Int64|ResolvesToNumber|float|int $value): * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/accumulator/ * @param non-empty-string $init 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. * @param non-empty-string $accumulate 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. - * @param BSONArray|PackedArray|ResolvesToArray|list $accumulateArgs Arguments passed to the accumulate function. You can use accumulateArgs to specify what field value(s) to pass to the accumulate function. + * @param BSONArray|PackedArray|ResolvesToArray|list $accumulateArgs Arguments passed to the accumulate function. You can use accumulateArgs to specify what field value(s) to pass to the accumulate function. * @param non-empty-string $merge 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. * @param non-empty-string $lang The language used in the $accumulator code. - * @param BSONArray|Optional|PackedArray|ResolvesToArray|list $initArgs Arguments passed to the init function. + * @param BSONArray|Optional|PackedArray|ResolvesToArray|list $initArgs Arguments passed to the init function. * @param Optional|non-empty-string $finalize Function used to update the result of the accumulation. */ public static function accumulator( @@ -300,7 +300,7 @@ public static function addToSet(mixed $expression): AddToSetAggregation * Returns true if no element of a set evaluates to false, otherwise, returns false. Accepts a single argument expression. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/allElementsTrue/ - * @param BSONArray|PackedArray|ResolvesToArray|list ...$expression + * @param BSONArray|PackedArray|ResolvesToArray|list ...$expression */ public static function allElementsTrue( PackedArray|ResolvesToArray|BSONArray|array ...$expression, @@ -324,7 +324,7 @@ public static function and(mixed ...$expression): AndAggregation * Returns true if any elements of a set evaluate to true; otherwise, returns false. Accepts a single argument expression. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/anyElementTrue/ - * @param BSONArray|PackedArray|ResolvesToArray|list $expression + * @param BSONArray|PackedArray|ResolvesToArray|list $expression */ public static function anyElementTrue( PackedArray|ResolvesToArray|BSONArray|array $expression, @@ -337,7 +337,7 @@ public static function anyElementTrue( * Returns the element at the specified array index. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/arrayElemAt/ - * @param BSONArray|PackedArray|ResolvesToArray|list $array + * @param BSONArray|PackedArray|ResolvesToArray|list $array * @param Int64|ResolvesToInt|int $idx */ public static function arrayElemAt( @@ -352,7 +352,7 @@ public static function arrayElemAt( * Converts an array of key value pairs to a document. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/arrayToObject/ - * @param BSONArray|PackedArray|ResolvesToArray|list $array + * @param BSONArray|PackedArray|ResolvesToArray|list $array */ public static function arrayToObject(PackedArray|ResolvesToArray|BSONArray|array $array): ArrayToObjectAggregation { @@ -586,7 +586,7 @@ public static function concat(ResolvesToString|string ...$expression): ConcatAgg * Concatenates arrays to return the concatenated array. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/concatArrays/ - * @param BSONArray|PackedArray|ResolvesToArray|list ...$array + * @param BSONArray|PackedArray|ResolvesToArray|list ...$array */ public static function concatArrays( PackedArray|ResolvesToArray|BSONArray|array ...$array, @@ -1038,7 +1038,7 @@ public static function expMovingAvg( * Selects a subset of the array to return an array with only the elements that match the filter condition. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/filter/ - * @param BSONArray|PackedArray|ResolvesToArray|list $input + * @param BSONArray|PackedArray|ResolvesToArray|list $input * @param ResolvesToBool|bool $cond 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. * @param Optional|non-empty-string $as 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. * @param Int64|Optional|ResolvesToInt|int $limit 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. @@ -1070,7 +1070,7 @@ public static function first(mixed $expression): FirstAggregation * Returns a specified number of elements from the beginning of an array. Distinct from the $firstN accumulator. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/firstN-array-element/ - * @param BSONArray|PackedArray|ResolvesToArray|list $input An expression that resolves to the array from which to return n elements. + * @param BSONArray|PackedArray|ResolvesToArray|list $input An expression that resolves to the array from which to return n elements. * @param Int64|ResolvesToInt|int $n An expression that resolves to a positive integer. The integer specifies the number of array elements that $firstN returns. */ public static function firstN( @@ -1098,7 +1098,7 @@ public static function floor(Decimal128|Int64|ResolvesToNumber|float|int $expres * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/function/ * @param non-empty-string $body The function definition. You can specify the function definition as either BSON type Code or String. - * @param BSONArray|PackedArray|list $args Arguments passed to the function body. If the body function does not take an argument, you can specify an empty array [ ]. + * @param BSONArray|PackedArray|list $args Arguments passed to the function body. If the body function does not take an argument, you can specify an empty array [ ]. * @param non-empty-string $lang */ public static function function( @@ -1180,7 +1180,7 @@ public static function ifNull(mixed ...$expression): IfNullAggregation * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/in/ * @param ExpressionInterface|mixed $expression Any valid expression expression. - * @param BSONArray|PackedArray|ResolvesToArray|list $array Any valid expression that resolves to an array. + * @param BSONArray|PackedArray|ResolvesToArray|list $array Any valid expression that resolves to an array. */ public static function in(mixed $expression, PackedArray|ResolvesToArray|BSONArray|array $array): InAggregation { @@ -1358,7 +1358,7 @@ public static function last(mixed $expression): LastAggregation * Returns a specified number of elements from the end of an array. Distinct from the $lastN accumulator. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/lastN/ - * @param BSONArray|PackedArray|ResolvesToArray|list $input An expression that resolves to the array from which to return n elements. + * @param BSONArray|PackedArray|ResolvesToArray|list $input An expression that resolves to the array from which to return n elements. * @param Int64|ResolvesToInt|int $n An expression that resolves to a positive integer. The integer specifies the number of array elements that $firstN returns. */ public static function lastN( @@ -1504,7 +1504,7 @@ public static function ltrim( * Applies a subexpression to each element of an array and returns the array of resulting values in order. Accepts named parameters. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/map/ - * @param BSONArray|PackedArray|ResolvesToArray|list $input An expression that resolves to an array. + * @param BSONArray|PackedArray|ResolvesToArray|list $input An expression that resolves to an array. * @param ExpressionInterface|mixed $in 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. * @param Optional|ResolvesToString|non-empty-string $as 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. */ @@ -1533,7 +1533,7 @@ public static function max(mixed ...$expression): MaxAggregation * Returns the n largest values in an array. Distinct from the $maxN accumulator. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/maxN-array-element/ - * @param BSONArray|PackedArray|ResolvesToArray|list $input An expression that resolves to the array from which to return the maximal n elements. + * @param BSONArray|PackedArray|ResolvesToArray|list $input An expression that resolves to the array from which to return the maximal n elements. * @param Int64|ResolvesToInt|int $n An expression that resolves to a positive integer. The integer specifies the number of array elements that $maxN returns. */ public static function maxN( @@ -1619,7 +1619,7 @@ public static function min(mixed ...$expression): MinAggregation * Returns the n smallest values in an array. Distinct from the $minN accumulator. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/minN-array-element/ - * @param BSONArray|PackedArray|ResolvesToArray|list $input An expression that resolves to the array from which to return the maximal n elements. + * @param BSONArray|PackedArray|ResolvesToArray|list $input An expression that resolves to the array from which to return the maximal n elements. * @param Int64|ResolvesToInt|int $n An expression that resolves to a positive integer. The integer specifies the number of array elements that $maxN returns. */ public static function minN( @@ -1747,7 +1747,7 @@ public static function or(mixed ...$expression): OrAggregation * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/percentile/ * @param Decimal128|Int64|ResolvesToNumber|float|int $input $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. - * @param BSONArray|PackedArray|ResolvesToArray|list $p $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. + * @param BSONArray|PackedArray|ResolvesToArray|list $p $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. * @param non-empty-string $method The method that mongod uses to calculate the percentile value. The method must be 'approximate'. */ @@ -1842,7 +1842,7 @@ public static function rank(): RankAggregation * Applies an expression to each element in an array and combines them into a single value. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/reduce/ - * @param BSONArray|PackedArray|ResolvesToArray|list $input Can be any valid expression that resolves to an array. + * @param BSONArray|PackedArray|ResolvesToArray|list $input 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. * @param ExpressionInterface|mixed $initialValue The initial cumulative value set before in is applied to the first element of the input array. @@ -1955,7 +1955,7 @@ public static function replaceOne( * Returns an array with the elements in reverse order. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/reverseArray/ - * @param BSONArray|PackedArray|ResolvesToArray|list $expression The argument can be any valid expression as long as it resolves to an array. + * @param BSONArray|PackedArray|ResolvesToArray|list $expression The argument can be any valid expression as long as it resolves to an array. */ public static function reverseArray( PackedArray|ResolvesToArray|BSONArray|array $expression, @@ -2028,8 +2028,8 @@ public static function second( * 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. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/setDifference/ - * @param BSONArray|PackedArray|ResolvesToArray|list $expression1 The arguments can be any valid expression as long as they each resolve to an array. - * @param BSONArray|PackedArray|ResolvesToArray|list $expression2 The arguments can be any valid expression as long as they each resolve to an array. + * @param BSONArray|PackedArray|ResolvesToArray|list $expression1 The arguments can be any valid expression as long as they each resolve to an array. + * @param BSONArray|PackedArray|ResolvesToArray|list $expression2 The arguments can be any valid expression as long as they each resolve to an array. */ public static function setDifference( PackedArray|ResolvesToArray|BSONArray|array $expression1, @@ -2043,7 +2043,7 @@ public static function setDifference( * Returns true if the input sets have the same distinct elements. Accepts two or more argument expressions. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/setEquals/ - * @param BSONArray|PackedArray|ResolvesToArray|list ...$expression + * @param BSONArray|PackedArray|ResolvesToArray|list ...$expression */ public static function setEquals(PackedArray|ResolvesToArray|BSONArray|array ...$expression): SetEqualsAggregation { @@ -2073,7 +2073,7 @@ public static function setField( * Returns a set with elements that appear in all of the input sets. Accepts any number of argument expressions. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/setIntersection/ - * @param BSONArray|PackedArray|ResolvesToArray|list ...$expression + * @param BSONArray|PackedArray|ResolvesToArray|list ...$expression */ public static function setIntersection( PackedArray|ResolvesToArray|BSONArray|array ...$expression, @@ -2086,8 +2086,8 @@ public static function setIntersection( * 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. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/setIsSubset/ - * @param BSONArray|PackedArray|ResolvesToArray|list $expression1 - * @param BSONArray|PackedArray|ResolvesToArray|list $expression2 + * @param BSONArray|PackedArray|ResolvesToArray|list $expression1 + * @param BSONArray|PackedArray|ResolvesToArray|list $expression2 */ public static function setIsSubset( PackedArray|ResolvesToArray|BSONArray|array $expression1, @@ -2101,7 +2101,7 @@ public static function setIsSubset( * Returns a set with elements that appear in any of the input sets. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/setUnion/ - * @param BSONArray|PackedArray|ResolvesToArray|list ...$expression + * @param BSONArray|PackedArray|ResolvesToArray|list ...$expression */ public static function setUnion(PackedArray|ResolvesToArray|BSONArray|array ...$expression): SetUnionAggregation { @@ -2156,7 +2156,7 @@ public static function sinh(Decimal128|Int64|ResolvesToNumber|float|int $express * Returns the number of elements in the array. Accepts a single expression as argument. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/size/ - * @param BSONArray|PackedArray|ResolvesToArray|list $expression The argument for $size can be any expression as long as it resolves to an array. + * @param BSONArray|PackedArray|ResolvesToArray|list $expression The argument for $size can be any expression as long as it resolves to an array. */ public static function size(PackedArray|ResolvesToArray|BSONArray|array $expression): SizeAggregation { @@ -2167,7 +2167,7 @@ public static function size(PackedArray|ResolvesToArray|BSONArray|array $express * Returns a subset of an array. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/slice/ - * @param BSONArray|PackedArray|ResolvesToArray|list $expression Any valid expression as long as it resolves to an array. + * @param BSONArray|PackedArray|ResolvesToArray|list $expression Any valid expression as long as it resolves to an array. * @param Int64|ResolvesToInt|int $n 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. @@ -2188,7 +2188,7 @@ public static function slice( * Sorts the elements of an array. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/sortArray/ - * @param BSONArray|PackedArray|ResolvesToArray|list $input The array to be sorted. + * @param BSONArray|PackedArray|ResolvesToArray|list $input The array to be sorted. * @param array|stdClass $sortBy The document specifies a sort ordering. */ public static function sortArray( @@ -2372,7 +2372,7 @@ public static function sum(Decimal128|Int64|ResolvesToNumber|float|int ...$expre * 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. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/switch/ - * @param BSONArray|PackedArray|list $branches An array of control branch documents. Each branch is a document with the following fields: + * @param BSONArray|PackedArray|list $branches 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. @@ -2679,12 +2679,12 @@ public static function year( * Merge two arrays together. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/zip/ - * @param BSONArray|PackedArray|ResolvesToArray|list $inputs An array of expressions that resolve to arrays. The elements of these input arrays combine to form the arrays of the output array. + * @param BSONArray|PackedArray|ResolvesToArray|list $inputs 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. * @param bool $useLongestLength 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. - * @param BSONArray|PackedArray|list $defaults 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. + * @param BSONArray|PackedArray|list $defaults 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. */ diff --git a/src/Builder/Aggregation/AccumulatorAggregation.php b/src/Builder/Aggregation/AccumulatorAggregation.php index 0385b514a..90012e27e 100644 --- a/src/Builder/Aggregation/AccumulatorAggregation.php +++ b/src/Builder/Aggregation/AccumulatorAggregation.php @@ -30,7 +30,7 @@ class AccumulatorAggregation implements AccumulatorInterface /** @param non-empty-string $accumulate 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. */ public string $accumulate; - /** @param BSONArray|PackedArray|ResolvesToArray|list $accumulateArgs Arguments passed to the accumulate function. You can use accumulateArgs to specify what field value(s) to pass to the accumulate function. */ + /** @param BSONArray|PackedArray|ResolvesToArray|list $accumulateArgs Arguments passed to the accumulate function. You can use accumulateArgs to specify what field value(s) to pass to the accumulate function. */ public PackedArray|ResolvesToArray|BSONArray|array $accumulateArgs; /** @param non-empty-string $merge 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. */ @@ -39,7 +39,7 @@ class AccumulatorAggregation implements AccumulatorInterface /** @param non-empty-string $lang The language used in the $accumulator code. */ public string $lang; - /** @param BSONArray|Optional|PackedArray|ResolvesToArray|list $initArgs Arguments passed to the init function. */ + /** @param BSONArray|Optional|PackedArray|ResolvesToArray|list $initArgs Arguments passed to the init function. */ public PackedArray|ResolvesToArray|Optional|BSONArray|array $initArgs; /** @param Optional|non-empty-string $finalize Function used to update the result of the accumulation. */ @@ -48,10 +48,10 @@ class AccumulatorAggregation implements AccumulatorInterface /** * @param non-empty-string $init 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. * @param non-empty-string $accumulate 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. - * @param BSONArray|PackedArray|ResolvesToArray|list $accumulateArgs Arguments passed to the accumulate function. You can use accumulateArgs to specify what field value(s) to pass to the accumulate function. + * @param BSONArray|PackedArray|ResolvesToArray|list $accumulateArgs Arguments passed to the accumulate function. You can use accumulateArgs to specify what field value(s) to pass to the accumulate function. * @param non-empty-string $merge 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. * @param non-empty-string $lang The language used in the $accumulator code. - * @param BSONArray|Optional|PackedArray|ResolvesToArray|list $initArgs Arguments passed to the init function. + * @param BSONArray|Optional|PackedArray|ResolvesToArray|list $initArgs Arguments passed to the init function. * @param Optional|non-empty-string $finalize Function used to update the result of the accumulation. */ public function __construct( diff --git a/src/Builder/Aggregation/AllElementsTrueAggregation.php b/src/Builder/Aggregation/AllElementsTrueAggregation.php index d30c03f53..20f8c549b 100644 --- a/src/Builder/Aggregation/AllElementsTrueAggregation.php +++ b/src/Builder/Aggregation/AllElementsTrueAggregation.php @@ -23,11 +23,11 @@ class AllElementsTrueAggregation implements ResolvesToBool public const NAME = '$allElementsTrue'; public const ENCODE = \MongoDB\Builder\Encode::Array; - /** @param list> ...$expression */ + /** @param list ...$expression */ public array $expression; /** - * @param BSONArray|PackedArray|ResolvesToArray|list ...$expression + * @param BSONArray|PackedArray|ResolvesToArray|list ...$expression * @no-named-arguments */ public function __construct(PackedArray|ResolvesToArray|BSONArray|array ...$expression) @@ -36,7 +36,7 @@ public function __construct(PackedArray|ResolvesToArray|BSONArray|array ...$expr throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); } if (! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression arguments to be a list of BSONArray|PackedArray|ResolvesToArray|list, named arguments are not supported'); + throw new \InvalidArgumentException('Expected $expression arguments to be a list of BSONArray|PackedArray|ResolvesToArray|list, named arguments are not supported'); } $this->expression = $expression; } diff --git a/src/Builder/Aggregation/AnyElementTrueAggregation.php b/src/Builder/Aggregation/AnyElementTrueAggregation.php index 070266a95..e7d6aa639 100644 --- a/src/Builder/Aggregation/AnyElementTrueAggregation.php +++ b/src/Builder/Aggregation/AnyElementTrueAggregation.php @@ -23,11 +23,11 @@ class AnyElementTrueAggregation implements ResolvesToBool public const NAME = '$anyElementTrue'; public const ENCODE = \MongoDB\Builder\Encode::Array; - /** @param BSONArray|PackedArray|ResolvesToArray|list $expression */ + /** @param BSONArray|PackedArray|ResolvesToArray|list $expression */ public PackedArray|ResolvesToArray|BSONArray|array $expression; /** - * @param BSONArray|PackedArray|ResolvesToArray|list $expression + * @param BSONArray|PackedArray|ResolvesToArray|list $expression */ public function __construct(PackedArray|ResolvesToArray|BSONArray|array $expression) { diff --git a/src/Builder/Aggregation/ArrayElemAtAggregation.php b/src/Builder/Aggregation/ArrayElemAtAggregation.php index 08d9d4d00..6387aa405 100644 --- a/src/Builder/Aggregation/ArrayElemAtAggregation.php +++ b/src/Builder/Aggregation/ArrayElemAtAggregation.php @@ -24,14 +24,14 @@ class ArrayElemAtAggregation implements ExpressionInterface public const NAME = '$arrayElemAt'; public const ENCODE = \MongoDB\Builder\Encode::Array; - /** @param BSONArray|PackedArray|ResolvesToArray|list $array */ + /** @param BSONArray|PackedArray|ResolvesToArray|list $array */ public PackedArray|ResolvesToArray|BSONArray|array $array; /** @param Int64|ResolvesToInt|int $idx */ public Int64|ResolvesToInt|int $idx; /** - * @param BSONArray|PackedArray|ResolvesToArray|list $array + * @param BSONArray|PackedArray|ResolvesToArray|list $array * @param Int64|ResolvesToInt|int $idx */ public function __construct(PackedArray|ResolvesToArray|BSONArray|array $array, Int64|ResolvesToInt|int $idx) diff --git a/src/Builder/Aggregation/ArrayToObjectAggregation.php b/src/Builder/Aggregation/ArrayToObjectAggregation.php index 33acea0ab..2d163004e 100644 --- a/src/Builder/Aggregation/ArrayToObjectAggregation.php +++ b/src/Builder/Aggregation/ArrayToObjectAggregation.php @@ -23,11 +23,11 @@ class ArrayToObjectAggregation implements ResolvesToObject public const NAME = '$arrayToObject'; public const ENCODE = \MongoDB\Builder\Encode::Array; - /** @param BSONArray|PackedArray|ResolvesToArray|list $array */ + /** @param BSONArray|PackedArray|ResolvesToArray|list $array */ public PackedArray|ResolvesToArray|BSONArray|array $array; /** - * @param BSONArray|PackedArray|ResolvesToArray|list $array + * @param BSONArray|PackedArray|ResolvesToArray|list $array */ public function __construct(PackedArray|ResolvesToArray|BSONArray|array $array) { diff --git a/src/Builder/Aggregation/ConcatArraysAggregation.php b/src/Builder/Aggregation/ConcatArraysAggregation.php index f1fe60b30..94358a19f 100644 --- a/src/Builder/Aggregation/ConcatArraysAggregation.php +++ b/src/Builder/Aggregation/ConcatArraysAggregation.php @@ -22,11 +22,11 @@ class ConcatArraysAggregation implements ResolvesToArray public const NAME = '$concatArrays'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param list> ...$array */ + /** @param list ...$array */ public array $array; /** - * @param BSONArray|PackedArray|ResolvesToArray|list ...$array + * @param BSONArray|PackedArray|ResolvesToArray|list ...$array * @no-named-arguments */ public function __construct(PackedArray|ResolvesToArray|BSONArray|array ...$array) @@ -35,7 +35,7 @@ public function __construct(PackedArray|ResolvesToArray|BSONArray|array ...$arra throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $array, got %d.', 1, \count($array))); } if (! \array_is_list($array)) { - throw new \InvalidArgumentException('Expected $array arguments to be a list of BSONArray|PackedArray|ResolvesToArray|list, named arguments are not supported'); + throw new \InvalidArgumentException('Expected $array arguments to be a list of BSONArray|PackedArray|ResolvesToArray|list, named arguments are not supported'); } $this->array = $array; } diff --git a/src/Builder/Aggregation/FilterAggregation.php b/src/Builder/Aggregation/FilterAggregation.php index 86cfb4e19..eac10ef0a 100644 --- a/src/Builder/Aggregation/FilterAggregation.php +++ b/src/Builder/Aggregation/FilterAggregation.php @@ -26,7 +26,7 @@ class FilterAggregation implements ResolvesToArray public const NAME = '$filter'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param BSONArray|PackedArray|ResolvesToArray|list $input */ + /** @param BSONArray|PackedArray|ResolvesToArray|list $input */ public PackedArray|ResolvesToArray|BSONArray|array $input; /** @param ResolvesToBool|bool $cond 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. */ @@ -42,7 +42,7 @@ class FilterAggregation implements ResolvesToArray public Int64|ResolvesToInt|Optional|int $limit; /** - * @param BSONArray|PackedArray|ResolvesToArray|list $input + * @param BSONArray|PackedArray|ResolvesToArray|list $input * @param ResolvesToBool|bool $cond 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. * @param Optional|non-empty-string $as 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. * @param Int64|Optional|ResolvesToInt|int $limit 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. diff --git a/src/Builder/Aggregation/FirstNAggregation.php b/src/Builder/Aggregation/FirstNAggregation.php index d0e19b345..04f887bff 100644 --- a/src/Builder/Aggregation/FirstNAggregation.php +++ b/src/Builder/Aggregation/FirstNAggregation.php @@ -24,14 +24,14 @@ class FirstNAggregation implements AccumulatorInterface public const NAME = '$firstN'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param BSONArray|PackedArray|ResolvesToArray|list $input An expression that resolves to the array from which to return n elements. */ + /** @param BSONArray|PackedArray|ResolvesToArray|list $input An expression that resolves to the array from which to return n elements. */ public PackedArray|ResolvesToArray|BSONArray|array $input; /** @param Int64|ResolvesToInt|int $n An expression that resolves to a positive integer. The integer specifies the number of array elements that $firstN returns. */ public Int64|ResolvesToInt|int $n; /** - * @param BSONArray|PackedArray|ResolvesToArray|list $input An expression that resolves to the array from which to return n elements. + * @param BSONArray|PackedArray|ResolvesToArray|list $input An expression that resolves to the array from which to return n elements. * @param Int64|ResolvesToInt|int $n An expression that resolves to a positive integer. The integer specifies the number of array elements that $firstN returns. */ public function __construct(PackedArray|ResolvesToArray|BSONArray|array $input, Int64|ResolvesToInt|int $n) diff --git a/src/Builder/Aggregation/FunctionAggregation.php b/src/Builder/Aggregation/FunctionAggregation.php index 66509b181..c79a1d21e 100644 --- a/src/Builder/Aggregation/FunctionAggregation.php +++ b/src/Builder/Aggregation/FunctionAggregation.php @@ -25,7 +25,7 @@ class FunctionAggregation implements ExpressionInterface /** @param non-empty-string $body The function definition. You can specify the function definition as either BSON type Code or String. */ public string $body; - /** @param BSONArray|PackedArray|list $args Arguments passed to the function body. If the body function does not take an argument, you can specify an empty array [ ]. */ + /** @param BSONArray|PackedArray|list $args Arguments passed to the function body. If the body function does not take an argument, you can specify an empty array [ ]. */ public PackedArray|BSONArray|array $args; /** @param non-empty-string $lang */ @@ -33,7 +33,7 @@ class FunctionAggregation implements ExpressionInterface /** * @param non-empty-string $body The function definition. You can specify the function definition as either BSON type Code or String. - * @param BSONArray|PackedArray|list $args Arguments passed to the function body. If the body function does not take an argument, you can specify an empty array [ ]. + * @param BSONArray|PackedArray|list $args Arguments passed to the function body. If the body function does not take an argument, you can specify an empty array [ ]. * @param non-empty-string $lang */ public function __construct(string $body, PackedArray|BSONArray|array $args, string $lang) diff --git a/src/Builder/Aggregation/InAggregation.php b/src/Builder/Aggregation/InAggregation.php index 907723a6e..4a07966c8 100644 --- a/src/Builder/Aggregation/InAggregation.php +++ b/src/Builder/Aggregation/InAggregation.php @@ -26,12 +26,12 @@ class InAggregation implements ResolvesToBool /** @param ExpressionInterface|mixed $expression Any valid expression expression. */ public mixed $expression; - /** @param BSONArray|PackedArray|ResolvesToArray|list $array Any valid expression that resolves to an array. */ + /** @param BSONArray|PackedArray|ResolvesToArray|list $array Any valid expression that resolves to an array. */ public PackedArray|ResolvesToArray|BSONArray|array $array; /** * @param ExpressionInterface|mixed $expression Any valid expression expression. - * @param BSONArray|PackedArray|ResolvesToArray|list $array Any valid expression that resolves to an array. + * @param BSONArray|PackedArray|ResolvesToArray|list $array Any valid expression that resolves to an array. */ public function __construct(mixed $expression, PackedArray|ResolvesToArray|BSONArray|array $array) { diff --git a/src/Builder/Aggregation/LastNAggregation.php b/src/Builder/Aggregation/LastNAggregation.php index 02e582ea4..e76ac8c25 100644 --- a/src/Builder/Aggregation/LastNAggregation.php +++ b/src/Builder/Aggregation/LastNAggregation.php @@ -24,14 +24,14 @@ class LastNAggregation implements ResolvesToArray public const NAME = '$lastN'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param BSONArray|PackedArray|ResolvesToArray|list $input An expression that resolves to the array from which to return n elements. */ + /** @param BSONArray|PackedArray|ResolvesToArray|list $input An expression that resolves to the array from which to return n elements. */ public PackedArray|ResolvesToArray|BSONArray|array $input; /** @param Int64|ResolvesToInt|int $n An expression that resolves to a positive integer. The integer specifies the number of array elements that $firstN returns. */ public Int64|ResolvesToInt|int $n; /** - * @param BSONArray|PackedArray|ResolvesToArray|list $input An expression that resolves to the array from which to return n elements. + * @param BSONArray|PackedArray|ResolvesToArray|list $input An expression that resolves to the array from which to return n elements. * @param Int64|ResolvesToInt|int $n An expression that resolves to a positive integer. The integer specifies the number of array elements that $firstN returns. */ public function __construct(PackedArray|ResolvesToArray|BSONArray|array $input, Int64|ResolvesToInt|int $n) diff --git a/src/Builder/Aggregation/MapAggregation.php b/src/Builder/Aggregation/MapAggregation.php index 02d08ca1d..04932b0d7 100644 --- a/src/Builder/Aggregation/MapAggregation.php +++ b/src/Builder/Aggregation/MapAggregation.php @@ -24,7 +24,7 @@ class MapAggregation implements ResolvesToArray public const NAME = '$map'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param BSONArray|PackedArray|ResolvesToArray|list $input An expression that resolves to an array. */ + /** @param BSONArray|PackedArray|ResolvesToArray|list $input An expression that resolves to an array. */ public PackedArray|ResolvesToArray|BSONArray|array $input; /** @param ExpressionInterface|mixed $in 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. */ @@ -34,7 +34,7 @@ class MapAggregation implements ResolvesToArray public ResolvesToString|Optional|string $as; /** - * @param BSONArray|PackedArray|ResolvesToArray|list $input An expression that resolves to an array. + * @param BSONArray|PackedArray|ResolvesToArray|list $input An expression that resolves to an array. * @param ExpressionInterface|mixed $in 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. * @param Optional|ResolvesToString|non-empty-string $as 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. */ diff --git a/src/Builder/Aggregation/MaxNAggregation.php b/src/Builder/Aggregation/MaxNAggregation.php index 4f8f610dc..684442855 100644 --- a/src/Builder/Aggregation/MaxNAggregation.php +++ b/src/Builder/Aggregation/MaxNAggregation.php @@ -24,14 +24,14 @@ class MaxNAggregation implements ResolvesToArray public const NAME = '$maxN'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param BSONArray|PackedArray|ResolvesToArray|list $input An expression that resolves to the array from which to return the maximal n elements. */ + /** @param BSONArray|PackedArray|ResolvesToArray|list $input An expression that resolves to the array from which to return the maximal n elements. */ public PackedArray|ResolvesToArray|BSONArray|array $input; /** @param Int64|ResolvesToInt|int $n An expression that resolves to a positive integer. The integer specifies the number of array elements that $maxN returns. */ public Int64|ResolvesToInt|int $n; /** - * @param BSONArray|PackedArray|ResolvesToArray|list $input An expression that resolves to the array from which to return the maximal n elements. + * @param BSONArray|PackedArray|ResolvesToArray|list $input An expression that resolves to the array from which to return the maximal n elements. * @param Int64|ResolvesToInt|int $n An expression that resolves to a positive integer. The integer specifies the number of array elements that $maxN returns. */ public function __construct(PackedArray|ResolvesToArray|BSONArray|array $input, Int64|ResolvesToInt|int $n) diff --git a/src/Builder/Aggregation/MinNAggregation.php b/src/Builder/Aggregation/MinNAggregation.php index 9413ae941..7a2546c16 100644 --- a/src/Builder/Aggregation/MinNAggregation.php +++ b/src/Builder/Aggregation/MinNAggregation.php @@ -24,14 +24,14 @@ class MinNAggregation implements ResolvesToArray public const NAME = '$minN'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param BSONArray|PackedArray|ResolvesToArray|list $input An expression that resolves to the array from which to return the maximal n elements. */ + /** @param BSONArray|PackedArray|ResolvesToArray|list $input An expression that resolves to the array from which to return the maximal n elements. */ public PackedArray|ResolvesToArray|BSONArray|array $input; /** @param Int64|ResolvesToInt|int $n An expression that resolves to a positive integer. The integer specifies the number of array elements that $maxN returns. */ public Int64|ResolvesToInt|int $n; /** - * @param BSONArray|PackedArray|ResolvesToArray|list $input An expression that resolves to the array from which to return the maximal n elements. + * @param BSONArray|PackedArray|ResolvesToArray|list $input An expression that resolves to the array from which to return the maximal n elements. * @param Int64|ResolvesToInt|int $n An expression that resolves to a positive integer. The integer specifies the number of array elements that $maxN returns. */ public function __construct(PackedArray|ResolvesToArray|BSONArray|array $input, Int64|ResolvesToInt|int $n) diff --git a/src/Builder/Aggregation/PercentileAggregation.php b/src/Builder/Aggregation/PercentileAggregation.php index 38640844d..a3b74bd67 100644 --- a/src/Builder/Aggregation/PercentileAggregation.php +++ b/src/Builder/Aggregation/PercentileAggregation.php @@ -37,7 +37,7 @@ class PercentileAggregation implements ResolvesToArray, AccumulatorInterface public Decimal128|Int64|ResolvesToNumber|float|int $input; /** - * @param BSONArray|PackedArray|ResolvesToArray|list $p $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. + * @param BSONArray|PackedArray|ResolvesToArray|list $p $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. */ public PackedArray|ResolvesToArray|BSONArray|array $p; @@ -47,7 +47,7 @@ class PercentileAggregation implements ResolvesToArray, AccumulatorInterface /** * @param Decimal128|Int64|ResolvesToNumber|float|int $input $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. - * @param BSONArray|PackedArray|ResolvesToArray|list $p $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. + * @param BSONArray|PackedArray|ResolvesToArray|list $p $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. * @param non-empty-string $method The method that mongod uses to calculate the percentile value. The method must be 'approximate'. */ diff --git a/src/Builder/Aggregation/ReduceAggregation.php b/src/Builder/Aggregation/ReduceAggregation.php index 0f9caa72f..6dbe25d0f 100644 --- a/src/Builder/Aggregation/ReduceAggregation.php +++ b/src/Builder/Aggregation/ReduceAggregation.php @@ -23,7 +23,7 @@ class ReduceAggregation implements ExpressionInterface public const ENCODE = \MongoDB\Builder\Encode::Object; /** - * @param BSONArray|PackedArray|ResolvesToArray|list $input Can be any valid expression that resolves to an array. + * @param BSONArray|PackedArray|ResolvesToArray|list $input 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. */ @@ -41,7 +41,7 @@ class ReduceAggregation implements ExpressionInterface public mixed $in; /** - * @param BSONArray|PackedArray|ResolvesToArray|list $input Can be any valid expression that resolves to an array. + * @param BSONArray|PackedArray|ResolvesToArray|list $input 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. * @param ExpressionInterface|mixed $initialValue The initial cumulative value set before in is applied to the first element of the input array. diff --git a/src/Builder/Aggregation/ReverseArrayAggregation.php b/src/Builder/Aggregation/ReverseArrayAggregation.php index 15d7f4e74..f982c2bfe 100644 --- a/src/Builder/Aggregation/ReverseArrayAggregation.php +++ b/src/Builder/Aggregation/ReverseArrayAggregation.php @@ -22,11 +22,11 @@ class ReverseArrayAggregation implements ResolvesToArray public const NAME = '$reverseArray'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param BSONArray|PackedArray|ResolvesToArray|list $expression The argument can be any valid expression as long as it resolves to an array. */ + /** @param BSONArray|PackedArray|ResolvesToArray|list $expression The argument can be any valid expression as long as it resolves to an array. */ public PackedArray|ResolvesToArray|BSONArray|array $expression; /** - * @param BSONArray|PackedArray|ResolvesToArray|list $expression The argument can be any valid expression as long as it resolves to an array. + * @param BSONArray|PackedArray|ResolvesToArray|list $expression The argument can be any valid expression as long as it resolves to an array. */ public function __construct(PackedArray|ResolvesToArray|BSONArray|array $expression) { diff --git a/src/Builder/Aggregation/SetDifferenceAggregation.php b/src/Builder/Aggregation/SetDifferenceAggregation.php index b4fd3eb27..054c7b0d5 100644 --- a/src/Builder/Aggregation/SetDifferenceAggregation.php +++ b/src/Builder/Aggregation/SetDifferenceAggregation.php @@ -22,15 +22,15 @@ class SetDifferenceAggregation implements ResolvesToArray public const NAME = '$setDifference'; public const ENCODE = \MongoDB\Builder\Encode::Array; - /** @param BSONArray|PackedArray|ResolvesToArray|list $expression1 The arguments can be any valid expression as long as they each resolve to an array. */ + /** @param BSONArray|PackedArray|ResolvesToArray|list $expression1 The arguments can be any valid expression as long as they each resolve to an array. */ public PackedArray|ResolvesToArray|BSONArray|array $expression1; - /** @param BSONArray|PackedArray|ResolvesToArray|list $expression2 The arguments can be any valid expression as long as they each resolve to an array. */ + /** @param BSONArray|PackedArray|ResolvesToArray|list $expression2 The arguments can be any valid expression as long as they each resolve to an array. */ public PackedArray|ResolvesToArray|BSONArray|array $expression2; /** - * @param BSONArray|PackedArray|ResolvesToArray|list $expression1 The arguments can be any valid expression as long as they each resolve to an array. - * @param BSONArray|PackedArray|ResolvesToArray|list $expression2 The arguments can be any valid expression as long as they each resolve to an array. + * @param BSONArray|PackedArray|ResolvesToArray|list $expression1 The arguments can be any valid expression as long as they each resolve to an array. + * @param BSONArray|PackedArray|ResolvesToArray|list $expression2 The arguments can be any valid expression as long as they each resolve to an array. */ public function __construct( PackedArray|ResolvesToArray|BSONArray|array $expression1, diff --git a/src/Builder/Aggregation/SetEqualsAggregation.php b/src/Builder/Aggregation/SetEqualsAggregation.php index fb6318168..c87bb1a13 100644 --- a/src/Builder/Aggregation/SetEqualsAggregation.php +++ b/src/Builder/Aggregation/SetEqualsAggregation.php @@ -23,11 +23,11 @@ class SetEqualsAggregation implements ResolvesToBool public const NAME = '$setEquals'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param list> ...$expression */ + /** @param list ...$expression */ public array $expression; /** - * @param BSONArray|PackedArray|ResolvesToArray|list ...$expression + * @param BSONArray|PackedArray|ResolvesToArray|list ...$expression * @no-named-arguments */ public function __construct(PackedArray|ResolvesToArray|BSONArray|array ...$expression) @@ -36,7 +36,7 @@ public function __construct(PackedArray|ResolvesToArray|BSONArray|array ...$expr throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); } if (! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression arguments to be a list of BSONArray|PackedArray|ResolvesToArray|list, named arguments are not supported'); + throw new \InvalidArgumentException('Expected $expression arguments to be a list of BSONArray|PackedArray|ResolvesToArray|list, named arguments are not supported'); } $this->expression = $expression; } diff --git a/src/Builder/Aggregation/SetIntersectionAggregation.php b/src/Builder/Aggregation/SetIntersectionAggregation.php index cd7d54a32..4669cb4f8 100644 --- a/src/Builder/Aggregation/SetIntersectionAggregation.php +++ b/src/Builder/Aggregation/SetIntersectionAggregation.php @@ -22,11 +22,11 @@ class SetIntersectionAggregation implements ResolvesToArray public const NAME = '$setIntersection'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param list> ...$expression */ + /** @param list ...$expression */ public array $expression; /** - * @param BSONArray|PackedArray|ResolvesToArray|list ...$expression + * @param BSONArray|PackedArray|ResolvesToArray|list ...$expression * @no-named-arguments */ public function __construct(PackedArray|ResolvesToArray|BSONArray|array ...$expression) @@ -35,7 +35,7 @@ public function __construct(PackedArray|ResolvesToArray|BSONArray|array ...$expr throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); } if (! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression arguments to be a list of BSONArray|PackedArray|ResolvesToArray|list, named arguments are not supported'); + throw new \InvalidArgumentException('Expected $expression arguments to be a list of BSONArray|PackedArray|ResolvesToArray|list, named arguments are not supported'); } $this->expression = $expression; } diff --git a/src/Builder/Aggregation/SetIsSubsetAggregation.php b/src/Builder/Aggregation/SetIsSubsetAggregation.php index 6897159a4..13234d863 100644 --- a/src/Builder/Aggregation/SetIsSubsetAggregation.php +++ b/src/Builder/Aggregation/SetIsSubsetAggregation.php @@ -23,15 +23,15 @@ class SetIsSubsetAggregation implements ResolvesToBool public const NAME = '$setIsSubset'; public const ENCODE = \MongoDB\Builder\Encode::Array; - /** @param BSONArray|PackedArray|ResolvesToArray|list $expression1 */ + /** @param BSONArray|PackedArray|ResolvesToArray|list $expression1 */ public PackedArray|ResolvesToArray|BSONArray|array $expression1; - /** @param BSONArray|PackedArray|ResolvesToArray|list $expression2 */ + /** @param BSONArray|PackedArray|ResolvesToArray|list $expression2 */ public PackedArray|ResolvesToArray|BSONArray|array $expression2; /** - * @param BSONArray|PackedArray|ResolvesToArray|list $expression1 - * @param BSONArray|PackedArray|ResolvesToArray|list $expression2 + * @param BSONArray|PackedArray|ResolvesToArray|list $expression1 + * @param BSONArray|PackedArray|ResolvesToArray|list $expression2 */ public function __construct( PackedArray|ResolvesToArray|BSONArray|array $expression1, diff --git a/src/Builder/Aggregation/SetUnionAggregation.php b/src/Builder/Aggregation/SetUnionAggregation.php index 4822dece7..53c1f0ac2 100644 --- a/src/Builder/Aggregation/SetUnionAggregation.php +++ b/src/Builder/Aggregation/SetUnionAggregation.php @@ -22,11 +22,11 @@ class SetUnionAggregation implements ResolvesToArray public const NAME = '$setUnion'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param list> ...$expression */ + /** @param list ...$expression */ public array $expression; /** - * @param BSONArray|PackedArray|ResolvesToArray|list ...$expression + * @param BSONArray|PackedArray|ResolvesToArray|list ...$expression * @no-named-arguments */ public function __construct(PackedArray|ResolvesToArray|BSONArray|array ...$expression) @@ -35,7 +35,7 @@ public function __construct(PackedArray|ResolvesToArray|BSONArray|array ...$expr throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); } if (! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression arguments to be a list of BSONArray|PackedArray|ResolvesToArray|list, named arguments are not supported'); + throw new \InvalidArgumentException('Expected $expression arguments to be a list of BSONArray|PackedArray|ResolvesToArray|list, named arguments are not supported'); } $this->expression = $expression; } diff --git a/src/Builder/Aggregation/SizeAggregation.php b/src/Builder/Aggregation/SizeAggregation.php index d05c21518..d033904b8 100644 --- a/src/Builder/Aggregation/SizeAggregation.php +++ b/src/Builder/Aggregation/SizeAggregation.php @@ -23,11 +23,11 @@ class SizeAggregation implements ResolvesToInt public const NAME = '$size'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param BSONArray|PackedArray|ResolvesToArray|list $expression The argument for $size can be any expression as long as it resolves to an array. */ + /** @param BSONArray|PackedArray|ResolvesToArray|list $expression The argument for $size can be any expression as long as it resolves to an array. */ public PackedArray|ResolvesToArray|BSONArray|array $expression; /** - * @param BSONArray|PackedArray|ResolvesToArray|list $expression The argument for $size can be any expression as long as it resolves to an array. + * @param BSONArray|PackedArray|ResolvesToArray|list $expression The argument for $size can be any expression as long as it resolves to an array. */ public function __construct(PackedArray|ResolvesToArray|BSONArray|array $expression) { diff --git a/src/Builder/Aggregation/SliceAggregation.php b/src/Builder/Aggregation/SliceAggregation.php index 4b843821d..942db265e 100644 --- a/src/Builder/Aggregation/SliceAggregation.php +++ b/src/Builder/Aggregation/SliceAggregation.php @@ -25,7 +25,7 @@ class SliceAggregation implements ResolvesToArray public const NAME = '$slice'; public const ENCODE = \MongoDB\Builder\Encode::Array; - /** @param BSONArray|PackedArray|ResolvesToArray|list $expression Any valid expression as long as it resolves to an array. */ + /** @param BSONArray|PackedArray|ResolvesToArray|list $expression Any valid expression as long as it resolves to an array. */ public PackedArray|ResolvesToArray|BSONArray|array $expression; /** @@ -43,7 +43,7 @@ class SliceAggregation implements ResolvesToArray public Int64|ResolvesToInt|Optional|int $position; /** - * @param BSONArray|PackedArray|ResolvesToArray|list $expression Any valid expression as long as it resolves to an array. + * @param BSONArray|PackedArray|ResolvesToArray|list $expression Any valid expression as long as it resolves to an array. * @param Int64|ResolvesToInt|int $n 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. diff --git a/src/Builder/Aggregation/SortArrayAggregation.php b/src/Builder/Aggregation/SortArrayAggregation.php index 6d65bc3c0..480639f47 100644 --- a/src/Builder/Aggregation/SortArrayAggregation.php +++ b/src/Builder/Aggregation/SortArrayAggregation.php @@ -23,14 +23,14 @@ class SortArrayAggregation implements ResolvesToArray public const NAME = '$sortArray'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param BSONArray|PackedArray|ResolvesToArray|list $input The array to be sorted. */ + /** @param BSONArray|PackedArray|ResolvesToArray|list $input The array to be sorted. */ public PackedArray|ResolvesToArray|BSONArray|array $input; /** @param array|stdClass $sortBy The document specifies a sort ordering. */ public stdClass|array $sortBy; /** - * @param BSONArray|PackedArray|ResolvesToArray|list $input The array to be sorted. + * @param BSONArray|PackedArray|ResolvesToArray|list $input The array to be sorted. * @param array|stdClass $sortBy The document specifies a sort ordering. */ public function __construct(PackedArray|ResolvesToArray|BSONArray|array $input, stdClass|array $sortBy) diff --git a/src/Builder/Aggregation/SwitchAggregation.php b/src/Builder/Aggregation/SwitchAggregation.php index 8624ede48..63296f554 100644 --- a/src/Builder/Aggregation/SwitchAggregation.php +++ b/src/Builder/Aggregation/SwitchAggregation.php @@ -23,7 +23,7 @@ class SwitchAggregation implements ExpressionInterface public const ENCODE = \MongoDB\Builder\Encode::Object; /** - * @param BSONArray|PackedArray|list $branches An array of control branch documents. Each branch is a document with the following fields: + * @param BSONArray|PackedArray|list $branches 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. @@ -37,7 +37,7 @@ class SwitchAggregation implements ExpressionInterface public mixed $default; /** - * @param BSONArray|PackedArray|list $branches An array of control branch documents. Each branch is a document with the following fields: + * @param BSONArray|PackedArray|list $branches 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. diff --git a/src/Builder/Aggregation/ZipAggregation.php b/src/Builder/Aggregation/ZipAggregation.php index faa466442..234c60d7f 100644 --- a/src/Builder/Aggregation/ZipAggregation.php +++ b/src/Builder/Aggregation/ZipAggregation.php @@ -23,7 +23,7 @@ class ZipAggregation implements ResolvesToArray public const ENCODE = \MongoDB\Builder\Encode::Object; /** - * @param BSONArray|PackedArray|ResolvesToArray|list $inputs An array of expressions that resolve to arrays. The elements of these input arrays combine to form the arrays of the output array. + * @param BSONArray|PackedArray|ResolvesToArray|list $inputs 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. */ @@ -36,19 +36,19 @@ class ZipAggregation implements ResolvesToArray public bool $useLongestLength; /** - * @param BSONArray|PackedArray|list $defaults 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. + * @param BSONArray|PackedArray|list $defaults 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. */ public PackedArray|BSONArray|array $defaults; /** - * @param BSONArray|PackedArray|ResolvesToArray|list $inputs An array of expressions that resolve to arrays. The elements of these input arrays combine to form the arrays of the output array. + * @param BSONArray|PackedArray|ResolvesToArray|list $inputs 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. * @param bool $useLongestLength 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. - * @param BSONArray|PackedArray|list $defaults 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. + * @param BSONArray|PackedArray|list $defaults 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. */ diff --git a/src/Builder/Query.php b/src/Builder/Query.php index adfa20704..33fbc9036 100644 --- a/src/Builder/Query.php +++ b/src/Builder/Query.php @@ -88,7 +88,7 @@ public static function and(QueryInterface|stdClass|array ...$expression): AndQue * Matches numeric or binary values in which a set of bit positions all have a value of 0. * * @see https://www.mongodb.com/docs/manual/reference/operator/query/bitsAllClear/ - * @param BSONArray|Binary|Int64|PackedArray|int|list|non-empty-string $bitmask + * @param BSONArray|Binary|Int64|PackedArray|int|list|non-empty-string $bitmask */ public static function bitsAllClear( Binary|Int64|PackedArray|BSONArray|array|int|string $bitmask, @@ -101,7 +101,7 @@ public static function bitsAllClear( * Matches numeric or binary values in which a set of bit positions all have a value of 1. * * @see https://www.mongodb.com/docs/manual/reference/operator/query/bitsAllSet/ - * @param BSONArray|Binary|Int64|PackedArray|int|list|non-empty-string $bitmask + * @param BSONArray|Binary|Int64|PackedArray|int|list|non-empty-string $bitmask */ public static function bitsAllSet(Binary|Int64|PackedArray|BSONArray|array|int|string $bitmask): BitsAllSetQuery { @@ -112,7 +112,7 @@ public static function bitsAllSet(Binary|Int64|PackedArray|BSONArray|array|int|s * Matches numeric or binary values in which any bit from a set of bit positions has a value of 0. * * @see https://www.mongodb.com/docs/manual/reference/operator/query/bitsAnyClear/ - * @param BSONArray|Binary|Int64|PackedArray|int|list|non-empty-string $bitmask + * @param BSONArray|Binary|Int64|PackedArray|int|list|non-empty-string $bitmask */ public static function bitsAnyClear( Binary|Int64|PackedArray|BSONArray|array|int|string $bitmask, @@ -125,7 +125,7 @@ public static function bitsAnyClear( * Matches numeric or binary values in which any bit from a set of bit positions has a value of 1. * * @see https://www.mongodb.com/docs/manual/reference/operator/query/bitsAnySet/ - * @param BSONArray|Binary|Int64|PackedArray|int|list|non-empty-string $bitmask + * @param BSONArray|Binary|Int64|PackedArray|int|list|non-empty-string $bitmask */ public static function bitsAnySet(Binary|Int64|PackedArray|BSONArray|array|int|string $bitmask): BitsAnySetQuery { @@ -136,7 +136,7 @@ public static function bitsAnySet(Binary|Int64|PackedArray|BSONArray|array|int|s * Specifies a rectangular box using legacy coordinate pairs for $geoWithin queries. The 2d index supports $box. * * @see https://www.mongodb.com/docs/manual/reference/operator/query/box/ - * @param BSONArray|PackedArray|list $value + * @param BSONArray|PackedArray|list $value */ public static function box(PackedArray|BSONArray|array $value): BoxQuery { @@ -147,7 +147,7 @@ public static function box(PackedArray|BSONArray|array $value): BoxQuery * Specifies a circle using legacy coordinate pairs to $geoWithin queries when using planar geometry. The 2d index supports $center. * * @see https://www.mongodb.com/docs/manual/reference/operator/query/center/ - * @param BSONArray|PackedArray|list $value + * @param BSONArray|PackedArray|list $value */ public static function center(PackedArray|BSONArray|array $value): CenterQuery { @@ -158,7 +158,7 @@ public static function center(PackedArray|BSONArray|array $value): CenterQuery * 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. * * @see https://www.mongodb.com/docs/manual/reference/operator/query/centerSphere/ - * @param BSONArray|PackedArray|list $value + * @param BSONArray|PackedArray|list $value */ public static function centerSphere(PackedArray|BSONArray|array $value): CenterSphereQuery { @@ -236,7 +236,7 @@ public static function geoIntersects(stdClass|array $geometry): GeoIntersectsQue * * @see https://www.mongodb.com/docs/manual/reference/operator/query/geometry/ * @param non-empty-string $type - * @param BSONArray|PackedArray|list $coordinates + * @param BSONArray|PackedArray|list $coordinates * @param Document|Serializable|array|stdClass $crs */ public static function geometry( @@ -285,9 +285,9 @@ public static function gte(mixed $value): GteQuery * Matches any of the values specified in an array. * * @see https://www.mongodb.com/docs/manual/reference/operator/query/in/ - * @param mixed $value + * @param BSONArray|PackedArray|list $value */ - public static function in(mixed $value): InQuery + public static function in(PackedArray|BSONArray|array $value): InQuery { return new InQuery($value); } @@ -428,9 +428,9 @@ public static function nearSphere( * Matches none of the values specified in an array. * * @see https://www.mongodb.com/docs/manual/reference/operator/query/nin/ - * @param mixed $value + * @param BSONArray|PackedArray|list $value */ - public static function nin(mixed $value): NinQuery + public static function nin(PackedArray|BSONArray|array $value): NinQuery { return new NinQuery($value); } @@ -472,7 +472,7 @@ public static function or(QueryInterface|stdClass|array ...$expression): OrQuery * Specifies a polygon to using legacy coordinate pairs for $geoWithin queries. The 2d index supports $center. * * @see https://www.mongodb.com/docs/manual/reference/operator/query/polygon/ - * @param BSONArray|PackedArray|list $points + * @param BSONArray|PackedArray|list $points */ public static function polygon(PackedArray|BSONArray|array $points): PolygonQuery { @@ -548,7 +548,7 @@ public static function text( * Selects documents if a field is of the specified type. * * @see https://www.mongodb.com/docs/manual/reference/operator/query/type/ - * @param BSONArray|Int64|PackedArray|int|list|non-empty-string $type + * @param BSONArray|Int64|PackedArray|int|list|non-empty-string $type */ public static function type(Int64|PackedArray|BSONArray|array|int|string $type): TypeQuery { diff --git a/src/Builder/Query/BitsAllClearQuery.php b/src/Builder/Query/BitsAllClearQuery.php index be4b0a0fb..167fa9167 100644 --- a/src/Builder/Query/BitsAllClearQuery.php +++ b/src/Builder/Query/BitsAllClearQuery.php @@ -23,11 +23,11 @@ class BitsAllClearQuery implements QueryInterface public const NAME = '$bitsAllClear'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param BSONArray|Binary|Int64|PackedArray|int|list|non-empty-string $bitmask */ + /** @param BSONArray|Binary|Int64|PackedArray|int|list|non-empty-string $bitmask */ public Binary|Int64|PackedArray|BSONArray|array|int|string $bitmask; /** - * @param BSONArray|Binary|Int64|PackedArray|int|list|non-empty-string $bitmask + * @param BSONArray|Binary|Int64|PackedArray|int|list|non-empty-string $bitmask */ public function __construct(Binary|Int64|PackedArray|BSONArray|array|int|string $bitmask) { diff --git a/src/Builder/Query/BitsAllSetQuery.php b/src/Builder/Query/BitsAllSetQuery.php index 275b2c23d..136bd3d5b 100644 --- a/src/Builder/Query/BitsAllSetQuery.php +++ b/src/Builder/Query/BitsAllSetQuery.php @@ -23,11 +23,11 @@ class BitsAllSetQuery implements QueryInterface public const NAME = '$bitsAllSet'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param BSONArray|Binary|Int64|PackedArray|int|list|non-empty-string $bitmask */ + /** @param BSONArray|Binary|Int64|PackedArray|int|list|non-empty-string $bitmask */ public Binary|Int64|PackedArray|BSONArray|array|int|string $bitmask; /** - * @param BSONArray|Binary|Int64|PackedArray|int|list|non-empty-string $bitmask + * @param BSONArray|Binary|Int64|PackedArray|int|list|non-empty-string $bitmask */ public function __construct(Binary|Int64|PackedArray|BSONArray|array|int|string $bitmask) { diff --git a/src/Builder/Query/BitsAnyClearQuery.php b/src/Builder/Query/BitsAnyClearQuery.php index 38b1e77e5..2e65b8c63 100644 --- a/src/Builder/Query/BitsAnyClearQuery.php +++ b/src/Builder/Query/BitsAnyClearQuery.php @@ -23,11 +23,11 @@ class BitsAnyClearQuery implements QueryInterface public const NAME = '$bitsAnyClear'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param BSONArray|Binary|Int64|PackedArray|int|list|non-empty-string $bitmask */ + /** @param BSONArray|Binary|Int64|PackedArray|int|list|non-empty-string $bitmask */ public Binary|Int64|PackedArray|BSONArray|array|int|string $bitmask; /** - * @param BSONArray|Binary|Int64|PackedArray|int|list|non-empty-string $bitmask + * @param BSONArray|Binary|Int64|PackedArray|int|list|non-empty-string $bitmask */ public function __construct(Binary|Int64|PackedArray|BSONArray|array|int|string $bitmask) { diff --git a/src/Builder/Query/BitsAnySetQuery.php b/src/Builder/Query/BitsAnySetQuery.php index 3f0f2f9e0..b9be52913 100644 --- a/src/Builder/Query/BitsAnySetQuery.php +++ b/src/Builder/Query/BitsAnySetQuery.php @@ -23,11 +23,11 @@ class BitsAnySetQuery implements QueryInterface public const NAME = '$bitsAnySet'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param BSONArray|Binary|Int64|PackedArray|int|list|non-empty-string $bitmask */ + /** @param BSONArray|Binary|Int64|PackedArray|int|list|non-empty-string $bitmask */ public Binary|Int64|PackedArray|BSONArray|array|int|string $bitmask; /** - * @param BSONArray|Binary|Int64|PackedArray|int|list|non-empty-string $bitmask + * @param BSONArray|Binary|Int64|PackedArray|int|list|non-empty-string $bitmask */ public function __construct(Binary|Int64|PackedArray|BSONArray|array|int|string $bitmask) { diff --git a/src/Builder/Query/BoxQuery.php b/src/Builder/Query/BoxQuery.php index e05d9af79..7e4f63a21 100644 --- a/src/Builder/Query/BoxQuery.php +++ b/src/Builder/Query/BoxQuery.php @@ -21,11 +21,11 @@ class BoxQuery implements QueryInterface public const NAME = '$box'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param BSONArray|PackedArray|list $value */ + /** @param BSONArray|PackedArray|list $value */ public PackedArray|BSONArray|array $value; /** - * @param BSONArray|PackedArray|list $value + * @param BSONArray|PackedArray|list $value */ public function __construct(PackedArray|BSONArray|array $value) { diff --git a/src/Builder/Query/CenterQuery.php b/src/Builder/Query/CenterQuery.php index 18239aaf9..01b9bfe40 100644 --- a/src/Builder/Query/CenterQuery.php +++ b/src/Builder/Query/CenterQuery.php @@ -21,11 +21,11 @@ class CenterQuery implements QueryInterface public const NAME = '$center'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param BSONArray|PackedArray|list $value */ + /** @param BSONArray|PackedArray|list $value */ public PackedArray|BSONArray|array $value; /** - * @param BSONArray|PackedArray|list $value + * @param BSONArray|PackedArray|list $value */ public function __construct(PackedArray|BSONArray|array $value) { diff --git a/src/Builder/Query/CenterSphereQuery.php b/src/Builder/Query/CenterSphereQuery.php index 421ea406d..9751ac0b2 100644 --- a/src/Builder/Query/CenterSphereQuery.php +++ b/src/Builder/Query/CenterSphereQuery.php @@ -21,11 +21,11 @@ class CenterSphereQuery implements QueryInterface public const NAME = '$centerSphere'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param BSONArray|PackedArray|list $value */ + /** @param BSONArray|PackedArray|list $value */ public PackedArray|BSONArray|array $value; /** - * @param BSONArray|PackedArray|list $value + * @param BSONArray|PackedArray|list $value */ public function __construct(PackedArray|BSONArray|array $value) { diff --git a/src/Builder/Query/GeometryQuery.php b/src/Builder/Query/GeometryQuery.php index bfcbe4b62..9815d9d4c 100644 --- a/src/Builder/Query/GeometryQuery.php +++ b/src/Builder/Query/GeometryQuery.php @@ -27,7 +27,7 @@ class GeometryQuery implements ExpressionInterface /** @param non-empty-string $type */ public string $type; - /** @param BSONArray|PackedArray|list $coordinates */ + /** @param BSONArray|PackedArray|list $coordinates */ public PackedArray|BSONArray|array $coordinates; /** @param Document|Serializable|array|stdClass $crs */ @@ -35,7 +35,7 @@ class GeometryQuery implements ExpressionInterface /** * @param non-empty-string $type - * @param BSONArray|PackedArray|list $coordinates + * @param BSONArray|PackedArray|list $coordinates * @param Document|Serializable|array|stdClass $crs */ public function __construct( diff --git a/src/Builder/Query/InQuery.php b/src/Builder/Query/InQuery.php index 7b2bba176..0d17fae2b 100644 --- a/src/Builder/Query/InQuery.php +++ b/src/Builder/Query/InQuery.php @@ -6,7 +6,10 @@ namespace MongoDB\Builder\Query; +use MongoDB\BSON\PackedArray; use MongoDB\Builder\Encode; +use MongoDB\Builder\Expression\ExpressionInterface; +use MongoDB\Model\BSONArray; /** * Matches any of the values specified in an array. @@ -18,14 +21,17 @@ class InQuery implements QueryInterface public const NAME = '$in'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param mixed $value */ - public mixed $value; + /** @param BSONArray|PackedArray|list $value */ + public PackedArray|BSONArray|array $value; /** - * @param mixed $value + * @param BSONArray|PackedArray|list $value */ - public function __construct(mixed $value) + public function __construct(PackedArray|BSONArray|array $value) { + if (\is_array($value) && ! \array_is_list($value)) { + throw new \InvalidArgumentException('Expected $value argument to be a list, got an associative array.'); + } $this->value = $value; } } diff --git a/src/Builder/Query/NinQuery.php b/src/Builder/Query/NinQuery.php index 2f1243ea5..068aa54f9 100644 --- a/src/Builder/Query/NinQuery.php +++ b/src/Builder/Query/NinQuery.php @@ -6,7 +6,10 @@ namespace MongoDB\Builder\Query; +use MongoDB\BSON\PackedArray; use MongoDB\Builder\Encode; +use MongoDB\Builder\Expression\ExpressionInterface; +use MongoDB\Model\BSONArray; /** * Matches none of the values specified in an array. @@ -18,14 +21,17 @@ class NinQuery implements QueryInterface public const NAME = '$nin'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param mixed $value */ - public mixed $value; + /** @param BSONArray|PackedArray|list $value */ + public PackedArray|BSONArray|array $value; /** - * @param mixed $value + * @param BSONArray|PackedArray|list $value */ - public function __construct(mixed $value) + public function __construct(PackedArray|BSONArray|array $value) { + if (\is_array($value) && ! \array_is_list($value)) { + throw new \InvalidArgumentException('Expected $value argument to be a list, got an associative array.'); + } $this->value = $value; } } diff --git a/src/Builder/Query/PolygonQuery.php b/src/Builder/Query/PolygonQuery.php index ad742dc12..2f13462a3 100644 --- a/src/Builder/Query/PolygonQuery.php +++ b/src/Builder/Query/PolygonQuery.php @@ -21,11 +21,11 @@ class PolygonQuery implements QueryInterface public const NAME = '$polygon'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param BSONArray|PackedArray|list $points */ + /** @param BSONArray|PackedArray|list $points */ public PackedArray|BSONArray|array $points; /** - * @param BSONArray|PackedArray|list $points + * @param BSONArray|PackedArray|list $points */ public function __construct(PackedArray|BSONArray|array $points) { diff --git a/src/Builder/Query/TypeQuery.php b/src/Builder/Query/TypeQuery.php index fa8bdc060..81d6fec3c 100644 --- a/src/Builder/Query/TypeQuery.php +++ b/src/Builder/Query/TypeQuery.php @@ -22,11 +22,11 @@ class TypeQuery implements QueryInterface public const NAME = '$type'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param BSONArray|Int64|PackedArray|int|list|non-empty-string $type */ + /** @param BSONArray|Int64|PackedArray|int|list|non-empty-string $type */ public Int64|PackedArray|BSONArray|array|int|string $type; /** - * @param BSONArray|Int64|PackedArray|int|list|non-empty-string $type + * @param BSONArray|Int64|PackedArray|int|list|non-empty-string $type */ public function __construct(Int64|PackedArray|BSONArray|array|int|string $type) { diff --git a/src/Builder/Stage.php b/src/Builder/Stage.php index 8c35c9e41..13dc43f2f 100644 --- a/src/Builder/Stage.php +++ b/src/Builder/Stage.php @@ -82,7 +82,7 @@ public static function addFields(mixed ...$expression): AddFieldsStage * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/bucket/ * @param ExpressionInterface|FieldPath|mixed|non-empty-string $groupBy 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. - * @param BSONArray|PackedArray|list $boundaries 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. + * @param BSONArray|PackedArray|list $boundaries 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: * @param ExpressionInterface|Optional|mixed $default 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. @@ -201,7 +201,7 @@ public static function currentOp(): CurrentOpStage * 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. * @param array|stdClass $range Specification for range based densification. - * @param BSONArray|Optional|PackedArray|list $partitionByFields The field(s) that will be used as the partition keys. + * @param BSONArray|Optional|PackedArray|list $partitionByFields The field(s) that will be used as the partition keys. */ public static function densify( FieldPath|string $field, @@ -216,7 +216,7 @@ public static function densify( * Returns literal documents from input values. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/documents/ - * @param BSONArray|PackedArray|ResolvesToArray|list $documents $documents accepts any valid expression that resolves to an array of objects. This includes: + * @param BSONArray|PackedArray|ResolvesToArray|list $documents $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 @@ -247,7 +247,7 @@ public static function facet(Pipeline|array ...$facet): FacetStage * @param Document|Optional|Serializable|array|non-empty-string|stdClass $partitionBy 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. - * @param BSONArray|Optional|PackedArray|list $partitionByFields 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. + * @param BSONArray|Optional|PackedArray|list $partitionByFields 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. * @param Optional|array|stdClass $sortBy Specifies the field or fields to sort the documents within each partition. Uses the same syntax as the $sort stage. @@ -303,7 +303,7 @@ public static function geoNear( * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/graphLookup/ * @param non-empty-string $from 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. - * @param BSONArray|ExpressionInterface|PackedArray|list|mixed $startWith 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. + * @param BSONArray|ExpressionInterface|PackedArray|list|mixed $startWith 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. * @param non-empty-string $connectFromField 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. * @param non-empty-string $connectToField Field name in other documents against which to match the value of the field specified by the connectFromField parameter. * @param non-empty-string $as Name of the array field added to each output document. Contains the documents traversed in the $graphLookup stage to reach the document. @@ -362,7 +362,7 @@ public static function limit(Int64|int $limit): LimitStage * 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. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/listLocalSessions/ - * @param BSONArray|Optional|PackedArray|list $users 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. + * @param BSONArray|Optional|PackedArray|list $users 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. * @param Optional|bool $allUsers Returns all sessions for all users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster. */ public static function listLocalSessions( @@ -405,7 +405,7 @@ public static function listSearchIndexes( * Lists all sessions that have been active long enough to propagate to the system.sessions collection. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSessions/ - * @param BSONArray|Optional|PackedArray|list $users 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. + * @param BSONArray|Optional|PackedArray|list $users 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. * @param Optional|bool $allUsers Returns all sessions for all users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster. */ public static function listSessions( @@ -460,7 +460,7 @@ public static function match(QueryInterface|stdClass|array $query): MatchStage * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/ * @param array|non-empty-string|stdClass $into The output collection. - * @param BSONArray|Optional|PackedArray|list|non-empty-string $on 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. + * @param BSONArray|Optional|PackedArray|list|non-empty-string $on 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. * @param Document|Optional|Serializable|array|stdClass $let Specifies variables for use in the whenMatched pipeline. * @param Optional|non-empty-string $whenMatched 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). * @param Optional|non-empty-string $whenNotMatched The behavior of $merge if a result document does not match an existing document in the out collection. diff --git a/src/Builder/Stage/BucketStage.php b/src/Builder/Stage/BucketStage.php index b122c3988..785ac059d 100644 --- a/src/Builder/Stage/BucketStage.php +++ b/src/Builder/Stage/BucketStage.php @@ -33,7 +33,7 @@ class BucketStage implements StageInterface public mixed $groupBy; /** - * @param BSONArray|PackedArray|list $boundaries 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. + * @param BSONArray|PackedArray|list $boundaries 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: */ public PackedArray|BSONArray|array $boundaries; @@ -56,7 +56,7 @@ class BucketStage implements StageInterface /** * @param ExpressionInterface|FieldPath|mixed|non-empty-string $groupBy 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. - * @param BSONArray|PackedArray|list $boundaries 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. + * @param BSONArray|PackedArray|list $boundaries 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: * @param ExpressionInterface|Optional|mixed $default 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. diff --git a/src/Builder/Stage/DensifyStage.php b/src/Builder/Stage/DensifyStage.php index 5074cf4a8..3d1749d1d 100644 --- a/src/Builder/Stage/DensifyStage.php +++ b/src/Builder/Stage/DensifyStage.php @@ -34,7 +34,7 @@ class DensifyStage implements StageInterface /** @param array|stdClass $range Specification for range based densification. */ public stdClass|array $range; - /** @param BSONArray|Optional|PackedArray|list $partitionByFields The field(s) that will be used as the partition keys. */ + /** @param BSONArray|Optional|PackedArray|list $partitionByFields The field(s) that will be used as the partition keys. */ public PackedArray|Optional|BSONArray|array $partitionByFields; /** @@ -42,7 +42,7 @@ class DensifyStage implements StageInterface * 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. * @param array|stdClass $range Specification for range based densification. - * @param BSONArray|Optional|PackedArray|list $partitionByFields The field(s) that will be used as the partition keys. + * @param BSONArray|Optional|PackedArray|list $partitionByFields The field(s) that will be used as the partition keys. */ public function __construct( FieldPath|string $field, diff --git a/src/Builder/Stage/DocumentsStage.php b/src/Builder/Stage/DocumentsStage.php index 682503632..b2ccb75ff 100644 --- a/src/Builder/Stage/DocumentsStage.php +++ b/src/Builder/Stage/DocumentsStage.php @@ -23,7 +23,7 @@ class DocumentsStage implements StageInterface public const ENCODE = \MongoDB\Builder\Encode::Single; /** - * @param BSONArray|PackedArray|ResolvesToArray|list $documents $documents accepts any valid expression that resolves to an array of objects. This includes: + * @param BSONArray|PackedArray|ResolvesToArray|list $documents $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 @@ -32,7 +32,7 @@ class DocumentsStage implements StageInterface public PackedArray|ResolvesToArray|BSONArray|array $documents; /** - * @param BSONArray|PackedArray|ResolvesToArray|list $documents $documents accepts any valid expression that resolves to an array of objects. This includes: + * @param BSONArray|PackedArray|ResolvesToArray|list $documents $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 diff --git a/src/Builder/Stage/FillStage.php b/src/Builder/Stage/FillStage.php index ed7ec11f2..fc7bb807d 100644 --- a/src/Builder/Stage/FillStage.php +++ b/src/Builder/Stage/FillStage.php @@ -39,7 +39,7 @@ class FillStage implements StageInterface public Document|Serializable|Optional|stdClass|array|string $partitionBy; /** - * @param BSONArray|Optional|PackedArray|list $partitionByFields 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. + * @param BSONArray|Optional|PackedArray|list $partitionByFields 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. */ @@ -54,7 +54,7 @@ class FillStage implements StageInterface * @param Document|Optional|Serializable|array|non-empty-string|stdClass $partitionBy 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. - * @param BSONArray|Optional|PackedArray|list $partitionByFields 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. + * @param BSONArray|Optional|PackedArray|list $partitionByFields 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. * @param Optional|array|stdClass $sortBy Specifies the field or fields to sort the documents within each partition. Uses the same syntax as the $sort stage. diff --git a/src/Builder/Stage/GraphLookupStage.php b/src/Builder/Stage/GraphLookupStage.php index 1f2c3e156..2333d7f93 100644 --- a/src/Builder/Stage/GraphLookupStage.php +++ b/src/Builder/Stage/GraphLookupStage.php @@ -31,7 +31,7 @@ class GraphLookupStage implements StageInterface */ public string $from; - /** @param BSONArray|ExpressionInterface|PackedArray|list|mixed $startWith 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. */ + /** @param BSONArray|ExpressionInterface|PackedArray|list|mixed $startWith 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. */ public mixed $startWith; /** @param non-empty-string $connectFromField 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. */ @@ -55,7 +55,7 @@ class GraphLookupStage implements StageInterface /** * @param non-empty-string $from 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. - * @param BSONArray|ExpressionInterface|PackedArray|list|mixed $startWith 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. + * @param BSONArray|ExpressionInterface|PackedArray|list|mixed $startWith 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. * @param non-empty-string $connectFromField 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. * @param non-empty-string $connectToField Field name in other documents against which to match the value of the field specified by the connectFromField parameter. * @param non-empty-string $as Name of the array field added to each output document. Contains the documents traversed in the $graphLookup stage to reach the document. diff --git a/src/Builder/Stage/ListLocalSessionsStage.php b/src/Builder/Stage/ListLocalSessionsStage.php index aace2ab7a..fe8f35fbc 100644 --- a/src/Builder/Stage/ListLocalSessionsStage.php +++ b/src/Builder/Stage/ListLocalSessionsStage.php @@ -22,14 +22,14 @@ class ListLocalSessionsStage implements StageInterface public const NAME = '$listLocalSessions'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param BSONArray|Optional|PackedArray|list $users 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. */ + /** @param BSONArray|Optional|PackedArray|list $users 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. */ public PackedArray|Optional|BSONArray|array $users; /** @param Optional|bool $allUsers Returns all sessions for all users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster. */ public Optional|bool $allUsers; /** - * @param BSONArray|Optional|PackedArray|list $users 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. + * @param BSONArray|Optional|PackedArray|list $users 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. * @param Optional|bool $allUsers Returns all sessions for all users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster. */ public function __construct( diff --git a/src/Builder/Stage/ListSessionsStage.php b/src/Builder/Stage/ListSessionsStage.php index 00396493c..45a94f87f 100644 --- a/src/Builder/Stage/ListSessionsStage.php +++ b/src/Builder/Stage/ListSessionsStage.php @@ -22,14 +22,14 @@ class ListSessionsStage implements StageInterface public const NAME = '$listSessions'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param BSONArray|Optional|PackedArray|list $users 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. */ + /** @param BSONArray|Optional|PackedArray|list $users 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. */ public PackedArray|Optional|BSONArray|array $users; /** @param Optional|bool $allUsers Returns all sessions for all users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster. */ public Optional|bool $allUsers; /** - * @param BSONArray|Optional|PackedArray|list $users 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. + * @param BSONArray|Optional|PackedArray|list $users 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. * @param Optional|bool $allUsers Returns all sessions for all users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster. */ public function __construct( diff --git a/src/Builder/Stage/MergeStage.php b/src/Builder/Stage/MergeStage.php index 925fb4955..f200ffd4b 100644 --- a/src/Builder/Stage/MergeStage.php +++ b/src/Builder/Stage/MergeStage.php @@ -29,7 +29,7 @@ class MergeStage implements StageInterface /** @param array|non-empty-string|stdClass $into The output collection. */ public stdClass|array|string $into; - /** @param BSONArray|Optional|PackedArray|list|non-empty-string $on 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. */ + /** @param BSONArray|Optional|PackedArray|list|non-empty-string $on 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. */ public PackedArray|Optional|BSONArray|array|string $on; /** @param Document|Optional|Serializable|array|stdClass $let Specifies variables for use in the whenMatched pipeline. */ @@ -43,7 +43,7 @@ class MergeStage implements StageInterface /** * @param array|non-empty-string|stdClass $into The output collection. - * @param BSONArray|Optional|PackedArray|list|non-empty-string $on 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. + * @param BSONArray|Optional|PackedArray|list|non-empty-string $on 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. * @param Document|Optional|Serializable|array|stdClass $let Specifies variables for use in the whenMatched pipeline. * @param Optional|non-empty-string $whenMatched 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). * @param Optional|non-empty-string $whenNotMatched The behavior of $merge if a result document does not match an existing document in the out collection. From 06c5294598bfaeef0235b7205921a806c7f3aca7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Mon, 9 Oct 2023 16:27:06 +0200 Subject: [PATCH 19/37] Improve operator classification and add all BSON types --- .gitattributes | 1 - .../aggregation-operators/accumulator.yaml | 2 +- .../aggregation-operators/addToSet.yaml | 2 +- .../aggregation-operators/arrayElemAt.yaml | 2 +- .../config/aggregation-operators/avg.yaml | 2 +- .../aggregation-operators/binarySize.yaml | 2 +- .../config/aggregation-operators/bottom.yaml | 2 +- .../config/aggregation-operators/bottomN.yaml | 2 +- .../config/aggregation-operators/cond.yaml | 2 +- .../config/aggregation-operators/convert.yaml | 2 +- .../config/aggregation-operators/count.yaml | 2 +- .../aggregation-operators/expMovingAvg.yaml | 2 +- .../config/aggregation-operators/first.yaml | 4 +- .../config/aggregation-operators/firstN.yaml | 2 +- .../aggregation-operators/function.yaml | 2 +- .../aggregation-operators/getField.yaml | 2 +- .../config/aggregation-operators/ifNull.yaml | 2 +- .../config/aggregation-operators/last.yaml | 4 +- .../config/aggregation-operators/let.yaml | 2 +- .../config/aggregation-operators/literal.yaml | 2 +- .../config/aggregation-operators/locf.yaml | 2 +- .../config/aggregation-operators/max.yaml | 4 +- .../config/aggregation-operators/median.yaml | 2 +- .../aggregation-operators/mergeObjects.yaml | 2 +- .../config/aggregation-operators/min.yaml | 4 +- .../aggregation-operators/percentile.yaml | 2 +- .../config/aggregation-operators/push.yaml | 2 +- .../config/aggregation-operators/rand.yaml | 2 +- .../config/aggregation-operators/reduce.yaml | 2 +- .../aggregation-operators/regexFind.yaml | 2 +- .../aggregation-operators/regexFindAll.yaml | 2 +- .../aggregation-operators/regexMatch.yaml | 2 +- .../config/aggregation-operators/round.yaml | 2 +- .../aggregation-operators/sampleRate.yaml | 4 +- .../config/aggregation-operators/shift.yaml | 2 +- .../aggregation-operators/stdDevPop.yaml | 2 +- .../aggregation-operators/stdDevSamp.yaml | 2 +- .../config/aggregation-operators/sum.yaml | 2 +- .../config/aggregation-operators/switch.yaml | 2 +- .../config/aggregation-operators/top.yaml | 2 +- .../config/aggregation-operators/topN.yaml | 2 +- .../config/aggregation-stages/addFields.yaml | 2 +- .../config/aggregation-stages/bucket.yaml | 2 +- .../config/aggregation-stages/bucketAuto.yaml | 2 +- .../aggregation-stages/changeStream.yaml | 4 +- .../changeStreamSplitLargeEvent.yaml | 2 +- .../config/aggregation-stages/collStats.yaml | 2 +- .../config/aggregation-stages/count.yaml | 2 +- .../config/aggregation-stages/currentOp.yaml | 2 +- .../config/aggregation-stages/densify.yaml | 4 +- .../config/aggregation-stages/documents.yaml | 2 +- .../config/aggregation-stages/facet.yaml | 4 +- generator/config/aggregation-stages/fill.yaml | 2 +- .../config/aggregation-stages/geoNear.yaml | 4 +- .../aggregation-stages/graphLookup.yaml | 4 +- .../config/aggregation-stages/group.yaml | 4 +- .../config/aggregation-stages/indexStats.yaml | 2 +- .../config/aggregation-stages/limit.yaml | 2 +- .../aggregation-stages/listLocalSessions.yaml | 2 +- .../listSampledQueries.yaml | 2 +- .../aggregation-stages/listSearchIndexes.yaml | 2 +- .../aggregation-stages/listSessions.yaml | 2 +- .../config/aggregation-stages/lookup.yaml | 4 +- .../config/aggregation-stages/match.yaml | 4 +- .../config/aggregation-stages/merge.yaml | 2 +- generator/config/aggregation-stages/out.yaml | 2 +- .../aggregation-stages/planCacheStats.yaml | 2 +- .../config/aggregation-stages/project.yaml | 6 +- .../config/aggregation-stages/redact.yaml | 2 +- .../aggregation-stages/replaceRoot.yaml | 2 +- .../aggregation-stages/replaceWith.yaml | 2 +- .../config/aggregation-stages/sample.yaml | 2 +- .../config/aggregation-stages/search.yaml | 2 +- .../config/aggregation-stages/searchMeta.yaml | 2 +- generator/config/aggregation-stages/set.yaml | 2 +- .../aggregation-stages/setWindowFields.yaml | 2 +- .../shardedDataDistribution.yaml | 2 +- generator/config/aggregation-stages/skip.yaml | 2 +- generator/config/aggregation-stages/sort.yaml | 2 +- .../aggregation-stages/sortByCount.yaml | 2 +- .../config/aggregation-stages/unionWith.yaml | 4 +- .../config/aggregation-stages/unset.yaml | 4 +- .../config/aggregation-stages/unwind.yaml | 4 +- generator/config/expressions.php | 294 +++--- generator/config/query-operators/all.yaml | 2 +- generator/config/query-operators/and.yaml | 4 +- .../config/query-operators/bitsAllClear.yaml | 4 +- .../config/query-operators/bitsAllSet.yaml | 4 +- .../config/query-operators/bitsAnyClear.yaml | 4 +- .../config/query-operators/bitsAnySet.yaml | 4 +- generator/config/query-operators/box.yaml | 2 +- generator/config/query-operators/center.yaml | 2 +- .../config/query-operators/centerSphere.yaml | 2 +- generator/config/query-operators/comment.yaml | 2 +- .../config/query-operators/elemMatch.yaml | 5 +- generator/config/query-operators/eq.yaml | 2 +- generator/config/query-operators/exists.yaml | 2 +- generator/config/query-operators/expr.yaml | 2 +- .../config/query-operators/geoIntersects.yaml | 2 +- .../config/query-operators/geoWithin.yaml | 2 +- .../config/query-operators/geometry.yaml | 2 +- generator/config/query-operators/gt.yaml | 2 +- generator/config/query-operators/gte.yaml | 2 +- generator/config/query-operators/in.yaml | 2 +- .../config/query-operators/jsonSchema.yaml | 2 +- generator/config/query-operators/lt.yaml | 2 +- generator/config/query-operators/lte.yaml | 2 +- .../config/query-operators/maxDistance.yaml | 5 +- generator/config/query-operators/meta.yaml | 2 +- .../config/query-operators/minDistance.yaml | 4 +- generator/config/query-operators/mod.yaml | 2 +- generator/config/query-operators/ne.yaml | 2 +- generator/config/query-operators/near.yaml | 2 +- .../config/query-operators/nearSphere.yaml | 2 +- generator/config/query-operators/nin.yaml | 2 +- generator/config/query-operators/nor.yaml | 4 +- generator/config/query-operators/not.yaml | 4 +- generator/config/query-operators/or.yaml | 4 +- generator/config/query-operators/polygon.yaml | 2 +- .../config/query-operators/positional.yaml | 2 +- generator/config/query-operators/regex.yaml | 4 +- generator/config/query-operators/size.yaml | 2 +- generator/config/query-operators/slice.yaml | 3 +- generator/config/query-operators/text.yaml | 2 +- generator/config/query-operators/type.yaml | 2 +- generator/config/query-operators/where.yaml | 2 +- generator/config/schema.json | 1 - generator/src/AbstractGenerator.php | 3 +- generator/src/CodecClassGenerator.php | 60 ++ generator/src/Command/GenerateCommand.php | 4 +- generator/src/Command/ScrapeCommand.php | 6 +- .../src/Definition/ExpressionDefinition.php | 32 +- generator/src/Definition/Generate.php | 13 + generator/src/Definition/YamlReader.php | 12 +- generator/src/ExpressionClassGenerator.php | 15 +- generator/src/ExpressionFactoryGenerator.php | 9 +- generator/src/OperatorClassGenerator.php | 24 +- generator/src/OperatorFactoryGenerator.php | 2 +- generator/src/OperatorGenerator.php | 55 +- psalm-baseline.xml | 9 - src/Builder/Aggregation.php | 903 ++++++++++-------- src/Builder/Aggregation/AbsAggregation.php | 15 +- .../Aggregation/AccumulatorAggregation.php | 12 +- .../Aggregation/AccumulatorInterface.php | 11 - src/Builder/Aggregation/AcosAggregation.php | 13 +- src/Builder/Aggregation/AcoshAggregation.php | 13 +- src/Builder/Aggregation/AddAggregation.php | 13 +- .../Aggregation/AddToSetAggregation.php | 31 +- .../AllElementsTrueAggregation.php | 7 +- src/Builder/Aggregation/AndAggregation.php | 27 +- .../Aggregation/AnyElementTrueAggregation.php | 6 +- .../Aggregation/ArrayElemAtAggregation.php | 18 +- .../Aggregation/ArrayToObjectAggregation.php | 6 +- src/Builder/Aggregation/AsinAggregation.php | 13 +- src/Builder/Aggregation/AsinhAggregation.php | 13 +- src/Builder/Aggregation/Atan2Aggregation.php | 18 +- src/Builder/Aggregation/AtanAggregation.php | 13 +- src/Builder/Aggregation/AtanhAggregation.php | 13 +- src/Builder/Aggregation/AvgAggregation.php | 16 +- .../Aggregation/BinarySizeAggregation.php | 10 +- src/Builder/Aggregation/BitAndAggregation.php | 2 +- src/Builder/Aggregation/BitOrAggregation.php | 2 +- src/Builder/Aggregation/BitXorAggregation.php | 2 +- src/Builder/Aggregation/BottomAggregation.php | 37 +- .../Aggregation/BottomNAggregation.php | 42 +- src/Builder/Aggregation/CeilAggregation.php | 14 +- src/Builder/Aggregation/CmpAggregation.php | 40 +- src/Builder/Aggregation/ConcatAggregation.php | 2 +- .../Aggregation/ConcatArraysAggregation.php | 7 +- src/Builder/Aggregation/CondAggregation.php | 45 +- .../Aggregation/ConvertAggregation.php | 60 +- src/Builder/Aggregation/CosAggregation.php | 13 +- src/Builder/Aggregation/CoshAggregation.php | 13 +- src/Builder/Aggregation/CountAggregation.php | 1 + .../Aggregation/CovariancePopAggregation.php | 18 +- .../Aggregation/CovarianceSampAggregation.php | 18 +- .../Aggregation/DateAddAggregation.php | 10 +- .../Aggregation/DateDiffAggregation.php | 19 +- .../Aggregation/DateFromPartsAggregation.php | 84 +- .../Aggregation/DateFromStringAggregation.php | 39 +- .../Aggregation/DateSubtractAggregation.php | 10 +- .../Aggregation/DateToPartsAggregation.php | 11 +- .../Aggregation/DateToStringAggregation.php | 33 +- .../Aggregation/DateTruncAggregation.php | 22 +- .../Aggregation/DayOfMonthAggregation.php | 11 +- .../Aggregation/DayOfWeekAggregation.php | 11 +- .../Aggregation/DayOfYearAggregation.php | 11 +- .../DegreesToRadiansAggregation.php | 13 +- .../Aggregation/DerivativeAggregation.php | 12 +- src/Builder/Aggregation/DivideAggregation.php | 19 +- src/Builder/Aggregation/EqAggregation.php | 41 +- src/Builder/Aggregation/ExpAggregation.php | 14 +- .../Aggregation/ExpMovingAvgAggregation.php | 19 +- src/Builder/Aggregation/FilterAggregation.php | 15 +- src/Builder/Aggregation/FirstAggregation.php | 34 +- src/Builder/Aggregation/FirstNAggregation.php | 16 +- src/Builder/Aggregation/FloorAggregation.php | 14 +- .../Aggregation/FunctionAggregation.php | 9 +- .../Aggregation/GetFieldAggregation.php | 34 +- src/Builder/Aggregation/GtAggregation.php | 41 +- src/Builder/Aggregation/GteAggregation.php | 41 +- src/Builder/Aggregation/HourAggregation.php | 11 +- src/Builder/Aggregation/IfNullAggregation.php | 29 +- src/Builder/Aggregation/InAggregation.php | 34 +- .../Aggregation/IndexOfArrayAggregation.php | 41 +- .../Aggregation/IndexOfBytesAggregation.php | 17 +- .../Aggregation/IndexOfCPAggregation.php | 17 +- .../Aggregation/IntegralAggregation.php | 11 +- .../Aggregation/IsArrayAggregation.php | 26 +- .../Aggregation/IsNumberAggregation.php | 26 +- .../Aggregation/IsoDayOfWeekAggregation.php | 11 +- .../Aggregation/IsoWeekAggregation.php | 11 +- .../Aggregation/IsoWeekYearAggregation.php | 11 +- src/Builder/Aggregation/LastAggregation.php | 34 +- src/Builder/Aggregation/LastNAggregation.php | 15 +- src/Builder/Aggregation/LetAggregation.php | 31 +- .../Aggregation/LinearFillAggregation.php | 15 +- .../Aggregation/LiteralAggregation.php | 32 +- src/Builder/Aggregation/LnAggregation.php | 14 +- src/Builder/Aggregation/LocfAggregation.php | 33 +- src/Builder/Aggregation/Log10Aggregation.php | 14 +- src/Builder/Aggregation/LogAggregation.php | 19 +- src/Builder/Aggregation/LtAggregation.php | 41 +- src/Builder/Aggregation/LteAggregation.php | 41 +- src/Builder/Aggregation/MapAggregation.php | 30 +- src/Builder/Aggregation/MaxAggregation.php | 30 +- src/Builder/Aggregation/MaxNAggregation.php | 15 +- src/Builder/Aggregation/MedianAggregation.php | 16 +- .../Aggregation/MergeObjectsAggregation.php | 3 +- .../Aggregation/MillisecondAggregation.php | 11 +- src/Builder/Aggregation/MinAggregation.php | 30 +- src/Builder/Aggregation/MinNAggregation.php | 15 +- src/Builder/Aggregation/MinuteAggregation.php | 11 +- src/Builder/Aggregation/ModAggregation.php | 19 +- src/Builder/Aggregation/MonthAggregation.php | 11 +- .../Aggregation/MultiplyAggregation.php | 14 +- src/Builder/Aggregation/NeAggregation.php | 41 +- src/Builder/Aggregation/NotAggregation.php | 30 +- src/Builder/Aggregation/OrAggregation.php | 26 +- .../Aggregation/PercentileAggregation.php | 19 +- src/Builder/Aggregation/PowAggregation.php | 20 +- src/Builder/Aggregation/PushAggregation.php | 31 +- .../RadiansToDegreesAggregation.php | 13 +- src/Builder/Aggregation/RandAggregation.php | 4 +- src/Builder/Aggregation/RangeAggregation.php | 25 +- src/Builder/Aggregation/ReduceAggregation.php | 48 +- .../Aggregation/ReverseArrayAggregation.php | 6 +- src/Builder/Aggregation/RoundAggregation.php | 8 +- .../Aggregation/SampleRateAggregation.php | 14 +- src/Builder/Aggregation/SecondAggregation.php | 11 +- .../Aggregation/SetDifferenceAggregation.php | 11 +- .../Aggregation/SetEqualsAggregation.php | 7 +- .../Aggregation/SetFieldAggregation.php | 24 +- .../SetIntersectionAggregation.php | 7 +- .../Aggregation/SetIsSubsetAggregation.php | 11 +- .../Aggregation/SetUnionAggregation.php | 7 +- src/Builder/Aggregation/ShiftAggregation.php | 50 +- src/Builder/Aggregation/SinAggregation.php | 13 +- src/Builder/Aggregation/SinhAggregation.php | 13 +- src/Builder/Aggregation/SizeAggregation.php | 6 +- src/Builder/Aggregation/SliceAggregation.php | 23 +- .../Aggregation/SortArrayAggregation.php | 20 +- src/Builder/Aggregation/SqrtAggregation.php | 14 +- .../Aggregation/StdDevPopAggregation.php | 15 +- .../Aggregation/StdDevSampAggregation.php | 15 +- src/Builder/Aggregation/SubstrAggregation.php | 20 +- .../Aggregation/SubstrBytesAggregation.php | 20 +- .../Aggregation/SubstrCPAggregation.php | 20 +- .../Aggregation/SubtractAggregation.php | 21 +- src/Builder/Aggregation/SumAggregation.php | 16 +- src/Builder/Aggregation/SwitchAggregation.php | 37 +- src/Builder/Aggregation/TanAggregation.php | 13 +- src/Builder/Aggregation/TanhAggregation.php | 13 +- src/Builder/Aggregation/ToBoolAggregation.php | 30 +- src/Builder/Aggregation/ToDateAggregation.php | 30 +- .../Aggregation/ToDecimalAggregation.php | 30 +- .../Aggregation/ToDoubleAggregation.php | 30 +- src/Builder/Aggregation/ToIntAggregation.php | 29 +- src/Builder/Aggregation/ToLongAggregation.php | 30 +- .../Aggregation/ToObjectIdAggregation.php | 30 +- .../Aggregation/ToStringAggregation.php | 30 +- src/Builder/Aggregation/TopAggregation.php | 37 +- src/Builder/Aggregation/TopNAggregation.php | 42 +- src/Builder/Aggregation/TruncAggregation.php | 19 +- .../Aggregation/TsIncrementAggregation.php | 10 +- .../Aggregation/TsSecondAggregation.php | 10 +- src/Builder/Aggregation/TypeAggregation.php | 30 +- src/Builder/Aggregation/WeekAggregation.php | 11 +- src/Builder/Aggregation/YearAggregation.php | 11 +- src/Builder/Aggregation/ZipAggregation.php | 11 +- src/Builder/BuilderEncoder.php | 8 +- src/Builder/Expression.php | 30 +- ...naryFieldPath.php => BinDataFieldPath.php} | 2 +- src/Builder/Expression/FieldPath.php | 2 + ...tFieldPath.php => JavascriptFieldPath.php} | 2 +- src/Builder/Expression/Literal.php | 17 - .../{FieldName.php => RegexFieldPath.php} | 2 +- ...ResolvesToBinary.php => ResolvesToAny.php} | 4 +- src/Builder/Expression/ResolvesToArray.php | 2 + ...ionInterface.php => ResolvesToBinData.php} | 4 +- src/Builder/Expression/ResolvesToBool.php | 2 + src/Builder/Expression/ResolvesToDate.php | 2 + src/Builder/Expression/ResolvesToDecimal.php | 4 +- src/Builder/Expression/ResolvesToDouble.php | 4 +- src/Builder/Expression/ResolvesToFloat.php | 11 - src/Builder/Expression/ResolvesToInt.php | 4 +- ...ionObject.php => ResolvesToJavascript.php} | 4 +- src/Builder/Expression/ResolvesToLong.php | 4 +- src/Builder/Expression/ResolvesToNull.php | 2 + src/Builder/Expression/ResolvesToNumber.php | 2 + src/Builder/Expression/ResolvesToObject.php | 2 + src/Builder/Expression/ResolvesToObjectId.php | 2 + .../{Operator.php => ResolvesToRegex.php} | 4 +- src/Builder/Expression/ResolvesToString.php | 2 + .../Expression/ResolvesToTimestamp.php | 4 +- src/Builder/Expression/Variable.php | 2 + src/Builder/Pipeline.php | 2 +- src/Builder/Query.php | 172 ++-- src/Builder/Query/AllQuery.php | 25 +- src/Builder/Query/AndQuery.php | 11 +- src/Builder/Query/BitsAllClearQuery.php | 12 +- src/Builder/Query/BitsAllSetQuery.php | 12 +- src/Builder/Query/BitsAnyClearQuery.php | 12 +- src/Builder/Query/BitsAnySetQuery.php | 12 +- src/Builder/Query/BoxQuery.php | 7 +- src/Builder/Query/CenterQuery.php | 7 +- src/Builder/Query/CenterSphereQuery.php | 7 +- src/Builder/Query/CommentQuery.php | 4 +- src/Builder/Query/ElemMatchQuery.php | 12 +- src/Builder/Query/EqQuery.php | 29 +- src/Builder/Query/ExistsQuery.php | 1 + src/Builder/Query/ExprQuery.php | 31 +- src/Builder/Query/GeoIntersectsQuery.php | 11 +- src/Builder/Query/GeoWithinQuery.php | 11 +- src/Builder/Query/GeometryQuery.php | 9 +- src/Builder/Query/GtQuery.php | 29 +- src/Builder/Query/GteQuery.php | 29 +- src/Builder/Query/InQuery.php | 7 +- src/Builder/Query/JsonSchemaQuery.php | 1 + src/Builder/Query/LtQuery.php | 29 +- src/Builder/Query/LteQuery.php | 29 +- src/Builder/Query/MaxDistanceQuery.php | 17 +- src/Builder/Query/MetaQuery.php | 4 +- src/Builder/Query/MinDistanceQuery.php | 1 + src/Builder/Query/ModQuery.php | 16 +- src/Builder/Query/NaturalQuery.php | 2 +- src/Builder/Query/NeQuery.php | 29 +- src/Builder/Query/NearQuery.php | 28 +- src/Builder/Query/NearSphereQuery.php | 28 +- src/Builder/Query/NinQuery.php | 7 +- src/Builder/Query/NorQuery.php | 11 +- src/Builder/Query/NotQuery.php | 11 +- src/Builder/Query/OrQuery.php | 11 +- src/Builder/Query/PolygonQuery.php | 7 +- src/Builder/Query/QueryInterface.php | 11 - src/Builder/Query/RandQuery.php | 2 +- src/Builder/Query/RegexQuery.php | 1 + src/Builder/Query/SizeQuery.php | 10 +- src/Builder/Query/SliceQuery.php | 19 +- src/Builder/Query/TextQuery.php | 1 + src/Builder/Query/TypeQuery.php | 12 +- src/Builder/Query/WhereQuery.php | 1 + src/Builder/Stage.php | 182 ++-- src/Builder/Stage/AddFieldsStage.php | 26 +- src/Builder/Stage/BucketAutoStage.php | 32 +- src/Builder/Stage/BucketStage.php | 40 +- .../ChangeStreamSplitLargeEventStage.php | 1 + src/Builder/Stage/ChangeStreamStage.php | 19 +- src/Builder/Stage/CollStatsStage.php | 1 + src/Builder/Stage/CountStage.php | 1 + src/Builder/Stage/CurrentOpStage.php | 1 + src/Builder/Stage/DensifyStage.php | 17 +- src/Builder/Stage/DocumentsStage.php | 7 +- src/Builder/Stage/FacetStage.php | 11 +- src/Builder/Stage/FillStage.php | 15 +- src/Builder/Stage/GeoNearStage.php | 49 +- src/Builder/Stage/GraphLookupStage.php | 39 +- src/Builder/Stage/GroupStage.php | 39 +- src/Builder/Stage/IndexStatsStage.php | 1 + src/Builder/Stage/LimitStage.php | 10 +- src/Builder/Stage/ListLocalSessionsStage.php | 7 +- src/Builder/Stage/ListSampledQueriesStage.php | 1 + src/Builder/Stage/ListSearchIndexesStage.php | 1 + src/Builder/Stage/ListSessionsStage.php | 7 +- src/Builder/Stage/LookupStage.php | 15 +- src/Builder/Stage/MatchStage.php | 13 +- src/Builder/Stage/MergeStage.php | 15 +- src/Builder/Stage/OutStage.php | 1 + src/Builder/Stage/PlanCacheStatsStage.php | 1 + src/Builder/Stage/ProjectStage.php | 18 +- src/Builder/Stage/RedactStage.php | 31 +- src/Builder/Stage/ReplaceRootStage.php | 1 + src/Builder/Stage/ReplaceWithStage.php | 1 + src/Builder/Stage/SampleStage.php | 10 +- src/Builder/Stage/SearchMetaStage.php | 1 + src/Builder/Stage/SearchStage.php | 1 + src/Builder/Stage/SetStage.php | 26 +- src/Builder/Stage/SetWindowFieldsStage.php | 41 +- .../Stage/ShardedDataDistributionStage.php | 1 + src/Builder/Stage/SkipStage.php | 10 +- src/Builder/Stage/SortByCountStage.php | 31 +- src/Builder/Stage/SortStage.php | 11 +- src/Builder/Stage/StageInterface.php | 7 - src/Builder/Stage/UnionWithStage.php | 19 +- src/Builder/Stage/UnsetStage.php | 3 +- src/Builder/Stage/UnwindStage.php | 1 + src/Builder/Type/AccumulatorInterface.php | 16 + src/Builder/Type/ExpressionInterface.php | 13 + .../Type/OperatorExpressionInterface.php | 8 + src/Builder/Type/ProjectionInterface.php | 12 + src/Builder/Type/QueryInterface.php | 16 + src/Builder/Type/StageInterface.php | 12 + 412 files changed, 4076 insertions(+), 2406 deletions(-) create mode 100644 generator/src/CodecClassGenerator.php create mode 100644 generator/src/Definition/Generate.php delete mode 100644 src/Builder/Aggregation/AccumulatorInterface.php rename src/Builder/Expression/{BinaryFieldPath.php => BinDataFieldPath.php} (78%) rename src/Builder/Expression/{FloatFieldPath.php => JavascriptFieldPath.php} (76%) delete mode 100644 src/Builder/Expression/Literal.php rename src/Builder/Expression/{FieldName.php => RegexFieldPath.php} (79%) rename src/Builder/Expression/{ResolvesToBinary.php => ResolvesToAny.php} (54%) rename src/Builder/Expression/{ExpressionInterface.php => ResolvesToBinData.php} (53%) delete mode 100644 src/Builder/Expression/ResolvesToFloat.php rename src/Builder/Expression/{ExpressionObject.php => ResolvesToJavascript.php} (52%) rename src/Builder/Expression/{Operator.php => ResolvesToRegex.php} (53%) delete mode 100644 src/Builder/Query/QueryInterface.php delete mode 100644 src/Builder/Stage/StageInterface.php create mode 100644 src/Builder/Type/AccumulatorInterface.php create mode 100644 src/Builder/Type/ExpressionInterface.php create mode 100644 src/Builder/Type/OperatorExpressionInterface.php create mode 100644 src/Builder/Type/ProjectionInterface.php create mode 100644 src/Builder/Type/QueryInterface.php create mode 100644 src/Builder/Type/StageInterface.php diff --git a/.gitattributes b/.gitattributes index 64c458128..8343031d6 100644 --- a/.gitattributes +++ b/.gitattributes @@ -26,4 +26,3 @@ psalm-baseline.xml export-ignore /src/Builder/Query/*.php linguist-generated=true /src/Builder/Stage.php linguist-generated=true /src/Builder/Stage/*.php linguist-generated=true -/src/Builder/Stage/Stage.php linguist-generated=false diff --git a/generator/config/aggregation-operators/accumulator.yaml b/generator/config/aggregation-operators/accumulator.yaml index c4071c6d1..8164d9bbf 100644 --- a/generator/config/aggregation-operators/accumulator.yaml +++ b/generator/config/aggregation-operators/accumulator.yaml @@ -5,7 +5,7 @@ category: - 'Custom Aggregation Expression Operator' link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/accumulator/' type: - - Accumulator + - accumulator encode: object description: | Defines a custom accumulator function. diff --git a/generator/config/aggregation-operators/addToSet.yaml b/generator/config/aggregation-operators/addToSet.yaml index 32d3b5042..a33be309d 100644 --- a/generator/config/aggregation-operators/addToSet.yaml +++ b/generator/config/aggregation-operators/addToSet.yaml @@ -5,7 +5,7 @@ category: - 'Window Operator' link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/addToSet/' type: - - Accumulator + - accumulator encode: single description: | Returns an array of unique expression values for each group. Order of the array elements is undefined. diff --git a/generator/config/aggregation-operators/arrayElemAt.yaml b/generator/config/aggregation-operators/arrayElemAt.yaml index 9f0119ed9..692236af0 100644 --- a/generator/config/aggregation-operators/arrayElemAt.yaml +++ b/generator/config/aggregation-operators/arrayElemAt.yaml @@ -4,7 +4,7 @@ category: - 'Array Expression Operator' link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/arrayElemAt/' type: - - resolvesToAnything + - resolvesToAny encode: array description: | Returns the element at the specified array index. diff --git a/generator/config/aggregation-operators/avg.yaml b/generator/config/aggregation-operators/avg.yaml index c2a7eaee9..47e558d42 100644 --- a/generator/config/aggregation-operators/avg.yaml +++ b/generator/config/aggregation-operators/avg.yaml @@ -7,7 +7,7 @@ category: link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/avg/' type: - resolvesToNumber - - Accumulator + - accumulator encode: single description: | Returns an average of numerical values. Ignores non-numeric values. diff --git a/generator/config/aggregation-operators/binarySize.yaml b/generator/config/aggregation-operators/binarySize.yaml index 7b2af86cd..0561f2450 100644 --- a/generator/config/aggregation-operators/binarySize.yaml +++ b/generator/config/aggregation-operators/binarySize.yaml @@ -13,5 +13,5 @@ arguments: name: expression type: - resolvesToString - - resolvesToBinary + - resolvesToBinData - resolvesToNull diff --git a/generator/config/aggregation-operators/bottom.yaml b/generator/config/aggregation-operators/bottom.yaml index 22c69b337..9360482eb 100644 --- a/generator/config/aggregation-operators/bottom.yaml +++ b/generator/config/aggregation-operators/bottom.yaml @@ -5,7 +5,7 @@ category: - 'Window Operator' link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/bottom/' type: - - Accumulator + - accumulator encode: object description: | Returns the bottom element within a group according to the specified sort order. diff --git a/generator/config/aggregation-operators/bottomN.yaml b/generator/config/aggregation-operators/bottomN.yaml index d4ce53d16..385e4aed2 100644 --- a/generator/config/aggregation-operators/bottomN.yaml +++ b/generator/config/aggregation-operators/bottomN.yaml @@ -5,7 +5,7 @@ category: - 'Window Operator' link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/bottomN/' type: - - Accumulator + - accumulator encode: object description: | Returns an aggregation of the bottom n elements within a group, according to the specified sort order. If the group contains fewer than n elements, $bottomN returns all elements in the group. diff --git a/generator/config/aggregation-operators/cond.yaml b/generator/config/aggregation-operators/cond.yaml index 5630dd00c..508782613 100644 --- a/generator/config/aggregation-operators/cond.yaml +++ b/generator/config/aggregation-operators/cond.yaml @@ -4,7 +4,7 @@ category: - 'Conditional Expression Operator' link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/cond/' type: - - resolvesToAnything + - 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. diff --git a/generator/config/aggregation-operators/convert.yaml b/generator/config/aggregation-operators/convert.yaml index 20e1f17ab..3fea95896 100644 --- a/generator/config/aggregation-operators/convert.yaml +++ b/generator/config/aggregation-operators/convert.yaml @@ -4,7 +4,7 @@ category: - 'Type Expression Operator' link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/convert/' type: - - resolvesToAnything + - resolvesToAny encode: object description: | Converts a value to a specified type. diff --git a/generator/config/aggregation-operators/count.yaml b/generator/config/aggregation-operators/count.yaml index 828ae9f56..b83f1d389 100644 --- a/generator/config/aggregation-operators/count.yaml +++ b/generator/config/aggregation-operators/count.yaml @@ -5,7 +5,7 @@ category: - 'Window Operator' link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/count/' type: - - Accumulator + - accumulator encode: object description: | Returns the number of documents in the group or window. diff --git a/generator/config/aggregation-operators/expMovingAvg.yaml b/generator/config/aggregation-operators/expMovingAvg.yaml index f380fc715..accaa5646 100644 --- a/generator/config/aggregation-operators/expMovingAvg.yaml +++ b/generator/config/aggregation-operators/expMovingAvg.yaml @@ -26,7 +26,7 @@ arguments: - name: alpha type: - - float + - 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. diff --git a/generator/config/aggregation-operators/first.yaml b/generator/config/aggregation-operators/first.yaml index 64597678f..78e08619a 100644 --- a/generator/config/aggregation-operators/first.yaml +++ b/generator/config/aggregation-operators/first.yaml @@ -6,8 +6,8 @@ category: - 'Window Operator' link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/first/' type: - - resolvesToAnything - - Accumulator + - resolvesToAny + - accumulator encode: single description: | Returns the result of an expression for the first document in a group or window. diff --git a/generator/config/aggregation-operators/firstN.yaml b/generator/config/aggregation-operators/firstN.yaml index fd2af2411..fb8499292 100644 --- a/generator/config/aggregation-operators/firstN.yaml +++ b/generator/config/aggregation-operators/firstN.yaml @@ -4,7 +4,7 @@ category: - 'Array Expression Operator' link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/firstN-array-element/' type: - - Accumulator + - accumulator encode: object description: | Returns a specified number of elements from the beginning of an array. Distinct from the $firstN accumulator. diff --git a/generator/config/aggregation-operators/function.yaml b/generator/config/aggregation-operators/function.yaml index ee21d5b58..423744173 100644 --- a/generator/config/aggregation-operators/function.yaml +++ b/generator/config/aggregation-operators/function.yaml @@ -4,7 +4,7 @@ category: - 'Custom Aggregation Expression Operator' link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/function/' type: - - resolvesToAnything + - resolvesToAny encode: object description: | Defines a custom function. diff --git a/generator/config/aggregation-operators/getField.yaml b/generator/config/aggregation-operators/getField.yaml index 3870bb83f..d6c4cfbd5 100644 --- a/generator/config/aggregation-operators/getField.yaml +++ b/generator/config/aggregation-operators/getField.yaml @@ -4,7 +4,7 @@ category: - 'Miscellaneous Operator' link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/getField/' type: - - resolvesToAnything + - resolvesToAny encode: object 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 ($). diff --git a/generator/config/aggregation-operators/ifNull.yaml b/generator/config/aggregation-operators/ifNull.yaml index 089a0721b..2a63a204d 100644 --- a/generator/config/aggregation-operators/ifNull.yaml +++ b/generator/config/aggregation-operators/ifNull.yaml @@ -4,7 +4,7 @@ category: - 'Conditional Expression Operator' link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/ifNull/' type: - - resolvesToAnything + - 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. diff --git a/generator/config/aggregation-operators/last.yaml b/generator/config/aggregation-operators/last.yaml index bbe68eb5c..aa1463cd6 100644 --- a/generator/config/aggregation-operators/last.yaml +++ b/generator/config/aggregation-operators/last.yaml @@ -6,8 +6,8 @@ category: - 'Window Operator' link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/last/' type: - - resolvesToAnything - - Accumulator + - resolvesToAny + - accumulator encode: single description: | Returns the result of an expression for the last document in a group or window. diff --git a/generator/config/aggregation-operators/let.yaml b/generator/config/aggregation-operators/let.yaml index 36d40ced7..01a597644 100644 --- a/generator/config/aggregation-operators/let.yaml +++ b/generator/config/aggregation-operators/let.yaml @@ -4,7 +4,7 @@ category: - 'Variable Expression Operator' link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/let/' type: - - resolvesToAnything + - resolvesToAny encode: object description: | Defines variables for use within the scope of a subexpression and returns the result of the subexpression. Accepts named parameters. diff --git a/generator/config/aggregation-operators/literal.yaml b/generator/config/aggregation-operators/literal.yaml index e7ae6ff5b..87991ee38 100644 --- a/generator/config/aggregation-operators/literal.yaml +++ b/generator/config/aggregation-operators/literal.yaml @@ -4,7 +4,7 @@ category: - 'Literal Expression Operator' link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/literal/' type: - - resolvesToAnything + - 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. diff --git a/generator/config/aggregation-operators/locf.yaml b/generator/config/aggregation-operators/locf.yaml index a0e9a065d..30e159e91 100644 --- a/generator/config/aggregation-operators/locf.yaml +++ b/generator/config/aggregation-operators/locf.yaml @@ -4,7 +4,7 @@ category: - 'Window Operator' link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/locf/' type: - - resolvesToAnything + - resolvesToAny encode: single description: | Last observation carried forward. Sets values for null and missing fields in a window to the last non-null value for the field. diff --git a/generator/config/aggregation-operators/max.yaml b/generator/config/aggregation-operators/max.yaml index 491a7a01b..4061f78c7 100644 --- a/generator/config/aggregation-operators/max.yaml +++ b/generator/config/aggregation-operators/max.yaml @@ -6,8 +6,8 @@ category: - 'Window Operator' link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/max/' type: - - resolvesToAnything - - Accumulator + - resolvesToAny + - accumulator encode: single description: | Returns the maximum value that results from applying an expression to each document. diff --git a/generator/config/aggregation-operators/median.yaml b/generator/config/aggregation-operators/median.yaml index 39089b699..cf679c119 100644 --- a/generator/config/aggregation-operators/median.yaml +++ b/generator/config/aggregation-operators/median.yaml @@ -6,7 +6,7 @@ category: link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/median/' type: - resolvesToDouble - - Accumulator + - accumulator encode: object description: | Returns an approximation of the median, the 50th percentile, as a scalar value. diff --git a/generator/config/aggregation-operators/mergeObjects.yaml b/generator/config/aggregation-operators/mergeObjects.yaml index 28f0ad85c..d9a20633d 100644 --- a/generator/config/aggregation-operators/mergeObjects.yaml +++ b/generator/config/aggregation-operators/mergeObjects.yaml @@ -5,7 +5,7 @@ category: - 'Object Expression Operator' link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/mergeObjects/' type: - - Accumulator + - accumulator encode: single description: | Combines multiple documents into a single document. diff --git a/generator/config/aggregation-operators/min.yaml b/generator/config/aggregation-operators/min.yaml index d581c2cc2..30d6f1acb 100644 --- a/generator/config/aggregation-operators/min.yaml +++ b/generator/config/aggregation-operators/min.yaml @@ -6,8 +6,8 @@ category: - 'Window Operator' link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/min/' type: - - resolvesToAnything - - Accumulator + - resolvesToAny + - accumulator encode: single description: | Returns the minimum value that results from applying an expression to each document. diff --git a/generator/config/aggregation-operators/percentile.yaml b/generator/config/aggregation-operators/percentile.yaml index 2efefd783..6de131fb6 100644 --- a/generator/config/aggregation-operators/percentile.yaml +++ b/generator/config/aggregation-operators/percentile.yaml @@ -6,7 +6,7 @@ category: link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/percentile/' type: - resolvesToArray - - Accumulator + - accumulator encode: object description: | Returns an array of scalar values that correspond to specified percentile values. diff --git a/generator/config/aggregation-operators/push.yaml b/generator/config/aggregation-operators/push.yaml index abc36eabc..2a190ce5d 100644 --- a/generator/config/aggregation-operators/push.yaml +++ b/generator/config/aggregation-operators/push.yaml @@ -5,7 +5,7 @@ category: - 'Window Operator' link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/push/' type: - - Accumulator + - accumulator encode: single description: | Returns an array of values that result from applying an expression to each document. diff --git a/generator/config/aggregation-operators/rand.yaml b/generator/config/aggregation-operators/rand.yaml index ff8954bb1..aed23bc8a 100644 --- a/generator/config/aggregation-operators/rand.yaml +++ b/generator/config/aggregation-operators/rand.yaml @@ -4,7 +4,7 @@ category: - 'Miscellaneous Operator' link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/rand/' type: - - resolvesToFloat + - resolvesToDouble encode: object description: | Returns a random float between 0 and 1 diff --git a/generator/config/aggregation-operators/reduce.yaml b/generator/config/aggregation-operators/reduce.yaml index e4c3ec6cb..439602c8c 100644 --- a/generator/config/aggregation-operators/reduce.yaml +++ b/generator/config/aggregation-operators/reduce.yaml @@ -4,7 +4,7 @@ category: - 'Array Expression Operator' link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/reduce/' type: - - resolvesToAnything + - resolvesToAny encode: object description: | Applies an expression to each element in an array and combines them into a single value. diff --git a/generator/config/aggregation-operators/regexFind.yaml b/generator/config/aggregation-operators/regexFind.yaml index 92293f6dd..808bbc650 100644 --- a/generator/config/aggregation-operators/regexFind.yaml +++ b/generator/config/aggregation-operators/regexFind.yaml @@ -20,7 +20,7 @@ arguments: name: regex type: - resolvesToString - - Regex + - 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) - diff --git a/generator/config/aggregation-operators/regexFindAll.yaml b/generator/config/aggregation-operators/regexFindAll.yaml index 4fae32660..498b0e2a1 100644 --- a/generator/config/aggregation-operators/regexFindAll.yaml +++ b/generator/config/aggregation-operators/regexFindAll.yaml @@ -20,7 +20,7 @@ arguments: name: regex type: - resolvesToString - - Regex + - 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) - diff --git a/generator/config/aggregation-operators/regexMatch.yaml b/generator/config/aggregation-operators/regexMatch.yaml index 11f3e66ef..a6227c268 100644 --- a/generator/config/aggregation-operators/regexMatch.yaml +++ b/generator/config/aggregation-operators/regexMatch.yaml @@ -20,7 +20,7 @@ arguments: name: regex type: - resolvesToString - - Regex + - 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) - diff --git a/generator/config/aggregation-operators/round.yaml b/generator/config/aggregation-operators/round.yaml index 0705e3b74..a1b8fd6d2 100644 --- a/generator/config/aggregation-operators/round.yaml +++ b/generator/config/aggregation-operators/round.yaml @@ -25,7 +25,7 @@ arguments: - name: place type: - - ResolvesToInt + - resolvesToInt optional: true description: | Can be any valid expression that resolves to an integer between -20 and 100, exclusive. diff --git a/generator/config/aggregation-operators/sampleRate.yaml b/generator/config/aggregation-operators/sampleRate.yaml index e463a7cb1..14245ce7c 100644 --- a/generator/config/aggregation-operators/sampleRate.yaml +++ b/generator/config/aggregation-operators/sampleRate.yaml @@ -4,7 +4,7 @@ category: - 'Miscellaneous Operator' link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/sampleRate/' type: - - resolvesToAnything + - resolvesToAny 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. @@ -12,7 +12,7 @@ arguments: - name: rate type: - - resolvesToFloat + - 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. diff --git a/generator/config/aggregation-operators/shift.yaml b/generator/config/aggregation-operators/shift.yaml index 9cc161a65..99a0d7034 100644 --- a/generator/config/aggregation-operators/shift.yaml +++ b/generator/config/aggregation-operators/shift.yaml @@ -4,7 +4,7 @@ category: - 'Window Operator' link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/shift/' type: - - resolvesToAnything + - resolvesToAny encode: object 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. diff --git a/generator/config/aggregation-operators/stdDevPop.yaml b/generator/config/aggregation-operators/stdDevPop.yaml index 428636250..f5f282426 100644 --- a/generator/config/aggregation-operators/stdDevPop.yaml +++ b/generator/config/aggregation-operators/stdDevPop.yaml @@ -7,7 +7,7 @@ category: link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/stdDevPop/' type: - resolvesToDouble - - Accumulator + - accumulator encode: single description: | Calculates the population standard deviation of the input values. Use if the values encompass the entire population of data you want to represent and do not wish to generalize about a larger population. $stdDevPop ignores non-numeric values. diff --git a/generator/config/aggregation-operators/stdDevSamp.yaml b/generator/config/aggregation-operators/stdDevSamp.yaml index ea251b362..53439f96f 100644 --- a/generator/config/aggregation-operators/stdDevSamp.yaml +++ b/generator/config/aggregation-operators/stdDevSamp.yaml @@ -7,7 +7,7 @@ category: link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/stdDevSamp/' type: - resolvesToDouble - - Accumulator + - accumulator encode: single 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. diff --git a/generator/config/aggregation-operators/sum.yaml b/generator/config/aggregation-operators/sum.yaml index eddf779e6..ca7674049 100644 --- a/generator/config/aggregation-operators/sum.yaml +++ b/generator/config/aggregation-operators/sum.yaml @@ -7,7 +7,7 @@ category: link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/sum/' type: - resolvesToNumber - - Accumulator + - accumulator encode: single description: | Returns a sum of numerical values. Ignores non-numeric values. diff --git a/generator/config/aggregation-operators/switch.yaml b/generator/config/aggregation-operators/switch.yaml index a302b6c00..9711e801a 100644 --- a/generator/config/aggregation-operators/switch.yaml +++ b/generator/config/aggregation-operators/switch.yaml @@ -4,7 +4,7 @@ category: - 'Conditional Expression Operator' link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/switch/' type: - - resolvesToAnything + - 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. diff --git a/generator/config/aggregation-operators/top.yaml b/generator/config/aggregation-operators/top.yaml index d8c746ac9..1c32ad325 100644 --- a/generator/config/aggregation-operators/top.yaml +++ b/generator/config/aggregation-operators/top.yaml @@ -5,7 +5,7 @@ category: - 'Window Operator' link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/top/' type: - - Accumulator + - accumulator encode: object description: | Returns the top element within a group according to the specified sort order. diff --git a/generator/config/aggregation-operators/topN.yaml b/generator/config/aggregation-operators/topN.yaml index a3ff0afe4..ef82c78d0 100644 --- a/generator/config/aggregation-operators/topN.yaml +++ b/generator/config/aggregation-operators/topN.yaml @@ -5,7 +5,7 @@ category: - 'Window Operator' link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/topN/' type: - - Accumulator + - accumulator encode: object description: | Returns an aggregation of the top n fields within a group, according to the specified sort order. diff --git a/generator/config/aggregation-stages/addFields.yaml b/generator/config/aggregation-stages/addFields.yaml index 147675eed..6b007f985 100644 --- a/generator/config/aggregation-stages/addFields.yaml +++ b/generator/config/aggregation-stages/addFields.yaml @@ -4,7 +4,7 @@ category: - Stage link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/addFields/' type: - - Stage + - stage encode: single description: | Adds new fields to documents. Outputs documents that contain all existing fields from the input documents and newly added fields. diff --git a/generator/config/aggregation-stages/bucket.yaml b/generator/config/aggregation-stages/bucket.yaml index fd8fcb16d..14b9c9a4e 100644 --- a/generator/config/aggregation-stages/bucket.yaml +++ b/generator/config/aggregation-stages/bucket.yaml @@ -4,7 +4,7 @@ category: - Stage link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/bucket/' type: - - Stage + - stage encode: object description: | Categorizes incoming documents into groups, called buckets, based on a specified expression and bucket boundaries. diff --git a/generator/config/aggregation-stages/bucketAuto.yaml b/generator/config/aggregation-stages/bucketAuto.yaml index 5a6b084df..f15335400 100644 --- a/generator/config/aggregation-stages/bucketAuto.yaml +++ b/generator/config/aggregation-stages/bucketAuto.yaml @@ -4,7 +4,7 @@ category: - Stage link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/bucketAuto/' type: - - Stage + - 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. diff --git a/generator/config/aggregation-stages/changeStream.yaml b/generator/config/aggregation-stages/changeStream.yaml index 05fe2408d..5a785b9ee 100644 --- a/generator/config/aggregation-stages/changeStream.yaml +++ b/generator/config/aggregation-stages/changeStream.yaml @@ -4,7 +4,7 @@ category: - Stage link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/changeStream/' type: - - Stage + - 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. @@ -55,7 +55,7 @@ arguments: - name: startAtOperationTime type: - - Timestamp + - timestamp optional: true description: | Specifies a time as the logical starting point for the change stream. Cannot be used with resumeAfter or startAfter fields. diff --git a/generator/config/aggregation-stages/changeStreamSplitLargeEvent.yaml b/generator/config/aggregation-stages/changeStreamSplitLargeEvent.yaml index 39352daa8..41aad4a43 100644 --- a/generator/config/aggregation-stages/changeStreamSplitLargeEvent.yaml +++ b/generator/config/aggregation-stages/changeStreamSplitLargeEvent.yaml @@ -4,7 +4,7 @@ category: - Stage link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/changeStreamSplitLargeEvent/' type: - - Stage + - stage encode: object description: | Splits large change stream events that exceed 16 MB into smaller fragments returned in a change stream cursor. diff --git a/generator/config/aggregation-stages/collStats.yaml b/generator/config/aggregation-stages/collStats.yaml index 96698f899..8e818b11d 100644 --- a/generator/config/aggregation-stages/collStats.yaml +++ b/generator/config/aggregation-stages/collStats.yaml @@ -4,7 +4,7 @@ category: - Stage link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/collStats/' type: - - Stage + - stage encode: single description: | Returns statistics regarding a collection or view. diff --git a/generator/config/aggregation-stages/count.yaml b/generator/config/aggregation-stages/count.yaml index 7ab62453a..d21f08440 100644 --- a/generator/config/aggregation-stages/count.yaml +++ b/generator/config/aggregation-stages/count.yaml @@ -4,7 +4,7 @@ category: - Stage link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/count/' type: - - Stage + - stage encode: single description: | Returns a count of the number of documents at this stage of the aggregation pipeline. diff --git a/generator/config/aggregation-stages/currentOp.yaml b/generator/config/aggregation-stages/currentOp.yaml index 62a2ab550..96441dc93 100644 --- a/generator/config/aggregation-stages/currentOp.yaml +++ b/generator/config/aggregation-stages/currentOp.yaml @@ -4,7 +4,7 @@ category: - Stage link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/currentOp/' type: - - Stage + - stage encode: object description: | Returns information on active and/or dormant operations for the MongoDB deployment. To run, use the db.aggregate() method. diff --git a/generator/config/aggregation-stages/densify.yaml b/generator/config/aggregation-stages/densify.yaml index ab572474c..18616bcce 100644 --- a/generator/config/aggregation-stages/densify.yaml +++ b/generator/config/aggregation-stages/densify.yaml @@ -4,7 +4,7 @@ category: - Stage link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/densify/' type: - - Stage + - stage encode: object description: | Creates new documents in a sequence of documents where certain values in a field are missing. @@ -12,7 +12,7 @@ arguments: - name: field type: - - FieldPath + - fieldPath 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. diff --git a/generator/config/aggregation-stages/documents.yaml b/generator/config/aggregation-stages/documents.yaml index ac9d60e5e..35559e63c 100644 --- a/generator/config/aggregation-stages/documents.yaml +++ b/generator/config/aggregation-stages/documents.yaml @@ -4,7 +4,7 @@ category: - Stage link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/documents/' type: - - Stage + - stage encode: single description: | Returns literal documents from input values. diff --git a/generator/config/aggregation-stages/facet.yaml b/generator/config/aggregation-stages/facet.yaml index f2a31d772..c9d1cfa21 100644 --- a/generator/config/aggregation-stages/facet.yaml +++ b/generator/config/aggregation-stages/facet.yaml @@ -4,7 +4,7 @@ category: - Stage link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/facet/' type: - - Stage + - 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. @@ -12,5 +12,5 @@ arguments: - name: facet type: - - Pipeline + - pipeline variadic: object diff --git a/generator/config/aggregation-stages/fill.yaml b/generator/config/aggregation-stages/fill.yaml index a3c6c7f75..88b85e88e 100644 --- a/generator/config/aggregation-stages/fill.yaml +++ b/generator/config/aggregation-stages/fill.yaml @@ -4,7 +4,7 @@ category: - Stage link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/fill/' type: - - Stage + - stage encode: object description: | Populates null and missing field values within documents. diff --git a/generator/config/aggregation-stages/geoNear.yaml b/generator/config/aggregation-stages/geoNear.yaml index 4a4246dc8..9db7244e0 100644 --- a/generator/config/aggregation-stages/geoNear.yaml +++ b/generator/config/aggregation-stages/geoNear.yaml @@ -4,7 +4,7 @@ category: - Stage link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/geoNear/' type: - - Stage + - 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. @@ -61,7 +61,7 @@ arguments: - name: query type: - - Query + - query optional: true description: | imits the results to the documents that match the query. The query syntax is the usual MongoDB read operation query syntax. diff --git a/generator/config/aggregation-stages/graphLookup.yaml b/generator/config/aggregation-stages/graphLookup.yaml index a8513b7f4..f08810c21 100644 --- a/generator/config/aggregation-stages/graphLookup.yaml +++ b/generator/config/aggregation-stages/graphLookup.yaml @@ -4,7 +4,7 @@ category: - Stage link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/graphLookup/' type: - - Stage + - 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. @@ -58,7 +58,7 @@ arguments: - name: restrictSearchWithMatch type: - - Query + - query optional: true description: | A document specifying additional conditions for the recursive search. The syntax is identical to query filter syntax. diff --git a/generator/config/aggregation-stages/group.yaml b/generator/config/aggregation-stages/group.yaml index ec4a618b2..23d8c1d6e 100644 --- a/generator/config/aggregation-stages/group.yaml +++ b/generator/config/aggregation-stages/group.yaml @@ -4,7 +4,7 @@ category: - Stage link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/group/' type: - - Stage + - stage encode: group 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. @@ -18,7 +18,7 @@ arguments: - name: field type: - - Accumulator + - accumulator variadic: object description: | Computed using the accumulator operators. diff --git a/generator/config/aggregation-stages/indexStats.yaml b/generator/config/aggregation-stages/indexStats.yaml index 3d2c9dab6..e7d5c2ecd 100644 --- a/generator/config/aggregation-stages/indexStats.yaml +++ b/generator/config/aggregation-stages/indexStats.yaml @@ -4,7 +4,7 @@ category: - Stage link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/indexStats/' type: - - Stage + - stage encode: object description: | Returns statistics regarding the use of each index for the collection. diff --git a/generator/config/aggregation-stages/limit.yaml b/generator/config/aggregation-stages/limit.yaml index 9fb542214..b48ab85c6 100644 --- a/generator/config/aggregation-stages/limit.yaml +++ b/generator/config/aggregation-stages/limit.yaml @@ -4,7 +4,7 @@ category: - Stage link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/limit/' type: - - Stage + - 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). diff --git a/generator/config/aggregation-stages/listLocalSessions.yaml b/generator/config/aggregation-stages/listLocalSessions.yaml index 7517b93a6..a914f4104 100644 --- a/generator/config/aggregation-stages/listLocalSessions.yaml +++ b/generator/config/aggregation-stages/listLocalSessions.yaml @@ -4,7 +4,7 @@ category: - Stage link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/listLocalSessions/' type: - - Stage + - 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. diff --git a/generator/config/aggregation-stages/listSampledQueries.yaml b/generator/config/aggregation-stages/listSampledQueries.yaml index c63cd33e5..cd0ead01c 100644 --- a/generator/config/aggregation-stages/listSampledQueries.yaml +++ b/generator/config/aggregation-stages/listSampledQueries.yaml @@ -4,7 +4,7 @@ category: - Stage link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSampledQueries/' type: - - Stage + - stage encode: object description: | Lists sampled queries for all collections or a specific collection. diff --git a/generator/config/aggregation-stages/listSearchIndexes.yaml b/generator/config/aggregation-stages/listSearchIndexes.yaml index 4cd8f604d..fa93ad105 100644 --- a/generator/config/aggregation-stages/listSearchIndexes.yaml +++ b/generator/config/aggregation-stages/listSearchIndexes.yaml @@ -4,7 +4,7 @@ category: - Stage link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSearchIndexes/' type: - - Stage + - stage encode: object description: | Returns information about existing Atlas Search indexes on a specified collection. diff --git a/generator/config/aggregation-stages/listSessions.yaml b/generator/config/aggregation-stages/listSessions.yaml index e854a0982..847956d48 100644 --- a/generator/config/aggregation-stages/listSessions.yaml +++ b/generator/config/aggregation-stages/listSessions.yaml @@ -4,7 +4,7 @@ category: - Stage link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSessions/' type: - - Stage + - stage encode: object description: | Lists all sessions that have been active long enough to propagate to the system.sessions collection. diff --git a/generator/config/aggregation-stages/lookup.yaml b/generator/config/aggregation-stages/lookup.yaml index aa0e8c991..1f52dc44d 100644 --- a/generator/config/aggregation-stages/lookup.yaml +++ b/generator/config/aggregation-stages/lookup.yaml @@ -4,7 +4,7 @@ category: - Stage link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/lookup/' type: - - Stage + - 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. @@ -42,7 +42,7 @@ arguments: - name: pipeline type: - - Pipeline + - 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 []. diff --git a/generator/config/aggregation-stages/match.yaml b/generator/config/aggregation-stages/match.yaml index 34812e307..447547b0d 100644 --- a/generator/config/aggregation-stages/match.yaml +++ b/generator/config/aggregation-stages/match.yaml @@ -4,7 +4,7 @@ category: - Stage link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/match/' type: - - Stage + - 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). @@ -12,4 +12,4 @@ arguments: - name: query type: - - Query + - query diff --git a/generator/config/aggregation-stages/merge.yaml b/generator/config/aggregation-stages/merge.yaml index 77b483108..6b5cc82e6 100644 --- a/generator/config/aggregation-stages/merge.yaml +++ b/generator/config/aggregation-stages/merge.yaml @@ -4,7 +4,7 @@ category: - Stage link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/' type: - - Stage + - stage encode: object 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. diff --git a/generator/config/aggregation-stages/out.yaml b/generator/config/aggregation-stages/out.yaml index 06ad86099..cec1933fb 100644 --- a/generator/config/aggregation-stages/out.yaml +++ b/generator/config/aggregation-stages/out.yaml @@ -4,7 +4,7 @@ category: - Stage link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/out/' type: - - Stage + - stage encode: object 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. diff --git a/generator/config/aggregation-stages/planCacheStats.yaml b/generator/config/aggregation-stages/planCacheStats.yaml index d8b52bc97..2136492e2 100644 --- a/generator/config/aggregation-stages/planCacheStats.yaml +++ b/generator/config/aggregation-stages/planCacheStats.yaml @@ -4,7 +4,7 @@ category: - Stage link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/planCacheStats/' type: - - Stage + - stage encode: object description: | Returns plan cache information for a collection. diff --git a/generator/config/aggregation-stages/project.yaml b/generator/config/aggregation-stages/project.yaml index 6ac6c524d..15c812841 100644 --- a/generator/config/aggregation-stages/project.yaml +++ b/generator/config/aggregation-stages/project.yaml @@ -4,7 +4,7 @@ category: - Stage link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/project/' type: - - Stage + - 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. @@ -14,5 +14,7 @@ arguments: type: - bool - int - - expression + - projection + - resolvesToBool + - object variadic: object diff --git a/generator/config/aggregation-stages/redact.yaml b/generator/config/aggregation-stages/redact.yaml index e6dfc1223..12f0a9ab6 100644 --- a/generator/config/aggregation-stages/redact.yaml +++ b/generator/config/aggregation-stages/redact.yaml @@ -4,7 +4,7 @@ category: - Stage link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/redact/' type: - - Stage + - 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. diff --git a/generator/config/aggregation-stages/replaceRoot.yaml b/generator/config/aggregation-stages/replaceRoot.yaml index da09d784b..891b16250 100644 --- a/generator/config/aggregation-stages/replaceRoot.yaml +++ b/generator/config/aggregation-stages/replaceRoot.yaml @@ -4,7 +4,7 @@ category: - Stage link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceRoot/' type: - - Stage + - 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. diff --git a/generator/config/aggregation-stages/replaceWith.yaml b/generator/config/aggregation-stages/replaceWith.yaml index 95e9e2d6e..6045ab0b6 100644 --- a/generator/config/aggregation-stages/replaceWith.yaml +++ b/generator/config/aggregation-stages/replaceWith.yaml @@ -4,7 +4,7 @@ category: - Stage link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceWith/' type: - - Stage + - stage encode: single 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. diff --git a/generator/config/aggregation-stages/sample.yaml b/generator/config/aggregation-stages/sample.yaml index 347869768..d0590e475 100644 --- a/generator/config/aggregation-stages/sample.yaml +++ b/generator/config/aggregation-stages/sample.yaml @@ -4,7 +4,7 @@ category: - Stage link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/sample/' type: - - Stage + - stage encode: object description: | Randomly selects the specified number of documents from its input. diff --git a/generator/config/aggregation-stages/search.yaml b/generator/config/aggregation-stages/search.yaml index 3664e418b..c1473863d 100644 --- a/generator/config/aggregation-stages/search.yaml +++ b/generator/config/aggregation-stages/search.yaml @@ -4,7 +4,7 @@ category: - Stage link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/search/' type: - - Stage + - stage encode: single description: | Performs a full-text search of the field or fields in an Atlas collection. diff --git a/generator/config/aggregation-stages/searchMeta.yaml b/generator/config/aggregation-stages/searchMeta.yaml index 97beabdab..e5744df48 100644 --- a/generator/config/aggregation-stages/searchMeta.yaml +++ b/generator/config/aggregation-stages/searchMeta.yaml @@ -4,7 +4,7 @@ category: - Stage link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/searchMeta/' type: - - Stage + - stage encode: single description: | Returns different types of metadata result documents for the Atlas Search query against an Atlas collection. diff --git a/generator/config/aggregation-stages/set.yaml b/generator/config/aggregation-stages/set.yaml index 48984ae7f..9372aebab 100644 --- a/generator/config/aggregation-stages/set.yaml +++ b/generator/config/aggregation-stages/set.yaml @@ -4,7 +4,7 @@ category: - Stage link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/set/' type: - - Stage + - stage encode: single description: | Adds new fields to documents. Outputs documents that contain all existing fields from the input documents and newly added fields. diff --git a/generator/config/aggregation-stages/setWindowFields.yaml b/generator/config/aggregation-stages/setWindowFields.yaml index 6670d8f1c..18b9c29ba 100644 --- a/generator/config/aggregation-stages/setWindowFields.yaml +++ b/generator/config/aggregation-stages/setWindowFields.yaml @@ -4,7 +4,7 @@ category: - Stage link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/setWindowFields/' type: - - Stage + - stage encode: object description: | Groups documents into windows and applies one or more operators to the documents in each window. diff --git a/generator/config/aggregation-stages/shardedDataDistribution.yaml b/generator/config/aggregation-stages/shardedDataDistribution.yaml index aa6925748..bd684338b 100644 --- a/generator/config/aggregation-stages/shardedDataDistribution.yaml +++ b/generator/config/aggregation-stages/shardedDataDistribution.yaml @@ -4,7 +4,7 @@ category: - Stage link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/shardedDataDistribution/' type: - - Stage + - stage encode: object description: | Provides data and size distribution information on sharded collections. diff --git a/generator/config/aggregation-stages/skip.yaml b/generator/config/aggregation-stages/skip.yaml index 29d1fdb7a..5354bd895 100644 --- a/generator/config/aggregation-stages/skip.yaml +++ b/generator/config/aggregation-stages/skip.yaml @@ -4,7 +4,7 @@ category: - Stage link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/skip/' type: - - Stage + - 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). diff --git a/generator/config/aggregation-stages/sort.yaml b/generator/config/aggregation-stages/sort.yaml index ce2dd0039..ed629e738 100644 --- a/generator/config/aggregation-stages/sort.yaml +++ b/generator/config/aggregation-stages/sort.yaml @@ -4,7 +4,7 @@ category: - Stage link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/sort/' type: - - Stage + - 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. diff --git a/generator/config/aggregation-stages/sortByCount.yaml b/generator/config/aggregation-stages/sortByCount.yaml index d9925574b..1dcf770cd 100644 --- a/generator/config/aggregation-stages/sortByCount.yaml +++ b/generator/config/aggregation-stages/sortByCount.yaml @@ -4,7 +4,7 @@ category: - Stage link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/sortByCount/' type: - - Stage + - stage encode: object description: | Groups incoming documents based on the value of a specified expression, then computes the count of documents in each distinct group. diff --git a/generator/config/aggregation-stages/unionWith.yaml b/generator/config/aggregation-stages/unionWith.yaml index fb4658b74..e4b5eff70 100644 --- a/generator/config/aggregation-stages/unionWith.yaml +++ b/generator/config/aggregation-stages/unionWith.yaml @@ -4,7 +4,7 @@ category: - Stage link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/unionWith/' type: - - Stage + - stage encode: object description: | Performs a union of two collections; i.e. combines pipeline results from two collections into a single result set. @@ -19,7 +19,7 @@ arguments: - name: pipeline type: - - Pipeline + - pipeline optional: true description: | An aggregation pipeline to apply to the specified coll. diff --git a/generator/config/aggregation-stages/unset.yaml b/generator/config/aggregation-stages/unset.yaml index df2b6f1b7..388ddeb12 100644 --- a/generator/config/aggregation-stages/unset.yaml +++ b/generator/config/aggregation-stages/unset.yaml @@ -4,7 +4,7 @@ category: - Stage link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/unset/' type: - - Stage + - stage encode: single description: | Removes or excludes fields from documents. @@ -13,5 +13,5 @@ arguments: - name: field type: - - FieldPath + - fieldPath variadic: array diff --git a/generator/config/aggregation-stages/unwind.yaml b/generator/config/aggregation-stages/unwind.yaml index 23a7553d0..78cca0db3 100644 --- a/generator/config/aggregation-stages/unwind.yaml +++ b/generator/config/aggregation-stages/unwind.yaml @@ -4,7 +4,7 @@ category: - Stage link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/unwind/' type: - - Stage + - 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. @@ -12,4 +12,4 @@ arguments: - name: field type: - - ArrayFieldPath + - arrayFieldPath diff --git a/generator/config/expressions.php b/generator/config/expressions.php index f1b6d1c60..8bfef4e6b 100644 --- a/generator/config/expressions.php +++ b/generator/config/expressions.php @@ -4,174 +4,152 @@ namespace MongoDB\Builder\Expression; -use DateTimeInterface; use MongoDB\BSON; -use MongoDB\Builder\Aggregation\AccumulatorInterface; use MongoDB\Builder\Pipeline; -use MongoDB\Builder\Query\QueryInterface; +use MongoDB\Builder\Type; +use MongoDB\CodeGenerator\Definition\Generate; use MongoDB\Model\BSONArray; use stdClass; -/** @param class-string $resolvesTo */ -function typeFieldPath(string $resolvesTo): array -{ - return [ - 'class' => true, +use function array_merge; +use function array_unique; +use function array_values; +use function ucfirst; + +$bsonTypes = [ + // BSON types + // @see https://www.mongodb.com/docs/manual/reference/bson-types/ + // Ignore deprecated types and min/max keys which are not actual types + 'double' => ['int', BSON\Int64::class, 'float'], + 'string' => ['string'], + 'object' => ['array', stdClass::class, BSON\Document::class, BSON\Serializable::class], + 'array' => ['list', BSONArray::class, BSON\PackedArray::class], + 'binData' => ['string', BSON\Binary::class], + 'objectId' => [BSON\ObjectId::class], + 'bool' => ['bool'], + 'date' => [BSON\UTCDateTime::class], + 'null' => ['null'], + 'regex' => [BSON\Regex::class], + 'javascript' => ['string'], + 'int' => ['int'], + 'timestamp' => ['int', BSON\Timestamp::class], + 'long' => ['int', BSON\Int64::class, ResolvesToInt::class], + 'decimal' => ['int', BSON\Int64::class, 'float', BSON\Decimal128::class], +]; + +// "any" accepts all the BSON types. No generic "object". +$bsonTypes['any'] = array_unique(array_merge(...array_values($bsonTypes))); + +// "number" accepts all the numeric types +$bsonTypes['number'] = [ + 'int', 'float', BSON\Int64::class, BSON\Decimal128::class, + ResolvesToInt::class, ResolvesToDouble::class, ResolvesToLong::class, ResolvesToDecimal::class, +]; + +$expressions = []; + +foreach ($bsonTypes as $name => $acceptedTypes) { + $expressions[$name] = ['acceptedTypes' => $acceptedTypes]; + + $resolvesTo = 'resolvesTo' . ucfirst($name); + $resolvesToInterface = __NAMESPACE__ . '\\' . ucfirst($resolvesTo); + $expressions[$resolvesTo] = [ + 'generate' => Generate::PhpInterface, + // @todo implement type hierarchy for resolvesToNumber + 'implements' => [Type\ExpressionInterface::class], + 'returnType' => $resolvesToInterface, + 'acceptedTypes' => $acceptedTypes, + ]; + + $expressions[$name . 'FieldPath'] = [ + 'generate' => Generate::PhpClass, 'extends' => FieldPath::class, - 'implements' => [$resolvesTo], - 'types' => ['string'], + 'implements' => [$resolvesToInterface], + 'acceptedTypes' => ['string'], ]; } -return [ - 'any' => ['scalar' => true, 'types' => ['mixed']], - 'null' => ['scalar' => true, 'types' => ['null']], - 'int' => ['scalar' => true, 'types' => ['int', BSON\Int64::class]], - 'double' => ['scalar' => true, 'types' => ['int', BSON\Int64::class, 'float']], - 'float' => ['scalar' => true, 'types' => ['int', BSON\Int64::class, 'float']], - 'decimal' => ['scalar' => true, 'types' => ['int', BSON\Int64::class, 'float', BSON\Decimal128::class]], - 'number' => ['scalar' => true, 'types' => ['int', BSON\Int64::class, 'float', BSON\Decimal128::class]], - 'string' => ['scalar' => true, 'types' => ['string']], - 'bool' => ['scalar' => true, 'types' => ['bool']], - 'object' => ['scalar' => true, 'types' => ['array', stdClass::class, BSON\Document::class, BSON\Serializable::class]], - 'Regex' => ['scalar' => true, 'types' => [BSON\Regex::class]], - 'Binary' => ['scalar' => true, 'types' => ['string', BSON\Binary::class]], - - AccumulatorInterface::class => ['scalar' => true, 'types' => [AccumulatorInterface::class]], - QueryInterface::class => ['scalar' => true, 'types' => [QueryInterface::class, 'array', stdClass::class]], +// AnyFieldPath doesn't make sense. Use FieldPath instead. +unset($expressions['anyFieldPath']); - // @todo merge this types - 'list' => ['scalar' => true, 'types' => ['list', BSONArray::class, BSON\PackedArray::class]], - 'array' => ['scalar' => true, 'types' => ['list', BSONArray::class, BSON\PackedArray::class]], +return $expressions + [ + 'expression' => [ + 'returnType' => Type\ExpressionInterface::class, + 'acceptedTypes' => [Type\ExpressionInterface::class, ...$bsonTypes['any']], + ], + 'query' => [ + 'returnType' => Type\QueryInterface::class, + 'acceptedTypes' => [Type\QueryInterface::class, ...$bsonTypes['object']], + ], + 'projection' => [ + 'returnType' => Type\ProjectionInterface::class, + 'acceptedTypes' => [Type\ProjectionInterface::class, ...$bsonTypes['object']], + ], + 'accumulator' => [ + 'returnType' => Type\AccumulatorInterface::class, + 'acceptedTypes' => [Type\AccumulatorInterface::class, ...$bsonTypes['object']], + ], + 'stage' => [ + 'returnType' => Type\StageInterface::class, + 'acceptedTypes' => [Type\StageInterface::class, ...$bsonTypes['object']], + ], + 'pipeline' => [ + 'acceptedTypes' => [Pipeline::class, ...$bsonTypes['array']], + ], + 'fieldPath' => [ + 'generate' => Generate::PhpClass, + 'implements' => [Type\ExpressionInterface::class], + 'acceptedTypes' => ['string'], + ], + 'variable' => [ + 'generate' => Generate::PhpClass, + 'implements' => [Type\ExpressionInterface::class], + 'acceptedTypes' => ['string'], + ], - // @todo fine-tune all this types - 'Granularity' => ['scalar' => true, 'types' => ['string']], - 'FullDocument' => ['scalar' => true, 'types' => ['string']], - 'FullDocumentBeforeChange' => ['scalar' => true, 'types' => ['string']], - 'AccumulatorPercentile' => ['scalar' => true, 'types' => ['string']], - 'Timestamp' => ['scalar' => true, 'types' => ['int']], - 'CollStats' => ['scalar' => true, 'types' => [stdClass::class, 'array']], - 'Range' => ['scalar' => true, 'types' => [stdClass::class, 'array']], - 'FillOut' => ['scalar' => true, 'types' => [stdClass::class, 'array']], - 'WhenMatched' => ['scalar' => true, 'types' => ['string']], - 'WhenNotMatched' => ['scalar' => true, 'types' => ['string']], - 'OutCollection' => ['scalar' => true, 'types' => ['string', stdClass::class, 'array']], - 'Pipeline' => ['scalar' => true, 'types' => [Pipeline::class, 'array']], - 'SortSpec' => ['scalar' => true, 'types' => [stdClass::class, 'array']], - 'Window' => ['scalar' => true, 'types' => [stdClass::class, 'array']], - 'GeoPoint' => ['scalar' => true, 'types' => [stdClass::class, 'array']], - 'Geometry' => ['scalar' => true, 'types' => [stdClass::class, 'array']], + // @todo add enum values + 'Granularity' => [ + 'acceptedTypes' => [...$bsonTypes['string']], + ], + 'FullDocument' => [ + 'acceptedTypes' => [...$bsonTypes['string']], + ], + 'FullDocumentBeforeChange' => [ + 'acceptedTypes' => [...$bsonTypes['string']], + ], + 'AccumulatorPercentile' => [ + 'acceptedTypes' => [...$bsonTypes['string']], + ], + 'WhenMatched' => [ + 'acceptedTypes' => [...$bsonTypes['string']], + ], + 'WhenNotMatched' => [ + 'acceptedTypes' => [...$bsonTypes['string']], + ], - // Use Interface suffix to avoid confusion with MongoDB\Builder\Expression factory class - ExpressionInterface::class => [ - 'types' => ['mixed'], - ], - // @todo must not start with $ - // Allows ORMs to translate field names - FieldName::class => [ - 'class' => true, - 'types' => ['string'], - ], - // @todo if replaced by a string, it must start with $ - FieldPath::class => [ - 'class' => true, - 'implements' => [ExpressionInterface::class], - 'types' => ['string'], - ], - // @todo if replaced by a string, it must start with $$ - Variable::class => [ - 'class' => true, - 'implements' => [ExpressionInterface::class], - 'types' => ['string'], - ], - Literal::class => [ - 'class' => true, - 'implements' => [ExpressionInterface::class], - 'types' => ['mixed'], - ], - // @todo check for use-case - ExpressionObject::class => [ - 'implements' => [ExpressionInterface::class], - 'types' => ['array', stdClass::class, BSON\Document::class, BSON\Serializable::class], - ], - // @todo check for use-case - Operator::class => [ - 'implements' => [ExpressionInterface::class], - 'types' => ['array', stdClass::class, BSON\Document::class, BSON\Serializable::class], - ], - ResolvesToArray::class => [ - 'implements' => [ExpressionInterface::class], - 'types' => ['list', BSONArray::class, BSON\PackedArray::class], - ], - ArrayFieldPath::class => typeFieldPath(ResolvesToArray::class), - ResolvesToBool::class => [ - 'implements' => [ExpressionInterface::class], - 'types' => ['bool'], - ], - BoolFieldPath::class => typeFieldPath(ResolvesToBool::class), - ResolvesToDate::class => [ - 'implements' => [ExpressionInterface::class], - 'types' => [DateTimeInterface::class, BSON\UTCDateTime::class], - ], - DateFieldPath::class => typeFieldPath(ResolvesToDate::class), - ResolvesToTimestamp::class => [ - 'implements' => [ResolvesToInt::class], - 'types' => ['int', BSON\Int64::class], - ], - TimestampFieldPath::class => typeFieldPath(ResolvesToTimestamp::class), - ResolvesToObjectId::class => [ - 'implements' => [ExpressionInterface::class], - 'types' => [BSON\ObjectId::class], - ], - ObjectIdFieldPath::class => typeFieldPath(ResolvesToObjectId::class), - ResolvesToObject::class => [ - 'implements' => [ExpressionInterface::class], - 'types' => ['array', stdClass::class, BSON\Document::class, BSON\Serializable::class], - ], - ObjectFieldPath::class => typeFieldPath(ResolvesToObject::class), - ResolvesToNull::class => [ - 'implements' => [ExpressionInterface::class], - 'types' => ['null'], - ], - NullFieldPath::class => typeFieldPath(ResolvesToNull::class), - ResolvesToNumber::class => [ - 'implements' => [ExpressionInterface::class], - 'types' => ['int', 'float', BSON\Int64::class, BSON\Decimal128::class], - ], - NumberFieldPath::class => typeFieldPath(ResolvesToNumber::class), - ResolvesToDecimal::class => [ - 'implements' => [ResolvesToNumber::class], - 'types' => ['int', 'float', BSON\Int64::class, BSON\Decimal128::class], - ], - DecimalFieldPath::class => typeFieldPath(ResolvesToDecimal::class), - ResolvesToDouble::class => [ - 'implements' => [ResolvesToNumber::class], - 'types' => ['int', BSON\Int64::class, 'float'], - ], - DoubleFieldPath::class => typeFieldPath(ResolvesToDouble::class), - ResolvesToFloat::class => [ - 'implements' => [ResolvesToNumber::class], - 'types' => ['int', 'float', BSON\Int64::class], - ], - FloatFieldPath::class => typeFieldPath(ResolvesToFloat::class), - ResolvesToInt::class => [ - 'implements' => [ResolvesToNumber::class], - 'types' => ['int', BSON\Int64::class], - ], - IntFieldPath::class => typeFieldPath(ResolvesToInt::class), - ResolvesToLong::class => [ - 'implements' => [ResolvesToNumber::class], - 'types' => ['int', BSON\Int64::class], - ], - LongFieldPath::class => typeFieldPath(ResolvesToLong::class), - ResolvesToString::class => [ - 'implements' => [ExpressionInterface::class], - 'types' => ['string'], - ], - StringFieldPath::class => typeFieldPath(ResolvesToString::class), - ResolvesToBinary::class => [ - 'implements' => [ExpressionInterface::class], - 'types' => ['string', BSON\Binary::class], - ], - BinaryFieldPath::class => typeFieldPath(ResolvesToBinary::class), + // @todo create specific model classes factories + 'OutCollection' => [ + 'acceptedTypes' => [...$bsonTypes['object']], + ], + 'CollStats' => [ + 'acceptedTypes' => [...$bsonTypes['object']], + ], + 'Range' => [ + 'acceptedTypes' => [...$bsonTypes['object']], + ], + 'FillOut' => [ + 'acceptedTypes' => [...$bsonTypes['object']], + ], + 'SortSpec' => [ + 'acceptedTypes' => [...$bsonTypes['object']], + ], + 'Window' => [ + 'acceptedTypes' => [...$bsonTypes['object']], + ], + 'GeoPoint' => [ + 'acceptedTypes' => [...$bsonTypes['object']], + ], + 'Geometry' => [ + 'acceptedTypes' => [...$bsonTypes['object']], + ], ]; diff --git a/generator/config/query-operators/all.yaml b/generator/config/query-operators/all.yaml index 24c7983aa..3f8b5fabc 100644 --- a/generator/config/query-operators/all.yaml +++ b/generator/config/query-operators/all.yaml @@ -4,7 +4,7 @@ category: - 'Array Query Operators' link: 'https://www.mongodb.com/docs/manual/reference/operator/query/all/' type: - - Query + - query encode: single description: | Matches arrays that contain all elements specified in the query. diff --git a/generator/config/query-operators/and.yaml b/generator/config/query-operators/and.yaml index 7fc8b2239..f2cad8e2a 100644 --- a/generator/config/query-operators/and.yaml +++ b/generator/config/query-operators/and.yaml @@ -4,7 +4,7 @@ category: - 'Logical Query Operators' link: 'https://www.mongodb.com/docs/manual/reference/operator/query/and/' type: - - Query + - query encode: single description: | Joins query clauses with a logical AND returns all documents that match the conditions of both clauses. @@ -12,5 +12,5 @@ arguments: - name: expression type: - - Query + - query variadic: array diff --git a/generator/config/query-operators/bitsAllClear.yaml b/generator/config/query-operators/bitsAllClear.yaml index cfbcff655..98b76ded8 100644 --- a/generator/config/query-operators/bitsAllClear.yaml +++ b/generator/config/query-operators/bitsAllClear.yaml @@ -4,7 +4,7 @@ category: - 'Bitwise Query Operators' link: 'https://www.mongodb.com/docs/manual/reference/operator/query/bitsAllClear/' type: - - Query + - query encode: single description: | Matches numeric or binary values in which a set of bit positions all have a value of 0. @@ -13,5 +13,5 @@ arguments: name: bitmask type: - int - - Binary + - binData - list diff --git a/generator/config/query-operators/bitsAllSet.yaml b/generator/config/query-operators/bitsAllSet.yaml index 49a0cdeb3..c7a795a86 100644 --- a/generator/config/query-operators/bitsAllSet.yaml +++ b/generator/config/query-operators/bitsAllSet.yaml @@ -4,7 +4,7 @@ category: - 'Bitwise Query Operators' link: 'https://www.mongodb.com/docs/manual/reference/operator/query/bitsAllSet/' type: - - Query + - query encode: single description: | Matches numeric or binary values in which a set of bit positions all have a value of 1. @@ -13,5 +13,5 @@ arguments: name: bitmask type: - int - - Binary + - binData - list diff --git a/generator/config/query-operators/bitsAnyClear.yaml b/generator/config/query-operators/bitsAnyClear.yaml index 64b7bc7ae..9d66db22b 100644 --- a/generator/config/query-operators/bitsAnyClear.yaml +++ b/generator/config/query-operators/bitsAnyClear.yaml @@ -4,7 +4,7 @@ category: - 'Bitwise Query Operators' link: 'https://www.mongodb.com/docs/manual/reference/operator/query/bitsAnyClear/' type: - - Query + - query encode: single description: | Matches numeric or binary values in which any bit from a set of bit positions has a value of 0. @@ -13,5 +13,5 @@ arguments: name: bitmask type: - int - - Binary + - binData - list diff --git a/generator/config/query-operators/bitsAnySet.yaml b/generator/config/query-operators/bitsAnySet.yaml index d06ae1b19..20dc51d60 100644 --- a/generator/config/query-operators/bitsAnySet.yaml +++ b/generator/config/query-operators/bitsAnySet.yaml @@ -4,7 +4,7 @@ category: - 'Bitwise Query Operators' link: 'https://www.mongodb.com/docs/manual/reference/operator/query/bitsAnySet/' type: - - Query + - query encode: single description: | Matches numeric or binary values in which any bit from a set of bit positions has a value of 1. @@ -13,5 +13,5 @@ arguments: name: bitmask type: - int - - Binary + - binData - list diff --git a/generator/config/query-operators/box.yaml b/generator/config/query-operators/box.yaml index b026177c0..80e03b197 100644 --- a/generator/config/query-operators/box.yaml +++ b/generator/config/query-operators/box.yaml @@ -4,7 +4,7 @@ category: - 'Geospatial Geometry Specifiers' link: 'https://www.mongodb.com/docs/manual/reference/operator/query/box/' type: - - Query + - query encode: single description: | Specifies a rectangular box using legacy coordinate pairs for $geoWithin queries. The 2d index supports $box. diff --git a/generator/config/query-operators/center.yaml b/generator/config/query-operators/center.yaml index 9b7b1b50f..81a234a6a 100644 --- a/generator/config/query-operators/center.yaml +++ b/generator/config/query-operators/center.yaml @@ -4,7 +4,7 @@ category: - 'Geospatial Geometry Specifiers' link: 'https://www.mongodb.com/docs/manual/reference/operator/query/center/' type: - - Query + - query encode: single description: | Specifies a circle using legacy coordinate pairs to $geoWithin queries when using planar geometry. The 2d index supports $center. diff --git a/generator/config/query-operators/centerSphere.yaml b/generator/config/query-operators/centerSphere.yaml index 7c0f2560a..5d9686222 100644 --- a/generator/config/query-operators/centerSphere.yaml +++ b/generator/config/query-operators/centerSphere.yaml @@ -4,7 +4,7 @@ category: - 'Geospatial Geometry Specifiers' link: 'https://www.mongodb.com/docs/manual/reference/operator/query/centerSphere/' type: - - Query + - query 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. diff --git a/generator/config/query-operators/comment.yaml b/generator/config/query-operators/comment.yaml index 6ec1a93da..73589cb77 100644 --- a/generator/config/query-operators/comment.yaml +++ b/generator/config/query-operators/comment.yaml @@ -4,7 +4,7 @@ category: - 'Miscellaneous Query Operators' link: 'https://www.mongodb.com/docs/manual/reference/operator/query/comment/' type: - - expression + - query encode: single description: | Adds a comment to a query predicate. diff --git a/generator/config/query-operators/elemMatch.yaml b/generator/config/query-operators/elemMatch.yaml index 09913c5bb..5cfa186e8 100644 --- a/generator/config/query-operators/elemMatch.yaml +++ b/generator/config/query-operators/elemMatch.yaml @@ -4,7 +4,8 @@ category: - 'Projection Operators' link: 'https://www.mongodb.com/docs/manual/reference/operator/query/elemMatch/' type: - - Query + - query + - projection encode: object description: | Projects the first element in an array that matches the specified $elemMatch condition. @@ -12,4 +13,4 @@ arguments: - name: queries type: - - object + - query diff --git a/generator/config/query-operators/eq.yaml b/generator/config/query-operators/eq.yaml index 537ad8fce..47f0a75ad 100644 --- a/generator/config/query-operators/eq.yaml +++ b/generator/config/query-operators/eq.yaml @@ -4,7 +4,7 @@ category: - 'Comparison Query Operators' link: 'https://www.mongodb.com/docs/manual/reference/operator/query/eq/' type: - - Query + - query encode: single description: | Matches values that are equal to a specified value. diff --git a/generator/config/query-operators/exists.yaml b/generator/config/query-operators/exists.yaml index f5bd2b6e1..65dba48c6 100644 --- a/generator/config/query-operators/exists.yaml +++ b/generator/config/query-operators/exists.yaml @@ -4,7 +4,7 @@ category: - 'Element Query Operators' link: 'https://www.mongodb.com/docs/manual/reference/operator/query/exists/' type: - - Query + - query encode: single description: | Matches documents that have the specified field. diff --git a/generator/config/query-operators/expr.yaml b/generator/config/query-operators/expr.yaml index 1c5125d34..c80d3ece7 100644 --- a/generator/config/query-operators/expr.yaml +++ b/generator/config/query-operators/expr.yaml @@ -4,7 +4,7 @@ category: - 'Evaluation Query Operators' link: 'https://www.mongodb.com/docs/manual/reference/operator/query/expr/' type: - - Query + - query encode: single description: | Allows use of aggregation expressions within the query language. diff --git a/generator/config/query-operators/geoIntersects.yaml b/generator/config/query-operators/geoIntersects.yaml index 45daa4325..a75e06617 100644 --- a/generator/config/query-operators/geoIntersects.yaml +++ b/generator/config/query-operators/geoIntersects.yaml @@ -4,7 +4,7 @@ category: - 'Geospatial Query Selectors' link: 'https://www.mongodb.com/docs/manual/reference/operator/query/geoIntersects/' type: - - Query + - query encode: single description: | Selects geometries that intersect with a GeoJSON geometry. The 2dsphere index supports $geoIntersects. diff --git a/generator/config/query-operators/geoWithin.yaml b/generator/config/query-operators/geoWithin.yaml index 400963854..2484b6187 100644 --- a/generator/config/query-operators/geoWithin.yaml +++ b/generator/config/query-operators/geoWithin.yaml @@ -4,7 +4,7 @@ category: - 'Geospatial Query Selectors' link: 'https://www.mongodb.com/docs/manual/reference/operator/query/geoWithin/' type: - - Query + - query encode: single description: | Selects geometries within a bounding GeoJSON geometry. The 2dsphere and 2d indexes support $geoWithin. diff --git a/generator/config/query-operators/geometry.yaml b/generator/config/query-operators/geometry.yaml index 2bcfcc6a9..84f6cf838 100644 --- a/generator/config/query-operators/geometry.yaml +++ b/generator/config/query-operators/geometry.yaml @@ -4,7 +4,7 @@ category: - 'Geospatial Geometry Specifiers' link: 'https://www.mongodb.com/docs/manual/reference/operator/query/geometry/' type: - - expression + - query encode: object description: | Specifies a geometry in GeoJSON format to geospatial query operators. diff --git a/generator/config/query-operators/gt.yaml b/generator/config/query-operators/gt.yaml index 247933a61..7b9888848 100644 --- a/generator/config/query-operators/gt.yaml +++ b/generator/config/query-operators/gt.yaml @@ -4,7 +4,7 @@ category: - 'Comparison Query Operators' link: 'https://www.mongodb.com/docs/manual/reference/operator/query/gt/' type: - - Query + - query encode: single description: | Matches values that are greater than a specified value. diff --git a/generator/config/query-operators/gte.yaml b/generator/config/query-operators/gte.yaml index 4de2132ca..82b3e1f22 100644 --- a/generator/config/query-operators/gte.yaml +++ b/generator/config/query-operators/gte.yaml @@ -4,7 +4,7 @@ category: - 'Comparison Query Operators' link: 'https://www.mongodb.com/docs/manual/reference/operator/query/gte/' type: - - Query + - query encode: single description: | Matches values that are greater than or equal to a specified value. diff --git a/generator/config/query-operators/in.yaml b/generator/config/query-operators/in.yaml index 67d1d989a..4d0c929d9 100644 --- a/generator/config/query-operators/in.yaml +++ b/generator/config/query-operators/in.yaml @@ -4,7 +4,7 @@ category: - 'Comparison Query Operators' link: 'https://www.mongodb.com/docs/manual/reference/operator/query/in/' type: - - Query + - query encode: single description: | Matches any of the values specified in an array. diff --git a/generator/config/query-operators/jsonSchema.yaml b/generator/config/query-operators/jsonSchema.yaml index 1c7080062..ec8bd67d4 100644 --- a/generator/config/query-operators/jsonSchema.yaml +++ b/generator/config/query-operators/jsonSchema.yaml @@ -4,7 +4,7 @@ category: - 'Evaluation Query Operators' link: 'https://www.mongodb.com/docs/manual/reference/operator/query/jsonSchema/' type: - - Query + - query encode: single description: | Validate documents against the given JSON Schema. diff --git a/generator/config/query-operators/lt.yaml b/generator/config/query-operators/lt.yaml index 5e45606f3..8763b0a58 100644 --- a/generator/config/query-operators/lt.yaml +++ b/generator/config/query-operators/lt.yaml @@ -4,7 +4,7 @@ category: - 'Comparison Query Operators' link: 'https://www.mongodb.com/docs/manual/reference/operator/query/lt/' type: - - Query + - query encode: single description: | Matches values that are less than a specified value. diff --git a/generator/config/query-operators/lte.yaml b/generator/config/query-operators/lte.yaml index aee5b71d6..3370c2efe 100644 --- a/generator/config/query-operators/lte.yaml +++ b/generator/config/query-operators/lte.yaml @@ -4,7 +4,7 @@ category: - 'Comparison Query Operators' link: 'https://www.mongodb.com/docs/manual/reference/operator/query/lte/' type: - - Query + - query encode: single description: | Matches values that are less than or equal to a specified value. diff --git a/generator/config/query-operators/maxDistance.yaml b/generator/config/query-operators/maxDistance.yaml index 31fcdad34..cbfaf8fcc 100644 --- a/generator/config/query-operators/maxDistance.yaml +++ b/generator/config/query-operators/maxDistance.yaml @@ -4,7 +4,7 @@ category: - 'Geospatial Geometry Specifiers' link: 'https://www.mongodb.com/docs/manual/reference/operator/query/maxDistance/' type: - - Query + - query encode: single description: | Specifies a maximum distance to limit the results of $near and $nearSphere queries. The 2dsphere and 2d indexes support $maxDistance. @@ -12,5 +12,4 @@ arguments: - name: value type: - - int - - float + - number diff --git a/generator/config/query-operators/meta.yaml b/generator/config/query-operators/meta.yaml index c275157e5..949ec393c 100644 --- a/generator/config/query-operators/meta.yaml +++ b/generator/config/query-operators/meta.yaml @@ -4,7 +4,7 @@ category: - 'Projection Operators' link: 'https://www.mongodb.com/docs/manual/reference/operator/query/meta/' type: - - expression + - projection encode: object description: | Projects the available per-document metadata. diff --git a/generator/config/query-operators/minDistance.yaml b/generator/config/query-operators/minDistance.yaml index d39e641dc..f01ca8691 100644 --- a/generator/config/query-operators/minDistance.yaml +++ b/generator/config/query-operators/minDistance.yaml @@ -4,7 +4,7 @@ category: - 'Geospatial Geometry Specifiers' link: 'https://www.mongodb.com/docs/manual/reference/operator/query/minDistance/' type: - - Query + - query encode: single description: | Specifies a minimum distance to limit the results of $near and $nearSphere queries. For use with 2dsphere index only. @@ -13,4 +13,4 @@ arguments: name: value type: - int - - float + - double diff --git a/generator/config/query-operators/mod.yaml b/generator/config/query-operators/mod.yaml index 516a6dac5..e251b0a46 100644 --- a/generator/config/query-operators/mod.yaml +++ b/generator/config/query-operators/mod.yaml @@ -4,7 +4,7 @@ category: - 'Evaluation Query Operators' link: 'https://www.mongodb.com/docs/manual/reference/operator/query/mod/' type: - - Query + - query encode: array description: | Performs a modulo operation on the value of a field and selects documents with a specified result. diff --git a/generator/config/query-operators/ne.yaml b/generator/config/query-operators/ne.yaml index 73697c030..366d999ec 100644 --- a/generator/config/query-operators/ne.yaml +++ b/generator/config/query-operators/ne.yaml @@ -4,7 +4,7 @@ category: - 'Comparison Query Operators' link: 'https://www.mongodb.com/docs/manual/reference/operator/query/ne/' type: - - Query + - query encode: single description: | Matches all values that are not equal to a specified value. diff --git a/generator/config/query-operators/near.yaml b/generator/config/query-operators/near.yaml index d0687abc9..5b44aafd9 100644 --- a/generator/config/query-operators/near.yaml +++ b/generator/config/query-operators/near.yaml @@ -4,7 +4,7 @@ category: - 'Geospatial Query Selectors' link: 'https://www.mongodb.com/docs/manual/reference/operator/query/near/' type: - - Query + - query encode: object description: | Returns geospatial objects in proximity to a point. Requires a geospatial index. The 2dsphere and 2d indexes support $near. diff --git a/generator/config/query-operators/nearSphere.yaml b/generator/config/query-operators/nearSphere.yaml index 5e86f9f03..d3d50c7c5 100644 --- a/generator/config/query-operators/nearSphere.yaml +++ b/generator/config/query-operators/nearSphere.yaml @@ -4,7 +4,7 @@ category: - 'Geospatial Query Selectors' link: 'https://www.mongodb.com/docs/manual/reference/operator/query/nearSphere/' type: - - Query + - query 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. diff --git a/generator/config/query-operators/nin.yaml b/generator/config/query-operators/nin.yaml index 695e740ca..40b22e9f8 100644 --- a/generator/config/query-operators/nin.yaml +++ b/generator/config/query-operators/nin.yaml @@ -4,7 +4,7 @@ category: - 'Comparison Query Operators' link: 'https://www.mongodb.com/docs/manual/reference/operator/query/nin/' type: - - Query + - query encode: single description: | Matches none of the values specified in an array. diff --git a/generator/config/query-operators/nor.yaml b/generator/config/query-operators/nor.yaml index 440d9f9b6..0c9e56fc5 100644 --- a/generator/config/query-operators/nor.yaml +++ b/generator/config/query-operators/nor.yaml @@ -4,7 +4,7 @@ category: - 'Logical Query Operators' link: 'https://www.mongodb.com/docs/manual/reference/operator/query/nor/' type: - - Query + - query encode: single description: | Joins query clauses with a logical NOR returns all documents that fail to match both clauses. @@ -12,5 +12,5 @@ arguments: - name: expression type: - - Query + - query variadic: array diff --git a/generator/config/query-operators/not.yaml b/generator/config/query-operators/not.yaml index f9a3d6779..c69acd36e 100644 --- a/generator/config/query-operators/not.yaml +++ b/generator/config/query-operators/not.yaml @@ -4,7 +4,7 @@ category: - 'Logical Query Operators' link: 'https://www.mongodb.com/docs/manual/reference/operator/query/not/' type: - - Query + - query encode: single description: | Inverts the effect of a query expression and returns documents that do not match the query expression. @@ -12,4 +12,4 @@ arguments: - name: expression type: - - Query + - query diff --git a/generator/config/query-operators/or.yaml b/generator/config/query-operators/or.yaml index c16ba5297..163b6ac32 100644 --- a/generator/config/query-operators/or.yaml +++ b/generator/config/query-operators/or.yaml @@ -4,7 +4,7 @@ category: - 'Logical Query Operators' link: 'https://www.mongodb.com/docs/manual/reference/operator/query/or/' type: - - Query + - query encode: single description: | Joins query clauses with a logical OR returns all documents that match the conditions of either clause. @@ -12,5 +12,5 @@ arguments: - name: expression type: - - Query + - query variadic: array diff --git a/generator/config/query-operators/polygon.yaml b/generator/config/query-operators/polygon.yaml index 6f2e54c36..c8fbe2faf 100644 --- a/generator/config/query-operators/polygon.yaml +++ b/generator/config/query-operators/polygon.yaml @@ -4,7 +4,7 @@ category: - 'Geospatial Geometry Specifiers' link: 'https://www.mongodb.com/docs/manual/reference/operator/query/polygon/' type: - - Query + - query encode: single description: | Specifies a polygon to using legacy coordinate pairs for $geoWithin queries. The 2d index supports $center. diff --git a/generator/config/query-operators/positional.yaml b/generator/config/query-operators/positional.yaml index da807eb21..38b9c4f5a 100644 --- a/generator/config/query-operators/positional.yaml +++ b/generator/config/query-operators/positional.yaml @@ -4,7 +4,7 @@ category: - 'Projection Operators' link: 'https://www.mongodb.com/docs/manual/reference/operator/projection/positional/' type: - - Query + - query encode: object description: | Projects the first element in an array that matches the query condition. diff --git a/generator/config/query-operators/regex.yaml b/generator/config/query-operators/regex.yaml index 29a79ae4b..1af41a06e 100644 --- a/generator/config/query-operators/regex.yaml +++ b/generator/config/query-operators/regex.yaml @@ -4,7 +4,7 @@ category: - 'Evaluation Query Operators' link: 'https://www.mongodb.com/docs/manual/reference/operator/query/regex/' type: - - Query + - query encode: single description: | Selects documents where values match a specified regular expression. @@ -12,4 +12,4 @@ arguments: - name: regex type: - - Regex + - regex diff --git a/generator/config/query-operators/size.yaml b/generator/config/query-operators/size.yaml index 2d71416fa..a7c1515d6 100644 --- a/generator/config/query-operators/size.yaml +++ b/generator/config/query-operators/size.yaml @@ -4,7 +4,7 @@ category: - 'Array Query Operators' link: 'https://www.mongodb.com/docs/manual/reference/operator/query/size/' type: - - Query + - query encode: single description: | Selects documents if the array field is a specified size. diff --git a/generator/config/query-operators/slice.yaml b/generator/config/query-operators/slice.yaml index b58a7acce..93fd3e250 100644 --- a/generator/config/query-operators/slice.yaml +++ b/generator/config/query-operators/slice.yaml @@ -4,7 +4,8 @@ category: - 'Projection Operators' link: 'https://www.mongodb.com/docs/manual/reference/operator/query/slice/' type: - - Query + - query + - projection encode: array description: | Limits the number of elements projected from an array. Supports skip and limit slices. diff --git a/generator/config/query-operators/text.yaml b/generator/config/query-operators/text.yaml index 03df77a2c..4a4ebd66c 100644 --- a/generator/config/query-operators/text.yaml +++ b/generator/config/query-operators/text.yaml @@ -4,7 +4,7 @@ category: - 'Evaluation Query Operators' link: 'https://www.mongodb.com/docs/manual/reference/operator/query/text/' type: - - Query + - query encode: object description: | Performs text search. diff --git a/generator/config/query-operators/type.yaml b/generator/config/query-operators/type.yaml index 3945b8f38..48d79f2e8 100644 --- a/generator/config/query-operators/type.yaml +++ b/generator/config/query-operators/type.yaml @@ -4,7 +4,7 @@ category: - 'Element Query Operators' link: 'https://www.mongodb.com/docs/manual/reference/operator/query/type/' type: - - Query + - query encode: single description: | Selects documents if a field is of the specified type. diff --git a/generator/config/query-operators/where.yaml b/generator/config/query-operators/where.yaml index 120ce2cf0..7a1febc8e 100644 --- a/generator/config/query-operators/where.yaml +++ b/generator/config/query-operators/where.yaml @@ -4,7 +4,7 @@ category: - 'Evaluation Query Operators' link: 'https://www.mongodb.com/docs/manual/reference/operator/query/where/' type: - - Query + - query encode: single description: | Matches documents that satisfy a JavaScript expression. diff --git a/generator/config/schema.json b/generator/config/schema.json index 2ee5c2f9b..8cd283fe7 100644 --- a/generator/config/schema.json +++ b/generator/config/schema.json @@ -64,7 +64,6 @@ "encode", "link", "name", - "arguments", "type" ], "title": "Operator" diff --git a/generator/src/AbstractGenerator.php b/generator/src/AbstractGenerator.php index a24d8ceb9..49c705906 100644 --- a/generator/src/AbstractGenerator.php +++ b/generator/src/AbstractGenerator.php @@ -18,6 +18,7 @@ use function file_put_contents; use function implode; use function is_dir; +use function ltrim; use function mkdir; use function sprintf; use function str_replace; @@ -40,7 +41,7 @@ public function __construct( */ final protected function splitNamespaceAndClassName(string $fqcn): array { - $parts = explode('\\', $fqcn); + $parts = explode('\\', ltrim($fqcn, '\\')); $className = array_pop($parts); return [implode('\\', $parts), $className]; diff --git a/generator/src/CodecClassGenerator.php b/generator/src/CodecClassGenerator.php new file mode 100644 index 000000000..11fda216d --- /dev/null +++ b/generator/src/CodecClassGenerator.php @@ -0,0 +1,60 @@ +getClassName($object)); + + $constuctor = $class->addMethod('__construct'); + + foreach ($object->arguments as $argument) { + ['native' => $nativeType, 'doc' => $docType] = $this->getAcceptedTypes($argument); + + // Property + $propertyComment = ''; + $property = $class->addProperty($argument->name); + if ($argument->isVariadic) { + $property->setType('array'); + $propertyComment .= '@param list<' . $docType . '> $' . $argument->name . PHP_EOL; + } else { + $property->setType($nativeType); + } + + $property->setComment($propertyComment); + + // Constructor + $constuctorParam = $constuctor->addParameter($argument->name); + $constuctorParam->setType($nativeType); + if ($argument->isVariadic) { + $constuctor->setVariadic(); + } + + $constuctor->addComment('@param ' . $docType . ' $' . $argument->name . PHP_EOL); + $constuctor->addBody('$this->' . $argument->name . ' = $' . $argument->name . ';' . PHP_EOL); + } + + return $class; + } + + public function generate(GeneratorDefinition $definition): void + { + // TODO: Implement generate() method. + } +} diff --git a/generator/src/Command/GenerateCommand.php b/generator/src/Command/GenerateCommand.php index c7439a2a2..14e165b63 100644 --- a/generator/src/Command/GenerateCommand.php +++ b/generator/src/Command/GenerateCommand.php @@ -3,7 +3,7 @@ namespace MongoDB\CodeGenerator\Command; -use MongoDB\Builder\Expression\ExpressionInterface; +use MongoDB\Builder\Expression\ExpressionType; use MongoDB\CodeGenerator\Definition\ExpressionDefinition; use MongoDB\CodeGenerator\Definition\GeneratorDefinition; use MongoDB\CodeGenerator\ExpressionClassGenerator; @@ -69,7 +69,7 @@ private function generateExpressionClasses(OutputInterface $output): array return $definitions; } - /** @param array, ExpressionDefinition> $expressions */ + /** @param array, ExpressionDefinition> $expressions */ private function generateOperatorClasses(array $expressions, OutputInterface $output): void { $config = require $this->configDir . '/operators.php'; diff --git a/generator/src/Command/ScrapeCommand.php b/generator/src/Command/ScrapeCommand.php index 7532e09e8..ab4ceea95 100644 --- a/generator/src/Command/ScrapeCommand.php +++ b/generator/src/Command/ScrapeCommand.php @@ -160,10 +160,10 @@ private function getTableData(Crawler $crawler, string $tabName): array return $docs; } - /** @param array{Name:string,Category:string,Description:string,Link:string,ReturnType:string,Encode:string,Args:array{Name:string,Type:string,Options:string,Description:string}} $doc */ + /** @param array{Name:string,Category:string,Description:string,Link:string,Type:string,Encode:string,Args:array{Name:string,Type:string,Options:string,Description:string}} $doc */ private function formatSpec(array $doc): array { - foreach (['Name', 'Category', 'Description', 'Link', 'ReturnType', 'Encode', 'Args'] as $key) { + foreach (['Name', 'Category', 'Description', 'Link', 'Type', 'Encode', 'Args'] as $key) { assert(isset($doc[$key]), 'Missing ' . $key . ' for ' . var_export($doc, true)); } @@ -172,7 +172,7 @@ private function formatSpec(array $doc): array $spec['category'] = explode(PHP_EOL, $doc['Category']); sort($spec['category']); $spec['link'] = $doc['Link']; - $spec['type'] = explode(PHP_EOL, $doc['ReturnType']); + $spec['type'] = explode(PHP_EOL, $doc['Type']); $spec['encode'] = $doc['Encode']; if ($doc['Description']) { diff --git a/generator/src/Definition/ExpressionDefinition.php b/generator/src/Definition/ExpressionDefinition.php index f5be42116..cd729202b 100644 --- a/generator/src/Definition/ExpressionDefinition.php +++ b/generator/src/Definition/ExpressionDefinition.php @@ -4,19 +4,41 @@ namespace MongoDB\CodeGenerator\Definition; use function assert; +use function interface_exists; +use function is_string; +use function ucfirst; final readonly class ExpressionDefinition { + /** @var list */ + public array $acceptedTypes; + + /** @var string|null Interface to implement for operators that resolve to this type. Generated class/enum/interface. */ + public ?string $returnType; + public function __construct( public string $name, - /** @var list */ - public array $types, - public bool $scalar = false, - public bool $class = false, + array $acceptedTypes, + ?string $returnType = null, public ?string $extends = null, /** @var list */ public array $implements = [], + public array $values = [], + public ?Generate $generate = null, ) { - assert($class || ! $extends, 'Cannot specify "extends" when "class" is not true'); + assert($generate === Generate::PhpClass || ! $extends, $name . ': Cannot specify "extends" when "generate" is not "class"'); + assert($generate === Generate::PhpEnum || ! $this->values, $name . ': Cannot specify "values" when "generate" is not "enum"'); + assert($returnType === null || interface_exists($returnType), $name . ': Return type must be an interface'); + + foreach ($acceptedTypes as $acceptedType) { + assert(is_string($acceptedType), $name . ': AcceptedTypes must be an array of strings.'); + } + + if ($generate) { + $returnType = 'MongoDB\\Builder\\Expression\\' . ucfirst($this->name); + } + + $this->returnType = $returnType; + $this->acceptedTypes = $acceptedTypes; } } diff --git a/generator/src/Definition/Generate.php b/generator/src/Definition/Generate.php new file mode 100644 index 000000000..b3771e4b1 --- /dev/null +++ b/generator/src/Definition/Generate.php @@ -0,0 +1,13 @@ +> */ - private static array $definitions = []; - /** @return list */ public function read(string $dirname): array { - if (array_key_exists($dirname, self::$definitions)) { - return self::$definitions[$dirname]; - } - $finder = new Finder(); - $finder->files()->in($dirname)->name('*.yaml'); + $finder->files()->in($dirname)->name('*.yaml')->sortByName(); $definitions = []; foreach ($finder as $file) { @@ -32,6 +24,6 @@ public function read(string $dirname): array $definitions[] = new OperatorDefinition(...$operator); } - return self::$definitions[$dirname] = $definitions; + return $definitions; } } diff --git a/generator/src/ExpressionClassGenerator.php b/generator/src/ExpressionClassGenerator.php index cd988bc3f..d718b1fdc 100644 --- a/generator/src/ExpressionClassGenerator.php +++ b/generator/src/ExpressionClassGenerator.php @@ -3,11 +3,14 @@ namespace MongoDB\CodeGenerator; +use LogicException; use MongoDB\CodeGenerator\Definition\ExpressionDefinition; +use MongoDB\CodeGenerator\Definition\Generate; use Nette\PhpGenerator\PhpNamespace; use Nette\PhpGenerator\Type; use function array_map; +use function var_export; /** * Generates a value object class for expressions @@ -16,7 +19,7 @@ class ExpressionClassGenerator extends AbstractGenerator { public function generate(ExpressionDefinition $definition): void { - if ($definition->scalar) { + if (! $definition->generate) { return; } @@ -25,7 +28,7 @@ public function generate(ExpressionDefinition $definition): void public function createClassOrInterface(ExpressionDefinition $definition): PhpNamespace { - [$namespace, $className] = $this->splitNamespaceAndClassName($definition->name); + [$namespace, $className] = $this->splitNamespaceAndClassName($definition->returnType); $namespace = new PhpNamespace($namespace); foreach ($definition->implements as $interface) { $namespace->addUse($interface); @@ -36,10 +39,10 @@ public function createClassOrInterface(ExpressionDefinition $definition): PhpNam 'list' => 'array', default => $type, }, - $definition->types, + $definition->acceptedTypes, ); - if ($definition->class) { + if ($definition->generate === Generate::PhpClass) { $class = $namespace->addClass($className); $class->setImplements($definition->implements); $class->setExtends($definition->extends); @@ -53,9 +56,11 @@ public function createClassOrInterface(ExpressionDefinition $definition): PhpNam $constructor = $class->addMethod('__construct'); $constructor->addParameter('expression')->setType($propertyType); $constructor->addBody('$this->expression = $expression;'); - } else { + } elseif ($definition->generate === Generate::PhpInterface) { $class = $namespace->addInterface($className); $class->setExtends($definition->implements); + } else { + throw new LogicException('Unknown generate type: ' . var_export($definition->generate, true)); } return $namespace; diff --git a/generator/src/ExpressionFactoryGenerator.php b/generator/src/ExpressionFactoryGenerator.php index e208f424f..a5ed5791e 100644 --- a/generator/src/ExpressionFactoryGenerator.php +++ b/generator/src/ExpressionFactoryGenerator.php @@ -4,6 +4,7 @@ namespace MongoDB\CodeGenerator; use MongoDB\CodeGenerator\Definition\ExpressionDefinition; +use MongoDB\CodeGenerator\Definition\Generate; use Nette\PhpGenerator\PhpNamespace; use function lcfirst; @@ -28,18 +29,18 @@ private function createFactoryClass(array $expressions): PhpNamespace usort($expressions, fn (ExpressionDefinition $a, ExpressionDefinition $b) => $a->name <=> $b->name); foreach ($expressions as $expression) { - if (! $expression->class) { + if ($expression->generate !== Generate::PhpClass) { continue; } - $namespace->addUse($expression->name); - $expressionShortClassName = $this->splitNamespaceAndClassName($expression->name)[1]; + $namespace->addUse($expression->returnType); + $expressionShortClassName = $this->splitNamespaceAndClassName($expression->returnType)[1]; $method = $class->addMethod(lcfirst($expressionShortClassName)); $method->setStatic(); $method->addParameter('expression')->setType('string'); $method->addBody('return new ' . $expressionShortClassName . '($expression);'); - $method->setReturnType($expression->name); + $method->setReturnType($expression->returnType); } // Pedantry requires private methods to be at the end diff --git a/generator/src/OperatorClassGenerator.php b/generator/src/OperatorClassGenerator.php index 1ce64a97b..3e88adf83 100644 --- a/generator/src/OperatorClassGenerator.php +++ b/generator/src/OperatorClassGenerator.php @@ -3,10 +3,7 @@ namespace MongoDB\CodeGenerator; -use MongoDB\Builder\Aggregation\AccumulatorInterface; use MongoDB\Builder\Encode; -use MongoDB\Builder\Query\QueryInterface; -use MongoDB\Builder\Stage\StageInterface; use MongoDB\CodeGenerator\Definition\GeneratorDefinition; use MongoDB\CodeGenerator\Definition\OperatorDefinition; use MongoDB\CodeGenerator\Definition\VariadicType; @@ -59,7 +56,7 @@ public function createClass(GeneratorDefinition $definition, OperatorDefinition $constuctor = $class->addMethod('__construct'); foreach ($operator->arguments as $argument) { - $type = $this->generateExpressionTypes($argument); + $type = $this->getAcceptedTypes($argument); foreach ($type->use as $use) { $namespace->addUse($use); } @@ -88,7 +85,7 @@ public function createClass(GeneratorDefinition $definition, OperatorDefinition $constuctor->addComment('@no-named-arguments'); $constuctor->addBody(<<name})) { - throw new \InvalidArgumentException('Expected \${$argument->name} arguments to be a list of {$type->doc}, named arguments are not supported'); + throw new \InvalidArgumentException('Expected \${$argument->name} arguments to be a list (array), named arguments are not supported'); } PHP); } elseif ($argument->variadic === VariadicType::Object) { @@ -98,7 +95,7 @@ public function createClass(GeneratorDefinition $definition, OperatorDefinition $constuctor->addBody(<<name} as \$key => \$value) { if (! \is_string(\$key)) { - throw new \InvalidArgumentException('Expected \${$argument->name} arguments to be a map of {$type->doc}, named arguments (:) or array unpacking ...[\'\' => ] must be used'); + throw new \InvalidArgumentException('Expected \${$argument->name} arguments to be a map (object), named arguments (:) or array unpacking ...[\'\' => ] must be used'); } } \${$argument->name} = (object) \${$argument->name}; @@ -121,6 +118,7 @@ public function createClass(GeneratorDefinition $definition, OperatorDefinition if (\is_array(\${$argument->name}) && ! \array_is_list(\${$argument->name})) { throw new \InvalidArgumentException('Expected \${$argument->name} argument to be a list, got an associative array.'); } + PHP); } } @@ -140,19 +138,7 @@ private function getInterfaces(OperatorDefinition $definition): array $interfaces = []; foreach ($definition->type as $type) { - if ($definition->type === 'Stage') { - return ['\\' . StageInterface::class]; - } - - if ($definition->type === 'Query') { - return ['\\' . QueryInterface::class]; - } - - if ($definition->type === 'Accumulator') { - return ['\\' . AccumulatorInterface::class]; - } - - $interfaces[] = $interface = $this->getExpressionTypeInterface($type); + $interfaces[] = $interface = $this->getType($type)->returnType; assert(interface_exists($interface), sprintf('"%s" is not an interface.', $interface)); } diff --git a/generator/src/OperatorFactoryGenerator.php b/generator/src/OperatorFactoryGenerator.php index 38cdc832b..d1924cc64 100644 --- a/generator/src/OperatorFactoryGenerator.php +++ b/generator/src/OperatorFactoryGenerator.php @@ -64,7 +64,7 @@ private function addMethod(GeneratorDefinition $definition, OperatorDefinition $ $method->addComment('@see ' . $operator->link); $args = []; foreach ($operator->arguments as $argument) { - $type = $this->generateExpressionTypes($argument); + $type = $this->getAcceptedTypes($argument); foreach ($type->use as $use) { $namespace->addUse($use); } diff --git a/generator/src/OperatorGenerator.php b/generator/src/OperatorGenerator.php index cfab6e463..866f10a8b 100644 --- a/generator/src/OperatorGenerator.php +++ b/generator/src/OperatorGenerator.php @@ -3,11 +3,8 @@ namespace MongoDB\CodeGenerator; -use MongoDB\Builder\Aggregation\AccumulatorInterface; -use MongoDB\Builder\Expression\ExpressionInterface; +use MongoDB\Builder\Expression\ExpressionType; use MongoDB\Builder\Optional; -use MongoDB\Builder\Query\QueryInterface; -use MongoDB\Builder\Stage\StageInterface; use MongoDB\CodeGenerator\Definition\ArgumentDefinition; use MongoDB\CodeGenerator\Definition\ExpressionDefinition; use MongoDB\CodeGenerator\Definition\GeneratorDefinition; @@ -35,7 +32,7 @@ abstract class OperatorGenerator extends AbstractGenerator final public function __construct( string $rootDir, - /** @var array, ExpressionDefinition> */ + /** @var array, ExpressionDefinition> */ private array $expressions ) { parent::__construct($rootDir); @@ -59,38 +56,20 @@ final protected function getOperatorClassName(GeneratorDefinition $definition, O return ucfirst(ltrim($operator->name, '$')) . $definition->classNameSuffix; } - /** @return class-string|string */ - final protected function getExpressionTypeInterface(string $type): string + final protected function getType(string $type): ExpressionDefinition { - if ('expression' === $type || 'resolvesToAnything' === $type) { - return ExpressionInterface::class; - } - - if ('Stage' === $type) { - return StageInterface::class; - } - - if ('Accumulator' === $type) { - return AccumulatorInterface::class; - } - - if ('Query' === $type) { - return QueryInterface::class; - } - // @todo handle generic types object and array $type = explode('<', $type, 2)[0]; $type = explode('{', $type, 2)[0]; - // Scalar types - if (array_key_exists($type, $this->expressions)) { - return $type; - } + $type = match ($type) { + 'list' => 'array', + default => $type, + }; - $interface = 'MongoDB\\Builder\\Expression\\' . ucfirst($type); - assert(array_key_exists($interface, $this->expressions), sprintf('Invalid expression type "%s".', $type)); + assert(array_key_exists($type, $this->expressions), sprintf('Invalid expression type "%s".', $type)); - return $interface; + return $this->expressions[$type]; } /** @@ -99,19 +78,16 @@ final protected function getExpressionTypeInterface(string $type): string * * @return object{native:string,doc:string,use:list,list:bool} */ - final protected function generateExpressionTypes(ArgumentDefinition $arg): object + final protected function getAcceptedTypes(ArgumentDefinition $arg): object { $nativeTypes = []; foreach ($arg->type as $type) { - $interface = $this->getExpressionTypeInterface($type); - $types = $this->expressions[$interface]->types; + $type = $this->getType($type); + $nativeTypes = array_merge($nativeTypes, $type->acceptedTypes); - // Add the interface to the allowed types if it is not a scalar - if (! $this->expressions[$interface]->scalar) { - $types = array_merge([$interface], $types); + if (isset($type->returnType)) { + $nativeTypes[] = $type->returnType; } - - $nativeTypes = array_merge($nativeTypes, $types); } if ($arg->optional) { @@ -129,8 +105,7 @@ final protected function generateExpressionTypes(ArgumentDefinition $arg): objec $listCheck = true; $nativeTypes[$key] = 'array'; // @todo allow to specify the type of the elements in the list - $docTypes[$key] = 'list'; - $use[] = '\\' . ExpressionInterface::class; + $docTypes[$key] = 'array'; continue; } diff --git a/psalm-baseline.xml b/psalm-baseline.xml index cac6e7790..309a48158 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -109,9 +109,6 @@ - - $value - $expression @@ -127,17 +124,11 @@ - - $value - $specification - - $value - $field diff --git a/src/Builder/Aggregation.php b/src/Builder/Aggregation.php index 20e7dd95e..b37030b75 100644 --- a/src/Builder/Aggregation.php +++ b/src/Builder/Aggregation.php @@ -6,7 +6,6 @@ namespace MongoDB\Builder; -use DateTimeInterface; use MongoDB\BSON\Binary; use MongoDB\BSON\Decimal128; use MongoDB\BSON\Document; @@ -15,6 +14,7 @@ use MongoDB\BSON\PackedArray; use MongoDB\BSON\Regex; use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Aggregation\AbsAggregation; use MongoDB\Builder\Aggregation\AccumulatorAggregation; @@ -186,15 +186,13 @@ use MongoDB\Builder\Aggregation\WeekAggregation; use MongoDB\Builder\Aggregation\YearAggregation; use MongoDB\Builder\Aggregation\ZipAggregation; -use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\FieldPath; use MongoDB\Builder\Expression\ResolvesToArray; -use MongoDB\Builder\Expression\ResolvesToBinary; +use MongoDB\Builder\Expression\ResolvesToBinData; use MongoDB\Builder\Expression\ResolvesToBool; use MongoDB\Builder\Expression\ResolvesToDate; use MongoDB\Builder\Expression\ResolvesToDecimal; use MongoDB\Builder\Expression\ResolvesToDouble; -use MongoDB\Builder\Expression\ResolvesToFloat; use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Expression\ResolvesToLong; use MongoDB\Builder\Expression\ResolvesToNull; @@ -203,6 +201,7 @@ use MongoDB\Builder\Expression\ResolvesToObjectId; use MongoDB\Builder\Expression\ResolvesToString; use MongoDB\Builder\Expression\ResolvesToTimestamp; +use MongoDB\Builder\Type\ExpressionInterface; use MongoDB\Model\BSONArray; use stdClass; @@ -212,9 +211,11 @@ final class Aggregation * Returns the absolute value of a number. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/abs/ - * @param Decimal128|Int64|ResolvesToNumber|float|int $value + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $value */ - public static function abs(Decimal128|Int64|ResolvesToNumber|float|int $value): AbsAggregation + public static function abs( + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $value, + ): AbsAggregation { return new AbsAggregation($value); } @@ -226,10 +227,10 @@ public static function abs(Decimal128|Int64|ResolvesToNumber|float|int $value): * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/accumulator/ * @param non-empty-string $init 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. * @param non-empty-string $accumulate 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. - * @param BSONArray|PackedArray|ResolvesToArray|list $accumulateArgs Arguments passed to the accumulate function. You can use accumulateArgs to specify what field value(s) to pass to the accumulate function. + * @param BSONArray|PackedArray|ResolvesToArray|array $accumulateArgs Arguments passed to the accumulate function. You can use accumulateArgs to specify what field value(s) to pass to the accumulate function. * @param non-empty-string $merge 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. * @param non-empty-string $lang The language used in the $accumulator code. - * @param BSONArray|Optional|PackedArray|ResolvesToArray|list $initArgs Arguments passed to the init function. + * @param BSONArray|Optional|PackedArray|ResolvesToArray|array $initArgs Arguments passed to the init function. * @param Optional|non-empty-string $finalize Function used to update the result of the accumulation. */ public static function accumulator( @@ -249,11 +250,13 @@ public static function accumulator( * Returns the inverse cosine (arc cosine) of a value in radians. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/acos/ - * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $acos takes any valid expression that resolves to a number between -1 and 1, e.g. -1 <= value <= 1. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression $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. */ - public static function acos(Decimal128|Int64|ResolvesToNumber|float|int $expression): AcosAggregation + public static function acos( + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression, + ): AcosAggregation { return new AcosAggregation($expression); } @@ -262,11 +265,13 @@ public static function acos(Decimal128|Int64|ResolvesToNumber|float|int $express * Returns the inverse hyperbolic cosine (hyperbolic arc cosine) of a value in radians. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/acosh/ - * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $acosh takes any valid expression that resolves to a number between 1 and +Infinity, e.g. 1 <= value <= +Infinity. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression $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. */ - public static function acosh(Decimal128|Int64|ResolvesToNumber|float|int $expression): AcoshAggregation + public static function acosh( + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression, + ): AcoshAggregation { return new AcoshAggregation($expression); } @@ -275,10 +280,10 @@ public static function acosh(Decimal128|Int64|ResolvesToNumber|float|int $expres * 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. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/add/ - * @param DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int ...$expression The arguments can be any valid expression as long as they resolve to either all numbers or to numbers and a date. + * @param Decimal128|Int64|ResolvesToDate|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|UTCDateTime|float|int ...$expression The arguments can be any valid expression as long as they resolve to either all numbers or to numbers and a date. */ public static function add( - DateTimeInterface|Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int ...$expression, + Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int ...$expression, ): AddAggregation { return new AddAggregation(...$expression); @@ -289,9 +294,11 @@ public static function add( * Changed in version 5.0: Available in the $setWindowFields stage. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/addToSet/ - * @param ExpressionInterface|FieldPath|mixed|non-empty-string $expression + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|FieldPath|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression */ - public static function addToSet(mixed $expression): AddToSetAggregation + public static function addToSet( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|FieldPath|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, + ): AddToSetAggregation { return new AddToSetAggregation($expression); } @@ -300,7 +307,7 @@ public static function addToSet(mixed $expression): AddToSetAggregation * Returns true if no element of a set evaluates to false, otherwise, returns false. Accepts a single argument expression. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/allElementsTrue/ - * @param BSONArray|PackedArray|ResolvesToArray|list ...$expression + * @param BSONArray|PackedArray|ResolvesToArray|array ...$expression */ public static function allElementsTrue( PackedArray|ResolvesToArray|BSONArray|array ...$expression, @@ -313,9 +320,11 @@ public static function allElementsTrue( * Returns true only when all its expressions evaluate to true. Accepts any number of argument expressions. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/and/ - * @param Decimal128|ExpressionInterface|Int64|ResolvesToBool|ResolvesToNull|ResolvesToNumber|ResolvesToString|bool|float|int|mixed|non-empty-string|null ...$expression + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToBool|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNull|ResolvesToNumber|ResolvesToString|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass ...$expression */ - public static function and(mixed ...$expression): AndAggregation + public static function and( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToBool|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNull|ResolvesToNumber|ResolvesToString|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string ...$expression, + ): AndAggregation { return new AndAggregation(...$expression); } @@ -324,7 +333,7 @@ public static function and(mixed ...$expression): AndAggregation * Returns true if any elements of a set evaluate to true; otherwise, returns false. Accepts a single argument expression. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/anyElementTrue/ - * @param BSONArray|PackedArray|ResolvesToArray|list $expression + * @param BSONArray|PackedArray|ResolvesToArray|array $expression */ public static function anyElementTrue( PackedArray|ResolvesToArray|BSONArray|array $expression, @@ -337,12 +346,12 @@ public static function anyElementTrue( * Returns the element at the specified array index. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/arrayElemAt/ - * @param BSONArray|PackedArray|ResolvesToArray|list $array - * @param Int64|ResolvesToInt|int $idx + * @param BSONArray|PackedArray|ResolvesToArray|array $array + * @param ResolvesToInt|int $idx */ public static function arrayElemAt( PackedArray|ResolvesToArray|BSONArray|array $array, - Int64|ResolvesToInt|int $idx, + ResolvesToInt|int $idx, ): ArrayElemAtAggregation { return new ArrayElemAtAggregation($array, $idx); @@ -352,7 +361,7 @@ public static function arrayElemAt( * Converts an array of key value pairs to a document. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/arrayToObject/ - * @param BSONArray|PackedArray|ResolvesToArray|list $array + * @param BSONArray|PackedArray|ResolvesToArray|array $array */ public static function arrayToObject(PackedArray|ResolvesToArray|BSONArray|array $array): ArrayToObjectAggregation { @@ -363,11 +372,13 @@ public static function arrayToObject(PackedArray|ResolvesToArray|BSONArray|array * Returns the inverse sin (arc sine) of a value in radians. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/asin/ - * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $asin takes any valid expression that resolves to a number between -1 and 1, e.g. -1 <= value <= 1. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression $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. */ - public static function asin(Decimal128|Int64|ResolvesToNumber|float|int $expression): AsinAggregation + public static function asin( + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression, + ): AsinAggregation { return new AsinAggregation($expression); } @@ -376,11 +387,13 @@ public static function asin(Decimal128|Int64|ResolvesToNumber|float|int $express * Returns the inverse hyperbolic sine (hyperbolic arc sine) of a value in radians. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/asinh/ - * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $asinh takes any valid expression that resolves to a number. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression $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. */ - public static function asinh(Decimal128|Int64|ResolvesToNumber|float|int $expression): AsinhAggregation + public static function asinh( + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression, + ): AsinhAggregation { return new AsinhAggregation($expression); } @@ -389,11 +402,13 @@ public static function asinh(Decimal128|Int64|ResolvesToNumber|float|int $expres * Returns the inverse tangent (arc tangent) of a value in radians. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/atan/ - * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $atan takes any valid expression that resolves to a number. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression $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. */ - public static function atan(Decimal128|Int64|ResolvesToNumber|float|int $expression): AtanAggregation + public static function atan( + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression, + ): AtanAggregation { return new AtanAggregation($expression); } @@ -402,14 +417,14 @@ public static function atan(Decimal128|Int64|ResolvesToNumber|float|int $express * 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. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/atan2/ - * @param Decimal128|Int64|ResolvesToNumber|float|int $y $atan2 takes any valid expression that resolves to a number. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $y $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. - * @param Decimal128|Int64|ResolvesToNumber|float|int $x + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $x */ public static function atan2( - Decimal128|Int64|ResolvesToNumber|float|int $y, - Decimal128|Int64|ResolvesToNumber|float|int $x, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $y, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $x, ): Atan2Aggregation { return new Atan2Aggregation($y, $x); @@ -419,11 +434,13 @@ public static function atan2( * Returns the inverse hyperbolic tangent (hyperbolic arc tangent) of a value in radians. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/atanh/ - * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $atanh takes any valid expression that resolves to a number between -1 and 1, e.g. -1 <= value <= 1. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression $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. */ - public static function atanh(Decimal128|Int64|ResolvesToNumber|float|int $expression): AtanhAggregation + public static function atanh( + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression, + ): AtanhAggregation { return new AtanhAggregation($expression); } @@ -433,9 +450,11 @@ public static function atanh(Decimal128|Int64|ResolvesToNumber|float|int $expres * Changed in version 5.0: Available in the $setWindowFields stage. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/avg/ - * @param Decimal128|Int64|ResolvesToNumber|float|int ...$expression + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int ...$expression */ - public static function avg(Decimal128|Int64|ResolvesToNumber|float|int ...$expression): AvgAggregation + public static function avg( + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int ...$expression, + ): AvgAggregation { return new AvgAggregation(...$expression); } @@ -444,10 +463,10 @@ public static function avg(Decimal128|Int64|ResolvesToNumber|float|int ...$expre * Returns the size of a given string or binary data value's content in bytes. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/binarySize/ - * @param Binary|ResolvesToBinary|ResolvesToNull|ResolvesToString|non-empty-string|null $expression + * @param Binary|ResolvesToBinData|ResolvesToNull|ResolvesToString|non-empty-string|null $expression */ public static function binarySize( - Binary|ResolvesToBinary|ResolvesToNull|ResolvesToString|null|string $expression, + Binary|ResolvesToBinData|ResolvesToNull|ResolvesToString|null|string $expression, ): BinarySizeAggregation { return new BinarySizeAggregation($expression); @@ -508,10 +527,13 @@ public static function bitXor(Int64|ResolvesToInt|ResolvesToLong|int ...$express * Available in the $group and $setWindowFields stages. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/bottom/ - * @param array|stdClass $sortBy Specifies the order of results, with syntax similar to $sort. - * @param ExpressionInterface|mixed $output Represents the output for each element in the group and can be any expression. + * @param Document|Serializable|array|stdClass $sortBy Specifies the order of results, with syntax similar to $sort. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $output Represents the output for each element in the group and can be any expression. */ - public static function bottom(stdClass|array $sortBy, mixed $output): BottomAggregation + public static function bottom( + Document|Serializable|stdClass|array $sortBy, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $output, + ): BottomAggregation { return new BottomAggregation($sortBy, $output); } @@ -522,14 +544,14 @@ public static function bottom(stdClass|array $sortBy, mixed $output): BottomAggr * Available in the $group and $setWindowFields stages. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/bottomN/ - * @param Int64|ResolvesToInt|int $n 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. - * @param array|stdClass $sortBy Specifies the order of results, with syntax similar to $sort. - * @param ExpressionInterface|mixed $output Represents the output for each element in the group and can be any expression. + * @param ResolvesToInt|int $n 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. + * @param Document|Serializable|array|stdClass $sortBy Specifies the order of results, with syntax similar to $sort. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $output Represents the output for each element in the group and can be any expression. */ public static function bottomN( - Int64|ResolvesToInt|int $n, - stdClass|array $sortBy, - mixed $output, + ResolvesToInt|int $n, + Document|Serializable|stdClass|array $sortBy, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $output, ): BottomNAggregation { return new BottomNAggregation($n, $sortBy, $output); @@ -552,9 +574,11 @@ public static function bsonSize( * Returns the smallest integer greater than or equal to the specified number. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/ceil/ - * @param Decimal128|Int64|ResolvesToNumber|float|int $expression 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. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression 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. */ - public static function ceil(Decimal128|Int64|ResolvesToNumber|float|int $expression): CeilAggregation + public static function ceil( + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression, + ): CeilAggregation { return new CeilAggregation($expression); } @@ -563,10 +587,13 @@ public static function ceil(Decimal128|Int64|ResolvesToNumber|float|int $express * 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. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/cmp/ - * @param ExpressionInterface|mixed $expression1 - * @param ExpressionInterface|mixed $expression2 + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression1 + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression2 */ - public static function cmp(mixed $expression1, mixed $expression2): CmpAggregation + public static function cmp( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression1, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression2, + ): CmpAggregation { return new CmpAggregation($expression1, $expression2); } @@ -586,7 +613,7 @@ public static function concat(ResolvesToString|string ...$expression): ConcatAgg * Concatenates arrays to return the concatenated array. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/concatArrays/ - * @param BSONArray|PackedArray|ResolvesToArray|list ...$array + * @param BSONArray|PackedArray|ResolvesToArray|array ...$array */ public static function concatArrays( PackedArray|ResolvesToArray|BSONArray|array ...$array, @@ -600,10 +627,14 @@ public static function concatArrays( * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/cond/ * @param ResolvesToBool|bool $if - * @param ExpressionInterface|mixed $then - * @param ExpressionInterface|mixed $else + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $then + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $else */ - public static function cond(ResolvesToBool|bool $if, mixed $then, mixed $else): CondAggregation + public static function cond( + ResolvesToBool|bool $if, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $then, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $else, + ): CondAggregation { return new CondAggregation($if, $then, $else); } @@ -613,18 +644,18 @@ public static function cond(ResolvesToBool|bool $if, mixed $then, mixed $else): * New in version 4.0. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/convert/ - * @param ExpressionInterface|mixed $input - * @param Int64|ResolvesToInt|ResolvesToString|int|non-empty-string $to - * @param ExpressionInterface|Optional|mixed $onError The value to return on encountering an error during conversion, including unsupported type conversions. The arguments can be any valid expression. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $input + * @param ResolvesToInt|ResolvesToString|int|non-empty-string $to + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|Optional|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $onError 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. - * @param ExpressionInterface|Optional|mixed $onNull The value to return if the input is null or missing. The arguments can be any valid expression. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|Optional|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $onNull 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. */ public static function convert( - mixed $input, - Int64|ResolvesToInt|ResolvesToString|int|string $to, - mixed $onError = Optional::Undefined, - mixed $onNull = Optional::Undefined, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $input, + ResolvesToInt|ResolvesToString|int|string $to, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|Optional|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $onError = Optional::Undefined, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|Optional|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $onNull = Optional::Undefined, ): ConvertAggregation { return new ConvertAggregation($input, $to, $onError, $onNull); @@ -634,10 +665,12 @@ public static function convert( * Returns the cosine of a value that is measured in radians. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/cos/ - * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $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. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression $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. */ - public static function cos(Decimal128|Int64|ResolvesToNumber|float|int $expression): CosAggregation + public static function cos( + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression, + ): CosAggregation { return new CosAggregation($expression); } @@ -646,10 +679,12 @@ public static function cos(Decimal128|Int64|ResolvesToNumber|float|int $expressi * Returns the hyperbolic cosine of a value that is measured in radians. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/cosh/ - * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $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. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression $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. */ - public static function cosh(Decimal128|Int64|ResolvesToNumber|float|int $expression): CoshAggregation + public static function cosh( + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression, + ): CoshAggregation { return new CoshAggregation($expression); } @@ -672,12 +707,12 @@ public static function count(string $field): CountAggregation * New in version 5.0. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/covariancePop/ - * @param Decimal128|Int64|ResolvesToNumber|float|int $expression1 - * @param Decimal128|Int64|ResolvesToNumber|float|int $expression2 + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression1 + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression2 */ public static function covariancePop( - Decimal128|Int64|ResolvesToNumber|float|int $expression1, - Decimal128|Int64|ResolvesToNumber|float|int $expression2, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression1, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression2, ): CovariancePopAggregation { return new CovariancePopAggregation($expression1, $expression2); @@ -688,12 +723,12 @@ public static function covariancePop( * New in version 5.0. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/covarianceSamp/ - * @param Decimal128|Int64|ResolvesToNumber|float|int $expression1 - * @param Decimal128|Int64|ResolvesToNumber|float|int $expression2 + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression1 + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression2 */ public static function covarianceSamp( - Decimal128|Int64|ResolvesToNumber|float|int $expression1, - Decimal128|Int64|ResolvesToNumber|float|int $expression2, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression1, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression2, ): CovarianceSampAggregation { return new CovarianceSampAggregation($expression1, $expression2); @@ -703,13 +738,13 @@ public static function covarianceSamp( * Adds a number of time units to a date object. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateAdd/ - * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $startDate 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. + * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $startDate 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. * @param ResolvesToString|non-empty-string $unit The unit used to measure the amount of time added to the startDate. * @param Int64|ResolvesToInt|ResolvesToLong|int $amount * @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public static function dateAdd( - DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $startDate, + ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $startDate, ResolvesToString|string $unit, Int64|ResolvesToInt|ResolvesToLong|int $amount, ResolvesToString|Optional|string $timezone = Optional::Undefined, @@ -722,15 +757,15 @@ public static function dateAdd( * Returns the difference between two dates. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateDiff/ - * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $startDate The start of the time period. The startDate can be any expression that resolves to a Date, a Timestamp, or an ObjectID. - * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $endDate The end of the time period. The endDate can be any expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $startDate The start of the time period. The startDate can be any expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $endDate The end of the time period. The endDate can be any expression that resolves to a Date, a Timestamp, or an ObjectID. * @param ResolvesToString|non-empty-string $unit The time measurement unit between the startDate and endDate * @param Optional|ResolvesToString|non-empty-string $timezone 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. * @param Optional|ResolvesToString|non-empty-string $startOfWeek Used when the unit is equal to week. Defaults to Sunday. The startOfWeek parameter is an expression that resolves to a case insensitive string */ public static function dateDiff( - DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $startDate, - DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $endDate, + ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $startDate, + ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $endDate, ResolvesToString|string $unit, ResolvesToString|Optional|string $timezone = Optional::Undefined, ResolvesToString|Optional|string $startOfWeek = Optional::Undefined, @@ -743,29 +778,29 @@ public static function dateDiff( * Constructs a BSON Date object given the date's constituent parts. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateFromParts/ - * @param Decimal128|Int64|ResolvesToNumber|float|int $year Calendar year. Can be any expression that evaluates to a number. - * @param Decimal128|Int64|ResolvesToNumber|float|int $isoWeekYear ISO Week Date Year. Can be any expression that evaluates to a number. - * @param Decimal128|Int64|Optional|ResolvesToNumber|float|int $month Month. Defaults to 1. - * @param Decimal128|Int64|Optional|ResolvesToNumber|float|int $isoWeek Week of year. Defaults to 1. - * @param Decimal128|Int64|Optional|ResolvesToNumber|float|int $day Day of month. Defaults to 1. - * @param Decimal128|Int64|Optional|ResolvesToNumber|float|int $isoDayOfWeek Day of week (Monday 1 - Sunday 7). Defaults to 1. - * @param Decimal128|Int64|Optional|ResolvesToNumber|float|int $hour Hour. Defaults to 0. - * @param Decimal128|Int64|Optional|ResolvesToNumber|float|int $minute Minute. Defaults to 0. - * @param Decimal128|Int64|Optional|ResolvesToNumber|float|int $second Second. Defaults to 0. - * @param Decimal128|Int64|Optional|ResolvesToNumber|float|int $millisecond Millisecond. Defaults to 0. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $year Calendar year. Can be any expression that evaluates to a number. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $isoWeekYear ISO Week Date Year. Can be any expression that evaluates to a number. + * @param Decimal128|Int64|Optional|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $month Month. Defaults to 1. + * @param Decimal128|Int64|Optional|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $isoWeek Week of year. Defaults to 1. + * @param Decimal128|Int64|Optional|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $day Day of month. Defaults to 1. + * @param Decimal128|Int64|Optional|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $isoDayOfWeek Day of week (Monday 1 - Sunday 7). Defaults to 1. + * @param Decimal128|Int64|Optional|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $hour Hour. Defaults to 0. + * @param Decimal128|Int64|Optional|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $minute Minute. Defaults to 0. + * @param Decimal128|Int64|Optional|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $second Second. Defaults to 0. + * @param Decimal128|Int64|Optional|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $millisecond Millisecond. Defaults to 0. * @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public static function dateFromParts( - Decimal128|Int64|ResolvesToNumber|float|int $year, - Decimal128|Int64|ResolvesToNumber|float|int $isoWeekYear, - Decimal128|Int64|ResolvesToNumber|Optional|float|int $month = Optional::Undefined, - Decimal128|Int64|ResolvesToNumber|Optional|float|int $isoWeek = Optional::Undefined, - Decimal128|Int64|ResolvesToNumber|Optional|float|int $day = Optional::Undefined, - Decimal128|Int64|ResolvesToNumber|Optional|float|int $isoDayOfWeek = Optional::Undefined, - Decimal128|Int64|ResolvesToNumber|Optional|float|int $hour = Optional::Undefined, - Decimal128|Int64|ResolvesToNumber|Optional|float|int $minute = Optional::Undefined, - Decimal128|Int64|ResolvesToNumber|Optional|float|int $second = Optional::Undefined, - Decimal128|Int64|ResolvesToNumber|Optional|float|int $millisecond = Optional::Undefined, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $year, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $isoWeekYear, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|Optional|float|int $month = Optional::Undefined, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|Optional|float|int $isoWeek = Optional::Undefined, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|Optional|float|int $day = Optional::Undefined, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|Optional|float|int $isoDayOfWeek = Optional::Undefined, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|Optional|float|int $hour = Optional::Undefined, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|Optional|float|int $minute = Optional::Undefined, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|Optional|float|int $second = Optional::Undefined, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|Optional|float|int $millisecond = Optional::Undefined, ResolvesToString|Optional|string $timezone = Optional::Undefined, ): DateFromPartsAggregation { @@ -780,17 +815,17 @@ public static function dateFromParts( * @param Optional|ResolvesToString|non-empty-string $format 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. * @param Optional|ResolvesToString|non-empty-string $timezone The time zone to use to format the date. - * @param ExpressionInterface|Optional|mixed $onError 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. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|Optional|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $onError 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. - * @param ExpressionInterface|Optional|mixed $onNull 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. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|Optional|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $onNull 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. */ public static function dateFromString( ResolvesToString|string $dateString, ResolvesToString|Optional|string $format = Optional::Undefined, ResolvesToString|Optional|string $timezone = Optional::Undefined, - mixed $onError = Optional::Undefined, - mixed $onNull = Optional::Undefined, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|Optional|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $onError = Optional::Undefined, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|Optional|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $onNull = Optional::Undefined, ): DateFromStringAggregation { return new DateFromStringAggregation($dateString, $format, $timezone, $onError, $onNull); @@ -800,13 +835,13 @@ public static function dateFromString( * Subtracts a number of time units from a date object. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateSubtract/ - * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $startDate 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. + * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $startDate 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. * @param ResolvesToString|non-empty-string $unit The unit used to measure the amount of time added to the startDate. * @param Int64|ResolvesToInt|ResolvesToLong|int $amount * @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public static function dateSubtract( - DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $startDate, + ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $startDate, ResolvesToString|string $unit, Int64|ResolvesToInt|ResolvesToLong|int $amount, ResolvesToString|Optional|string $timezone = Optional::Undefined, @@ -819,12 +854,12 @@ public static function dateSubtract( * Returns a document containing the constituent parts of a date. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateToParts/ - * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The input date for which to return parts. date can be any expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The input date for which to return parts. date can be any expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|non-empty-string $timezone 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. * @param Optional|bool $iso8601 If set to true, modifies the output document to use ISO week date fields. Defaults to false. */ public static function dateToParts( - DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|Optional|string $timezone = Optional::Undefined, Optional|bool $iso8601 = Optional::Undefined, ): DateToPartsAggregation @@ -836,18 +871,18 @@ public static function dateToParts( * Returns the date as a formatted string. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateToString/ - * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to convert to string. Must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The date to convert to string. Must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|non-empty-string $format 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. * @param Optional|ResolvesToString|non-empty-string $timezone The time zone to use to format the date. - * @param ExpressionInterface|Optional|mixed $onNull The value to return if the date is null or missing. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|Optional|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $onNull The value to return if the date is null or missing. * If unspecified, $dateToString returns null if the date is null or missing. */ public static function dateToString( - DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|Optional|string $format = Optional::Undefined, ResolvesToString|Optional|string $timezone = Optional::Undefined, - mixed $onNull = Optional::Undefined, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|Optional|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $onNull = Optional::Undefined, ): DateToStringAggregation { return new DateToStringAggregation($date, $format, $timezone, $onNull); @@ -857,19 +892,19 @@ public static function dateToString( * Truncates a date. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateTrunc/ - * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to truncate, specified in UTC. The date can be any expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The date to truncate, specified in UTC. The date can be any expression that resolves to a Date, a Timestamp, or an ObjectID. * @param ResolvesToString|non-empty-string $unit 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. - * @param Decimal128|Int64|Optional|ResolvesToNumber|float|int $binSize The numeric time value, specified as an expression that must resolve to a positive non-zero number. Defaults to 1. + * @param Decimal128|Int64|Optional|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $binSize 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. * @param Optional|ResolvesToString|non-empty-string $timezone 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. * @param Optional|non-empty-string $startOfWeek The start of the week. Used when * unit is week. Defaults to Sunday. */ public static function dateTrunc( - DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|string $unit, - Decimal128|Int64|ResolvesToNumber|Optional|float|int $binSize = Optional::Undefined, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|Optional|float|int $binSize = Optional::Undefined, ResolvesToString|Optional|string $timezone = Optional::Undefined, Optional|string $startOfWeek = Optional::Undefined, ): DateTruncAggregation @@ -881,11 +916,11 @@ public static function dateTrunc( * Returns the day of the month for a date as a number between 1 and 31. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/dayOfMonth/ - * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public static function dayOfMonth( - DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|Optional|string $timezone = Optional::Undefined, ): DayOfMonthAggregation { @@ -896,11 +931,11 @@ public static function dayOfMonth( * Returns the day of the week for a date as a number between 1 (Sunday) and 7 (Saturday). * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/dayOfWeek/ - * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public static function dayOfWeek( - DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|Optional|string $timezone = Optional::Undefined, ): DayOfWeekAggregation { @@ -911,11 +946,11 @@ public static function dayOfWeek( * Returns the day of the year for a date as a number between 1 and 366 (leap year). * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/dayOfYear/ - * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public static function dayOfYear( - DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|Optional|string $timezone = Optional::Undefined, ): DayOfYearAggregation { @@ -926,11 +961,11 @@ public static function dayOfYear( * Converts a value from degrees to radians. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/degreesToRadians/ - * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $degreesToRadians takes any valid expression that resolves to a number. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression $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. */ public static function degreesToRadians( - Decimal128|Int64|ResolvesToNumber|float|int $expression, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression, ): DegreesToRadiansAggregation { return new DegreesToRadiansAggregation($expression); @@ -952,12 +987,12 @@ public static function denseRank(): DenseRankAggregation * New in version 5.0. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/derivative/ - * @param DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int $input + * @param Decimal128|Int64|ResolvesToDate|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|UTCDateTime|float|int $input * @param Optional|non-empty-string $unit 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. */ public static function derivative( - DateTimeInterface|Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int $input, + Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $input, Optional|string $unit = Optional::Undefined, ): DerivativeAggregation { @@ -968,12 +1003,12 @@ public static function derivative( * Returns the result of dividing the first number by the second. Accepts two argument expressions. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/divide/ - * @param Decimal128|Int64|ResolvesToNumber|float|int $dividend The first argument is the dividend, and the second argument is the divisor; i.e. the first argument is divided by the second argument. - * @param Decimal128|Int64|ResolvesToNumber|float|int $divisor + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $dividend The first argument is the dividend, and the second argument is the divisor; i.e. the first argument is divided by the second argument. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $divisor */ public static function divide( - Decimal128|Int64|ResolvesToNumber|float|int $dividend, - Decimal128|Int64|ResolvesToNumber|float|int $divisor, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $dividend, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $divisor, ): DivideAggregation { return new DivideAggregation($dividend, $divisor); @@ -994,10 +1029,13 @@ public static function documentNumber(): DocumentNumberAggregation * Returns true if the values are equivalent. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/eq/ - * @param ExpressionInterface|mixed $expression1 - * @param ExpressionInterface|mixed $expression2 + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression1 + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression2 */ - public static function eq(mixed $expression1, mixed $expression2): EqAggregation + public static function eq( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression1, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression2, + ): EqAggregation { return new EqAggregation($expression1, $expression2); } @@ -1006,9 +1044,11 @@ public static function eq(mixed $expression1, mixed $expression2): EqAggregation * Raises e to the specified exponent. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/exp/ - * @param Decimal128|Int64|ResolvesToNumber|float|int $exponent + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $exponent */ - public static function exp(Decimal128|Int64|ResolvesToNumber|float|int $exponent): ExpAggregation + public static function exp( + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $exponent, + ): ExpAggregation { return new ExpAggregation($exponent); } @@ -1018,16 +1058,16 @@ public static function exp(Decimal128|Int64|ResolvesToNumber|float|int $exponent * New in version 5.0. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/expMovingAvg/ - * @param Decimal128|Int64|ResolvesToNumber|float|int $input - * @param Int64|Optional|int $N 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. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $input + * @param Optional|int $N 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: * @param Int64|Optional|float|int $alpha 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. */ public static function expMovingAvg( - Decimal128|Int64|ResolvesToNumber|float|int $input, - Int64|Optional|int $N = Optional::Undefined, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $input, + Optional|int $N = Optional::Undefined, Int64|Optional|float|int $alpha = Optional::Undefined, ): ExpMovingAvgAggregation { @@ -1038,17 +1078,17 @@ public static function expMovingAvg( * Selects a subset of the array to return an array with only the elements that match the filter condition. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/filter/ - * @param BSONArray|PackedArray|ResolvesToArray|list $input + * @param BSONArray|PackedArray|ResolvesToArray|array $input * @param ResolvesToBool|bool $cond 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. * @param Optional|non-empty-string $as 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. - * @param Int64|Optional|ResolvesToInt|int $limit 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. + * @param Optional|ResolvesToInt|int $limit 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. */ public static function filter( PackedArray|ResolvesToArray|BSONArray|array $input, ResolvesToBool|bool $cond, Optional|string $as = Optional::Undefined, - Int64|ResolvesToInt|Optional|int $limit = Optional::Undefined, + ResolvesToInt|Optional|int $limit = Optional::Undefined, ): FilterAggregation { return new FilterAggregation($input, $cond, $as, $limit); @@ -1059,9 +1099,11 @@ public static function filter( * Changed in version 5.0: Available in the $setWindowFields stage. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/first/ - * @param ExpressionInterface|mixed $expression + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression */ - public static function first(mixed $expression): FirstAggregation + public static function first( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, + ): FirstAggregation { return new FirstAggregation($expression); } @@ -1070,12 +1112,12 @@ public static function first(mixed $expression): FirstAggregation * Returns a specified number of elements from the beginning of an array. Distinct from the $firstN accumulator. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/firstN-array-element/ - * @param BSONArray|PackedArray|ResolvesToArray|list $input An expression that resolves to the array from which to return n elements. - * @param Int64|ResolvesToInt|int $n An expression that resolves to a positive integer. The integer specifies the number of array elements that $firstN returns. + * @param BSONArray|PackedArray|ResolvesToArray|array $input An expression that resolves to the array from which to return n elements. + * @param ResolvesToInt|int $n An expression that resolves to a positive integer. The integer specifies the number of array elements that $firstN returns. */ public static function firstN( PackedArray|ResolvesToArray|BSONArray|array $input, - Int64|ResolvesToInt|int $n, + ResolvesToInt|int $n, ): FirstNAggregation { return new FirstNAggregation($input, $n); @@ -1085,9 +1127,11 @@ public static function firstN( * Returns the largest integer less than or equal to the specified number. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/floor/ - * @param Decimal128|Int64|ResolvesToNumber|float|int $expression + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression */ - public static function floor(Decimal128|Int64|ResolvesToNumber|float|int $expression): FloorAggregation + public static function floor( + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression, + ): FloorAggregation { return new FloorAggregation($expression); } @@ -1098,7 +1142,7 @@ public static function floor(Decimal128|Int64|ResolvesToNumber|float|int $expres * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/function/ * @param non-empty-string $body The function definition. You can specify the function definition as either BSON type Code or String. - * @param BSONArray|PackedArray|list $args Arguments passed to the function body. If the body function does not take an argument, you can specify an empty array [ ]. + * @param BSONArray|PackedArray|array $args Arguments passed to the function body. If the body function does not take an argument, you can specify an empty array [ ]. * @param non-empty-string $lang */ public static function function( @@ -1117,10 +1161,13 @@ public static function function( * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/getField/ * @param non-empty-string $field 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. - * @param ExpressionInterface|Optional|mixed $input Default: $$CURRENT + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|Optional|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $input 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). */ - public static function getField(string $field, mixed $input = Optional::Undefined): GetFieldAggregation + public static function getField( + string $field, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|Optional|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $input = Optional::Undefined, + ): GetFieldAggregation { return new GetFieldAggregation($field, $input); } @@ -1129,10 +1176,13 @@ public static function getField(string $field, mixed $input = Optional::Undefine * Returns true if the first value is greater than the second. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/gt/ - * @param ExpressionInterface|mixed $expression1 - * @param ExpressionInterface|mixed $expression2 + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression1 + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression2 */ - public static function gt(mixed $expression1, mixed $expression2): GtAggregation + public static function gt( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression1, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression2, + ): GtAggregation { return new GtAggregation($expression1, $expression2); } @@ -1141,10 +1191,13 @@ public static function gt(mixed $expression1, mixed $expression2): GtAggregation * Returns true if the first value is greater than or equal to the second. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/gte/ - * @param ExpressionInterface|mixed $expression1 - * @param ExpressionInterface|mixed $expression2 + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression1 + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression2 */ - public static function gte(mixed $expression1, mixed $expression2): GteAggregation + public static function gte( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression1, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression2, + ): GteAggregation { return new GteAggregation($expression1, $expression2); } @@ -1153,11 +1206,11 @@ public static function gte(mixed $expression1, mixed $expression2): GteAggregati * Returns the hour for a date as a number between 0 and 23. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/hour/ - * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public static function hour( - DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|Optional|string $timezone = Optional::Undefined, ): HourAggregation { @@ -1168,9 +1221,11 @@ public static function hour( * 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. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/ifNull/ - * @param ExpressionInterface|mixed ...$expression + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass ...$expression */ - public static function ifNull(mixed ...$expression): IfNullAggregation + public static function ifNull( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string ...$expression, + ): IfNullAggregation { return new IfNullAggregation(...$expression); } @@ -1179,10 +1234,13 @@ public static function ifNull(mixed ...$expression): IfNullAggregation * Returns a boolean indicating whether a specified value is in an array. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/in/ - * @param ExpressionInterface|mixed $expression Any valid expression expression. - * @param BSONArray|PackedArray|ResolvesToArray|list $array Any valid expression that resolves to an array. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression Any valid expression expression. + * @param BSONArray|PackedArray|ResolvesToArray|array $array Any valid expression that resolves to an array. */ - public static function in(mixed $expression, PackedArray|ResolvesToArray|BSONArray|array $array): InAggregation + public static function in( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, + PackedArray|ResolvesToArray|BSONArray|array $array, + ): InAggregation { return new InAggregation($expression, $array); } @@ -1194,17 +1252,17 @@ public static function in(mixed $expression, PackedArray|ResolvesToArray|BSONArr * @param ResolvesToString|non-empty-string $array 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. - * @param ExpressionInterface|mixed $search - * @param Int64|Optional|ResolvesToInt|int $start 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. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $search + * @param Optional|ResolvesToInt|int $start 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. - * @param Int64|Optional|ResolvesToInt|int $end 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. + * @param Optional|ResolvesToInt|int $end 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. */ public static function indexOfArray( ResolvesToString|string $array, - mixed $search, - Int64|ResolvesToInt|Optional|int $start = Optional::Undefined, - Int64|ResolvesToInt|Optional|int $end = Optional::Undefined, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $search, + ResolvesToInt|Optional|int $start = Optional::Undefined, + ResolvesToInt|Optional|int $end = Optional::Undefined, ): IndexOfArrayAggregation { return new IndexOfArrayAggregation($array, $search, $start, $end); @@ -1218,16 +1276,16 @@ public static function indexOfArray( * 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. * @param ResolvesToString|non-empty-string $substring Can be any valid expression as long as it resolves to a string. - * @param Int64|Optional|ResolvesToInt|int $start 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. + * @param Optional|ResolvesToInt|int $start 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. - * @param Int64|Optional|ResolvesToInt|int $end 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. + * @param Optional|ResolvesToInt|int $end 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. */ public static function indexOfBytes( ResolvesToString|string $string, ResolvesToString|string $substring, - Int64|ResolvesToInt|Optional|int $start = Optional::Undefined, - Int64|ResolvesToInt|Optional|int $end = Optional::Undefined, + ResolvesToInt|Optional|int $start = Optional::Undefined, + ResolvesToInt|Optional|int $end = Optional::Undefined, ): IndexOfBytesAggregation { return new IndexOfBytesAggregation($string, $substring, $start, $end); @@ -1241,16 +1299,16 @@ public static function indexOfBytes( * 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. * @param ResolvesToString|non-empty-string $substring Can be any valid expression as long as it resolves to a string. - * @param Int64|Optional|ResolvesToInt|int $start 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. + * @param Optional|ResolvesToInt|int $start 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. - * @param Int64|Optional|ResolvesToInt|int $end 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. + * @param Optional|ResolvesToInt|int $end 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. */ public static function indexOfCP( ResolvesToString|string $string, ResolvesToString|string $substring, - Int64|ResolvesToInt|Optional|int $start = Optional::Undefined, - Int64|ResolvesToInt|Optional|int $end = Optional::Undefined, + ResolvesToInt|Optional|int $start = Optional::Undefined, + ResolvesToInt|Optional|int $end = Optional::Undefined, ): IndexOfCPAggregation { return new IndexOfCPAggregation($string, $substring, $start, $end); @@ -1261,12 +1319,12 @@ public static function indexOfCP( * New in version 5.0. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/integral/ - * @param DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int $input + * @param Decimal128|Int64|ResolvesToDate|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|UTCDateTime|float|int $input * @param Optional|ResolvesToString|non-empty-string $unit 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. */ public static function integral( - DateTimeInterface|Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int $input, + Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $input, ResolvesToString|Optional|string $unit = Optional::Undefined, ): IntegralAggregation { @@ -1277,9 +1335,11 @@ public static function integral( * Determines if the operand is an array. Returns a boolean. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/isArray/ - * @param ExpressionInterface|mixed ...$expression + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass ...$expression */ - public static function isArray(mixed ...$expression): IsArrayAggregation + public static function isArray( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string ...$expression, + ): IsArrayAggregation { return new IsArrayAggregation(...$expression); } @@ -1290,9 +1350,11 @@ public static function isArray(mixed ...$expression): IsArrayAggregation * New in version 4.4. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/isNumber/ - * @param ExpressionInterface|mixed ...$expression + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass ...$expression */ - public static function isNumber(mixed ...$expression): IsNumberAggregation + public static function isNumber( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string ...$expression, + ): IsNumberAggregation { return new IsNumberAggregation(...$expression); } @@ -1301,11 +1363,11 @@ public static function isNumber(mixed ...$expression): IsNumberAggregation * Returns the weekday number in ISO 8601 format, ranging from 1 (for Monday) to 7 (for Sunday). * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/isoDayOfWeek/ - * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public static function isoDayOfWeek( - DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|Optional|string $timezone = Optional::Undefined, ): IsoDayOfWeekAggregation { @@ -1316,11 +1378,11 @@ public static function isoDayOfWeek( * 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. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/isoWeek/ - * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public static function isoWeek( - DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|Optional|string $timezone = Optional::Undefined, ): IsoWeekAggregation { @@ -1331,11 +1393,11 @@ public static function isoWeek( * 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). * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/isoWeekYear/ - * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public static function isoWeekYear( - DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|Optional|string $timezone = Optional::Undefined, ): IsoWeekYearAggregation { @@ -1347,9 +1409,11 @@ public static function isoWeekYear( * Changed in version 5.0: Available in the $setWindowFields stage. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/last/ - * @param ExpressionInterface|mixed $expression + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression */ - public static function last(mixed $expression): LastAggregation + public static function last( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, + ): LastAggregation { return new LastAggregation($expression); } @@ -1358,12 +1422,12 @@ public static function last(mixed $expression): LastAggregation * Returns a specified number of elements from the end of an array. Distinct from the $lastN accumulator. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/lastN/ - * @param BSONArray|PackedArray|ResolvesToArray|list $input An expression that resolves to the array from which to return n elements. - * @param Int64|ResolvesToInt|int $n An expression that resolves to a positive integer. The integer specifies the number of array elements that $firstN returns. + * @param BSONArray|PackedArray|ResolvesToArray|array $input An expression that resolves to the array from which to return n elements. + * @param ResolvesToInt|int $n An expression that resolves to a positive integer. The integer specifies the number of array elements that $firstN returns. */ public static function lastN( PackedArray|ResolvesToArray|BSONArray|array $input, - Int64|ResolvesToInt|int $n, + ResolvesToInt|int $n, ): LastNAggregation { return new LastNAggregation($input, $n); @@ -1376,9 +1440,12 @@ public static function lastN( * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/let/ * @param Document|Serializable|array|stdClass $vars 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. - * @param ExpressionInterface|mixed $in The expression to evaluate. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $in The expression to evaluate. */ - public static function let(Document|Serializable|stdClass|array $vars, mixed $in): LetAggregation + public static function let( + Document|Serializable|stdClass|array $vars, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $in, + ): LetAggregation { return new LetAggregation($vars, $in); } @@ -1389,9 +1456,11 @@ public static function let(Document|Serializable|stdClass|array $vars, mixed $in * New in version 5.3. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/linearFill/ - * @param Decimal128|Int64|ResolvesToNumber|float|int $expression + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression */ - public static function linearFill(Decimal128|Int64|ResolvesToNumber|float|int $expression): LinearFillAggregation + public static function linearFill( + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression, + ): LinearFillAggregation { return new LinearFillAggregation($expression); } @@ -1400,9 +1469,11 @@ public static function linearFill(Decimal128|Int64|ResolvesToNumber|float|int $e * 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. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/literal/ - * @param mixed $value If the value is an expression, $literal does not evaluate the expression but instead returns the unparsed expression. + * @param BSONArray|Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $value If the value is an expression, $literal does not evaluate the expression but instead returns the unparsed expression. */ - public static function literal(mixed $value): LiteralAggregation + public static function literal( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|BSONArray|stdClass|array|bool|float|int|null|string $value, + ): LiteralAggregation { return new LiteralAggregation($value); } @@ -1412,9 +1483,11 @@ public static function literal(mixed $value): LiteralAggregation * $ln is equivalent to $log: [ , Math.E ] expression, where Math.E is a JavaScript representation for Euler's number e. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/ln/ - * @param Decimal128|Int64|ResolvesToNumber|float|int $number Any valid expression as long as it resolves to a non-negative number. For more information on expressions, see Expressions. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $number Any valid expression as long as it resolves to a non-negative number. For more information on expressions, see Expressions. */ - public static function ln(Decimal128|Int64|ResolvesToNumber|float|int $number): LnAggregation + public static function ln( + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $number, + ): LnAggregation { return new LnAggregation($number); } @@ -1425,9 +1498,11 @@ public static function ln(Decimal128|Int64|ResolvesToNumber|float|int $number): * New in version 5.2. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/locf/ - * @param ExpressionInterface|mixed $expression + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression */ - public static function locf(mixed $expression): LocfAggregation + public static function locf( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, + ): LocfAggregation { return new LocfAggregation($expression); } @@ -1436,12 +1511,12 @@ public static function locf(mixed $expression): LocfAggregation * Calculates the log of a number in the specified base. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/log/ - * @param Decimal128|Int64|ResolvesToNumber|float|int $number Any valid expression as long as it resolves to a non-negative number. - * @param Decimal128|Int64|ResolvesToNumber|float|int $base Any valid expression as long as it resolves to a positive number greater than 1. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $number Any valid expression as long as it resolves to a non-negative number. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $base Any valid expression as long as it resolves to a positive number greater than 1. */ public static function log( - Decimal128|Int64|ResolvesToNumber|float|int $number, - Decimal128|Int64|ResolvesToNumber|float|int $base, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $number, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $base, ): LogAggregation { return new LogAggregation($number, $base); @@ -1451,9 +1526,11 @@ public static function log( * Calculates the log base 10 of a number. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/log10/ - * @param Decimal128|Int64|ResolvesToNumber|float|int $number Any valid expression as long as it resolves to a non-negative number. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $number Any valid expression as long as it resolves to a non-negative number. */ - public static function log10(Decimal128|Int64|ResolvesToNumber|float|int $number): Log10Aggregation + public static function log10( + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $number, + ): Log10Aggregation { return new Log10Aggregation($number); } @@ -1462,10 +1539,13 @@ public static function log10(Decimal128|Int64|ResolvesToNumber|float|int $number * Returns true if the first value is less than the second. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/lt/ - * @param ExpressionInterface|mixed $expression1 - * @param ExpressionInterface|mixed $expression2 + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression1 + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression2 */ - public static function lt(mixed $expression1, mixed $expression2): LtAggregation + public static function lt( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression1, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression2, + ): LtAggregation { return new LtAggregation($expression1, $expression2); } @@ -1474,10 +1554,13 @@ public static function lt(mixed $expression1, mixed $expression2): LtAggregation * Returns true if the first value is less than or equal to the second. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/lte/ - * @param ExpressionInterface|mixed $expression1 - * @param ExpressionInterface|mixed $expression2 + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression1 + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression2 */ - public static function lte(mixed $expression1, mixed $expression2): LteAggregation + public static function lte( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression1, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression2, + ): LteAggregation { return new LteAggregation($expression1, $expression2); } @@ -1504,13 +1587,13 @@ public static function ltrim( * Applies a subexpression to each element of an array and returns the array of resulting values in order. Accepts named parameters. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/map/ - * @param BSONArray|PackedArray|ResolvesToArray|list $input An expression that resolves to an array. - * @param ExpressionInterface|mixed $in 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. + * @param BSONArray|PackedArray|ResolvesToArray|array $input An expression that resolves to an array. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $in 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. * @param Optional|ResolvesToString|non-empty-string $as 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. */ public static function map( PackedArray|ResolvesToArray|BSONArray|array $input, - mixed $in, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $in, ResolvesToString|Optional|string $as = Optional::Undefined, ): MapAggregation { @@ -1522,9 +1605,11 @@ public static function map( * Changed in version 5.0: Available in the $setWindowFields stage. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/max/ - * @param ExpressionInterface|mixed ...$expression + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass ...$expression */ - public static function max(mixed ...$expression): MaxAggregation + public static function max( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string ...$expression, + ): MaxAggregation { return new MaxAggregation(...$expression); } @@ -1533,12 +1618,12 @@ public static function max(mixed ...$expression): MaxAggregation * Returns the n largest values in an array. Distinct from the $maxN accumulator. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/maxN-array-element/ - * @param BSONArray|PackedArray|ResolvesToArray|list $input An expression that resolves to the array from which to return the maximal n elements. - * @param Int64|ResolvesToInt|int $n An expression that resolves to a positive integer. The integer specifies the number of array elements that $maxN returns. + * @param BSONArray|PackedArray|ResolvesToArray|array $input An expression that resolves to the array from which to return the maximal n elements. + * @param ResolvesToInt|int $n An expression that resolves to a positive integer. The integer specifies the number of array elements that $maxN returns. */ public static function maxN( PackedArray|ResolvesToArray|BSONArray|array $input, - Int64|ResolvesToInt|int $n, + ResolvesToInt|int $n, ): MaxNAggregation { return new MaxNAggregation($input, $n); @@ -1553,11 +1638,11 @@ public static function maxN( * It is also available as an aggregation expression. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/median/ - * @param Decimal128|Int64|ResolvesToNumber|float|int $input $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. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $input $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. * @param non-empty-string $method The method that mongod uses to calculate the 50th percentile value. The method must be 'approximate'. */ public static function median( - Decimal128|Int64|ResolvesToNumber|float|int $input, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $input, string $method, ): MedianAggregation { @@ -1592,11 +1677,11 @@ public static function meta(string $keyword): MetaAggregation * Returns the milliseconds of a date as a number between 0 and 999. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/millisecond/ - * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public static function millisecond( - DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|Optional|string $timezone = Optional::Undefined, ): MillisecondAggregation { @@ -1608,9 +1693,11 @@ public static function millisecond( * Changed in version 5.0: Available in the $setWindowFields stage. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/min/ - * @param ExpressionInterface|mixed ...$expression + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass ...$expression */ - public static function min(mixed ...$expression): MinAggregation + public static function min( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string ...$expression, + ): MinAggregation { return new MinAggregation(...$expression); } @@ -1619,12 +1706,12 @@ public static function min(mixed ...$expression): MinAggregation * Returns the n smallest values in an array. Distinct from the $minN accumulator. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/minN-array-element/ - * @param BSONArray|PackedArray|ResolvesToArray|list $input An expression that resolves to the array from which to return the maximal n elements. - * @param Int64|ResolvesToInt|int $n An expression that resolves to a positive integer. The integer specifies the number of array elements that $maxN returns. + * @param BSONArray|PackedArray|ResolvesToArray|array $input An expression that resolves to the array from which to return the maximal n elements. + * @param ResolvesToInt|int $n An expression that resolves to a positive integer. The integer specifies the number of array elements that $maxN returns. */ public static function minN( PackedArray|ResolvesToArray|BSONArray|array $input, - Int64|ResolvesToInt|int $n, + ResolvesToInt|int $n, ): MinNAggregation { return new MinNAggregation($input, $n); @@ -1634,11 +1721,11 @@ public static function minN( * Returns the minute for a date as a number between 0 and 59. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/minute/ - * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public static function minute( - DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|Optional|string $timezone = Optional::Undefined, ): MinuteAggregation { @@ -1649,12 +1736,12 @@ public static function minute( * Returns the remainder of the first number divided by the second. Accepts two argument expressions. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/mod/ - * @param Decimal128|Int64|ResolvesToNumber|float|int $dividend The first argument is the dividend, and the second argument is the divisor; i.e. first argument is divided by the second argument. - * @param Decimal128|Int64|ResolvesToNumber|float|int $divisor + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $dividend The first argument is the dividend, and the second argument is the divisor; i.e. first argument is divided by the second argument. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $divisor */ public static function mod( - Decimal128|Int64|ResolvesToNumber|float|int $dividend, - Decimal128|Int64|ResolvesToNumber|float|int $divisor, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $dividend, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $divisor, ): ModAggregation { return new ModAggregation($dividend, $divisor); @@ -1664,11 +1751,11 @@ public static function mod( * Returns the month for a date as a number between 1 (January) and 12 (December). * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/month/ - * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public static function month( - DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|Optional|string $timezone = Optional::Undefined, ): MonthAggregation { @@ -1679,10 +1766,12 @@ public static function month( * Multiplies numbers to return the product. Accepts any number of argument expressions. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/multiply/ - * @param Decimal128|Int64|ResolvesToNumber|float|int ...$expression The arguments can be any valid expression as long as they resolve to numbers. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int ...$expression 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. */ - public static function multiply(Decimal128|Int64|ResolvesToNumber|float|int ...$expression): MultiplyAggregation + public static function multiply( + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int ...$expression, + ): MultiplyAggregation { return new MultiplyAggregation(...$expression); } @@ -1691,10 +1780,13 @@ public static function multiply(Decimal128|Int64|ResolvesToNumber|float|int ...$ * Returns true if the values are not equivalent. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/ne/ - * @param ExpressionInterface|mixed $expression1 - * @param ExpressionInterface|mixed $expression2 + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression1 + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression2 */ - public static function ne(mixed $expression1, mixed $expression2): NeAggregation + public static function ne( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression1, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression2, + ): NeAggregation { return new NeAggregation($expression1, $expression2); } @@ -1703,9 +1795,11 @@ public static function ne(mixed $expression1, mixed $expression2): NeAggregation * Returns the boolean value that is the opposite of its argument expression. Accepts a single argument expression. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/not/ - * @param ExpressionInterface|ResolvesToBool|bool|mixed $expression + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToBool|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression */ - public static function not(mixed $expression): NotAggregation + public static function not( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToBool|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, + ): NotAggregation { return new NotAggregation($expression); } @@ -1727,9 +1821,11 @@ public static function objectToArray( * Returns true when any of its expressions evaluates to true. Accepts any number of argument expressions. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/or/ - * @param ExpressionInterface|ResolvesToBool|bool|mixed ...$expression + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToBool|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass ...$expression */ - public static function or(mixed ...$expression): OrAggregation + public static function or( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToBool|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string ...$expression, + ): OrAggregation { return new OrAggregation(...$expression); } @@ -1746,13 +1842,13 @@ public static function or(mixed ...$expression): OrAggregation * It is also available as an aggregation expression. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/percentile/ - * @param Decimal128|Int64|ResolvesToNumber|float|int $input $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. - * @param BSONArray|PackedArray|ResolvesToArray|list $p $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. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $input $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. + * @param BSONArray|PackedArray|ResolvesToArray|array $p $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. * @param non-empty-string $method The method that mongod uses to calculate the percentile value. The method must be 'approximate'. */ public static function percentile( - Decimal128|Int64|ResolvesToNumber|float|int $input, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $input, PackedArray|ResolvesToArray|BSONArray|array $p, string $method, ): PercentileAggregation @@ -1764,12 +1860,12 @@ public static function percentile( * Raises a number to the specified exponent. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/pow/ - * @param Decimal128|Int64|ResolvesToNumber|float|int $number - * @param Decimal128|Int64|ResolvesToNumber|float|int $exponent + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $number + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $exponent */ public static function pow( - Decimal128|Int64|ResolvesToNumber|float|int $number, - Decimal128|Int64|ResolvesToNumber|float|int $exponent, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $number, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $exponent, ): PowAggregation { return new PowAggregation($number, $exponent); @@ -1780,9 +1876,11 @@ public static function pow( * Changed in version 5.0: Available in the $setWindowFields stage. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/push/ - * @param ExpressionInterface|mixed $expression + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression */ - public static function push(mixed $expression): PushAggregation + public static function push( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, + ): PushAggregation { return new PushAggregation($expression); } @@ -1791,10 +1889,10 @@ public static function push(mixed $expression): PushAggregation * Converts a value from radians to degrees. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/radiansToDegrees/ - * @param Decimal128|Int64|ResolvesToNumber|float|int $expression + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression */ public static function radiansToDegrees( - Decimal128|Int64|ResolvesToNumber|float|int $expression, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression, ): RadiansToDegreesAggregation { return new RadiansToDegreesAggregation($expression); @@ -1814,14 +1912,14 @@ public static function rand(): RandAggregation * Outputs an array containing a sequence of integers according to user-defined inputs. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/range/ - * @param Int64|ResolvesToInt|int $start An integer that specifies the start of the sequence. Can be any valid expression that resolves to an integer. - * @param Int64|ResolvesToInt|int $end An integer that specifies the exclusive upper limit of the sequence. Can be any valid expression that resolves to an integer. - * @param Int64|Optional|ResolvesToInt|int $step An integer that specifies the increment value. Can be any valid expression that resolves to a non-zero integer. Defaults to 1. + * @param ResolvesToInt|int $start An integer that specifies the start of the sequence. Can be any valid expression that resolves to an integer. + * @param ResolvesToInt|int $end An integer that specifies the exclusive upper limit of the sequence. Can be any valid expression that resolves to an integer. + * @param Optional|ResolvesToInt|int $step An integer that specifies the increment value. Can be any valid expression that resolves to a non-zero integer. Defaults to 1. */ public static function range( - Int64|ResolvesToInt|int $start, - Int64|ResolvesToInt|int $end, - Int64|ResolvesToInt|Optional|int $step = Optional::Undefined, + ResolvesToInt|int $start, + ResolvesToInt|int $end, + ResolvesToInt|Optional|int $step = Optional::Undefined, ): RangeAggregation { return new RangeAggregation($start, $end, $step); @@ -1842,19 +1940,19 @@ public static function rank(): RankAggregation * Applies an expression to each element in an array and combines them into a single value. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/reduce/ - * @param BSONArray|PackedArray|ResolvesToArray|list $input Can be any valid expression that resolves to an array. + * @param BSONArray|PackedArray|ResolvesToArray|array $input 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. - * @param ExpressionInterface|mixed $initialValue The initial cumulative value set before in is applied to the first element of the input array. - * @param ExpressionInterface|mixed $in 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. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $initialValue The initial cumulative value set before in is applied to the first element of the input array. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $in 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. */ public static function reduce( PackedArray|ResolvesToArray|BSONArray|array $input, - mixed $initialValue, - mixed $in, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $initialValue, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $in, ): ReduceAggregation { return new ReduceAggregation($input, $initialValue, $in); @@ -1955,7 +2053,7 @@ public static function replaceOne( * Returns an array with the elements in reverse order. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/reverseArray/ - * @param BSONArray|PackedArray|ResolvesToArray|list $expression The argument can be any valid expression as long as it resolves to an array. + * @param BSONArray|PackedArray|ResolvesToArray|array $expression The argument can be any valid expression as long as it resolves to an array. */ public static function reverseArray( PackedArray|ResolvesToArray|BSONArray|array $expression, @@ -1970,11 +2068,11 @@ public static function reverseArray( * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/round/ * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|float|int $number 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. - * @param Int64|Optional|ResolvesToInt|int $place Can be any valid expression that resolves to an integer between -20 and 100, exclusive. + * @param Optional|ResolvesToInt|int $place Can be any valid expression that resolves to an integer between -20 and 100, exclusive. */ public static function round( Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|float|int $number, - Int64|ResolvesToInt|Optional|int $place = Optional::Undefined, + ResolvesToInt|Optional|int $place = Optional::Undefined, ): RoundAggregation { return new RoundAggregation($number, $place); @@ -2001,10 +2099,10 @@ public static function rtrim( * 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. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/sampleRate/ - * @param Int64|ResolvesToFloat|float|int $rate 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. + * @param Int64|ResolvesToDouble|float|int $rate 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. */ - public static function sampleRate(Int64|ResolvesToFloat|float|int $rate): SampleRateAggregation + public static function sampleRate(Int64|ResolvesToDouble|float|int $rate): SampleRateAggregation { return new SampleRateAggregation($rate); } @@ -2013,11 +2111,11 @@ public static function sampleRate(Int64|ResolvesToFloat|float|int $rate): Sample * Returns the seconds for a date as a number between 0 and 60 (leap seconds). * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/second/ - * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public static function second( - DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|Optional|string $timezone = Optional::Undefined, ): SecondAggregation { @@ -2028,8 +2126,8 @@ public static function second( * 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. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/setDifference/ - * @param BSONArray|PackedArray|ResolvesToArray|list $expression1 The arguments can be any valid expression as long as they each resolve to an array. - * @param BSONArray|PackedArray|ResolvesToArray|list $expression2 The arguments can be any valid expression as long as they each resolve to an array. + * @param BSONArray|PackedArray|ResolvesToArray|array $expression1 The arguments can be any valid expression as long as they each resolve to an array. + * @param BSONArray|PackedArray|ResolvesToArray|array $expression2 The arguments can be any valid expression as long as they each resolve to an array. */ public static function setDifference( PackedArray|ResolvesToArray|BSONArray|array $expression1, @@ -2043,7 +2141,7 @@ public static function setDifference( * Returns true if the input sets have the same distinct elements. Accepts two or more argument expressions. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/setEquals/ - * @param BSONArray|PackedArray|ResolvesToArray|list ...$expression + * @param BSONArray|PackedArray|ResolvesToArray|array ...$expression */ public static function setEquals(PackedArray|ResolvesToArray|BSONArray|array ...$expression): SetEqualsAggregation { @@ -2057,13 +2155,13 @@ public static function setEquals(PackedArray|ResolvesToArray|BSONArray|array ... * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/setField/ * @param ResolvesToString|non-empty-string $field 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. * @param Document|ResolvesToObject|Serializable|array|stdClass $input Document that contains the field that you want to add or update. input must resolve to an object, missing, null, or undefined. - * @param ExpressionInterface|mixed $value The value that you want to assign to field. value can be any valid expression. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $value 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. */ public static function setField( ResolvesToString|string $field, Document|Serializable|ResolvesToObject|stdClass|array $input, - mixed $value, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $value, ): SetFieldAggregation { return new SetFieldAggregation($field, $input, $value); @@ -2073,7 +2171,7 @@ public static function setField( * Returns a set with elements that appear in all of the input sets. Accepts any number of argument expressions. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/setIntersection/ - * @param BSONArray|PackedArray|ResolvesToArray|list ...$expression + * @param BSONArray|PackedArray|ResolvesToArray|array ...$expression */ public static function setIntersection( PackedArray|ResolvesToArray|BSONArray|array ...$expression, @@ -2086,8 +2184,8 @@ public static function setIntersection( * 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. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/setIsSubset/ - * @param BSONArray|PackedArray|ResolvesToArray|list $expression1 - * @param BSONArray|PackedArray|ResolvesToArray|list $expression2 + * @param BSONArray|PackedArray|ResolvesToArray|array $expression1 + * @param BSONArray|PackedArray|ResolvesToArray|array $expression2 */ public static function setIsSubset( PackedArray|ResolvesToArray|BSONArray|array $expression1, @@ -2101,7 +2199,7 @@ public static function setIsSubset( * Returns a set with elements that appear in any of the input sets. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/setUnion/ - * @param BSONArray|PackedArray|ResolvesToArray|list ...$expression + * @param BSONArray|PackedArray|ResolvesToArray|array ...$expression */ public static function setUnion(PackedArray|ResolvesToArray|BSONArray|array ...$expression): SetUnionAggregation { @@ -2113,17 +2211,21 @@ public static function setUnion(PackedArray|ResolvesToArray|BSONArray|array ...$ * New in version 5.0. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/shift/ - * @param ExpressionInterface|mixed $output Specifies an expression to evaluate and return in the output. - * @param Int64|int $by Specifies an integer with a numeric document position relative to the current document in the output. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $output Specifies an expression to evaluate and return in the output. + * @param int $by 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. - * @param ExpressionInterface|mixed $default 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. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $default 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. */ - public static function shift(mixed $output, Int64|int $by, mixed $default): ShiftAggregation + public static function shift( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $output, + int $by, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $default, + ): ShiftAggregation { return new ShiftAggregation($output, $by, $default); } @@ -2132,10 +2234,12 @@ public static function shift(mixed $output, Int64|int $by, mixed $default): Shif * Returns the sine of a value that is measured in radians. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/sin/ - * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $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. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression $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. */ - public static function sin(Decimal128|Int64|ResolvesToNumber|float|int $expression): SinAggregation + public static function sin( + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression, + ): SinAggregation { return new SinAggregation($expression); } @@ -2144,10 +2248,12 @@ public static function sin(Decimal128|Int64|ResolvesToNumber|float|int $expressi * Returns the hyperbolic sine of a value that is measured in radians. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/sinh/ - * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $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. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression $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. */ - public static function sinh(Decimal128|Int64|ResolvesToNumber|float|int $expression): SinhAggregation + public static function sinh( + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression, + ): SinhAggregation { return new SinhAggregation($expression); } @@ -2156,7 +2262,7 @@ public static function sinh(Decimal128|Int64|ResolvesToNumber|float|int $express * Returns the number of elements in the array. Accepts a single expression as argument. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/size/ - * @param BSONArray|PackedArray|ResolvesToArray|list $expression The argument for $size can be any expression as long as it resolves to an array. + * @param BSONArray|PackedArray|ResolvesToArray|array $expression The argument for $size can be any expression as long as it resolves to an array. */ public static function size(PackedArray|ResolvesToArray|BSONArray|array $expression): SizeAggregation { @@ -2167,18 +2273,18 @@ public static function size(PackedArray|ResolvesToArray|BSONArray|array $express * Returns a subset of an array. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/slice/ - * @param BSONArray|PackedArray|ResolvesToArray|list $expression Any valid expression as long as it resolves to an array. - * @param Int64|ResolvesToInt|int $n Any valid expression as long as it resolves to an integer. If position is specified, n must resolve to a positive integer. + * @param BSONArray|PackedArray|ResolvesToArray|array $expression Any valid expression as long as it resolves to an array. + * @param ResolvesToInt|int $n 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. - * @param Int64|Optional|ResolvesToInt|int $position Any valid expression as long as it resolves to an integer. + * @param Optional|ResolvesToInt|int $position 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. */ public static function slice( PackedArray|ResolvesToArray|BSONArray|array $expression, - Int64|ResolvesToInt|int $n, - Int64|ResolvesToInt|Optional|int $position = Optional::Undefined, + ResolvesToInt|int $n, + ResolvesToInt|Optional|int $position = Optional::Undefined, ): SliceAggregation { return new SliceAggregation($expression, $n, $position); @@ -2188,12 +2294,12 @@ public static function slice( * Sorts the elements of an array. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/sortArray/ - * @param BSONArray|PackedArray|ResolvesToArray|list $input The array to be sorted. - * @param array|stdClass $sortBy The document specifies a sort ordering. + * @param BSONArray|PackedArray|ResolvesToArray|array $input The array to be sorted. + * @param Document|Serializable|array|stdClass $sortBy The document specifies a sort ordering. */ public static function sortArray( PackedArray|ResolvesToArray|BSONArray|array $input, - stdClass|array $sortBy, + Document|Serializable|stdClass|array $sortBy, ): SortArrayAggregation { return new SortArrayAggregation($input, $sortBy); @@ -2218,9 +2324,11 @@ public static function split( * Calculates the square root. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/sqrt/ - * @param Decimal128|Int64|ResolvesToNumber|float|int $number The argument can be any valid expression as long as it resolves to a non-negative number. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $number The argument can be any valid expression as long as it resolves to a non-negative number. */ - public static function sqrt(Decimal128|Int64|ResolvesToNumber|float|int $number): SqrtAggregation + public static function sqrt( + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $number, + ): SqrtAggregation { return new SqrtAggregation($number); } @@ -2231,9 +2339,11 @@ public static function sqrt(Decimal128|Int64|ResolvesToNumber|float|int $number) * Changed in version 5.0: Available in the $setWindowFields stage. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/stdDevPop/ - * @param Decimal128|Int64|ResolvesToNumber|float|int ...$expression + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int ...$expression */ - public static function stdDevPop(Decimal128|Int64|ResolvesToNumber|float|int ...$expression): StdDevPopAggregation + public static function stdDevPop( + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int ...$expression, + ): StdDevPopAggregation { return new StdDevPopAggregation(...$expression); } @@ -2244,10 +2354,10 @@ public static function stdDevPop(Decimal128|Int64|ResolvesToNumber|float|int ... * Changed in version 5.0: Available in the $setWindowFields stage. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/stdDevSamp/ - * @param Decimal128|Int64|ResolvesToNumber|float|int ...$expression + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int ...$expression */ public static function stdDevSamp( - Decimal128|Int64|ResolvesToNumber|float|int ...$expression, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int ...$expression, ): StdDevSampAggregation { return new StdDevSampAggregation(...$expression); @@ -2295,13 +2405,13 @@ public static function strLenCP(ResolvesToString|string $expression): StrLenCPAg * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/substr/ * @param ResolvesToString|non-empty-string $string - * @param Int64|ResolvesToInt|int $start If start is a negative number, $substr returns an empty string "". - * @param Int64|ResolvesToInt|int $length If length is a negative number, $substr returns a substring that starts at the specified index and includes the rest of the string. + * @param ResolvesToInt|int $start If start is a negative number, $substr returns an empty string "". + * @param ResolvesToInt|int $length If length is a negative number, $substr returns a substring that starts at the specified index and includes the rest of the string. */ public static function substr( ResolvesToString|string $string, - Int64|ResolvesToInt|int $start, - Int64|ResolvesToInt|int $length, + ResolvesToInt|int $start, + ResolvesToInt|int $length, ): SubstrAggregation { return new SubstrAggregation($string, $start, $length); @@ -2312,13 +2422,13 @@ public static function substr( * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/substrBytes/ * @param ResolvesToString|non-empty-string $string - * @param Int64|ResolvesToInt|int $start If start is a negative number, $substr returns an empty string "". - * @param Int64|ResolvesToInt|int $length If length is a negative number, $substr returns a substring that starts at the specified index and includes the rest of the string. + * @param ResolvesToInt|int $start If start is a negative number, $substr returns an empty string "". + * @param ResolvesToInt|int $length If length is a negative number, $substr returns a substring that starts at the specified index and includes the rest of the string. */ public static function substrBytes( ResolvesToString|string $string, - Int64|ResolvesToInt|int $start, - Int64|ResolvesToInt|int $length, + ResolvesToInt|int $start, + ResolvesToInt|int $length, ): SubstrBytesAggregation { return new SubstrBytesAggregation($string, $start, $length); @@ -2329,13 +2439,13 @@ public static function substrBytes( * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/substrCP/ * @param ResolvesToString|non-empty-string $string - * @param Int64|ResolvesToInt|int $start If start is a negative number, $substr returns an empty string "". - * @param Int64|ResolvesToInt|int $length If length is a negative number, $substr returns a substring that starts at the specified index and includes the rest of the string. + * @param ResolvesToInt|int $start If start is a negative number, $substr returns an empty string "". + * @param ResolvesToInt|int $length If length is a negative number, $substr returns a substring that starts at the specified index and includes the rest of the string. */ public static function substrCP( ResolvesToString|string $string, - Int64|ResolvesToInt|int $start, - Int64|ResolvesToInt|int $length, + ResolvesToInt|int $start, + ResolvesToInt|int $length, ): SubstrCPAggregation { return new SubstrCPAggregation($string, $start, $length); @@ -2345,12 +2455,12 @@ public static function substrCP( * 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. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/subtract/ - * @param DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int $expression1 - * @param DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int $expression2 + * @param Decimal128|Int64|ResolvesToDate|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|UTCDateTime|float|int $expression1 + * @param Decimal128|Int64|ResolvesToDate|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|UTCDateTime|float|int $expression2 */ public static function subtract( - DateTimeInterface|Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int $expression1, - DateTimeInterface|Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int $expression2, + Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression1, + Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression2, ): SubtractAggregation { return new SubtractAggregation($expression1, $expression2); @@ -2361,9 +2471,11 @@ public static function subtract( * Changed in version 5.0: Available in the $setWindowFields stage. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/sum/ - * @param Decimal128|Int64|ResolvesToNumber|float|int ...$expression + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int ...$expression */ - public static function sum(Decimal128|Int64|ResolvesToNumber|float|int ...$expression): SumAggregation + public static function sum( + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int ...$expression, + ): SumAggregation { return new SumAggregation(...$expression); } @@ -2372,16 +2484,16 @@ public static function sum(Decimal128|Int64|ResolvesToNumber|float|int ...$expre * 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. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/switch/ - * @param BSONArray|PackedArray|list $branches An array of control branch documents. Each branch is a document with the following fields: + * @param BSONArray|PackedArray|array $branches 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. - * @param ExpressionInterface|Optional|mixed $default The path to take if no branch case expression evaluates to true. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|Optional|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $default 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. */ public static function switch( PackedArray|BSONArray|array $branches, - mixed $default = Optional::Undefined, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|Optional|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $default = Optional::Undefined, ): SwitchAggregation { return new SwitchAggregation($branches, $default); @@ -2391,10 +2503,12 @@ public static function switch( * Returns the tangent of a value that is measured in radians. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/tan/ - * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $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. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression $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. */ - public static function tan(Decimal128|Int64|ResolvesToNumber|float|int $expression): TanAggregation + public static function tan( + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression, + ): TanAggregation { return new TanAggregation($expression); } @@ -2403,10 +2517,12 @@ public static function tan(Decimal128|Int64|ResolvesToNumber|float|int $expressi * Returns the hyperbolic tangent of a value that is measured in radians. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/tanh/ - * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $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. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression $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. */ - public static function tanh(Decimal128|Int64|ResolvesToNumber|float|int $expression): TanhAggregation + public static function tanh( + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression, + ): TanhAggregation { return new TanhAggregation($expression); } @@ -2416,9 +2532,11 @@ public static function tanh(Decimal128|Int64|ResolvesToNumber|float|int $express * New in version 4.0. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toBool/ - * @param ExpressionInterface|mixed $expression + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression */ - public static function toBool(mixed $expression): ToBoolAggregation + public static function toBool( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, + ): ToBoolAggregation { return new ToBoolAggregation($expression); } @@ -2428,9 +2546,11 @@ public static function toBool(mixed $expression): ToBoolAggregation * New in version 4.0. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toDate/ - * @param ExpressionInterface|mixed $expression + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression */ - public static function toDate(mixed $expression): ToDateAggregation + public static function toDate( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, + ): ToDateAggregation { return new ToDateAggregation($expression); } @@ -2440,9 +2560,11 @@ public static function toDate(mixed $expression): ToDateAggregation * New in version 4.0. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toDecimal/ - * @param ExpressionInterface|mixed $expression + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression */ - public static function toDecimal(mixed $expression): ToDecimalAggregation + public static function toDecimal( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, + ): ToDecimalAggregation { return new ToDecimalAggregation($expression); } @@ -2452,9 +2574,11 @@ public static function toDecimal(mixed $expression): ToDecimalAggregation * New in version 4.0. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toDouble/ - * @param ExpressionInterface|mixed $expression + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression */ - public static function toDouble(mixed $expression): ToDoubleAggregation + public static function toDouble( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, + ): ToDoubleAggregation { return new ToDoubleAggregation($expression); } @@ -2464,9 +2588,11 @@ public static function toDouble(mixed $expression): ToDoubleAggregation * New in version 4.0. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toInt/ - * @param ExpressionInterface|mixed $expression + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression */ - public static function toInt(mixed $expression): ToIntAggregation + public static function toInt( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, + ): ToIntAggregation { return new ToIntAggregation($expression); } @@ -2476,9 +2602,11 @@ public static function toInt(mixed $expression): ToIntAggregation * New in version 4.0. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toLong/ - * @param ExpressionInterface|mixed $expression + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression */ - public static function toLong(mixed $expression): ToLongAggregation + public static function toLong( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, + ): ToLongAggregation { return new ToLongAggregation($expression); } @@ -2499,9 +2627,11 @@ public static function toLower(ResolvesToString|string $expression): ToLowerAggr * New in version 4.0. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toObjectId/ - * @param ExpressionInterface|mixed $expression + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression */ - public static function toObjectId(mixed $expression): ToObjectIdAggregation + public static function toObjectId( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, + ): ToObjectIdAggregation { return new ToObjectIdAggregation($expression); } @@ -2513,10 +2643,13 @@ public static function toObjectId(mixed $expression): ToObjectIdAggregation * Available in the $group and $setWindowFields stages. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/top/ - * @param array|stdClass $sortBy Specifies the order of results, with syntax similar to $sort. - * @param ExpressionInterface|mixed $output Represents the output for each element in the group and can be any expression. + * @param Document|Serializable|array|stdClass $sortBy Specifies the order of results, with syntax similar to $sort. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $output Represents the output for each element in the group and can be any expression. */ - public static function top(stdClass|array $sortBy, mixed $output): TopAggregation + public static function top( + Document|Serializable|stdClass|array $sortBy, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $output, + ): TopAggregation { return new TopAggregation($sortBy, $output); } @@ -2528,11 +2661,15 @@ public static function top(stdClass|array $sortBy, mixed $output): TopAggregatio * Available in the $group and $setWindowFields stages. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/topN/ - * @param Int64|ResolvesToInt|int $n 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. - * @param array|stdClass $sortBy Specifies the order of results, with syntax similar to $sort. - * @param ExpressionInterface|mixed $output Represents the output for each element in the group and can be any expression. + * @param ResolvesToInt|int $n 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. + * @param Document|Serializable|array|stdClass $sortBy Specifies the order of results, with syntax similar to $sort. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $output Represents the output for each element in the group and can be any expression. */ - public static function topN(Int64|ResolvesToInt|int $n, stdClass|array $sortBy, mixed $output): TopNAggregation + public static function topN( + ResolvesToInt|int $n, + Document|Serializable|stdClass|array $sortBy, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $output, + ): TopNAggregation { return new TopNAggregation($n, $sortBy, $output); } @@ -2542,9 +2679,11 @@ public static function topN(Int64|ResolvesToInt|int $n, stdClass|array $sortBy, * New in version 4.0. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toString/ - * @param ExpressionInterface|mixed $expression + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression */ - public static function toString(mixed $expression): ToStringAggregation + public static function toString( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, + ): ToStringAggregation { return new ToStringAggregation($expression); } @@ -2582,13 +2721,13 @@ public static function trim( * Truncates a number to a whole integer or to a specified decimal place. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/trunc/ - * @param Decimal128|Int64|ResolvesToNumber|float|int $number Can be any valid expression that resolves to a number. Specifically, the expression must resolve to an integer, double, decimal, or long. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $number 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. - * @param Int64|Optional|ResolvesToInt|int $place Can be any valid expression that resolves to an integer between -20 and 100, exclusive. e.g. -20 < place < 100. Defaults to 0. + * @param Optional|ResolvesToInt|int $place Can be any valid expression that resolves to an integer between -20 and 100, exclusive. e.g. -20 < place < 100. Defaults to 0. */ public static function trunc( - Decimal128|Int64|ResolvesToNumber|float|int $number, - Int64|ResolvesToInt|Optional|int $place = Optional::Undefined, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $number, + ResolvesToInt|Optional|int $place = Optional::Undefined, ): TruncAggregation { return new TruncAggregation($number, $place); @@ -2599,9 +2738,9 @@ public static function trunc( * New in version 5.1. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/tsIncrement/ - * @param Int64|ResolvesToTimestamp|int $expression + * @param ResolvesToTimestamp|Timestamp|int $expression */ - public static function tsIncrement(Int64|ResolvesToTimestamp|int $expression): TsIncrementAggregation + public static function tsIncrement(Timestamp|ResolvesToTimestamp|int $expression): TsIncrementAggregation { return new TsIncrementAggregation($expression); } @@ -2611,9 +2750,9 @@ public static function tsIncrement(Int64|ResolvesToTimestamp|int $expression): T * New in version 5.1. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/tsSecond/ - * @param Int64|ResolvesToTimestamp|int $expression + * @param ResolvesToTimestamp|Timestamp|int $expression */ - public static function tsSecond(Int64|ResolvesToTimestamp|int $expression): TsSecondAggregation + public static function tsSecond(Timestamp|ResolvesToTimestamp|int $expression): TsSecondAggregation { return new TsSecondAggregation($expression); } @@ -2622,9 +2761,11 @@ public static function tsSecond(Int64|ResolvesToTimestamp|int $expression): TsSe * Return the BSON data type of the field. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/type/ - * @param ExpressionInterface|mixed $expression + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression */ - public static function type(mixed $expression): TypeAggregation + public static function type( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, + ): TypeAggregation { return new TypeAggregation($expression); } @@ -2649,11 +2790,11 @@ public static function unsetField( * 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). * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/week/ - * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public static function week( - DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|Optional|string $timezone = Optional::Undefined, ): WeekAggregation { @@ -2664,11 +2805,11 @@ public static function week( * Returns the year for a date as a number (e.g. 2014). * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/year/ - * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public static function year( - DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|Optional|string $timezone = Optional::Undefined, ): YearAggregation { @@ -2679,12 +2820,12 @@ public static function year( * Merge two arrays together. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/zip/ - * @param BSONArray|PackedArray|ResolvesToArray|list $inputs An array of expressions that resolve to arrays. The elements of these input arrays combine to form the arrays of the output array. + * @param BSONArray|PackedArray|ResolvesToArray|array $inputs 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. * @param bool $useLongestLength 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. - * @param BSONArray|PackedArray|list $defaults 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. + * @param BSONArray|PackedArray|array $defaults 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. */ diff --git a/src/Builder/Aggregation/AbsAggregation.php b/src/Builder/Aggregation/AbsAggregation.php index 0632f071e..d51be0336 100644 --- a/src/Builder/Aggregation/AbsAggregation.php +++ b/src/Builder/Aggregation/AbsAggregation.php @@ -9,6 +9,10 @@ use MongoDB\BSON\Decimal128; use MongoDB\BSON\Int64; use MongoDB\Builder\Encode; +use MongoDB\Builder\Expression\ResolvesToDecimal; +use MongoDB\Builder\Expression\ResolvesToDouble; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Expression\ResolvesToLong; use MongoDB\Builder\Expression\ResolvesToNumber; /** @@ -21,14 +25,15 @@ class AbsAggregation implements ResolvesToNumber public const NAME = '$abs'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param Decimal128|Int64|ResolvesToNumber|float|int $value */ - public Decimal128|Int64|ResolvesToNumber|float|int $value; + /** @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $value */ + public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $value; /** - * @param Decimal128|Int64|ResolvesToNumber|float|int $value + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $value */ - public function __construct(Decimal128|Int64|ResolvesToNumber|float|int $value) - { + public function __construct( + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $value, + ) { $this->value = $value; } } diff --git a/src/Builder/Aggregation/AccumulatorAggregation.php b/src/Builder/Aggregation/AccumulatorAggregation.php index 90012e27e..0ee47f894 100644 --- a/src/Builder/Aggregation/AccumulatorAggregation.php +++ b/src/Builder/Aggregation/AccumulatorAggregation.php @@ -8,9 +8,9 @@ use MongoDB\BSON\PackedArray; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToArray; use MongoDB\Builder\Optional; +use MongoDB\Builder\Type\AccumulatorInterface; use MongoDB\Model\BSONArray; /** @@ -30,7 +30,7 @@ class AccumulatorAggregation implements AccumulatorInterface /** @param non-empty-string $accumulate 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. */ public string $accumulate; - /** @param BSONArray|PackedArray|ResolvesToArray|list $accumulateArgs Arguments passed to the accumulate function. You can use accumulateArgs to specify what field value(s) to pass to the accumulate function. */ + /** @param BSONArray|PackedArray|ResolvesToArray|array $accumulateArgs Arguments passed to the accumulate function. You can use accumulateArgs to specify what field value(s) to pass to the accumulate function. */ public PackedArray|ResolvesToArray|BSONArray|array $accumulateArgs; /** @param non-empty-string $merge 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. */ @@ -39,7 +39,7 @@ class AccumulatorAggregation implements AccumulatorInterface /** @param non-empty-string $lang The language used in the $accumulator code. */ public string $lang; - /** @param BSONArray|Optional|PackedArray|ResolvesToArray|list $initArgs Arguments passed to the init function. */ + /** @param BSONArray|Optional|PackedArray|ResolvesToArray|array $initArgs Arguments passed to the init function. */ public PackedArray|ResolvesToArray|Optional|BSONArray|array $initArgs; /** @param Optional|non-empty-string $finalize Function used to update the result of the accumulation. */ @@ -48,10 +48,10 @@ class AccumulatorAggregation implements AccumulatorInterface /** * @param non-empty-string $init 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. * @param non-empty-string $accumulate 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. - * @param BSONArray|PackedArray|ResolvesToArray|list $accumulateArgs Arguments passed to the accumulate function. You can use accumulateArgs to specify what field value(s) to pass to the accumulate function. + * @param BSONArray|PackedArray|ResolvesToArray|array $accumulateArgs Arguments passed to the accumulate function. You can use accumulateArgs to specify what field value(s) to pass to the accumulate function. * @param non-empty-string $merge 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. * @param non-empty-string $lang The language used in the $accumulator code. - * @param BSONArray|Optional|PackedArray|ResolvesToArray|list $initArgs Arguments passed to the init function. + * @param BSONArray|Optional|PackedArray|ResolvesToArray|array $initArgs Arguments passed to the init function. * @param Optional|non-empty-string $finalize Function used to update the result of the accumulation. */ public function __construct( @@ -68,12 +68,14 @@ public function __construct( if (\is_array($accumulateArgs) && ! \array_is_list($accumulateArgs)) { throw new \InvalidArgumentException('Expected $accumulateArgs argument to be a list, got an associative array.'); } + $this->accumulateArgs = $accumulateArgs; $this->merge = $merge; $this->lang = $lang; if (\is_array($initArgs) && ! \array_is_list($initArgs)) { throw new \InvalidArgumentException('Expected $initArgs argument to be a list, got an associative array.'); } + $this->initArgs = $initArgs; $this->finalize = $finalize; } diff --git a/src/Builder/Aggregation/AccumulatorInterface.php b/src/Builder/Aggregation/AccumulatorInterface.php deleted file mode 100644 index b537a636b..000000000 --- a/src/Builder/Aggregation/AccumulatorInterface.php +++ /dev/null @@ -1,11 +0,0 @@ -expression = $expression; } } diff --git a/src/Builder/Aggregation/AcoshAggregation.php b/src/Builder/Aggregation/AcoshAggregation.php index 2b54ba690..7f93c51e3 100644 --- a/src/Builder/Aggregation/AcoshAggregation.php +++ b/src/Builder/Aggregation/AcoshAggregation.php @@ -11,6 +11,8 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToDecimal; use MongoDB\Builder\Expression\ResolvesToDouble; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Expression\ResolvesToLong; use MongoDB\Builder\Expression\ResolvesToNumber; /** @@ -24,19 +26,20 @@ class AcoshAggregation implements ResolvesToDouble, ResolvesToDecimal public const ENCODE = \MongoDB\Builder\Encode::Single; /** - * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $acosh takes any valid expression that resolves to a number between 1 and +Infinity, e.g. 1 <= value <= +Infinity. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression $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. */ - public Decimal128|Int64|ResolvesToNumber|float|int $expression; + public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression; /** - * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $acosh takes any valid expression that resolves to a number between 1 and +Infinity, e.g. 1 <= value <= +Infinity. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression $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. */ - public function __construct(Decimal128|Int64|ResolvesToNumber|float|int $expression) - { + public function __construct( + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression, + ) { $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/AddAggregation.php b/src/Builder/Aggregation/AddAggregation.php index 78ba79096..9d7a86223 100644 --- a/src/Builder/Aggregation/AddAggregation.php +++ b/src/Builder/Aggregation/AddAggregation.php @@ -6,12 +6,15 @@ namespace MongoDB\Builder\Aggregation; -use DateTimeInterface; use MongoDB\BSON\Decimal128; use MongoDB\BSON\Int64; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToDate; +use MongoDB\Builder\Expression\ResolvesToDecimal; +use MongoDB\Builder\Expression\ResolvesToDouble; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Expression\ResolvesToLong; use MongoDB\Builder\Expression\ResolvesToNumber; /** @@ -24,21 +27,21 @@ class AddAggregation implements ResolvesToNumber, ResolvesToDate public const NAME = '$add'; public const ENCODE = \MongoDB\Builder\Encode::Array; - /** @param list ...$expression The arguments can be any valid expression as long as they resolve to either all numbers or to numbers and a date. */ + /** @param list ...$expression The arguments can be any valid expression as long as they resolve to either all numbers or to numbers and a date. */ public array $expression; /** - * @param DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int ...$expression The arguments can be any valid expression as long as they resolve to either all numbers or to numbers and a date. + * @param Decimal128|Int64|ResolvesToDate|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|UTCDateTime|float|int ...$expression The arguments can be any valid expression as long as they resolve to either all numbers or to numbers and a date. * @no-named-arguments */ public function __construct( - DateTimeInterface|Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int ...$expression, + Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int ...$expression, ) { if (\count($expression) < 1) { throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); } if (! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression arguments to be a list of DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int, named arguments are not supported'); + throw new \InvalidArgumentException('Expected $expression arguments to be a list (array), named arguments are not supported'); } $this->expression = $expression; } diff --git a/src/Builder/Aggregation/AddToSetAggregation.php b/src/Builder/Aggregation/AddToSetAggregation.php index ede4a02ab..2cbb3df92 100644 --- a/src/Builder/Aggregation/AddToSetAggregation.php +++ b/src/Builder/Aggregation/AddToSetAggregation.php @@ -6,9 +6,23 @@ namespace MongoDB\Builder\Aggregation; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Document; +use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; +use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; +use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\FieldPath; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Type\AccumulatorInterface; +use MongoDB\Builder\Type\ExpressionInterface; +use MongoDB\Model\BSONArray; +use stdClass; /** * Returns an array of unique expression values for each group. Order of the array elements is undefined. @@ -21,14 +35,19 @@ class AddToSetAggregation implements AccumulatorInterface public const NAME = '$addToSet'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param ExpressionInterface|FieldPath|mixed|non-empty-string $expression */ - public mixed $expression; + /** @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|FieldPath|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression */ + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|FieldPath|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression; /** - * @param ExpressionInterface|FieldPath|mixed|non-empty-string $expression + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|FieldPath|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression */ - public function __construct(mixed $expression) - { + public function __construct( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|FieldPath|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, + ) { + if (\is_array($expression) && ! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression argument to be a list, got an associative array.'); + } + $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/AllElementsTrueAggregation.php b/src/Builder/Aggregation/AllElementsTrueAggregation.php index 20f8c549b..8e319cf6f 100644 --- a/src/Builder/Aggregation/AllElementsTrueAggregation.php +++ b/src/Builder/Aggregation/AllElementsTrueAggregation.php @@ -8,7 +8,6 @@ use MongoDB\BSON\PackedArray; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToArray; use MongoDB\Builder\Expression\ResolvesToBool; use MongoDB\Model\BSONArray; @@ -23,11 +22,11 @@ class AllElementsTrueAggregation implements ResolvesToBool public const NAME = '$allElementsTrue'; public const ENCODE = \MongoDB\Builder\Encode::Array; - /** @param list ...$expression */ + /** @param list ...$expression */ public array $expression; /** - * @param BSONArray|PackedArray|ResolvesToArray|list ...$expression + * @param BSONArray|PackedArray|ResolvesToArray|array ...$expression * @no-named-arguments */ public function __construct(PackedArray|ResolvesToArray|BSONArray|array ...$expression) @@ -36,7 +35,7 @@ public function __construct(PackedArray|ResolvesToArray|BSONArray|array ...$expr throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); } if (! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression arguments to be a list of BSONArray|PackedArray|ResolvesToArray|list, named arguments are not supported'); + throw new \InvalidArgumentException('Expected $expression arguments to be a list (array), named arguments are not supported'); } $this->expression = $expression; } diff --git a/src/Builder/Aggregation/AndAggregation.php b/src/Builder/Aggregation/AndAggregation.php index a004a6db6..a40eb7290 100644 --- a/src/Builder/Aggregation/AndAggregation.php +++ b/src/Builder/Aggregation/AndAggregation.php @@ -6,14 +6,28 @@ namespace MongoDB\Builder\Aggregation; +use MongoDB\BSON\Binary; use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Document; use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; +use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; +use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToBool; +use MongoDB\Builder\Expression\ResolvesToDecimal; +use MongoDB\Builder\Expression\ResolvesToDouble; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Expression\ResolvesToLong; use MongoDB\Builder\Expression\ResolvesToNull; use MongoDB\Builder\Expression\ResolvesToNumber; use MongoDB\Builder\Expression\ResolvesToString; +use MongoDB\Builder\Type\ExpressionInterface; +use MongoDB\Model\BSONArray; +use stdClass; /** * Returns true only when all its expressions evaluate to true. Accepts any number of argument expressions. @@ -25,20 +39,21 @@ class AndAggregation implements ResolvesToBool public const NAME = '$and'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param list ...$expression */ + /** @param list ...$expression */ public array $expression; /** - * @param Decimal128|ExpressionInterface|Int64|ResolvesToBool|ResolvesToNull|ResolvesToNumber|ResolvesToString|bool|float|int|mixed|non-empty-string|null ...$expression + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToBool|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNull|ResolvesToNumber|ResolvesToString|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass ...$expression * @no-named-arguments */ - public function __construct(mixed ...$expression) - { + public function __construct( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToBool|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNull|ResolvesToNumber|ResolvesToString|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string ...$expression, + ) { if (\count($expression) < 1) { throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); } if (! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression arguments to be a list of Decimal128|ExpressionInterface|Int64|ResolvesToBool|ResolvesToNull|ResolvesToNumber|ResolvesToString|bool|float|int|mixed|non-empty-string|null, named arguments are not supported'); + throw new \InvalidArgumentException('Expected $expression arguments to be a list (array), named arguments are not supported'); } $this->expression = $expression; } diff --git a/src/Builder/Aggregation/AnyElementTrueAggregation.php b/src/Builder/Aggregation/AnyElementTrueAggregation.php index e7d6aa639..e7b865fbf 100644 --- a/src/Builder/Aggregation/AnyElementTrueAggregation.php +++ b/src/Builder/Aggregation/AnyElementTrueAggregation.php @@ -8,7 +8,6 @@ use MongoDB\BSON\PackedArray; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToArray; use MongoDB\Builder\Expression\ResolvesToBool; use MongoDB\Model\BSONArray; @@ -23,17 +22,18 @@ class AnyElementTrueAggregation implements ResolvesToBool public const NAME = '$anyElementTrue'; public const ENCODE = \MongoDB\Builder\Encode::Array; - /** @param BSONArray|PackedArray|ResolvesToArray|list $expression */ + /** @param BSONArray|PackedArray|ResolvesToArray|array $expression */ public PackedArray|ResolvesToArray|BSONArray|array $expression; /** - * @param BSONArray|PackedArray|ResolvesToArray|list $expression + * @param BSONArray|PackedArray|ResolvesToArray|array $expression */ public function __construct(PackedArray|ResolvesToArray|BSONArray|array $expression) { if (\is_array($expression) && ! \array_is_list($expression)) { throw new \InvalidArgumentException('Expected $expression argument to be a list, got an associative array.'); } + $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/ArrayElemAtAggregation.php b/src/Builder/Aggregation/ArrayElemAtAggregation.php index 6387aa405..0f6aa3283 100644 --- a/src/Builder/Aggregation/ArrayElemAtAggregation.php +++ b/src/Builder/Aggregation/ArrayElemAtAggregation.php @@ -6,10 +6,9 @@ namespace MongoDB\Builder\Aggregation; -use MongoDB\BSON\Int64; use MongoDB\BSON\PackedArray; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; +use MongoDB\Builder\Expression\ResolvesToAny; use MongoDB\Builder\Expression\ResolvesToArray; use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Model\BSONArray; @@ -19,26 +18,27 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/arrayElemAt/ */ -class ArrayElemAtAggregation implements ExpressionInterface +class ArrayElemAtAggregation implements ResolvesToAny { public const NAME = '$arrayElemAt'; public const ENCODE = \MongoDB\Builder\Encode::Array; - /** @param BSONArray|PackedArray|ResolvesToArray|list $array */ + /** @param BSONArray|PackedArray|ResolvesToArray|array $array */ public PackedArray|ResolvesToArray|BSONArray|array $array; - /** @param Int64|ResolvesToInt|int $idx */ - public Int64|ResolvesToInt|int $idx; + /** @param ResolvesToInt|int $idx */ + public ResolvesToInt|int $idx; /** - * @param BSONArray|PackedArray|ResolvesToArray|list $array - * @param Int64|ResolvesToInt|int $idx + * @param BSONArray|PackedArray|ResolvesToArray|array $array + * @param ResolvesToInt|int $idx */ - public function __construct(PackedArray|ResolvesToArray|BSONArray|array $array, Int64|ResolvesToInt|int $idx) + public function __construct(PackedArray|ResolvesToArray|BSONArray|array $array, ResolvesToInt|int $idx) { if (\is_array($array) && ! \array_is_list($array)) { throw new \InvalidArgumentException('Expected $array argument to be a list, got an associative array.'); } + $this->array = $array; $this->idx = $idx; } diff --git a/src/Builder/Aggregation/ArrayToObjectAggregation.php b/src/Builder/Aggregation/ArrayToObjectAggregation.php index 2d163004e..f41762d97 100644 --- a/src/Builder/Aggregation/ArrayToObjectAggregation.php +++ b/src/Builder/Aggregation/ArrayToObjectAggregation.php @@ -8,7 +8,6 @@ use MongoDB\BSON\PackedArray; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToArray; use MongoDB\Builder\Expression\ResolvesToObject; use MongoDB\Model\BSONArray; @@ -23,17 +22,18 @@ class ArrayToObjectAggregation implements ResolvesToObject public const NAME = '$arrayToObject'; public const ENCODE = \MongoDB\Builder\Encode::Array; - /** @param BSONArray|PackedArray|ResolvesToArray|list $array */ + /** @param BSONArray|PackedArray|ResolvesToArray|array $array */ public PackedArray|ResolvesToArray|BSONArray|array $array; /** - * @param BSONArray|PackedArray|ResolvesToArray|list $array + * @param BSONArray|PackedArray|ResolvesToArray|array $array */ public function __construct(PackedArray|ResolvesToArray|BSONArray|array $array) { if (\is_array($array) && ! \array_is_list($array)) { throw new \InvalidArgumentException('Expected $array argument to be a list, got an associative array.'); } + $this->array = $array; } } diff --git a/src/Builder/Aggregation/AsinAggregation.php b/src/Builder/Aggregation/AsinAggregation.php index c7e61661a..2d23ea597 100644 --- a/src/Builder/Aggregation/AsinAggregation.php +++ b/src/Builder/Aggregation/AsinAggregation.php @@ -11,6 +11,8 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToDecimal; use MongoDB\Builder\Expression\ResolvesToDouble; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Expression\ResolvesToLong; use MongoDB\Builder\Expression\ResolvesToNumber; /** @@ -24,19 +26,20 @@ class AsinAggregation implements ResolvesToDouble, ResolvesToDecimal public const ENCODE = \MongoDB\Builder\Encode::Single; /** - * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $asin takes any valid expression that resolves to a number between -1 and 1, e.g. -1 <= value <= 1. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression $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. */ - public Decimal128|Int64|ResolvesToNumber|float|int $expression; + public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression; /** - * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $asin takes any valid expression that resolves to a number between -1 and 1, e.g. -1 <= value <= 1. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression $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. */ - public function __construct(Decimal128|Int64|ResolvesToNumber|float|int $expression) - { + public function __construct( + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression, + ) { $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/AsinhAggregation.php b/src/Builder/Aggregation/AsinhAggregation.php index 9a7b51893..1524098e3 100644 --- a/src/Builder/Aggregation/AsinhAggregation.php +++ b/src/Builder/Aggregation/AsinhAggregation.php @@ -11,6 +11,8 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToDecimal; use MongoDB\Builder\Expression\ResolvesToDouble; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Expression\ResolvesToLong; use MongoDB\Builder\Expression\ResolvesToNumber; /** @@ -24,19 +26,20 @@ class AsinhAggregation implements ResolvesToDouble, ResolvesToDecimal public const ENCODE = \MongoDB\Builder\Encode::Single; /** - * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $asinh takes any valid expression that resolves to a number. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression $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. */ - public Decimal128|Int64|ResolvesToNumber|float|int $expression; + public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression; /** - * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $asinh takes any valid expression that resolves to a number. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression $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. */ - public function __construct(Decimal128|Int64|ResolvesToNumber|float|int $expression) - { + public function __construct( + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression, + ) { $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/Atan2Aggregation.php b/src/Builder/Aggregation/Atan2Aggregation.php index e6174b865..f54998e7f 100644 --- a/src/Builder/Aggregation/Atan2Aggregation.php +++ b/src/Builder/Aggregation/Atan2Aggregation.php @@ -11,6 +11,8 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToDecimal; use MongoDB\Builder\Expression\ResolvesToDouble; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Expression\ResolvesToLong; use MongoDB\Builder\Expression\ResolvesToNumber; /** @@ -24,24 +26,24 @@ class Atan2Aggregation implements ResolvesToDouble, ResolvesToDecimal public const ENCODE = \MongoDB\Builder\Encode::Array; /** - * @param Decimal128|Int64|ResolvesToNumber|float|int $y $atan2 takes any valid expression that resolves to a number. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $y $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. */ - public Decimal128|Int64|ResolvesToNumber|float|int $y; + public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $y; - /** @param Decimal128|Int64|ResolvesToNumber|float|int $x */ - public Decimal128|Int64|ResolvesToNumber|float|int $x; + /** @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $x */ + public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $x; /** - * @param Decimal128|Int64|ResolvesToNumber|float|int $y $atan2 takes any valid expression that resolves to a number. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $y $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. - * @param Decimal128|Int64|ResolvesToNumber|float|int $x + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $x */ public function __construct( - Decimal128|Int64|ResolvesToNumber|float|int $y, - Decimal128|Int64|ResolvesToNumber|float|int $x, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $y, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $x, ) { $this->y = $y; $this->x = $x; diff --git a/src/Builder/Aggregation/AtanAggregation.php b/src/Builder/Aggregation/AtanAggregation.php index 69757ea20..4f5478282 100644 --- a/src/Builder/Aggregation/AtanAggregation.php +++ b/src/Builder/Aggregation/AtanAggregation.php @@ -11,6 +11,8 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToDecimal; use MongoDB\Builder\Expression\ResolvesToDouble; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Expression\ResolvesToLong; use MongoDB\Builder\Expression\ResolvesToNumber; /** @@ -24,19 +26,20 @@ class AtanAggregation implements ResolvesToDouble, ResolvesToDecimal public const ENCODE = \MongoDB\Builder\Encode::Single; /** - * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $atan takes any valid expression that resolves to a number. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression $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. */ - public Decimal128|Int64|ResolvesToNumber|float|int $expression; + public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression; /** - * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $atan takes any valid expression that resolves to a number. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression $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. */ - public function __construct(Decimal128|Int64|ResolvesToNumber|float|int $expression) - { + public function __construct( + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression, + ) { $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/AtanhAggregation.php b/src/Builder/Aggregation/AtanhAggregation.php index a82897aa6..a37abf92d 100644 --- a/src/Builder/Aggregation/AtanhAggregation.php +++ b/src/Builder/Aggregation/AtanhAggregation.php @@ -11,6 +11,8 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToDecimal; use MongoDB\Builder\Expression\ResolvesToDouble; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Expression\ResolvesToLong; use MongoDB\Builder\Expression\ResolvesToNumber; /** @@ -24,19 +26,20 @@ class AtanhAggregation implements ResolvesToDouble, ResolvesToDecimal public const ENCODE = \MongoDB\Builder\Encode::Single; /** - * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $atanh takes any valid expression that resolves to a number between -1 and 1, e.g. -1 <= value <= 1. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression $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. */ - public Decimal128|Int64|ResolvesToNumber|float|int $expression; + public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression; /** - * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $atanh takes any valid expression that resolves to a number between -1 and 1, e.g. -1 <= value <= 1. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression $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. */ - public function __construct(Decimal128|Int64|ResolvesToNumber|float|int $expression) - { + public function __construct( + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression, + ) { $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/AvgAggregation.php b/src/Builder/Aggregation/AvgAggregation.php index 8a0535215..0a1812765 100644 --- a/src/Builder/Aggregation/AvgAggregation.php +++ b/src/Builder/Aggregation/AvgAggregation.php @@ -9,7 +9,12 @@ use MongoDB\BSON\Decimal128; use MongoDB\BSON\Int64; use MongoDB\Builder\Encode; +use MongoDB\Builder\Expression\ResolvesToDecimal; +use MongoDB\Builder\Expression\ResolvesToDouble; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Expression\ResolvesToLong; use MongoDB\Builder\Expression\ResolvesToNumber; +use MongoDB\Builder\Type\AccumulatorInterface; /** * Returns an average of numerical values. Ignores non-numeric values. @@ -22,20 +27,21 @@ class AvgAggregation implements ResolvesToNumber, AccumulatorInterface public const NAME = '$avg'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param list ...$expression */ + /** @param list ...$expression */ public array $expression; /** - * @param Decimal128|Int64|ResolvesToNumber|float|int ...$expression + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int ...$expression * @no-named-arguments */ - public function __construct(Decimal128|Int64|ResolvesToNumber|float|int ...$expression) - { + public function __construct( + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int ...$expression, + ) { if (\count($expression) < 1) { throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); } if (! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression arguments to be a list of Decimal128|Int64|ResolvesToNumber|float|int, named arguments are not supported'); + throw new \InvalidArgumentException('Expected $expression arguments to be a list (array), named arguments are not supported'); } $this->expression = $expression; } diff --git a/src/Builder/Aggregation/BinarySizeAggregation.php b/src/Builder/Aggregation/BinarySizeAggregation.php index 17dc0443b..43c7d2aea 100644 --- a/src/Builder/Aggregation/BinarySizeAggregation.php +++ b/src/Builder/Aggregation/BinarySizeAggregation.php @@ -8,7 +8,7 @@ use MongoDB\BSON\Binary; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToBinary; +use MongoDB\Builder\Expression\ResolvesToBinData; use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Expression\ResolvesToNull; use MongoDB\Builder\Expression\ResolvesToString; @@ -23,13 +23,13 @@ class BinarySizeAggregation implements ResolvesToInt public const NAME = '$binarySize'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param Binary|ResolvesToBinary|ResolvesToNull|ResolvesToString|non-empty-string|null $expression */ - public Binary|ResolvesToBinary|ResolvesToNull|ResolvesToString|null|string $expression; + /** @param Binary|ResolvesToBinData|ResolvesToNull|ResolvesToString|non-empty-string|null $expression */ + public Binary|ResolvesToBinData|ResolvesToNull|ResolvesToString|null|string $expression; /** - * @param Binary|ResolvesToBinary|ResolvesToNull|ResolvesToString|non-empty-string|null $expression + * @param Binary|ResolvesToBinData|ResolvesToNull|ResolvesToString|non-empty-string|null $expression */ - public function __construct(Binary|ResolvesToBinary|ResolvesToNull|ResolvesToString|null|string $expression) + public function __construct(Binary|ResolvesToBinData|ResolvesToNull|ResolvesToString|null|string $expression) { $this->expression = $expression; } diff --git a/src/Builder/Aggregation/BitAndAggregation.php b/src/Builder/Aggregation/BitAndAggregation.php index dd9d73918..97e448af4 100644 --- a/src/Builder/Aggregation/BitAndAggregation.php +++ b/src/Builder/Aggregation/BitAndAggregation.php @@ -35,7 +35,7 @@ public function __construct(Int64|ResolvesToInt|ResolvesToLong|int ...$expressio throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); } if (! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression arguments to be a list of Int64|ResolvesToInt|ResolvesToLong|int, named arguments are not supported'); + throw new \InvalidArgumentException('Expected $expression arguments to be a list (array), named arguments are not supported'); } $this->expression = $expression; } diff --git a/src/Builder/Aggregation/BitOrAggregation.php b/src/Builder/Aggregation/BitOrAggregation.php index b0fa1ed1b..85a5b7457 100644 --- a/src/Builder/Aggregation/BitOrAggregation.php +++ b/src/Builder/Aggregation/BitOrAggregation.php @@ -35,7 +35,7 @@ public function __construct(Int64|ResolvesToInt|ResolvesToLong|int ...$expressio throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); } if (! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression arguments to be a list of Int64|ResolvesToInt|ResolvesToLong|int, named arguments are not supported'); + throw new \InvalidArgumentException('Expected $expression arguments to be a list (array), named arguments are not supported'); } $this->expression = $expression; } diff --git a/src/Builder/Aggregation/BitXorAggregation.php b/src/Builder/Aggregation/BitXorAggregation.php index 130f58d3d..f91c70e39 100644 --- a/src/Builder/Aggregation/BitXorAggregation.php +++ b/src/Builder/Aggregation/BitXorAggregation.php @@ -35,7 +35,7 @@ public function __construct(Int64|ResolvesToInt|ResolvesToLong|int ...$expressio throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); } if (! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression arguments to be a list of Int64|ResolvesToInt|ResolvesToLong|int, named arguments are not supported'); + throw new \InvalidArgumentException('Expected $expression arguments to be a list (array), named arguments are not supported'); } $this->expression = $expression; } diff --git a/src/Builder/Aggregation/BottomAggregation.php b/src/Builder/Aggregation/BottomAggregation.php index 4938ec732..dd0ee23cb 100644 --- a/src/Builder/Aggregation/BottomAggregation.php +++ b/src/Builder/Aggregation/BottomAggregation.php @@ -6,8 +6,21 @@ namespace MongoDB\Builder\Aggregation; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Document; +use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; +use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; +use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Type\AccumulatorInterface; +use MongoDB\Builder\Type\ExpressionInterface; +use MongoDB\Model\BSONArray; use stdClass; /** @@ -23,19 +36,25 @@ class BottomAggregation implements AccumulatorInterface public const NAME = '$bottom'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param array|stdClass $sortBy Specifies the order of results, with syntax similar to $sort. */ - public stdClass|array $sortBy; + /** @param Document|Serializable|array|stdClass $sortBy Specifies the order of results, with syntax similar to $sort. */ + public Document|Serializable|stdClass|array $sortBy; - /** @param ExpressionInterface|mixed $output Represents the output for each element in the group and can be any expression. */ - public mixed $output; + /** @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $output Represents the output for each element in the group and can be any expression. */ + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $output; /** - * @param array|stdClass $sortBy Specifies the order of results, with syntax similar to $sort. - * @param ExpressionInterface|mixed $output Represents the output for each element in the group and can be any expression. + * @param Document|Serializable|array|stdClass $sortBy Specifies the order of results, with syntax similar to $sort. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $output Represents the output for each element in the group and can be any expression. */ - public function __construct(stdClass|array $sortBy, mixed $output) - { + public function __construct( + Document|Serializable|stdClass|array $sortBy, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $output, + ) { $this->sortBy = $sortBy; + if (\is_array($output) && ! \array_is_list($output)) { + throw new \InvalidArgumentException('Expected $output argument to be a list, got an associative array.'); + } + $this->output = $output; } } diff --git a/src/Builder/Aggregation/BottomNAggregation.php b/src/Builder/Aggregation/BottomNAggregation.php index 99678051b..d72a394b7 100644 --- a/src/Builder/Aggregation/BottomNAggregation.php +++ b/src/Builder/Aggregation/BottomNAggregation.php @@ -6,10 +6,21 @@ namespace MongoDB\Builder\Aggregation; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Document; use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; +use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; +use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Type\AccumulatorInterface; +use MongoDB\Builder\Type\ExpressionInterface; +use MongoDB\Model\BSONArray; use stdClass; /** @@ -24,24 +35,31 @@ class BottomNAggregation implements AccumulatorInterface public const NAME = '$bottomN'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param Int64|ResolvesToInt|int $n 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. */ - public Int64|ResolvesToInt|int $n; + /** @param ResolvesToInt|int $n 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. */ + public ResolvesToInt|int $n; - /** @param array|stdClass $sortBy Specifies the order of results, with syntax similar to $sort. */ - public stdClass|array $sortBy; + /** @param Document|Serializable|array|stdClass $sortBy Specifies the order of results, with syntax similar to $sort. */ + public Document|Serializable|stdClass|array $sortBy; - /** @param ExpressionInterface|mixed $output Represents the output for each element in the group and can be any expression. */ - public mixed $output; + /** @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $output Represents the output for each element in the group and can be any expression. */ + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $output; /** - * @param Int64|ResolvesToInt|int $n 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. - * @param array|stdClass $sortBy Specifies the order of results, with syntax similar to $sort. - * @param ExpressionInterface|mixed $output Represents the output for each element in the group and can be any expression. + * @param ResolvesToInt|int $n 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. + * @param Document|Serializable|array|stdClass $sortBy Specifies the order of results, with syntax similar to $sort. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $output Represents the output for each element in the group and can be any expression. */ - public function __construct(Int64|ResolvesToInt|int $n, stdClass|array $sortBy, mixed $output) - { + public function __construct( + ResolvesToInt|int $n, + Document|Serializable|stdClass|array $sortBy, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $output, + ) { $this->n = $n; $this->sortBy = $sortBy; + if (\is_array($output) && ! \array_is_list($output)) { + throw new \InvalidArgumentException('Expected $output argument to be a list, got an associative array.'); + } + $this->output = $output; } } diff --git a/src/Builder/Aggregation/CeilAggregation.php b/src/Builder/Aggregation/CeilAggregation.php index 1c0e29596..070230d0f 100644 --- a/src/Builder/Aggregation/CeilAggregation.php +++ b/src/Builder/Aggregation/CeilAggregation.php @@ -9,7 +9,10 @@ use MongoDB\BSON\Decimal128; use MongoDB\BSON\Int64; use MongoDB\Builder\Encode; +use MongoDB\Builder\Expression\ResolvesToDecimal; +use MongoDB\Builder\Expression\ResolvesToDouble; use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Expression\ResolvesToLong; use MongoDB\Builder\Expression\ResolvesToNumber; /** @@ -22,14 +25,15 @@ class CeilAggregation implements ResolvesToInt public const NAME = '$ceil'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param Decimal128|Int64|ResolvesToNumber|float|int $expression 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. */ - public Decimal128|Int64|ResolvesToNumber|float|int $expression; + /** @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression 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. */ + public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression; /** - * @param Decimal128|Int64|ResolvesToNumber|float|int $expression 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. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression 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. */ - public function __construct(Decimal128|Int64|ResolvesToNumber|float|int $expression) - { + public function __construct( + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression, + ) { $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/CmpAggregation.php b/src/Builder/Aggregation/CmpAggregation.php index e620d9c18..9424f79e1 100644 --- a/src/Builder/Aggregation/CmpAggregation.php +++ b/src/Builder/Aggregation/CmpAggregation.php @@ -6,9 +6,21 @@ namespace MongoDB\Builder\Aggregation; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Document; +use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; +use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; +use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Type\ExpressionInterface; +use MongoDB\Model\BSONArray; +use stdClass; /** * 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. @@ -20,19 +32,29 @@ class CmpAggregation implements ResolvesToInt public const NAME = '$cmp'; public const ENCODE = \MongoDB\Builder\Encode::Array; - /** @param ExpressionInterface|mixed $expression1 */ - public mixed $expression1; + /** @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression1 */ + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression1; - /** @param ExpressionInterface|mixed $expression2 */ - public mixed $expression2; + /** @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression2 */ + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression2; /** - * @param ExpressionInterface|mixed $expression1 - * @param ExpressionInterface|mixed $expression2 + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression1 + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression2 */ - public function __construct(mixed $expression1, mixed $expression2) - { + public function __construct( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression1, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression2, + ) { + if (\is_array($expression1) && ! \array_is_list($expression1)) { + throw new \InvalidArgumentException('Expected $expression1 argument to be a list, got an associative array.'); + } + $this->expression1 = $expression1; + if (\is_array($expression2) && ! \array_is_list($expression2)) { + throw new \InvalidArgumentException('Expected $expression2 argument to be a list, got an associative array.'); + } + $this->expression2 = $expression2; } } diff --git a/src/Builder/Aggregation/ConcatAggregation.php b/src/Builder/Aggregation/ConcatAggregation.php index b9cb94bb3..dbab898c7 100644 --- a/src/Builder/Aggregation/ConcatAggregation.php +++ b/src/Builder/Aggregation/ConcatAggregation.php @@ -32,7 +32,7 @@ public function __construct(ResolvesToString|string ...$expression) throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); } if (! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression arguments to be a list of ResolvesToString|non-empty-string, named arguments are not supported'); + throw new \InvalidArgumentException('Expected $expression arguments to be a list (array), named arguments are not supported'); } $this->expression = $expression; } diff --git a/src/Builder/Aggregation/ConcatArraysAggregation.php b/src/Builder/Aggregation/ConcatArraysAggregation.php index 94358a19f..d9ae07521 100644 --- a/src/Builder/Aggregation/ConcatArraysAggregation.php +++ b/src/Builder/Aggregation/ConcatArraysAggregation.php @@ -8,7 +8,6 @@ use MongoDB\BSON\PackedArray; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToArray; use MongoDB\Model\BSONArray; @@ -22,11 +21,11 @@ class ConcatArraysAggregation implements ResolvesToArray public const NAME = '$concatArrays'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param list ...$array */ + /** @param list ...$array */ public array $array; /** - * @param BSONArray|PackedArray|ResolvesToArray|list ...$array + * @param BSONArray|PackedArray|ResolvesToArray|array ...$array * @no-named-arguments */ public function __construct(PackedArray|ResolvesToArray|BSONArray|array ...$array) @@ -35,7 +34,7 @@ public function __construct(PackedArray|ResolvesToArray|BSONArray|array ...$arra throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $array, got %d.', 1, \count($array))); } if (! \array_is_list($array)) { - throw new \InvalidArgumentException('Expected $array arguments to be a list of BSONArray|PackedArray|ResolvesToArray|list, named arguments are not supported'); + throw new \InvalidArgumentException('Expected $array arguments to be a list (array), named arguments are not supported'); } $this->array = $array; } diff --git a/src/Builder/Aggregation/CondAggregation.php b/src/Builder/Aggregation/CondAggregation.php index cbc9a0ea2..36b616160 100644 --- a/src/Builder/Aggregation/CondAggregation.php +++ b/src/Builder/Aggregation/CondAggregation.php @@ -6,16 +6,30 @@ namespace MongoDB\Builder\Aggregation; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Document; +use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; +use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; +use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; +use MongoDB\Builder\Expression\ResolvesToAny; use MongoDB\Builder\Expression\ResolvesToBool; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Type\ExpressionInterface; +use MongoDB\Model\BSONArray; +use stdClass; /** * 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. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/cond/ */ -class CondAggregation implements ExpressionInterface +class CondAggregation implements ResolvesToAny { public const NAME = '$cond'; public const ENCODE = \MongoDB\Builder\Encode::Object; @@ -23,21 +37,32 @@ class CondAggregation implements ExpressionInterface /** @param ResolvesToBool|bool $if */ public ResolvesToBool|bool $if; - /** @param ExpressionInterface|mixed $then */ - public mixed $then; + /** @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $then */ + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $then; - /** @param ExpressionInterface|mixed $else */ - public mixed $else; + /** @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $else */ + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $else; /** * @param ResolvesToBool|bool $if - * @param ExpressionInterface|mixed $then - * @param ExpressionInterface|mixed $else + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $then + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $else */ - public function __construct(ResolvesToBool|bool $if, mixed $then, mixed $else) - { + public function __construct( + ResolvesToBool|bool $if, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $then, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $else, + ) { $this->if = $if; + if (\is_array($then) && ! \array_is_list($then)) { + throw new \InvalidArgumentException('Expected $then argument to be a list, got an associative array.'); + } + $this->then = $then; + if (\is_array($else) && ! \array_is_list($else)) { + throw new \InvalidArgumentException('Expected $else argument to be a list, got an associative array.'); + } + $this->else = $else; } } diff --git a/src/Builder/Aggregation/ConvertAggregation.php b/src/Builder/Aggregation/ConvertAggregation.php index add9a80e7..4ca5881dd 100644 --- a/src/Builder/Aggregation/ConvertAggregation.php +++ b/src/Builder/Aggregation/ConvertAggregation.php @@ -6,12 +6,24 @@ namespace MongoDB\Builder\Aggregation; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Document; use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; +use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; +use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; +use MongoDB\Builder\Expression\ResolvesToAny; use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Expression\ResolvesToString; use MongoDB\Builder\Optional; +use MongoDB\Builder\Type\ExpressionInterface; +use MongoDB\Model\BSONArray; +use stdClass; /** * Converts a value to a specified type. @@ -19,46 +31,58 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/convert/ */ -class ConvertAggregation implements ExpressionInterface +class ConvertAggregation implements ResolvesToAny { public const NAME = '$convert'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param ExpressionInterface|mixed $input */ - public mixed $input; + /** @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $input */ + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $input; - /** @param Int64|ResolvesToInt|ResolvesToString|int|non-empty-string $to */ - public Int64|ResolvesToInt|ResolvesToString|int|string $to; + /** @param ResolvesToInt|ResolvesToString|int|non-empty-string $to */ + public ResolvesToInt|ResolvesToString|int|string $to; /** - * @param ExpressionInterface|Optional|mixed $onError The value to return on encountering an error during conversion, including unsupported type conversions. The arguments can be any valid expression. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|Optional|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $onError 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. */ - public mixed $onError; + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|Optional|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $onError; /** - * @param ExpressionInterface|Optional|mixed $onNull The value to return if the input is null or missing. The arguments can be any valid expression. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|Optional|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $onNull 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. */ - public mixed $onNull; + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|Optional|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $onNull; /** - * @param ExpressionInterface|mixed $input - * @param Int64|ResolvesToInt|ResolvesToString|int|non-empty-string $to - * @param ExpressionInterface|Optional|mixed $onError The value to return on encountering an error during conversion, including unsupported type conversions. The arguments can be any valid expression. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $input + * @param ResolvesToInt|ResolvesToString|int|non-empty-string $to + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|Optional|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $onError 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. - * @param ExpressionInterface|Optional|mixed $onNull The value to return if the input is null or missing. The arguments can be any valid expression. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|Optional|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $onNull 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. */ public function __construct( - mixed $input, - Int64|ResolvesToInt|ResolvesToString|int|string $to, - mixed $onError = Optional::Undefined, - mixed $onNull = Optional::Undefined, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $input, + ResolvesToInt|ResolvesToString|int|string $to, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|Optional|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $onError = Optional::Undefined, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|Optional|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $onNull = Optional::Undefined, ) { + if (\is_array($input) && ! \array_is_list($input)) { + throw new \InvalidArgumentException('Expected $input argument to be a list, got an associative array.'); + } + $this->input = $input; $this->to = $to; + if (\is_array($onError) && ! \array_is_list($onError)) { + throw new \InvalidArgumentException('Expected $onError argument to be a list, got an associative array.'); + } + $this->onError = $onError; + if (\is_array($onNull) && ! \array_is_list($onNull)) { + throw new \InvalidArgumentException('Expected $onNull argument to be a list, got an associative array.'); + } + $this->onNull = $onNull; } } diff --git a/src/Builder/Aggregation/CosAggregation.php b/src/Builder/Aggregation/CosAggregation.php index 96a057687..86b90e242 100644 --- a/src/Builder/Aggregation/CosAggregation.php +++ b/src/Builder/Aggregation/CosAggregation.php @@ -11,6 +11,8 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToDecimal; use MongoDB\Builder\Expression\ResolvesToDouble; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Expression\ResolvesToLong; use MongoDB\Builder\Expression\ResolvesToNumber; /** @@ -24,17 +26,18 @@ class CosAggregation implements ResolvesToDouble, ResolvesToDecimal public const ENCODE = \MongoDB\Builder\Encode::Single; /** - * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $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. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression $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. */ - public Decimal128|Int64|ResolvesToNumber|float|int $expression; + public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression; /** - * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $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. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression $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. */ - public function __construct(Decimal128|Int64|ResolvesToNumber|float|int $expression) - { + public function __construct( + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression, + ) { $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/CoshAggregation.php b/src/Builder/Aggregation/CoshAggregation.php index db7fbcc5a..dcaaa94c7 100644 --- a/src/Builder/Aggregation/CoshAggregation.php +++ b/src/Builder/Aggregation/CoshAggregation.php @@ -11,6 +11,8 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToDecimal; use MongoDB\Builder\Expression\ResolvesToDouble; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Expression\ResolvesToLong; use MongoDB\Builder\Expression\ResolvesToNumber; /** @@ -24,17 +26,18 @@ class CoshAggregation implements ResolvesToDouble, ResolvesToDecimal public const ENCODE = \MongoDB\Builder\Encode::Single; /** - * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $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. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression $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. */ - public Decimal128|Int64|ResolvesToNumber|float|int $expression; + public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression; /** - * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $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. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression $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. */ - public function __construct(Decimal128|Int64|ResolvesToNumber|float|int $expression) - { + public function __construct( + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression, + ) { $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/CountAggregation.php b/src/Builder/Aggregation/CountAggregation.php index 1ff53e097..faba192a0 100644 --- a/src/Builder/Aggregation/CountAggregation.php +++ b/src/Builder/Aggregation/CountAggregation.php @@ -7,6 +7,7 @@ namespace MongoDB\Builder\Aggregation; use MongoDB\Builder\Encode; +use MongoDB\Builder\Type\AccumulatorInterface; /** * Returns the number of documents in the group or window. diff --git a/src/Builder/Aggregation/CovariancePopAggregation.php b/src/Builder/Aggregation/CovariancePopAggregation.php index 1f3afdff3..5fcfc0fbf 100644 --- a/src/Builder/Aggregation/CovariancePopAggregation.php +++ b/src/Builder/Aggregation/CovariancePopAggregation.php @@ -11,6 +11,8 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToDecimal; use MongoDB\Builder\Expression\ResolvesToDouble; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Expression\ResolvesToLong; use MongoDB\Builder\Expression\ResolvesToNumber; /** @@ -24,19 +26,19 @@ class CovariancePopAggregation implements ResolvesToDouble, ResolvesToDecimal public const NAME = '$covariancePop'; public const ENCODE = \MongoDB\Builder\Encode::Array; - /** @param Decimal128|Int64|ResolvesToNumber|float|int $expression1 */ - public Decimal128|Int64|ResolvesToNumber|float|int $expression1; + /** @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression1 */ + public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression1; - /** @param Decimal128|Int64|ResolvesToNumber|float|int $expression2 */ - public Decimal128|Int64|ResolvesToNumber|float|int $expression2; + /** @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression2 */ + public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression2; /** - * @param Decimal128|Int64|ResolvesToNumber|float|int $expression1 - * @param Decimal128|Int64|ResolvesToNumber|float|int $expression2 + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression1 + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression2 */ public function __construct( - Decimal128|Int64|ResolvesToNumber|float|int $expression1, - Decimal128|Int64|ResolvesToNumber|float|int $expression2, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression1, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression2, ) { $this->expression1 = $expression1; $this->expression2 = $expression2; diff --git a/src/Builder/Aggregation/CovarianceSampAggregation.php b/src/Builder/Aggregation/CovarianceSampAggregation.php index d76a38f7c..8c65a909f 100644 --- a/src/Builder/Aggregation/CovarianceSampAggregation.php +++ b/src/Builder/Aggregation/CovarianceSampAggregation.php @@ -11,6 +11,8 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToDecimal; use MongoDB\Builder\Expression\ResolvesToDouble; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Expression\ResolvesToLong; use MongoDB\Builder\Expression\ResolvesToNumber; /** @@ -24,19 +26,19 @@ class CovarianceSampAggregation implements ResolvesToDouble, ResolvesToDecimal public const NAME = '$covarianceSamp'; public const ENCODE = \MongoDB\Builder\Encode::Array; - /** @param Decimal128|Int64|ResolvesToNumber|float|int $expression1 */ - public Decimal128|Int64|ResolvesToNumber|float|int $expression1; + /** @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression1 */ + public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression1; - /** @param Decimal128|Int64|ResolvesToNumber|float|int $expression2 */ - public Decimal128|Int64|ResolvesToNumber|float|int $expression2; + /** @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression2 */ + public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression2; /** - * @param Decimal128|Int64|ResolvesToNumber|float|int $expression1 - * @param Decimal128|Int64|ResolvesToNumber|float|int $expression2 + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression1 + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression2 */ public function __construct( - Decimal128|Int64|ResolvesToNumber|float|int $expression1, - Decimal128|Int64|ResolvesToNumber|float|int $expression2, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression1, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression2, ) { $this->expression1 = $expression1; $this->expression2 = $expression2; diff --git a/src/Builder/Aggregation/DateAddAggregation.php b/src/Builder/Aggregation/DateAddAggregation.php index 8f81ec0c1..3a252034a 100644 --- a/src/Builder/Aggregation/DateAddAggregation.php +++ b/src/Builder/Aggregation/DateAddAggregation.php @@ -6,9 +6,9 @@ namespace MongoDB\Builder\Aggregation; -use DateTimeInterface; use MongoDB\BSON\Int64; use MongoDB\BSON\ObjectId; +use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToDate; @@ -29,8 +29,8 @@ class DateAddAggregation implements ResolvesToDate public const NAME = '$dateAdd'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $startDate 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. */ - public DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $startDate; + /** @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $startDate 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. */ + public ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $startDate; /** @param ResolvesToString|non-empty-string $unit The unit used to measure the amount of time added to the startDate. */ public ResolvesToString|string $unit; @@ -42,13 +42,13 @@ class DateAddAggregation implements ResolvesToDate public ResolvesToString|Optional|string $timezone; /** - * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $startDate 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. + * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $startDate 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. * @param ResolvesToString|non-empty-string $unit The unit used to measure the amount of time added to the startDate. * @param Int64|ResolvesToInt|ResolvesToLong|int $amount * @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public function __construct( - DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $startDate, + ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $startDate, ResolvesToString|string $unit, Int64|ResolvesToInt|ResolvesToLong|int $amount, ResolvesToString|Optional|string $timezone = Optional::Undefined, diff --git a/src/Builder/Aggregation/DateDiffAggregation.php b/src/Builder/Aggregation/DateDiffAggregation.php index 85fc37174..a5cb077a2 100644 --- a/src/Builder/Aggregation/DateDiffAggregation.php +++ b/src/Builder/Aggregation/DateDiffAggregation.php @@ -6,9 +6,8 @@ namespace MongoDB\Builder\Aggregation; -use DateTimeInterface; -use MongoDB\BSON\Int64; use MongoDB\BSON\ObjectId; +use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToDate; @@ -28,11 +27,11 @@ class DateDiffAggregation implements ResolvesToInt public const NAME = '$dateDiff'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $startDate The start of the time period. The startDate can be any expression that resolves to a Date, a Timestamp, or an ObjectID. */ - public DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $startDate; + /** @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $startDate The start of the time period. The startDate can be any expression that resolves to a Date, a Timestamp, or an ObjectID. */ + public ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $startDate; - /** @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $endDate The end of the time period. The endDate can be any expression that resolves to a Date, a Timestamp, or an ObjectID. */ - public DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $endDate; + /** @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $endDate The end of the time period. The endDate can be any expression that resolves to a Date, a Timestamp, or an ObjectID. */ + public ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $endDate; /** @param ResolvesToString|non-empty-string $unit The time measurement unit between the startDate and endDate */ public ResolvesToString|string $unit; @@ -44,15 +43,15 @@ class DateDiffAggregation implements ResolvesToInt public ResolvesToString|Optional|string $startOfWeek; /** - * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $startDate The start of the time period. The startDate can be any expression that resolves to a Date, a Timestamp, or an ObjectID. - * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $endDate The end of the time period. The endDate can be any expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $startDate The start of the time period. The startDate can be any expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $endDate The end of the time period. The endDate can be any expression that resolves to a Date, a Timestamp, or an ObjectID. * @param ResolvesToString|non-empty-string $unit The time measurement unit between the startDate and endDate * @param Optional|ResolvesToString|non-empty-string $timezone 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. * @param Optional|ResolvesToString|non-empty-string $startOfWeek Used when the unit is equal to week. Defaults to Sunday. The startOfWeek parameter is an expression that resolves to a case insensitive string */ public function __construct( - DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $startDate, - DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $endDate, + ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $startDate, + ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $endDate, ResolvesToString|string $unit, ResolvesToString|Optional|string $timezone = Optional::Undefined, ResolvesToString|Optional|string $startOfWeek = Optional::Undefined, diff --git a/src/Builder/Aggregation/DateFromPartsAggregation.php b/src/Builder/Aggregation/DateFromPartsAggregation.php index 7874a0bd4..b318bc3ef 100644 --- a/src/Builder/Aggregation/DateFromPartsAggregation.php +++ b/src/Builder/Aggregation/DateFromPartsAggregation.php @@ -10,6 +10,10 @@ use MongoDB\BSON\Int64; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToDate; +use MongoDB\Builder\Expression\ResolvesToDecimal; +use MongoDB\Builder\Expression\ResolvesToDouble; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Expression\ResolvesToLong; use MongoDB\Builder\Expression\ResolvesToNumber; use MongoDB\Builder\Expression\ResolvesToString; use MongoDB\Builder\Optional; @@ -24,63 +28,63 @@ class DateFromPartsAggregation implements ResolvesToDate public const NAME = '$dateFromParts'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param Decimal128|Int64|ResolvesToNumber|float|int $year Calendar year. Can be any expression that evaluates to a number. */ - public Decimal128|Int64|ResolvesToNumber|float|int $year; + /** @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $year Calendar year. Can be any expression that evaluates to a number. */ + public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $year; - /** @param Decimal128|Int64|ResolvesToNumber|float|int $isoWeekYear ISO Week Date Year. Can be any expression that evaluates to a number. */ - public Decimal128|Int64|ResolvesToNumber|float|int $isoWeekYear; + /** @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $isoWeekYear ISO Week Date Year. Can be any expression that evaluates to a number. */ + public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $isoWeekYear; - /** @param Decimal128|Int64|Optional|ResolvesToNumber|float|int $month Month. Defaults to 1. */ - public Decimal128|Int64|ResolvesToNumber|Optional|float|int $month; + /** @param Decimal128|Int64|Optional|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $month Month. Defaults to 1. */ + public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|Optional|float|int $month; - /** @param Decimal128|Int64|Optional|ResolvesToNumber|float|int $isoWeek Week of year. Defaults to 1. */ - public Decimal128|Int64|ResolvesToNumber|Optional|float|int $isoWeek; + /** @param Decimal128|Int64|Optional|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $isoWeek Week of year. Defaults to 1. */ + public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|Optional|float|int $isoWeek; - /** @param Decimal128|Int64|Optional|ResolvesToNumber|float|int $day Day of month. Defaults to 1. */ - public Decimal128|Int64|ResolvesToNumber|Optional|float|int $day; + /** @param Decimal128|Int64|Optional|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $day Day of month. Defaults to 1. */ + public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|Optional|float|int $day; - /** @param Decimal128|Int64|Optional|ResolvesToNumber|float|int $isoDayOfWeek Day of week (Monday 1 - Sunday 7). Defaults to 1. */ - public Decimal128|Int64|ResolvesToNumber|Optional|float|int $isoDayOfWeek; + /** @param Decimal128|Int64|Optional|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $isoDayOfWeek Day of week (Monday 1 - Sunday 7). Defaults to 1. */ + public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|Optional|float|int $isoDayOfWeek; - /** @param Decimal128|Int64|Optional|ResolvesToNumber|float|int $hour Hour. Defaults to 0. */ - public Decimal128|Int64|ResolvesToNumber|Optional|float|int $hour; + /** @param Decimal128|Int64|Optional|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $hour Hour. Defaults to 0. */ + public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|Optional|float|int $hour; - /** @param Decimal128|Int64|Optional|ResolvesToNumber|float|int $minute Minute. Defaults to 0. */ - public Decimal128|Int64|ResolvesToNumber|Optional|float|int $minute; + /** @param Decimal128|Int64|Optional|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $minute Minute. Defaults to 0. */ + public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|Optional|float|int $minute; - /** @param Decimal128|Int64|Optional|ResolvesToNumber|float|int $second Second. Defaults to 0. */ - public Decimal128|Int64|ResolvesToNumber|Optional|float|int $second; + /** @param Decimal128|Int64|Optional|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $second Second. Defaults to 0. */ + public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|Optional|float|int $second; - /** @param Decimal128|Int64|Optional|ResolvesToNumber|float|int $millisecond Millisecond. Defaults to 0. */ - public Decimal128|Int64|ResolvesToNumber|Optional|float|int $millisecond; + /** @param Decimal128|Int64|Optional|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $millisecond Millisecond. Defaults to 0. */ + public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|Optional|float|int $millisecond; /** @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public ResolvesToString|Optional|string $timezone; /** - * @param Decimal128|Int64|ResolvesToNumber|float|int $year Calendar year. Can be any expression that evaluates to a number. - * @param Decimal128|Int64|ResolvesToNumber|float|int $isoWeekYear ISO Week Date Year. Can be any expression that evaluates to a number. - * @param Decimal128|Int64|Optional|ResolvesToNumber|float|int $month Month. Defaults to 1. - * @param Decimal128|Int64|Optional|ResolvesToNumber|float|int $isoWeek Week of year. Defaults to 1. - * @param Decimal128|Int64|Optional|ResolvesToNumber|float|int $day Day of month. Defaults to 1. - * @param Decimal128|Int64|Optional|ResolvesToNumber|float|int $isoDayOfWeek Day of week (Monday 1 - Sunday 7). Defaults to 1. - * @param Decimal128|Int64|Optional|ResolvesToNumber|float|int $hour Hour. Defaults to 0. - * @param Decimal128|Int64|Optional|ResolvesToNumber|float|int $minute Minute. Defaults to 0. - * @param Decimal128|Int64|Optional|ResolvesToNumber|float|int $second Second. Defaults to 0. - * @param Decimal128|Int64|Optional|ResolvesToNumber|float|int $millisecond Millisecond. Defaults to 0. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $year Calendar year. Can be any expression that evaluates to a number. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $isoWeekYear ISO Week Date Year. Can be any expression that evaluates to a number. + * @param Decimal128|Int64|Optional|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $month Month. Defaults to 1. + * @param Decimal128|Int64|Optional|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $isoWeek Week of year. Defaults to 1. + * @param Decimal128|Int64|Optional|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $day Day of month. Defaults to 1. + * @param Decimal128|Int64|Optional|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $isoDayOfWeek Day of week (Monday 1 - Sunday 7). Defaults to 1. + * @param Decimal128|Int64|Optional|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $hour Hour. Defaults to 0. + * @param Decimal128|Int64|Optional|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $minute Minute. Defaults to 0. + * @param Decimal128|Int64|Optional|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $second Second. Defaults to 0. + * @param Decimal128|Int64|Optional|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $millisecond Millisecond. Defaults to 0. * @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public function __construct( - Decimal128|Int64|ResolvesToNumber|float|int $year, - Decimal128|Int64|ResolvesToNumber|float|int $isoWeekYear, - Decimal128|Int64|ResolvesToNumber|Optional|float|int $month = Optional::Undefined, - Decimal128|Int64|ResolvesToNumber|Optional|float|int $isoWeek = Optional::Undefined, - Decimal128|Int64|ResolvesToNumber|Optional|float|int $day = Optional::Undefined, - Decimal128|Int64|ResolvesToNumber|Optional|float|int $isoDayOfWeek = Optional::Undefined, - Decimal128|Int64|ResolvesToNumber|Optional|float|int $hour = Optional::Undefined, - Decimal128|Int64|ResolvesToNumber|Optional|float|int $minute = Optional::Undefined, - Decimal128|Int64|ResolvesToNumber|Optional|float|int $second = Optional::Undefined, - Decimal128|Int64|ResolvesToNumber|Optional|float|int $millisecond = Optional::Undefined, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $year, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $isoWeekYear, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|Optional|float|int $month = Optional::Undefined, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|Optional|float|int $isoWeek = Optional::Undefined, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|Optional|float|int $day = Optional::Undefined, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|Optional|float|int $isoDayOfWeek = Optional::Undefined, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|Optional|float|int $hour = Optional::Undefined, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|Optional|float|int $minute = Optional::Undefined, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|Optional|float|int $second = Optional::Undefined, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|Optional|float|int $millisecond = Optional::Undefined, ResolvesToString|Optional|string $timezone = Optional::Undefined, ) { $this->year = $year; diff --git a/src/Builder/Aggregation/DateFromStringAggregation.php b/src/Builder/Aggregation/DateFromStringAggregation.php index 2d892a5cb..a36e90c27 100644 --- a/src/Builder/Aggregation/DateFromStringAggregation.php +++ b/src/Builder/Aggregation/DateFromStringAggregation.php @@ -6,11 +6,24 @@ namespace MongoDB\Builder\Aggregation; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Document; +use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; +use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; +use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToDate; +use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Expression\ResolvesToString; use MongoDB\Builder\Optional; +use MongoDB\Builder\Type\ExpressionInterface; +use MongoDB\Model\BSONArray; +use stdClass; /** * Converts a date/time string to a date object. @@ -35,38 +48,46 @@ class DateFromStringAggregation implements ResolvesToDate public ResolvesToString|Optional|string $timezone; /** - * @param ExpressionInterface|Optional|mixed $onError 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. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|Optional|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $onError 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. */ - public mixed $onError; + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|Optional|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $onError; /** - * @param ExpressionInterface|Optional|mixed $onNull 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. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|Optional|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $onNull 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. */ - public mixed $onNull; + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|Optional|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $onNull; /** * @param ResolvesToString|non-empty-string $dateString The date/time string to convert to a date object. * @param Optional|ResolvesToString|non-empty-string $format 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. * @param Optional|ResolvesToString|non-empty-string $timezone The time zone to use to format the date. - * @param ExpressionInterface|Optional|mixed $onError 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. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|Optional|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $onError 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. - * @param ExpressionInterface|Optional|mixed $onNull 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. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|Optional|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $onNull 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. */ public function __construct( ResolvesToString|string $dateString, ResolvesToString|Optional|string $format = Optional::Undefined, ResolvesToString|Optional|string $timezone = Optional::Undefined, - mixed $onError = Optional::Undefined, - mixed $onNull = Optional::Undefined, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|Optional|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $onError = Optional::Undefined, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|Optional|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $onNull = Optional::Undefined, ) { $this->dateString = $dateString; $this->format = $format; $this->timezone = $timezone; + if (\is_array($onError) && ! \array_is_list($onError)) { + throw new \InvalidArgumentException('Expected $onError argument to be a list, got an associative array.'); + } + $this->onError = $onError; + if (\is_array($onNull) && ! \array_is_list($onNull)) { + throw new \InvalidArgumentException('Expected $onNull argument to be a list, got an associative array.'); + } + $this->onNull = $onNull; } } diff --git a/src/Builder/Aggregation/DateSubtractAggregation.php b/src/Builder/Aggregation/DateSubtractAggregation.php index c3f777779..4e0a4a5df 100644 --- a/src/Builder/Aggregation/DateSubtractAggregation.php +++ b/src/Builder/Aggregation/DateSubtractAggregation.php @@ -6,9 +6,9 @@ namespace MongoDB\Builder\Aggregation; -use DateTimeInterface; use MongoDB\BSON\Int64; use MongoDB\BSON\ObjectId; +use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToDate; @@ -29,8 +29,8 @@ class DateSubtractAggregation implements ResolvesToDate public const NAME = '$dateSubtract'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $startDate 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. */ - public DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $startDate; + /** @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $startDate 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. */ + public ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $startDate; /** @param ResolvesToString|non-empty-string $unit The unit used to measure the amount of time added to the startDate. */ public ResolvesToString|string $unit; @@ -42,13 +42,13 @@ class DateSubtractAggregation implements ResolvesToDate public ResolvesToString|Optional|string $timezone; /** - * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $startDate 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. + * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $startDate 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. * @param ResolvesToString|non-empty-string $unit The unit used to measure the amount of time added to the startDate. * @param Int64|ResolvesToInt|ResolvesToLong|int $amount * @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public function __construct( - DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $startDate, + ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $startDate, ResolvesToString|string $unit, Int64|ResolvesToInt|ResolvesToLong|int $amount, ResolvesToString|Optional|string $timezone = Optional::Undefined, diff --git a/src/Builder/Aggregation/DateToPartsAggregation.php b/src/Builder/Aggregation/DateToPartsAggregation.php index 80b8a94e2..4251fa0a0 100644 --- a/src/Builder/Aggregation/DateToPartsAggregation.php +++ b/src/Builder/Aggregation/DateToPartsAggregation.php @@ -6,9 +6,8 @@ namespace MongoDB\Builder\Aggregation; -use DateTimeInterface; -use MongoDB\BSON\Int64; use MongoDB\BSON\ObjectId; +use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToDate; @@ -28,8 +27,8 @@ class DateToPartsAggregation implements ResolvesToObject public const NAME = '$dateToParts'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The input date for which to return parts. date can be any expression that resolves to a Date, a Timestamp, or an ObjectID. */ - public DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; + /** @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The input date for which to return parts. date can be any expression that resolves to a Date, a Timestamp, or an ObjectID. */ + public ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; /** @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public ResolvesToString|Optional|string $timezone; @@ -38,12 +37,12 @@ class DateToPartsAggregation implements ResolvesToObject public Optional|bool $iso8601; /** - * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The input date for which to return parts. date can be any expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The input date for which to return parts. date can be any expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|non-empty-string $timezone 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. * @param Optional|bool $iso8601 If set to true, modifies the output document to use ISO week date fields. Defaults to false. */ public function __construct( - DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|Optional|string $timezone = Optional::Undefined, Optional|bool $iso8601 = Optional::Undefined, ) { diff --git a/src/Builder/Aggregation/DateToStringAggregation.php b/src/Builder/Aggregation/DateToStringAggregation.php index a7f45388d..2ed63b1d1 100644 --- a/src/Builder/Aggregation/DateToStringAggregation.php +++ b/src/Builder/Aggregation/DateToStringAggregation.php @@ -6,17 +6,26 @@ namespace MongoDB\Builder\Aggregation; -use DateTimeInterface; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Document; use MongoDB\BSON\Int64; use MongoDB\BSON\ObjectId; +use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; +use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToDate; +use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Expression\ResolvesToObjectId; use MongoDB\Builder\Expression\ResolvesToString; use MongoDB\Builder\Expression\ResolvesToTimestamp; use MongoDB\Builder\Optional; +use MongoDB\Builder\Type\ExpressionInterface; +use MongoDB\Model\BSONArray; +use stdClass; /** * Returns the date as a formatted string. @@ -28,8 +37,8 @@ class DateToStringAggregation implements ResolvesToString public const NAME = '$dateToString'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to convert to string. Must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ - public DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; + /** @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The date to convert to string. Must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ + public ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; /** * @param Optional|ResolvesToString|non-empty-string $format 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. @@ -41,28 +50,32 @@ class DateToStringAggregation implements ResolvesToString public ResolvesToString|Optional|string $timezone; /** - * @param ExpressionInterface|Optional|mixed $onNull The value to return if the date is null or missing. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|Optional|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $onNull The value to return if the date is null or missing. * If unspecified, $dateToString returns null if the date is null or missing. */ - public mixed $onNull; + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|Optional|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $onNull; /** - * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to convert to string. Must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The date to convert to string. Must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|non-empty-string $format 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. * @param Optional|ResolvesToString|non-empty-string $timezone The time zone to use to format the date. - * @param ExpressionInterface|Optional|mixed $onNull The value to return if the date is null or missing. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|Optional|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $onNull The value to return if the date is null or missing. * If unspecified, $dateToString returns null if the date is null or missing. */ public function __construct( - DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|Optional|string $format = Optional::Undefined, ResolvesToString|Optional|string $timezone = Optional::Undefined, - mixed $onNull = Optional::Undefined, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|Optional|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $onNull = Optional::Undefined, ) { $this->date = $date; $this->format = $format; $this->timezone = $timezone; + if (\is_array($onNull) && ! \array_is_list($onNull)) { + throw new \InvalidArgumentException('Expected $onNull argument to be a list, got an associative array.'); + } + $this->onNull = $onNull; } } diff --git a/src/Builder/Aggregation/DateTruncAggregation.php b/src/Builder/Aggregation/DateTruncAggregation.php index bbe9d2cd5..9a5816be5 100644 --- a/src/Builder/Aggregation/DateTruncAggregation.php +++ b/src/Builder/Aggregation/DateTruncAggregation.php @@ -6,13 +6,17 @@ namespace MongoDB\Builder\Aggregation; -use DateTimeInterface; use MongoDB\BSON\Decimal128; use MongoDB\BSON\Int64; use MongoDB\BSON\ObjectId; +use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToDate; +use MongoDB\Builder\Expression\ResolvesToDecimal; +use MongoDB\Builder\Expression\ResolvesToDouble; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Expression\ResolvesToLong; use MongoDB\Builder\Expression\ResolvesToNumber; use MongoDB\Builder\Expression\ResolvesToObjectId; use MongoDB\Builder\Expression\ResolvesToString; @@ -29,8 +33,8 @@ class DateTruncAggregation implements ResolvesToDate public const NAME = '$dateTrunc'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to truncate, specified in UTC. The date can be any expression that resolves to a Date, a Timestamp, or an ObjectID. */ - public DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; + /** @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The date to truncate, specified in UTC. The date can be any expression that resolves to a Date, a Timestamp, or an ObjectID. */ + public ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; /** * @param ResolvesToString|non-empty-string $unit The unit of time, specified as an expression that must resolve to one of these strings: year, quarter, week, month, day, hour, minute, second. @@ -39,10 +43,10 @@ class DateTruncAggregation implements ResolvesToDate public ResolvesToString|string $unit; /** - * @param Decimal128|Int64|Optional|ResolvesToNumber|float|int $binSize The numeric time value, specified as an expression that must resolve to a positive non-zero number. Defaults to 1. + * @param Decimal128|Int64|Optional|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $binSize 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. */ - public Decimal128|Int64|ResolvesToNumber|Optional|float|int $binSize; + public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|Optional|float|int $binSize; /** @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public ResolvesToString|Optional|string $timezone; @@ -54,19 +58,19 @@ class DateTruncAggregation implements ResolvesToDate public Optional|string $startOfWeek; /** - * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to truncate, specified in UTC. The date can be any expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The date to truncate, specified in UTC. The date can be any expression that resolves to a Date, a Timestamp, or an ObjectID. * @param ResolvesToString|non-empty-string $unit 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. - * @param Decimal128|Int64|Optional|ResolvesToNumber|float|int $binSize The numeric time value, specified as an expression that must resolve to a positive non-zero number. Defaults to 1. + * @param Decimal128|Int64|Optional|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $binSize 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. * @param Optional|ResolvesToString|non-empty-string $timezone 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. * @param Optional|non-empty-string $startOfWeek The start of the week. Used when * unit is week. Defaults to Sunday. */ public function __construct( - DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|string $unit, - Decimal128|Int64|ResolvesToNumber|Optional|float|int $binSize = Optional::Undefined, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|Optional|float|int $binSize = Optional::Undefined, ResolvesToString|Optional|string $timezone = Optional::Undefined, Optional|string $startOfWeek = Optional::Undefined, ) { diff --git a/src/Builder/Aggregation/DayOfMonthAggregation.php b/src/Builder/Aggregation/DayOfMonthAggregation.php index d99eceffc..600cb743b 100644 --- a/src/Builder/Aggregation/DayOfMonthAggregation.php +++ b/src/Builder/Aggregation/DayOfMonthAggregation.php @@ -6,9 +6,8 @@ namespace MongoDB\Builder\Aggregation; -use DateTimeInterface; -use MongoDB\BSON\Int64; use MongoDB\BSON\ObjectId; +use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToDate; @@ -28,18 +27,18 @@ class DayOfMonthAggregation implements ResolvesToInt public const NAME = '$dayOfMonth'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ - public DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; + /** @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ + public ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; /** @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public ResolvesToString|Optional|string $timezone; /** - * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public function __construct( - DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|Optional|string $timezone = Optional::Undefined, ) { $this->date = $date; diff --git a/src/Builder/Aggregation/DayOfWeekAggregation.php b/src/Builder/Aggregation/DayOfWeekAggregation.php index 97f6f51ad..4ed18f88f 100644 --- a/src/Builder/Aggregation/DayOfWeekAggregation.php +++ b/src/Builder/Aggregation/DayOfWeekAggregation.php @@ -6,9 +6,8 @@ namespace MongoDB\Builder\Aggregation; -use DateTimeInterface; -use MongoDB\BSON\Int64; use MongoDB\BSON\ObjectId; +use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToDate; @@ -28,18 +27,18 @@ class DayOfWeekAggregation implements ResolvesToInt public const NAME = '$dayOfWeek'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ - public DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; + /** @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ + public ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; /** @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public ResolvesToString|Optional|string $timezone; /** - * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public function __construct( - DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|Optional|string $timezone = Optional::Undefined, ) { $this->date = $date; diff --git a/src/Builder/Aggregation/DayOfYearAggregation.php b/src/Builder/Aggregation/DayOfYearAggregation.php index 7a952016b..e61aa75da 100644 --- a/src/Builder/Aggregation/DayOfYearAggregation.php +++ b/src/Builder/Aggregation/DayOfYearAggregation.php @@ -6,9 +6,8 @@ namespace MongoDB\Builder\Aggregation; -use DateTimeInterface; -use MongoDB\BSON\Int64; use MongoDB\BSON\ObjectId; +use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToDate; @@ -28,18 +27,18 @@ class DayOfYearAggregation implements ResolvesToInt public const NAME = '$dayOfYear'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ - public DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; + /** @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ + public ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; /** @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public ResolvesToString|Optional|string $timezone; /** - * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public function __construct( - DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|Optional|string $timezone = Optional::Undefined, ) { $this->date = $date; diff --git a/src/Builder/Aggregation/DegreesToRadiansAggregation.php b/src/Builder/Aggregation/DegreesToRadiansAggregation.php index 37a4df5b4..f5cd7b5ed 100644 --- a/src/Builder/Aggregation/DegreesToRadiansAggregation.php +++ b/src/Builder/Aggregation/DegreesToRadiansAggregation.php @@ -11,6 +11,8 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToDecimal; use MongoDB\Builder\Expression\ResolvesToDouble; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Expression\ResolvesToLong; use MongoDB\Builder\Expression\ResolvesToNumber; /** @@ -24,17 +26,18 @@ class DegreesToRadiansAggregation implements ResolvesToDouble, ResolvesToDecimal public const ENCODE = \MongoDB\Builder\Encode::Single; /** - * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $degreesToRadians takes any valid expression that resolves to a number. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression $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. */ - public Decimal128|Int64|ResolvesToNumber|float|int $expression; + public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression; /** - * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $degreesToRadians takes any valid expression that resolves to a number. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression $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. */ - public function __construct(Decimal128|Int64|ResolvesToNumber|float|int $expression) - { + public function __construct( + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression, + ) { $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/DerivativeAggregation.php b/src/Builder/Aggregation/DerivativeAggregation.php index 14e41a1f7..9b35851af 100644 --- a/src/Builder/Aggregation/DerivativeAggregation.php +++ b/src/Builder/Aggregation/DerivativeAggregation.php @@ -6,13 +6,15 @@ namespace MongoDB\Builder\Aggregation; -use DateTimeInterface; use MongoDB\BSON\Decimal128; use MongoDB\BSON\Int64; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToDate; +use MongoDB\Builder\Expression\ResolvesToDecimal; use MongoDB\Builder\Expression\ResolvesToDouble; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Expression\ResolvesToLong; use MongoDB\Builder\Expression\ResolvesToNumber; use MongoDB\Builder\Optional; @@ -27,8 +29,8 @@ class DerivativeAggregation implements ResolvesToDouble public const NAME = '$derivative'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int $input */ - public DateTimeInterface|Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int $input; + /** @param Decimal128|Int64|ResolvesToDate|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|UTCDateTime|float|int $input */ + public Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $input; /** * @param Optional|non-empty-string $unit A string that specifies the time unit. Use one of these strings: "week", "day","hour", "minute", "second", "millisecond". @@ -37,12 +39,12 @@ class DerivativeAggregation implements ResolvesToDouble public Optional|string $unit; /** - * @param DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int $input + * @param Decimal128|Int64|ResolvesToDate|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|UTCDateTime|float|int $input * @param Optional|non-empty-string $unit 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. */ public function __construct( - DateTimeInterface|Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int $input, + Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $input, Optional|string $unit = Optional::Undefined, ) { $this->input = $input; diff --git a/src/Builder/Aggregation/DivideAggregation.php b/src/Builder/Aggregation/DivideAggregation.php index 612c4e7c8..3ad6ffc44 100644 --- a/src/Builder/Aggregation/DivideAggregation.php +++ b/src/Builder/Aggregation/DivideAggregation.php @@ -9,7 +9,10 @@ use MongoDB\BSON\Decimal128; use MongoDB\BSON\Int64; use MongoDB\Builder\Encode; +use MongoDB\Builder\Expression\ResolvesToDecimal; use MongoDB\Builder\Expression\ResolvesToDouble; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Expression\ResolvesToLong; use MongoDB\Builder\Expression\ResolvesToNumber; /** @@ -22,19 +25,19 @@ class DivideAggregation implements ResolvesToDouble public const NAME = '$divide'; public const ENCODE = \MongoDB\Builder\Encode::Array; - /** @param Decimal128|Int64|ResolvesToNumber|float|int $dividend The first argument is the dividend, and the second argument is the divisor; i.e. the first argument is divided by the second argument. */ - public Decimal128|Int64|ResolvesToNumber|float|int $dividend; + /** @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $dividend The first argument is the dividend, and the second argument is the divisor; i.e. the first argument is divided by the second argument. */ + public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $dividend; - /** @param Decimal128|Int64|ResolvesToNumber|float|int $divisor */ - public Decimal128|Int64|ResolvesToNumber|float|int $divisor; + /** @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $divisor */ + public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $divisor; /** - * @param Decimal128|Int64|ResolvesToNumber|float|int $dividend The first argument is the dividend, and the second argument is the divisor; i.e. the first argument is divided by the second argument. - * @param Decimal128|Int64|ResolvesToNumber|float|int $divisor + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $dividend The first argument is the dividend, and the second argument is the divisor; i.e. the first argument is divided by the second argument. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $divisor */ public function __construct( - Decimal128|Int64|ResolvesToNumber|float|int $dividend, - Decimal128|Int64|ResolvesToNumber|float|int $divisor, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $dividend, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $divisor, ) { $this->dividend = $dividend; $this->divisor = $divisor; diff --git a/src/Builder/Aggregation/EqAggregation.php b/src/Builder/Aggregation/EqAggregation.php index d6b5fd594..180518007 100644 --- a/src/Builder/Aggregation/EqAggregation.php +++ b/src/Builder/Aggregation/EqAggregation.php @@ -6,9 +6,22 @@ namespace MongoDB\Builder\Aggregation; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Document; +use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; +use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; +use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToBool; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Type\ExpressionInterface; +use MongoDB\Model\BSONArray; +use stdClass; /** * Returns true if the values are equivalent. @@ -20,19 +33,29 @@ class EqAggregation implements ResolvesToBool public const NAME = '$eq'; public const ENCODE = \MongoDB\Builder\Encode::Array; - /** @param ExpressionInterface|mixed $expression1 */ - public mixed $expression1; + /** @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression1 */ + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression1; - /** @param ExpressionInterface|mixed $expression2 */ - public mixed $expression2; + /** @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression2 */ + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression2; /** - * @param ExpressionInterface|mixed $expression1 - * @param ExpressionInterface|mixed $expression2 + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression1 + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression2 */ - public function __construct(mixed $expression1, mixed $expression2) - { + public function __construct( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression1, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression2, + ) { + if (\is_array($expression1) && ! \array_is_list($expression1)) { + throw new \InvalidArgumentException('Expected $expression1 argument to be a list, got an associative array.'); + } + $this->expression1 = $expression1; + if (\is_array($expression2) && ! \array_is_list($expression2)) { + throw new \InvalidArgumentException('Expected $expression2 argument to be a list, got an associative array.'); + } + $this->expression2 = $expression2; } } diff --git a/src/Builder/Aggregation/ExpAggregation.php b/src/Builder/Aggregation/ExpAggregation.php index b319ea281..955b5a45d 100644 --- a/src/Builder/Aggregation/ExpAggregation.php +++ b/src/Builder/Aggregation/ExpAggregation.php @@ -9,7 +9,10 @@ use MongoDB\BSON\Decimal128; use MongoDB\BSON\Int64; use MongoDB\Builder\Encode; +use MongoDB\Builder\Expression\ResolvesToDecimal; use MongoDB\Builder\Expression\ResolvesToDouble; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Expression\ResolvesToLong; use MongoDB\Builder\Expression\ResolvesToNumber; /** @@ -22,14 +25,15 @@ class ExpAggregation implements ResolvesToDouble public const NAME = '$exp'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param Decimal128|Int64|ResolvesToNumber|float|int $exponent */ - public Decimal128|Int64|ResolvesToNumber|float|int $exponent; + /** @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $exponent */ + public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $exponent; /** - * @param Decimal128|Int64|ResolvesToNumber|float|int $exponent + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $exponent */ - public function __construct(Decimal128|Int64|ResolvesToNumber|float|int $exponent) - { + public function __construct( + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $exponent, + ) { $this->exponent = $exponent; } } diff --git a/src/Builder/Aggregation/ExpMovingAvgAggregation.php b/src/Builder/Aggregation/ExpMovingAvgAggregation.php index 6571c5fe6..6c3a5fc81 100644 --- a/src/Builder/Aggregation/ExpMovingAvgAggregation.php +++ b/src/Builder/Aggregation/ExpMovingAvgAggregation.php @@ -9,7 +9,10 @@ use MongoDB\BSON\Decimal128; use MongoDB\BSON\Int64; use MongoDB\Builder\Encode; +use MongoDB\Builder\Expression\ResolvesToDecimal; use MongoDB\Builder\Expression\ResolvesToDouble; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Expression\ResolvesToLong; use MongoDB\Builder\Expression\ResolvesToNumber; use MongoDB\Builder\Optional; @@ -24,15 +27,15 @@ class ExpMovingAvgAggregation implements ResolvesToDouble public const NAME = '$expMovingAvg'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param Decimal128|Int64|ResolvesToNumber|float|int $input */ - public Decimal128|Int64|ResolvesToNumber|float|int $input; + /** @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $input */ + public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $input; /** - * @param Int64|Optional|int $N 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. + * @param Optional|int $N 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: */ - public Int64|Optional|int $N; + public Optional|int $N; /** * @param Int64|Optional|float|int $alpha 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. @@ -41,16 +44,16 @@ class ExpMovingAvgAggregation implements ResolvesToDouble public Int64|Optional|float|int $alpha; /** - * @param Decimal128|Int64|ResolvesToNumber|float|int $input - * @param Int64|Optional|int $N 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. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $input + * @param Optional|int $N 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: * @param Int64|Optional|float|int $alpha 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. */ public function __construct( - Decimal128|Int64|ResolvesToNumber|float|int $input, - Int64|Optional|int $N = Optional::Undefined, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $input, + Optional|int $N = Optional::Undefined, Int64|Optional|float|int $alpha = Optional::Undefined, ) { $this->input = $input; diff --git a/src/Builder/Aggregation/FilterAggregation.php b/src/Builder/Aggregation/FilterAggregation.php index eac10ef0a..f1ff46d9e 100644 --- a/src/Builder/Aggregation/FilterAggregation.php +++ b/src/Builder/Aggregation/FilterAggregation.php @@ -6,10 +6,8 @@ namespace MongoDB\Builder\Aggregation; -use MongoDB\BSON\Int64; use MongoDB\BSON\PackedArray; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToArray; use MongoDB\Builder\Expression\ResolvesToBool; use MongoDB\Builder\Expression\ResolvesToInt; @@ -26,7 +24,7 @@ class FilterAggregation implements ResolvesToArray public const NAME = '$filter'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param BSONArray|PackedArray|ResolvesToArray|list $input */ + /** @param BSONArray|PackedArray|ResolvesToArray|array $input */ public PackedArray|ResolvesToArray|BSONArray|array $input; /** @param ResolvesToBool|bool $cond 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. */ @@ -36,27 +34,28 @@ class FilterAggregation implements ResolvesToArray public Optional|string $as; /** - * @param Int64|Optional|ResolvesToInt|int $limit 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. + * @param Optional|ResolvesToInt|int $limit 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. */ - public Int64|ResolvesToInt|Optional|int $limit; + public ResolvesToInt|Optional|int $limit; /** - * @param BSONArray|PackedArray|ResolvesToArray|list $input + * @param BSONArray|PackedArray|ResolvesToArray|array $input * @param ResolvesToBool|bool $cond 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. * @param Optional|non-empty-string $as 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. - * @param Int64|Optional|ResolvesToInt|int $limit 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. + * @param Optional|ResolvesToInt|int $limit 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. */ public function __construct( PackedArray|ResolvesToArray|BSONArray|array $input, ResolvesToBool|bool $cond, Optional|string $as = Optional::Undefined, - Int64|ResolvesToInt|Optional|int $limit = Optional::Undefined, + ResolvesToInt|Optional|int $limit = Optional::Undefined, ) { if (\is_array($input) && ! \array_is_list($input)) { throw new \InvalidArgumentException('Expected $input argument to be a list, got an associative array.'); } + $this->input = $input; $this->cond = $cond; $this->as = $as; diff --git a/src/Builder/Aggregation/FirstAggregation.php b/src/Builder/Aggregation/FirstAggregation.php index ab1f4477e..6cf21dcc8 100644 --- a/src/Builder/Aggregation/FirstAggregation.php +++ b/src/Builder/Aggregation/FirstAggregation.php @@ -6,8 +6,23 @@ namespace MongoDB\Builder\Aggregation; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Document; +use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; +use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; +use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; +use MongoDB\Builder\Expression\ResolvesToAny; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Type\AccumulatorInterface; +use MongoDB\Builder\Type\ExpressionInterface; +use MongoDB\Model\BSONArray; +use stdClass; /** * Returns the result of an expression for the first document in a group or window. @@ -15,19 +30,24 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/first/ */ -class FirstAggregation implements ExpressionInterface, AccumulatorInterface +class FirstAggregation implements ResolvesToAny, AccumulatorInterface { public const NAME = '$first'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param ExpressionInterface|mixed $expression */ - public mixed $expression; + /** @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression */ + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression; /** - * @param ExpressionInterface|mixed $expression + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression */ - public function __construct(mixed $expression) - { + public function __construct( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, + ) { + if (\is_array($expression) && ! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression argument to be a list, got an associative array.'); + } + $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/FirstNAggregation.php b/src/Builder/Aggregation/FirstNAggregation.php index 04f887bff..2c0340a89 100644 --- a/src/Builder/Aggregation/FirstNAggregation.php +++ b/src/Builder/Aggregation/FirstNAggregation.php @@ -6,12 +6,11 @@ namespace MongoDB\Builder\Aggregation; -use MongoDB\BSON\Int64; use MongoDB\BSON\PackedArray; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToArray; use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Type\AccumulatorInterface; use MongoDB\Model\BSONArray; /** @@ -24,21 +23,22 @@ class FirstNAggregation implements AccumulatorInterface public const NAME = '$firstN'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param BSONArray|PackedArray|ResolvesToArray|list $input An expression that resolves to the array from which to return n elements. */ + /** @param BSONArray|PackedArray|ResolvesToArray|array $input An expression that resolves to the array from which to return n elements. */ public PackedArray|ResolvesToArray|BSONArray|array $input; - /** @param Int64|ResolvesToInt|int $n An expression that resolves to a positive integer. The integer specifies the number of array elements that $firstN returns. */ - public Int64|ResolvesToInt|int $n; + /** @param ResolvesToInt|int $n An expression that resolves to a positive integer. The integer specifies the number of array elements that $firstN returns. */ + public ResolvesToInt|int $n; /** - * @param BSONArray|PackedArray|ResolvesToArray|list $input An expression that resolves to the array from which to return n elements. - * @param Int64|ResolvesToInt|int $n An expression that resolves to a positive integer. The integer specifies the number of array elements that $firstN returns. + * @param BSONArray|PackedArray|ResolvesToArray|array $input An expression that resolves to the array from which to return n elements. + * @param ResolvesToInt|int $n An expression that resolves to a positive integer. The integer specifies the number of array elements that $firstN returns. */ - public function __construct(PackedArray|ResolvesToArray|BSONArray|array $input, Int64|ResolvesToInt|int $n) + public function __construct(PackedArray|ResolvesToArray|BSONArray|array $input, ResolvesToInt|int $n) { if (\is_array($input) && ! \array_is_list($input)) { throw new \InvalidArgumentException('Expected $input argument to be a list, got an associative array.'); } + $this->input = $input; $this->n = $n; } diff --git a/src/Builder/Aggregation/FloorAggregation.php b/src/Builder/Aggregation/FloorAggregation.php index 679726e58..5c6bdf63a 100644 --- a/src/Builder/Aggregation/FloorAggregation.php +++ b/src/Builder/Aggregation/FloorAggregation.php @@ -9,7 +9,10 @@ use MongoDB\BSON\Decimal128; use MongoDB\BSON\Int64; use MongoDB\Builder\Encode; +use MongoDB\Builder\Expression\ResolvesToDecimal; +use MongoDB\Builder\Expression\ResolvesToDouble; use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Expression\ResolvesToLong; use MongoDB\Builder\Expression\ResolvesToNumber; /** @@ -22,14 +25,15 @@ class FloorAggregation implements ResolvesToInt public const NAME = '$floor'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param Decimal128|Int64|ResolvesToNumber|float|int $expression */ - public Decimal128|Int64|ResolvesToNumber|float|int $expression; + /** @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression */ + public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression; /** - * @param Decimal128|Int64|ResolvesToNumber|float|int $expression + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression */ - public function __construct(Decimal128|Int64|ResolvesToNumber|float|int $expression) - { + public function __construct( + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression, + ) { $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/FunctionAggregation.php b/src/Builder/Aggregation/FunctionAggregation.php index c79a1d21e..c4241081c 100644 --- a/src/Builder/Aggregation/FunctionAggregation.php +++ b/src/Builder/Aggregation/FunctionAggregation.php @@ -8,7 +8,7 @@ use MongoDB\BSON\PackedArray; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; +use MongoDB\Builder\Expression\ResolvesToAny; use MongoDB\Model\BSONArray; /** @@ -17,7 +17,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/function/ */ -class FunctionAggregation implements ExpressionInterface +class FunctionAggregation implements ResolvesToAny { public const NAME = '$function'; public const ENCODE = \MongoDB\Builder\Encode::Object; @@ -25,7 +25,7 @@ class FunctionAggregation implements ExpressionInterface /** @param non-empty-string $body The function definition. You can specify the function definition as either BSON type Code or String. */ public string $body; - /** @param BSONArray|PackedArray|list $args Arguments passed to the function body. If the body function does not take an argument, you can specify an empty array [ ]. */ + /** @param BSONArray|PackedArray|array $args Arguments passed to the function body. If the body function does not take an argument, you can specify an empty array [ ]. */ public PackedArray|BSONArray|array $args; /** @param non-empty-string $lang */ @@ -33,7 +33,7 @@ class FunctionAggregation implements ExpressionInterface /** * @param non-empty-string $body The function definition. You can specify the function definition as either BSON type Code or String. - * @param BSONArray|PackedArray|list $args Arguments passed to the function body. If the body function does not take an argument, you can specify an empty array [ ]. + * @param BSONArray|PackedArray|array $args Arguments passed to the function body. If the body function does not take an argument, you can specify an empty array [ ]. * @param non-empty-string $lang */ public function __construct(string $body, PackedArray|BSONArray|array $args, string $lang) @@ -42,6 +42,7 @@ public function __construct(string $body, PackedArray|BSONArray|array $args, str if (\is_array($args) && ! \array_is_list($args)) { throw new \InvalidArgumentException('Expected $args argument to be a list, got an associative array.'); } + $this->args = $args; $this->lang = $lang; } diff --git a/src/Builder/Aggregation/GetFieldAggregation.php b/src/Builder/Aggregation/GetFieldAggregation.php index dfe8fda27..0a86988db 100644 --- a/src/Builder/Aggregation/GetFieldAggregation.php +++ b/src/Builder/Aggregation/GetFieldAggregation.php @@ -6,9 +6,23 @@ namespace MongoDB\Builder\Aggregation; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Document; +use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; +use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; +use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; +use MongoDB\Builder\Expression\ResolvesToAny; +use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Optional; +use MongoDB\Builder\Type\ExpressionInterface; +use MongoDB\Model\BSONArray; +use stdClass; /** * 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 ($). @@ -16,7 +30,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/getField/ */ -class GetFieldAggregation implements ExpressionInterface +class GetFieldAggregation implements ResolvesToAny { public const NAME = '$getField'; public const ENCODE = \MongoDB\Builder\Encode::Object; @@ -28,20 +42,26 @@ class GetFieldAggregation implements ExpressionInterface public string $field; /** - * @param ExpressionInterface|Optional|mixed $input Default: $$CURRENT + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|Optional|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $input 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). */ - public mixed $input; + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|Optional|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $input; /** * @param non-empty-string $field 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. - * @param ExpressionInterface|Optional|mixed $input Default: $$CURRENT + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|Optional|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $input 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). */ - public function __construct(string $field, mixed $input = Optional::Undefined) - { + public function __construct( + string $field, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|Optional|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $input = Optional::Undefined, + ) { $this->field = $field; + if (\is_array($input) && ! \array_is_list($input)) { + throw new \InvalidArgumentException('Expected $input argument to be a list, got an associative array.'); + } + $this->input = $input; } } diff --git a/src/Builder/Aggregation/GtAggregation.php b/src/Builder/Aggregation/GtAggregation.php index 7615df4a8..473046050 100644 --- a/src/Builder/Aggregation/GtAggregation.php +++ b/src/Builder/Aggregation/GtAggregation.php @@ -6,9 +6,22 @@ namespace MongoDB\Builder\Aggregation; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Document; +use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; +use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; +use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToBool; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Type\ExpressionInterface; +use MongoDB\Model\BSONArray; +use stdClass; /** * Returns true if the first value is greater than the second. @@ -20,19 +33,29 @@ class GtAggregation implements ResolvesToBool public const NAME = '$gt'; public const ENCODE = \MongoDB\Builder\Encode::Array; - /** @param ExpressionInterface|mixed $expression1 */ - public mixed $expression1; + /** @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression1 */ + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression1; - /** @param ExpressionInterface|mixed $expression2 */ - public mixed $expression2; + /** @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression2 */ + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression2; /** - * @param ExpressionInterface|mixed $expression1 - * @param ExpressionInterface|mixed $expression2 + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression1 + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression2 */ - public function __construct(mixed $expression1, mixed $expression2) - { + public function __construct( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression1, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression2, + ) { + if (\is_array($expression1) && ! \array_is_list($expression1)) { + throw new \InvalidArgumentException('Expected $expression1 argument to be a list, got an associative array.'); + } + $this->expression1 = $expression1; + if (\is_array($expression2) && ! \array_is_list($expression2)) { + throw new \InvalidArgumentException('Expected $expression2 argument to be a list, got an associative array.'); + } + $this->expression2 = $expression2; } } diff --git a/src/Builder/Aggregation/GteAggregation.php b/src/Builder/Aggregation/GteAggregation.php index 05f9049a9..43e709fce 100644 --- a/src/Builder/Aggregation/GteAggregation.php +++ b/src/Builder/Aggregation/GteAggregation.php @@ -6,9 +6,22 @@ namespace MongoDB\Builder\Aggregation; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Document; +use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; +use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; +use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToBool; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Type\ExpressionInterface; +use MongoDB\Model\BSONArray; +use stdClass; /** * Returns true if the first value is greater than or equal to the second. @@ -20,19 +33,29 @@ class GteAggregation implements ResolvesToBool public const NAME = '$gte'; public const ENCODE = \MongoDB\Builder\Encode::Array; - /** @param ExpressionInterface|mixed $expression1 */ - public mixed $expression1; + /** @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression1 */ + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression1; - /** @param ExpressionInterface|mixed $expression2 */ - public mixed $expression2; + /** @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression2 */ + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression2; /** - * @param ExpressionInterface|mixed $expression1 - * @param ExpressionInterface|mixed $expression2 + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression1 + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression2 */ - public function __construct(mixed $expression1, mixed $expression2) - { + public function __construct( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression1, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression2, + ) { + if (\is_array($expression1) && ! \array_is_list($expression1)) { + throw new \InvalidArgumentException('Expected $expression1 argument to be a list, got an associative array.'); + } + $this->expression1 = $expression1; + if (\is_array($expression2) && ! \array_is_list($expression2)) { + throw new \InvalidArgumentException('Expected $expression2 argument to be a list, got an associative array.'); + } + $this->expression2 = $expression2; } } diff --git a/src/Builder/Aggregation/HourAggregation.php b/src/Builder/Aggregation/HourAggregation.php index be068fbbb..cb44ef497 100644 --- a/src/Builder/Aggregation/HourAggregation.php +++ b/src/Builder/Aggregation/HourAggregation.php @@ -6,9 +6,8 @@ namespace MongoDB\Builder\Aggregation; -use DateTimeInterface; -use MongoDB\BSON\Int64; use MongoDB\BSON\ObjectId; +use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToDate; @@ -28,18 +27,18 @@ class HourAggregation implements ResolvesToInt public const NAME = '$hour'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ - public DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; + /** @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ + public ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; /** @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public ResolvesToString|Optional|string $timezone; /** - * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public function __construct( - DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|Optional|string $timezone = Optional::Undefined, ) { $this->date = $date; diff --git a/src/Builder/Aggregation/IfNullAggregation.php b/src/Builder/Aggregation/IfNullAggregation.php index 2cf306191..52d949e7d 100644 --- a/src/Builder/Aggregation/IfNullAggregation.php +++ b/src/Builder/Aggregation/IfNullAggregation.php @@ -6,33 +6,48 @@ namespace MongoDB\Builder\Aggregation; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Document; +use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; +use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; +use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; +use MongoDB\Builder\Expression\ResolvesToAny; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Type\ExpressionInterface; +use MongoDB\Model\BSONArray; +use stdClass; /** * 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. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/ifNull/ */ -class IfNullAggregation implements ExpressionInterface +class IfNullAggregation implements ResolvesToAny { public const NAME = '$ifNull'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param list ...$expression */ + /** @param list ...$expression */ public array $expression; /** - * @param ExpressionInterface|mixed ...$expression + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass ...$expression * @no-named-arguments */ - public function __construct(mixed ...$expression) - { + public function __construct( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string ...$expression, + ) { if (\count($expression) < 1) { throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); } if (! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression arguments to be a list of ExpressionInterface|mixed, named arguments are not supported'); + throw new \InvalidArgumentException('Expected $expression arguments to be a list (array), named arguments are not supported'); } $this->expression = $expression; } diff --git a/src/Builder/Aggregation/InAggregation.php b/src/Builder/Aggregation/InAggregation.php index 4a07966c8..a35e185bc 100644 --- a/src/Builder/Aggregation/InAggregation.php +++ b/src/Builder/Aggregation/InAggregation.php @@ -6,12 +6,23 @@ namespace MongoDB\Builder\Aggregation; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Document; +use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; +use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToArray; use MongoDB\Builder\Expression\ResolvesToBool; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Type\ExpressionInterface; use MongoDB\Model\BSONArray; +use stdClass; /** * Returns a boolean indicating whether a specified value is in an array. @@ -23,22 +34,29 @@ class InAggregation implements ResolvesToBool public const NAME = '$in'; public const ENCODE = \MongoDB\Builder\Encode::Array; - /** @param ExpressionInterface|mixed $expression Any valid expression expression. */ - public mixed $expression; + /** @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression Any valid expression expression. */ + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression; - /** @param BSONArray|PackedArray|ResolvesToArray|list $array Any valid expression that resolves to an array. */ + /** @param BSONArray|PackedArray|ResolvesToArray|array $array Any valid expression that resolves to an array. */ public PackedArray|ResolvesToArray|BSONArray|array $array; /** - * @param ExpressionInterface|mixed $expression Any valid expression expression. - * @param BSONArray|PackedArray|ResolvesToArray|list $array Any valid expression that resolves to an array. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression Any valid expression expression. + * @param BSONArray|PackedArray|ResolvesToArray|array $array Any valid expression that resolves to an array. */ - public function __construct(mixed $expression, PackedArray|ResolvesToArray|BSONArray|array $array) - { + public function __construct( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, + PackedArray|ResolvesToArray|BSONArray|array $array, + ) { + if (\is_array($expression) && ! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression argument to be a list, got an associative array.'); + } + $this->expression = $expression; if (\is_array($array) && ! \array_is_list($array)) { throw new \InvalidArgumentException('Expected $array argument to be a list, got an associative array.'); } + $this->array = $array; } } diff --git a/src/Builder/Aggregation/IndexOfArrayAggregation.php b/src/Builder/Aggregation/IndexOfArrayAggregation.php index 4cfc36de6..6f8ec09bb 100644 --- a/src/Builder/Aggregation/IndexOfArrayAggregation.php +++ b/src/Builder/Aggregation/IndexOfArrayAggregation.php @@ -6,12 +6,23 @@ namespace MongoDB\Builder\Aggregation; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Document; use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; +use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; +use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Expression\ResolvesToString; use MongoDB\Builder\Optional; +use MongoDB\Builder\Type\ExpressionInterface; +use MongoDB\Model\BSONArray; +use stdClass; /** * Searches an array for an occurrence of a specified value and returns the array index of the first occurrence. Array indexes start at zero. @@ -30,38 +41,42 @@ class IndexOfArrayAggregation implements ResolvesToInt */ public ResolvesToString|string $array; - /** @param ExpressionInterface|mixed $search */ - public mixed $search; + /** @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $search */ + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $search; /** - * @param Int64|Optional|ResolvesToInt|int $start 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. + * @param Optional|ResolvesToInt|int $start 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. */ - public Int64|ResolvesToInt|Optional|int $start; + public ResolvesToInt|Optional|int $start; /** - * @param Int64|Optional|ResolvesToInt|int $end 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. + * @param Optional|ResolvesToInt|int $end 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. */ - public Int64|ResolvesToInt|Optional|int $end; + public ResolvesToInt|Optional|int $end; /** * @param ResolvesToString|non-empty-string $array 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. - * @param ExpressionInterface|mixed $search - * @param Int64|Optional|ResolvesToInt|int $start 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. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $search + * @param Optional|ResolvesToInt|int $start 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. - * @param Int64|Optional|ResolvesToInt|int $end 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. + * @param Optional|ResolvesToInt|int $end 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. */ public function __construct( ResolvesToString|string $array, - mixed $search, - Int64|ResolvesToInt|Optional|int $start = Optional::Undefined, - Int64|ResolvesToInt|Optional|int $end = Optional::Undefined, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $search, + ResolvesToInt|Optional|int $start = Optional::Undefined, + ResolvesToInt|Optional|int $end = Optional::Undefined, ) { $this->array = $array; + if (\is_array($search) && ! \array_is_list($search)) { + throw new \InvalidArgumentException('Expected $search argument to be a list, got an associative array.'); + } + $this->search = $search; $this->start = $start; $this->end = $end; diff --git a/src/Builder/Aggregation/IndexOfBytesAggregation.php b/src/Builder/Aggregation/IndexOfBytesAggregation.php index 05dafd4be..fa19ae992 100644 --- a/src/Builder/Aggregation/IndexOfBytesAggregation.php +++ b/src/Builder/Aggregation/IndexOfBytesAggregation.php @@ -6,7 +6,6 @@ namespace MongoDB\Builder\Aggregation; -use MongoDB\BSON\Int64; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Expression\ResolvesToString; @@ -33,32 +32,32 @@ class IndexOfBytesAggregation implements ResolvesToInt public ResolvesToString|string $substring; /** - * @param Int64|Optional|ResolvesToInt|int $start 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. + * @param Optional|ResolvesToInt|int $start 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. */ - public Int64|ResolvesToInt|Optional|int $start; + public ResolvesToInt|Optional|int $start; /** - * @param Int64|Optional|ResolvesToInt|int $end 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. + * @param Optional|ResolvesToInt|int $end 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. */ - public Int64|ResolvesToInt|Optional|int $end; + public ResolvesToInt|Optional|int $end; /** * @param ResolvesToString|non-empty-string $string 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. * @param ResolvesToString|non-empty-string $substring Can be any valid expression as long as it resolves to a string. - * @param Int64|Optional|ResolvesToInt|int $start 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. + * @param Optional|ResolvesToInt|int $start 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. - * @param Int64|Optional|ResolvesToInt|int $end 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. + * @param Optional|ResolvesToInt|int $end 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. */ public function __construct( ResolvesToString|string $string, ResolvesToString|string $substring, - Int64|ResolvesToInt|Optional|int $start = Optional::Undefined, - Int64|ResolvesToInt|Optional|int $end = Optional::Undefined, + ResolvesToInt|Optional|int $start = Optional::Undefined, + ResolvesToInt|Optional|int $end = Optional::Undefined, ) { $this->string = $string; $this->substring = $substring; diff --git a/src/Builder/Aggregation/IndexOfCPAggregation.php b/src/Builder/Aggregation/IndexOfCPAggregation.php index 81a1c4ba7..78b9dd331 100644 --- a/src/Builder/Aggregation/IndexOfCPAggregation.php +++ b/src/Builder/Aggregation/IndexOfCPAggregation.php @@ -6,7 +6,6 @@ namespace MongoDB\Builder\Aggregation; -use MongoDB\BSON\Int64; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Expression\ResolvesToString; @@ -33,32 +32,32 @@ class IndexOfCPAggregation implements ResolvesToInt public ResolvesToString|string $substring; /** - * @param Int64|Optional|ResolvesToInt|int $start 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. + * @param Optional|ResolvesToInt|int $start 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. */ - public Int64|ResolvesToInt|Optional|int $start; + public ResolvesToInt|Optional|int $start; /** - * @param Int64|Optional|ResolvesToInt|int $end 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. + * @param Optional|ResolvesToInt|int $end 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. */ - public Int64|ResolvesToInt|Optional|int $end; + public ResolvesToInt|Optional|int $end; /** * @param ResolvesToString|non-empty-string $string 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. * @param ResolvesToString|non-empty-string $substring Can be any valid expression as long as it resolves to a string. - * @param Int64|Optional|ResolvesToInt|int $start 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. + * @param Optional|ResolvesToInt|int $start 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. - * @param Int64|Optional|ResolvesToInt|int $end 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. + * @param Optional|ResolvesToInt|int $end 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. */ public function __construct( ResolvesToString|string $string, ResolvesToString|string $substring, - Int64|ResolvesToInt|Optional|int $start = Optional::Undefined, - Int64|ResolvesToInt|Optional|int $end = Optional::Undefined, + ResolvesToInt|Optional|int $start = Optional::Undefined, + ResolvesToInt|Optional|int $end = Optional::Undefined, ) { $this->string = $string; $this->substring = $substring; diff --git a/src/Builder/Aggregation/IntegralAggregation.php b/src/Builder/Aggregation/IntegralAggregation.php index 831c1db9c..8f39d9f73 100644 --- a/src/Builder/Aggregation/IntegralAggregation.php +++ b/src/Builder/Aggregation/IntegralAggregation.php @@ -6,7 +6,6 @@ namespace MongoDB\Builder\Aggregation; -use DateTimeInterface; use MongoDB\BSON\Decimal128; use MongoDB\BSON\Int64; use MongoDB\BSON\UTCDateTime; @@ -14,6 +13,8 @@ use MongoDB\Builder\Expression\ResolvesToDate; use MongoDB\Builder\Expression\ResolvesToDecimal; use MongoDB\Builder\Expression\ResolvesToDouble; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Expression\ResolvesToLong; use MongoDB\Builder\Expression\ResolvesToNumber; use MongoDB\Builder\Expression\ResolvesToString; use MongoDB\Builder\Optional; @@ -29,8 +30,8 @@ class IntegralAggregation implements ResolvesToDouble, ResolvesToDecimal public const NAME = '$integral'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int $input */ - public DateTimeInterface|Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int $input; + /** @param Decimal128|Int64|ResolvesToDate|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|UTCDateTime|float|int $input */ + public Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $input; /** * @param Optional|ResolvesToString|non-empty-string $unit A string that specifies the time unit. Use one of these strings: "week", "day","hour", "minute", "second", "millisecond". @@ -39,12 +40,12 @@ class IntegralAggregation implements ResolvesToDouble, ResolvesToDecimal public ResolvesToString|Optional|string $unit; /** - * @param DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int $input + * @param Decimal128|Int64|ResolvesToDate|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|UTCDateTime|float|int $input * @param Optional|ResolvesToString|non-empty-string $unit 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. */ public function __construct( - DateTimeInterface|Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int $input, + Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $input, ResolvesToString|Optional|string $unit = Optional::Undefined, ) { $this->input = $input; diff --git a/src/Builder/Aggregation/IsArrayAggregation.php b/src/Builder/Aggregation/IsArrayAggregation.php index f10c40b3c..990759f0d 100644 --- a/src/Builder/Aggregation/IsArrayAggregation.php +++ b/src/Builder/Aggregation/IsArrayAggregation.php @@ -6,9 +6,22 @@ namespace MongoDB\Builder\Aggregation; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Document; +use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; +use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; +use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToBool; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Type\ExpressionInterface; +use MongoDB\Model\BSONArray; +use stdClass; /** * Determines if the operand is an array. Returns a boolean. @@ -20,20 +33,21 @@ class IsArrayAggregation implements ResolvesToBool public const NAME = '$isArray'; public const ENCODE = \MongoDB\Builder\Encode::Array; - /** @param list ...$expression */ + /** @param list ...$expression */ public array $expression; /** - * @param ExpressionInterface|mixed ...$expression + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass ...$expression * @no-named-arguments */ - public function __construct(mixed ...$expression) - { + public function __construct( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string ...$expression, + ) { if (\count($expression) < 1) { throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); } if (! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression arguments to be a list of ExpressionInterface|mixed, named arguments are not supported'); + throw new \InvalidArgumentException('Expected $expression arguments to be a list (array), named arguments are not supported'); } $this->expression = $expression; } diff --git a/src/Builder/Aggregation/IsNumberAggregation.php b/src/Builder/Aggregation/IsNumberAggregation.php index b741bd1af..aa63d1af8 100644 --- a/src/Builder/Aggregation/IsNumberAggregation.php +++ b/src/Builder/Aggregation/IsNumberAggregation.php @@ -6,9 +6,22 @@ namespace MongoDB\Builder\Aggregation; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Document; +use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; +use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; +use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToBool; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Type\ExpressionInterface; +use MongoDB\Model\BSONArray; +use stdClass; /** * Returns boolean true if the specified expression resolves to an integer, decimal, double, or long. @@ -22,20 +35,21 @@ class IsNumberAggregation implements ResolvesToBool public const NAME = '$isNumber'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param list ...$expression */ + /** @param list ...$expression */ public array $expression; /** - * @param ExpressionInterface|mixed ...$expression + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass ...$expression * @no-named-arguments */ - public function __construct(mixed ...$expression) - { + public function __construct( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string ...$expression, + ) { if (\count($expression) < 1) { throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); } if (! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression arguments to be a list of ExpressionInterface|mixed, named arguments are not supported'); + throw new \InvalidArgumentException('Expected $expression arguments to be a list (array), named arguments are not supported'); } $this->expression = $expression; } diff --git a/src/Builder/Aggregation/IsoDayOfWeekAggregation.php b/src/Builder/Aggregation/IsoDayOfWeekAggregation.php index 45fc7d1c5..42f604c39 100644 --- a/src/Builder/Aggregation/IsoDayOfWeekAggregation.php +++ b/src/Builder/Aggregation/IsoDayOfWeekAggregation.php @@ -6,9 +6,8 @@ namespace MongoDB\Builder\Aggregation; -use DateTimeInterface; -use MongoDB\BSON\Int64; use MongoDB\BSON\ObjectId; +use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToDate; @@ -28,18 +27,18 @@ class IsoDayOfWeekAggregation implements ResolvesToInt public const NAME = '$isoDayOfWeek'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ - public DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; + /** @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ + public ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; /** @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public ResolvesToString|Optional|string $timezone; /** - * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public function __construct( - DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|Optional|string $timezone = Optional::Undefined, ) { $this->date = $date; diff --git a/src/Builder/Aggregation/IsoWeekAggregation.php b/src/Builder/Aggregation/IsoWeekAggregation.php index 518ff9075..a66db5585 100644 --- a/src/Builder/Aggregation/IsoWeekAggregation.php +++ b/src/Builder/Aggregation/IsoWeekAggregation.php @@ -6,9 +6,8 @@ namespace MongoDB\Builder\Aggregation; -use DateTimeInterface; -use MongoDB\BSON\Int64; use MongoDB\BSON\ObjectId; +use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToDate; @@ -28,18 +27,18 @@ class IsoWeekAggregation implements ResolvesToInt public const NAME = '$isoWeek'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ - public DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; + /** @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ + public ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; /** @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public ResolvesToString|Optional|string $timezone; /** - * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public function __construct( - DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|Optional|string $timezone = Optional::Undefined, ) { $this->date = $date; diff --git a/src/Builder/Aggregation/IsoWeekYearAggregation.php b/src/Builder/Aggregation/IsoWeekYearAggregation.php index 730b39cb3..8eb7a1c97 100644 --- a/src/Builder/Aggregation/IsoWeekYearAggregation.php +++ b/src/Builder/Aggregation/IsoWeekYearAggregation.php @@ -6,9 +6,8 @@ namespace MongoDB\Builder\Aggregation; -use DateTimeInterface; -use MongoDB\BSON\Int64; use MongoDB\BSON\ObjectId; +use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToDate; @@ -28,18 +27,18 @@ class IsoWeekYearAggregation implements ResolvesToInt public const NAME = '$isoWeekYear'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ - public DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; + /** @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ + public ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; /** @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public ResolvesToString|Optional|string $timezone; /** - * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public function __construct( - DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|Optional|string $timezone = Optional::Undefined, ) { $this->date = $date; diff --git a/src/Builder/Aggregation/LastAggregation.php b/src/Builder/Aggregation/LastAggregation.php index fc173461e..0b4e43ee4 100644 --- a/src/Builder/Aggregation/LastAggregation.php +++ b/src/Builder/Aggregation/LastAggregation.php @@ -6,8 +6,23 @@ namespace MongoDB\Builder\Aggregation; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Document; +use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; +use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; +use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; +use MongoDB\Builder\Expression\ResolvesToAny; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Type\AccumulatorInterface; +use MongoDB\Builder\Type\ExpressionInterface; +use MongoDB\Model\BSONArray; +use stdClass; /** * Returns the result of an expression for the last document in a group or window. @@ -15,19 +30,24 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/last/ */ -class LastAggregation implements ExpressionInterface, AccumulatorInterface +class LastAggregation implements ResolvesToAny, AccumulatorInterface { public const NAME = '$last'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param ExpressionInterface|mixed $expression */ - public mixed $expression; + /** @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression */ + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression; /** - * @param ExpressionInterface|mixed $expression + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression */ - public function __construct(mixed $expression) - { + public function __construct( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, + ) { + if (\is_array($expression) && ! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression argument to be a list, got an associative array.'); + } + $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/LastNAggregation.php b/src/Builder/Aggregation/LastNAggregation.php index e76ac8c25..bb119667e 100644 --- a/src/Builder/Aggregation/LastNAggregation.php +++ b/src/Builder/Aggregation/LastNAggregation.php @@ -6,10 +6,8 @@ namespace MongoDB\Builder\Aggregation; -use MongoDB\BSON\Int64; use MongoDB\BSON\PackedArray; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToArray; use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Model\BSONArray; @@ -24,21 +22,22 @@ class LastNAggregation implements ResolvesToArray public const NAME = '$lastN'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param BSONArray|PackedArray|ResolvesToArray|list $input An expression that resolves to the array from which to return n elements. */ + /** @param BSONArray|PackedArray|ResolvesToArray|array $input An expression that resolves to the array from which to return n elements. */ public PackedArray|ResolvesToArray|BSONArray|array $input; - /** @param Int64|ResolvesToInt|int $n An expression that resolves to a positive integer. The integer specifies the number of array elements that $firstN returns. */ - public Int64|ResolvesToInt|int $n; + /** @param ResolvesToInt|int $n An expression that resolves to a positive integer. The integer specifies the number of array elements that $firstN returns. */ + public ResolvesToInt|int $n; /** - * @param BSONArray|PackedArray|ResolvesToArray|list $input An expression that resolves to the array from which to return n elements. - * @param Int64|ResolvesToInt|int $n An expression that resolves to a positive integer. The integer specifies the number of array elements that $firstN returns. + * @param BSONArray|PackedArray|ResolvesToArray|array $input An expression that resolves to the array from which to return n elements. + * @param ResolvesToInt|int $n An expression that resolves to a positive integer. The integer specifies the number of array elements that $firstN returns. */ - public function __construct(PackedArray|ResolvesToArray|BSONArray|array $input, Int64|ResolvesToInt|int $n) + public function __construct(PackedArray|ResolvesToArray|BSONArray|array $input, ResolvesToInt|int $n) { if (\is_array($input) && ! \array_is_list($input)) { throw new \InvalidArgumentException('Expected $input argument to be a list, got an associative array.'); } + $this->input = $input; $this->n = $n; } diff --git a/src/Builder/Aggregation/LetAggregation.php b/src/Builder/Aggregation/LetAggregation.php index f0899f33f..19a71eb7d 100644 --- a/src/Builder/Aggregation/LetAggregation.php +++ b/src/Builder/Aggregation/LetAggregation.php @@ -6,10 +6,21 @@ namespace MongoDB\Builder\Aggregation; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Decimal128; use MongoDB\BSON\Document; +use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; +use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; +use MongoDB\Builder\Expression\ResolvesToAny; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Type\ExpressionInterface; +use MongoDB\Model\BSONArray; use stdClass; /** @@ -18,7 +29,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/let/ */ -class LetAggregation implements ExpressionInterface +class LetAggregation implements ResolvesToAny { public const NAME = '$let'; public const ENCODE = \MongoDB\Builder\Encode::Object; @@ -29,17 +40,23 @@ class LetAggregation implements ExpressionInterface */ public Document|Serializable|stdClass|array $vars; - /** @param ExpressionInterface|mixed $in The expression to evaluate. */ - public mixed $in; + /** @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $in The expression to evaluate. */ + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $in; /** * @param Document|Serializable|array|stdClass $vars 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. - * @param ExpressionInterface|mixed $in The expression to evaluate. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $in The expression to evaluate. */ - public function __construct(Document|Serializable|stdClass|array $vars, mixed $in) - { + public function __construct( + Document|Serializable|stdClass|array $vars, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $in, + ) { $this->vars = $vars; + if (\is_array($in) && ! \array_is_list($in)) { + throw new \InvalidArgumentException('Expected $in argument to be a list, got an associative array.'); + } + $this->in = $in; } } diff --git a/src/Builder/Aggregation/LinearFillAggregation.php b/src/Builder/Aggregation/LinearFillAggregation.php index 875eff33b..bf246f30c 100644 --- a/src/Builder/Aggregation/LinearFillAggregation.php +++ b/src/Builder/Aggregation/LinearFillAggregation.php @@ -9,6 +9,10 @@ use MongoDB\BSON\Decimal128; use MongoDB\BSON\Int64; use MongoDB\Builder\Encode; +use MongoDB\Builder\Expression\ResolvesToDecimal; +use MongoDB\Builder\Expression\ResolvesToDouble; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Expression\ResolvesToLong; use MongoDB\Builder\Expression\ResolvesToNumber; /** @@ -23,14 +27,15 @@ class LinearFillAggregation implements ResolvesToNumber public const NAME = '$linearFill'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param Decimal128|Int64|ResolvesToNumber|float|int $expression */ - public Decimal128|Int64|ResolvesToNumber|float|int $expression; + /** @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression */ + public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression; /** - * @param Decimal128|Int64|ResolvesToNumber|float|int $expression + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression */ - public function __construct(Decimal128|Int64|ResolvesToNumber|float|int $expression) - { + public function __construct( + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression, + ) { $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/LiteralAggregation.php b/src/Builder/Aggregation/LiteralAggregation.php index 722637a76..615803b01 100644 --- a/src/Builder/Aggregation/LiteralAggregation.php +++ b/src/Builder/Aggregation/LiteralAggregation.php @@ -6,27 +6,45 @@ namespace MongoDB\Builder\Aggregation; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Document; +use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; +use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; +use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; +use MongoDB\Builder\Expression\ResolvesToAny; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Model\BSONArray; +use stdClass; /** * 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. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/literal/ */ -class LiteralAggregation implements ExpressionInterface +class LiteralAggregation implements ResolvesToAny { public const NAME = '$literal'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param mixed $value If the value is an expression, $literal does not evaluate the expression but instead returns the unparsed expression. */ - public mixed $value; + /** @param BSONArray|Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $value If the value is an expression, $literal does not evaluate the expression but instead returns the unparsed expression. */ + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|BSONArray|stdClass|array|bool|float|int|null|string $value; /** - * @param mixed $value If the value is an expression, $literal does not evaluate the expression but instead returns the unparsed expression. + * @param BSONArray|Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $value If the value is an expression, $literal does not evaluate the expression but instead returns the unparsed expression. */ - public function __construct(mixed $value) - { + public function __construct( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|BSONArray|stdClass|array|bool|float|int|null|string $value, + ) { + if (\is_array($value) && ! \array_is_list($value)) { + throw new \InvalidArgumentException('Expected $value argument to be a list, got an associative array.'); + } + $this->value = $value; } } diff --git a/src/Builder/Aggregation/LnAggregation.php b/src/Builder/Aggregation/LnAggregation.php index eb146c22a..28a8659f4 100644 --- a/src/Builder/Aggregation/LnAggregation.php +++ b/src/Builder/Aggregation/LnAggregation.php @@ -9,7 +9,10 @@ use MongoDB\BSON\Decimal128; use MongoDB\BSON\Int64; use MongoDB\Builder\Encode; +use MongoDB\Builder\Expression\ResolvesToDecimal; use MongoDB\Builder\Expression\ResolvesToDouble; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Expression\ResolvesToLong; use MongoDB\Builder\Expression\ResolvesToNumber; /** @@ -23,14 +26,15 @@ class LnAggregation implements ResolvesToDouble public const NAME = '$ln'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param Decimal128|Int64|ResolvesToNumber|float|int $number Any valid expression as long as it resolves to a non-negative number. For more information on expressions, see Expressions. */ - public Decimal128|Int64|ResolvesToNumber|float|int $number; + /** @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $number Any valid expression as long as it resolves to a non-negative number. For more information on expressions, see Expressions. */ + public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $number; /** - * @param Decimal128|Int64|ResolvesToNumber|float|int $number Any valid expression as long as it resolves to a non-negative number. For more information on expressions, see Expressions. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $number Any valid expression as long as it resolves to a non-negative number. For more information on expressions, see Expressions. */ - public function __construct(Decimal128|Int64|ResolvesToNumber|float|int $number) - { + public function __construct( + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $number, + ) { $this->number = $number; } } diff --git a/src/Builder/Aggregation/LocfAggregation.php b/src/Builder/Aggregation/LocfAggregation.php index 05df29310..982658c3a 100644 --- a/src/Builder/Aggregation/LocfAggregation.php +++ b/src/Builder/Aggregation/LocfAggregation.php @@ -6,8 +6,22 @@ namespace MongoDB\Builder\Aggregation; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Document; +use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; +use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; +use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; +use MongoDB\Builder\Expression\ResolvesToAny; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Type\ExpressionInterface; +use MongoDB\Model\BSONArray; +use stdClass; /** * Last observation carried forward. Sets values for null and missing fields in a window to the last non-null value for the field. @@ -16,19 +30,24 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/locf/ */ -class LocfAggregation implements ExpressionInterface +class LocfAggregation implements ResolvesToAny { public const NAME = '$locf'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param ExpressionInterface|mixed $expression */ - public mixed $expression; + /** @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression */ + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression; /** - * @param ExpressionInterface|mixed $expression + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression */ - public function __construct(mixed $expression) - { + public function __construct( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, + ) { + if (\is_array($expression) && ! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression argument to be a list, got an associative array.'); + } + $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/Log10Aggregation.php b/src/Builder/Aggregation/Log10Aggregation.php index fd7c1499b..54a935e61 100644 --- a/src/Builder/Aggregation/Log10Aggregation.php +++ b/src/Builder/Aggregation/Log10Aggregation.php @@ -9,7 +9,10 @@ use MongoDB\BSON\Decimal128; use MongoDB\BSON\Int64; use MongoDB\Builder\Encode; +use MongoDB\Builder\Expression\ResolvesToDecimal; use MongoDB\Builder\Expression\ResolvesToDouble; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Expression\ResolvesToLong; use MongoDB\Builder\Expression\ResolvesToNumber; /** @@ -22,14 +25,15 @@ class Log10Aggregation implements ResolvesToDouble public const NAME = '$log10'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param Decimal128|Int64|ResolvesToNumber|float|int $number Any valid expression as long as it resolves to a non-negative number. */ - public Decimal128|Int64|ResolvesToNumber|float|int $number; + /** @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $number Any valid expression as long as it resolves to a non-negative number. */ + public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $number; /** - * @param Decimal128|Int64|ResolvesToNumber|float|int $number Any valid expression as long as it resolves to a non-negative number. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $number Any valid expression as long as it resolves to a non-negative number. */ - public function __construct(Decimal128|Int64|ResolvesToNumber|float|int $number) - { + public function __construct( + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $number, + ) { $this->number = $number; } } diff --git a/src/Builder/Aggregation/LogAggregation.php b/src/Builder/Aggregation/LogAggregation.php index 374d556bc..d3315164e 100644 --- a/src/Builder/Aggregation/LogAggregation.php +++ b/src/Builder/Aggregation/LogAggregation.php @@ -9,7 +9,10 @@ use MongoDB\BSON\Decimal128; use MongoDB\BSON\Int64; use MongoDB\Builder\Encode; +use MongoDB\Builder\Expression\ResolvesToDecimal; use MongoDB\Builder\Expression\ResolvesToDouble; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Expression\ResolvesToLong; use MongoDB\Builder\Expression\ResolvesToNumber; /** @@ -22,19 +25,19 @@ class LogAggregation implements ResolvesToDouble public const NAME = '$log'; public const ENCODE = \MongoDB\Builder\Encode::Array; - /** @param Decimal128|Int64|ResolvesToNumber|float|int $number Any valid expression as long as it resolves to a non-negative number. */ - public Decimal128|Int64|ResolvesToNumber|float|int $number; + /** @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $number Any valid expression as long as it resolves to a non-negative number. */ + public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $number; - /** @param Decimal128|Int64|ResolvesToNumber|float|int $base Any valid expression as long as it resolves to a positive number greater than 1. */ - public Decimal128|Int64|ResolvesToNumber|float|int $base; + /** @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $base Any valid expression as long as it resolves to a positive number greater than 1. */ + public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $base; /** - * @param Decimal128|Int64|ResolvesToNumber|float|int $number Any valid expression as long as it resolves to a non-negative number. - * @param Decimal128|Int64|ResolvesToNumber|float|int $base Any valid expression as long as it resolves to a positive number greater than 1. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $number Any valid expression as long as it resolves to a non-negative number. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $base Any valid expression as long as it resolves to a positive number greater than 1. */ public function __construct( - Decimal128|Int64|ResolvesToNumber|float|int $number, - Decimal128|Int64|ResolvesToNumber|float|int $base, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $number, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $base, ) { $this->number = $number; $this->base = $base; diff --git a/src/Builder/Aggregation/LtAggregation.php b/src/Builder/Aggregation/LtAggregation.php index b248153b6..8a8e84808 100644 --- a/src/Builder/Aggregation/LtAggregation.php +++ b/src/Builder/Aggregation/LtAggregation.php @@ -6,9 +6,22 @@ namespace MongoDB\Builder\Aggregation; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Document; +use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; +use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; +use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToBool; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Type\ExpressionInterface; +use MongoDB\Model\BSONArray; +use stdClass; /** * Returns true if the first value is less than the second. @@ -20,19 +33,29 @@ class LtAggregation implements ResolvesToBool public const NAME = '$lt'; public const ENCODE = \MongoDB\Builder\Encode::Array; - /** @param ExpressionInterface|mixed $expression1 */ - public mixed $expression1; + /** @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression1 */ + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression1; - /** @param ExpressionInterface|mixed $expression2 */ - public mixed $expression2; + /** @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression2 */ + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression2; /** - * @param ExpressionInterface|mixed $expression1 - * @param ExpressionInterface|mixed $expression2 + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression1 + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression2 */ - public function __construct(mixed $expression1, mixed $expression2) - { + public function __construct( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression1, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression2, + ) { + if (\is_array($expression1) && ! \array_is_list($expression1)) { + throw new \InvalidArgumentException('Expected $expression1 argument to be a list, got an associative array.'); + } + $this->expression1 = $expression1; + if (\is_array($expression2) && ! \array_is_list($expression2)) { + throw new \InvalidArgumentException('Expected $expression2 argument to be a list, got an associative array.'); + } + $this->expression2 = $expression2; } } diff --git a/src/Builder/Aggregation/LteAggregation.php b/src/Builder/Aggregation/LteAggregation.php index 430dca7c3..1335dc581 100644 --- a/src/Builder/Aggregation/LteAggregation.php +++ b/src/Builder/Aggregation/LteAggregation.php @@ -6,9 +6,22 @@ namespace MongoDB\Builder\Aggregation; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Document; +use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; +use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; +use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToBool; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Type\ExpressionInterface; +use MongoDB\Model\BSONArray; +use stdClass; /** * Returns true if the first value is less than or equal to the second. @@ -20,19 +33,29 @@ class LteAggregation implements ResolvesToBool public const NAME = '$lte'; public const ENCODE = \MongoDB\Builder\Encode::Array; - /** @param ExpressionInterface|mixed $expression1 */ - public mixed $expression1; + /** @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression1 */ + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression1; - /** @param ExpressionInterface|mixed $expression2 */ - public mixed $expression2; + /** @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression2 */ + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression2; /** - * @param ExpressionInterface|mixed $expression1 - * @param ExpressionInterface|mixed $expression2 + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression1 + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression2 */ - public function __construct(mixed $expression1, mixed $expression2) - { + public function __construct( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression1, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression2, + ) { + if (\is_array($expression1) && ! \array_is_list($expression1)) { + throw new \InvalidArgumentException('Expected $expression1 argument to be a list, got an associative array.'); + } + $this->expression1 = $expression1; + if (\is_array($expression2) && ! \array_is_list($expression2)) { + throw new \InvalidArgumentException('Expected $expression2 argument to be a list, got an associative array.'); + } + $this->expression2 = $expression2; } } diff --git a/src/Builder/Aggregation/MapAggregation.php b/src/Builder/Aggregation/MapAggregation.php index 04932b0d7..6d07913b8 100644 --- a/src/Builder/Aggregation/MapAggregation.php +++ b/src/Builder/Aggregation/MapAggregation.php @@ -6,13 +6,24 @@ namespace MongoDB\Builder\Aggregation; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Document; +use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; +use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToArray; +use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Expression\ResolvesToString; use MongoDB\Builder\Optional; +use MongoDB\Builder\Type\ExpressionInterface; use MongoDB\Model\BSONArray; +use stdClass; /** * Applies a subexpression to each element of an array and returns the array of resulting values in order. Accepts named parameters. @@ -24,29 +35,34 @@ class MapAggregation implements ResolvesToArray public const NAME = '$map'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param BSONArray|PackedArray|ResolvesToArray|list $input An expression that resolves to an array. */ + /** @param BSONArray|PackedArray|ResolvesToArray|array $input An expression that resolves to an array. */ public PackedArray|ResolvesToArray|BSONArray|array $input; - /** @param ExpressionInterface|mixed $in 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. */ - public mixed $in; + /** @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $in 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. */ + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $in; /** @param Optional|ResolvesToString|non-empty-string $as 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. */ public ResolvesToString|Optional|string $as; /** - * @param BSONArray|PackedArray|ResolvesToArray|list $input An expression that resolves to an array. - * @param ExpressionInterface|mixed $in 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. + * @param BSONArray|PackedArray|ResolvesToArray|array $input An expression that resolves to an array. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $in 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. * @param Optional|ResolvesToString|non-empty-string $as 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. */ public function __construct( PackedArray|ResolvesToArray|BSONArray|array $input, - mixed $in, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $in, ResolvesToString|Optional|string $as = Optional::Undefined, ) { if (\is_array($input) && ! \array_is_list($input)) { throw new \InvalidArgumentException('Expected $input argument to be a list, got an associative array.'); } + $this->input = $input; + if (\is_array($in) && ! \array_is_list($in)) { + throw new \InvalidArgumentException('Expected $in argument to be a list, got an associative array.'); + } + $this->in = $in; $this->as = $as; } diff --git a/src/Builder/Aggregation/MaxAggregation.php b/src/Builder/Aggregation/MaxAggregation.php index 41a7a9eb0..de01dfd9a 100644 --- a/src/Builder/Aggregation/MaxAggregation.php +++ b/src/Builder/Aggregation/MaxAggregation.php @@ -6,8 +6,23 @@ namespace MongoDB\Builder\Aggregation; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Document; +use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; +use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; +use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; +use MongoDB\Builder\Expression\ResolvesToAny; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Type\AccumulatorInterface; +use MongoDB\Builder\Type\ExpressionInterface; +use MongoDB\Model\BSONArray; +use stdClass; /** * Returns the maximum value that results from applying an expression to each document. @@ -15,25 +30,26 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/max/ */ -class MaxAggregation implements ExpressionInterface, AccumulatorInterface +class MaxAggregation implements ResolvesToAny, AccumulatorInterface { public const NAME = '$max'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param list ...$expression */ + /** @param list ...$expression */ public array $expression; /** - * @param ExpressionInterface|mixed ...$expression + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass ...$expression * @no-named-arguments */ - public function __construct(mixed ...$expression) - { + public function __construct( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string ...$expression, + ) { if (\count($expression) < 1) { throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); } if (! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression arguments to be a list of ExpressionInterface|mixed, named arguments are not supported'); + throw new \InvalidArgumentException('Expected $expression arguments to be a list (array), named arguments are not supported'); } $this->expression = $expression; } diff --git a/src/Builder/Aggregation/MaxNAggregation.php b/src/Builder/Aggregation/MaxNAggregation.php index 684442855..342edff8e 100644 --- a/src/Builder/Aggregation/MaxNAggregation.php +++ b/src/Builder/Aggregation/MaxNAggregation.php @@ -6,10 +6,8 @@ namespace MongoDB\Builder\Aggregation; -use MongoDB\BSON\Int64; use MongoDB\BSON\PackedArray; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToArray; use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Model\BSONArray; @@ -24,21 +22,22 @@ class MaxNAggregation implements ResolvesToArray public const NAME = '$maxN'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param BSONArray|PackedArray|ResolvesToArray|list $input An expression that resolves to the array from which to return the maximal n elements. */ + /** @param BSONArray|PackedArray|ResolvesToArray|array $input An expression that resolves to the array from which to return the maximal n elements. */ public PackedArray|ResolvesToArray|BSONArray|array $input; - /** @param Int64|ResolvesToInt|int $n An expression that resolves to a positive integer. The integer specifies the number of array elements that $maxN returns. */ - public Int64|ResolvesToInt|int $n; + /** @param ResolvesToInt|int $n An expression that resolves to a positive integer. The integer specifies the number of array elements that $maxN returns. */ + public ResolvesToInt|int $n; /** - * @param BSONArray|PackedArray|ResolvesToArray|list $input An expression that resolves to the array from which to return the maximal n elements. - * @param Int64|ResolvesToInt|int $n An expression that resolves to a positive integer. The integer specifies the number of array elements that $maxN returns. + * @param BSONArray|PackedArray|ResolvesToArray|array $input An expression that resolves to the array from which to return the maximal n elements. + * @param ResolvesToInt|int $n An expression that resolves to a positive integer. The integer specifies the number of array elements that $maxN returns. */ - public function __construct(PackedArray|ResolvesToArray|BSONArray|array $input, Int64|ResolvesToInt|int $n) + public function __construct(PackedArray|ResolvesToArray|BSONArray|array $input, ResolvesToInt|int $n) { if (\is_array($input) && ! \array_is_list($input)) { throw new \InvalidArgumentException('Expected $input argument to be a list, got an associative array.'); } + $this->input = $input; $this->n = $n; } diff --git a/src/Builder/Aggregation/MedianAggregation.php b/src/Builder/Aggregation/MedianAggregation.php index eabe80284..783f22868 100644 --- a/src/Builder/Aggregation/MedianAggregation.php +++ b/src/Builder/Aggregation/MedianAggregation.php @@ -9,8 +9,12 @@ use MongoDB\BSON\Decimal128; use MongoDB\BSON\Int64; use MongoDB\Builder\Encode; +use MongoDB\Builder\Expression\ResolvesToDecimal; use MongoDB\Builder\Expression\ResolvesToDouble; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Expression\ResolvesToLong; use MongoDB\Builder\Expression\ResolvesToNumber; +use MongoDB\Builder\Type\AccumulatorInterface; /** * Returns an approximation of the median, the 50th percentile, as a scalar value. @@ -27,18 +31,20 @@ class MedianAggregation implements ResolvesToDouble, AccumulatorInterface public const NAME = '$median'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param Decimal128|Int64|ResolvesToNumber|float|int $input $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. */ - public Decimal128|Int64|ResolvesToNumber|float|int $input; + /** @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $input $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. */ + public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $input; /** @param non-empty-string $method The method that mongod uses to calculate the 50th percentile value. The method must be 'approximate'. */ public string $method; /** - * @param Decimal128|Int64|ResolvesToNumber|float|int $input $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. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $input $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. * @param non-empty-string $method The method that mongod uses to calculate the 50th percentile value. The method must be 'approximate'. */ - public function __construct(Decimal128|Int64|ResolvesToNumber|float|int $input, string $method) - { + public function __construct( + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $input, + string $method, + ) { $this->input = $input; $this->method = $method; } diff --git a/src/Builder/Aggregation/MergeObjectsAggregation.php b/src/Builder/Aggregation/MergeObjectsAggregation.php index 7a70f1033..760f61bb4 100644 --- a/src/Builder/Aggregation/MergeObjectsAggregation.php +++ b/src/Builder/Aggregation/MergeObjectsAggregation.php @@ -10,6 +10,7 @@ use MongoDB\BSON\Serializable; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToObject; +use MongoDB\Builder\Type\AccumulatorInterface; use stdClass; /** @@ -35,7 +36,7 @@ public function __construct(Document|Serializable|ResolvesToObject|stdClass|arra throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $document, got %d.', 1, \count($document))); } if (! \array_is_list($document)) { - throw new \InvalidArgumentException('Expected $document arguments to be a list of Document|ResolvesToObject|Serializable|array|stdClass, named arguments are not supported'); + throw new \InvalidArgumentException('Expected $document arguments to be a list (array), named arguments are not supported'); } $this->document = $document; } diff --git a/src/Builder/Aggregation/MillisecondAggregation.php b/src/Builder/Aggregation/MillisecondAggregation.php index 09d213c09..4b34b5696 100644 --- a/src/Builder/Aggregation/MillisecondAggregation.php +++ b/src/Builder/Aggregation/MillisecondAggregation.php @@ -6,9 +6,8 @@ namespace MongoDB\Builder\Aggregation; -use DateTimeInterface; -use MongoDB\BSON\Int64; use MongoDB\BSON\ObjectId; +use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToDate; @@ -28,18 +27,18 @@ class MillisecondAggregation implements ResolvesToInt public const NAME = '$millisecond'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ - public DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; + /** @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ + public ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; /** @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public ResolvesToString|Optional|string $timezone; /** - * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public function __construct( - DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|Optional|string $timezone = Optional::Undefined, ) { $this->date = $date; diff --git a/src/Builder/Aggregation/MinAggregation.php b/src/Builder/Aggregation/MinAggregation.php index cc32841dd..c411ba6d6 100644 --- a/src/Builder/Aggregation/MinAggregation.php +++ b/src/Builder/Aggregation/MinAggregation.php @@ -6,8 +6,23 @@ namespace MongoDB\Builder\Aggregation; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Document; +use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; +use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; +use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; +use MongoDB\Builder\Expression\ResolvesToAny; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Type\AccumulatorInterface; +use MongoDB\Builder\Type\ExpressionInterface; +use MongoDB\Model\BSONArray; +use stdClass; /** * Returns the minimum value that results from applying an expression to each document. @@ -15,25 +30,26 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/min/ */ -class MinAggregation implements ExpressionInterface, AccumulatorInterface +class MinAggregation implements ResolvesToAny, AccumulatorInterface { public const NAME = '$min'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param list ...$expression */ + /** @param list ...$expression */ public array $expression; /** - * @param ExpressionInterface|mixed ...$expression + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass ...$expression * @no-named-arguments */ - public function __construct(mixed ...$expression) - { + public function __construct( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string ...$expression, + ) { if (\count($expression) < 1) { throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); } if (! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression arguments to be a list of ExpressionInterface|mixed, named arguments are not supported'); + throw new \InvalidArgumentException('Expected $expression arguments to be a list (array), named arguments are not supported'); } $this->expression = $expression; } diff --git a/src/Builder/Aggregation/MinNAggregation.php b/src/Builder/Aggregation/MinNAggregation.php index 7a2546c16..2f45dcc33 100644 --- a/src/Builder/Aggregation/MinNAggregation.php +++ b/src/Builder/Aggregation/MinNAggregation.php @@ -6,10 +6,8 @@ namespace MongoDB\Builder\Aggregation; -use MongoDB\BSON\Int64; use MongoDB\BSON\PackedArray; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToArray; use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Model\BSONArray; @@ -24,21 +22,22 @@ class MinNAggregation implements ResolvesToArray public const NAME = '$minN'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param BSONArray|PackedArray|ResolvesToArray|list $input An expression that resolves to the array from which to return the maximal n elements. */ + /** @param BSONArray|PackedArray|ResolvesToArray|array $input An expression that resolves to the array from which to return the maximal n elements. */ public PackedArray|ResolvesToArray|BSONArray|array $input; - /** @param Int64|ResolvesToInt|int $n An expression that resolves to a positive integer. The integer specifies the number of array elements that $maxN returns. */ - public Int64|ResolvesToInt|int $n; + /** @param ResolvesToInt|int $n An expression that resolves to a positive integer. The integer specifies the number of array elements that $maxN returns. */ + public ResolvesToInt|int $n; /** - * @param BSONArray|PackedArray|ResolvesToArray|list $input An expression that resolves to the array from which to return the maximal n elements. - * @param Int64|ResolvesToInt|int $n An expression that resolves to a positive integer. The integer specifies the number of array elements that $maxN returns. + * @param BSONArray|PackedArray|ResolvesToArray|array $input An expression that resolves to the array from which to return the maximal n elements. + * @param ResolvesToInt|int $n An expression that resolves to a positive integer. The integer specifies the number of array elements that $maxN returns. */ - public function __construct(PackedArray|ResolvesToArray|BSONArray|array $input, Int64|ResolvesToInt|int $n) + public function __construct(PackedArray|ResolvesToArray|BSONArray|array $input, ResolvesToInt|int $n) { if (\is_array($input) && ! \array_is_list($input)) { throw new \InvalidArgumentException('Expected $input argument to be a list, got an associative array.'); } + $this->input = $input; $this->n = $n; } diff --git a/src/Builder/Aggregation/MinuteAggregation.php b/src/Builder/Aggregation/MinuteAggregation.php index cb82f54a6..e4a527bc3 100644 --- a/src/Builder/Aggregation/MinuteAggregation.php +++ b/src/Builder/Aggregation/MinuteAggregation.php @@ -6,9 +6,8 @@ namespace MongoDB\Builder\Aggregation; -use DateTimeInterface; -use MongoDB\BSON\Int64; use MongoDB\BSON\ObjectId; +use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToDate; @@ -28,18 +27,18 @@ class MinuteAggregation implements ResolvesToInt public const NAME = '$minute'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ - public DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; + /** @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ + public ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; /** @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public ResolvesToString|Optional|string $timezone; /** - * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public function __construct( - DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|Optional|string $timezone = Optional::Undefined, ) { $this->date = $date; diff --git a/src/Builder/Aggregation/ModAggregation.php b/src/Builder/Aggregation/ModAggregation.php index 52cf6bde9..84fc22c4e 100644 --- a/src/Builder/Aggregation/ModAggregation.php +++ b/src/Builder/Aggregation/ModAggregation.php @@ -9,7 +9,10 @@ use MongoDB\BSON\Decimal128; use MongoDB\BSON\Int64; use MongoDB\Builder\Encode; +use MongoDB\Builder\Expression\ResolvesToDecimal; +use MongoDB\Builder\Expression\ResolvesToDouble; use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Expression\ResolvesToLong; use MongoDB\Builder\Expression\ResolvesToNumber; /** @@ -22,19 +25,19 @@ class ModAggregation implements ResolvesToInt public const NAME = '$mod'; public const ENCODE = \MongoDB\Builder\Encode::Array; - /** @param Decimal128|Int64|ResolvesToNumber|float|int $dividend The first argument is the dividend, and the second argument is the divisor; i.e. first argument is divided by the second argument. */ - public Decimal128|Int64|ResolvesToNumber|float|int $dividend; + /** @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $dividend The first argument is the dividend, and the second argument is the divisor; i.e. first argument is divided by the second argument. */ + public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $dividend; - /** @param Decimal128|Int64|ResolvesToNumber|float|int $divisor */ - public Decimal128|Int64|ResolvesToNumber|float|int $divisor; + /** @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $divisor */ + public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $divisor; /** - * @param Decimal128|Int64|ResolvesToNumber|float|int $dividend The first argument is the dividend, and the second argument is the divisor; i.e. first argument is divided by the second argument. - * @param Decimal128|Int64|ResolvesToNumber|float|int $divisor + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $dividend The first argument is the dividend, and the second argument is the divisor; i.e. first argument is divided by the second argument. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $divisor */ public function __construct( - Decimal128|Int64|ResolvesToNumber|float|int $dividend, - Decimal128|Int64|ResolvesToNumber|float|int $divisor, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $dividend, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $divisor, ) { $this->dividend = $dividend; $this->divisor = $divisor; diff --git a/src/Builder/Aggregation/MonthAggregation.php b/src/Builder/Aggregation/MonthAggregation.php index 3ef8a3569..717b4fda5 100644 --- a/src/Builder/Aggregation/MonthAggregation.php +++ b/src/Builder/Aggregation/MonthAggregation.php @@ -6,9 +6,8 @@ namespace MongoDB\Builder\Aggregation; -use DateTimeInterface; -use MongoDB\BSON\Int64; use MongoDB\BSON\ObjectId; +use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToDate; @@ -28,18 +27,18 @@ class MonthAggregation implements ResolvesToInt public const NAME = '$month'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ - public DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; + /** @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ + public ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; /** @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public ResolvesToString|Optional|string $timezone; /** - * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public function __construct( - DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|Optional|string $timezone = Optional::Undefined, ) { $this->date = $date; diff --git a/src/Builder/Aggregation/MultiplyAggregation.php b/src/Builder/Aggregation/MultiplyAggregation.php index e21243682..98ef93b78 100644 --- a/src/Builder/Aggregation/MultiplyAggregation.php +++ b/src/Builder/Aggregation/MultiplyAggregation.php @@ -10,6 +10,9 @@ use MongoDB\BSON\Int64; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToDecimal; +use MongoDB\Builder\Expression\ResolvesToDouble; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Expression\ResolvesToLong; use MongoDB\Builder\Expression\ResolvesToNumber; /** @@ -23,23 +26,24 @@ class MultiplyAggregation implements ResolvesToDecimal public const ENCODE = \MongoDB\Builder\Encode::Single; /** - * @param list ...$expression The arguments can be any valid expression as long as they resolve to numbers. + * @param list ...$expression 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. */ public array $expression; /** - * @param Decimal128|Int64|ResolvesToNumber|float|int ...$expression The arguments can be any valid expression as long as they resolve to numbers. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int ...$expression 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. * @no-named-arguments */ - public function __construct(Decimal128|Int64|ResolvesToNumber|float|int ...$expression) - { + public function __construct( + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int ...$expression, + ) { if (\count($expression) < 1) { throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); } if (! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression arguments to be a list of Decimal128|Int64|ResolvesToNumber|float|int, named arguments are not supported'); + throw new \InvalidArgumentException('Expected $expression arguments to be a list (array), named arguments are not supported'); } $this->expression = $expression; } diff --git a/src/Builder/Aggregation/NeAggregation.php b/src/Builder/Aggregation/NeAggregation.php index 50224149c..175bf210b 100644 --- a/src/Builder/Aggregation/NeAggregation.php +++ b/src/Builder/Aggregation/NeAggregation.php @@ -6,9 +6,22 @@ namespace MongoDB\Builder\Aggregation; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Document; +use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; +use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; +use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToBool; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Type\ExpressionInterface; +use MongoDB\Model\BSONArray; +use stdClass; /** * Returns true if the values are not equivalent. @@ -20,19 +33,29 @@ class NeAggregation implements ResolvesToBool public const NAME = '$ne'; public const ENCODE = \MongoDB\Builder\Encode::Array; - /** @param ExpressionInterface|mixed $expression1 */ - public mixed $expression1; + /** @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression1 */ + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression1; - /** @param ExpressionInterface|mixed $expression2 */ - public mixed $expression2; + /** @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression2 */ + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression2; /** - * @param ExpressionInterface|mixed $expression1 - * @param ExpressionInterface|mixed $expression2 + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression1 + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression2 */ - public function __construct(mixed $expression1, mixed $expression2) - { + public function __construct( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression1, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression2, + ) { + if (\is_array($expression1) && ! \array_is_list($expression1)) { + throw new \InvalidArgumentException('Expected $expression1 argument to be a list, got an associative array.'); + } + $this->expression1 = $expression1; + if (\is_array($expression2) && ! \array_is_list($expression2)) { + throw new \InvalidArgumentException('Expected $expression2 argument to be a list, got an associative array.'); + } + $this->expression2 = $expression2; } } diff --git a/src/Builder/Aggregation/NotAggregation.php b/src/Builder/Aggregation/NotAggregation.php index dbc43c497..b901a00d8 100644 --- a/src/Builder/Aggregation/NotAggregation.php +++ b/src/Builder/Aggregation/NotAggregation.php @@ -6,9 +6,22 @@ namespace MongoDB\Builder\Aggregation; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Document; +use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; +use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; +use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToBool; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Type\ExpressionInterface; +use MongoDB\Model\BSONArray; +use stdClass; /** * Returns the boolean value that is the opposite of its argument expression. Accepts a single argument expression. @@ -20,14 +33,19 @@ class NotAggregation implements ResolvesToBool public const NAME = '$not'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param ExpressionInterface|ResolvesToBool|bool|mixed $expression */ - public mixed $expression; + /** @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToBool|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression */ + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToBool|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression; /** - * @param ExpressionInterface|ResolvesToBool|bool|mixed $expression + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToBool|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression */ - public function __construct(mixed $expression) - { + public function __construct( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToBool|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, + ) { + if (\is_array($expression) && ! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression argument to be a list, got an associative array.'); + } + $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/OrAggregation.php b/src/Builder/Aggregation/OrAggregation.php index 2f865c63d..69db5010f 100644 --- a/src/Builder/Aggregation/OrAggregation.php +++ b/src/Builder/Aggregation/OrAggregation.php @@ -6,9 +6,22 @@ namespace MongoDB\Builder\Aggregation; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Document; +use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; +use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; +use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToBool; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Type\ExpressionInterface; +use MongoDB\Model\BSONArray; +use stdClass; /** * Returns true when any of its expressions evaluates to true. Accepts any number of argument expressions. @@ -20,20 +33,21 @@ class OrAggregation implements ResolvesToBool public const NAME = '$or'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param list ...$expression */ + /** @param list ...$expression */ public array $expression; /** - * @param ExpressionInterface|ResolvesToBool|bool|mixed ...$expression + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToBool|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass ...$expression * @no-named-arguments */ - public function __construct(mixed ...$expression) - { + public function __construct( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToBool|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string ...$expression, + ) { if (\count($expression) < 1) { throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); } if (! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression arguments to be a list of ExpressionInterface|ResolvesToBool|bool|mixed, named arguments are not supported'); + throw new \InvalidArgumentException('Expected $expression arguments to be a list (array), named arguments are not supported'); } $this->expression = $expression; } diff --git a/src/Builder/Aggregation/PercentileAggregation.php b/src/Builder/Aggregation/PercentileAggregation.php index a3b74bd67..4c80ca1c2 100644 --- a/src/Builder/Aggregation/PercentileAggregation.php +++ b/src/Builder/Aggregation/PercentileAggregation.php @@ -10,9 +10,13 @@ use MongoDB\BSON\Int64; use MongoDB\BSON\PackedArray; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToArray; +use MongoDB\Builder\Expression\ResolvesToDecimal; +use MongoDB\Builder\Expression\ResolvesToDouble; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Expression\ResolvesToLong; use MongoDB\Builder\Expression\ResolvesToNumber; +use MongoDB\Builder\Type\AccumulatorInterface; use MongoDB\Model\BSONArray; /** @@ -33,11 +37,11 @@ class PercentileAggregation implements ResolvesToArray, AccumulatorInterface public const NAME = '$percentile'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param Decimal128|Int64|ResolvesToNumber|float|int $input $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. */ - public Decimal128|Int64|ResolvesToNumber|float|int $input; + /** @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $input $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. */ + public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $input; /** - * @param BSONArray|PackedArray|ResolvesToArray|list $p $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. + * @param BSONArray|PackedArray|ResolvesToArray|array $p $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. */ public PackedArray|ResolvesToArray|BSONArray|array $p; @@ -46,13 +50,13 @@ class PercentileAggregation implements ResolvesToArray, AccumulatorInterface public string $method; /** - * @param Decimal128|Int64|ResolvesToNumber|float|int $input $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. - * @param BSONArray|PackedArray|ResolvesToArray|list $p $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. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $input $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. + * @param BSONArray|PackedArray|ResolvesToArray|array $p $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. * @param non-empty-string $method The method that mongod uses to calculate the percentile value. The method must be 'approximate'. */ public function __construct( - Decimal128|Int64|ResolvesToNumber|float|int $input, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $input, PackedArray|ResolvesToArray|BSONArray|array $p, string $method, ) { @@ -60,6 +64,7 @@ public function __construct( if (\is_array($p) && ! \array_is_list($p)) { throw new \InvalidArgumentException('Expected $p argument to be a list, got an associative array.'); } + $this->p = $p; $this->method = $method; } diff --git a/src/Builder/Aggregation/PowAggregation.php b/src/Builder/Aggregation/PowAggregation.php index e576e87f6..e2f5b3763 100644 --- a/src/Builder/Aggregation/PowAggregation.php +++ b/src/Builder/Aggregation/PowAggregation.php @@ -9,6 +9,10 @@ use MongoDB\BSON\Decimal128; use MongoDB\BSON\Int64; use MongoDB\Builder\Encode; +use MongoDB\Builder\Expression\ResolvesToDecimal; +use MongoDB\Builder\Expression\ResolvesToDouble; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Expression\ResolvesToLong; use MongoDB\Builder\Expression\ResolvesToNumber; /** @@ -21,19 +25,19 @@ class PowAggregation implements ResolvesToNumber public const NAME = '$pow'; public const ENCODE = \MongoDB\Builder\Encode::Array; - /** @param Decimal128|Int64|ResolvesToNumber|float|int $number */ - public Decimal128|Int64|ResolvesToNumber|float|int $number; + /** @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $number */ + public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $number; - /** @param Decimal128|Int64|ResolvesToNumber|float|int $exponent */ - public Decimal128|Int64|ResolvesToNumber|float|int $exponent; + /** @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $exponent */ + public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $exponent; /** - * @param Decimal128|Int64|ResolvesToNumber|float|int $number - * @param Decimal128|Int64|ResolvesToNumber|float|int $exponent + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $number + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $exponent */ public function __construct( - Decimal128|Int64|ResolvesToNumber|float|int $number, - Decimal128|Int64|ResolvesToNumber|float|int $exponent, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $number, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $exponent, ) { $this->number = $number; $this->exponent = $exponent; diff --git a/src/Builder/Aggregation/PushAggregation.php b/src/Builder/Aggregation/PushAggregation.php index 0c0a0ab5d..9c550979d 100644 --- a/src/Builder/Aggregation/PushAggregation.php +++ b/src/Builder/Aggregation/PushAggregation.php @@ -6,8 +6,22 @@ namespace MongoDB\Builder\Aggregation; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Document; +use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; +use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; +use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Type\AccumulatorInterface; +use MongoDB\Builder\Type\ExpressionInterface; +use MongoDB\Model\BSONArray; +use stdClass; /** * Returns an array of values that result from applying an expression to each document. @@ -20,14 +34,19 @@ class PushAggregation implements AccumulatorInterface public const NAME = '$push'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param ExpressionInterface|mixed $expression */ - public mixed $expression; + /** @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression */ + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression; /** - * @param ExpressionInterface|mixed $expression + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression */ - public function __construct(mixed $expression) - { + public function __construct( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, + ) { + if (\is_array($expression) && ! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression argument to be a list, got an associative array.'); + } + $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/RadiansToDegreesAggregation.php b/src/Builder/Aggregation/RadiansToDegreesAggregation.php index b79658a79..1e03ef516 100644 --- a/src/Builder/Aggregation/RadiansToDegreesAggregation.php +++ b/src/Builder/Aggregation/RadiansToDegreesAggregation.php @@ -11,6 +11,8 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToDecimal; use MongoDB\Builder\Expression\ResolvesToDouble; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Expression\ResolvesToLong; use MongoDB\Builder\Expression\ResolvesToNumber; /** @@ -23,14 +25,15 @@ class RadiansToDegreesAggregation implements ResolvesToDouble, ResolvesToDecimal public const NAME = '$radiansToDegrees'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param Decimal128|Int64|ResolvesToNumber|float|int $expression */ - public Decimal128|Int64|ResolvesToNumber|float|int $expression; + /** @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression */ + public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression; /** - * @param Decimal128|Int64|ResolvesToNumber|float|int $expression + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression */ - public function __construct(Decimal128|Int64|ResolvesToNumber|float|int $expression) - { + public function __construct( + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression, + ) { $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/RandAggregation.php b/src/Builder/Aggregation/RandAggregation.php index 8b55e32d2..3a65c2aa2 100644 --- a/src/Builder/Aggregation/RandAggregation.php +++ b/src/Builder/Aggregation/RandAggregation.php @@ -7,14 +7,14 @@ namespace MongoDB\Builder\Aggregation; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToFloat; +use MongoDB\Builder\Expression\ResolvesToDouble; /** * Returns a random float between 0 and 1 * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/rand/ */ -class RandAggregation implements ResolvesToFloat +class RandAggregation implements ResolvesToDouble { public const NAME = '$rand'; public const ENCODE = \MongoDB\Builder\Encode::Object; diff --git a/src/Builder/Aggregation/RangeAggregation.php b/src/Builder/Aggregation/RangeAggregation.php index 4f31ebafb..d07de6aa9 100644 --- a/src/Builder/Aggregation/RangeAggregation.php +++ b/src/Builder/Aggregation/RangeAggregation.php @@ -6,7 +6,6 @@ namespace MongoDB\Builder\Aggregation; -use MongoDB\BSON\Int64; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToArray; use MongoDB\Builder\Expression\ResolvesToInt; @@ -22,24 +21,24 @@ class RangeAggregation implements ResolvesToArray public const NAME = '$range'; public const ENCODE = \MongoDB\Builder\Encode::Array; - /** @param Int64|ResolvesToInt|int $start An integer that specifies the start of the sequence. Can be any valid expression that resolves to an integer. */ - public Int64|ResolvesToInt|int $start; + /** @param ResolvesToInt|int $start An integer that specifies the start of the sequence. Can be any valid expression that resolves to an integer. */ + public ResolvesToInt|int $start; - /** @param Int64|ResolvesToInt|int $end An integer that specifies the exclusive upper limit of the sequence. Can be any valid expression that resolves to an integer. */ - public Int64|ResolvesToInt|int $end; + /** @param ResolvesToInt|int $end An integer that specifies the exclusive upper limit of the sequence. Can be any valid expression that resolves to an integer. */ + public ResolvesToInt|int $end; - /** @param Int64|Optional|ResolvesToInt|int $step An integer that specifies the increment value. Can be any valid expression that resolves to a non-zero integer. Defaults to 1. */ - public Int64|ResolvesToInt|Optional|int $step; + /** @param Optional|ResolvesToInt|int $step An integer that specifies the increment value. Can be any valid expression that resolves to a non-zero integer. Defaults to 1. */ + public ResolvesToInt|Optional|int $step; /** - * @param Int64|ResolvesToInt|int $start An integer that specifies the start of the sequence. Can be any valid expression that resolves to an integer. - * @param Int64|ResolvesToInt|int $end An integer that specifies the exclusive upper limit of the sequence. Can be any valid expression that resolves to an integer. - * @param Int64|Optional|ResolvesToInt|int $step An integer that specifies the increment value. Can be any valid expression that resolves to a non-zero integer. Defaults to 1. + * @param ResolvesToInt|int $start An integer that specifies the start of the sequence. Can be any valid expression that resolves to an integer. + * @param ResolvesToInt|int $end An integer that specifies the exclusive upper limit of the sequence. Can be any valid expression that resolves to an integer. + * @param Optional|ResolvesToInt|int $step An integer that specifies the increment value. Can be any valid expression that resolves to a non-zero integer. Defaults to 1. */ public function __construct( - Int64|ResolvesToInt|int $start, - Int64|ResolvesToInt|int $end, - Int64|ResolvesToInt|Optional|int $step = Optional::Undefined, + ResolvesToInt|int $start, + ResolvesToInt|int $end, + ResolvesToInt|Optional|int $step = Optional::Undefined, ) { $this->start = $start; $this->end = $end; diff --git a/src/Builder/Aggregation/ReduceAggregation.php b/src/Builder/Aggregation/ReduceAggregation.php index 6dbe25d0f..c2948fb61 100644 --- a/src/Builder/Aggregation/ReduceAggregation.php +++ b/src/Builder/Aggregation/ReduceAggregation.php @@ -6,57 +6,81 @@ namespace MongoDB\Builder\Aggregation; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Document; +use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; +use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; +use MongoDB\Builder\Expression\ResolvesToAny; use MongoDB\Builder\Expression\ResolvesToArray; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Type\ExpressionInterface; use MongoDB\Model\BSONArray; +use stdClass; /** * Applies an expression to each element in an array and combines them into a single value. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/reduce/ */ -class ReduceAggregation implements ExpressionInterface +class ReduceAggregation implements ResolvesToAny { public const NAME = '$reduce'; public const ENCODE = \MongoDB\Builder\Encode::Object; /** - * @param BSONArray|PackedArray|ResolvesToArray|list $input Can be any valid expression that resolves to an array. + * @param BSONArray|PackedArray|ResolvesToArray|array $input 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. */ public PackedArray|ResolvesToArray|BSONArray|array $input; - /** @param ExpressionInterface|mixed $initialValue The initial cumulative value set before in is applied to the first element of the input array. */ - public mixed $initialValue; + /** @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $initialValue The initial cumulative value set before in is applied to the first element of the input array. */ + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $initialValue; /** - * @param ExpressionInterface|mixed $in 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. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $in 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. */ - public mixed $in; + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $in; /** - * @param BSONArray|PackedArray|ResolvesToArray|list $input Can be any valid expression that resolves to an array. + * @param BSONArray|PackedArray|ResolvesToArray|array $input 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. - * @param ExpressionInterface|mixed $initialValue The initial cumulative value set before in is applied to the first element of the input array. - * @param ExpressionInterface|mixed $in 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. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $initialValue The initial cumulative value set before in is applied to the first element of the input array. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $in 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. */ - public function __construct(PackedArray|ResolvesToArray|BSONArray|array $input, mixed $initialValue, mixed $in) - { + public function __construct( + PackedArray|ResolvesToArray|BSONArray|array $input, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $initialValue, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $in, + ) { if (\is_array($input) && ! \array_is_list($input)) { throw new \InvalidArgumentException('Expected $input argument to be a list, got an associative array.'); } + $this->input = $input; + if (\is_array($initialValue) && ! \array_is_list($initialValue)) { + throw new \InvalidArgumentException('Expected $initialValue argument to be a list, got an associative array.'); + } + $this->initialValue = $initialValue; + if (\is_array($in) && ! \array_is_list($in)) { + throw new \InvalidArgumentException('Expected $in argument to be a list, got an associative array.'); + } + $this->in = $in; } } diff --git a/src/Builder/Aggregation/ReverseArrayAggregation.php b/src/Builder/Aggregation/ReverseArrayAggregation.php index f982c2bfe..8bcf7d4ff 100644 --- a/src/Builder/Aggregation/ReverseArrayAggregation.php +++ b/src/Builder/Aggregation/ReverseArrayAggregation.php @@ -8,7 +8,6 @@ use MongoDB\BSON\PackedArray; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToArray; use MongoDB\Model\BSONArray; @@ -22,17 +21,18 @@ class ReverseArrayAggregation implements ResolvesToArray public const NAME = '$reverseArray'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param BSONArray|PackedArray|ResolvesToArray|list $expression The argument can be any valid expression as long as it resolves to an array. */ + /** @param BSONArray|PackedArray|ResolvesToArray|array $expression The argument can be any valid expression as long as it resolves to an array. */ public PackedArray|ResolvesToArray|BSONArray|array $expression; /** - * @param BSONArray|PackedArray|ResolvesToArray|list $expression The argument can be any valid expression as long as it resolves to an array. + * @param BSONArray|PackedArray|ResolvesToArray|array $expression The argument can be any valid expression as long as it resolves to an array. */ public function __construct(PackedArray|ResolvesToArray|BSONArray|array $expression) { if (\is_array($expression) && ! \array_is_list($expression)) { throw new \InvalidArgumentException('Expected $expression argument to be a list, got an associative array.'); } + $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/RoundAggregation.php b/src/Builder/Aggregation/RoundAggregation.php index 8e164c30a..00898b26d 100644 --- a/src/Builder/Aggregation/RoundAggregation.php +++ b/src/Builder/Aggregation/RoundAggregation.php @@ -31,17 +31,17 @@ class RoundAggregation implements ResolvesToInt, ResolvesToDouble, ResolvesToDec */ public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|float|int $number; - /** @param Int64|Optional|ResolvesToInt|int $place Can be any valid expression that resolves to an integer between -20 and 100, exclusive. */ - public Int64|ResolvesToInt|Optional|int $place; + /** @param Optional|ResolvesToInt|int $place Can be any valid expression that resolves to an integer between -20 and 100, exclusive. */ + public ResolvesToInt|Optional|int $place; /** * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|float|int $number 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. - * @param Int64|Optional|ResolvesToInt|int $place Can be any valid expression that resolves to an integer between -20 and 100, exclusive. + * @param Optional|ResolvesToInt|int $place Can be any valid expression that resolves to an integer between -20 and 100, exclusive. */ public function __construct( Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|float|int $number, - Int64|ResolvesToInt|Optional|int $place = Optional::Undefined, + ResolvesToInt|Optional|int $place = Optional::Undefined, ) { $this->number = $number; $this->place = $place; diff --git a/src/Builder/Aggregation/SampleRateAggregation.php b/src/Builder/Aggregation/SampleRateAggregation.php index 9cc7ddd46..ec1652f07 100644 --- a/src/Builder/Aggregation/SampleRateAggregation.php +++ b/src/Builder/Aggregation/SampleRateAggregation.php @@ -8,30 +8,30 @@ use MongoDB\BSON\Int64; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; -use MongoDB\Builder\Expression\ResolvesToFloat; +use MongoDB\Builder\Expression\ResolvesToAny; +use MongoDB\Builder\Expression\ResolvesToDouble; /** * 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. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/sampleRate/ */ -class SampleRateAggregation implements ExpressionInterface +class SampleRateAggregation implements ResolvesToAny { public const NAME = '$sampleRate'; public const ENCODE = \MongoDB\Builder\Encode::Single; /** - * @param Int64|ResolvesToFloat|float|int $rate 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. + * @param Int64|ResolvesToDouble|float|int $rate 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. */ - public Int64|ResolvesToFloat|float|int $rate; + public Int64|ResolvesToDouble|float|int $rate; /** - * @param Int64|ResolvesToFloat|float|int $rate 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. + * @param Int64|ResolvesToDouble|float|int $rate 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. */ - public function __construct(Int64|ResolvesToFloat|float|int $rate) + public function __construct(Int64|ResolvesToDouble|float|int $rate) { $this->rate = $rate; } diff --git a/src/Builder/Aggregation/SecondAggregation.php b/src/Builder/Aggregation/SecondAggregation.php index 068957878..0e6a17d3d 100644 --- a/src/Builder/Aggregation/SecondAggregation.php +++ b/src/Builder/Aggregation/SecondAggregation.php @@ -6,9 +6,8 @@ namespace MongoDB\Builder\Aggregation; -use DateTimeInterface; -use MongoDB\BSON\Int64; use MongoDB\BSON\ObjectId; +use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToDate; @@ -28,18 +27,18 @@ class SecondAggregation implements ResolvesToInt public const NAME = '$second'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ - public DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; + /** @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ + public ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; /** @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public ResolvesToString|Optional|string $timezone; /** - * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public function __construct( - DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|Optional|string $timezone = Optional::Undefined, ) { $this->date = $date; diff --git a/src/Builder/Aggregation/SetDifferenceAggregation.php b/src/Builder/Aggregation/SetDifferenceAggregation.php index 054c7b0d5..e613a4f22 100644 --- a/src/Builder/Aggregation/SetDifferenceAggregation.php +++ b/src/Builder/Aggregation/SetDifferenceAggregation.php @@ -8,7 +8,6 @@ use MongoDB\BSON\PackedArray; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToArray; use MongoDB\Model\BSONArray; @@ -22,15 +21,15 @@ class SetDifferenceAggregation implements ResolvesToArray public const NAME = '$setDifference'; public const ENCODE = \MongoDB\Builder\Encode::Array; - /** @param BSONArray|PackedArray|ResolvesToArray|list $expression1 The arguments can be any valid expression as long as they each resolve to an array. */ + /** @param BSONArray|PackedArray|ResolvesToArray|array $expression1 The arguments can be any valid expression as long as they each resolve to an array. */ public PackedArray|ResolvesToArray|BSONArray|array $expression1; - /** @param BSONArray|PackedArray|ResolvesToArray|list $expression2 The arguments can be any valid expression as long as they each resolve to an array. */ + /** @param BSONArray|PackedArray|ResolvesToArray|array $expression2 The arguments can be any valid expression as long as they each resolve to an array. */ public PackedArray|ResolvesToArray|BSONArray|array $expression2; /** - * @param BSONArray|PackedArray|ResolvesToArray|list $expression1 The arguments can be any valid expression as long as they each resolve to an array. - * @param BSONArray|PackedArray|ResolvesToArray|list $expression2 The arguments can be any valid expression as long as they each resolve to an array. + * @param BSONArray|PackedArray|ResolvesToArray|array $expression1 The arguments can be any valid expression as long as they each resolve to an array. + * @param BSONArray|PackedArray|ResolvesToArray|array $expression2 The arguments can be any valid expression as long as they each resolve to an array. */ public function __construct( PackedArray|ResolvesToArray|BSONArray|array $expression1, @@ -39,10 +38,12 @@ public function __construct( if (\is_array($expression1) && ! \array_is_list($expression1)) { throw new \InvalidArgumentException('Expected $expression1 argument to be a list, got an associative array.'); } + $this->expression1 = $expression1; if (\is_array($expression2) && ! \array_is_list($expression2)) { throw new \InvalidArgumentException('Expected $expression2 argument to be a list, got an associative array.'); } + $this->expression2 = $expression2; } } diff --git a/src/Builder/Aggregation/SetEqualsAggregation.php b/src/Builder/Aggregation/SetEqualsAggregation.php index c87bb1a13..11f865d3d 100644 --- a/src/Builder/Aggregation/SetEqualsAggregation.php +++ b/src/Builder/Aggregation/SetEqualsAggregation.php @@ -8,7 +8,6 @@ use MongoDB\BSON\PackedArray; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToArray; use MongoDB\Builder\Expression\ResolvesToBool; use MongoDB\Model\BSONArray; @@ -23,11 +22,11 @@ class SetEqualsAggregation implements ResolvesToBool public const NAME = '$setEquals'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param list ...$expression */ + /** @param list ...$expression */ public array $expression; /** - * @param BSONArray|PackedArray|ResolvesToArray|list ...$expression + * @param BSONArray|PackedArray|ResolvesToArray|array ...$expression * @no-named-arguments */ public function __construct(PackedArray|ResolvesToArray|BSONArray|array ...$expression) @@ -36,7 +35,7 @@ public function __construct(PackedArray|ResolvesToArray|BSONArray|array ...$expr throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); } if (! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression arguments to be a list of BSONArray|PackedArray|ResolvesToArray|list, named arguments are not supported'); + throw new \InvalidArgumentException('Expected $expression arguments to be a list (array), named arguments are not supported'); } $this->expression = $expression; } diff --git a/src/Builder/Aggregation/SetFieldAggregation.php b/src/Builder/Aggregation/SetFieldAggregation.php index 8484fa2ac..4f05611ed 100644 --- a/src/Builder/Aggregation/SetFieldAggregation.php +++ b/src/Builder/Aggregation/SetFieldAggregation.php @@ -6,12 +6,22 @@ namespace MongoDB\Builder\Aggregation; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Decimal128; use MongoDB\BSON\Document; +use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; +use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; +use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Expression\ResolvesToObject; use MongoDB\Builder\Expression\ResolvesToString; +use MongoDB\Builder\Type\ExpressionInterface; +use MongoDB\Model\BSONArray; use stdClass; /** @@ -32,24 +42,28 @@ class SetFieldAggregation implements ResolvesToObject public Document|Serializable|ResolvesToObject|stdClass|array $input; /** - * @param ExpressionInterface|mixed $value The value that you want to assign to field. value can be any valid expression. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $value 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. */ - public mixed $value; + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $value; /** * @param ResolvesToString|non-empty-string $field 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. * @param Document|ResolvesToObject|Serializable|array|stdClass $input Document that contains the field that you want to add or update. input must resolve to an object, missing, null, or undefined. - * @param ExpressionInterface|mixed $value The value that you want to assign to field. value can be any valid expression. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $value 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. */ public function __construct( ResolvesToString|string $field, Document|Serializable|ResolvesToObject|stdClass|array $input, - mixed $value, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $value, ) { $this->field = $field; $this->input = $input; + if (\is_array($value) && ! \array_is_list($value)) { + throw new \InvalidArgumentException('Expected $value argument to be a list, got an associative array.'); + } + $this->value = $value; } } diff --git a/src/Builder/Aggregation/SetIntersectionAggregation.php b/src/Builder/Aggregation/SetIntersectionAggregation.php index 4669cb4f8..95ba07813 100644 --- a/src/Builder/Aggregation/SetIntersectionAggregation.php +++ b/src/Builder/Aggregation/SetIntersectionAggregation.php @@ -8,7 +8,6 @@ use MongoDB\BSON\PackedArray; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToArray; use MongoDB\Model\BSONArray; @@ -22,11 +21,11 @@ class SetIntersectionAggregation implements ResolvesToArray public const NAME = '$setIntersection'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param list ...$expression */ + /** @param list ...$expression */ public array $expression; /** - * @param BSONArray|PackedArray|ResolvesToArray|list ...$expression + * @param BSONArray|PackedArray|ResolvesToArray|array ...$expression * @no-named-arguments */ public function __construct(PackedArray|ResolvesToArray|BSONArray|array ...$expression) @@ -35,7 +34,7 @@ public function __construct(PackedArray|ResolvesToArray|BSONArray|array ...$expr throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); } if (! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression arguments to be a list of BSONArray|PackedArray|ResolvesToArray|list, named arguments are not supported'); + throw new \InvalidArgumentException('Expected $expression arguments to be a list (array), named arguments are not supported'); } $this->expression = $expression; } diff --git a/src/Builder/Aggregation/SetIsSubsetAggregation.php b/src/Builder/Aggregation/SetIsSubsetAggregation.php index 13234d863..178150cda 100644 --- a/src/Builder/Aggregation/SetIsSubsetAggregation.php +++ b/src/Builder/Aggregation/SetIsSubsetAggregation.php @@ -8,7 +8,6 @@ use MongoDB\BSON\PackedArray; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToArray; use MongoDB\Builder\Expression\ResolvesToBool; use MongoDB\Model\BSONArray; @@ -23,15 +22,15 @@ class SetIsSubsetAggregation implements ResolvesToBool public const NAME = '$setIsSubset'; public const ENCODE = \MongoDB\Builder\Encode::Array; - /** @param BSONArray|PackedArray|ResolvesToArray|list $expression1 */ + /** @param BSONArray|PackedArray|ResolvesToArray|array $expression1 */ public PackedArray|ResolvesToArray|BSONArray|array $expression1; - /** @param BSONArray|PackedArray|ResolvesToArray|list $expression2 */ + /** @param BSONArray|PackedArray|ResolvesToArray|array $expression2 */ public PackedArray|ResolvesToArray|BSONArray|array $expression2; /** - * @param BSONArray|PackedArray|ResolvesToArray|list $expression1 - * @param BSONArray|PackedArray|ResolvesToArray|list $expression2 + * @param BSONArray|PackedArray|ResolvesToArray|array $expression1 + * @param BSONArray|PackedArray|ResolvesToArray|array $expression2 */ public function __construct( PackedArray|ResolvesToArray|BSONArray|array $expression1, @@ -40,10 +39,12 @@ public function __construct( if (\is_array($expression1) && ! \array_is_list($expression1)) { throw new \InvalidArgumentException('Expected $expression1 argument to be a list, got an associative array.'); } + $this->expression1 = $expression1; if (\is_array($expression2) && ! \array_is_list($expression2)) { throw new \InvalidArgumentException('Expected $expression2 argument to be a list, got an associative array.'); } + $this->expression2 = $expression2; } } diff --git a/src/Builder/Aggregation/SetUnionAggregation.php b/src/Builder/Aggregation/SetUnionAggregation.php index 53c1f0ac2..8804b4bbd 100644 --- a/src/Builder/Aggregation/SetUnionAggregation.php +++ b/src/Builder/Aggregation/SetUnionAggregation.php @@ -8,7 +8,6 @@ use MongoDB\BSON\PackedArray; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToArray; use MongoDB\Model\BSONArray; @@ -22,11 +21,11 @@ class SetUnionAggregation implements ResolvesToArray public const NAME = '$setUnion'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param list ...$expression */ + /** @param list ...$expression */ public array $expression; /** - * @param BSONArray|PackedArray|ResolvesToArray|list ...$expression + * @param BSONArray|PackedArray|ResolvesToArray|array ...$expression * @no-named-arguments */ public function __construct(PackedArray|ResolvesToArray|BSONArray|array ...$expression) @@ -35,7 +34,7 @@ public function __construct(PackedArray|ResolvesToArray|BSONArray|array ...$expr throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); } if (! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression arguments to be a list of BSONArray|PackedArray|ResolvesToArray|list, named arguments are not supported'); + throw new \InvalidArgumentException('Expected $expression arguments to be a list (array), named arguments are not supported'); } $this->expression = $expression; } diff --git a/src/Builder/Aggregation/ShiftAggregation.php b/src/Builder/Aggregation/ShiftAggregation.php index 705f117a5..ad33cea5d 100644 --- a/src/Builder/Aggregation/ShiftAggregation.php +++ b/src/Builder/Aggregation/ShiftAggregation.php @@ -6,9 +6,22 @@ namespace MongoDB\Builder\Aggregation; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Document; use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; +use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; +use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; +use MongoDB\Builder\Expression\ResolvesToAny; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Type\ExpressionInterface; +use MongoDB\Model\BSONArray; +use stdClass; /** * Returns the value from an expression applied to a document in a specified position relative to the current document in the $setWindowFields stage partition. @@ -16,45 +29,56 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/shift/ */ -class ShiftAggregation implements ExpressionInterface +class ShiftAggregation implements ResolvesToAny { public const NAME = '$shift'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param ExpressionInterface|mixed $output Specifies an expression to evaluate and return in the output. */ - public mixed $output; + /** @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $output Specifies an expression to evaluate and return in the output. */ + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $output; /** - * @param Int64|int $by Specifies an integer with a numeric document position relative to the current document in the output. + * @param int $by 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. */ - public Int64|int $by; + public int $by; /** - * @param ExpressionInterface|mixed $default 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. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $default 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. */ - public mixed $default; + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $default; /** - * @param ExpressionInterface|mixed $output Specifies an expression to evaluate and return in the output. - * @param Int64|int $by Specifies an integer with a numeric document position relative to the current document in the output. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $output Specifies an expression to evaluate and return in the output. + * @param int $by 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. - * @param ExpressionInterface|mixed $default 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. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $default 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. */ - public function __construct(mixed $output, Int64|int $by, mixed $default) - { + public function __construct( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $output, + int $by, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $default, + ) { + if (\is_array($output) && ! \array_is_list($output)) { + throw new \InvalidArgumentException('Expected $output argument to be a list, got an associative array.'); + } + $this->output = $output; $this->by = $by; + if (\is_array($default) && ! \array_is_list($default)) { + throw new \InvalidArgumentException('Expected $default argument to be a list, got an associative array.'); + } + $this->default = $default; } } diff --git a/src/Builder/Aggregation/SinAggregation.php b/src/Builder/Aggregation/SinAggregation.php index 59b59711c..0f96b1aca 100644 --- a/src/Builder/Aggregation/SinAggregation.php +++ b/src/Builder/Aggregation/SinAggregation.php @@ -11,6 +11,8 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToDecimal; use MongoDB\Builder\Expression\ResolvesToDouble; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Expression\ResolvesToLong; use MongoDB\Builder\Expression\ResolvesToNumber; /** @@ -24,17 +26,18 @@ class SinAggregation implements ResolvesToDouble, ResolvesToDecimal public const ENCODE = \MongoDB\Builder\Encode::Single; /** - * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $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. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression $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. */ - public Decimal128|Int64|ResolvesToNumber|float|int $expression; + public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression; /** - * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $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. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression $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. */ - public function __construct(Decimal128|Int64|ResolvesToNumber|float|int $expression) - { + public function __construct( + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression, + ) { $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/SinhAggregation.php b/src/Builder/Aggregation/SinhAggregation.php index 480a9b321..897d183af 100644 --- a/src/Builder/Aggregation/SinhAggregation.php +++ b/src/Builder/Aggregation/SinhAggregation.php @@ -11,6 +11,8 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToDecimal; use MongoDB\Builder\Expression\ResolvesToDouble; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Expression\ResolvesToLong; use MongoDB\Builder\Expression\ResolvesToNumber; /** @@ -24,17 +26,18 @@ class SinhAggregation implements ResolvesToDouble, ResolvesToDecimal public const ENCODE = \MongoDB\Builder\Encode::Single; /** - * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $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. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression $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. */ - public Decimal128|Int64|ResolvesToNumber|float|int $expression; + public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression; /** - * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $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. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression $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. */ - public function __construct(Decimal128|Int64|ResolvesToNumber|float|int $expression) - { + public function __construct( + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression, + ) { $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/SizeAggregation.php b/src/Builder/Aggregation/SizeAggregation.php index d033904b8..ea1f8bb38 100644 --- a/src/Builder/Aggregation/SizeAggregation.php +++ b/src/Builder/Aggregation/SizeAggregation.php @@ -8,7 +8,6 @@ use MongoDB\BSON\PackedArray; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToArray; use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Model\BSONArray; @@ -23,17 +22,18 @@ class SizeAggregation implements ResolvesToInt public const NAME = '$size'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param BSONArray|PackedArray|ResolvesToArray|list $expression The argument for $size can be any expression as long as it resolves to an array. */ + /** @param BSONArray|PackedArray|ResolvesToArray|array $expression The argument for $size can be any expression as long as it resolves to an array. */ public PackedArray|ResolvesToArray|BSONArray|array $expression; /** - * @param BSONArray|PackedArray|ResolvesToArray|list $expression The argument for $size can be any expression as long as it resolves to an array. + * @param BSONArray|PackedArray|ResolvesToArray|array $expression The argument for $size can be any expression as long as it resolves to an array. */ public function __construct(PackedArray|ResolvesToArray|BSONArray|array $expression) { if (\is_array($expression) && ! \array_is_list($expression)) { throw new \InvalidArgumentException('Expected $expression argument to be a list, got an associative array.'); } + $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/SliceAggregation.php b/src/Builder/Aggregation/SliceAggregation.php index 942db265e..70f491fb6 100644 --- a/src/Builder/Aggregation/SliceAggregation.php +++ b/src/Builder/Aggregation/SliceAggregation.php @@ -6,10 +6,8 @@ namespace MongoDB\Builder\Aggregation; -use MongoDB\BSON\Int64; use MongoDB\BSON\PackedArray; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToArray; use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Optional; @@ -25,40 +23,41 @@ class SliceAggregation implements ResolvesToArray public const NAME = '$slice'; public const ENCODE = \MongoDB\Builder\Encode::Array; - /** @param BSONArray|PackedArray|ResolvesToArray|list $expression Any valid expression as long as it resolves to an array. */ + /** @param BSONArray|PackedArray|ResolvesToArray|array $expression Any valid expression as long as it resolves to an array. */ public PackedArray|ResolvesToArray|BSONArray|array $expression; /** - * @param Int64|ResolvesToInt|int $n Any valid expression as long as it resolves to an integer. If position is specified, n must resolve to a positive integer. + * @param ResolvesToInt|int $n 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. */ - public Int64|ResolvesToInt|int $n; + public ResolvesToInt|int $n; /** - * @param Int64|Optional|ResolvesToInt|int $position Any valid expression as long as it resolves to an integer. + * @param Optional|ResolvesToInt|int $position 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. */ - public Int64|ResolvesToInt|Optional|int $position; + public ResolvesToInt|Optional|int $position; /** - * @param BSONArray|PackedArray|ResolvesToArray|list $expression Any valid expression as long as it resolves to an array. - * @param Int64|ResolvesToInt|int $n Any valid expression as long as it resolves to an integer. If position is specified, n must resolve to a positive integer. + * @param BSONArray|PackedArray|ResolvesToArray|array $expression Any valid expression as long as it resolves to an array. + * @param ResolvesToInt|int $n 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. - * @param Int64|Optional|ResolvesToInt|int $position Any valid expression as long as it resolves to an integer. + * @param Optional|ResolvesToInt|int $position 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. */ public function __construct( PackedArray|ResolvesToArray|BSONArray|array $expression, - Int64|ResolvesToInt|int $n, - Int64|ResolvesToInt|Optional|int $position = Optional::Undefined, + ResolvesToInt|int $n, + ResolvesToInt|Optional|int $position = Optional::Undefined, ) { if (\is_array($expression) && ! \array_is_list($expression)) { throw new \InvalidArgumentException('Expected $expression argument to be a list, got an associative array.'); } + $this->expression = $expression; $this->n = $n; $this->position = $position; diff --git a/src/Builder/Aggregation/SortArrayAggregation.php b/src/Builder/Aggregation/SortArrayAggregation.php index 480639f47..6e1bfe561 100644 --- a/src/Builder/Aggregation/SortArrayAggregation.php +++ b/src/Builder/Aggregation/SortArrayAggregation.php @@ -6,9 +6,10 @@ namespace MongoDB\Builder\Aggregation; +use MongoDB\BSON\Document; use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Serializable; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToArray; use MongoDB\Model\BSONArray; use stdClass; @@ -23,21 +24,24 @@ class SortArrayAggregation implements ResolvesToArray public const NAME = '$sortArray'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param BSONArray|PackedArray|ResolvesToArray|list $input The array to be sorted. */ + /** @param BSONArray|PackedArray|ResolvesToArray|array $input The array to be sorted. */ public PackedArray|ResolvesToArray|BSONArray|array $input; - /** @param array|stdClass $sortBy The document specifies a sort ordering. */ - public stdClass|array $sortBy; + /** @param Document|Serializable|array|stdClass $sortBy The document specifies a sort ordering. */ + public Document|Serializable|stdClass|array $sortBy; /** - * @param BSONArray|PackedArray|ResolvesToArray|list $input The array to be sorted. - * @param array|stdClass $sortBy The document specifies a sort ordering. + * @param BSONArray|PackedArray|ResolvesToArray|array $input The array to be sorted. + * @param Document|Serializable|array|stdClass $sortBy The document specifies a sort ordering. */ - public function __construct(PackedArray|ResolvesToArray|BSONArray|array $input, stdClass|array $sortBy) - { + public function __construct( + PackedArray|ResolvesToArray|BSONArray|array $input, + Document|Serializable|stdClass|array $sortBy, + ) { if (\is_array($input) && ! \array_is_list($input)) { throw new \InvalidArgumentException('Expected $input argument to be a list, got an associative array.'); } + $this->input = $input; $this->sortBy = $sortBy; } diff --git a/src/Builder/Aggregation/SqrtAggregation.php b/src/Builder/Aggregation/SqrtAggregation.php index b819efe0a..d797c5291 100644 --- a/src/Builder/Aggregation/SqrtAggregation.php +++ b/src/Builder/Aggregation/SqrtAggregation.php @@ -9,7 +9,10 @@ use MongoDB\BSON\Decimal128; use MongoDB\BSON\Int64; use MongoDB\Builder\Encode; +use MongoDB\Builder\Expression\ResolvesToDecimal; use MongoDB\Builder\Expression\ResolvesToDouble; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Expression\ResolvesToLong; use MongoDB\Builder\Expression\ResolvesToNumber; /** @@ -22,14 +25,15 @@ class SqrtAggregation implements ResolvesToDouble public const NAME = '$sqrt'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param Decimal128|Int64|ResolvesToNumber|float|int $number The argument can be any valid expression as long as it resolves to a non-negative number. */ - public Decimal128|Int64|ResolvesToNumber|float|int $number; + /** @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $number The argument can be any valid expression as long as it resolves to a non-negative number. */ + public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $number; /** - * @param Decimal128|Int64|ResolvesToNumber|float|int $number The argument can be any valid expression as long as it resolves to a non-negative number. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $number The argument can be any valid expression as long as it resolves to a non-negative number. */ - public function __construct(Decimal128|Int64|ResolvesToNumber|float|int $number) - { + public function __construct( + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $number, + ) { $this->number = $number; } } diff --git a/src/Builder/Aggregation/StdDevPopAggregation.php b/src/Builder/Aggregation/StdDevPopAggregation.php index 357a3f047..c785007c8 100644 --- a/src/Builder/Aggregation/StdDevPopAggregation.php +++ b/src/Builder/Aggregation/StdDevPopAggregation.php @@ -9,8 +9,12 @@ use MongoDB\BSON\Decimal128; use MongoDB\BSON\Int64; use MongoDB\Builder\Encode; +use MongoDB\Builder\Expression\ResolvesToDecimal; use MongoDB\Builder\Expression\ResolvesToDouble; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Expression\ResolvesToLong; use MongoDB\Builder\Expression\ResolvesToNumber; +use MongoDB\Builder\Type\AccumulatorInterface; /** * Calculates the population standard deviation of the input values. Use if the values encompass the entire population of data you want to represent and do not wish to generalize about a larger population. $stdDevPop ignores non-numeric values. @@ -24,20 +28,21 @@ class StdDevPopAggregation implements ResolvesToDouble, AccumulatorInterface public const NAME = '$stdDevPop'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param list ...$expression */ + /** @param list ...$expression */ public array $expression; /** - * @param Decimal128|Int64|ResolvesToNumber|float|int ...$expression + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int ...$expression * @no-named-arguments */ - public function __construct(Decimal128|Int64|ResolvesToNumber|float|int ...$expression) - { + public function __construct( + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int ...$expression, + ) { if (\count($expression) < 1) { throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); } if (! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression arguments to be a list of Decimal128|Int64|ResolvesToNumber|float|int, named arguments are not supported'); + throw new \InvalidArgumentException('Expected $expression arguments to be a list (array), named arguments are not supported'); } $this->expression = $expression; } diff --git a/src/Builder/Aggregation/StdDevSampAggregation.php b/src/Builder/Aggregation/StdDevSampAggregation.php index 044b2189e..32b24e776 100644 --- a/src/Builder/Aggregation/StdDevSampAggregation.php +++ b/src/Builder/Aggregation/StdDevSampAggregation.php @@ -9,8 +9,12 @@ use MongoDB\BSON\Decimal128; use MongoDB\BSON\Int64; use MongoDB\Builder\Encode; +use MongoDB\Builder\Expression\ResolvesToDecimal; use MongoDB\Builder\Expression\ResolvesToDouble; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Expression\ResolvesToLong; use MongoDB\Builder\Expression\ResolvesToNumber; +use MongoDB\Builder\Type\AccumulatorInterface; /** * 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. @@ -24,20 +28,21 @@ class StdDevSampAggregation implements ResolvesToDouble, AccumulatorInterface public const NAME = '$stdDevSamp'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param list ...$expression */ + /** @param list ...$expression */ public array $expression; /** - * @param Decimal128|Int64|ResolvesToNumber|float|int ...$expression + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int ...$expression * @no-named-arguments */ - public function __construct(Decimal128|Int64|ResolvesToNumber|float|int ...$expression) - { + public function __construct( + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int ...$expression, + ) { if (\count($expression) < 1) { throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); } if (! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression arguments to be a list of Decimal128|Int64|ResolvesToNumber|float|int, named arguments are not supported'); + throw new \InvalidArgumentException('Expected $expression arguments to be a list (array), named arguments are not supported'); } $this->expression = $expression; } diff --git a/src/Builder/Aggregation/SubstrAggregation.php b/src/Builder/Aggregation/SubstrAggregation.php index ea3517378..fad3bd99d 100644 --- a/src/Builder/Aggregation/SubstrAggregation.php +++ b/src/Builder/Aggregation/SubstrAggregation.php @@ -6,7 +6,6 @@ namespace MongoDB\Builder\Aggregation; -use MongoDB\BSON\Int64; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Expression\ResolvesToString; @@ -24,22 +23,19 @@ class SubstrAggregation implements ResolvesToString /** @param ResolvesToString|non-empty-string $string */ public ResolvesToString|string $string; - /** @param Int64|ResolvesToInt|int $start If start is a negative number, $substr returns an empty string "". */ - public Int64|ResolvesToInt|int $start; + /** @param ResolvesToInt|int $start If start is a negative number, $substr returns an empty string "". */ + public ResolvesToInt|int $start; - /** @param Int64|ResolvesToInt|int $length If length is a negative number, $substr returns a substring that starts at the specified index and includes the rest of the string. */ - public Int64|ResolvesToInt|int $length; + /** @param ResolvesToInt|int $length If length is a negative number, $substr returns a substring that starts at the specified index and includes the rest of the string. */ + public ResolvesToInt|int $length; /** * @param ResolvesToString|non-empty-string $string - * @param Int64|ResolvesToInt|int $start If start is a negative number, $substr returns an empty string "". - * @param Int64|ResolvesToInt|int $length If length is a negative number, $substr returns a substring that starts at the specified index and includes the rest of the string. + * @param ResolvesToInt|int $start If start is a negative number, $substr returns an empty string "". + * @param ResolvesToInt|int $length If length is a negative number, $substr returns a substring that starts at the specified index and includes the rest of the string. */ - public function __construct( - ResolvesToString|string $string, - Int64|ResolvesToInt|int $start, - Int64|ResolvesToInt|int $length, - ) { + public function __construct(ResolvesToString|string $string, ResolvesToInt|int $start, ResolvesToInt|int $length) + { $this->string = $string; $this->start = $start; $this->length = $length; diff --git a/src/Builder/Aggregation/SubstrBytesAggregation.php b/src/Builder/Aggregation/SubstrBytesAggregation.php index 0fdd73906..7a168f558 100644 --- a/src/Builder/Aggregation/SubstrBytesAggregation.php +++ b/src/Builder/Aggregation/SubstrBytesAggregation.php @@ -6,7 +6,6 @@ namespace MongoDB\Builder\Aggregation; -use MongoDB\BSON\Int64; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Expression\ResolvesToString; @@ -24,22 +23,19 @@ class SubstrBytesAggregation implements ResolvesToString /** @param ResolvesToString|non-empty-string $string */ public ResolvesToString|string $string; - /** @param Int64|ResolvesToInt|int $start If start is a negative number, $substr returns an empty string "". */ - public Int64|ResolvesToInt|int $start; + /** @param ResolvesToInt|int $start If start is a negative number, $substr returns an empty string "". */ + public ResolvesToInt|int $start; - /** @param Int64|ResolvesToInt|int $length If length is a negative number, $substr returns a substring that starts at the specified index and includes the rest of the string. */ - public Int64|ResolvesToInt|int $length; + /** @param ResolvesToInt|int $length If length is a negative number, $substr returns a substring that starts at the specified index and includes the rest of the string. */ + public ResolvesToInt|int $length; /** * @param ResolvesToString|non-empty-string $string - * @param Int64|ResolvesToInt|int $start If start is a negative number, $substr returns an empty string "". - * @param Int64|ResolvesToInt|int $length If length is a negative number, $substr returns a substring that starts at the specified index and includes the rest of the string. + * @param ResolvesToInt|int $start If start is a negative number, $substr returns an empty string "". + * @param ResolvesToInt|int $length If length is a negative number, $substr returns a substring that starts at the specified index and includes the rest of the string. */ - public function __construct( - ResolvesToString|string $string, - Int64|ResolvesToInt|int $start, - Int64|ResolvesToInt|int $length, - ) { + public function __construct(ResolvesToString|string $string, ResolvesToInt|int $start, ResolvesToInt|int $length) + { $this->string = $string; $this->start = $start; $this->length = $length; diff --git a/src/Builder/Aggregation/SubstrCPAggregation.php b/src/Builder/Aggregation/SubstrCPAggregation.php index ef4a764f5..734fcacab 100644 --- a/src/Builder/Aggregation/SubstrCPAggregation.php +++ b/src/Builder/Aggregation/SubstrCPAggregation.php @@ -6,7 +6,6 @@ namespace MongoDB\Builder\Aggregation; -use MongoDB\BSON\Int64; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Expression\ResolvesToString; @@ -24,22 +23,19 @@ class SubstrCPAggregation implements ResolvesToString /** @param ResolvesToString|non-empty-string $string */ public ResolvesToString|string $string; - /** @param Int64|ResolvesToInt|int $start If start is a negative number, $substr returns an empty string "". */ - public Int64|ResolvesToInt|int $start; + /** @param ResolvesToInt|int $start If start is a negative number, $substr returns an empty string "". */ + public ResolvesToInt|int $start; - /** @param Int64|ResolvesToInt|int $length If length is a negative number, $substr returns a substring that starts at the specified index and includes the rest of the string. */ - public Int64|ResolvesToInt|int $length; + /** @param ResolvesToInt|int $length If length is a negative number, $substr returns a substring that starts at the specified index and includes the rest of the string. */ + public ResolvesToInt|int $length; /** * @param ResolvesToString|non-empty-string $string - * @param Int64|ResolvesToInt|int $start If start is a negative number, $substr returns an empty string "". - * @param Int64|ResolvesToInt|int $length If length is a negative number, $substr returns a substring that starts at the specified index and includes the rest of the string. + * @param ResolvesToInt|int $start If start is a negative number, $substr returns an empty string "". + * @param ResolvesToInt|int $length If length is a negative number, $substr returns a substring that starts at the specified index and includes the rest of the string. */ - public function __construct( - ResolvesToString|string $string, - Int64|ResolvesToInt|int $start, - Int64|ResolvesToInt|int $length, - ) { + public function __construct(ResolvesToString|string $string, ResolvesToInt|int $start, ResolvesToInt|int $length) + { $this->string = $string; $this->start = $start; $this->length = $length; diff --git a/src/Builder/Aggregation/SubtractAggregation.php b/src/Builder/Aggregation/SubtractAggregation.php index cbc834f58..ffa736e36 100644 --- a/src/Builder/Aggregation/SubtractAggregation.php +++ b/src/Builder/Aggregation/SubtractAggregation.php @@ -6,12 +6,15 @@ namespace MongoDB\Builder\Aggregation; -use DateTimeInterface; use MongoDB\BSON\Decimal128; use MongoDB\BSON\Int64; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToDate; +use MongoDB\Builder\Expression\ResolvesToDecimal; +use MongoDB\Builder\Expression\ResolvesToDouble; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Expression\ResolvesToLong; use MongoDB\Builder\Expression\ResolvesToNumber; /** @@ -24,19 +27,19 @@ class SubtractAggregation implements ResolvesToNumber, ResolvesToDate public const NAME = '$subtract'; public const ENCODE = \MongoDB\Builder\Encode::Array; - /** @param DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int $expression1 */ - public DateTimeInterface|Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int $expression1; + /** @param Decimal128|Int64|ResolvesToDate|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|UTCDateTime|float|int $expression1 */ + public Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression1; - /** @param DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int $expression2 */ - public DateTimeInterface|Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int $expression2; + /** @param Decimal128|Int64|ResolvesToDate|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|UTCDateTime|float|int $expression2 */ + public Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression2; /** - * @param DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int $expression1 - * @param DateTimeInterface|Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int $expression2 + * @param Decimal128|Int64|ResolvesToDate|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|UTCDateTime|float|int $expression1 + * @param Decimal128|Int64|ResolvesToDate|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|UTCDateTime|float|int $expression2 */ public function __construct( - DateTimeInterface|Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int $expression1, - DateTimeInterface|Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int $expression2, + Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression1, + Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression2, ) { $this->expression1 = $expression1; $this->expression2 = $expression2; diff --git a/src/Builder/Aggregation/SumAggregation.php b/src/Builder/Aggregation/SumAggregation.php index 10d4fbc19..b46ce52e1 100644 --- a/src/Builder/Aggregation/SumAggregation.php +++ b/src/Builder/Aggregation/SumAggregation.php @@ -9,7 +9,12 @@ use MongoDB\BSON\Decimal128; use MongoDB\BSON\Int64; use MongoDB\Builder\Encode; +use MongoDB\Builder\Expression\ResolvesToDecimal; +use MongoDB\Builder\Expression\ResolvesToDouble; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Expression\ResolvesToLong; use MongoDB\Builder\Expression\ResolvesToNumber; +use MongoDB\Builder\Type\AccumulatorInterface; /** * Returns a sum of numerical values. Ignores non-numeric values. @@ -22,20 +27,21 @@ class SumAggregation implements ResolvesToNumber, AccumulatorInterface public const NAME = '$sum'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param list ...$expression */ + /** @param list ...$expression */ public array $expression; /** - * @param Decimal128|Int64|ResolvesToNumber|float|int ...$expression + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int ...$expression * @no-named-arguments */ - public function __construct(Decimal128|Int64|ResolvesToNumber|float|int ...$expression) - { + public function __construct( + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int ...$expression, + ) { if (\count($expression) < 1) { throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); } if (! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression arguments to be a list of Decimal128|Int64|ResolvesToNumber|float|int, named arguments are not supported'); + throw new \InvalidArgumentException('Expected $expression arguments to be a list (array), named arguments are not supported'); } $this->expression = $expression; } diff --git a/src/Builder/Aggregation/SwitchAggregation.php b/src/Builder/Aggregation/SwitchAggregation.php index 63296f554..eac030021 100644 --- a/src/Builder/Aggregation/SwitchAggregation.php +++ b/src/Builder/Aggregation/SwitchAggregation.php @@ -6,24 +6,36 @@ namespace MongoDB\Builder\Aggregation; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Document; +use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; +use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; +use MongoDB\Builder\Expression\ResolvesToAny; +use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Optional; +use MongoDB\Builder\Type\ExpressionInterface; use MongoDB\Model\BSONArray; +use stdClass; /** * 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. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/switch/ */ -class SwitchAggregation implements ExpressionInterface +class SwitchAggregation implements ResolvesToAny { public const NAME = '$switch'; public const ENCODE = \MongoDB\Builder\Encode::Object; /** - * @param BSONArray|PackedArray|list $branches An array of control branch documents. Each branch is a document with the following fields: + * @param BSONArray|PackedArray|array $branches 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. @@ -31,25 +43,32 @@ class SwitchAggregation implements ExpressionInterface public PackedArray|BSONArray|array $branches; /** - * @param ExpressionInterface|Optional|mixed $default The path to take if no branch case expression evaluates to true. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|Optional|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $default 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. */ - public mixed $default; + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|Optional|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $default; /** - * @param BSONArray|PackedArray|list $branches An array of control branch documents. Each branch is a document with the following fields: + * @param BSONArray|PackedArray|array $branches 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. - * @param ExpressionInterface|Optional|mixed $default The path to take if no branch case expression evaluates to true. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|Optional|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $default 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. */ - public function __construct(PackedArray|BSONArray|array $branches, mixed $default = Optional::Undefined) - { + public function __construct( + PackedArray|BSONArray|array $branches, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|Optional|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $default = Optional::Undefined, + ) { if (\is_array($branches) && ! \array_is_list($branches)) { throw new \InvalidArgumentException('Expected $branches argument to be a list, got an associative array.'); } + $this->branches = $branches; + if (\is_array($default) && ! \array_is_list($default)) { + throw new \InvalidArgumentException('Expected $default argument to be a list, got an associative array.'); + } + $this->default = $default; } } diff --git a/src/Builder/Aggregation/TanAggregation.php b/src/Builder/Aggregation/TanAggregation.php index 5d355f615..a2e9de353 100644 --- a/src/Builder/Aggregation/TanAggregation.php +++ b/src/Builder/Aggregation/TanAggregation.php @@ -11,6 +11,8 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToDecimal; use MongoDB\Builder\Expression\ResolvesToDouble; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Expression\ResolvesToLong; use MongoDB\Builder\Expression\ResolvesToNumber; /** @@ -24,17 +26,18 @@ class TanAggregation implements ResolvesToDouble, ResolvesToDecimal public const ENCODE = \MongoDB\Builder\Encode::Single; /** - * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $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. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression $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. */ - public Decimal128|Int64|ResolvesToNumber|float|int $expression; + public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression; /** - * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $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. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression $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. */ - public function __construct(Decimal128|Int64|ResolvesToNumber|float|int $expression) - { + public function __construct( + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression, + ) { $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/TanhAggregation.php b/src/Builder/Aggregation/TanhAggregation.php index 1ab3680b2..d7a3c1c69 100644 --- a/src/Builder/Aggregation/TanhAggregation.php +++ b/src/Builder/Aggregation/TanhAggregation.php @@ -11,6 +11,8 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToDecimal; use MongoDB\Builder\Expression\ResolvesToDouble; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Expression\ResolvesToLong; use MongoDB\Builder\Expression\ResolvesToNumber; /** @@ -24,17 +26,18 @@ class TanhAggregation implements ResolvesToDouble, ResolvesToDecimal public const ENCODE = \MongoDB\Builder\Encode::Single; /** - * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $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. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression $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. */ - public Decimal128|Int64|ResolvesToNumber|float|int $expression; + public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression; /** - * @param Decimal128|Int64|ResolvesToNumber|float|int $expression $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. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression $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. */ - public function __construct(Decimal128|Int64|ResolvesToNumber|float|int $expression) - { + public function __construct( + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression, + ) { $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/ToBoolAggregation.php b/src/Builder/Aggregation/ToBoolAggregation.php index 4e2889a5f..e39e03c3c 100644 --- a/src/Builder/Aggregation/ToBoolAggregation.php +++ b/src/Builder/Aggregation/ToBoolAggregation.php @@ -6,9 +6,22 @@ namespace MongoDB\Builder\Aggregation; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Document; +use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; +use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; +use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToBool; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Type\ExpressionInterface; +use MongoDB\Model\BSONArray; +use stdClass; /** * Converts value to a boolean. @@ -21,14 +34,19 @@ class ToBoolAggregation implements ResolvesToBool public const NAME = '$toBool'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param ExpressionInterface|mixed $expression */ - public mixed $expression; + /** @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression */ + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression; /** - * @param ExpressionInterface|mixed $expression + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression */ - public function __construct(mixed $expression) - { + public function __construct( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, + ) { + if (\is_array($expression) && ! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression argument to be a list, got an associative array.'); + } + $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/ToDateAggregation.php b/src/Builder/Aggregation/ToDateAggregation.php index f3022884b..dd2fab1ed 100644 --- a/src/Builder/Aggregation/ToDateAggregation.php +++ b/src/Builder/Aggregation/ToDateAggregation.php @@ -6,9 +6,22 @@ namespace MongoDB\Builder\Aggregation; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Document; +use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; +use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; +use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToDate; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Type\ExpressionInterface; +use MongoDB\Model\BSONArray; +use stdClass; /** * Converts value to a Date. @@ -21,14 +34,19 @@ class ToDateAggregation implements ResolvesToDate public const NAME = '$toDate'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param ExpressionInterface|mixed $expression */ - public mixed $expression; + /** @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression */ + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression; /** - * @param ExpressionInterface|mixed $expression + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression */ - public function __construct(mixed $expression) - { + public function __construct( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, + ) { + if (\is_array($expression) && ! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression argument to be a list, got an associative array.'); + } + $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/ToDecimalAggregation.php b/src/Builder/Aggregation/ToDecimalAggregation.php index 608a34604..e712804d6 100644 --- a/src/Builder/Aggregation/ToDecimalAggregation.php +++ b/src/Builder/Aggregation/ToDecimalAggregation.php @@ -6,9 +6,22 @@ namespace MongoDB\Builder\Aggregation; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Document; +use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; +use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; +use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToDecimal; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Type\ExpressionInterface; +use MongoDB\Model\BSONArray; +use stdClass; /** * Converts value to a Decimal128. @@ -21,14 +34,19 @@ class ToDecimalAggregation implements ResolvesToDecimal public const NAME = '$toDecimal'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param ExpressionInterface|mixed $expression */ - public mixed $expression; + /** @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression */ + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression; /** - * @param ExpressionInterface|mixed $expression + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression */ - public function __construct(mixed $expression) - { + public function __construct( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, + ) { + if (\is_array($expression) && ! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression argument to be a list, got an associative array.'); + } + $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/ToDoubleAggregation.php b/src/Builder/Aggregation/ToDoubleAggregation.php index 7ed811274..6893e85ba 100644 --- a/src/Builder/Aggregation/ToDoubleAggregation.php +++ b/src/Builder/Aggregation/ToDoubleAggregation.php @@ -6,9 +6,22 @@ namespace MongoDB\Builder\Aggregation; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Document; +use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; +use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; +use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToDouble; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Type\ExpressionInterface; +use MongoDB\Model\BSONArray; +use stdClass; /** * Converts value to a double. @@ -21,14 +34,19 @@ class ToDoubleAggregation implements ResolvesToDouble public const NAME = '$toDouble'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param ExpressionInterface|mixed $expression */ - public mixed $expression; + /** @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression */ + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression; /** - * @param ExpressionInterface|mixed $expression + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression */ - public function __construct(mixed $expression) - { + public function __construct( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, + ) { + if (\is_array($expression) && ! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression argument to be a list, got an associative array.'); + } + $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/ToIntAggregation.php b/src/Builder/Aggregation/ToIntAggregation.php index c13fdbecc..b216d8a21 100644 --- a/src/Builder/Aggregation/ToIntAggregation.php +++ b/src/Builder/Aggregation/ToIntAggregation.php @@ -6,9 +6,21 @@ namespace MongoDB\Builder\Aggregation; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Document; +use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; +use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; +use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Type\ExpressionInterface; +use MongoDB\Model\BSONArray; +use stdClass; /** * Converts value to an integer. @@ -21,14 +33,19 @@ class ToIntAggregation implements ResolvesToInt public const NAME = '$toInt'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param ExpressionInterface|mixed $expression */ - public mixed $expression; + /** @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression */ + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression; /** - * @param ExpressionInterface|mixed $expression + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression */ - public function __construct(mixed $expression) - { + public function __construct( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, + ) { + if (\is_array($expression) && ! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression argument to be a list, got an associative array.'); + } + $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/ToLongAggregation.php b/src/Builder/Aggregation/ToLongAggregation.php index 72a1079c9..c05b1542d 100644 --- a/src/Builder/Aggregation/ToLongAggregation.php +++ b/src/Builder/Aggregation/ToLongAggregation.php @@ -6,9 +6,22 @@ namespace MongoDB\Builder\Aggregation; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Document; +use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; +use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; +use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; +use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Expression\ResolvesToLong; +use MongoDB\Builder\Type\ExpressionInterface; +use MongoDB\Model\BSONArray; +use stdClass; /** * Converts value to a long. @@ -21,14 +34,19 @@ class ToLongAggregation implements ResolvesToLong public const NAME = '$toLong'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param ExpressionInterface|mixed $expression */ - public mixed $expression; + /** @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression */ + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression; /** - * @param ExpressionInterface|mixed $expression + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression */ - public function __construct(mixed $expression) - { + public function __construct( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, + ) { + if (\is_array($expression) && ! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression argument to be a list, got an associative array.'); + } + $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/ToObjectIdAggregation.php b/src/Builder/Aggregation/ToObjectIdAggregation.php index d09242270..cffc9a46d 100644 --- a/src/Builder/Aggregation/ToObjectIdAggregation.php +++ b/src/Builder/Aggregation/ToObjectIdAggregation.php @@ -6,9 +6,22 @@ namespace MongoDB\Builder\Aggregation; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Document; +use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; +use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; +use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; +use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Expression\ResolvesToObjectId; +use MongoDB\Builder\Type\ExpressionInterface; +use MongoDB\Model\BSONArray; +use stdClass; /** * Converts value to an ObjectId. @@ -21,14 +34,19 @@ class ToObjectIdAggregation implements ResolvesToObjectId public const NAME = '$toObjectId'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param ExpressionInterface|mixed $expression */ - public mixed $expression; + /** @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression */ + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression; /** - * @param ExpressionInterface|mixed $expression + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression */ - public function __construct(mixed $expression) - { + public function __construct( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, + ) { + if (\is_array($expression) && ! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression argument to be a list, got an associative array.'); + } + $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/ToStringAggregation.php b/src/Builder/Aggregation/ToStringAggregation.php index 533d3efcf..e43edd0ce 100644 --- a/src/Builder/Aggregation/ToStringAggregation.php +++ b/src/Builder/Aggregation/ToStringAggregation.php @@ -6,9 +6,22 @@ namespace MongoDB\Builder\Aggregation; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Document; +use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; +use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; +use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; +use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Expression\ResolvesToString; +use MongoDB\Builder\Type\ExpressionInterface; +use MongoDB\Model\BSONArray; +use stdClass; /** * Converts value to a string. @@ -21,14 +34,19 @@ class ToStringAggregation implements ResolvesToString public const NAME = '$toString'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param ExpressionInterface|mixed $expression */ - public mixed $expression; + /** @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression */ + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression; /** - * @param ExpressionInterface|mixed $expression + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression */ - public function __construct(mixed $expression) - { + public function __construct( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, + ) { + if (\is_array($expression) && ! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression argument to be a list, got an associative array.'); + } + $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/TopAggregation.php b/src/Builder/Aggregation/TopAggregation.php index d82450393..6c3744f6a 100644 --- a/src/Builder/Aggregation/TopAggregation.php +++ b/src/Builder/Aggregation/TopAggregation.php @@ -6,8 +6,21 @@ namespace MongoDB\Builder\Aggregation; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Document; +use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; +use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; +use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Type\AccumulatorInterface; +use MongoDB\Builder\Type\ExpressionInterface; +use MongoDB\Model\BSONArray; use stdClass; /** @@ -23,19 +36,25 @@ class TopAggregation implements AccumulatorInterface public const NAME = '$top'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param array|stdClass $sortBy Specifies the order of results, with syntax similar to $sort. */ - public stdClass|array $sortBy; + /** @param Document|Serializable|array|stdClass $sortBy Specifies the order of results, with syntax similar to $sort. */ + public Document|Serializable|stdClass|array $sortBy; - /** @param ExpressionInterface|mixed $output Represents the output for each element in the group and can be any expression. */ - public mixed $output; + /** @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $output Represents the output for each element in the group and can be any expression. */ + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $output; /** - * @param array|stdClass $sortBy Specifies the order of results, with syntax similar to $sort. - * @param ExpressionInterface|mixed $output Represents the output for each element in the group and can be any expression. + * @param Document|Serializable|array|stdClass $sortBy Specifies the order of results, with syntax similar to $sort. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $output Represents the output for each element in the group and can be any expression. */ - public function __construct(stdClass|array $sortBy, mixed $output) - { + public function __construct( + Document|Serializable|stdClass|array $sortBy, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $output, + ) { $this->sortBy = $sortBy; + if (\is_array($output) && ! \array_is_list($output)) { + throw new \InvalidArgumentException('Expected $output argument to be a list, got an associative array.'); + } + $this->output = $output; } } diff --git a/src/Builder/Aggregation/TopNAggregation.php b/src/Builder/Aggregation/TopNAggregation.php index 148927e69..d4b8bdb47 100644 --- a/src/Builder/Aggregation/TopNAggregation.php +++ b/src/Builder/Aggregation/TopNAggregation.php @@ -6,10 +6,21 @@ namespace MongoDB\Builder\Aggregation; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Document; use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; +use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; +use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Type\AccumulatorInterface; +use MongoDB\Builder\Type\ExpressionInterface; +use MongoDB\Model\BSONArray; use stdClass; /** @@ -25,24 +36,31 @@ class TopNAggregation implements AccumulatorInterface public const NAME = '$topN'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param Int64|ResolvesToInt|int $n 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. */ - public Int64|ResolvesToInt|int $n; + /** @param ResolvesToInt|int $n 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. */ + public ResolvesToInt|int $n; - /** @param array|stdClass $sortBy Specifies the order of results, with syntax similar to $sort. */ - public stdClass|array $sortBy; + /** @param Document|Serializable|array|stdClass $sortBy Specifies the order of results, with syntax similar to $sort. */ + public Document|Serializable|stdClass|array $sortBy; - /** @param ExpressionInterface|mixed $output Represents the output for each element in the group and can be any expression. */ - public mixed $output; + /** @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $output Represents the output for each element in the group and can be any expression. */ + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $output; /** - * @param Int64|ResolvesToInt|int $n 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. - * @param array|stdClass $sortBy Specifies the order of results, with syntax similar to $sort. - * @param ExpressionInterface|mixed $output Represents the output for each element in the group and can be any expression. + * @param ResolvesToInt|int $n 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. + * @param Document|Serializable|array|stdClass $sortBy Specifies the order of results, with syntax similar to $sort. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $output Represents the output for each element in the group and can be any expression. */ - public function __construct(Int64|ResolvesToInt|int $n, stdClass|array $sortBy, mixed $output) - { + public function __construct( + ResolvesToInt|int $n, + Document|Serializable|stdClass|array $sortBy, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $output, + ) { $this->n = $n; $this->sortBy = $sortBy; + if (\is_array($output) && ! \array_is_list($output)) { + throw new \InvalidArgumentException('Expected $output argument to be a list, got an associative array.'); + } + $this->output = $output; } } diff --git a/src/Builder/Aggregation/TruncAggregation.php b/src/Builder/Aggregation/TruncAggregation.php index 8844f851a..619a9179c 100644 --- a/src/Builder/Aggregation/TruncAggregation.php +++ b/src/Builder/Aggregation/TruncAggregation.php @@ -9,7 +9,10 @@ use MongoDB\BSON\Decimal128; use MongoDB\BSON\Int64; use MongoDB\Builder\Encode; +use MongoDB\Builder\Expression\ResolvesToDecimal; +use MongoDB\Builder\Expression\ResolvesToDouble; use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Expression\ResolvesToLong; use MongoDB\Builder\Expression\ResolvesToNumber; use MongoDB\Builder\Expression\ResolvesToString; use MongoDB\Builder\Optional; @@ -25,22 +28,22 @@ class TruncAggregation implements ResolvesToString public const ENCODE = \MongoDB\Builder\Encode::Array; /** - * @param Decimal128|Int64|ResolvesToNumber|float|int $number Can be any valid expression that resolves to a number. Specifically, the expression must resolve to an integer, double, decimal, or long. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $number 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. */ - public Decimal128|Int64|ResolvesToNumber|float|int $number; + public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $number; - /** @param Int64|Optional|ResolvesToInt|int $place Can be any valid expression that resolves to an integer between -20 and 100, exclusive. e.g. -20 < place < 100. Defaults to 0. */ - public Int64|ResolvesToInt|Optional|int $place; + /** @param Optional|ResolvesToInt|int $place Can be any valid expression that resolves to an integer between -20 and 100, exclusive. e.g. -20 < place < 100. Defaults to 0. */ + public ResolvesToInt|Optional|int $place; /** - * @param Decimal128|Int64|ResolvesToNumber|float|int $number Can be any valid expression that resolves to a number. Specifically, the expression must resolve to an integer, double, decimal, or long. + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $number 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. - * @param Int64|Optional|ResolvesToInt|int $place Can be any valid expression that resolves to an integer between -20 and 100, exclusive. e.g. -20 < place < 100. Defaults to 0. + * @param Optional|ResolvesToInt|int $place Can be any valid expression that resolves to an integer between -20 and 100, exclusive. e.g. -20 < place < 100. Defaults to 0. */ public function __construct( - Decimal128|Int64|ResolvesToNumber|float|int $number, - Int64|ResolvesToInt|Optional|int $place = Optional::Undefined, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $number, + ResolvesToInt|Optional|int $place = Optional::Undefined, ) { $this->number = $number; $this->place = $place; diff --git a/src/Builder/Aggregation/TsIncrementAggregation.php b/src/Builder/Aggregation/TsIncrementAggregation.php index 488b48c69..afd4ff69e 100644 --- a/src/Builder/Aggregation/TsIncrementAggregation.php +++ b/src/Builder/Aggregation/TsIncrementAggregation.php @@ -6,7 +6,7 @@ namespace MongoDB\Builder\Aggregation; -use MongoDB\BSON\Int64; +use MongoDB\BSON\Timestamp; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToLong; use MongoDB\Builder\Expression\ResolvesToTimestamp; @@ -22,13 +22,13 @@ class TsIncrementAggregation implements ResolvesToLong public const NAME = '$tsIncrement'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param Int64|ResolvesToTimestamp|int $expression */ - public Int64|ResolvesToTimestamp|int $expression; + /** @param ResolvesToTimestamp|Timestamp|int $expression */ + public Timestamp|ResolvesToTimestamp|int $expression; /** - * @param Int64|ResolvesToTimestamp|int $expression + * @param ResolvesToTimestamp|Timestamp|int $expression */ - public function __construct(Int64|ResolvesToTimestamp|int $expression) + public function __construct(Timestamp|ResolvesToTimestamp|int $expression) { $this->expression = $expression; } diff --git a/src/Builder/Aggregation/TsSecondAggregation.php b/src/Builder/Aggregation/TsSecondAggregation.php index 3b2dfed36..12678baa1 100644 --- a/src/Builder/Aggregation/TsSecondAggregation.php +++ b/src/Builder/Aggregation/TsSecondAggregation.php @@ -6,7 +6,7 @@ namespace MongoDB\Builder\Aggregation; -use MongoDB\BSON\Int64; +use MongoDB\BSON\Timestamp; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToLong; use MongoDB\Builder\Expression\ResolvesToTimestamp; @@ -22,13 +22,13 @@ class TsSecondAggregation implements ResolvesToLong public const NAME = '$tsSecond'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param Int64|ResolvesToTimestamp|int $expression */ - public Int64|ResolvesToTimestamp|int $expression; + /** @param ResolvesToTimestamp|Timestamp|int $expression */ + public Timestamp|ResolvesToTimestamp|int $expression; /** - * @param Int64|ResolvesToTimestamp|int $expression + * @param ResolvesToTimestamp|Timestamp|int $expression */ - public function __construct(Int64|ResolvesToTimestamp|int $expression) + public function __construct(Timestamp|ResolvesToTimestamp|int $expression) { $this->expression = $expression; } diff --git a/src/Builder/Aggregation/TypeAggregation.php b/src/Builder/Aggregation/TypeAggregation.php index 2d5a1958e..0ceaa1bc9 100644 --- a/src/Builder/Aggregation/TypeAggregation.php +++ b/src/Builder/Aggregation/TypeAggregation.php @@ -6,9 +6,22 @@ namespace MongoDB\Builder\Aggregation; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Document; +use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; +use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; +use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; +use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Expression\ResolvesToString; +use MongoDB\Builder\Type\ExpressionInterface; +use MongoDB\Model\BSONArray; +use stdClass; /** * Return the BSON data type of the field. @@ -20,14 +33,19 @@ class TypeAggregation implements ResolvesToString public const NAME = '$type'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param ExpressionInterface|mixed $expression */ - public mixed $expression; + /** @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression */ + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression; /** - * @param ExpressionInterface|mixed $expression + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression */ - public function __construct(mixed $expression) - { + public function __construct( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, + ) { + if (\is_array($expression) && ! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression argument to be a list, got an associative array.'); + } + $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/WeekAggregation.php b/src/Builder/Aggregation/WeekAggregation.php index f67e5fe78..e3ae7d643 100644 --- a/src/Builder/Aggregation/WeekAggregation.php +++ b/src/Builder/Aggregation/WeekAggregation.php @@ -6,9 +6,8 @@ namespace MongoDB\Builder\Aggregation; -use DateTimeInterface; -use MongoDB\BSON\Int64; use MongoDB\BSON\ObjectId; +use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToDate; @@ -28,18 +27,18 @@ class WeekAggregation implements ResolvesToInt public const NAME = '$week'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ - public DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; + /** @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ + public ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; /** @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public ResolvesToString|Optional|string $timezone; /** - * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public function __construct( - DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|Optional|string $timezone = Optional::Undefined, ) { $this->date = $date; diff --git a/src/Builder/Aggregation/YearAggregation.php b/src/Builder/Aggregation/YearAggregation.php index c63909766..178218dcc 100644 --- a/src/Builder/Aggregation/YearAggregation.php +++ b/src/Builder/Aggregation/YearAggregation.php @@ -6,9 +6,8 @@ namespace MongoDB\Builder\Aggregation; -use DateTimeInterface; -use MongoDB\BSON\Int64; use MongoDB\BSON\ObjectId; +use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToDate; @@ -28,18 +27,18 @@ class YearAggregation implements ResolvesToInt public const NAME = '$year'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ - public DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; + /** @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. */ + public ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; /** @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public ResolvesToString|Optional|string $timezone; /** - * @param DateTimeInterface|Int64|ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. + * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public function __construct( - DateTimeInterface|Int64|ObjectId|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, + ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|Optional|string $timezone = Optional::Undefined, ) { $this->date = $date; diff --git a/src/Builder/Aggregation/ZipAggregation.php b/src/Builder/Aggregation/ZipAggregation.php index 234c60d7f..7c1489e07 100644 --- a/src/Builder/Aggregation/ZipAggregation.php +++ b/src/Builder/Aggregation/ZipAggregation.php @@ -8,7 +8,6 @@ use MongoDB\BSON\PackedArray; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToArray; use MongoDB\Model\BSONArray; @@ -23,7 +22,7 @@ class ZipAggregation implements ResolvesToArray public const ENCODE = \MongoDB\Builder\Encode::Object; /** - * @param BSONArray|PackedArray|ResolvesToArray|list $inputs An array of expressions that resolve to arrays. The elements of these input arrays combine to form the arrays of the output array. + * @param BSONArray|PackedArray|ResolvesToArray|array $inputs 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. */ @@ -36,19 +35,19 @@ class ZipAggregation implements ResolvesToArray public bool $useLongestLength; /** - * @param BSONArray|PackedArray|list $defaults 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. + * @param BSONArray|PackedArray|array $defaults 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. */ public PackedArray|BSONArray|array $defaults; /** - * @param BSONArray|PackedArray|ResolvesToArray|list $inputs An array of expressions that resolve to arrays. The elements of these input arrays combine to form the arrays of the output array. + * @param BSONArray|PackedArray|ResolvesToArray|array $inputs 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. * @param bool $useLongestLength 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. - * @param BSONArray|PackedArray|list $defaults 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. + * @param BSONArray|PackedArray|array $defaults 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. */ @@ -60,11 +59,13 @@ public function __construct( if (\is_array($inputs) && ! \array_is_list($inputs)) { throw new \InvalidArgumentException('Expected $inputs argument to be a list, got an associative array.'); } + $this->inputs = $inputs; $this->useLongestLength = $useLongestLength; if (\is_array($defaults) && ! \array_is_list($defaults)) { throw new \InvalidArgumentException('Expected $defaults argument to be a list, got an associative array.'); } + $this->defaults = $defaults; } } diff --git a/src/Builder/BuilderEncoder.php b/src/Builder/BuilderEncoder.php index bbcd20780..e13f89747 100644 --- a/src/Builder/BuilderEncoder.php +++ b/src/Builder/BuilderEncoder.php @@ -3,13 +3,13 @@ namespace MongoDB\Builder; use LogicException; -use MongoDB\Builder\Aggregation\AccumulatorInterface; -use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\FieldPath; use MongoDB\Builder\Expression\Variable; -use MongoDB\Builder\Query\QueryInterface; use MongoDB\Builder\Stage\GroupStage; -use MongoDB\Builder\Stage\StageInterface; +use MongoDB\Builder\Type\AccumulatorInterface; +use MongoDB\Builder\Type\ExpressionInterface; +use MongoDB\Builder\Type\QueryInterface; +use MongoDB\Builder\Type\StageInterface; use MongoDB\Codec\EncodeIfSupported; use MongoDB\Codec\Encoder; use MongoDB\Exception\UnsupportedValueException; diff --git a/src/Builder/Expression.php b/src/Builder/Expression.php index 92b835419..3ab38672a 100644 --- a/src/Builder/Expression.php +++ b/src/Builder/Expression.php @@ -7,21 +7,20 @@ namespace MongoDB\Builder; use MongoDB\Builder\Expression\ArrayFieldPath; -use MongoDB\Builder\Expression\BinaryFieldPath; +use MongoDB\Builder\Expression\BinDataFieldPath; use MongoDB\Builder\Expression\BoolFieldPath; use MongoDB\Builder\Expression\DateFieldPath; use MongoDB\Builder\Expression\DecimalFieldPath; use MongoDB\Builder\Expression\DoubleFieldPath; -use MongoDB\Builder\Expression\FieldName; use MongoDB\Builder\Expression\FieldPath; -use MongoDB\Builder\Expression\FloatFieldPath; use MongoDB\Builder\Expression\IntFieldPath; -use MongoDB\Builder\Expression\Literal; +use MongoDB\Builder\Expression\JavascriptFieldPath; use MongoDB\Builder\Expression\LongFieldPath; use MongoDB\Builder\Expression\NullFieldPath; use MongoDB\Builder\Expression\NumberFieldPath; use MongoDB\Builder\Expression\ObjectFieldPath; use MongoDB\Builder\Expression\ObjectIdFieldPath; +use MongoDB\Builder\Expression\RegexFieldPath; use MongoDB\Builder\Expression\StringFieldPath; use MongoDB\Builder\Expression\TimestampFieldPath; use MongoDB\Builder\Expression\Variable; @@ -33,9 +32,9 @@ public static function arrayFieldPath(string $expression): ArrayFieldPath return new ArrayFieldPath($expression); } - public static function binaryFieldPath(string $expression): BinaryFieldPath + public static function binDataFieldPath(string $expression): BinDataFieldPath { - return new BinaryFieldPath($expression); + return new BinDataFieldPath($expression); } public static function boolFieldPath(string $expression): BoolFieldPath @@ -58,29 +57,19 @@ public static function doubleFieldPath(string $expression): DoubleFieldPath return new DoubleFieldPath($expression); } - public static function fieldName(string $expression): FieldName - { - return new FieldName($expression); - } - public static function fieldPath(string $expression): FieldPath { return new FieldPath($expression); } - public static function floatFieldPath(string $expression): FloatFieldPath - { - return new FloatFieldPath($expression); - } - public static function intFieldPath(string $expression): IntFieldPath { return new IntFieldPath($expression); } - public static function literal(string $expression): Literal + public static function javascriptFieldPath(string $expression): JavascriptFieldPath { - return new Literal($expression); + return new JavascriptFieldPath($expression); } public static function longFieldPath(string $expression): LongFieldPath @@ -108,6 +97,11 @@ public static function objectIdFieldPath(string $expression): ObjectIdFieldPath return new ObjectIdFieldPath($expression); } + public static function regexFieldPath(string $expression): RegexFieldPath + { + return new RegexFieldPath($expression); + } + public static function stringFieldPath(string $expression): StringFieldPath { return new StringFieldPath($expression); diff --git a/src/Builder/Expression/BinaryFieldPath.php b/src/Builder/Expression/BinDataFieldPath.php similarity index 78% rename from src/Builder/Expression/BinaryFieldPath.php rename to src/Builder/Expression/BinDataFieldPath.php index 9813faee6..cff641e13 100644 --- a/src/Builder/Expression/BinaryFieldPath.php +++ b/src/Builder/Expression/BinDataFieldPath.php @@ -6,7 +6,7 @@ namespace MongoDB\Builder\Expression; -class BinaryFieldPath extends FieldPath implements ResolvesToBinary +class BinDataFieldPath extends FieldPath implements ResolvesToBinData { public string $expression; diff --git a/src/Builder/Expression/FieldPath.php b/src/Builder/Expression/FieldPath.php index 15f6192d2..2b580c314 100644 --- a/src/Builder/Expression/FieldPath.php +++ b/src/Builder/Expression/FieldPath.php @@ -6,6 +6,8 @@ namespace MongoDB\Builder\Expression; +use MongoDB\Builder\Type\ExpressionInterface; + class FieldPath implements ExpressionInterface { public string $expression; diff --git a/src/Builder/Expression/FloatFieldPath.php b/src/Builder/Expression/JavascriptFieldPath.php similarity index 76% rename from src/Builder/Expression/FloatFieldPath.php rename to src/Builder/Expression/JavascriptFieldPath.php index d58f5ce06..21628de62 100644 --- a/src/Builder/Expression/FloatFieldPath.php +++ b/src/Builder/Expression/JavascriptFieldPath.php @@ -6,7 +6,7 @@ namespace MongoDB\Builder\Expression; -class FloatFieldPath extends FieldPath implements ResolvesToFloat +class JavascriptFieldPath extends FieldPath implements ResolvesToJavascript { public string $expression; diff --git a/src/Builder/Expression/Literal.php b/src/Builder/Expression/Literal.php deleted file mode 100644 index 0222123ba..000000000 --- a/src/Builder/Expression/Literal.php +++ /dev/null @@ -1,17 +0,0 @@ -expression = $expression; - } -} diff --git a/src/Builder/Expression/FieldName.php b/src/Builder/Expression/RegexFieldPath.php similarity index 79% rename from src/Builder/Expression/FieldName.php rename to src/Builder/Expression/RegexFieldPath.php index d76dd6aa0..812306228 100644 --- a/src/Builder/Expression/FieldName.php +++ b/src/Builder/Expression/RegexFieldPath.php @@ -6,7 +6,7 @@ namespace MongoDB\Builder\Expression; -class FieldName +class RegexFieldPath extends FieldPath implements ResolvesToRegex { public string $expression; diff --git a/src/Builder/Expression/ResolvesToBinary.php b/src/Builder/Expression/ResolvesToAny.php similarity index 54% rename from src/Builder/Expression/ResolvesToBinary.php rename to src/Builder/Expression/ResolvesToAny.php index 14b505a83..0625e7658 100644 --- a/src/Builder/Expression/ResolvesToBinary.php +++ b/src/Builder/Expression/ResolvesToAny.php @@ -6,6 +6,8 @@ namespace MongoDB\Builder\Expression; -interface ResolvesToBinary extends ExpressionInterface +use MongoDB\Builder\Type\ExpressionInterface; + +interface ResolvesToAny extends ExpressionInterface { } diff --git a/src/Builder/Expression/ResolvesToArray.php b/src/Builder/Expression/ResolvesToArray.php index 476fdf331..12ede39a9 100644 --- a/src/Builder/Expression/ResolvesToArray.php +++ b/src/Builder/Expression/ResolvesToArray.php @@ -6,6 +6,8 @@ namespace MongoDB\Builder\Expression; +use MongoDB\Builder\Type\ExpressionInterface; + interface ResolvesToArray extends ExpressionInterface { } diff --git a/src/Builder/Expression/ExpressionInterface.php b/src/Builder/Expression/ResolvesToBinData.php similarity index 53% rename from src/Builder/Expression/ExpressionInterface.php rename to src/Builder/Expression/ResolvesToBinData.php index bc1fa5551..d436851fa 100644 --- a/src/Builder/Expression/ExpressionInterface.php +++ b/src/Builder/Expression/ResolvesToBinData.php @@ -6,6 +6,8 @@ namespace MongoDB\Builder\Expression; -interface ExpressionInterface +use MongoDB\Builder\Type\ExpressionInterface; + +interface ResolvesToBinData extends ExpressionInterface { } diff --git a/src/Builder/Expression/ResolvesToBool.php b/src/Builder/Expression/ResolvesToBool.php index 6f81fb438..b5c61a2d0 100644 --- a/src/Builder/Expression/ResolvesToBool.php +++ b/src/Builder/Expression/ResolvesToBool.php @@ -6,6 +6,8 @@ namespace MongoDB\Builder\Expression; +use MongoDB\Builder\Type\ExpressionInterface; + interface ResolvesToBool extends ExpressionInterface { } diff --git a/src/Builder/Expression/ResolvesToDate.php b/src/Builder/Expression/ResolvesToDate.php index 87c276a5d..3b504c70e 100644 --- a/src/Builder/Expression/ResolvesToDate.php +++ b/src/Builder/Expression/ResolvesToDate.php @@ -6,6 +6,8 @@ namespace MongoDB\Builder\Expression; +use MongoDB\Builder\Type\ExpressionInterface; + interface ResolvesToDate extends ExpressionInterface { } diff --git a/src/Builder/Expression/ResolvesToDecimal.php b/src/Builder/Expression/ResolvesToDecimal.php index 7ae2e5450..68afb3236 100644 --- a/src/Builder/Expression/ResolvesToDecimal.php +++ b/src/Builder/Expression/ResolvesToDecimal.php @@ -6,6 +6,8 @@ namespace MongoDB\Builder\Expression; -interface ResolvesToDecimal extends ResolvesToNumber +use MongoDB\Builder\Type\ExpressionInterface; + +interface ResolvesToDecimal extends ExpressionInterface { } diff --git a/src/Builder/Expression/ResolvesToDouble.php b/src/Builder/Expression/ResolvesToDouble.php index 0c52ba433..68b4f50dd 100644 --- a/src/Builder/Expression/ResolvesToDouble.php +++ b/src/Builder/Expression/ResolvesToDouble.php @@ -6,6 +6,8 @@ namespace MongoDB\Builder\Expression; -interface ResolvesToDouble extends ResolvesToNumber +use MongoDB\Builder\Type\ExpressionInterface; + +interface ResolvesToDouble extends ExpressionInterface { } diff --git a/src/Builder/Expression/ResolvesToFloat.php b/src/Builder/Expression/ResolvesToFloat.php deleted file mode 100644 index dc6b88297..000000000 --- a/src/Builder/Expression/ResolvesToFloat.php +++ /dev/null @@ -1,11 +0,0 @@ - ...$value */ + /** @param list ...$value */ public array $value; /** - * @param mixed ...$value + * @param BSONArray|Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass ...$value * @no-named-arguments */ - public function __construct(mixed ...$value) - { + public function __construct( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|BSONArray|stdClass|array|bool|float|int|null|string ...$value, + ) { if (\count($value) < 1) { throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $value, got %d.', 1, \count($value))); } if (! \array_is_list($value)) { - throw new \InvalidArgumentException('Expected $value arguments to be a list of mixed, named arguments are not supported'); + throw new \InvalidArgumentException('Expected $value arguments to be a list (array), named arguments are not supported'); } $this->value = $value; } diff --git a/src/Builder/Query/AndQuery.php b/src/Builder/Query/AndQuery.php index dee936236..a072f15fe 100644 --- a/src/Builder/Query/AndQuery.php +++ b/src/Builder/Query/AndQuery.php @@ -6,7 +6,10 @@ namespace MongoDB\Builder\Query; +use MongoDB\BSON\Document; +use MongoDB\BSON\Serializable; use MongoDB\Builder\Encode; +use MongoDB\Builder\Type\QueryInterface; use stdClass; /** @@ -19,20 +22,20 @@ class AndQuery implements QueryInterface public const NAME = '$and'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param list ...$expression */ + /** @param list ...$expression */ public array $expression; /** - * @param QueryInterface|array|stdClass ...$expression + * @param Document|QueryInterface|Serializable|array|stdClass ...$expression * @no-named-arguments */ - public function __construct(QueryInterface|stdClass|array ...$expression) + public function __construct(Document|Serializable|QueryInterface|stdClass|array ...$expression) { if (\count($expression) < 1) { throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); } if (! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression arguments to be a list of QueryInterface|array|stdClass, named arguments are not supported'); + throw new \InvalidArgumentException('Expected $expression arguments to be a list (array), named arguments are not supported'); } $this->expression = $expression; } diff --git a/src/Builder/Query/BitsAllClearQuery.php b/src/Builder/Query/BitsAllClearQuery.php index 167fa9167..65cf5dafb 100644 --- a/src/Builder/Query/BitsAllClearQuery.php +++ b/src/Builder/Query/BitsAllClearQuery.php @@ -7,10 +7,9 @@ namespace MongoDB\Builder\Query; use MongoDB\BSON\Binary; -use MongoDB\BSON\Int64; use MongoDB\BSON\PackedArray; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; +use MongoDB\Builder\Type\QueryInterface; use MongoDB\Model\BSONArray; /** @@ -23,17 +22,18 @@ class BitsAllClearQuery implements QueryInterface public const NAME = '$bitsAllClear'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param BSONArray|Binary|Int64|PackedArray|int|list|non-empty-string $bitmask */ - public Binary|Int64|PackedArray|BSONArray|array|int|string $bitmask; + /** @param BSONArray|Binary|PackedArray|array|int|non-empty-string $bitmask */ + public Binary|PackedArray|BSONArray|array|int|string $bitmask; /** - * @param BSONArray|Binary|Int64|PackedArray|int|list|non-empty-string $bitmask + * @param BSONArray|Binary|PackedArray|array|int|non-empty-string $bitmask */ - public function __construct(Binary|Int64|PackedArray|BSONArray|array|int|string $bitmask) + public function __construct(Binary|PackedArray|BSONArray|array|int|string $bitmask) { if (\is_array($bitmask) && ! \array_is_list($bitmask)) { throw new \InvalidArgumentException('Expected $bitmask argument to be a list, got an associative array.'); } + $this->bitmask = $bitmask; } } diff --git a/src/Builder/Query/BitsAllSetQuery.php b/src/Builder/Query/BitsAllSetQuery.php index 136bd3d5b..af3c5f416 100644 --- a/src/Builder/Query/BitsAllSetQuery.php +++ b/src/Builder/Query/BitsAllSetQuery.php @@ -7,10 +7,9 @@ namespace MongoDB\Builder\Query; use MongoDB\BSON\Binary; -use MongoDB\BSON\Int64; use MongoDB\BSON\PackedArray; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; +use MongoDB\Builder\Type\QueryInterface; use MongoDB\Model\BSONArray; /** @@ -23,17 +22,18 @@ class BitsAllSetQuery implements QueryInterface public const NAME = '$bitsAllSet'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param BSONArray|Binary|Int64|PackedArray|int|list|non-empty-string $bitmask */ - public Binary|Int64|PackedArray|BSONArray|array|int|string $bitmask; + /** @param BSONArray|Binary|PackedArray|array|int|non-empty-string $bitmask */ + public Binary|PackedArray|BSONArray|array|int|string $bitmask; /** - * @param BSONArray|Binary|Int64|PackedArray|int|list|non-empty-string $bitmask + * @param BSONArray|Binary|PackedArray|array|int|non-empty-string $bitmask */ - public function __construct(Binary|Int64|PackedArray|BSONArray|array|int|string $bitmask) + public function __construct(Binary|PackedArray|BSONArray|array|int|string $bitmask) { if (\is_array($bitmask) && ! \array_is_list($bitmask)) { throw new \InvalidArgumentException('Expected $bitmask argument to be a list, got an associative array.'); } + $this->bitmask = $bitmask; } } diff --git a/src/Builder/Query/BitsAnyClearQuery.php b/src/Builder/Query/BitsAnyClearQuery.php index 2e65b8c63..86040db65 100644 --- a/src/Builder/Query/BitsAnyClearQuery.php +++ b/src/Builder/Query/BitsAnyClearQuery.php @@ -7,10 +7,9 @@ namespace MongoDB\Builder\Query; use MongoDB\BSON\Binary; -use MongoDB\BSON\Int64; use MongoDB\BSON\PackedArray; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; +use MongoDB\Builder\Type\QueryInterface; use MongoDB\Model\BSONArray; /** @@ -23,17 +22,18 @@ class BitsAnyClearQuery implements QueryInterface public const NAME = '$bitsAnyClear'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param BSONArray|Binary|Int64|PackedArray|int|list|non-empty-string $bitmask */ - public Binary|Int64|PackedArray|BSONArray|array|int|string $bitmask; + /** @param BSONArray|Binary|PackedArray|array|int|non-empty-string $bitmask */ + public Binary|PackedArray|BSONArray|array|int|string $bitmask; /** - * @param BSONArray|Binary|Int64|PackedArray|int|list|non-empty-string $bitmask + * @param BSONArray|Binary|PackedArray|array|int|non-empty-string $bitmask */ - public function __construct(Binary|Int64|PackedArray|BSONArray|array|int|string $bitmask) + public function __construct(Binary|PackedArray|BSONArray|array|int|string $bitmask) { if (\is_array($bitmask) && ! \array_is_list($bitmask)) { throw new \InvalidArgumentException('Expected $bitmask argument to be a list, got an associative array.'); } + $this->bitmask = $bitmask; } } diff --git a/src/Builder/Query/BitsAnySetQuery.php b/src/Builder/Query/BitsAnySetQuery.php index b9be52913..2fb1468da 100644 --- a/src/Builder/Query/BitsAnySetQuery.php +++ b/src/Builder/Query/BitsAnySetQuery.php @@ -7,10 +7,9 @@ namespace MongoDB\Builder\Query; use MongoDB\BSON\Binary; -use MongoDB\BSON\Int64; use MongoDB\BSON\PackedArray; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; +use MongoDB\Builder\Type\QueryInterface; use MongoDB\Model\BSONArray; /** @@ -23,17 +22,18 @@ class BitsAnySetQuery implements QueryInterface public const NAME = '$bitsAnySet'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param BSONArray|Binary|Int64|PackedArray|int|list|non-empty-string $bitmask */ - public Binary|Int64|PackedArray|BSONArray|array|int|string $bitmask; + /** @param BSONArray|Binary|PackedArray|array|int|non-empty-string $bitmask */ + public Binary|PackedArray|BSONArray|array|int|string $bitmask; /** - * @param BSONArray|Binary|Int64|PackedArray|int|list|non-empty-string $bitmask + * @param BSONArray|Binary|PackedArray|array|int|non-empty-string $bitmask */ - public function __construct(Binary|Int64|PackedArray|BSONArray|array|int|string $bitmask) + public function __construct(Binary|PackedArray|BSONArray|array|int|string $bitmask) { if (\is_array($bitmask) && ! \array_is_list($bitmask)) { throw new \InvalidArgumentException('Expected $bitmask argument to be a list, got an associative array.'); } + $this->bitmask = $bitmask; } } diff --git a/src/Builder/Query/BoxQuery.php b/src/Builder/Query/BoxQuery.php index 7e4f63a21..bd398cb62 100644 --- a/src/Builder/Query/BoxQuery.php +++ b/src/Builder/Query/BoxQuery.php @@ -8,7 +8,7 @@ use MongoDB\BSON\PackedArray; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; +use MongoDB\Builder\Type\QueryInterface; use MongoDB\Model\BSONArray; /** @@ -21,17 +21,18 @@ class BoxQuery implements QueryInterface public const NAME = '$box'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param BSONArray|PackedArray|list $value */ + /** @param BSONArray|PackedArray|array $value */ public PackedArray|BSONArray|array $value; /** - * @param BSONArray|PackedArray|list $value + * @param BSONArray|PackedArray|array $value */ public function __construct(PackedArray|BSONArray|array $value) { if (\is_array($value) && ! \array_is_list($value)) { throw new \InvalidArgumentException('Expected $value argument to be a list, got an associative array.'); } + $this->value = $value; } } diff --git a/src/Builder/Query/CenterQuery.php b/src/Builder/Query/CenterQuery.php index 01b9bfe40..c2d5a1811 100644 --- a/src/Builder/Query/CenterQuery.php +++ b/src/Builder/Query/CenterQuery.php @@ -8,7 +8,7 @@ use MongoDB\BSON\PackedArray; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; +use MongoDB\Builder\Type\QueryInterface; use MongoDB\Model\BSONArray; /** @@ -21,17 +21,18 @@ class CenterQuery implements QueryInterface public const NAME = '$center'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param BSONArray|PackedArray|list $value */ + /** @param BSONArray|PackedArray|array $value */ public PackedArray|BSONArray|array $value; /** - * @param BSONArray|PackedArray|list $value + * @param BSONArray|PackedArray|array $value */ public function __construct(PackedArray|BSONArray|array $value) { if (\is_array($value) && ! \array_is_list($value)) { throw new \InvalidArgumentException('Expected $value argument to be a list, got an associative array.'); } + $this->value = $value; } } diff --git a/src/Builder/Query/CenterSphereQuery.php b/src/Builder/Query/CenterSphereQuery.php index 9751ac0b2..530b4de9f 100644 --- a/src/Builder/Query/CenterSphereQuery.php +++ b/src/Builder/Query/CenterSphereQuery.php @@ -8,7 +8,7 @@ use MongoDB\BSON\PackedArray; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; +use MongoDB\Builder\Type\QueryInterface; use MongoDB\Model\BSONArray; /** @@ -21,17 +21,18 @@ class CenterSphereQuery implements QueryInterface public const NAME = '$centerSphere'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param BSONArray|PackedArray|list $value */ + /** @param BSONArray|PackedArray|array $value */ public PackedArray|BSONArray|array $value; /** - * @param BSONArray|PackedArray|list $value + * @param BSONArray|PackedArray|array $value */ public function __construct(PackedArray|BSONArray|array $value) { if (\is_array($value) && ! \array_is_list($value)) { throw new \InvalidArgumentException('Expected $value argument to be a list, got an associative array.'); } + $this->value = $value; } } diff --git a/src/Builder/Query/CommentQuery.php b/src/Builder/Query/CommentQuery.php index bb0a98ccb..e8a617ef5 100644 --- a/src/Builder/Query/CommentQuery.php +++ b/src/Builder/Query/CommentQuery.php @@ -7,14 +7,14 @@ namespace MongoDB\Builder\Query; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; +use MongoDB\Builder\Type\QueryInterface; /** * Adds a comment to a query predicate. * * @see https://www.mongodb.com/docs/manual/reference/operator/query/comment/ */ -class CommentQuery implements ExpressionInterface +class CommentQuery implements QueryInterface { public const NAME = '$comment'; public const ENCODE = \MongoDB\Builder\Encode::Single; diff --git a/src/Builder/Query/ElemMatchQuery.php b/src/Builder/Query/ElemMatchQuery.php index e308e254b..9580fec0f 100644 --- a/src/Builder/Query/ElemMatchQuery.php +++ b/src/Builder/Query/ElemMatchQuery.php @@ -9,6 +9,8 @@ use MongoDB\BSON\Document; use MongoDB\BSON\Serializable; use MongoDB\Builder\Encode; +use MongoDB\Builder\Type\ProjectionInterface; +use MongoDB\Builder\Type\QueryInterface; use stdClass; /** @@ -16,18 +18,18 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/query/elemMatch/ */ -class ElemMatchQuery implements QueryInterface +class ElemMatchQuery implements QueryInterface, ProjectionInterface { public const NAME = '$elemMatch'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param Document|Serializable|array|stdClass $queries */ - public Document|Serializable|stdClass|array $queries; + /** @param Document|QueryInterface|Serializable|array|stdClass $queries */ + public Document|Serializable|QueryInterface|stdClass|array $queries; /** - * @param Document|Serializable|array|stdClass $queries + * @param Document|QueryInterface|Serializable|array|stdClass $queries */ - public function __construct(Document|Serializable|stdClass|array $queries) + public function __construct(Document|Serializable|QueryInterface|stdClass|array $queries) { $this->queries = $queries; } diff --git a/src/Builder/Query/EqQuery.php b/src/Builder/Query/EqQuery.php index d2652687c..3dcb5e529 100644 --- a/src/Builder/Query/EqQuery.php +++ b/src/Builder/Query/EqQuery.php @@ -6,7 +6,21 @@ namespace MongoDB\Builder\Query; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Document; +use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; +use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; +use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Type\QueryInterface; +use MongoDB\Model\BSONArray; +use stdClass; /** * Matches values that are equal to a specified value. @@ -18,14 +32,19 @@ class EqQuery implements QueryInterface public const NAME = '$eq'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param mixed $value */ - public mixed $value; + /** @param BSONArray|Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $value */ + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|BSONArray|stdClass|array|bool|float|int|null|string $value; /** - * @param mixed $value + * @param BSONArray|Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $value */ - public function __construct(mixed $value) - { + public function __construct( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|BSONArray|stdClass|array|bool|float|int|null|string $value, + ) { + if (\is_array($value) && ! \array_is_list($value)) { + throw new \InvalidArgumentException('Expected $value argument to be a list, got an associative array.'); + } + $this->value = $value; } } diff --git a/src/Builder/Query/ExistsQuery.php b/src/Builder/Query/ExistsQuery.php index e3d8c2912..21d353c4a 100644 --- a/src/Builder/Query/ExistsQuery.php +++ b/src/Builder/Query/ExistsQuery.php @@ -7,6 +7,7 @@ namespace MongoDB\Builder\Query; use MongoDB\Builder\Encode; +use MongoDB\Builder\Type\QueryInterface; /** * Matches documents that have the specified field. diff --git a/src/Builder/Query/ExprQuery.php b/src/Builder/Query/ExprQuery.php index 7061dcf26..ff80b4f4e 100644 --- a/src/Builder/Query/ExprQuery.php +++ b/src/Builder/Query/ExprQuery.php @@ -6,8 +6,22 @@ namespace MongoDB\Builder\Query; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Document; +use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; +use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; +use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Type\ExpressionInterface; +use MongoDB\Builder\Type\QueryInterface; +use MongoDB\Model\BSONArray; +use stdClass; /** * Allows use of aggregation expressions within the query language. @@ -19,14 +33,19 @@ class ExprQuery implements QueryInterface public const NAME = '$expr'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param ExpressionInterface|mixed $expression */ - public mixed $expression; + /** @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression */ + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression; /** - * @param ExpressionInterface|mixed $expression + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression */ - public function __construct(mixed $expression) - { + public function __construct( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, + ) { + if (\is_array($expression) && ! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression argument to be a list, got an associative array.'); + } + $this->expression = $expression; } } diff --git a/src/Builder/Query/GeoIntersectsQuery.php b/src/Builder/Query/GeoIntersectsQuery.php index 770b11294..2639f6d00 100644 --- a/src/Builder/Query/GeoIntersectsQuery.php +++ b/src/Builder/Query/GeoIntersectsQuery.php @@ -6,7 +6,10 @@ namespace MongoDB\Builder\Query; +use MongoDB\BSON\Document; +use MongoDB\BSON\Serializable; use MongoDB\Builder\Encode; +use MongoDB\Builder\Type\QueryInterface; use stdClass; /** @@ -19,13 +22,13 @@ class GeoIntersectsQuery implements QueryInterface public const NAME = '$geoIntersects'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param array|stdClass $geometry */ - public stdClass|array $geometry; + /** @param Document|Serializable|array|stdClass $geometry */ + public Document|Serializable|stdClass|array $geometry; /** - * @param array|stdClass $geometry + * @param Document|Serializable|array|stdClass $geometry */ - public function __construct(stdClass|array $geometry) + public function __construct(Document|Serializable|stdClass|array $geometry) { $this->geometry = $geometry; } diff --git a/src/Builder/Query/GeoWithinQuery.php b/src/Builder/Query/GeoWithinQuery.php index 6fe9005f0..42b0b6017 100644 --- a/src/Builder/Query/GeoWithinQuery.php +++ b/src/Builder/Query/GeoWithinQuery.php @@ -6,7 +6,10 @@ namespace MongoDB\Builder\Query; +use MongoDB\BSON\Document; +use MongoDB\BSON\Serializable; use MongoDB\Builder\Encode; +use MongoDB\Builder\Type\QueryInterface; use stdClass; /** @@ -19,13 +22,13 @@ class GeoWithinQuery implements QueryInterface public const NAME = '$geoWithin'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param array|stdClass $geometry */ - public stdClass|array $geometry; + /** @param Document|Serializable|array|stdClass $geometry */ + public Document|Serializable|stdClass|array $geometry; /** - * @param array|stdClass $geometry + * @param Document|Serializable|array|stdClass $geometry */ - public function __construct(stdClass|array $geometry) + public function __construct(Document|Serializable|stdClass|array $geometry) { $this->geometry = $geometry; } diff --git a/src/Builder/Query/GeometryQuery.php b/src/Builder/Query/GeometryQuery.php index 9815d9d4c..afea4044e 100644 --- a/src/Builder/Query/GeometryQuery.php +++ b/src/Builder/Query/GeometryQuery.php @@ -10,7 +10,7 @@ use MongoDB\BSON\PackedArray; use MongoDB\BSON\Serializable; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; +use MongoDB\Builder\Type\QueryInterface; use MongoDB\Model\BSONArray; use stdClass; @@ -19,7 +19,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/query/geometry/ */ -class GeometryQuery implements ExpressionInterface +class GeometryQuery implements QueryInterface { public const NAME = '$geometry'; public const ENCODE = \MongoDB\Builder\Encode::Object; @@ -27,7 +27,7 @@ class GeometryQuery implements ExpressionInterface /** @param non-empty-string $type */ public string $type; - /** @param BSONArray|PackedArray|list $coordinates */ + /** @param BSONArray|PackedArray|array $coordinates */ public PackedArray|BSONArray|array $coordinates; /** @param Document|Serializable|array|stdClass $crs */ @@ -35,7 +35,7 @@ class GeometryQuery implements ExpressionInterface /** * @param non-empty-string $type - * @param BSONArray|PackedArray|list $coordinates + * @param BSONArray|PackedArray|array $coordinates * @param Document|Serializable|array|stdClass $crs */ public function __construct( @@ -47,6 +47,7 @@ public function __construct( if (\is_array($coordinates) && ! \array_is_list($coordinates)) { throw new \InvalidArgumentException('Expected $coordinates argument to be a list, got an associative array.'); } + $this->coordinates = $coordinates; $this->crs = $crs; } diff --git a/src/Builder/Query/GtQuery.php b/src/Builder/Query/GtQuery.php index 0d97be526..b5909169f 100644 --- a/src/Builder/Query/GtQuery.php +++ b/src/Builder/Query/GtQuery.php @@ -6,7 +6,21 @@ namespace MongoDB\Builder\Query; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Document; +use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; +use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; +use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Type\QueryInterface; +use MongoDB\Model\BSONArray; +use stdClass; /** * Matches values that are greater than a specified value. @@ -18,14 +32,19 @@ class GtQuery implements QueryInterface public const NAME = '$gt'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param mixed $value */ - public mixed $value; + /** @param BSONArray|Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $value */ + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|BSONArray|stdClass|array|bool|float|int|null|string $value; /** - * @param mixed $value + * @param BSONArray|Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $value */ - public function __construct(mixed $value) - { + public function __construct( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|BSONArray|stdClass|array|bool|float|int|null|string $value, + ) { + if (\is_array($value) && ! \array_is_list($value)) { + throw new \InvalidArgumentException('Expected $value argument to be a list, got an associative array.'); + } + $this->value = $value; } } diff --git a/src/Builder/Query/GteQuery.php b/src/Builder/Query/GteQuery.php index a221f982e..4fccdf020 100644 --- a/src/Builder/Query/GteQuery.php +++ b/src/Builder/Query/GteQuery.php @@ -6,7 +6,21 @@ namespace MongoDB\Builder\Query; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Document; +use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; +use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; +use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Type\QueryInterface; +use MongoDB\Model\BSONArray; +use stdClass; /** * Matches values that are greater than or equal to a specified value. @@ -18,14 +32,19 @@ class GteQuery implements QueryInterface public const NAME = '$gte'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param mixed $value */ - public mixed $value; + /** @param BSONArray|Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $value */ + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|BSONArray|stdClass|array|bool|float|int|null|string $value; /** - * @param mixed $value + * @param BSONArray|Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $value */ - public function __construct(mixed $value) - { + public function __construct( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|BSONArray|stdClass|array|bool|float|int|null|string $value, + ) { + if (\is_array($value) && ! \array_is_list($value)) { + throw new \InvalidArgumentException('Expected $value argument to be a list, got an associative array.'); + } + $this->value = $value; } } diff --git a/src/Builder/Query/InQuery.php b/src/Builder/Query/InQuery.php index 0d17fae2b..8dec39d76 100644 --- a/src/Builder/Query/InQuery.php +++ b/src/Builder/Query/InQuery.php @@ -8,7 +8,7 @@ use MongoDB\BSON\PackedArray; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; +use MongoDB\Builder\Type\QueryInterface; use MongoDB\Model\BSONArray; /** @@ -21,17 +21,18 @@ class InQuery implements QueryInterface public const NAME = '$in'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param BSONArray|PackedArray|list $value */ + /** @param BSONArray|PackedArray|array $value */ public PackedArray|BSONArray|array $value; /** - * @param BSONArray|PackedArray|list $value + * @param BSONArray|PackedArray|array $value */ public function __construct(PackedArray|BSONArray|array $value) { if (\is_array($value) && ! \array_is_list($value)) { throw new \InvalidArgumentException('Expected $value argument to be a list, got an associative array.'); } + $this->value = $value; } } diff --git a/src/Builder/Query/JsonSchemaQuery.php b/src/Builder/Query/JsonSchemaQuery.php index 02e1c0456..7fbe37a5a 100644 --- a/src/Builder/Query/JsonSchemaQuery.php +++ b/src/Builder/Query/JsonSchemaQuery.php @@ -9,6 +9,7 @@ use MongoDB\BSON\Document; use MongoDB\BSON\Serializable; use MongoDB\Builder\Encode; +use MongoDB\Builder\Type\QueryInterface; use stdClass; /** diff --git a/src/Builder/Query/LtQuery.php b/src/Builder/Query/LtQuery.php index 11bac4894..a59839103 100644 --- a/src/Builder/Query/LtQuery.php +++ b/src/Builder/Query/LtQuery.php @@ -6,7 +6,21 @@ namespace MongoDB\Builder\Query; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Document; +use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; +use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; +use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Type\QueryInterface; +use MongoDB\Model\BSONArray; +use stdClass; /** * Matches values that are less than a specified value. @@ -18,14 +32,19 @@ class LtQuery implements QueryInterface public const NAME = '$lt'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param mixed $value */ - public mixed $value; + /** @param BSONArray|Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $value */ + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|BSONArray|stdClass|array|bool|float|int|null|string $value; /** - * @param mixed $value + * @param BSONArray|Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $value */ - public function __construct(mixed $value) - { + public function __construct( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|BSONArray|stdClass|array|bool|float|int|null|string $value, + ) { + if (\is_array($value) && ! \array_is_list($value)) { + throw new \InvalidArgumentException('Expected $value argument to be a list, got an associative array.'); + } + $this->value = $value; } } diff --git a/src/Builder/Query/LteQuery.php b/src/Builder/Query/LteQuery.php index 7442e616d..df207566f 100644 --- a/src/Builder/Query/LteQuery.php +++ b/src/Builder/Query/LteQuery.php @@ -6,7 +6,21 @@ namespace MongoDB\Builder\Query; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Document; +use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; +use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; +use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Type\QueryInterface; +use MongoDB\Model\BSONArray; +use stdClass; /** * Matches values that are less than or equal to a specified value. @@ -18,14 +32,19 @@ class LteQuery implements QueryInterface public const NAME = '$lte'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param mixed $value */ - public mixed $value; + /** @param BSONArray|Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $value */ + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|BSONArray|stdClass|array|bool|float|int|null|string $value; /** - * @param mixed $value + * @param BSONArray|Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $value */ - public function __construct(mixed $value) - { + public function __construct( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|BSONArray|stdClass|array|bool|float|int|null|string $value, + ) { + if (\is_array($value) && ! \array_is_list($value)) { + throw new \InvalidArgumentException('Expected $value argument to be a list, got an associative array.'); + } + $this->value = $value; } } diff --git a/src/Builder/Query/MaxDistanceQuery.php b/src/Builder/Query/MaxDistanceQuery.php index 514c7dc2b..e6116a92e 100644 --- a/src/Builder/Query/MaxDistanceQuery.php +++ b/src/Builder/Query/MaxDistanceQuery.php @@ -6,8 +6,14 @@ namespace MongoDB\Builder\Query; +use MongoDB\BSON\Decimal128; use MongoDB\BSON\Int64; use MongoDB\Builder\Encode; +use MongoDB\Builder\Expression\ResolvesToDecimal; +use MongoDB\Builder\Expression\ResolvesToDouble; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Expression\ResolvesToLong; +use MongoDB\Builder\Type\QueryInterface; /** * Specifies a maximum distance to limit the results of $near and $nearSphere queries. The 2dsphere and 2d indexes support $maxDistance. @@ -19,14 +25,15 @@ class MaxDistanceQuery implements QueryInterface public const NAME = '$maxDistance'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param Int64|float|int $value */ - public Int64|float|int $value; + /** @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|float|int $value */ + public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|float|int $value; /** - * @param Int64|float|int $value + * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|float|int $value */ - public function __construct(Int64|float|int $value) - { + public function __construct( + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|float|int $value, + ) { $this->value = $value; } } diff --git a/src/Builder/Query/MetaQuery.php b/src/Builder/Query/MetaQuery.php index 70ead0e6e..79f9defae 100644 --- a/src/Builder/Query/MetaQuery.php +++ b/src/Builder/Query/MetaQuery.php @@ -7,14 +7,14 @@ namespace MongoDB\Builder\Query; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; +use MongoDB\Builder\Type\ProjectionInterface; /** * Projects the available per-document metadata. * * @see https://www.mongodb.com/docs/manual/reference/operator/query/meta/ */ -class MetaQuery implements ExpressionInterface +class MetaQuery implements ProjectionInterface { public const NAME = '$meta'; public const ENCODE = \MongoDB\Builder\Encode::Object; diff --git a/src/Builder/Query/MinDistanceQuery.php b/src/Builder/Query/MinDistanceQuery.php index c2bca0700..831ccdcfb 100644 --- a/src/Builder/Query/MinDistanceQuery.php +++ b/src/Builder/Query/MinDistanceQuery.php @@ -8,6 +8,7 @@ use MongoDB\BSON\Int64; use MongoDB\Builder\Encode; +use MongoDB\Builder\Type\QueryInterface; /** * Specifies a minimum distance to limit the results of $near and $nearSphere queries. For use with 2dsphere index only. diff --git a/src/Builder/Query/ModQuery.php b/src/Builder/Query/ModQuery.php index db99ab172..c0b1deb8e 100644 --- a/src/Builder/Query/ModQuery.php +++ b/src/Builder/Query/ModQuery.php @@ -6,8 +6,8 @@ namespace MongoDB\Builder\Query; -use MongoDB\BSON\Int64; use MongoDB\Builder\Encode; +use MongoDB\Builder\Type\QueryInterface; /** * Performs a modulo operation on the value of a field and selects documents with a specified result. @@ -19,17 +19,17 @@ class ModQuery implements QueryInterface public const NAME = '$mod'; public const ENCODE = \MongoDB\Builder\Encode::Array; - /** @param Int64|int $divisor */ - public Int64|int $divisor; + /** @param int $divisor */ + public int $divisor; - /** @param Int64|int $remainder */ - public Int64|int $remainder; + /** @param int $remainder */ + public int $remainder; /** - * @param Int64|int $divisor - * @param Int64|int $remainder + * @param int $divisor + * @param int $remainder */ - public function __construct(Int64|int $divisor, Int64|int $remainder) + public function __construct(int $divisor, int $remainder) { $this->divisor = $divisor; $this->remainder = $remainder; diff --git a/src/Builder/Query/NaturalQuery.php b/src/Builder/Query/NaturalQuery.php index 12e470b60..2a2dc6e09 100644 --- a/src/Builder/Query/NaturalQuery.php +++ b/src/Builder/Query/NaturalQuery.php @@ -7,7 +7,7 @@ namespace MongoDB\Builder\Query; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; +use MongoDB\Builder\Type\ExpressionInterface; /** * A special hint that can be provided via the sort() or hint() methods that can be used to force either a forward or reverse collection scan. diff --git a/src/Builder/Query/NeQuery.php b/src/Builder/Query/NeQuery.php index 4b28a192a..cf5d56649 100644 --- a/src/Builder/Query/NeQuery.php +++ b/src/Builder/Query/NeQuery.php @@ -6,7 +6,21 @@ namespace MongoDB\Builder\Query; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Document; +use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; +use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; +use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Type\QueryInterface; +use MongoDB\Model\BSONArray; +use stdClass; /** * Matches all values that are not equal to a specified value. @@ -18,14 +32,19 @@ class NeQuery implements QueryInterface public const NAME = '$ne'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param mixed $value */ - public mixed $value; + /** @param BSONArray|Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $value */ + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|BSONArray|stdClass|array|bool|float|int|null|string $value; /** - * @param mixed $value + * @param BSONArray|Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $value */ - public function __construct(mixed $value) - { + public function __construct( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|BSONArray|stdClass|array|bool|float|int|null|string $value, + ) { + if (\is_array($value) && ! \array_is_list($value)) { + throw new \InvalidArgumentException('Expected $value argument to be a list, got an associative array.'); + } + $this->value = $value; } } diff --git a/src/Builder/Query/NearQuery.php b/src/Builder/Query/NearQuery.php index 1a1581923..49d414706 100644 --- a/src/Builder/Query/NearQuery.php +++ b/src/Builder/Query/NearQuery.php @@ -6,9 +6,11 @@ namespace MongoDB\Builder\Query; -use MongoDB\BSON\Int64; +use MongoDB\BSON\Document; +use MongoDB\BSON\Serializable; use MongoDB\Builder\Encode; use MongoDB\Builder\Optional; +use MongoDB\Builder\Type\QueryInterface; use stdClass; /** @@ -21,24 +23,24 @@ class NearQuery implements QueryInterface public const NAME = '$near'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param array|stdClass $geometry */ - public stdClass|array $geometry; + /** @param Document|Serializable|array|stdClass $geometry */ + public Document|Serializable|stdClass|array $geometry; - /** @param Int64|Optional|int $maxDistance Distance in meters. Limits the results to those documents that are at most the specified distance from the center point. */ - public Int64|Optional|int $maxDistance; + /** @param Optional|int $maxDistance Distance in meters. Limits the results to those documents that are at most the specified distance from the center point. */ + public Optional|int $maxDistance; - /** @param Int64|Optional|int $minDistance Distance in meters. Limits the results to those documents that are at least the specified distance from the center point. */ - public Int64|Optional|int $minDistance; + /** @param Optional|int $minDistance Distance in meters. Limits the results to those documents that are at least the specified distance from the center point. */ + public Optional|int $minDistance; /** - * @param array|stdClass $geometry - * @param Int64|Optional|int $maxDistance Distance in meters. Limits the results to those documents that are at most the specified distance from the center point. - * @param Int64|Optional|int $minDistance Distance in meters. Limits the results to those documents that are at least the specified distance from the center point. + * @param Document|Serializable|array|stdClass $geometry + * @param Optional|int $maxDistance Distance in meters. Limits the results to those documents that are at most the specified distance from the center point. + * @param Optional|int $minDistance Distance in meters. Limits the results to those documents that are at least the specified distance from the center point. */ public function __construct( - stdClass|array $geometry, - Int64|Optional|int $maxDistance = Optional::Undefined, - Int64|Optional|int $minDistance = Optional::Undefined, + Document|Serializable|stdClass|array $geometry, + Optional|int $maxDistance = Optional::Undefined, + Optional|int $minDistance = Optional::Undefined, ) { $this->geometry = $geometry; $this->maxDistance = $maxDistance; diff --git a/src/Builder/Query/NearSphereQuery.php b/src/Builder/Query/NearSphereQuery.php index b181b19bb..b97512df6 100644 --- a/src/Builder/Query/NearSphereQuery.php +++ b/src/Builder/Query/NearSphereQuery.php @@ -6,9 +6,11 @@ namespace MongoDB\Builder\Query; -use MongoDB\BSON\Int64; +use MongoDB\BSON\Document; +use MongoDB\BSON\Serializable; use MongoDB\Builder\Encode; use MongoDB\Builder\Optional; +use MongoDB\Builder\Type\QueryInterface; use stdClass; /** @@ -21,24 +23,24 @@ class NearSphereQuery implements QueryInterface public const NAME = '$nearSphere'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param array|stdClass $geometry */ - public stdClass|array $geometry; + /** @param Document|Serializable|array|stdClass $geometry */ + public Document|Serializable|stdClass|array $geometry; - /** @param Int64|Optional|int $maxDistance Distance in meters. */ - public Int64|Optional|int $maxDistance; + /** @param Optional|int $maxDistance Distance in meters. */ + public Optional|int $maxDistance; - /** @param Int64|Optional|int $minDistance Distance in meters. Limits the results to those documents that are at least the specified distance from the center point. */ - public Int64|Optional|int $minDistance; + /** @param Optional|int $minDistance Distance in meters. Limits the results to those documents that are at least the specified distance from the center point. */ + public Optional|int $minDistance; /** - * @param array|stdClass $geometry - * @param Int64|Optional|int $maxDistance Distance in meters. - * @param Int64|Optional|int $minDistance Distance in meters. Limits the results to those documents that are at least the specified distance from the center point. + * @param Document|Serializable|array|stdClass $geometry + * @param Optional|int $maxDistance Distance in meters. + * @param Optional|int $minDistance Distance in meters. Limits the results to those documents that are at least the specified distance from the center point. */ public function __construct( - stdClass|array $geometry, - Int64|Optional|int $maxDistance = Optional::Undefined, - Int64|Optional|int $minDistance = Optional::Undefined, + Document|Serializable|stdClass|array $geometry, + Optional|int $maxDistance = Optional::Undefined, + Optional|int $minDistance = Optional::Undefined, ) { $this->geometry = $geometry; $this->maxDistance = $maxDistance; diff --git a/src/Builder/Query/NinQuery.php b/src/Builder/Query/NinQuery.php index 068aa54f9..173c7aee1 100644 --- a/src/Builder/Query/NinQuery.php +++ b/src/Builder/Query/NinQuery.php @@ -8,7 +8,7 @@ use MongoDB\BSON\PackedArray; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; +use MongoDB\Builder\Type\QueryInterface; use MongoDB\Model\BSONArray; /** @@ -21,17 +21,18 @@ class NinQuery implements QueryInterface public const NAME = '$nin'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param BSONArray|PackedArray|list $value */ + /** @param BSONArray|PackedArray|array $value */ public PackedArray|BSONArray|array $value; /** - * @param BSONArray|PackedArray|list $value + * @param BSONArray|PackedArray|array $value */ public function __construct(PackedArray|BSONArray|array $value) { if (\is_array($value) && ! \array_is_list($value)) { throw new \InvalidArgumentException('Expected $value argument to be a list, got an associative array.'); } + $this->value = $value; } } diff --git a/src/Builder/Query/NorQuery.php b/src/Builder/Query/NorQuery.php index 2644a3032..b2bf37aee 100644 --- a/src/Builder/Query/NorQuery.php +++ b/src/Builder/Query/NorQuery.php @@ -6,7 +6,10 @@ namespace MongoDB\Builder\Query; +use MongoDB\BSON\Document; +use MongoDB\BSON\Serializable; use MongoDB\Builder\Encode; +use MongoDB\Builder\Type\QueryInterface; use stdClass; /** @@ -19,20 +22,20 @@ class NorQuery implements QueryInterface public const NAME = '$nor'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param list ...$expression */ + /** @param list ...$expression */ public array $expression; /** - * @param QueryInterface|array|stdClass ...$expression + * @param Document|QueryInterface|Serializable|array|stdClass ...$expression * @no-named-arguments */ - public function __construct(QueryInterface|stdClass|array ...$expression) + public function __construct(Document|Serializable|QueryInterface|stdClass|array ...$expression) { if (\count($expression) < 1) { throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); } if (! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression arguments to be a list of QueryInterface|array|stdClass, named arguments are not supported'); + throw new \InvalidArgumentException('Expected $expression arguments to be a list (array), named arguments are not supported'); } $this->expression = $expression; } diff --git a/src/Builder/Query/NotQuery.php b/src/Builder/Query/NotQuery.php index 032fc8009..327ac73fd 100644 --- a/src/Builder/Query/NotQuery.php +++ b/src/Builder/Query/NotQuery.php @@ -6,7 +6,10 @@ namespace MongoDB\Builder\Query; +use MongoDB\BSON\Document; +use MongoDB\BSON\Serializable; use MongoDB\Builder\Encode; +use MongoDB\Builder\Type\QueryInterface; use stdClass; /** @@ -19,13 +22,13 @@ class NotQuery implements QueryInterface public const NAME = '$not'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param QueryInterface|array|stdClass $expression */ - public QueryInterface|stdClass|array $expression; + /** @param Document|QueryInterface|Serializable|array|stdClass $expression */ + public Document|Serializable|QueryInterface|stdClass|array $expression; /** - * @param QueryInterface|array|stdClass $expression + * @param Document|QueryInterface|Serializable|array|stdClass $expression */ - public function __construct(QueryInterface|stdClass|array $expression) + public function __construct(Document|Serializable|QueryInterface|stdClass|array $expression) { $this->expression = $expression; } diff --git a/src/Builder/Query/OrQuery.php b/src/Builder/Query/OrQuery.php index 082f7db31..8416fae83 100644 --- a/src/Builder/Query/OrQuery.php +++ b/src/Builder/Query/OrQuery.php @@ -6,7 +6,10 @@ namespace MongoDB\Builder\Query; +use MongoDB\BSON\Document; +use MongoDB\BSON\Serializable; use MongoDB\Builder\Encode; +use MongoDB\Builder\Type\QueryInterface; use stdClass; /** @@ -19,20 +22,20 @@ class OrQuery implements QueryInterface public const NAME = '$or'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param list ...$expression */ + /** @param list ...$expression */ public array $expression; /** - * @param QueryInterface|array|stdClass ...$expression + * @param Document|QueryInterface|Serializable|array|stdClass ...$expression * @no-named-arguments */ - public function __construct(QueryInterface|stdClass|array ...$expression) + public function __construct(Document|Serializable|QueryInterface|stdClass|array ...$expression) { if (\count($expression) < 1) { throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); } if (! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression arguments to be a list of QueryInterface|array|stdClass, named arguments are not supported'); + throw new \InvalidArgumentException('Expected $expression arguments to be a list (array), named arguments are not supported'); } $this->expression = $expression; } diff --git a/src/Builder/Query/PolygonQuery.php b/src/Builder/Query/PolygonQuery.php index 2f13462a3..ebea98f89 100644 --- a/src/Builder/Query/PolygonQuery.php +++ b/src/Builder/Query/PolygonQuery.php @@ -8,7 +8,7 @@ use MongoDB\BSON\PackedArray; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; +use MongoDB\Builder\Type\QueryInterface; use MongoDB\Model\BSONArray; /** @@ -21,17 +21,18 @@ class PolygonQuery implements QueryInterface public const NAME = '$polygon'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param BSONArray|PackedArray|list $points */ + /** @param BSONArray|PackedArray|array $points */ public PackedArray|BSONArray|array $points; /** - * @param BSONArray|PackedArray|list $points + * @param BSONArray|PackedArray|array $points */ public function __construct(PackedArray|BSONArray|array $points) { if (\is_array($points) && ! \array_is_list($points)) { throw new \InvalidArgumentException('Expected $points argument to be a list, got an associative array.'); } + $this->points = $points; } } diff --git a/src/Builder/Query/QueryInterface.php b/src/Builder/Query/QueryInterface.php deleted file mode 100644 index 72b0862ac..000000000 --- a/src/Builder/Query/QueryInterface.php +++ /dev/null @@ -1,11 +0,0 @@ -value = $value; } diff --git a/src/Builder/Query/SliceQuery.php b/src/Builder/Query/SliceQuery.php index afa4801ef..84b748c14 100644 --- a/src/Builder/Query/SliceQuery.php +++ b/src/Builder/Query/SliceQuery.php @@ -6,30 +6,31 @@ namespace MongoDB\Builder\Query; -use MongoDB\BSON\Int64; use MongoDB\Builder\Encode; +use MongoDB\Builder\Type\ProjectionInterface; +use MongoDB\Builder\Type\QueryInterface; /** * Limits the number of elements projected from an array. Supports skip and limit slices. * * @see https://www.mongodb.com/docs/manual/reference/operator/query/slice/ */ -class SliceQuery implements QueryInterface +class SliceQuery implements QueryInterface, ProjectionInterface { public const NAME = '$slice'; public const ENCODE = \MongoDB\Builder\Encode::Array; - /** @param Int64|int $limit */ - public Int64|int $limit; + /** @param int $limit */ + public int $limit; - /** @param Int64|int $skip */ - public Int64|int $skip; + /** @param int $skip */ + public int $skip; /** - * @param Int64|int $limit - * @param Int64|int $skip + * @param int $limit + * @param int $skip */ - public function __construct(Int64|int $limit, Int64|int $skip) + public function __construct(int $limit, int $skip) { $this->limit = $limit; $this->skip = $skip; diff --git a/src/Builder/Query/TextQuery.php b/src/Builder/Query/TextQuery.php index 416f2ca65..ecc1ef990 100644 --- a/src/Builder/Query/TextQuery.php +++ b/src/Builder/Query/TextQuery.php @@ -8,6 +8,7 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Optional; +use MongoDB\Builder\Type\QueryInterface; /** * Performs text search. diff --git a/src/Builder/Query/TypeQuery.php b/src/Builder/Query/TypeQuery.php index 81d6fec3c..2f3f247e4 100644 --- a/src/Builder/Query/TypeQuery.php +++ b/src/Builder/Query/TypeQuery.php @@ -6,10 +6,9 @@ namespace MongoDB\Builder\Query; -use MongoDB\BSON\Int64; use MongoDB\BSON\PackedArray; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; +use MongoDB\Builder\Type\QueryInterface; use MongoDB\Model\BSONArray; /** @@ -22,17 +21,18 @@ class TypeQuery implements QueryInterface public const NAME = '$type'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param BSONArray|Int64|PackedArray|int|list|non-empty-string $type */ - public Int64|PackedArray|BSONArray|array|int|string $type; + /** @param BSONArray|PackedArray|array|int|non-empty-string $type */ + public PackedArray|BSONArray|array|int|string $type; /** - * @param BSONArray|Int64|PackedArray|int|list|non-empty-string $type + * @param BSONArray|PackedArray|array|int|non-empty-string $type */ - public function __construct(Int64|PackedArray|BSONArray|array|int|string $type) + public function __construct(PackedArray|BSONArray|array|int|string $type) { if (\is_array($type) && ! \array_is_list($type)) { throw new \InvalidArgumentException('Expected $type argument to be a list, got an associative array.'); } + $this->type = $type; } } diff --git a/src/Builder/Query/WhereQuery.php b/src/Builder/Query/WhereQuery.php index 20b6c2890..4e7f10f08 100644 --- a/src/Builder/Query/WhereQuery.php +++ b/src/Builder/Query/WhereQuery.php @@ -7,6 +7,7 @@ namespace MongoDB\Builder\Query; use MongoDB\Builder\Encode; +use MongoDB\Builder\Type\QueryInterface; /** * Matches documents that satisfy a JavaScript expression. diff --git a/src/Builder/Stage.php b/src/Builder/Stage.php index 13dc43f2f..927da9d82 100644 --- a/src/Builder/Stage.php +++ b/src/Builder/Stage.php @@ -6,18 +6,25 @@ namespace MongoDB\Builder; +use MongoDB\BSON\Binary; use MongoDB\BSON\Decimal128; use MongoDB\BSON\Document; use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; use MongoDB\BSON\Serializable; -use MongoDB\Builder\Aggregation\AccumulatorInterface; +use MongoDB\BSON\Timestamp; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Expression\ArrayFieldPath; -use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\FieldPath; use MongoDB\Builder\Expression\ResolvesToArray; +use MongoDB\Builder\Expression\ResolvesToBool; +use MongoDB\Builder\Expression\ResolvesToDecimal; +use MongoDB\Builder\Expression\ResolvesToDouble; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Expression\ResolvesToLong; use MongoDB\Builder\Expression\ResolvesToObject; -use MongoDB\Builder\Query\QueryInterface; use MongoDB\Builder\Stage\AddFieldsStage; use MongoDB\Builder\Stage\BucketAutoStage; use MongoDB\Builder\Stage\BucketStage; @@ -60,6 +67,10 @@ use MongoDB\Builder\Stage\UnionWithStage; use MongoDB\Builder\Stage\UnsetStage; use MongoDB\Builder\Stage\UnwindStage; +use MongoDB\Builder\Type\AccumulatorInterface; +use MongoDB\Builder\Type\ExpressionInterface; +use MongoDB\Builder\Type\ProjectionInterface; +use MongoDB\Builder\Type\QueryInterface; use MongoDB\Model\BSONArray; use stdClass; @@ -69,9 +80,11 @@ final class Stage * Adds new fields to documents. Outputs documents that contain all existing fields from the input documents and newly added fields. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/addFields/ - * @param ExpressionInterface|mixed ...$expression Specify the name of each field to add and set its value to an aggregation expression or an empty object. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass ...$expression Specify the name of each field to add and set its value to an aggregation expression or an empty object. */ - public static function addFields(mixed ...$expression): AddFieldsStage + public static function addFields( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string ...$expression, + ): AddFieldsStage { return new AddFieldsStage(...$expression); } @@ -80,11 +93,11 @@ public static function addFields(mixed ...$expression): AddFieldsStage * Categorizes incoming documents into groups, called buckets, based on a specified expression and bucket boundaries. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/bucket/ - * @param ExpressionInterface|FieldPath|mixed|non-empty-string $groupBy An expression to group documents by. To specify a field path, prefix the field name with a dollar sign $ and enclose it in quotes. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|FieldPath|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $groupBy 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. - * @param BSONArray|PackedArray|list $boundaries 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. + * @param BSONArray|PackedArray|array $boundaries 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: - * @param ExpressionInterface|Optional|mixed $default 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. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|Optional|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $default 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. @@ -93,9 +106,9 @@ public static function addFields(mixed ...$expression): AddFieldsStage * 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. */ public static function bucket( - mixed $groupBy, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|FieldPath|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $groupBy, PackedArray|BSONArray|array $boundaries, - mixed $default = Optional::Undefined, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|Optional|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $default = Optional::Undefined, Document|Serializable|Optional|stdClass|array $output = Optional::Undefined, ): BucketStage { @@ -106,16 +119,16 @@ public static function bucket( * 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. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/bucketAuto/ - * @param ExpressionInterface|mixed $groupBy An expression to group documents by. To specify a field path, prefix the field name with a dollar sign $ and enclose it in quotes. - * @param Int64|int $buckets A positive 32-bit integer that specifies the number of buckets into which input documents are grouped. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $groupBy An expression to group documents by. To specify a field path, prefix the field name with a dollar sign $ and enclose it in quotes. + * @param int $buckets A positive 32-bit integer that specifies the number of buckets into which input documents are grouped. * @param Document|Optional|Serializable|array|stdClass $output 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. * @param Optional|non-empty-string $granularity 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. */ public static function bucketAuto( - mixed $groupBy, - Int64|int $buckets, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $groupBy, + int $buckets, Document|Serializable|Optional|stdClass|array $output = Optional::Undefined, Optional|string $granularity = Optional::Undefined, ): BucketAutoStage @@ -130,20 +143,20 @@ public static function bucketAuto( * @param Optional|bool $allChangesForCluster A flag indicating whether the stream should report all changes that occur on the deployment, aside from those on internal databases or collections. * @param Optional|non-empty-string $fullDocument Specifies whether change notifications include a copy of the full document when modified by update operations. * @param Optional|non-empty-string $fullDocumentBeforeChange 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. - * @param Int64|Optional|int $resumeAfter Specifies a resume token as the logical starting point for the change stream. Cannot be used with startAfter or startAtOperationTime fields. + * @param Optional|int $resumeAfter Specifies a resume token as the logical starting point for the change stream. Cannot be used with startAfter or startAtOperationTime fields. * @param Optional|bool $showExpandedEvents Specifies whether to include additional change events, such as such as DDL and index operations. * New in version 6.0. * @param Document|Optional|Serializable|array|stdClass $startAfter Specifies a resume token as the logical starting point for the change stream. Cannot be used with resumeAfter or startAtOperationTime fields. - * @param Optional|int $startAtOperationTime Specifies a time as the logical starting point for the change stream. Cannot be used with resumeAfter or startAfter fields. + * @param Optional|Timestamp|int $startAtOperationTime Specifies a time as the logical starting point for the change stream. Cannot be used with resumeAfter or startAfter fields. */ public static function changeStream( Optional|bool $allChangesForCluster = Optional::Undefined, Optional|string $fullDocument = Optional::Undefined, Optional|string $fullDocumentBeforeChange = Optional::Undefined, - Int64|Optional|int $resumeAfter = Optional::Undefined, + Optional|int $resumeAfter = Optional::Undefined, Optional|bool $showExpandedEvents = Optional::Undefined, Document|Serializable|Optional|stdClass|array $startAfter = Optional::Undefined, - Optional|int $startAtOperationTime = Optional::Undefined, + Timestamp|Optional|int $startAtOperationTime = Optional::Undefined, ): ChangeStreamStage { return new ChangeStreamStage($allChangesForCluster, $fullDocument, $fullDocumentBeforeChange, $resumeAfter, $showExpandedEvents, $startAfter, $startAtOperationTime); @@ -200,12 +213,12 @@ public static function currentOp(): CurrentOpStage * @param FieldPath|non-empty-string $field 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. - * @param array|stdClass $range Specification for range based densification. - * @param BSONArray|Optional|PackedArray|list $partitionByFields The field(s) that will be used as the partition keys. + * @param Document|Serializable|array|stdClass $range Specification for range based densification. + * @param BSONArray|Optional|PackedArray|array $partitionByFields The field(s) that will be used as the partition keys. */ public static function densify( FieldPath|string $field, - stdClass|array $range, + Document|Serializable|stdClass|array $range, PackedArray|Optional|BSONArray|array $partitionByFields = Optional::Undefined, ): DensifyStage { @@ -216,7 +229,7 @@ public static function densify( * Returns literal documents from input values. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/documents/ - * @param BSONArray|PackedArray|ResolvesToArray|list $documents $documents accepts any valid expression that resolves to an array of objects. This includes: + * @param BSONArray|PackedArray|ResolvesToArray|array $documents $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 @@ -231,9 +244,9 @@ public static function documents(PackedArray|ResolvesToArray|BSONArray|array $do * 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. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/facet/ - * @param Pipeline|array ...$facet + * @param BSONArray|PackedArray|Pipeline|array ...$facet */ - public static function facet(Pipeline|array ...$facet): FacetStage + public static function facet(PackedArray|Pipeline|BSONArray|array ...$facet): FacetStage { return new FacetStage(...$facet); } @@ -247,16 +260,16 @@ public static function facet(Pipeline|array ...$facet): FacetStage * @param Document|Optional|Serializable|array|non-empty-string|stdClass $partitionBy 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. - * @param BSONArray|Optional|PackedArray|list $partitionByFields 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. + * @param BSONArray|Optional|PackedArray|array $partitionByFields 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. - * @param Optional|array|stdClass $sortBy Specifies the field or fields to sort the documents within each partition. Uses the same syntax as the $sort stage. + * @param Document|Optional|Serializable|array|stdClass $sortBy Specifies the field or fields to sort the documents within each partition. Uses the same syntax as the $sort stage. */ public static function fill( Document|Serializable|stdClass|array $output, Document|Serializable|Optional|stdClass|array|string $partitionBy = Optional::Undefined, PackedArray|Optional|BSONArray|array $partitionByFields = Optional::Undefined, - Optional|stdClass|array $sortBy = Optional::Undefined, + Document|Serializable|Optional|stdClass|array $sortBy = Optional::Undefined, ): FillStage { return new FillStage($output, $partitionBy, $partitionByFields, $sortBy); @@ -267,15 +280,15 @@ public static function fill( * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/geoNear/ * @param non-empty-string $distanceField The output field that contains the calculated distance. To specify a field within an embedded document, use dot notation. - * @param array|stdClass $near The point for which to find the closest documents. - * @param Decimal128|Int64|Optional|float|int $distanceMultiplier 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. + * @param Document|Serializable|array|stdClass $near The point for which to find the closest documents. + * @param Decimal128|Int64|Optional|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|float|int $distanceMultiplier 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. * @param Optional|non-empty-string $includeLocs 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. * @param Optional|non-empty-string $key Specify the geospatial indexed field to use when calculating the distance. - * @param Decimal128|Int64|Optional|float|int $maxDistance 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. + * @param Decimal128|Int64|Optional|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|float|int $maxDistance 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. - * @param Decimal128|Int64|Optional|float|int $minDistance 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. + * @param Decimal128|Int64|Optional|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|float|int $minDistance 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. - * @param Optional|QueryInterface|array|stdClass $query imits the results to the documents that match the query. The query syntax is the usual MongoDB read operation query syntax. + * @param Document|Optional|QueryInterface|Serializable|array|stdClass $query imits 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. * @param Optional|bool $spherical Determines how MongoDB calculates the distance between two points: * - When true, MongoDB uses $nearSphere semantics and calculates distances using spherical geometry. @@ -284,13 +297,13 @@ public static function fill( */ public static function geoNear( string $distanceField, - stdClass|array $near, - Decimal128|Int64|Optional|float|int $distanceMultiplier = Optional::Undefined, + Document|Serializable|stdClass|array $near, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|Optional|float|int $distanceMultiplier = Optional::Undefined, Optional|string $includeLocs = Optional::Undefined, Optional|string $key = Optional::Undefined, - Decimal128|Int64|Optional|float|int $maxDistance = Optional::Undefined, - Decimal128|Int64|Optional|float|int $minDistance = Optional::Undefined, - Optional|QueryInterface|stdClass|array $query = Optional::Undefined, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|Optional|float|int $maxDistance = Optional::Undefined, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|Optional|float|int $minDistance = Optional::Undefined, + Document|Serializable|Optional|QueryInterface|stdClass|array $query = Optional::Undefined, Optional|bool $spherical = Optional::Undefined, ): GeoNearStage { @@ -303,23 +316,23 @@ public static function geoNear( * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/graphLookup/ * @param non-empty-string $from 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. - * @param BSONArray|ExpressionInterface|PackedArray|list|mixed $startWith 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. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $startWith 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. * @param non-empty-string $connectFromField 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. * @param non-empty-string $connectToField Field name in other documents against which to match the value of the field specified by the connectFromField parameter. * @param non-empty-string $as Name of the array field added to each output document. Contains the documents traversed in the $graphLookup stage to reach the document. - * @param Int64|Optional|int $maxDepth Non-negative integral number specifying the maximum recursion depth. + * @param Optional|int $maxDepth Non-negative integral number specifying the maximum recursion depth. * @param Optional|non-empty-string $depthField 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. - * @param Optional|QueryInterface|array|stdClass $restrictSearchWithMatch A document specifying additional conditions for the recursive search. The syntax is identical to query filter syntax. + * @param Document|Optional|QueryInterface|Serializable|array|stdClass $restrictSearchWithMatch A document specifying additional conditions for the recursive search. The syntax is identical to query filter syntax. */ public static function graphLookup( string $from, - mixed $startWith, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $startWith, string $connectFromField, string $connectToField, string $as, - Int64|Optional|int $maxDepth = Optional::Undefined, + Optional|int $maxDepth = Optional::Undefined, Optional|string $depthField = Optional::Undefined, - Optional|QueryInterface|stdClass|array $restrictSearchWithMatch = Optional::Undefined, + Document|Serializable|Optional|QueryInterface|stdClass|array $restrictSearchWithMatch = Optional::Undefined, ): GraphLookupStage { return new GraphLookupStage($from, $startWith, $connectFromField, $connectToField, $as, $maxDepth, $depthField, $restrictSearchWithMatch); @@ -329,10 +342,13 @@ public static function graphLookup( * 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. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/group/ - * @param ExpressionInterface|mixed $_id 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. - * @param AccumulatorInterface ...$field Computed using the accumulator operators. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $_id 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. + * @param AccumulatorInterface|Document|Serializable|array|stdClass ...$field Computed using the accumulator operators. */ - public static function group(mixed $_id, AccumulatorInterface ...$field): GroupStage + public static function group( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $_id, + Document|Serializable|AccumulatorInterface|stdClass|array ...$field, + ): GroupStage { return new GroupStage($_id, ...$field); } @@ -351,9 +367,9 @@ public static function indexStats(): IndexStatsStage * 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). * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/limit/ - * @param Int64|int $limit + * @param int $limit */ - public static function limit(Int64|int $limit): LimitStage + public static function limit(int $limit): LimitStage { return new LimitStage($limit); } @@ -362,7 +378,7 @@ public static function limit(Int64|int $limit): LimitStage * 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. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/listLocalSessions/ - * @param BSONArray|Optional|PackedArray|list $users 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. + * @param BSONArray|Optional|PackedArray|array $users 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. * @param Optional|bool $allUsers Returns all sessions for all users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster. */ public static function listLocalSessions( @@ -405,7 +421,7 @@ public static function listSearchIndexes( * Lists all sessions that have been active long enough to propagate to the system.sessions collection. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSessions/ - * @param BSONArray|Optional|PackedArray|list $users 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. + * @param BSONArray|Optional|PackedArray|array $users 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. * @param Optional|bool $allUsers Returns all sessions for all users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster. */ public static function listSessions( @@ -427,7 +443,7 @@ public static function listSessions( * @param Optional|non-empty-string $localField 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. * @param Optional|non-empty-string $foreignField 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. * @param Document|Optional|Serializable|array|stdClass $let 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. - * @param Optional|Pipeline|array $pipeline 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 []. + * @param BSONArray|Optional|PackedArray|Pipeline|array $pipeline 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 $mergestage. 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. */ @@ -437,7 +453,7 @@ public static function lookup( Optional|string $localField = Optional::Undefined, Optional|string $foreignField = Optional::Undefined, Document|Serializable|Optional|stdClass|array $let = Optional::Undefined, - Optional|Pipeline|array $pipeline = Optional::Undefined, + PackedArray|Optional|Pipeline|BSONArray|array $pipeline = Optional::Undefined, ): LookupStage { return new LookupStage($as, $from, $localField, $foreignField, $let, $pipeline); @@ -447,9 +463,9 @@ public static function lookup( * 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). * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/match/ - * @param QueryInterface|array|stdClass $query + * @param Document|QueryInterface|Serializable|array|stdClass $query */ - public static function match(QueryInterface|stdClass|array $query): MatchStage + public static function match(Document|Serializable|QueryInterface|stdClass|array $query): MatchStage { return new MatchStage($query); } @@ -459,14 +475,14 @@ public static function match(QueryInterface|stdClass|array $query): MatchStage * New in version 4.2. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/ - * @param array|non-empty-string|stdClass $into The output collection. - * @param BSONArray|Optional|PackedArray|list|non-empty-string $on 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. + * @param Document|Serializable|array|non-empty-string|stdClass $into The output collection. + * @param BSONArray|Optional|PackedArray|array|non-empty-string $on 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. * @param Document|Optional|Serializable|array|stdClass $let Specifies variables for use in the whenMatched pipeline. * @param Optional|non-empty-string $whenMatched 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). * @param Optional|non-empty-string $whenNotMatched The behavior of $merge if a result document does not match an existing document in the out collection. */ public static function merge( - stdClass|array|string $into, + Document|Serializable|stdClass|array|string $into, PackedArray|Optional|BSONArray|array|string $on = Optional::Undefined, Document|Serializable|Optional|stdClass|array $let = Optional::Undefined, Optional|string $whenMatched = Optional::Undefined, @@ -507,9 +523,11 @@ public static function planCacheStats(): PlanCacheStatsStage * Reshapes each document in the stream, such as by adding new fields or removing existing fields. For each input document, outputs one document. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/project/ - * @param ExpressionInterface|Int64|bool|int|mixed ...$specification + * @param Document|ProjectionInterface|ResolvesToBool|Serializable|array|bool|int|stdClass ...$specification */ - public static function project(mixed ...$specification): ProjectStage + public static function project( + Document|Serializable|ResolvesToBool|ProjectionInterface|stdClass|array|bool|int ...$specification, + ): ProjectStage { return new ProjectStage(...$specification); } @@ -518,9 +536,11 @@ public static function project(mixed ...$specification): ProjectStage * 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. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/redact/ - * @param ExpressionInterface|mixed $expression + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression */ - public static function redact(mixed $expression): RedactStage + public static function redact( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, + ): RedactStage { return new RedactStage($expression); } @@ -556,9 +576,9 @@ public static function replaceWith( * Randomly selects the specified number of documents from its input. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/sample/ - * @param Int64|int $size The number of documents to randomly select. + * @param int $size The number of documents to randomly select. */ - public static function sample(Int64|int $size): SampleStage + public static function sample(int $size): SampleStage { return new SampleStage($size); } @@ -592,9 +612,11 @@ public static function searchMeta(Document|Serializable|stdClass|array $meta): S * Alias for $addFields. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/set/ - * @param ExpressionInterface|mixed ...$field + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass ...$field */ - public static function set(mixed ...$field): SetStage + public static function set( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string ...$field, + ): SetStage { return new SetStage(...$field); } @@ -604,17 +626,17 @@ public static function set(mixed ...$field): SetStage * New in version 5.0. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/setWindowFields/ - * @param ExpressionInterface|mixed $partitionBy 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. - * @param array|stdClass $sortBy Specifies the field(s) to sort the documents by in the partition. Uses the same syntax as the $sort stage. Default is no sorting. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $partitionBy 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. + * @param Document|Serializable|array|stdClass $sortBy Specifies the field(s) to sort the documents by in the partition. Uses the same syntax as the $sort stage. Default is no sorting. * @param Document|Serializable|array|stdClass $output 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. - * @param Optional|array|stdClass $window Specifies the window boundaries and parameters. Window boundaries are inclusive. Default is an unbounded window, which includes all documents in the partition. + * @param Document|Optional|Serializable|array|stdClass $window Specifies the window boundaries and parameters. Window boundaries are inclusive. Default is an unbounded window, which includes all documents in the partition. */ public static function setWindowFields( - mixed $partitionBy, - stdClass|array $sortBy, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $partitionBy, + Document|Serializable|stdClass|array $sortBy, Document|Serializable|stdClass|array $output, - Optional|stdClass|array $window = Optional::Undefined, + Document|Serializable|Optional|stdClass|array $window = Optional::Undefined, ): SetWindowFieldsStage { return new SetWindowFieldsStage($partitionBy, $sortBy, $output, $window); @@ -635,9 +657,9 @@ public static function shardedDataDistribution(): ShardedDataDistributionStage * 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). * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/skip/ - * @param Int64|int $skip + * @param int $skip */ - public static function skip(Int64|int $skip): SkipStage + public static function skip(int $skip): SkipStage { return new SkipStage($skip); } @@ -646,9 +668,9 @@ public static function skip(Int64|int $skip): SkipStage * Reorders the document stream by a specified sort key. Only the order changes; the documents remain unmodified. For each input document, outputs one document. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/sort/ - * @param array|stdClass $sort + * @param Document|Serializable|array|stdClass $sort */ - public static function sort(stdClass|array $sort): SortStage + public static function sort(Document|Serializable|stdClass|array $sort): SortStage { return new SortStage($sort); } @@ -657,9 +679,11 @@ public static function sort(stdClass|array $sort): SortStage * Groups incoming documents based on the value of a specified expression, then computes the count of documents in each distinct group. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/sortByCount/ - * @param ExpressionInterface|mixed $expression + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression */ - public static function sortByCount(mixed $expression): SortByCountStage + public static function sortByCount( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, + ): SortByCountStage { return new SortByCountStage($expression); } @@ -670,12 +694,12 @@ public static function sortByCount(mixed $expression): SortByCountStage * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/unionWith/ * @param non-empty-string $coll The collection or view whose pipeline results you wish to include in the result set. - * @param Optional|Pipeline|array $pipeline An aggregation pipeline to apply to the specified coll. + * @param BSONArray|Optional|PackedArray|Pipeline|array $pipeline 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. */ public static function unionWith( string $coll, - Optional|Pipeline|array $pipeline = Optional::Undefined, + PackedArray|Optional|Pipeline|BSONArray|array $pipeline = Optional::Undefined, ): UnionWithStage { return new UnionWithStage($coll, $pipeline); diff --git a/src/Builder/Stage/AddFieldsStage.php b/src/Builder/Stage/AddFieldsStage.php index 2c5354bb7..ba8b1c028 100644 --- a/src/Builder/Stage/AddFieldsStage.php +++ b/src/Builder/Stage/AddFieldsStage.php @@ -6,8 +6,21 @@ namespace MongoDB\Builder\Stage; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Document; +use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; +use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; +use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Type\ExpressionInterface; +use MongoDB\Builder\Type\StageInterface; +use MongoDB\Model\BSONArray; use stdClass; /** @@ -20,20 +33,21 @@ class AddFieldsStage implements StageInterface public const NAME = '$addFields'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param stdClass ...$expression Specify the name of each field to add and set its value to an aggregation expression or an empty object. */ + /** @param stdClass ...$expression Specify the name of each field to add and set its value to an aggregation expression or an empty object. */ public stdClass $expression; /** - * @param ExpressionInterface|mixed ...$expression Specify the name of each field to add and set its value to an aggregation expression or an empty object. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass ...$expression Specify the name of each field to add and set its value to an aggregation expression or an empty object. */ - public function __construct(mixed ...$expression) - { + public function __construct( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string ...$expression, + ) { if (\count($expression) < 1) { throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); } foreach($expression as $key => $value) { if (! \is_string($key)) { - throw new \InvalidArgumentException('Expected $expression arguments to be a map of ExpressionInterface|mixed, named arguments (:) or array unpacking ...[\'\' => ] must be used'); + throw new \InvalidArgumentException('Expected $expression arguments to be a map (object), named arguments (:) or array unpacking ...[\'\' => ] must be used'); } } $expression = (object) $expression; diff --git a/src/Builder/Stage/BucketAutoStage.php b/src/Builder/Stage/BucketAutoStage.php index 92715edb7..fd28bbcb7 100644 --- a/src/Builder/Stage/BucketAutoStage.php +++ b/src/Builder/Stage/BucketAutoStage.php @@ -6,12 +6,22 @@ namespace MongoDB\Builder\Stage; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Decimal128; use MongoDB\BSON\Document; use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; +use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; +use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Optional; +use MongoDB\Builder\Type\ExpressionInterface; +use MongoDB\Builder\Type\StageInterface; +use MongoDB\Model\BSONArray; use stdClass; /** @@ -24,11 +34,11 @@ class BucketAutoStage implements StageInterface public const NAME = '$bucketAuto'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param ExpressionInterface|mixed $groupBy An expression to group documents by. To specify a field path, prefix the field name with a dollar sign $ and enclose it in quotes. */ - public mixed $groupBy; + /** @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $groupBy An expression to group documents by. To specify a field path, prefix the field name with a dollar sign $ and enclose it in quotes. */ + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $groupBy; - /** @param Int64|int $buckets A positive 32-bit integer that specifies the number of buckets into which input documents are grouped. */ - public Int64|int $buckets; + /** @param int $buckets A positive 32-bit integer that specifies the number of buckets into which input documents are grouped. */ + public int $buckets; /** * @param Document|Optional|Serializable|array|stdClass $output 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. @@ -43,19 +53,23 @@ class BucketAutoStage implements StageInterface public Optional|string $granularity; /** - * @param ExpressionInterface|mixed $groupBy An expression to group documents by. To specify a field path, prefix the field name with a dollar sign $ and enclose it in quotes. - * @param Int64|int $buckets A positive 32-bit integer that specifies the number of buckets into which input documents are grouped. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $groupBy An expression to group documents by. To specify a field path, prefix the field name with a dollar sign $ and enclose it in quotes. + * @param int $buckets A positive 32-bit integer that specifies the number of buckets into which input documents are grouped. * @param Document|Optional|Serializable|array|stdClass $output 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. * @param Optional|non-empty-string $granularity 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. */ public function __construct( - mixed $groupBy, - Int64|int $buckets, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $groupBy, + int $buckets, Document|Serializable|Optional|stdClass|array $output = Optional::Undefined, Optional|string $granularity = Optional::Undefined, ) { + if (\is_array($groupBy) && ! \array_is_list($groupBy)) { + throw new \InvalidArgumentException('Expected $groupBy argument to be a list, got an associative array.'); + } + $this->groupBy = $groupBy; $this->buckets = $buckets; $this->output = $output; diff --git a/src/Builder/Stage/BucketStage.php b/src/Builder/Stage/BucketStage.php index 785ac059d..3edbb37f9 100644 --- a/src/Builder/Stage/BucketStage.php +++ b/src/Builder/Stage/BucketStage.php @@ -6,13 +6,22 @@ namespace MongoDB\Builder\Stage; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Decimal128; use MongoDB\BSON\Document; +use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\FieldPath; +use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Optional; +use MongoDB\Builder\Type\ExpressionInterface; +use MongoDB\Builder\Type\StageInterface; use MongoDB\Model\BSONArray; use stdClass; @@ -27,24 +36,24 @@ class BucketStage implements StageInterface public const ENCODE = \MongoDB\Builder\Encode::Object; /** - * @param ExpressionInterface|FieldPath|mixed|non-empty-string $groupBy An expression to group documents by. To specify a field path, prefix the field name with a dollar sign $ and enclose it in quotes. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|FieldPath|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $groupBy 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. */ - public mixed $groupBy; + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|FieldPath|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $groupBy; /** - * @param BSONArray|PackedArray|list $boundaries 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. + * @param BSONArray|PackedArray|array $boundaries 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: */ public PackedArray|BSONArray|array $boundaries; /** - * @param ExpressionInterface|Optional|mixed $default 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. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|Optional|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $default 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. */ - public mixed $default; + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|Optional|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $default; /** * @param Document|Optional|Serializable|array|stdClass $output 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. @@ -54,11 +63,11 @@ class BucketStage implements StageInterface public Document|Serializable|Optional|stdClass|array $output; /** - * @param ExpressionInterface|FieldPath|mixed|non-empty-string $groupBy An expression to group documents by. To specify a field path, prefix the field name with a dollar sign $ and enclose it in quotes. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|FieldPath|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $groupBy 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. - * @param BSONArray|PackedArray|list $boundaries 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. + * @param BSONArray|PackedArray|array $boundaries 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: - * @param ExpressionInterface|Optional|mixed $default 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. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|Optional|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $default 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. @@ -67,16 +76,25 @@ class BucketStage implements StageInterface * 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. */ public function __construct( - mixed $groupBy, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|FieldPath|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $groupBy, PackedArray|BSONArray|array $boundaries, - mixed $default = Optional::Undefined, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|Optional|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $default = Optional::Undefined, Document|Serializable|Optional|stdClass|array $output = Optional::Undefined, ) { + if (\is_array($groupBy) && ! \array_is_list($groupBy)) { + throw new \InvalidArgumentException('Expected $groupBy argument to be a list, got an associative array.'); + } + $this->groupBy = $groupBy; if (\is_array($boundaries) && ! \array_is_list($boundaries)) { throw new \InvalidArgumentException('Expected $boundaries argument to be a list, got an associative array.'); } + $this->boundaries = $boundaries; + if (\is_array($default) && ! \array_is_list($default)) { + throw new \InvalidArgumentException('Expected $default argument to be a list, got an associative array.'); + } + $this->default = $default; $this->output = $output; } diff --git a/src/Builder/Stage/ChangeStreamSplitLargeEventStage.php b/src/Builder/Stage/ChangeStreamSplitLargeEventStage.php index f637003c2..38afb57d9 100644 --- a/src/Builder/Stage/ChangeStreamSplitLargeEventStage.php +++ b/src/Builder/Stage/ChangeStreamSplitLargeEventStage.php @@ -7,6 +7,7 @@ namespace MongoDB\Builder\Stage; use MongoDB\Builder\Encode; +use MongoDB\Builder\Type\StageInterface; /** * Splits large change stream events that exceed 16 MB into smaller fragments returned in a change stream cursor. diff --git a/src/Builder/Stage/ChangeStreamStage.php b/src/Builder/Stage/ChangeStreamStage.php index 4df1d9dd5..41bc299d6 100644 --- a/src/Builder/Stage/ChangeStreamStage.php +++ b/src/Builder/Stage/ChangeStreamStage.php @@ -7,10 +7,11 @@ namespace MongoDB\Builder\Stage; use MongoDB\BSON\Document; -use MongoDB\BSON\Int64; use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; use MongoDB\Builder\Encode; use MongoDB\Builder\Optional; +use MongoDB\Builder\Type\StageInterface; use stdClass; /** @@ -32,8 +33,8 @@ class ChangeStreamStage implements StageInterface /** @param Optional|non-empty-string $fullDocumentBeforeChange 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. */ public Optional|string $fullDocumentBeforeChange; - /** @param Int64|Optional|int $resumeAfter Specifies a resume token as the logical starting point for the change stream. Cannot be used with startAfter or startAtOperationTime fields. */ - public Int64|Optional|int $resumeAfter; + /** @param Optional|int $resumeAfter Specifies a resume token as the logical starting point for the change stream. Cannot be used with startAfter or startAtOperationTime fields. */ + public Optional|int $resumeAfter; /** * @param Optional|bool $showExpandedEvents Specifies whether to include additional change events, such as such as DDL and index operations. @@ -44,27 +45,27 @@ class ChangeStreamStage implements StageInterface /** @param Document|Optional|Serializable|array|stdClass $startAfter Specifies a resume token as the logical starting point for the change stream. Cannot be used with resumeAfter or startAtOperationTime fields. */ public Document|Serializable|Optional|stdClass|array $startAfter; - /** @param Optional|int $startAtOperationTime Specifies a time as the logical starting point for the change stream. Cannot be used with resumeAfter or startAfter fields. */ - public Optional|int $startAtOperationTime; + /** @param Optional|Timestamp|int $startAtOperationTime Specifies a time as the logical starting point for the change stream. Cannot be used with resumeAfter or startAfter fields. */ + public Timestamp|Optional|int $startAtOperationTime; /** * @param Optional|bool $allChangesForCluster A flag indicating whether the stream should report all changes that occur on the deployment, aside from those on internal databases or collections. * @param Optional|non-empty-string $fullDocument Specifies whether change notifications include a copy of the full document when modified by update operations. * @param Optional|non-empty-string $fullDocumentBeforeChange 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. - * @param Int64|Optional|int $resumeAfter Specifies a resume token as the logical starting point for the change stream. Cannot be used with startAfter or startAtOperationTime fields. + * @param Optional|int $resumeAfter Specifies a resume token as the logical starting point for the change stream. Cannot be used with startAfter or startAtOperationTime fields. * @param Optional|bool $showExpandedEvents Specifies whether to include additional change events, such as such as DDL and index operations. * New in version 6.0. * @param Document|Optional|Serializable|array|stdClass $startAfter Specifies a resume token as the logical starting point for the change stream. Cannot be used with resumeAfter or startAtOperationTime fields. - * @param Optional|int $startAtOperationTime Specifies a time as the logical starting point for the change stream. Cannot be used with resumeAfter or startAfter fields. + * @param Optional|Timestamp|int $startAtOperationTime Specifies a time as the logical starting point for the change stream. Cannot be used with resumeAfter or startAfter fields. */ public function __construct( Optional|bool $allChangesForCluster = Optional::Undefined, Optional|string $fullDocument = Optional::Undefined, Optional|string $fullDocumentBeforeChange = Optional::Undefined, - Int64|Optional|int $resumeAfter = Optional::Undefined, + Optional|int $resumeAfter = Optional::Undefined, Optional|bool $showExpandedEvents = Optional::Undefined, Document|Serializable|Optional|stdClass|array $startAfter = Optional::Undefined, - Optional|int $startAtOperationTime = Optional::Undefined, + Timestamp|Optional|int $startAtOperationTime = Optional::Undefined, ) { $this->allChangesForCluster = $allChangesForCluster; $this->fullDocument = $fullDocument; diff --git a/src/Builder/Stage/CollStatsStage.php b/src/Builder/Stage/CollStatsStage.php index e67831004..cce72109d 100644 --- a/src/Builder/Stage/CollStatsStage.php +++ b/src/Builder/Stage/CollStatsStage.php @@ -9,6 +9,7 @@ use MongoDB\BSON\Document; use MongoDB\BSON\Serializable; use MongoDB\Builder\Encode; +use MongoDB\Builder\Type\StageInterface; use stdClass; /** diff --git a/src/Builder/Stage/CountStage.php b/src/Builder/Stage/CountStage.php index c930acf05..3eb682104 100644 --- a/src/Builder/Stage/CountStage.php +++ b/src/Builder/Stage/CountStage.php @@ -7,6 +7,7 @@ namespace MongoDB\Builder\Stage; use MongoDB\Builder\Encode; +use MongoDB\Builder\Type\StageInterface; /** * Returns a count of the number of documents at this stage of the aggregation pipeline. diff --git a/src/Builder/Stage/CurrentOpStage.php b/src/Builder/Stage/CurrentOpStage.php index 3e8fe3ca1..80357cdd3 100644 --- a/src/Builder/Stage/CurrentOpStage.php +++ b/src/Builder/Stage/CurrentOpStage.php @@ -7,6 +7,7 @@ namespace MongoDB\Builder\Stage; use MongoDB\Builder\Encode; +use MongoDB\Builder\Type\StageInterface; /** * Returns information on active and/or dormant operations for the MongoDB deployment. To run, use the db.aggregate() method. diff --git a/src/Builder/Stage/DensifyStage.php b/src/Builder/Stage/DensifyStage.php index 3d1749d1d..817c2ed66 100644 --- a/src/Builder/Stage/DensifyStage.php +++ b/src/Builder/Stage/DensifyStage.php @@ -6,11 +6,13 @@ namespace MongoDB\Builder\Stage; +use MongoDB\BSON\Document; use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Serializable; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\FieldPath; use MongoDB\Builder\Optional; +use MongoDB\Builder\Type\StageInterface; use MongoDB\Model\BSONArray; use stdClass; @@ -31,22 +33,22 @@ class DensifyStage implements StageInterface */ public FieldPath|string $field; - /** @param array|stdClass $range Specification for range based densification. */ - public stdClass|array $range; + /** @param Document|Serializable|array|stdClass $range Specification for range based densification. */ + public Document|Serializable|stdClass|array $range; - /** @param BSONArray|Optional|PackedArray|list $partitionByFields The field(s) that will be used as the partition keys. */ + /** @param BSONArray|Optional|PackedArray|array $partitionByFields The field(s) that will be used as the partition keys. */ public PackedArray|Optional|BSONArray|array $partitionByFields; /** * @param FieldPath|non-empty-string $field 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. - * @param array|stdClass $range Specification for range based densification. - * @param BSONArray|Optional|PackedArray|list $partitionByFields The field(s) that will be used as the partition keys. + * @param Document|Serializable|array|stdClass $range Specification for range based densification. + * @param BSONArray|Optional|PackedArray|array $partitionByFields The field(s) that will be used as the partition keys. */ public function __construct( FieldPath|string $field, - stdClass|array $range, + Document|Serializable|stdClass|array $range, PackedArray|Optional|BSONArray|array $partitionByFields = Optional::Undefined, ) { $this->field = $field; @@ -54,6 +56,7 @@ public function __construct( if (\is_array($partitionByFields) && ! \array_is_list($partitionByFields)) { throw new \InvalidArgumentException('Expected $partitionByFields argument to be a list, got an associative array.'); } + $this->partitionByFields = $partitionByFields; } } diff --git a/src/Builder/Stage/DocumentsStage.php b/src/Builder/Stage/DocumentsStage.php index b2ccb75ff..1228b43ae 100644 --- a/src/Builder/Stage/DocumentsStage.php +++ b/src/Builder/Stage/DocumentsStage.php @@ -8,8 +8,8 @@ use MongoDB\BSON\PackedArray; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Expression\ResolvesToArray; +use MongoDB\Builder\Type\StageInterface; use MongoDB\Model\BSONArray; /** @@ -23,7 +23,7 @@ class DocumentsStage implements StageInterface public const ENCODE = \MongoDB\Builder\Encode::Single; /** - * @param BSONArray|PackedArray|ResolvesToArray|list $documents $documents accepts any valid expression that resolves to an array of objects. This includes: + * @param BSONArray|PackedArray|ResolvesToArray|array $documents $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 @@ -32,7 +32,7 @@ class DocumentsStage implements StageInterface public PackedArray|ResolvesToArray|BSONArray|array $documents; /** - * @param BSONArray|PackedArray|ResolvesToArray|list $documents $documents accepts any valid expression that resolves to an array of objects. This includes: + * @param BSONArray|PackedArray|ResolvesToArray|array $documents $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 @@ -43,6 +43,7 @@ public function __construct(PackedArray|ResolvesToArray|BSONArray|array $documen if (\is_array($documents) && ! \array_is_list($documents)) { throw new \InvalidArgumentException('Expected $documents argument to be a list, got an associative array.'); } + $this->documents = $documents; } } diff --git a/src/Builder/Stage/FacetStage.php b/src/Builder/Stage/FacetStage.php index 2fa1e86ad..139f7a68f 100644 --- a/src/Builder/Stage/FacetStage.php +++ b/src/Builder/Stage/FacetStage.php @@ -6,8 +6,11 @@ namespace MongoDB\Builder\Stage; +use MongoDB\BSON\PackedArray; use MongoDB\Builder\Encode; use MongoDB\Builder\Pipeline; +use MongoDB\Builder\Type\StageInterface; +use MongoDB\Model\BSONArray; use stdClass; /** @@ -20,20 +23,20 @@ class FacetStage implements StageInterface public const NAME = '$facet'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param stdClass ...$facet */ + /** @param stdClass ...$facet */ public stdClass $facet; /** - * @param Pipeline|array ...$facet + * @param BSONArray|PackedArray|Pipeline|array ...$facet */ - public function __construct(Pipeline|array ...$facet) + public function __construct(PackedArray|Pipeline|BSONArray|array ...$facet) { if (\count($facet) < 1) { throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $facet, got %d.', 1, \count($facet))); } foreach($facet as $key => $value) { if (! \is_string($key)) { - throw new \InvalidArgumentException('Expected $facet arguments to be a map of Pipeline|array, named arguments (:) or array unpacking ...[\'\' => ] must be used'); + throw new \InvalidArgumentException('Expected $facet arguments to be a map (object), named arguments (:) or array unpacking ...[\'\' => ] must be used'); } } $facet = (object) $facet; diff --git a/src/Builder/Stage/FillStage.php b/src/Builder/Stage/FillStage.php index fc7bb807d..666417d89 100644 --- a/src/Builder/Stage/FillStage.php +++ b/src/Builder/Stage/FillStage.php @@ -10,8 +10,8 @@ use MongoDB\BSON\PackedArray; use MongoDB\BSON\Serializable; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Optional; +use MongoDB\Builder\Type\StageInterface; use MongoDB\Model\BSONArray; use stdClass; @@ -39,14 +39,14 @@ class FillStage implements StageInterface public Document|Serializable|Optional|stdClass|array|string $partitionBy; /** - * @param BSONArray|Optional|PackedArray|list $partitionByFields 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. + * @param BSONArray|Optional|PackedArray|array $partitionByFields 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. */ public PackedArray|Optional|BSONArray|array $partitionByFields; - /** @param Optional|array|stdClass $sortBy Specifies the field or fields to sort the documents within each partition. Uses the same syntax as the $sort stage. */ - public Optional|stdClass|array $sortBy; + /** @param Document|Optional|Serializable|array|stdClass $sortBy Specifies the field or fields to sort the documents within each partition. Uses the same syntax as the $sort stage. */ + public Document|Serializable|Optional|stdClass|array $sortBy; /** * @param Document|Serializable|array|stdClass $output Specifies an object containing each field for which to fill missing values. You can specify multiple fields in the output object. @@ -54,22 +54,23 @@ class FillStage implements StageInterface * @param Document|Optional|Serializable|array|non-empty-string|stdClass $partitionBy 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. - * @param BSONArray|Optional|PackedArray|list $partitionByFields 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. + * @param BSONArray|Optional|PackedArray|array $partitionByFields 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. - * @param Optional|array|stdClass $sortBy Specifies the field or fields to sort the documents within each partition. Uses the same syntax as the $sort stage. + * @param Document|Optional|Serializable|array|stdClass $sortBy Specifies the field or fields to sort the documents within each partition. Uses the same syntax as the $sort stage. */ public function __construct( Document|Serializable|stdClass|array $output, Document|Serializable|Optional|stdClass|array|string $partitionBy = Optional::Undefined, PackedArray|Optional|BSONArray|array $partitionByFields = Optional::Undefined, - Optional|stdClass|array $sortBy = Optional::Undefined, + Document|Serializable|Optional|stdClass|array $sortBy = Optional::Undefined, ) { $this->output = $output; $this->partitionBy = $partitionBy; if (\is_array($partitionByFields) && ! \array_is_list($partitionByFields)) { throw new \InvalidArgumentException('Expected $partitionByFields argument to be a list, got an associative array.'); } + $this->partitionByFields = $partitionByFields; $this->sortBy = $sortBy; } diff --git a/src/Builder/Stage/GeoNearStage.php b/src/Builder/Stage/GeoNearStage.php index 810d736ba..9ea3cee6a 100644 --- a/src/Builder/Stage/GeoNearStage.php +++ b/src/Builder/Stage/GeoNearStage.php @@ -7,10 +7,17 @@ namespace MongoDB\Builder\Stage; use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Document; use MongoDB\BSON\Int64; +use MongoDB\BSON\Serializable; use MongoDB\Builder\Encode; +use MongoDB\Builder\Expression\ResolvesToDecimal; +use MongoDB\Builder\Expression\ResolvesToDouble; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Expression\ResolvesToLong; use MongoDB\Builder\Optional; -use MongoDB\Builder\Query\QueryInterface; +use MongoDB\Builder\Type\QueryInterface; +use MongoDB\Builder\Type\StageInterface; use stdClass; /** @@ -26,11 +33,11 @@ class GeoNearStage implements StageInterface /** @param non-empty-string $distanceField The output field that contains the calculated distance. To specify a field within an embedded document, use dot notation. */ public string $distanceField; - /** @param array|stdClass $near The point for which to find the closest documents. */ - public stdClass|array $near; + /** @param Document|Serializable|array|stdClass $near The point for which to find the closest documents. */ + public Document|Serializable|stdClass|array $near; - /** @param Decimal128|Int64|Optional|float|int $distanceMultiplier 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. */ - public Decimal128|Int64|Optional|float|int $distanceMultiplier; + /** @param Decimal128|Int64|Optional|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|float|int $distanceMultiplier 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. */ + public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|Optional|float|int $distanceMultiplier; /** @param Optional|non-empty-string $includeLocs 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. */ public Optional|string $includeLocs; @@ -39,22 +46,22 @@ class GeoNearStage implements StageInterface public Optional|string $key; /** - * @param Decimal128|Int64|Optional|float|int $maxDistance 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. + * @param Decimal128|Int64|Optional|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|float|int $maxDistance 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. */ - public Decimal128|Int64|Optional|float|int $maxDistance; + public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|Optional|float|int $maxDistance; /** - * @param Decimal128|Int64|Optional|float|int $minDistance 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. + * @param Decimal128|Int64|Optional|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|float|int $minDistance 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. */ - public Decimal128|Int64|Optional|float|int $minDistance; + public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|Optional|float|int $minDistance; /** - * @param Optional|QueryInterface|array|stdClass $query imits the results to the documents that match the query. The query syntax is the usual MongoDB read operation query syntax. + * @param Document|Optional|QueryInterface|Serializable|array|stdClass $query imits 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. */ - public Optional|QueryInterface|stdClass|array $query; + public Document|Serializable|Optional|QueryInterface|stdClass|array $query; /** * @param Optional|bool $spherical Determines how MongoDB calculates the distance between two points: @@ -66,15 +73,15 @@ class GeoNearStage implements StageInterface /** * @param non-empty-string $distanceField The output field that contains the calculated distance. To specify a field within an embedded document, use dot notation. - * @param array|stdClass $near The point for which to find the closest documents. - * @param Decimal128|Int64|Optional|float|int $distanceMultiplier 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. + * @param Document|Serializable|array|stdClass $near The point for which to find the closest documents. + * @param Decimal128|Int64|Optional|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|float|int $distanceMultiplier 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. * @param Optional|non-empty-string $includeLocs 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. * @param Optional|non-empty-string $key Specify the geospatial indexed field to use when calculating the distance. - * @param Decimal128|Int64|Optional|float|int $maxDistance 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. + * @param Decimal128|Int64|Optional|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|float|int $maxDistance 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. - * @param Decimal128|Int64|Optional|float|int $minDistance 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. + * @param Decimal128|Int64|Optional|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|float|int $minDistance 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. - * @param Optional|QueryInterface|array|stdClass $query imits the results to the documents that match the query. The query syntax is the usual MongoDB read operation query syntax. + * @param Document|Optional|QueryInterface|Serializable|array|stdClass $query imits 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. * @param Optional|bool $spherical Determines how MongoDB calculates the distance between two points: * - When true, MongoDB uses $nearSphere semantics and calculates distances using spherical geometry. @@ -83,13 +90,13 @@ class GeoNearStage implements StageInterface */ public function __construct( string $distanceField, - stdClass|array $near, - Decimal128|Int64|Optional|float|int $distanceMultiplier = Optional::Undefined, + Document|Serializable|stdClass|array $near, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|Optional|float|int $distanceMultiplier = Optional::Undefined, Optional|string $includeLocs = Optional::Undefined, Optional|string $key = Optional::Undefined, - Decimal128|Int64|Optional|float|int $maxDistance = Optional::Undefined, - Decimal128|Int64|Optional|float|int $minDistance = Optional::Undefined, - Optional|QueryInterface|stdClass|array $query = Optional::Undefined, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|Optional|float|int $maxDistance = Optional::Undefined, + Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|Optional|float|int $minDistance = Optional::Undefined, + Document|Serializable|Optional|QueryInterface|stdClass|array $query = Optional::Undefined, Optional|bool $spherical = Optional::Undefined, ) { $this->distanceField = $distanceField; diff --git a/src/Builder/Stage/GraphLookupStage.php b/src/Builder/Stage/GraphLookupStage.php index 2333d7f93..effa015d7 100644 --- a/src/Builder/Stage/GraphLookupStage.php +++ b/src/Builder/Stage/GraphLookupStage.php @@ -6,12 +6,22 @@ namespace MongoDB\Builder\Stage; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Document; use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; +use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; +use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Optional; -use MongoDB\Builder\Query\QueryInterface; +use MongoDB\Builder\Type\ExpressionInterface; +use MongoDB\Builder\Type\QueryInterface; +use MongoDB\Builder\Type\StageInterface; use MongoDB\Model\BSONArray; use stdClass; @@ -31,8 +41,8 @@ class GraphLookupStage implements StageInterface */ public string $from; - /** @param BSONArray|ExpressionInterface|PackedArray|list|mixed $startWith 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. */ - public mixed $startWith; + /** @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $startWith 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. */ + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $startWith; /** @param non-empty-string $connectFromField 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. */ public string $connectFromField; @@ -43,40 +53,41 @@ class GraphLookupStage implements StageInterface /** @param non-empty-string $as Name of the array field added to each output document. Contains the documents traversed in the $graphLookup stage to reach the document. */ public string $as; - /** @param Int64|Optional|int $maxDepth Non-negative integral number specifying the maximum recursion depth. */ - public Int64|Optional|int $maxDepth; + /** @param Optional|int $maxDepth Non-negative integral number specifying the maximum recursion depth. */ + public Optional|int $maxDepth; /** @param Optional|non-empty-string $depthField 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. */ public Optional|string $depthField; - /** @param Optional|QueryInterface|array|stdClass $restrictSearchWithMatch A document specifying additional conditions for the recursive search. The syntax is identical to query filter syntax. */ - public Optional|QueryInterface|stdClass|array $restrictSearchWithMatch; + /** @param Document|Optional|QueryInterface|Serializable|array|stdClass $restrictSearchWithMatch A document specifying additional conditions for the recursive search. The syntax is identical to query filter syntax. */ + public Document|Serializable|Optional|QueryInterface|stdClass|array $restrictSearchWithMatch; /** * @param non-empty-string $from 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. - * @param BSONArray|ExpressionInterface|PackedArray|list|mixed $startWith 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. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $startWith 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. * @param non-empty-string $connectFromField 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. * @param non-empty-string $connectToField Field name in other documents against which to match the value of the field specified by the connectFromField parameter. * @param non-empty-string $as Name of the array field added to each output document. Contains the documents traversed in the $graphLookup stage to reach the document. - * @param Int64|Optional|int $maxDepth Non-negative integral number specifying the maximum recursion depth. + * @param Optional|int $maxDepth Non-negative integral number specifying the maximum recursion depth. * @param Optional|non-empty-string $depthField 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. - * @param Optional|QueryInterface|array|stdClass $restrictSearchWithMatch A document specifying additional conditions for the recursive search. The syntax is identical to query filter syntax. + * @param Document|Optional|QueryInterface|Serializable|array|stdClass $restrictSearchWithMatch A document specifying additional conditions for the recursive search. The syntax is identical to query filter syntax. */ public function __construct( string $from, - mixed $startWith, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $startWith, string $connectFromField, string $connectToField, string $as, - Int64|Optional|int $maxDepth = Optional::Undefined, + Optional|int $maxDepth = Optional::Undefined, Optional|string $depthField = Optional::Undefined, - Optional|QueryInterface|stdClass|array $restrictSearchWithMatch = Optional::Undefined, + Document|Serializable|Optional|QueryInterface|stdClass|array $restrictSearchWithMatch = Optional::Undefined, ) { $this->from = $from; if (\is_array($startWith) && ! \array_is_list($startWith)) { throw new \InvalidArgumentException('Expected $startWith argument to be a list, got an associative array.'); } + $this->startWith = $startWith; $this->connectFromField = $connectFromField; $this->connectToField = $connectToField; diff --git a/src/Builder/Stage/GroupStage.php b/src/Builder/Stage/GroupStage.php index dc3c40339..f67f84478 100644 --- a/src/Builder/Stage/GroupStage.php +++ b/src/Builder/Stage/GroupStage.php @@ -6,9 +6,22 @@ namespace MongoDB\Builder\Stage; -use MongoDB\Builder\Aggregation\AccumulatorInterface; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Document; +use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; +use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; +use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Type\AccumulatorInterface; +use MongoDB\Builder\Type\ExpressionInterface; +use MongoDB\Builder\Type\StageInterface; +use MongoDB\Model\BSONArray; use stdClass; /** @@ -21,25 +34,31 @@ class GroupStage implements StageInterface public const NAME = '$group'; public const ENCODE = \MongoDB\Builder\Encode::Group; - /** @param ExpressionInterface|mixed $_id 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. */ - public mixed $_id; + /** @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $_id 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. */ + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $_id; - /** @param stdClass ...$field Computed using the accumulator operators. */ + /** @param stdClass ...$field Computed using the accumulator operators. */ public stdClass $field; /** - * @param ExpressionInterface|mixed $_id 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. - * @param AccumulatorInterface ...$field Computed using the accumulator operators. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $_id 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. + * @param AccumulatorInterface|Document|Serializable|array|stdClass ...$field Computed using the accumulator operators. */ - public function __construct(mixed $_id, AccumulatorInterface ...$field) - { + public function __construct( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $_id, + Document|Serializable|AccumulatorInterface|stdClass|array ...$field, + ) { + if (\is_array($_id) && ! \array_is_list($_id)) { + throw new \InvalidArgumentException('Expected $_id argument to be a list, got an associative array.'); + } + $this->_id = $_id; if (\count($field) < 1) { throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $field, got %d.', 1, \count($field))); } foreach($field as $key => $value) { if (! \is_string($key)) { - throw new \InvalidArgumentException('Expected $field arguments to be a map of AccumulatorInterface, named arguments (:) or array unpacking ...[\'\' => ] must be used'); + throw new \InvalidArgumentException('Expected $field arguments to be a map (object), named arguments (:) or array unpacking ...[\'\' => ] must be used'); } } $field = (object) $field; diff --git a/src/Builder/Stage/IndexStatsStage.php b/src/Builder/Stage/IndexStatsStage.php index e13515d69..d6984e2e9 100644 --- a/src/Builder/Stage/IndexStatsStage.php +++ b/src/Builder/Stage/IndexStatsStage.php @@ -7,6 +7,7 @@ namespace MongoDB\Builder\Stage; use MongoDB\Builder\Encode; +use MongoDB\Builder\Type\StageInterface; /** * Returns statistics regarding the use of each index for the collection. diff --git a/src/Builder/Stage/LimitStage.php b/src/Builder/Stage/LimitStage.php index 9050d2d1f..f0d02c08d 100644 --- a/src/Builder/Stage/LimitStage.php +++ b/src/Builder/Stage/LimitStage.php @@ -6,8 +6,8 @@ namespace MongoDB\Builder\Stage; -use MongoDB\BSON\Int64; use MongoDB\Builder\Encode; +use MongoDB\Builder\Type\StageInterface; /** * 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). @@ -19,13 +19,13 @@ class LimitStage implements StageInterface public const NAME = '$limit'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param Int64|int $limit */ - public Int64|int $limit; + /** @param int $limit */ + public int $limit; /** - * @param Int64|int $limit + * @param int $limit */ - public function __construct(Int64|int $limit) + public function __construct(int $limit) { $this->limit = $limit; } diff --git a/src/Builder/Stage/ListLocalSessionsStage.php b/src/Builder/Stage/ListLocalSessionsStage.php index fe8f35fbc..fcd4cf9cb 100644 --- a/src/Builder/Stage/ListLocalSessionsStage.php +++ b/src/Builder/Stage/ListLocalSessionsStage.php @@ -8,8 +8,8 @@ use MongoDB\BSON\PackedArray; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Optional; +use MongoDB\Builder\Type\StageInterface; use MongoDB\Model\BSONArray; /** @@ -22,14 +22,14 @@ class ListLocalSessionsStage implements StageInterface public const NAME = '$listLocalSessions'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param BSONArray|Optional|PackedArray|list $users 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. */ + /** @param BSONArray|Optional|PackedArray|array $users 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. */ public PackedArray|Optional|BSONArray|array $users; /** @param Optional|bool $allUsers Returns all sessions for all users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster. */ public Optional|bool $allUsers; /** - * @param BSONArray|Optional|PackedArray|list $users 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. + * @param BSONArray|Optional|PackedArray|array $users 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. * @param Optional|bool $allUsers Returns all sessions for all users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster. */ public function __construct( @@ -39,6 +39,7 @@ public function __construct( if (\is_array($users) && ! \array_is_list($users)) { throw new \InvalidArgumentException('Expected $users argument to be a list, got an associative array.'); } + $this->users = $users; $this->allUsers = $allUsers; } diff --git a/src/Builder/Stage/ListSampledQueriesStage.php b/src/Builder/Stage/ListSampledQueriesStage.php index 466a7eeaf..e4c609456 100644 --- a/src/Builder/Stage/ListSampledQueriesStage.php +++ b/src/Builder/Stage/ListSampledQueriesStage.php @@ -8,6 +8,7 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Optional; +use MongoDB\Builder\Type\StageInterface; /** * Lists sampled queries for all collections or a specific collection. diff --git a/src/Builder/Stage/ListSearchIndexesStage.php b/src/Builder/Stage/ListSearchIndexesStage.php index 473a426d1..caaa29fb1 100644 --- a/src/Builder/Stage/ListSearchIndexesStage.php +++ b/src/Builder/Stage/ListSearchIndexesStage.php @@ -8,6 +8,7 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Optional; +use MongoDB\Builder\Type\StageInterface; /** * Returns information about existing Atlas Search indexes on a specified collection. diff --git a/src/Builder/Stage/ListSessionsStage.php b/src/Builder/Stage/ListSessionsStage.php index 45a94f87f..7496c629c 100644 --- a/src/Builder/Stage/ListSessionsStage.php +++ b/src/Builder/Stage/ListSessionsStage.php @@ -8,8 +8,8 @@ use MongoDB\BSON\PackedArray; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Optional; +use MongoDB\Builder\Type\StageInterface; use MongoDB\Model\BSONArray; /** @@ -22,14 +22,14 @@ class ListSessionsStage implements StageInterface public const NAME = '$listSessions'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param BSONArray|Optional|PackedArray|list $users 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. */ + /** @param BSONArray|Optional|PackedArray|array $users 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. */ public PackedArray|Optional|BSONArray|array $users; /** @param Optional|bool $allUsers Returns all sessions for all users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster. */ public Optional|bool $allUsers; /** - * @param BSONArray|Optional|PackedArray|list $users 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. + * @param BSONArray|Optional|PackedArray|array $users 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. * @param Optional|bool $allUsers Returns all sessions for all users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster. */ public function __construct( @@ -39,6 +39,7 @@ public function __construct( if (\is_array($users) && ! \array_is_list($users)) { throw new \InvalidArgumentException('Expected $users argument to be a list, got an associative array.'); } + $this->users = $users; $this->allUsers = $allUsers; } diff --git a/src/Builder/Stage/LookupStage.php b/src/Builder/Stage/LookupStage.php index 0daf0946f..daf81eaec 100644 --- a/src/Builder/Stage/LookupStage.php +++ b/src/Builder/Stage/LookupStage.php @@ -7,10 +7,13 @@ namespace MongoDB\Builder\Stage; use MongoDB\BSON\Document; +use MongoDB\BSON\PackedArray; use MongoDB\BSON\Serializable; use MongoDB\Builder\Encode; use MongoDB\Builder\Optional; use MongoDB\Builder\Pipeline; +use MongoDB\Builder\Type\StageInterface; +use MongoDB\Model\BSONArray; use stdClass; /** @@ -43,11 +46,11 @@ class LookupStage implements StageInterface public Document|Serializable|Optional|stdClass|array $let; /** - * @param Optional|Pipeline|array $pipeline 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 []. + * @param BSONArray|Optional|PackedArray|Pipeline|array $pipeline 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 $mergestage. 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. */ - public Optional|Pipeline|array $pipeline; + public PackedArray|Optional|Pipeline|BSONArray|array $pipeline; /** * @param non-empty-string $as 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. @@ -57,7 +60,7 @@ class LookupStage implements StageInterface * @param Optional|non-empty-string $localField 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. * @param Optional|non-empty-string $foreignField 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. * @param Document|Optional|Serializable|array|stdClass $let 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. - * @param Optional|Pipeline|array $pipeline 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 []. + * @param BSONArray|Optional|PackedArray|Pipeline|array $pipeline 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 $mergestage. 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. */ @@ -67,13 +70,17 @@ public function __construct( Optional|string $localField = Optional::Undefined, Optional|string $foreignField = Optional::Undefined, Document|Serializable|Optional|stdClass|array $let = Optional::Undefined, - Optional|Pipeline|array $pipeline = Optional::Undefined, + PackedArray|Optional|Pipeline|BSONArray|array $pipeline = Optional::Undefined, ) { $this->as = $as; $this->from = $from; $this->localField = $localField; $this->foreignField = $foreignField; $this->let = $let; + if (\is_array($pipeline) && ! \array_is_list($pipeline)) { + throw new \InvalidArgumentException('Expected $pipeline argument to be a list, got an associative array.'); + } + $this->pipeline = $pipeline; } } diff --git a/src/Builder/Stage/MatchStage.php b/src/Builder/Stage/MatchStage.php index 1f48a44fa..64b49736c 100644 --- a/src/Builder/Stage/MatchStage.php +++ b/src/Builder/Stage/MatchStage.php @@ -6,8 +6,11 @@ namespace MongoDB\Builder\Stage; +use MongoDB\BSON\Document; +use MongoDB\BSON\Serializable; use MongoDB\Builder\Encode; -use MongoDB\Builder\Query\QueryInterface; +use MongoDB\Builder\Type\QueryInterface; +use MongoDB\Builder\Type\StageInterface; use stdClass; /** @@ -20,13 +23,13 @@ class MatchStage implements StageInterface public const NAME = '$match'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param QueryInterface|array|stdClass $query */ - public QueryInterface|stdClass|array $query; + /** @param Document|QueryInterface|Serializable|array|stdClass $query */ + public Document|Serializable|QueryInterface|stdClass|array $query; /** - * @param QueryInterface|array|stdClass $query + * @param Document|QueryInterface|Serializable|array|stdClass $query */ - public function __construct(QueryInterface|stdClass|array $query) + public function __construct(Document|Serializable|QueryInterface|stdClass|array $query) { $this->query = $query; } diff --git a/src/Builder/Stage/MergeStage.php b/src/Builder/Stage/MergeStage.php index f200ffd4b..bc9d17ab4 100644 --- a/src/Builder/Stage/MergeStage.php +++ b/src/Builder/Stage/MergeStage.php @@ -10,8 +10,8 @@ use MongoDB\BSON\PackedArray; use MongoDB\BSON\Serializable; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; use MongoDB\Builder\Optional; +use MongoDB\Builder\Type\StageInterface; use MongoDB\Model\BSONArray; use stdClass; @@ -26,10 +26,10 @@ class MergeStage implements StageInterface public const NAME = '$merge'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param array|non-empty-string|stdClass $into The output collection. */ - public stdClass|array|string $into; + /** @param Document|Serializable|array|non-empty-string|stdClass $into The output collection. */ + public Document|Serializable|stdClass|array|string $into; - /** @param BSONArray|Optional|PackedArray|list|non-empty-string $on 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. */ + /** @param BSONArray|Optional|PackedArray|array|non-empty-string $on 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. */ public PackedArray|Optional|BSONArray|array|string $on; /** @param Document|Optional|Serializable|array|stdClass $let Specifies variables for use in the whenMatched pipeline. */ @@ -42,14 +42,14 @@ class MergeStage implements StageInterface public Optional|string $whenNotMatched; /** - * @param array|non-empty-string|stdClass $into The output collection. - * @param BSONArray|Optional|PackedArray|list|non-empty-string $on 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. + * @param Document|Serializable|array|non-empty-string|stdClass $into The output collection. + * @param BSONArray|Optional|PackedArray|array|non-empty-string $on 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. * @param Document|Optional|Serializable|array|stdClass $let Specifies variables for use in the whenMatched pipeline. * @param Optional|non-empty-string $whenMatched 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). * @param Optional|non-empty-string $whenNotMatched The behavior of $merge if a result document does not match an existing document in the out collection. */ public function __construct( - stdClass|array|string $into, + Document|Serializable|stdClass|array|string $into, PackedArray|Optional|BSONArray|array|string $on = Optional::Undefined, Document|Serializable|Optional|stdClass|array $let = Optional::Undefined, Optional|string $whenMatched = Optional::Undefined, @@ -59,6 +59,7 @@ public function __construct( if (\is_array($on) && ! \array_is_list($on)) { throw new \InvalidArgumentException('Expected $on argument to be a list, got an associative array.'); } + $this->on = $on; $this->let = $let; $this->whenMatched = $whenMatched; diff --git a/src/Builder/Stage/OutStage.php b/src/Builder/Stage/OutStage.php index a25328b80..fc05b03b7 100644 --- a/src/Builder/Stage/OutStage.php +++ b/src/Builder/Stage/OutStage.php @@ -10,6 +10,7 @@ use MongoDB\BSON\Serializable; use MongoDB\Builder\Encode; use MongoDB\Builder\Optional; +use MongoDB\Builder\Type\StageInterface; use stdClass; /** diff --git a/src/Builder/Stage/PlanCacheStatsStage.php b/src/Builder/Stage/PlanCacheStatsStage.php index b6b1987ea..d95560f94 100644 --- a/src/Builder/Stage/PlanCacheStatsStage.php +++ b/src/Builder/Stage/PlanCacheStatsStage.php @@ -7,6 +7,7 @@ namespace MongoDB\Builder\Stage; use MongoDB\Builder\Encode; +use MongoDB\Builder\Type\StageInterface; /** * Returns plan cache information for a collection. diff --git a/src/Builder/Stage/ProjectStage.php b/src/Builder/Stage/ProjectStage.php index cf1424ba2..4f1851bb8 100644 --- a/src/Builder/Stage/ProjectStage.php +++ b/src/Builder/Stage/ProjectStage.php @@ -6,9 +6,12 @@ namespace MongoDB\Builder\Stage; -use MongoDB\BSON\Int64; +use MongoDB\BSON\Document; +use MongoDB\BSON\Serializable; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; +use MongoDB\Builder\Expression\ResolvesToBool; +use MongoDB\Builder\Type\ProjectionInterface; +use MongoDB\Builder\Type\StageInterface; use stdClass; /** @@ -21,20 +24,21 @@ class ProjectStage implements StageInterface public const NAME = '$project'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param stdClass ...$specification */ + /** @param stdClass ...$specification */ public stdClass $specification; /** - * @param ExpressionInterface|Int64|bool|int|mixed ...$specification + * @param Document|ProjectionInterface|ResolvesToBool|Serializable|array|bool|int|stdClass ...$specification */ - public function __construct(mixed ...$specification) - { + public function __construct( + Document|Serializable|ResolvesToBool|ProjectionInterface|stdClass|array|bool|int ...$specification, + ) { if (\count($specification) < 1) { throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $specification, got %d.', 1, \count($specification))); } foreach($specification as $key => $value) { if (! \is_string($key)) { - throw new \InvalidArgumentException('Expected $specification arguments to be a map of ExpressionInterface|Int64|bool|int|mixed, named arguments (:) or array unpacking ...[\'\' => ] must be used'); + throw new \InvalidArgumentException('Expected $specification arguments to be a map (object), named arguments (:) or array unpacking ...[\'\' => ] must be used'); } } $specification = (object) $specification; diff --git a/src/Builder/Stage/RedactStage.php b/src/Builder/Stage/RedactStage.php index 4fc132687..fc9cc68e1 100644 --- a/src/Builder/Stage/RedactStage.php +++ b/src/Builder/Stage/RedactStage.php @@ -6,8 +6,22 @@ namespace MongoDB\Builder\Stage; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Document; +use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; +use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; +use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Type\ExpressionInterface; +use MongoDB\Builder\Type\StageInterface; +use MongoDB\Model\BSONArray; +use stdClass; /** * 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. @@ -19,14 +33,19 @@ class RedactStage implements StageInterface public const NAME = '$redact'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param ExpressionInterface|mixed $expression */ - public mixed $expression; + /** @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression */ + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression; /** - * @param ExpressionInterface|mixed $expression + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression */ - public function __construct(mixed $expression) - { + public function __construct( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, + ) { + if (\is_array($expression) && ! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression argument to be a list, got an associative array.'); + } + $this->expression = $expression; } } diff --git a/src/Builder/Stage/ReplaceRootStage.php b/src/Builder/Stage/ReplaceRootStage.php index 004a40a4d..b77bb56e9 100644 --- a/src/Builder/Stage/ReplaceRootStage.php +++ b/src/Builder/Stage/ReplaceRootStage.php @@ -10,6 +10,7 @@ use MongoDB\BSON\Serializable; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToObject; +use MongoDB\Builder\Type\StageInterface; use stdClass; /** diff --git a/src/Builder/Stage/ReplaceWithStage.php b/src/Builder/Stage/ReplaceWithStage.php index e05786856..292df82cd 100644 --- a/src/Builder/Stage/ReplaceWithStage.php +++ b/src/Builder/Stage/ReplaceWithStage.php @@ -10,6 +10,7 @@ use MongoDB\BSON\Serializable; use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ResolvesToObject; +use MongoDB\Builder\Type\StageInterface; use stdClass; /** diff --git a/src/Builder/Stage/SampleStage.php b/src/Builder/Stage/SampleStage.php index 0729e420f..daef55bf3 100644 --- a/src/Builder/Stage/SampleStage.php +++ b/src/Builder/Stage/SampleStage.php @@ -6,8 +6,8 @@ namespace MongoDB\Builder\Stage; -use MongoDB\BSON\Int64; use MongoDB\Builder\Encode; +use MongoDB\Builder\Type\StageInterface; /** * Randomly selects the specified number of documents from its input. @@ -19,13 +19,13 @@ class SampleStage implements StageInterface public const NAME = '$sample'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param Int64|int $size The number of documents to randomly select. */ - public Int64|int $size; + /** @param int $size The number of documents to randomly select. */ + public int $size; /** - * @param Int64|int $size The number of documents to randomly select. + * @param int $size The number of documents to randomly select. */ - public function __construct(Int64|int $size) + public function __construct(int $size) { $this->size = $size; } diff --git a/src/Builder/Stage/SearchMetaStage.php b/src/Builder/Stage/SearchMetaStage.php index 66b1ccf3b..710c66236 100644 --- a/src/Builder/Stage/SearchMetaStage.php +++ b/src/Builder/Stage/SearchMetaStage.php @@ -9,6 +9,7 @@ use MongoDB\BSON\Document; use MongoDB\BSON\Serializable; use MongoDB\Builder\Encode; +use MongoDB\Builder\Type\StageInterface; use stdClass; /** diff --git a/src/Builder/Stage/SearchStage.php b/src/Builder/Stage/SearchStage.php index cc5f92002..36cb7b266 100644 --- a/src/Builder/Stage/SearchStage.php +++ b/src/Builder/Stage/SearchStage.php @@ -9,6 +9,7 @@ use MongoDB\BSON\Document; use MongoDB\BSON\Serializable; use MongoDB\Builder\Encode; +use MongoDB\Builder\Type\StageInterface; use stdClass; /** diff --git a/src/Builder/Stage/SetStage.php b/src/Builder/Stage/SetStage.php index 38a60cdf8..835c2dd3d 100644 --- a/src/Builder/Stage/SetStage.php +++ b/src/Builder/Stage/SetStage.php @@ -6,8 +6,21 @@ namespace MongoDB\Builder\Stage; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Document; +use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; +use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; +use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Type\ExpressionInterface; +use MongoDB\Builder\Type\StageInterface; +use MongoDB\Model\BSONArray; use stdClass; /** @@ -21,20 +34,21 @@ class SetStage implements StageInterface public const NAME = '$set'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param stdClass ...$field */ + /** @param stdClass ...$field */ public stdClass $field; /** - * @param ExpressionInterface|mixed ...$field + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass ...$field */ - public function __construct(mixed ...$field) - { + public function __construct( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string ...$field, + ) { if (\count($field) < 1) { throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $field, got %d.', 1, \count($field))); } foreach($field as $key => $value) { if (! \is_string($key)) { - throw new \InvalidArgumentException('Expected $field arguments to be a map of ExpressionInterface|mixed, named arguments (:) or array unpacking ...[\'\' => ] must be used'); + throw new \InvalidArgumentException('Expected $field arguments to be a map (object), named arguments (:) or array unpacking ...[\'\' => ] must be used'); } } $field = (object) $field; diff --git a/src/Builder/Stage/SetWindowFieldsStage.php b/src/Builder/Stage/SetWindowFieldsStage.php index bf9cc59cc..886e4a771 100644 --- a/src/Builder/Stage/SetWindowFieldsStage.php +++ b/src/Builder/Stage/SetWindowFieldsStage.php @@ -6,11 +6,22 @@ namespace MongoDB\Builder\Stage; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Decimal128; use MongoDB\BSON\Document; +use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; +use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; +use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Optional; +use MongoDB\Builder\Type\ExpressionInterface; +use MongoDB\Builder\Type\StageInterface; +use MongoDB\Model\BSONArray; use stdClass; /** @@ -24,11 +35,11 @@ class SetWindowFieldsStage implements StageInterface public const NAME = '$setWindowFields'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param ExpressionInterface|mixed $partitionBy 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. */ - public mixed $partitionBy; + /** @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $partitionBy 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. */ + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $partitionBy; - /** @param array|stdClass $sortBy Specifies the field(s) to sort the documents by in the partition. Uses the same syntax as the $sort stage. Default is no sorting. */ - public stdClass|array $sortBy; + /** @param Document|Serializable|array|stdClass $sortBy Specifies the field(s) to sort the documents by in the partition. Uses the same syntax as the $sort stage. Default is no sorting. */ + public Document|Serializable|stdClass|array $sortBy; /** * @param Document|Serializable|array|stdClass $output 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. @@ -36,22 +47,26 @@ class SetWindowFieldsStage implements StageInterface */ public Document|Serializable|stdClass|array $output; - /** @param Optional|array|stdClass $window Specifies the window boundaries and parameters. Window boundaries are inclusive. Default is an unbounded window, which includes all documents in the partition. */ - public Optional|stdClass|array $window; + /** @param Document|Optional|Serializable|array|stdClass $window Specifies the window boundaries and parameters. Window boundaries are inclusive. Default is an unbounded window, which includes all documents in the partition. */ + public Document|Serializable|Optional|stdClass|array $window; /** - * @param ExpressionInterface|mixed $partitionBy 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. - * @param array|stdClass $sortBy Specifies the field(s) to sort the documents by in the partition. Uses the same syntax as the $sort stage. Default is no sorting. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $partitionBy 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. + * @param Document|Serializable|array|stdClass $sortBy Specifies the field(s) to sort the documents by in the partition. Uses the same syntax as the $sort stage. Default is no sorting. * @param Document|Serializable|array|stdClass $output 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. - * @param Optional|array|stdClass $window Specifies the window boundaries and parameters. Window boundaries are inclusive. Default is an unbounded window, which includes all documents in the partition. + * @param Document|Optional|Serializable|array|stdClass $window Specifies the window boundaries and parameters. Window boundaries are inclusive. Default is an unbounded window, which includes all documents in the partition. */ public function __construct( - mixed $partitionBy, - stdClass|array $sortBy, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $partitionBy, + Document|Serializable|stdClass|array $sortBy, Document|Serializable|stdClass|array $output, - Optional|stdClass|array $window = Optional::Undefined, + Document|Serializable|Optional|stdClass|array $window = Optional::Undefined, ) { + if (\is_array($partitionBy) && ! \array_is_list($partitionBy)) { + throw new \InvalidArgumentException('Expected $partitionBy argument to be a list, got an associative array.'); + } + $this->partitionBy = $partitionBy; $this->sortBy = $sortBy; $this->output = $output; diff --git a/src/Builder/Stage/ShardedDataDistributionStage.php b/src/Builder/Stage/ShardedDataDistributionStage.php index f8b15e596..3457e9969 100644 --- a/src/Builder/Stage/ShardedDataDistributionStage.php +++ b/src/Builder/Stage/ShardedDataDistributionStage.php @@ -7,6 +7,7 @@ namespace MongoDB\Builder\Stage; use MongoDB\Builder\Encode; +use MongoDB\Builder\Type\StageInterface; /** * Provides data and size distribution information on sharded collections. diff --git a/src/Builder/Stage/SkipStage.php b/src/Builder/Stage/SkipStage.php index 79038b5b7..fa6f50eca 100644 --- a/src/Builder/Stage/SkipStage.php +++ b/src/Builder/Stage/SkipStage.php @@ -6,8 +6,8 @@ namespace MongoDB\Builder\Stage; -use MongoDB\BSON\Int64; use MongoDB\Builder\Encode; +use MongoDB\Builder\Type\StageInterface; /** * 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). @@ -19,13 +19,13 @@ class SkipStage implements StageInterface public const NAME = '$skip'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param Int64|int $skip */ - public Int64|int $skip; + /** @param int $skip */ + public int $skip; /** - * @param Int64|int $skip + * @param int $skip */ - public function __construct(Int64|int $skip) + public function __construct(int $skip) { $this->skip = $skip; } diff --git a/src/Builder/Stage/SortByCountStage.php b/src/Builder/Stage/SortByCountStage.php index 47d51f92d..32d093510 100644 --- a/src/Builder/Stage/SortByCountStage.php +++ b/src/Builder/Stage/SortByCountStage.php @@ -6,8 +6,22 @@ namespace MongoDB\Builder\Stage; +use MongoDB\BSON\Binary; +use MongoDB\BSON\Decimal128; +use MongoDB\BSON\Document; +use MongoDB\BSON\Int64; +use MongoDB\BSON\ObjectId; +use MongoDB\BSON\PackedArray; +use MongoDB\BSON\Regex; +use MongoDB\BSON\Serializable; +use MongoDB\BSON\Timestamp; +use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ExpressionInterface; +use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Type\ExpressionInterface; +use MongoDB\Builder\Type\StageInterface; +use MongoDB\Model\BSONArray; +use stdClass; /** * Groups incoming documents based on the value of a specified expression, then computes the count of documents in each distinct group. @@ -19,14 +33,19 @@ class SortByCountStage implements StageInterface public const NAME = '$sortByCount'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param ExpressionInterface|mixed $expression */ - public mixed $expression; + /** @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression */ + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression; /** - * @param ExpressionInterface|mixed $expression + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression */ - public function __construct(mixed $expression) - { + public function __construct( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, + ) { + if (\is_array($expression) && ! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression argument to be a list, got an associative array.'); + } + $this->expression = $expression; } } diff --git a/src/Builder/Stage/SortStage.php b/src/Builder/Stage/SortStage.php index d3d970457..3da5e6b45 100644 --- a/src/Builder/Stage/SortStage.php +++ b/src/Builder/Stage/SortStage.php @@ -6,7 +6,10 @@ namespace MongoDB\Builder\Stage; +use MongoDB\BSON\Document; +use MongoDB\BSON\Serializable; use MongoDB\Builder\Encode; +use MongoDB\Builder\Type\StageInterface; use stdClass; /** @@ -19,13 +22,13 @@ class SortStage implements StageInterface public const NAME = '$sort'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param array|stdClass $sort */ - public stdClass|array $sort; + /** @param Document|Serializable|array|stdClass $sort */ + public Document|Serializable|stdClass|array $sort; /** - * @param array|stdClass $sort + * @param Document|Serializable|array|stdClass $sort */ - public function __construct(stdClass|array $sort) + public function __construct(Document|Serializable|stdClass|array $sort) { $this->sort = $sort; } diff --git a/src/Builder/Stage/StageInterface.php b/src/Builder/Stage/StageInterface.php deleted file mode 100644 index 2e7524f26..000000000 --- a/src/Builder/Stage/StageInterface.php +++ /dev/null @@ -1,7 +0,0 @@ -coll = $coll; + if (\is_array($pipeline) && ! \array_is_list($pipeline)) { + throw new \InvalidArgumentException('Expected $pipeline argument to be a list, got an associative array.'); + } + $this->pipeline = $pipeline; } } diff --git a/src/Builder/Stage/UnsetStage.php b/src/Builder/Stage/UnsetStage.php index 0dfb5edc4..8a2f831d2 100644 --- a/src/Builder/Stage/UnsetStage.php +++ b/src/Builder/Stage/UnsetStage.php @@ -8,6 +8,7 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\FieldPath; +use MongoDB\Builder\Type\StageInterface; /** * Removes or excludes fields from documents. @@ -33,7 +34,7 @@ public function __construct(FieldPath|string ...$field) throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $field, got %d.', 1, \count($field))); } if (! \array_is_list($field)) { - throw new \InvalidArgumentException('Expected $field arguments to be a list of FieldPath|non-empty-string, named arguments are not supported'); + throw new \InvalidArgumentException('Expected $field arguments to be a list (array), named arguments are not supported'); } $this->field = $field; } diff --git a/src/Builder/Stage/UnwindStage.php b/src/Builder/Stage/UnwindStage.php index daadc8099..efe5a830f 100644 --- a/src/Builder/Stage/UnwindStage.php +++ b/src/Builder/Stage/UnwindStage.php @@ -8,6 +8,7 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ArrayFieldPath; +use MongoDB\Builder\Type\StageInterface; /** * 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. diff --git a/src/Builder/Type/AccumulatorInterface.php b/src/Builder/Type/AccumulatorInterface.php new file mode 100644 index 000000000..63a96a89a --- /dev/null +++ b/src/Builder/Type/AccumulatorInterface.php @@ -0,0 +1,16 @@ + Date: Wed, 11 Oct 2023 00:37:37 +0200 Subject: [PATCH 20/37] Rename Expression Operators and write architecture document --- .gitattributes | 5 - examples/aggregation-builder.php | 27 +- .../config/aggregation-stages/unwind.yaml | 15 - .../config/{operators.php => definitions.php} | 12 +- .../abs.yaml | 0 .../accumulator.yaml | 0 .../acos.yaml | 0 .../acosh.yaml | 0 .../add.yaml | 0 .../addToSet.yaml | 2 +- .../allElementsTrue.yaml | 0 .../and.yaml | 0 .../anyElementTrue.yaml | 0 .../arrayElemAt.yaml | 0 .../arrayToObject.yaml | 0 .../asin.yaml | 0 .../asinh.yaml | 0 .../atan.yaml | 0 .../atan2.yaml | 0 .../atanh.yaml | 0 .../avg.yaml | 1 + .../binarySize.yaml | 0 .../bitAnd.yaml | 0 .../bitNot.yaml | 0 .../bitOr.yaml | 0 .../bitXor.yaml | 0 .../bottom.yaml | 1 + .../bottomN.yaml | 1 + .../bsonSize.yaml | 0 .../ceil.yaml | 0 .../cmp.yaml | 0 .../concat.yaml | 0 .../concatArrays.yaml | 0 .../cond.yaml | 0 .../convert.yaml | 0 .../cos.yaml | 0 .../cosh.yaml | 0 .../count.yaml | 1 + .../covariancePop.yaml | 3 +- .../covarianceSamp.yaml | 3 +- .../dateAdd.yaml | 0 .../dateDiff.yaml | 0 .../dateFromParts.yaml | 0 .../dateFromString.yaml | 0 .../dateSubtract.yaml | 0 .../dateToParts.yaml | 0 .../dateToString.yaml | 0 .../dateTrunc.yaml | 0 .../dayOfMonth.yaml | 0 .../dayOfWeek.yaml | 0 .../dayOfYear.yaml | 0 .../degreesToRadians.yaml | 0 .../denseRank.yaml | 2 +- .../derivative.yaml | 2 +- .../divide.yaml | 0 .../documentNumber.yaml | 2 +- .../eq.yaml | 0 .../exp.yaml | 0 .../expMovingAvg.yaml | 2 +- .../filter.yaml | 1 + .../first.yaml | 2 +- .../firstN.yaml | 1 + .../floor.yaml | 0 .../function.yaml | 0 .../getField.yaml | 0 .../gt.yaml | 0 .../gte.yaml | 0 .../hour.yaml | 0 .../ifNull.yaml | 0 .../in.yaml | 0 .../indexOfArray.yaml | 0 .../indexOfBytes.yaml | 0 .../indexOfCP.yaml | 0 .../integral.yaml | 0 .../isArray.yaml | 0 .../isNumber.yaml | 0 .../isoDayOfWeek.yaml | 0 .../isoWeek.yaml | 0 .../isoWeekYear.yaml | 0 .../last.yaml | 2 +- .../lastN.yaml | 1 + .../let.yaml | 2 +- .../linearFill.yaml | 0 .../literal.yaml | 0 .../ln.yaml | 0 .../locf.yaml | 0 .../log.yaml | 0 .../log10.yaml | 0 .../lt.yaml | 0 .../lte.yaml | 0 .../ltrim.yaml | 0 .../map.yaml | 0 .../max.yaml | 1 + .../maxN.yaml | 2 + .../median.yaml | 3 +- .../mergeObjects.yaml | 0 .../meta.yaml | 0 .../millisecond.yaml | 0 .../min.yaml | 1 + .../minN.yaml | 2 + .../minute.yaml | 0 .../mod.yaml | 0 .../month.yaml | 0 .../multiply.yaml | 0 .../ne.yaml | 0 .../not.yaml | 0 .../objectToArray.yaml | 0 .../or.yaml | 0 .../percentile.yaml | 7 +- .../pow.yaml | 0 .../push.yaml | 1 + .../radiansToDegrees.yaml | 0 .../rand.yaml | 0 .../range.yaml | 2 +- .../rank.yaml | 0 .../reduce.yaml | 0 .../regexFind.yaml | 0 .../regexFindAll.yaml | 2 +- .../regexMatch.yaml | 0 .../replaceAll.yaml | 0 .../replaceOne.yaml | 0 .../reverseArray.yaml | 0 .../round.yaml | 0 .../rtrim.yaml | 0 .../sampleRate.yaml | 0 .../second.yaml | 0 .../setDifference.yaml | 0 .../setEquals.yaml | 0 .../setField.yaml | 0 .../setIntersection.yaml | 0 .../setIsSubset.yaml | 0 .../setUnion.yaml | 0 .../shift.yaml | 2 +- .../sin.yaml | 0 .../sinh.yaml | 0 .../size.yaml | 0 .../slice.yaml | 3 +- .../sortArray.yaml | 0 .../split.yaml | 2 +- .../sqrt.yaml | 0 .../stdDevPop.yaml | 0 .../stdDevSamp.yaml | 0 .../strLenBytes.yaml | 0 .../strLenCP.yaml | 0 .../strcasecmp.yaml | 0 .../substr.yaml | 0 .../substrBytes.yaml | 0 .../substrCP.yaml | 0 .../subtract.yaml | 0 .../sum.yaml | 0 .../switch.yaml | 2 +- .../tan.yaml | 0 .../tanh.yaml | 0 .../toBool.yaml | 0 .../toDate.yaml | 0 .../toDecimal.yaml | 0 .../toDouble.yaml | 0 .../toInt.yaml | 0 .../toLong.yaml | 0 .../toLower.yaml | 0 .../toObjectId.yaml | 0 .../toString.yaml | 0 .../toUpper.yaml | 0 .../top.yaml | 0 .../topN.yaml | 0 .../trim.yaml | 0 .../trunc.yaml | 0 .../tsIncrement.yaml | 0 .../tsSecond.yaml | 0 .../type.yaml | 0 .../unsetField.yaml | 0 .../week.yaml | 0 .../year.yaml | 0 .../zip.yaml | 4 +- generator/config/expressions.php | 38 +- .../{query-operators => query}/all.yaml | 0 .../{query-operators => query}/and.yaml | 0 .../bitsAllClear.yaml | 2 +- .../bitsAllSet.yaml | 2 +- .../bitsAnyClear.yaml | 2 +- .../bitsAnySet.yaml | 2 +- .../{query-operators => query}/box.yaml | 0 .../{query-operators => query}/center.yaml | 0 .../centerSphere.yaml | 0 .../{query-operators => query}/comment.yaml | 0 .../{query-operators => query}/elemMatch.yaml | 0 .../config/{query-operators => query}/eq.yaml | 0 .../{query-operators => query}/exists.yaml | 0 .../{query-operators => query}/expr.yaml | 0 .../geoIntersects.yaml | 0 .../{query-operators => query}/geoWithin.yaml | 0 .../{query-operators => query}/geometry.yaml | 0 .../config/{query-operators => query}/gt.yaml | 0 .../{query-operators => query}/gte.yaml | 0 .../config/{query-operators => query}/in.yaml | 2 +- .../jsonSchema.yaml | 0 .../config/{query-operators => query}/lt.yaml | 0 .../{query-operators => query}/lte.yaml | 0 .../maxDistance.yaml | 0 .../{query-operators => query}/meta.yaml | 0 .../minDistance.yaml | 0 .../{query-operators => query}/mod.yaml | 0 .../{query-operators => query}/natural.yaml | 0 .../config/{query-operators => query}/ne.yaml | 0 .../{query-operators => query}/near.yaml | 0 .../nearSphere.yaml | 0 .../{query-operators => query}/nin.yaml | 2 +- .../{query-operators => query}/nor.yaml | 0 .../{query-operators => query}/not.yaml | 0 .../config/{query-operators => query}/or.yaml | 0 .../{query-operators => query}/polygon.yaml | 0 .../positional.yaml | 0 .../{query-operators => query}/rand.yaml | 0 .../{query-operators => query}/regex.yaml | 0 .../{query-operators => query}/size.yaml | 0 .../{query-operators => query}/slice.yaml | 0 .../{query-operators => query}/text.yaml | 0 .../{query-operators => query}/type.yaml | 3 +- .../{query-operators => query}/where.yaml | 0 generator/config/schema.json | 53 +- .../addFields.yaml | 0 .../{aggregation-stages => stage}/bucket.yaml | 7 +- .../bucketAuto.yaml | 4 +- .../changeStream.yaml | 0 .../changeStreamSplitLargeEvent.yaml | 0 .../collStats.yaml | 0 .../{aggregation-stages => stage}/count.yaml | 0 .../currentOp.yaml | 0 .../densify.yaml | 6 +- .../documents.yaml | 2 +- .../{aggregation-stages => stage}/facet.yaml | 0 .../{aggregation-stages => stage}/fill.yaml | 8 +- .../geoNear.yaml | 0 .../graphLookup.yaml | 2 +- .../{aggregation-stages => stage}/group.yaml | 0 .../indexStats.yaml | 0 .../{aggregation-stages => stage}/limit.yaml | 0 .../listLocalSessions.yaml | 0 .../listSampledQueries.yaml | 0 .../listSearchIndexes.yaml | 0 .../listSessions.yaml | 0 .../{aggregation-stages => stage}/lookup.yaml | 2 +- .../{aggregation-stages => stage}/match.yaml | 0 .../{aggregation-stages => stage}/merge.yaml | 6 +- .../{aggregation-stages => stage}/out.yaml | 0 .../planCacheStats.yaml | 0 .../project.yaml | 0 .../{aggregation-stages => stage}/redact.yaml | 0 .../replaceRoot.yaml | 0 .../replaceWith.yaml | 0 .../{aggregation-stages => stage}/sample.yaml | 0 .../{aggregation-stages => stage}/search.yaml | 0 .../searchMeta.yaml | 0 .../{aggregation-stages => stage}/set.yaml | 0 .../setWindowFields.yaml | 0 .../shardedDataDistribution.yaml | 0 .../{aggregation-stages => stage}/skip.yaml | 0 .../{aggregation-stages => stage}/sort.yaml | 0 .../sortByCount.yaml | 0 .../unionWith.yaml | 0 .../{aggregation-stages => stage}/unset.yaml | 0 generator/config/stage/unwind.yaml | 33 + generator/src/CodecClassGenerator.php | 60 - generator/src/Command/GenerateCommand.php | 2 +- generator/src/ExpressionFactoryGenerator.php | 16 +- generator/src/OperatorFactoryGenerator.php | 24 +- generator/src/OperatorGenerator.php | 55 +- phpcs.xml.dist | 3 +- src/Builder/Aggregation/AbsAggregation.php | 39 - src/Builder/Aggregation/AcosAggregation.php | 45 - src/Builder/Aggregation/AcoshAggregation.php | 45 - .../Aggregation/AddToSetAggregation.php | 53 - src/Builder/Aggregation/AndAggregation.php | 60 - src/Builder/Aggregation/AsinAggregation.php | 45 - src/Builder/Aggregation/Atan2Aggregation.php | 51 - src/Builder/Aggregation/AtanhAggregation.php | 45 - src/Builder/Aggregation/CeilAggregation.php | 39 - src/Builder/Aggregation/CosAggregation.php | 43 - src/Builder/Aggregation/CoshAggregation.php | 43 - .../Aggregation/CovariancePopAggregation.php | 46 - .../Aggregation/CovarianceSampAggregation.php | 46 - .../Aggregation/DateFromPartsAggregation.php | 102 -- .../DegreesToRadiansAggregation.php | 43 - src/Builder/Aggregation/DivideAggregation.php | 45 - src/Builder/Aggregation/ExpAggregation.php | 39 - src/Builder/Aggregation/FloorAggregation.php | 39 - .../Aggregation/LinearFillAggregation.php | 41 - src/Builder/Aggregation/LnAggregation.php | 40 - src/Builder/Aggregation/Log10Aggregation.php | 39 - src/Builder/Aggregation/LogAggregation.php | 45 - src/Builder/Aggregation/MedianAggregation.php | 51 - src/Builder/Aggregation/ModAggregation.php | 45 - src/Builder/Aggregation/PowAggregation.php | 45 - .../RadiansToDegreesAggregation.php | 39 - src/Builder/Aggregation/SinAggregation.php | 43 - src/Builder/Aggregation/SinhAggregation.php | 43 - src/Builder/Aggregation/SqrtAggregation.php | 39 - .../Aggregation/SubtractAggregation.php | 47 - src/Builder/Aggregation/TanAggregation.php | 43 - src/Builder/Aggregation/TanhAggregation.php | 43 - src/Builder/Aggregation/TruncAggregation.php | 51 - src/Builder/BuilderEncoder.php | 7 +- src/Builder/Encode.php | 5 + src/Builder/Expression.php | 119 +- src/Builder/Expression/AbsOperator.php | 33 + .../AccumulatorOperator.php} | 13 +- src/Builder/Expression/AcosOperator.php | 39 + src/Builder/Expression/AcoshOperator.php | 39 + .../AddOperator.php} | 16 +- src/Builder/Expression/AddToSetOperator.php | 48 + .../AllElementsTrueOperator.php} | 6 +- src/Builder/Expression/AndOperator.php | 52 + .../AnyElementTrueOperator.php} | 6 +- .../ArrayElemAtOperator.php} | 7 +- .../ArrayToObjectOperator.php} | 6 +- src/Builder/Expression/AsinOperator.php | 39 + .../AsinhOperator.php} | 20 +- src/Builder/Expression/Atan2Operator.php | 46 + .../AtanOperator.php} | 20 +- src/Builder/Expression/AtanhOperator.php | 39 + .../AvgOperator.php} | 19 +- .../BinarySizeOperator.php} | 8 +- .../BitAndOperator.php} | 6 +- .../BitNotOperator.php} | 6 +- .../BitOrOperator.php} | 6 +- .../BitXorOperator.php} | 6 +- .../BottomNOperator.php} | 10 +- .../BottomOperator.php} | 10 +- .../BsonSizeOperator.php} | 7 +- src/Builder/Expression/CeilOperator.php | 33 + .../CmpOperator.php} | 13 +- .../ConcatArraysOperator.php} | 5 +- .../ConcatOperator.php} | 5 +- .../CondOperator.php} | 15 +- .../ConvertOperator.php} | 35 +- src/Builder/Expression/CosOperator.php | 37 + src/Builder/Expression/CoshOperator.php | 37 + .../CountOperator.php} | 5 +- .../Expression/CovariancePopOperator.php | 42 + .../Expression/CovarianceSampOperator.php | 42 + .../DateAddOperator.php} | 14 +- .../DateDiffOperator.php} | 17 +- .../Expression/DateFromPartsOperator.php | 95 ++ .../DateFromStringOperator.php} | 39 +- .../DateSubtractOperator.php} | 14 +- .../DateToPartsOperator.php} | 13 +- .../DateToStringOperator.php} | 29 +- .../DateTruncOperator.php} | 25 +- .../DayOfMonthOperator.php} | 13 +- .../DayOfWeekOperator.php} | 13 +- .../DayOfYearOperator.php} | 13 +- .../Expression/DegreesToRadiansOperator.php | 37 + .../DenseRankOperator.php} | 6 +- .../DerivativeOperator.php} | 19 +- src/Builder/Expression/DivideOperator.php | 40 + .../DocumentNumberOperator.php} | 6 +- .../EqOperator.php} | 14 +- .../ExpMovingAvgOperator.php} | 26 +- src/Builder/Expression/ExpOperator.php | 33 + .../Expression/ExpressionFactoryTrait.php | 103 ++ .../FactoryTrait.php} | 1259 +++++++---------- .../FilterOperator.php} | 12 +- .../FirstNOperator.php} | 7 +- .../FirstOperator.php} | 11 +- src/Builder/Expression/FloorOperator.php | 33 + .../FunctionOperator.php} | 5 +- .../GetFieldOperator.php} | 18 +- .../GtOperator.php} | 14 +- .../GteOperator.php} | 14 +- .../HourOperator.php} | 13 +- .../IfNullOperator.php} | 6 +- .../InOperator.php} | 11 +- .../IndexOfArrayOperator.php} | 18 +- .../IndexOfBytesOperator.php} | 14 +- .../IndexOfCPOperator.php} | 14 +- .../IntegralOperator.php} | 23 +- .../IsArrayOperator.php} | 6 +- .../IsNumberOperator.php} | 6 +- .../IsoDayOfWeekOperator.php} | 13 +- .../IsoWeekOperator.php} | 13 +- .../IsoWeekYearOperator.php} | 13 +- .../LastNOperator.php} | 7 +- .../LastOperator.php} | 11 +- .../LetOperator.php} | 10 +- src/Builder/Expression/LinearFillOperator.php | 35 + .../LiteralOperator.php} | 10 +- src/Builder/Expression/LnOperator.php | 34 + .../LocfOperator.php} | 10 +- src/Builder/Expression/Log10Operator.php | 33 + src/Builder/Expression/LogOperator.php | 40 + .../LtOperator.php} | 14 +- .../LteOperator.php} | 14 +- .../LtrimOperator.php} | 9 +- .../MapOperator.php} | 15 +- .../MaxNOperator.php} | 8 +- .../MaxOperator.php} | 7 +- src/Builder/Expression/MedianOperator.php | 45 + .../MergeObjectsOperator.php} | 5 +- .../MetaOperator.php} | 5 +- .../MillisecondOperator.php} | 13 +- .../MinNOperator.php} | 8 +- .../MinOperator.php} | 7 +- .../MinuteOperator.php} | 13 +- src/Builder/Expression/ModOperator.php | 40 + .../MonthOperator.php} | 13 +- .../MultiplyOperator.php} | 18 +- .../NeOperator.php} | 14 +- .../NotOperator.php} | 10 +- .../ObjectToArrayOperator.php} | 6 +- .../OrOperator.php} | 6 +- .../PercentileOperator.php} | 19 +- src/Builder/Expression/PowOperator.php | 40 + .../PushOperator.php} | 10 +- .../Expression/RadiansToDegreesOperator.php | 33 + .../RandOperator.php} | 5 +- .../RangeOperator.php} | 10 +- .../RankOperator.php} | 5 +- .../ReduceOperator.php} | 15 +- .../RegexFindAllOperator.php} | 6 +- .../RegexFindOperator.php} | 6 +- .../RegexMatchOperator.php} | 6 +- .../ReplaceAllOperator.php} | 6 +- .../ReplaceOneOperator.php} | 6 +- src/Builder/Expression/ResolvesToAny.php | 4 +- src/Builder/Expression/ResolvesToDecimal.php | 4 +- src/Builder/Expression/ResolvesToDouble.php | 4 +- src/Builder/Expression/ResolvesToInt.php | 4 +- src/Builder/Expression/ResolvesToLong.php | 4 +- .../ReverseArrayOperator.php} | 5 +- .../RoundOperator.php} | 12 +- .../RtrimOperator.php} | 9 +- .../SampleRateOperator.php} | 6 +- .../SecondOperator.php} | 13 +- .../SetDifferenceOperator.php} | 5 +- .../SetEqualsOperator.php} | 6 +- .../SetFieldOperator.php} | 11 +- .../SetIntersectionOperator.php} | 5 +- .../SetIsSubsetOperator.php} | 6 +- .../SetUnionOperator.php} | 5 +- .../ShiftOperator.php} | 15 +- src/Builder/Expression/SinOperator.php | 37 + src/Builder/Expression/SinhOperator.php | 37 + .../SizeOperator.php} | 6 +- .../SliceOperator.php} | 11 +- .../SortArrayOperator.php} | 5 +- .../SplitOperator.php} | 6 +- src/Builder/Expression/SqrtOperator.php | 33 + .../StdDevPopOperator.php} | 18 +- .../StdDevSampOperator.php} | 18 +- .../StrLenBytesOperator.php} | 6 +- .../StrLenCPOperator.php} | 6 +- .../StrcasecmpOperator.php} | 6 +- .../SubstrBytesOperator.php} | 6 +- .../SubstrCPOperator.php} | 6 +- .../SubstrOperator.php} | 6 +- src/Builder/Expression/SubtractOperator.php | 41 + .../SumOperator.php} | 18 +- .../SwitchOperator.php} | 18 +- src/Builder/Expression/TanOperator.php | 37 + src/Builder/Expression/TanhOperator.php | 37 + .../ToBoolOperator.php} | 10 +- .../ToDateOperator.php} | 10 +- .../ToDecimalOperator.php} | 10 +- .../ToDoubleOperator.php} | 10 +- .../ToIntOperator.php} | 9 +- .../ToLongOperator.php} | 10 +- .../ToLowerOperator.php} | 5 +- .../ToObjectIdOperator.php} | 10 +- .../ToStringOperator.php} | 10 +- .../ToUpperOperator.php} | 5 +- .../TopNOperator.php} | 9 +- .../TopOperator.php} | 9 +- .../TrimOperator.php} | 9 +- src/Builder/Expression/TruncOperator.php | 45 + .../TsIncrementOperator.php} | 6 +- .../TsSecondOperator.php} | 6 +- .../TypeOperator.php} | 10 +- .../UnsetFieldOperator.php} | 6 +- src/Builder/Expression/Variable.php | 4 +- .../WeekOperator.php} | 13 +- .../YearOperator.php} | 13 +- .../ZipOperator.php} | 5 +- src/Builder/Pipeline.php | 13 +- src/Builder/Query.php | 593 +------- .../Query/{AllQuery.php => AllOperator.php} | 2 +- .../Query/{AndQuery.php => AndOperator.php} | 2 +- ...learQuery.php => BitsAllClearOperator.php} | 2 +- ...AllSetQuery.php => BitsAllSetOperator.php} | 2 +- ...learQuery.php => BitsAnyClearOperator.php} | 2 +- ...AnySetQuery.php => BitsAnySetOperator.php} | 2 +- .../Query/{BoxQuery.php => BoxOperator.php} | 2 +- .../{CenterQuery.php => CenterOperator.php} | 2 +- ...hereQuery.php => CenterSphereOperator.php} | 2 +- .../{CommentQuery.php => CommentOperator.php} | 2 +- ...emMatchQuery.php => ElemMatchOperator.php} | 2 +- .../Query/{EqQuery.php => EqOperator.php} | 6 +- .../{ExistsQuery.php => ExistsOperator.php} | 2 +- .../Query/{ExprQuery.php => ExprOperator.php} | 6 +- src/Builder/Query/FactoryTrait.php | 546 +++++++ ...ctsQuery.php => GeoIntersectsOperator.php} | 2 +- ...oWithinQuery.php => GeoWithinOperator.php} | 2 +- ...GeometryQuery.php => GeometryOperator.php} | 2 +- .../Query/{GtQuery.php => GtOperator.php} | 6 +- .../Query/{GteQuery.php => GteOperator.php} | 6 +- .../Query/{InQuery.php => InOperator.php} | 2 +- ...SchemaQuery.php => JsonSchemaOperator.php} | 2 +- .../Query/{LtQuery.php => LtOperator.php} | 6 +- .../Query/{LteQuery.php => LteOperator.php} | 6 +- src/Builder/Query/MaxDistanceOperator.php | 35 + src/Builder/Query/MaxDistanceQuery.php | 39 - .../Query/{MetaQuery.php => MetaOperator.php} | 2 +- ...tanceQuery.php => MinDistanceOperator.php} | 2 +- .../Query/{ModQuery.php => ModOperator.php} | 2 +- .../{NaturalQuery.php => NaturalOperator.php} | 2 +- .../Query/{NeQuery.php => NeOperator.php} | 6 +- .../Query/{NearQuery.php => NearOperator.php} | 2 +- ...SphereQuery.php => NearSphereOperator.php} | 2 +- .../Query/{NinQuery.php => NinOperator.php} | 2 +- .../Query/{NorQuery.php => NorOperator.php} | 2 +- .../Query/{NotQuery.php => NotOperator.php} | 2 +- .../Query/{OrQuery.php => OrOperator.php} | 2 +- .../{PolygonQuery.php => PolygonOperator.php} | 2 +- .../Query/{RandQuery.php => RandOperator.php} | 2 +- .../{RegexQuery.php => RegexOperator.php} | 2 +- .../Query/{SizeQuery.php => SizeOperator.php} | 2 +- .../{SliceQuery.php => SliceOperator.php} | 2 +- .../Query/{TextQuery.php => TextOperator.php} | 2 +- .../Query/{TypeQuery.php => TypeOperator.php} | 2 +- .../{WhereQuery.php => WhereOperator.php} | 2 +- src/Builder/Stage.php | 733 +--------- src/Builder/Stage/BucketAutoStage.php | 20 +- src/Builder/Stage/BucketStage.php | 33 +- src/Builder/Stage/ChangeStreamStage.php | 12 +- src/Builder/Stage/DensifyStage.php | 17 +- src/Builder/Stage/FactoryTrait.php | 698 +++++++++ src/Builder/Stage/FillStage.php | 24 +- src/Builder/Stage/GeoNearStage.php | 35 +- src/Builder/Stage/GraphLookupStage.php | 12 +- src/Builder/Stage/GroupStage.php | 4 - src/Builder/Stage/ListLocalSessionsStage.php | 8 +- src/Builder/Stage/ListSessionsStage.php | 8 +- src/Builder/Stage/LookupStage.php | 16 +- src/Builder/Stage/MergeStage.php | 24 +- src/Builder/Stage/OutStage.php | 8 +- src/Builder/Stage/RedactStage.php | 4 - src/Builder/Stage/SetWindowFieldsStage.php | 12 +- src/Builder/Stage/SortByCountStage.php | 4 - src/Builder/Stage/UnionWithStage.php | 8 +- src/Builder/Stage/UnwindStage.php | 32 +- src/Builder/Type/WindowInterface.php | 16 + src/Builder/architecture.md | 247 ++++ tests/Builder/BuilderEncoderTest.php | 48 +- 552 files changed, 4422 insertions(+), 5245 deletions(-) delete mode 100644 generator/config/aggregation-stages/unwind.yaml rename generator/config/{operators.php => definitions.php} (72%) rename generator/config/{aggregation-operators => expression}/abs.yaml (100%) rename generator/config/{aggregation-operators => expression}/accumulator.yaml (100%) rename generator/config/{aggregation-operators => expression}/acos.yaml (100%) rename generator/config/{aggregation-operators => expression}/acosh.yaml (100%) rename generator/config/{aggregation-operators => expression}/add.yaml (100%) rename generator/config/{aggregation-operators => expression}/addToSet.yaml (95%) rename generator/config/{aggregation-operators => expression}/allElementsTrue.yaml (100%) rename generator/config/{aggregation-operators => expression}/and.yaml (100%) rename generator/config/{aggregation-operators => expression}/anyElementTrue.yaml (100%) rename generator/config/{aggregation-operators => expression}/arrayElemAt.yaml (100%) rename generator/config/{aggregation-operators => expression}/arrayToObject.yaml (100%) rename generator/config/{aggregation-operators => expression}/asin.yaml (100%) rename generator/config/{aggregation-operators => expression}/asinh.yaml (100%) rename generator/config/{aggregation-operators => expression}/atan.yaml (100%) rename generator/config/{aggregation-operators => expression}/atan2.yaml (100%) rename generator/config/{aggregation-operators => expression}/atanh.yaml (100%) rename generator/config/{aggregation-operators => expression}/avg.yaml (97%) rename generator/config/{aggregation-operators => expression}/binarySize.yaml (100%) rename generator/config/{aggregation-operators => expression}/bitAnd.yaml (100%) rename generator/config/{aggregation-operators => expression}/bitNot.yaml (100%) rename generator/config/{aggregation-operators => expression}/bitOr.yaml (100%) rename generator/config/{aggregation-operators => expression}/bitXor.yaml (100%) rename generator/config/{aggregation-operators => expression}/bottom.yaml (98%) rename generator/config/{aggregation-operators => expression}/bottomN.yaml (98%) rename generator/config/{aggregation-operators => expression}/bsonSize.yaml (100%) rename generator/config/{aggregation-operators => expression}/ceil.yaml (100%) rename generator/config/{aggregation-operators => expression}/cmp.yaml (100%) rename generator/config/{aggregation-operators => expression}/concat.yaml (100%) rename generator/config/{aggregation-operators => expression}/concatArrays.yaml (100%) rename generator/config/{aggregation-operators => expression}/cond.yaml (100%) rename generator/config/{aggregation-operators => expression}/convert.yaml (100%) rename generator/config/{aggregation-operators => expression}/cos.yaml (100%) rename generator/config/{aggregation-operators => expression}/cosh.yaml (100%) rename generator/config/{aggregation-operators => expression}/count.yaml (97%) rename generator/config/{aggregation-operators => expression}/covariancePop.yaml (90%) rename generator/config/{aggregation-operators => expression}/covarianceSamp.yaml (90%) rename generator/config/{aggregation-operators => expression}/dateAdd.yaml (100%) rename generator/config/{aggregation-operators => expression}/dateDiff.yaml (100%) rename generator/config/{aggregation-operators => expression}/dateFromParts.yaml (100%) rename generator/config/{aggregation-operators => expression}/dateFromString.yaml (100%) rename generator/config/{aggregation-operators => expression}/dateSubtract.yaml (100%) rename generator/config/{aggregation-operators => expression}/dateToParts.yaml (100%) rename generator/config/{aggregation-operators => expression}/dateToString.yaml (100%) rename generator/config/{aggregation-operators => expression}/dateTrunc.yaml (100%) rename generator/config/{aggregation-operators => expression}/dayOfMonth.yaml (100%) rename generator/config/{aggregation-operators => expression}/dayOfWeek.yaml (100%) rename generator/config/{aggregation-operators => expression}/dayOfYear.yaml (100%) rename generator/config/{aggregation-operators => expression}/degreesToRadians.yaml (100%) rename generator/config/{aggregation-operators => expression}/denseRank.yaml (95%) rename generator/config/{aggregation-operators => expression}/derivative.yaml (97%) rename generator/config/{aggregation-operators => expression}/divide.yaml (100%) rename generator/config/{aggregation-operators => expression}/documentNumber.yaml (95%) rename generator/config/{aggregation-operators => expression}/eq.yaml (100%) rename generator/config/{aggregation-operators => expression}/exp.yaml (100%) rename generator/config/{aggregation-operators => expression}/expMovingAvg.yaml (98%) rename generator/config/{aggregation-operators => expression}/filter.yaml (98%) rename generator/config/{aggregation-operators => expression}/first.yaml (96%) rename generator/config/{aggregation-operators => expression}/firstN.yaml (98%) rename generator/config/{aggregation-operators => expression}/floor.yaml (100%) rename generator/config/{aggregation-operators => expression}/function.yaml (100%) rename generator/config/{aggregation-operators => expression}/getField.yaml (100%) rename generator/config/{aggregation-operators => expression}/gt.yaml (100%) rename generator/config/{aggregation-operators => expression}/gte.yaml (100%) rename generator/config/{aggregation-operators => expression}/hour.yaml (100%) rename generator/config/{aggregation-operators => expression}/ifNull.yaml (100%) rename generator/config/{aggregation-operators => expression}/in.yaml (100%) rename generator/config/{aggregation-operators => expression}/indexOfArray.yaml (100%) rename generator/config/{aggregation-operators => expression}/indexOfBytes.yaml (100%) rename generator/config/{aggregation-operators => expression}/indexOfCP.yaml (100%) rename generator/config/{aggregation-operators => expression}/integral.yaml (100%) rename generator/config/{aggregation-operators => expression}/isArray.yaml (100%) rename generator/config/{aggregation-operators => expression}/isNumber.yaml (100%) rename generator/config/{aggregation-operators => expression}/isoDayOfWeek.yaml (100%) rename generator/config/{aggregation-operators => expression}/isoWeek.yaml (100%) rename generator/config/{aggregation-operators => expression}/isoWeekYear.yaml (100%) rename generator/config/{aggregation-operators => expression}/last.yaml (96%) rename generator/config/{aggregation-operators => expression}/lastN.yaml (98%) rename generator/config/{aggregation-operators => expression}/let.yaml (96%) rename generator/config/{aggregation-operators => expression}/linearFill.yaml (100%) rename generator/config/{aggregation-operators => expression}/literal.yaml (100%) rename generator/config/{aggregation-operators => expression}/ln.yaml (100%) rename generator/config/{aggregation-operators => expression}/locf.yaml (100%) rename generator/config/{aggregation-operators => expression}/log.yaml (100%) rename generator/config/{aggregation-operators => expression}/log10.yaml (100%) rename generator/config/{aggregation-operators => expression}/lt.yaml (100%) rename generator/config/{aggregation-operators => expression}/lte.yaml (100%) rename generator/config/{aggregation-operators => expression}/ltrim.yaml (100%) rename generator/config/{aggregation-operators => expression}/map.yaml (100%) rename generator/config/{aggregation-operators => expression}/max.yaml (97%) rename generator/config/{aggregation-operators => expression}/maxN.yaml (95%) rename generator/config/{aggregation-operators => expression}/median.yaml (94%) rename generator/config/{aggregation-operators => expression}/mergeObjects.yaml (100%) rename generator/config/{aggregation-operators => expression}/meta.yaml (100%) rename generator/config/{aggregation-operators => expression}/millisecond.yaml (100%) rename generator/config/{aggregation-operators => expression}/min.yaml (97%) rename generator/config/{aggregation-operators => expression}/minN.yaml (96%) rename generator/config/{aggregation-operators => expression}/minute.yaml (100%) rename generator/config/{aggregation-operators => expression}/mod.yaml (100%) rename generator/config/{aggregation-operators => expression}/month.yaml (100%) rename generator/config/{aggregation-operators => expression}/multiply.yaml (100%) rename generator/config/{aggregation-operators => expression}/ne.yaml (100%) rename generator/config/{aggregation-operators => expression}/not.yaml (100%) rename generator/config/{aggregation-operators => expression}/objectToArray.yaml (100%) rename generator/config/{aggregation-operators => expression}/or.yaml (100%) rename generator/config/{aggregation-operators => expression}/percentile.yaml (90%) rename generator/config/{aggregation-operators => expression}/pow.yaml (100%) rename generator/config/{aggregation-operators => expression}/push.yaml (97%) rename generator/config/{aggregation-operators => expression}/radiansToDegrees.yaml (100%) rename generator/config/{aggregation-operators => expression}/rand.yaml (100%) rename generator/config/{aggregation-operators => expression}/range.yaml (96%) rename generator/config/{aggregation-operators => expression}/rank.yaml (100%) rename generator/config/{aggregation-operators => expression}/reduce.yaml (100%) rename generator/config/{aggregation-operators => expression}/regexFind.yaml (100%) rename generator/config/{aggregation-operators => expression}/regexFindAll.yaml (96%) rename generator/config/{aggregation-operators => expression}/regexMatch.yaml (100%) rename generator/config/{aggregation-operators => expression}/replaceAll.yaml (100%) rename generator/config/{aggregation-operators => expression}/replaceOne.yaml (100%) rename generator/config/{aggregation-operators => expression}/reverseArray.yaml (100%) rename generator/config/{aggregation-operators => expression}/round.yaml (100%) rename generator/config/{aggregation-operators => expression}/rtrim.yaml (100%) rename generator/config/{aggregation-operators => expression}/sampleRate.yaml (100%) rename generator/config/{aggregation-operators => expression}/second.yaml (100%) rename generator/config/{aggregation-operators => expression}/setDifference.yaml (100%) rename generator/config/{aggregation-operators => expression}/setEquals.yaml (100%) rename generator/config/{aggregation-operators => expression}/setField.yaml (100%) rename generator/config/{aggregation-operators => expression}/setIntersection.yaml (100%) rename generator/config/{aggregation-operators => expression}/setIsSubset.yaml (100%) rename generator/config/{aggregation-operators => expression}/setUnion.yaml (100%) rename generator/config/{aggregation-operators => expression}/shift.yaml (98%) rename generator/config/{aggregation-operators => expression}/sin.yaml (100%) rename generator/config/{aggregation-operators => expression}/sinh.yaml (100%) rename generator/config/{aggregation-operators => expression}/size.yaml (100%) rename generator/config/{aggregation-operators => expression}/slice.yaml (97%) rename generator/config/{aggregation-operators => expression}/sortArray.yaml (100%) rename generator/config/{aggregation-operators => expression}/split.yaml (96%) rename generator/config/{aggregation-operators => expression}/sqrt.yaml (100%) rename generator/config/{aggregation-operators => expression}/stdDevPop.yaml (100%) rename generator/config/{aggregation-operators => expression}/stdDevSamp.yaml (100%) rename generator/config/{aggregation-operators => expression}/strLenBytes.yaml (100%) rename generator/config/{aggregation-operators => expression}/strLenCP.yaml (100%) rename generator/config/{aggregation-operators => expression}/strcasecmp.yaml (100%) rename generator/config/{aggregation-operators => expression}/substr.yaml (100%) rename generator/config/{aggregation-operators => expression}/substrBytes.yaml (100%) rename generator/config/{aggregation-operators => expression}/substrCP.yaml (100%) rename generator/config/{aggregation-operators => expression}/subtract.yaml (100%) rename generator/config/{aggregation-operators => expression}/sum.yaml (100%) rename generator/config/{aggregation-operators => expression}/switch.yaml (94%) rename generator/config/{aggregation-operators => expression}/tan.yaml (100%) rename generator/config/{aggregation-operators => expression}/tanh.yaml (100%) rename generator/config/{aggregation-operators => expression}/toBool.yaml (100%) rename generator/config/{aggregation-operators => expression}/toDate.yaml (100%) rename generator/config/{aggregation-operators => expression}/toDecimal.yaml (100%) rename generator/config/{aggregation-operators => expression}/toDouble.yaml (100%) rename generator/config/{aggregation-operators => expression}/toInt.yaml (100%) rename generator/config/{aggregation-operators => expression}/toLong.yaml (100%) rename generator/config/{aggregation-operators => expression}/toLower.yaml (100%) rename generator/config/{aggregation-operators => expression}/toObjectId.yaml (100%) rename generator/config/{aggregation-operators => expression}/toString.yaml (100%) rename generator/config/{aggregation-operators => expression}/toUpper.yaml (100%) rename generator/config/{aggregation-operators => expression}/top.yaml (100%) rename generator/config/{aggregation-operators => expression}/topN.yaml (100%) rename generator/config/{aggregation-operators => expression}/trim.yaml (100%) rename generator/config/{aggregation-operators => expression}/trunc.yaml (100%) rename generator/config/{aggregation-operators => expression}/tsIncrement.yaml (100%) rename generator/config/{aggregation-operators => expression}/tsSecond.yaml (100%) rename generator/config/{aggregation-operators => expression}/type.yaml (100%) rename generator/config/{aggregation-operators => expression}/unsetField.yaml (100%) rename generator/config/{aggregation-operators => expression}/week.yaml (100%) rename generator/config/{aggregation-operators => expression}/year.yaml (100%) rename generator/config/{aggregation-operators => expression}/zip.yaml (95%) rename generator/config/{query-operators => query}/all.yaml (100%) rename generator/config/{query-operators => query}/and.yaml (100%) rename generator/config/{query-operators => query}/bitsAllClear.yaml (93%) rename generator/config/{query-operators => query}/bitsAllSet.yaml (93%) rename generator/config/{query-operators => query}/bitsAnyClear.yaml (93%) rename generator/config/{query-operators => query}/bitsAnySet.yaml (93%) rename generator/config/{query-operators => query}/box.yaml (100%) rename generator/config/{query-operators => query}/center.yaml (100%) rename generator/config/{query-operators => query}/centerSphere.yaml (100%) rename generator/config/{query-operators => query}/comment.yaml (100%) rename generator/config/{query-operators => query}/elemMatch.yaml (100%) rename generator/config/{query-operators => query}/eq.yaml (100%) rename generator/config/{query-operators => query}/exists.yaml (100%) rename generator/config/{query-operators => query}/expr.yaml (100%) rename generator/config/{query-operators => query}/geoIntersects.yaml (100%) rename generator/config/{query-operators => query}/geoWithin.yaml (100%) rename generator/config/{query-operators => query}/geometry.yaml (100%) rename generator/config/{query-operators => query}/gt.yaml (100%) rename generator/config/{query-operators => query}/gte.yaml (100%) rename generator/config/{query-operators => query}/in.yaml (89%) rename generator/config/{query-operators => query}/jsonSchema.yaml (100%) rename generator/config/{query-operators => query}/lt.yaml (100%) rename generator/config/{query-operators => query}/lte.yaml (100%) rename generator/config/{query-operators => query}/maxDistance.yaml (100%) rename generator/config/{query-operators => query}/meta.yaml (100%) rename generator/config/{query-operators => query}/minDistance.yaml (100%) rename generator/config/{query-operators => query}/mod.yaml (100%) rename generator/config/{query-operators => query}/natural.yaml (100%) rename generator/config/{query-operators => query}/ne.yaml (100%) rename generator/config/{query-operators => query}/near.yaml (100%) rename generator/config/{query-operators => query}/nearSphere.yaml (100%) rename generator/config/{query-operators => query}/nin.yaml (89%) rename generator/config/{query-operators => query}/nor.yaml (100%) rename generator/config/{query-operators => query}/not.yaml (100%) rename generator/config/{query-operators => query}/or.yaml (100%) rename generator/config/{query-operators => query}/polygon.yaml (100%) rename generator/config/{query-operators => query}/positional.yaml (100%) rename generator/config/{query-operators => query}/rand.yaml (100%) rename generator/config/{query-operators => query}/regex.yaml (100%) rename generator/config/{query-operators => query}/size.yaml (100%) rename generator/config/{query-operators => query}/slice.yaml (100%) rename generator/config/{query-operators => query}/text.yaml (100%) rename generator/config/{query-operators => query}/type.yaml (86%) rename generator/config/{query-operators => query}/where.yaml (100%) rename generator/config/{aggregation-stages => stage}/addFields.yaml (100%) rename generator/config/{aggregation-stages => stage}/bucket.yaml (95%) rename generator/config/{aggregation-stages => stage}/bucketAuto.yaml (95%) rename generator/config/{aggregation-stages => stage}/changeStream.yaml (100%) rename generator/config/{aggregation-stages => stage}/changeStreamSplitLargeEvent.yaml (100%) rename generator/config/{aggregation-stages => stage}/collStats.yaml (100%) rename generator/config/{aggregation-stages => stage}/count.yaml (100%) rename generator/config/{aggregation-stages => stage}/currentOp.yaml (100%) rename generator/config/{aggregation-stages => stage}/densify.yaml (91%) rename generator/config/{aggregation-stages => stage}/documents.yaml (94%) rename generator/config/{aggregation-stages => stage}/facet.yaml (100%) rename generator/config/{aggregation-stages => stage}/fill.yaml (90%) rename generator/config/{aggregation-stages => stage}/geoNear.yaml (100%) rename generator/config/{aggregation-stages => stage}/graphLookup.yaml (98%) rename generator/config/{aggregation-stages => stage}/group.yaml (100%) rename generator/config/{aggregation-stages => stage}/indexStats.yaml (100%) rename generator/config/{aggregation-stages => stage}/limit.yaml (100%) rename generator/config/{aggregation-stages => stage}/listLocalSessions.yaml (100%) rename generator/config/{aggregation-stages => stage}/listSampledQueries.yaml (100%) rename generator/config/{aggregation-stages => stage}/listSearchIndexes.yaml (100%) rename generator/config/{aggregation-stages => stage}/listSessions.yaml (100%) rename generator/config/{aggregation-stages => stage}/lookup.yaml (98%) rename generator/config/{aggregation-stages => stage}/match.yaml (100%) rename generator/config/{aggregation-stages => stage}/merge.yaml (94%) rename generator/config/{aggregation-stages => stage}/out.yaml (100%) rename generator/config/{aggregation-stages => stage}/planCacheStats.yaml (100%) rename generator/config/{aggregation-stages => stage}/project.yaml (100%) rename generator/config/{aggregation-stages => stage}/redact.yaml (100%) rename generator/config/{aggregation-stages => stage}/replaceRoot.yaml (100%) rename generator/config/{aggregation-stages => stage}/replaceWith.yaml (100%) rename generator/config/{aggregation-stages => stage}/sample.yaml (100%) rename generator/config/{aggregation-stages => stage}/search.yaml (100%) rename generator/config/{aggregation-stages => stage}/searchMeta.yaml (100%) rename generator/config/{aggregation-stages => stage}/set.yaml (100%) rename generator/config/{aggregation-stages => stage}/setWindowFields.yaml (100%) rename generator/config/{aggregation-stages => stage}/shardedDataDistribution.yaml (100%) rename generator/config/{aggregation-stages => stage}/skip.yaml (100%) rename generator/config/{aggregation-stages => stage}/sort.yaml (100%) rename generator/config/{aggregation-stages => stage}/sortByCount.yaml (100%) rename generator/config/{aggregation-stages => stage}/unionWith.yaml (100%) rename generator/config/{aggregation-stages => stage}/unset.yaml (100%) create mode 100644 generator/config/stage/unwind.yaml delete mode 100644 generator/src/CodecClassGenerator.php delete mode 100644 src/Builder/Aggregation/AbsAggregation.php delete mode 100644 src/Builder/Aggregation/AcosAggregation.php delete mode 100644 src/Builder/Aggregation/AcoshAggregation.php delete mode 100644 src/Builder/Aggregation/AddToSetAggregation.php delete mode 100644 src/Builder/Aggregation/AndAggregation.php delete mode 100644 src/Builder/Aggregation/AsinAggregation.php delete mode 100644 src/Builder/Aggregation/Atan2Aggregation.php delete mode 100644 src/Builder/Aggregation/AtanhAggregation.php delete mode 100644 src/Builder/Aggregation/CeilAggregation.php delete mode 100644 src/Builder/Aggregation/CosAggregation.php delete mode 100644 src/Builder/Aggregation/CoshAggregation.php delete mode 100644 src/Builder/Aggregation/CovariancePopAggregation.php delete mode 100644 src/Builder/Aggregation/CovarianceSampAggregation.php delete mode 100644 src/Builder/Aggregation/DateFromPartsAggregation.php delete mode 100644 src/Builder/Aggregation/DegreesToRadiansAggregation.php delete mode 100644 src/Builder/Aggregation/DivideAggregation.php delete mode 100644 src/Builder/Aggregation/ExpAggregation.php delete mode 100644 src/Builder/Aggregation/FloorAggregation.php delete mode 100644 src/Builder/Aggregation/LinearFillAggregation.php delete mode 100644 src/Builder/Aggregation/LnAggregation.php delete mode 100644 src/Builder/Aggregation/Log10Aggregation.php delete mode 100644 src/Builder/Aggregation/LogAggregation.php delete mode 100644 src/Builder/Aggregation/MedianAggregation.php delete mode 100644 src/Builder/Aggregation/ModAggregation.php delete mode 100644 src/Builder/Aggregation/PowAggregation.php delete mode 100644 src/Builder/Aggregation/RadiansToDegreesAggregation.php delete mode 100644 src/Builder/Aggregation/SinAggregation.php delete mode 100644 src/Builder/Aggregation/SinhAggregation.php delete mode 100644 src/Builder/Aggregation/SqrtAggregation.php delete mode 100644 src/Builder/Aggregation/SubtractAggregation.php delete mode 100644 src/Builder/Aggregation/TanAggregation.php delete mode 100644 src/Builder/Aggregation/TanhAggregation.php delete mode 100644 src/Builder/Aggregation/TruncAggregation.php create mode 100644 src/Builder/Expression/AbsOperator.php rename src/Builder/{Aggregation/AccumulatorAggregation.php => Expression/AccumulatorOperator.php} (91%) create mode 100644 src/Builder/Expression/AcosOperator.php create mode 100644 src/Builder/Expression/AcoshOperator.php rename src/Builder/{Aggregation/AddAggregation.php => Expression/AddOperator.php} (50%) create mode 100644 src/Builder/Expression/AddToSetOperator.php rename src/Builder/{Aggregation/AllElementsTrueAggregation.php => Expression/AllElementsTrueOperator.php} (86%) create mode 100644 src/Builder/Expression/AndOperator.php rename src/Builder/{Aggregation/AnyElementTrueAggregation.php => Expression/AnyElementTrueOperator.php} (84%) rename src/Builder/{Aggregation/ArrayElemAtAggregation.php => Expression/ArrayElemAtOperator.php} (82%) rename src/Builder/{Aggregation/ArrayToObjectAggregation.php => Expression/ArrayToObjectOperator.php} (83%) create mode 100644 src/Builder/Expression/AsinOperator.php rename src/Builder/{Aggregation/AsinhAggregation.php => Expression/AsinhOperator.php} (51%) create mode 100644 src/Builder/Expression/Atan2Operator.php rename src/Builder/{Aggregation/AtanAggregation.php => Expression/AtanOperator.php} (50%) create mode 100644 src/Builder/Expression/AtanhOperator.php rename src/Builder/{Aggregation/AvgAggregation.php => Expression/AvgOperator.php} (56%) rename src/Builder/{Aggregation/BinarySizeAggregation.php => Expression/BinarySizeOperator.php} (76%) rename src/Builder/{Aggregation/BitAndAggregation.php => Expression/BitAndOperator.php} (85%) rename src/Builder/{Aggregation/BitNotAggregation.php => Expression/BitNotOperator.php} (80%) rename src/Builder/{Aggregation/BitOrAggregation.php => Expression/BitOrOperator.php} (85%) rename src/Builder/{Aggregation/BitXorAggregation.php => Expression/BitXorOperator.php} (85%) rename src/Builder/{Aggregation/BottomNAggregation.php => Expression/BottomNOperator.php} (89%) rename src/Builder/{Aggregation/BottomAggregation.php => Expression/BottomOperator.php} (87%) rename src/Builder/{Aggregation/BsonSizeAggregation.php => Expression/BsonSizeOperator.php} (80%) create mode 100644 src/Builder/Expression/CeilOperator.php rename src/Builder/{Aggregation/CmpAggregation.php => Expression/CmpOperator.php} (82%) rename src/Builder/{Aggregation/ConcatArraysAggregation.php => Expression/ConcatArraysOperator.php} (88%) rename src/Builder/{Aggregation/ConcatAggregation.php => Expression/ConcatOperator.php} (88%) rename src/Builder/{Aggregation/CondAggregation.php => Expression/CondOperator.php} (82%) rename src/Builder/{Aggregation/ConvertAggregation.php => Expression/ConvertOperator.php} (66%) create mode 100644 src/Builder/Expression/CosOperator.php create mode 100644 src/Builder/Expression/CoshOperator.php rename src/Builder/{Aggregation/CountAggregation.php => Expression/CountOperator.php} (82%) create mode 100644 src/Builder/Expression/CovariancePopOperator.php create mode 100644 src/Builder/Expression/CovarianceSampOperator.php rename src/Builder/{Aggregation/DateAddAggregation.php => Expression/DateAddOperator.php} (83%) rename src/Builder/{Aggregation/DateDiffAggregation.php => Expression/DateDiffOperator.php} (85%) create mode 100644 src/Builder/Expression/DateFromPartsOperator.php rename src/Builder/{Aggregation/DateFromStringAggregation.php => Expression/DateFromStringOperator.php} (69%) rename src/Builder/{Aggregation/DateSubtractAggregation.php => Expression/DateSubtractOperator.php} (83%) rename src/Builder/{Aggregation/DateToPartsAggregation.php => Expression/DateToPartsOperator.php} (83%) rename src/Builder/{Aggregation/DateToStringAggregation.php => Expression/DateToStringOperator.php} (72%) rename src/Builder/{Aggregation/DateTruncAggregation.php => Expression/DateTruncOperator.php} (69%) rename src/Builder/{Aggregation/DayOfMonthAggregation.php => Expression/DayOfMonthOperator.php} (80%) rename src/Builder/{Aggregation/DayOfWeekAggregation.php => Expression/DayOfWeekOperator.php} (80%) rename src/Builder/{Aggregation/DayOfYearAggregation.php => Expression/DayOfYearOperator.php} (80%) create mode 100644 src/Builder/Expression/DegreesToRadiansOperator.php rename src/Builder/{Aggregation/DenseRankAggregation.php => Expression/DenseRankOperator.php} (80%) rename src/Builder/{Aggregation/DerivativeAggregation.php => Expression/DerivativeOperator.php} (59%) create mode 100644 src/Builder/Expression/DivideOperator.php rename src/Builder/{Aggregation/DocumentNumberAggregation.php => Expression/DocumentNumberOperator.php} (79%) rename src/Builder/{Aggregation/EqAggregation.php => Expression/EqOperator.php} (81%) rename src/Builder/{Aggregation/ExpMovingAvgAggregation.php => Expression/ExpMovingAvgOperator.php} (67%) create mode 100644 src/Builder/Expression/ExpOperator.php create mode 100644 src/Builder/Expression/ExpressionFactoryTrait.php rename src/Builder/{Aggregation.php => Expression/FactoryTrait.php} (70%) rename src/Builder/{Aggregation/FilterAggregation.php => Expression/FilterOperator.php} (90%) rename src/Builder/{Aggregation/FirstNAggregation.php => Expression/FirstNOperator.php} (89%) rename src/Builder/{Aggregation/FirstAggregation.php => Expression/FirstOperator.php} (81%) create mode 100644 src/Builder/Expression/FloorOperator.php rename src/Builder/{Aggregation/FunctionAggregation.php => Expression/FunctionOperator.php} (92%) rename src/Builder/{Aggregation/GetFieldAggregation.php => Expression/GetFieldOperator.php} (74%) rename src/Builder/{Aggregation/GtAggregation.php => Expression/GtOperator.php} (81%) rename src/Builder/{Aggregation/GteAggregation.php => Expression/GteOperator.php} (81%) rename src/Builder/{Aggregation/HourAggregation.php => Expression/HourOperator.php} (80%) rename src/Builder/{Aggregation/IfNullAggregation.php => Expression/IfNullOperator.php} (92%) rename src/Builder/{Aggregation/InAggregation.php => Expression/InOperator.php} (84%) rename src/Builder/{Aggregation/IndexOfArrayAggregation.php => Expression/IndexOfArrayOperator.php} (88%) rename src/Builder/{Aggregation/IndexOfBytesAggregation.php => Expression/IndexOfBytesOperator.php} (90%) rename src/Builder/{Aggregation/IndexOfCPAggregation.php => Expression/IndexOfCPOperator.php} (90%) rename src/Builder/{Aggregation/IntegralAggregation.php => Expression/IntegralOperator.php} (54%) rename src/Builder/{Aggregation/IsArrayAggregation.php => Expression/IsArrayOperator.php} (91%) rename src/Builder/{Aggregation/IsNumberAggregation.php => Expression/IsNumberOperator.php} (91%) rename src/Builder/{Aggregation/IsoDayOfWeekAggregation.php => Expression/IsoDayOfWeekOperator.php} (80%) rename src/Builder/{Aggregation/IsoWeekAggregation.php => Expression/IsoWeekOperator.php} (81%) rename src/Builder/{Aggregation/IsoWeekYearAggregation.php => Expression/IsoWeekYearOperator.php} (81%) rename src/Builder/{Aggregation/LastNAggregation.php => Expression/LastNOperator.php} (89%) rename src/Builder/{Aggregation/LastAggregation.php => Expression/LastOperator.php} (81%) rename src/Builder/{Aggregation/LetAggregation.php => Expression/LetOperator.php} (88%) create mode 100644 src/Builder/Expression/LinearFillOperator.php rename src/Builder/{Aggregation/LiteralAggregation.php => Expression/LiteralOperator.php} (83%) create mode 100644 src/Builder/Expression/LnOperator.php rename src/Builder/{Aggregation/LocfAggregation.php => Expression/LocfOperator.php} (82%) create mode 100644 src/Builder/Expression/Log10Operator.php create mode 100644 src/Builder/Expression/LogOperator.php rename src/Builder/{Aggregation/LtAggregation.php => Expression/LtOperator.php} (81%) rename src/Builder/{Aggregation/LteAggregation.php => Expression/LteOperator.php} (81%) rename src/Builder/{Aggregation/LtrimAggregation.php => Expression/LtrimOperator.php} (87%) rename src/Builder/{Aggregation/MapAggregation.php => Expression/MapOperator.php} (85%) rename src/Builder/{Aggregation/MaxNAggregation.php => Expression/MaxNOperator.php} (87%) rename src/Builder/{Aggregation/MaxAggregation.php => Expression/MaxOperator.php} (91%) create mode 100644 src/Builder/Expression/MedianOperator.php rename src/Builder/{Aggregation/MergeObjectsAggregation.php => Expression/MergeObjectsOperator.php} (89%) rename src/Builder/{Aggregation/MetaAggregation.php => Expression/MetaOperator.php} (81%) rename src/Builder/{Aggregation/MillisecondAggregation.php => Expression/MillisecondOperator.php} (80%) rename src/Builder/{Aggregation/MinNAggregation.php => Expression/MinNOperator.php} (87%) rename src/Builder/{Aggregation/MinAggregation.php => Expression/MinOperator.php} (91%) rename src/Builder/{Aggregation/MinuteAggregation.php => Expression/MinuteOperator.php} (80%) create mode 100644 src/Builder/Expression/ModOperator.php rename src/Builder/{Aggregation/MonthAggregation.php => Expression/MonthOperator.php} (80%) rename src/Builder/{Aggregation/MultiplyAggregation.php => Expression/MultiplyOperator.php} (57%) rename src/Builder/{Aggregation/NeAggregation.php => Expression/NeOperator.php} (81%) rename src/Builder/{Aggregation/NotAggregation.php => Expression/NotOperator.php} (82%) rename src/Builder/{Aggregation/ObjectToArrayAggregation.php => Expression/ObjectToArrayOperator.php} (87%) rename src/Builder/{Aggregation/OrAggregation.php => Expression/OrOperator.php} (91%) rename src/Builder/{Aggregation/PercentileAggregation.php => Expression/PercentileOperator.php} (60%) create mode 100644 src/Builder/Expression/PowOperator.php rename src/Builder/{Aggregation/PushAggregation.php => Expression/PushOperator.php} (84%) create mode 100644 src/Builder/Expression/RadiansToDegreesOperator.php rename src/Builder/{Aggregation/RandAggregation.php => Expression/RandOperator.php} (73%) rename src/Builder/{Aggregation/RangeAggregation.php => Expression/RangeOperator.php} (85%) rename src/Builder/{Aggregation/RankAggregation.php => Expression/RankOperator.php} (78%) rename src/Builder/{Aggregation/ReduceAggregation.php => Expression/ReduceOperator.php} (88%) rename src/Builder/{Aggregation/RegexFindAllAggregation.php => Expression/RegexFindAllOperator.php} (91%) rename src/Builder/{Aggregation/RegexFindAggregation.php => Expression/RegexFindOperator.php} (91%) rename src/Builder/{Aggregation/RegexMatchAggregation.php => Expression/RegexMatchOperator.php} (91%) rename src/Builder/{Aggregation/ReplaceAllAggregation.php => Expression/ReplaceAllOperator.php} (93%) rename src/Builder/{Aggregation/ReplaceOneAggregation.php => Expression/ReplaceOneOperator.php} (92%) rename src/Builder/{Aggregation/ReverseArrayAggregation.php => Expression/ReverseArrayOperator.php} (88%) rename src/Builder/{Aggregation/RoundAggregation.php => Expression/RoundOperator.php} (79%) rename src/Builder/{Aggregation/RtrimAggregation.php => Expression/RtrimOperator.php} (87%) rename src/Builder/{Aggregation/SampleRateAggregation.php => Expression/SampleRateOperator.php} (88%) rename src/Builder/{Aggregation/SecondAggregation.php => Expression/SecondOperator.php} (80%) rename src/Builder/{Aggregation/SetDifferenceAggregation.php => Expression/SetDifferenceOperator.php} (93%) rename src/Builder/{Aggregation/SetEqualsAggregation.php => Expression/SetEqualsOperator.php} (86%) rename src/Builder/{Aggregation/SetFieldAggregation.php => Expression/SetFieldOperator.php} (88%) rename src/Builder/{Aggregation/SetIntersectionAggregation.php => Expression/SetIntersectionOperator.php} (89%) rename src/Builder/{Aggregation/SetIsSubsetAggregation.php => Expression/SetIsSubsetOperator.php} (89%) rename src/Builder/{Aggregation/SetUnionAggregation.php => Expression/SetUnionOperator.php} (89%) rename src/Builder/{Aggregation/ShiftAggregation.php => Expression/ShiftOperator.php} (88%) create mode 100644 src/Builder/Expression/SinOperator.php create mode 100644 src/Builder/Expression/SinhOperator.php rename src/Builder/{Aggregation/SizeAggregation.php => Expression/SizeOperator.php} (86%) rename src/Builder/{Aggregation/SliceAggregation.php => Expression/SliceOperator.php} (91%) rename src/Builder/{Aggregation/SortArrayAggregation.php => Expression/SortArrayOperator.php} (90%) rename src/Builder/{Aggregation/SplitAggregation.php => Expression/SplitOperator.php} (88%) create mode 100644 src/Builder/Expression/SqrtOperator.php rename src/Builder/{Aggregation/StdDevPopAggregation.php => Expression/StdDevPopOperator.php} (62%) rename src/Builder/{Aggregation/StdDevSampAggregation.php => Expression/StdDevSampOperator.php} (62%) rename src/Builder/{Aggregation/StrLenBytesAggregation.php => Expression/StrLenBytesOperator.php} (78%) rename src/Builder/{Aggregation/StrLenCPAggregation.php => Expression/StrLenCPOperator.php} (78%) rename src/Builder/{Aggregation/StrcasecmpAggregation.php => Expression/StrcasecmpOperator.php} (85%) rename src/Builder/{Aggregation/SubstrBytesAggregation.php => Expression/SubstrBytesOperator.php} (88%) rename src/Builder/{Aggregation/SubstrCPAggregation.php => Expression/SubstrCPOperator.php} (89%) rename src/Builder/{Aggregation/SubstrAggregation.php => Expression/SubstrOperator.php} (88%) create mode 100644 src/Builder/Expression/SubtractOperator.php rename src/Builder/{Aggregation/SumAggregation.php => Expression/SumOperator.php} (55%) rename src/Builder/{Aggregation/SwitchAggregation.php => Expression/SwitchOperator.php} (77%) create mode 100644 src/Builder/Expression/TanOperator.php create mode 100644 src/Builder/Expression/TanhOperator.php rename src/Builder/{Aggregation/ToBoolAggregation.php => Expression/ToBoolOperator.php} (81%) rename src/Builder/{Aggregation/ToDateAggregation.php => Expression/ToDateOperator.php} (81%) rename src/Builder/{Aggregation/ToDecimalAggregation.php => Expression/ToDecimalOperator.php} (80%) rename src/Builder/{Aggregation/ToDoubleAggregation.php => Expression/ToDoubleOperator.php} (80%) rename src/Builder/{Aggregation/ToIntAggregation.php => Expression/ToIntOperator.php} (83%) rename src/Builder/{Aggregation/ToLongAggregation.php => Expression/ToLongOperator.php} (81%) rename src/Builder/{Aggregation/ToLowerAggregation.php => Expression/ToLowerOperator.php} (82%) rename src/Builder/{Aggregation/ToObjectIdAggregation.php => Expression/ToObjectIdOperator.php} (80%) rename src/Builder/{Aggregation/ToStringAggregation.php => Expression/ToStringOperator.php} (80%) rename src/Builder/{Aggregation/ToUpperAggregation.php => Expression/ToUpperOperator.php} (82%) rename src/Builder/{Aggregation/TopNAggregation.php => Expression/TopNOperator.php} (89%) rename src/Builder/{Aggregation/TopAggregation.php => Expression/TopOperator.php} (87%) rename src/Builder/{Aggregation/TrimAggregation.php => Expression/TrimOperator.php} (87%) create mode 100644 src/Builder/Expression/TruncOperator.php rename src/Builder/{Aggregation/TsIncrementAggregation.php => Expression/TsIncrementOperator.php} (79%) rename src/Builder/{Aggregation/TsSecondAggregation.php => Expression/TsSecondOperator.php} (79%) rename src/Builder/{Aggregation/TypeAggregation.php => Expression/TypeOperator.php} (80%) rename src/Builder/{Aggregation/UnsetFieldAggregation.php => Expression/UnsetFieldOperator.php} (89%) rename src/Builder/{Aggregation/WeekAggregation.php => Expression/WeekOperator.php} (81%) rename src/Builder/{Aggregation/YearAggregation.php => Expression/YearOperator.php} (80%) rename src/Builder/{Aggregation/ZipAggregation.php => Expression/ZipOperator.php} (96%) rename src/Builder/Query/{AllQuery.php => AllOperator.php} (97%) rename src/Builder/Query/{AndQuery.php => AndOperator.php} (96%) rename src/Builder/Query/{BitsAllClearQuery.php => BitsAllClearOperator.php} (95%) rename src/Builder/Query/{BitsAllSetQuery.php => BitsAllSetOperator.php} (95%) rename src/Builder/Query/{BitsAnyClearQuery.php => BitsAnyClearOperator.php} (95%) rename src/Builder/Query/{BitsAnySetQuery.php => BitsAnySetOperator.php} (95%) rename src/Builder/Query/{BoxQuery.php => BoxOperator.php} (95%) rename src/Builder/Query/{CenterQuery.php => CenterOperator.php} (95%) rename src/Builder/Query/{CenterSphereQuery.php => CenterSphereOperator.php} (95%) rename src/Builder/Query/{CommentQuery.php => CommentOperator.php} (92%) rename src/Builder/Query/{ElemMatchQuery.php => ElemMatchOperator.php} (93%) rename src/Builder/Query/{EqQuery.php => EqOperator.php} (87%) rename src/Builder/Query/{ExistsQuery.php => ExistsOperator.php} (92%) rename src/Builder/Query/{ExprQuery.php => ExprOperator.php} (87%) create mode 100644 src/Builder/Query/FactoryTrait.php rename src/Builder/Query/{GeoIntersectsQuery.php => GeoIntersectsOperator.php} (94%) rename src/Builder/Query/{GeoWithinQuery.php => GeoWithinOperator.php} (94%) rename src/Builder/Query/{GeometryQuery.php => GeometryOperator.php} (96%) rename src/Builder/Query/{GtQuery.php => GtOperator.php} (87%) rename src/Builder/Query/{GteQuery.php => GteOperator.php} (87%) rename src/Builder/Query/{InQuery.php => InOperator.php} (95%) rename src/Builder/Query/{JsonSchemaQuery.php => JsonSchemaOperator.php} (94%) rename src/Builder/Query/{LtQuery.php => LtOperator.php} (87%) rename src/Builder/Query/{LteQuery.php => LteOperator.php} (87%) create mode 100644 src/Builder/Query/MaxDistanceOperator.php delete mode 100644 src/Builder/Query/MaxDistanceQuery.php rename src/Builder/Query/{MetaQuery.php => MetaOperator.php} (90%) rename src/Builder/Query/{MinDistanceQuery.php => MinDistanceOperator.php} (93%) rename src/Builder/Query/{ModQuery.php => ModOperator.php} (94%) rename src/Builder/Query/{NaturalQuery.php => NaturalOperator.php} (91%) rename src/Builder/Query/{NeQuery.php => NeOperator.php} (87%) rename src/Builder/Query/{NearQuery.php => NearOperator.php} (97%) rename src/Builder/Query/{NearSphereQuery.php => NearSphereOperator.php} (97%) rename src/Builder/Query/{NinQuery.php => NinOperator.php} (95%) rename src/Builder/Query/{NorQuery.php => NorOperator.php} (96%) rename src/Builder/Query/{NotQuery.php => NotOperator.php} (95%) rename src/Builder/Query/{OrQuery.php => OrOperator.php} (96%) rename src/Builder/Query/{PolygonQuery.php => PolygonOperator.php} (95%) rename src/Builder/Query/{RandQuery.php => RandOperator.php} (90%) rename src/Builder/Query/{RegexQuery.php => RegexOperator.php} (93%) rename src/Builder/Query/{SizeQuery.php => SizeOperator.php} (93%) rename src/Builder/Query/{SliceQuery.php => SliceOperator.php} (92%) rename src/Builder/Query/{TextQuery.php => TextOperator.php} (98%) rename src/Builder/Query/{TypeQuery.php => TypeOperator.php} (95%) rename src/Builder/Query/{WhereQuery.php => WhereOperator.php} (93%) create mode 100644 src/Builder/Stage/FactoryTrait.php create mode 100644 src/Builder/Type/WindowInterface.php create mode 100644 src/Builder/architecture.md diff --git a/.gitattributes b/.gitattributes index 8343031d6..933293a11 100644 --- a/.gitattributes +++ b/.gitattributes @@ -18,11 +18,6 @@ psalm-baseline.xml export-ignore # Keep generated files from displaying in diffs by default # https://docs.github.com/en/repositories/working-with-files/managing-files/customizing-how-changed-files-appear-on-github -/src/Builder/Aggregation.php linguist-generated=true -/src/Builder/Aggregation/*.php linguist-generated=true -/src/Builder/Expression.php linguist-generated=true /src/Builder/Expression/*.php linguist-generated=true -/src/Builder/Query.php linguist-generated=true /src/Builder/Query/*.php linguist-generated=true -/src/Builder/Stage.php linguist-generated=true /src/Builder/Stage/*.php linguist-generated=true diff --git a/examples/aggregation-builder.php b/examples/aggregation-builder.php index 16077921e..98ccd906e 100644 --- a/examples/aggregation-builder.php +++ b/examples/aggregation-builder.php @@ -7,7 +7,6 @@ namespace MongoDB\Examples\AggregationBuilder; -use MongoDB\Builder\Aggregation; use MongoDB\Builder\BuilderEncoder; use MongoDB\Builder\Expression; use MongoDB\Builder\Pipeline; @@ -47,28 +46,18 @@ function toJSON(object $document): string $pipeline = new Pipeline( Stage::group( _id: null, - totalCount: Aggregation::sum(1), - evenCount: Aggregation::sum( - Aggregation::mod( - Expression::numberFieldPath('randomValue'), - 2, - ), + totalCount: Expression::sum(1), + evenCount: Expression::sum( + Expression::mod(Expression::numberFieldPath('randomValue'), 2), ), - oddCount: Aggregation::sum( - Aggregation::subtract( + oddCount: Expression::sum( + Expression::subtract( 1, - Aggregation::mod( - Expression::numberFieldPath('randomValue'), - 2, - ), + Expression::mod(Expression::numberFieldPath('randomValue'), 2), ), ), - maxValue: Aggregation::max( - Expression::fieldPath('randomValue'), - ), - minValue: Aggregation::min( - Expression::fieldPath('randomValue'), - ), + maxValue: Expression::max(Expression::numberFieldPath('randomValue')), + minValue: Expression::min(Expression::numberfieldPath('randomValue')), ), ); diff --git a/generator/config/aggregation-stages/unwind.yaml b/generator/config/aggregation-stages/unwind.yaml deleted file mode 100644 index 78cca0db3..000000000 --- a/generator/config/aggregation-stages/unwind.yaml +++ /dev/null @@ -1,15 +0,0 @@ -# $schema: ../schema.json -name: $unwind -category: - - Stage -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: field - type: - - arrayFieldPath diff --git a/generator/config/operators.php b/generator/config/definitions.php similarity index 72% rename from generator/config/operators.php rename to generator/config/definitions.php index 5ea99a850..041575745 100644 --- a/generator/config/operators.php +++ b/generator/config/definitions.php @@ -8,7 +8,7 @@ return [ // Aggregation Pipeline Stages [ - 'configFiles' => __DIR__ . '/aggregation-stages', + 'configFiles' => __DIR__ . '/stage', 'namespace' => 'MongoDB\\Builder\\Stage', 'classNameSuffix' => 'Stage', 'generators' => [ @@ -19,9 +19,9 @@ // Aggregation Pipeline Operators [ - 'configFiles' => __DIR__ . '/aggregation-operators', - 'namespace' => 'MongoDB\\Builder\\Aggregation', - 'classNameSuffix' => 'Aggregation', + 'configFiles' => __DIR__ . '/expression', + 'namespace' => 'MongoDB\\Builder\\Expression', + 'classNameSuffix' => 'Operator', 'generators' => [ OperatorClassGenerator::class, OperatorFactoryGenerator::class, @@ -30,9 +30,9 @@ // Query Operators [ - 'configFiles' => __DIR__ . '/query-operators', + 'configFiles' => __DIR__ . '/query', 'namespace' => 'MongoDB\\Builder\\Query', - 'classNameSuffix' => 'Query', + 'classNameSuffix' => 'Operator', 'generators' => [ OperatorClassGenerator::class, OperatorFactoryGenerator::class, diff --git a/generator/config/aggregation-operators/abs.yaml b/generator/config/expression/abs.yaml similarity index 100% rename from generator/config/aggregation-operators/abs.yaml rename to generator/config/expression/abs.yaml diff --git a/generator/config/aggregation-operators/accumulator.yaml b/generator/config/expression/accumulator.yaml similarity index 100% rename from generator/config/aggregation-operators/accumulator.yaml rename to generator/config/expression/accumulator.yaml diff --git a/generator/config/aggregation-operators/acos.yaml b/generator/config/expression/acos.yaml similarity index 100% rename from generator/config/aggregation-operators/acos.yaml rename to generator/config/expression/acos.yaml diff --git a/generator/config/aggregation-operators/acosh.yaml b/generator/config/expression/acosh.yaml similarity index 100% rename from generator/config/aggregation-operators/acosh.yaml rename to generator/config/expression/acosh.yaml diff --git a/generator/config/aggregation-operators/add.yaml b/generator/config/expression/add.yaml similarity index 100% rename from generator/config/aggregation-operators/add.yaml rename to generator/config/expression/add.yaml diff --git a/generator/config/aggregation-operators/addToSet.yaml b/generator/config/expression/addToSet.yaml similarity index 95% rename from generator/config/aggregation-operators/addToSet.yaml rename to generator/config/expression/addToSet.yaml index a33be309d..df20a5d1b 100644 --- a/generator/config/aggregation-operators/addToSet.yaml +++ b/generator/config/expression/addToSet.yaml @@ -6,6 +6,7 @@ category: link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/addToSet/' type: - accumulator + - window encode: single description: | Returns an array of unique expression values for each group. Order of the array elements is undefined. @@ -15,4 +16,3 @@ arguments: name: expression type: - expression - - fieldPath diff --git a/generator/config/aggregation-operators/allElementsTrue.yaml b/generator/config/expression/allElementsTrue.yaml similarity index 100% rename from generator/config/aggregation-operators/allElementsTrue.yaml rename to generator/config/expression/allElementsTrue.yaml diff --git a/generator/config/aggregation-operators/and.yaml b/generator/config/expression/and.yaml similarity index 100% rename from generator/config/aggregation-operators/and.yaml rename to generator/config/expression/and.yaml diff --git a/generator/config/aggregation-operators/anyElementTrue.yaml b/generator/config/expression/anyElementTrue.yaml similarity index 100% rename from generator/config/aggregation-operators/anyElementTrue.yaml rename to generator/config/expression/anyElementTrue.yaml diff --git a/generator/config/aggregation-operators/arrayElemAt.yaml b/generator/config/expression/arrayElemAt.yaml similarity index 100% rename from generator/config/aggregation-operators/arrayElemAt.yaml rename to generator/config/expression/arrayElemAt.yaml diff --git a/generator/config/aggregation-operators/arrayToObject.yaml b/generator/config/expression/arrayToObject.yaml similarity index 100% rename from generator/config/aggregation-operators/arrayToObject.yaml rename to generator/config/expression/arrayToObject.yaml diff --git a/generator/config/aggregation-operators/asin.yaml b/generator/config/expression/asin.yaml similarity index 100% rename from generator/config/aggregation-operators/asin.yaml rename to generator/config/expression/asin.yaml diff --git a/generator/config/aggregation-operators/asinh.yaml b/generator/config/expression/asinh.yaml similarity index 100% rename from generator/config/aggregation-operators/asinh.yaml rename to generator/config/expression/asinh.yaml diff --git a/generator/config/aggregation-operators/atan.yaml b/generator/config/expression/atan.yaml similarity index 100% rename from generator/config/aggregation-operators/atan.yaml rename to generator/config/expression/atan.yaml diff --git a/generator/config/aggregation-operators/atan2.yaml b/generator/config/expression/atan2.yaml similarity index 100% rename from generator/config/aggregation-operators/atan2.yaml rename to generator/config/expression/atan2.yaml diff --git a/generator/config/aggregation-operators/atanh.yaml b/generator/config/expression/atanh.yaml similarity index 100% rename from generator/config/aggregation-operators/atanh.yaml rename to generator/config/expression/atanh.yaml diff --git a/generator/config/aggregation-operators/avg.yaml b/generator/config/expression/avg.yaml similarity index 97% rename from generator/config/aggregation-operators/avg.yaml rename to generator/config/expression/avg.yaml index 47e558d42..b62d6ab56 100644 --- a/generator/config/aggregation-operators/avg.yaml +++ b/generator/config/expression/avg.yaml @@ -8,6 +8,7 @@ link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/avg/' type: - resolvesToNumber - accumulator + - window encode: single description: | Returns an average of numerical values. Ignores non-numeric values. diff --git a/generator/config/aggregation-operators/binarySize.yaml b/generator/config/expression/binarySize.yaml similarity index 100% rename from generator/config/aggregation-operators/binarySize.yaml rename to generator/config/expression/binarySize.yaml diff --git a/generator/config/aggregation-operators/bitAnd.yaml b/generator/config/expression/bitAnd.yaml similarity index 100% rename from generator/config/aggregation-operators/bitAnd.yaml rename to generator/config/expression/bitAnd.yaml diff --git a/generator/config/aggregation-operators/bitNot.yaml b/generator/config/expression/bitNot.yaml similarity index 100% rename from generator/config/aggregation-operators/bitNot.yaml rename to generator/config/expression/bitNot.yaml diff --git a/generator/config/aggregation-operators/bitOr.yaml b/generator/config/expression/bitOr.yaml similarity index 100% rename from generator/config/aggregation-operators/bitOr.yaml rename to generator/config/expression/bitOr.yaml diff --git a/generator/config/aggregation-operators/bitXor.yaml b/generator/config/expression/bitXor.yaml similarity index 100% rename from generator/config/aggregation-operators/bitXor.yaml rename to generator/config/expression/bitXor.yaml diff --git a/generator/config/aggregation-operators/bottom.yaml b/generator/config/expression/bottom.yaml similarity index 98% rename from generator/config/aggregation-operators/bottom.yaml rename to generator/config/expression/bottom.yaml index 9360482eb..7cae94e69 100644 --- a/generator/config/aggregation-operators/bottom.yaml +++ b/generator/config/expression/bottom.yaml @@ -6,6 +6,7 @@ category: link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/bottom/' type: - accumulator + - window encode: object description: | Returns the bottom element within a group according to the specified sort order. diff --git a/generator/config/aggregation-operators/bottomN.yaml b/generator/config/expression/bottomN.yaml similarity index 98% rename from generator/config/aggregation-operators/bottomN.yaml rename to generator/config/expression/bottomN.yaml index 385e4aed2..af44e7044 100644 --- a/generator/config/aggregation-operators/bottomN.yaml +++ b/generator/config/expression/bottomN.yaml @@ -6,6 +6,7 @@ category: link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/bottomN/' type: - accumulator + - window encode: object description: | Returns an aggregation of the bottom n elements within a group, according to the specified sort order. If the group contains fewer than n elements, $bottomN returns all elements in the group. diff --git a/generator/config/aggregation-operators/bsonSize.yaml b/generator/config/expression/bsonSize.yaml similarity index 100% rename from generator/config/aggregation-operators/bsonSize.yaml rename to generator/config/expression/bsonSize.yaml diff --git a/generator/config/aggregation-operators/ceil.yaml b/generator/config/expression/ceil.yaml similarity index 100% rename from generator/config/aggregation-operators/ceil.yaml rename to generator/config/expression/ceil.yaml diff --git a/generator/config/aggregation-operators/cmp.yaml b/generator/config/expression/cmp.yaml similarity index 100% rename from generator/config/aggregation-operators/cmp.yaml rename to generator/config/expression/cmp.yaml diff --git a/generator/config/aggregation-operators/concat.yaml b/generator/config/expression/concat.yaml similarity index 100% rename from generator/config/aggregation-operators/concat.yaml rename to generator/config/expression/concat.yaml diff --git a/generator/config/aggregation-operators/concatArrays.yaml b/generator/config/expression/concatArrays.yaml similarity index 100% rename from generator/config/aggregation-operators/concatArrays.yaml rename to generator/config/expression/concatArrays.yaml diff --git a/generator/config/aggregation-operators/cond.yaml b/generator/config/expression/cond.yaml similarity index 100% rename from generator/config/aggregation-operators/cond.yaml rename to generator/config/expression/cond.yaml diff --git a/generator/config/aggregation-operators/convert.yaml b/generator/config/expression/convert.yaml similarity index 100% rename from generator/config/aggregation-operators/convert.yaml rename to generator/config/expression/convert.yaml diff --git a/generator/config/aggregation-operators/cos.yaml b/generator/config/expression/cos.yaml similarity index 100% rename from generator/config/aggregation-operators/cos.yaml rename to generator/config/expression/cos.yaml diff --git a/generator/config/aggregation-operators/cosh.yaml b/generator/config/expression/cosh.yaml similarity index 100% rename from generator/config/aggregation-operators/cosh.yaml rename to generator/config/expression/cosh.yaml diff --git a/generator/config/aggregation-operators/count.yaml b/generator/config/expression/count.yaml similarity index 97% rename from generator/config/aggregation-operators/count.yaml rename to generator/config/expression/count.yaml index b83f1d389..46cb372ad 100644 --- a/generator/config/aggregation-operators/count.yaml +++ b/generator/config/expression/count.yaml @@ -6,6 +6,7 @@ category: link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/count/' type: - accumulator + - window encode: object description: | Returns the number of documents in the group or window. diff --git a/generator/config/aggregation-operators/covariancePop.yaml b/generator/config/expression/covariancePop.yaml similarity index 90% rename from generator/config/aggregation-operators/covariancePop.yaml rename to generator/config/expression/covariancePop.yaml index 084ef15e7..73dd28b76 100644 --- a/generator/config/aggregation-operators/covariancePop.yaml +++ b/generator/config/expression/covariancePop.yaml @@ -4,8 +4,7 @@ category: - 'Window Operator' link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/covariancePop/' type: - - resolvesToDouble - - resolvesToDecimal + - window encode: array description: | Returns the population covariance of two numeric expressions. diff --git a/generator/config/aggregation-operators/covarianceSamp.yaml b/generator/config/expression/covarianceSamp.yaml similarity index 90% rename from generator/config/aggregation-operators/covarianceSamp.yaml rename to generator/config/expression/covarianceSamp.yaml index 701776b3f..f21eb7ad3 100644 --- a/generator/config/aggregation-operators/covarianceSamp.yaml +++ b/generator/config/expression/covarianceSamp.yaml @@ -4,8 +4,7 @@ category: - 'Window Operator' link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/covarianceSamp/' type: - - resolvesToDouble - - resolvesToDecimal + - window encode: array description: | Returns the sample covariance of two numeric expressions. diff --git a/generator/config/aggregation-operators/dateAdd.yaml b/generator/config/expression/dateAdd.yaml similarity index 100% rename from generator/config/aggregation-operators/dateAdd.yaml rename to generator/config/expression/dateAdd.yaml diff --git a/generator/config/aggregation-operators/dateDiff.yaml b/generator/config/expression/dateDiff.yaml similarity index 100% rename from generator/config/aggregation-operators/dateDiff.yaml rename to generator/config/expression/dateDiff.yaml diff --git a/generator/config/aggregation-operators/dateFromParts.yaml b/generator/config/expression/dateFromParts.yaml similarity index 100% rename from generator/config/aggregation-operators/dateFromParts.yaml rename to generator/config/expression/dateFromParts.yaml diff --git a/generator/config/aggregation-operators/dateFromString.yaml b/generator/config/expression/dateFromString.yaml similarity index 100% rename from generator/config/aggregation-operators/dateFromString.yaml rename to generator/config/expression/dateFromString.yaml diff --git a/generator/config/aggregation-operators/dateSubtract.yaml b/generator/config/expression/dateSubtract.yaml similarity index 100% rename from generator/config/aggregation-operators/dateSubtract.yaml rename to generator/config/expression/dateSubtract.yaml diff --git a/generator/config/aggregation-operators/dateToParts.yaml b/generator/config/expression/dateToParts.yaml similarity index 100% rename from generator/config/aggregation-operators/dateToParts.yaml rename to generator/config/expression/dateToParts.yaml diff --git a/generator/config/aggregation-operators/dateToString.yaml b/generator/config/expression/dateToString.yaml similarity index 100% rename from generator/config/aggregation-operators/dateToString.yaml rename to generator/config/expression/dateToString.yaml diff --git a/generator/config/aggregation-operators/dateTrunc.yaml b/generator/config/expression/dateTrunc.yaml similarity index 100% rename from generator/config/aggregation-operators/dateTrunc.yaml rename to generator/config/expression/dateTrunc.yaml diff --git a/generator/config/aggregation-operators/dayOfMonth.yaml b/generator/config/expression/dayOfMonth.yaml similarity index 100% rename from generator/config/aggregation-operators/dayOfMonth.yaml rename to generator/config/expression/dayOfMonth.yaml diff --git a/generator/config/aggregation-operators/dayOfWeek.yaml b/generator/config/expression/dayOfWeek.yaml similarity index 100% rename from generator/config/aggregation-operators/dayOfWeek.yaml rename to generator/config/expression/dayOfWeek.yaml diff --git a/generator/config/aggregation-operators/dayOfYear.yaml b/generator/config/expression/dayOfYear.yaml similarity index 100% rename from generator/config/aggregation-operators/dayOfYear.yaml rename to generator/config/expression/dayOfYear.yaml diff --git a/generator/config/aggregation-operators/degreesToRadians.yaml b/generator/config/expression/degreesToRadians.yaml similarity index 100% rename from generator/config/aggregation-operators/degreesToRadians.yaml rename to generator/config/expression/degreesToRadians.yaml diff --git a/generator/config/aggregation-operators/denseRank.yaml b/generator/config/expression/denseRank.yaml similarity index 95% rename from generator/config/aggregation-operators/denseRank.yaml rename to generator/config/expression/denseRank.yaml index 0f3c3ab77..5578b676e 100644 --- a/generator/config/aggregation-operators/denseRank.yaml +++ b/generator/config/expression/denseRank.yaml @@ -4,7 +4,7 @@ category: - 'Window Operator' link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/denseRank/' type: - - resolvesToInt + - window encode: object 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. diff --git a/generator/config/aggregation-operators/derivative.yaml b/generator/config/expression/derivative.yaml similarity index 97% rename from generator/config/aggregation-operators/derivative.yaml rename to generator/config/expression/derivative.yaml index f8d13922c..f31af37d8 100644 --- a/generator/config/aggregation-operators/derivative.yaml +++ b/generator/config/expression/derivative.yaml @@ -4,7 +4,7 @@ category: - 'Window Operator' link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/derivative/' type: - - resolvesToDouble + - window encode: object description: | Returns the average rate of change within the specified window. diff --git a/generator/config/aggregation-operators/divide.yaml b/generator/config/expression/divide.yaml similarity index 100% rename from generator/config/aggregation-operators/divide.yaml rename to generator/config/expression/divide.yaml diff --git a/generator/config/aggregation-operators/documentNumber.yaml b/generator/config/expression/documentNumber.yaml similarity index 95% rename from generator/config/aggregation-operators/documentNumber.yaml rename to generator/config/expression/documentNumber.yaml index 745d546a8..84a9570aa 100644 --- a/generator/config/aggregation-operators/documentNumber.yaml +++ b/generator/config/expression/documentNumber.yaml @@ -4,7 +4,7 @@ category: - 'Window Operator' link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/documentNumber/' type: - - resolvesToInt + - window encode: object description: | Returns the position of a document (known as the document number) in the $setWindowFields stage partition. Ties result in different adjacent document numbers. diff --git a/generator/config/aggregation-operators/eq.yaml b/generator/config/expression/eq.yaml similarity index 100% rename from generator/config/aggregation-operators/eq.yaml rename to generator/config/expression/eq.yaml diff --git a/generator/config/aggregation-operators/exp.yaml b/generator/config/expression/exp.yaml similarity index 100% rename from generator/config/aggregation-operators/exp.yaml rename to generator/config/expression/exp.yaml diff --git a/generator/config/aggregation-operators/expMovingAvg.yaml b/generator/config/expression/expMovingAvg.yaml similarity index 98% rename from generator/config/aggregation-operators/expMovingAvg.yaml rename to generator/config/expression/expMovingAvg.yaml index accaa5646..17f575c42 100644 --- a/generator/config/aggregation-operators/expMovingAvg.yaml +++ b/generator/config/expression/expMovingAvg.yaml @@ -4,7 +4,7 @@ category: - 'Window Operator' link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/expMovingAvg/' type: - - resolvesToDouble + - window encode: object description: | Returns the exponential moving average for the numeric expression. diff --git a/generator/config/aggregation-operators/filter.yaml b/generator/config/expression/filter.yaml similarity index 98% rename from generator/config/aggregation-operators/filter.yaml rename to generator/config/expression/filter.yaml index ddf538abd..c83b75aad 100644 --- a/generator/config/aggregation-operators/filter.yaml +++ b/generator/config/expression/filter.yaml @@ -5,6 +5,7 @@ category: link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/filter/' type: - resolvesToArray + - projection encode: object description: | Selects a subset of the array to return an array with only the elements that match the filter condition. diff --git a/generator/config/aggregation-operators/first.yaml b/generator/config/expression/first.yaml similarity index 96% rename from generator/config/aggregation-operators/first.yaml rename to generator/config/expression/first.yaml index 78e08619a..41e3145d2 100644 --- a/generator/config/aggregation-operators/first.yaml +++ b/generator/config/expression/first.yaml @@ -6,8 +6,8 @@ category: - 'Window Operator' link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/first/' type: - - resolvesToAny - accumulator + - window encode: single description: | Returns the result of an expression for the first document in a group or window. diff --git a/generator/config/aggregation-operators/firstN.yaml b/generator/config/expression/firstN.yaml similarity index 98% rename from generator/config/aggregation-operators/firstN.yaml rename to generator/config/expression/firstN.yaml index fb8499292..f6c38dea7 100644 --- a/generator/config/aggregation-operators/firstN.yaml +++ b/generator/config/expression/firstN.yaml @@ -5,6 +5,7 @@ category: link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/firstN-array-element/' type: - accumulator + - window encode: object description: | Returns a specified number of elements from the beginning of an array. Distinct from the $firstN accumulator. diff --git a/generator/config/aggregation-operators/floor.yaml b/generator/config/expression/floor.yaml similarity index 100% rename from generator/config/aggregation-operators/floor.yaml rename to generator/config/expression/floor.yaml diff --git a/generator/config/aggregation-operators/function.yaml b/generator/config/expression/function.yaml similarity index 100% rename from generator/config/aggregation-operators/function.yaml rename to generator/config/expression/function.yaml diff --git a/generator/config/aggregation-operators/getField.yaml b/generator/config/expression/getField.yaml similarity index 100% rename from generator/config/aggregation-operators/getField.yaml rename to generator/config/expression/getField.yaml diff --git a/generator/config/aggregation-operators/gt.yaml b/generator/config/expression/gt.yaml similarity index 100% rename from generator/config/aggregation-operators/gt.yaml rename to generator/config/expression/gt.yaml diff --git a/generator/config/aggregation-operators/gte.yaml b/generator/config/expression/gte.yaml similarity index 100% rename from generator/config/aggregation-operators/gte.yaml rename to generator/config/expression/gte.yaml diff --git a/generator/config/aggregation-operators/hour.yaml b/generator/config/expression/hour.yaml similarity index 100% rename from generator/config/aggregation-operators/hour.yaml rename to generator/config/expression/hour.yaml diff --git a/generator/config/aggregation-operators/ifNull.yaml b/generator/config/expression/ifNull.yaml similarity index 100% rename from generator/config/aggregation-operators/ifNull.yaml rename to generator/config/expression/ifNull.yaml diff --git a/generator/config/aggregation-operators/in.yaml b/generator/config/expression/in.yaml similarity index 100% rename from generator/config/aggregation-operators/in.yaml rename to generator/config/expression/in.yaml diff --git a/generator/config/aggregation-operators/indexOfArray.yaml b/generator/config/expression/indexOfArray.yaml similarity index 100% rename from generator/config/aggregation-operators/indexOfArray.yaml rename to generator/config/expression/indexOfArray.yaml diff --git a/generator/config/aggregation-operators/indexOfBytes.yaml b/generator/config/expression/indexOfBytes.yaml similarity index 100% rename from generator/config/aggregation-operators/indexOfBytes.yaml rename to generator/config/expression/indexOfBytes.yaml diff --git a/generator/config/aggregation-operators/indexOfCP.yaml b/generator/config/expression/indexOfCP.yaml similarity index 100% rename from generator/config/aggregation-operators/indexOfCP.yaml rename to generator/config/expression/indexOfCP.yaml diff --git a/generator/config/aggregation-operators/integral.yaml b/generator/config/expression/integral.yaml similarity index 100% rename from generator/config/aggregation-operators/integral.yaml rename to generator/config/expression/integral.yaml diff --git a/generator/config/aggregation-operators/isArray.yaml b/generator/config/expression/isArray.yaml similarity index 100% rename from generator/config/aggregation-operators/isArray.yaml rename to generator/config/expression/isArray.yaml diff --git a/generator/config/aggregation-operators/isNumber.yaml b/generator/config/expression/isNumber.yaml similarity index 100% rename from generator/config/aggregation-operators/isNumber.yaml rename to generator/config/expression/isNumber.yaml diff --git a/generator/config/aggregation-operators/isoDayOfWeek.yaml b/generator/config/expression/isoDayOfWeek.yaml similarity index 100% rename from generator/config/aggregation-operators/isoDayOfWeek.yaml rename to generator/config/expression/isoDayOfWeek.yaml diff --git a/generator/config/aggregation-operators/isoWeek.yaml b/generator/config/expression/isoWeek.yaml similarity index 100% rename from generator/config/aggregation-operators/isoWeek.yaml rename to generator/config/expression/isoWeek.yaml diff --git a/generator/config/aggregation-operators/isoWeekYear.yaml b/generator/config/expression/isoWeekYear.yaml similarity index 100% rename from generator/config/aggregation-operators/isoWeekYear.yaml rename to generator/config/expression/isoWeekYear.yaml diff --git a/generator/config/aggregation-operators/last.yaml b/generator/config/expression/last.yaml similarity index 96% rename from generator/config/aggregation-operators/last.yaml rename to generator/config/expression/last.yaml index aa1463cd6..e23aad54e 100644 --- a/generator/config/aggregation-operators/last.yaml +++ b/generator/config/expression/last.yaml @@ -6,8 +6,8 @@ category: - 'Window Operator' link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/last/' type: - - resolvesToAny - accumulator + - window encode: single description: | Returns the result of an expression for the last document in a group or window. diff --git a/generator/config/aggregation-operators/lastN.yaml b/generator/config/expression/lastN.yaml similarity index 98% rename from generator/config/aggregation-operators/lastN.yaml rename to generator/config/expression/lastN.yaml index 121859038..06fce3bd5 100644 --- a/generator/config/aggregation-operators/lastN.yaml +++ b/generator/config/expression/lastN.yaml @@ -5,6 +5,7 @@ category: link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/lastN/' type: - resolvesToArray + - window encode: object description: | Returns a specified number of elements from the end of an array. Distinct from the $lastN accumulator. diff --git a/generator/config/aggregation-operators/let.yaml b/generator/config/expression/let.yaml similarity index 96% rename from generator/config/aggregation-operators/let.yaml rename to generator/config/expression/let.yaml index 01a597644..98645bc6d 100644 --- a/generator/config/aggregation-operators/let.yaml +++ b/generator/config/expression/let.yaml @@ -13,7 +13,7 @@ arguments: - name: vars type: - - object + - 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. diff --git a/generator/config/aggregation-operators/linearFill.yaml b/generator/config/expression/linearFill.yaml similarity index 100% rename from generator/config/aggregation-operators/linearFill.yaml rename to generator/config/expression/linearFill.yaml diff --git a/generator/config/aggregation-operators/literal.yaml b/generator/config/expression/literal.yaml similarity index 100% rename from generator/config/aggregation-operators/literal.yaml rename to generator/config/expression/literal.yaml diff --git a/generator/config/aggregation-operators/ln.yaml b/generator/config/expression/ln.yaml similarity index 100% rename from generator/config/aggregation-operators/ln.yaml rename to generator/config/expression/ln.yaml diff --git a/generator/config/aggregation-operators/locf.yaml b/generator/config/expression/locf.yaml similarity index 100% rename from generator/config/aggregation-operators/locf.yaml rename to generator/config/expression/locf.yaml diff --git a/generator/config/aggregation-operators/log.yaml b/generator/config/expression/log.yaml similarity index 100% rename from generator/config/aggregation-operators/log.yaml rename to generator/config/expression/log.yaml diff --git a/generator/config/aggregation-operators/log10.yaml b/generator/config/expression/log10.yaml similarity index 100% rename from generator/config/aggregation-operators/log10.yaml rename to generator/config/expression/log10.yaml diff --git a/generator/config/aggregation-operators/lt.yaml b/generator/config/expression/lt.yaml similarity index 100% rename from generator/config/aggregation-operators/lt.yaml rename to generator/config/expression/lt.yaml diff --git a/generator/config/aggregation-operators/lte.yaml b/generator/config/expression/lte.yaml similarity index 100% rename from generator/config/aggregation-operators/lte.yaml rename to generator/config/expression/lte.yaml diff --git a/generator/config/aggregation-operators/ltrim.yaml b/generator/config/expression/ltrim.yaml similarity index 100% rename from generator/config/aggregation-operators/ltrim.yaml rename to generator/config/expression/ltrim.yaml diff --git a/generator/config/aggregation-operators/map.yaml b/generator/config/expression/map.yaml similarity index 100% rename from generator/config/aggregation-operators/map.yaml rename to generator/config/expression/map.yaml diff --git a/generator/config/aggregation-operators/max.yaml b/generator/config/expression/max.yaml similarity index 97% rename from generator/config/aggregation-operators/max.yaml rename to generator/config/expression/max.yaml index 4061f78c7..73fd69e43 100644 --- a/generator/config/aggregation-operators/max.yaml +++ b/generator/config/expression/max.yaml @@ -8,6 +8,7 @@ link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/max/' type: - resolvesToAny - accumulator + - window encode: single description: | Returns the maximum value that results from applying an expression to each document. diff --git a/generator/config/aggregation-operators/maxN.yaml b/generator/config/expression/maxN.yaml similarity index 95% rename from generator/config/aggregation-operators/maxN.yaml rename to generator/config/expression/maxN.yaml index 9bc55aa2f..e7c5cd172 100644 --- a/generator/config/aggregation-operators/maxN.yaml +++ b/generator/config/expression/maxN.yaml @@ -5,6 +5,8 @@ category: link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/maxN-array-element/' type: - resolvesToArray + - accumulator + - window encode: object description: | Returns the n largest values in an array. Distinct from the $maxN accumulator. diff --git a/generator/config/aggregation-operators/median.yaml b/generator/config/expression/median.yaml similarity index 94% rename from generator/config/aggregation-operators/median.yaml rename to generator/config/expression/median.yaml index cf679c119..da25390ba 100644 --- a/generator/config/aggregation-operators/median.yaml +++ b/generator/config/expression/median.yaml @@ -7,6 +7,7 @@ link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/median type: - resolvesToDouble - accumulator + - window encode: object description: | Returns an approximation of the median, the 50th percentile, as a scalar value. @@ -25,6 +26,6 @@ arguments: - name: method type: - - AccumulatorPercentile + - string # AccumulatorPercentile description: | The method that mongod uses to calculate the 50th percentile value. The method must be 'approximate'. diff --git a/generator/config/aggregation-operators/mergeObjects.yaml b/generator/config/expression/mergeObjects.yaml similarity index 100% rename from generator/config/aggregation-operators/mergeObjects.yaml rename to generator/config/expression/mergeObjects.yaml diff --git a/generator/config/aggregation-operators/meta.yaml b/generator/config/expression/meta.yaml similarity index 100% rename from generator/config/aggregation-operators/meta.yaml rename to generator/config/expression/meta.yaml diff --git a/generator/config/aggregation-operators/millisecond.yaml b/generator/config/expression/millisecond.yaml similarity index 100% rename from generator/config/aggregation-operators/millisecond.yaml rename to generator/config/expression/millisecond.yaml diff --git a/generator/config/aggregation-operators/min.yaml b/generator/config/expression/min.yaml similarity index 97% rename from generator/config/aggregation-operators/min.yaml rename to generator/config/expression/min.yaml index 30d6f1acb..4553b818a 100644 --- a/generator/config/aggregation-operators/min.yaml +++ b/generator/config/expression/min.yaml @@ -8,6 +8,7 @@ link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/min/' type: - resolvesToAny - accumulator + - window encode: single description: | Returns the minimum value that results from applying an expression to each document. diff --git a/generator/config/aggregation-operators/minN.yaml b/generator/config/expression/minN.yaml similarity index 96% rename from generator/config/aggregation-operators/minN.yaml rename to generator/config/expression/minN.yaml index 9c55a4e84..03f43ba4e 100644 --- a/generator/config/aggregation-operators/minN.yaml +++ b/generator/config/expression/minN.yaml @@ -5,6 +5,8 @@ category: link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/minN-array-element/' type: - resolvesToArray + - accumulator + - window encode: object description: | Returns the n smallest values in an array. Distinct from the $minN accumulator. diff --git a/generator/config/aggregation-operators/minute.yaml b/generator/config/expression/minute.yaml similarity index 100% rename from generator/config/aggregation-operators/minute.yaml rename to generator/config/expression/minute.yaml diff --git a/generator/config/aggregation-operators/mod.yaml b/generator/config/expression/mod.yaml similarity index 100% rename from generator/config/aggregation-operators/mod.yaml rename to generator/config/expression/mod.yaml diff --git a/generator/config/aggregation-operators/month.yaml b/generator/config/expression/month.yaml similarity index 100% rename from generator/config/aggregation-operators/month.yaml rename to generator/config/expression/month.yaml diff --git a/generator/config/aggregation-operators/multiply.yaml b/generator/config/expression/multiply.yaml similarity index 100% rename from generator/config/aggregation-operators/multiply.yaml rename to generator/config/expression/multiply.yaml diff --git a/generator/config/aggregation-operators/ne.yaml b/generator/config/expression/ne.yaml similarity index 100% rename from generator/config/aggregation-operators/ne.yaml rename to generator/config/expression/ne.yaml diff --git a/generator/config/aggregation-operators/not.yaml b/generator/config/expression/not.yaml similarity index 100% rename from generator/config/aggregation-operators/not.yaml rename to generator/config/expression/not.yaml diff --git a/generator/config/aggregation-operators/objectToArray.yaml b/generator/config/expression/objectToArray.yaml similarity index 100% rename from generator/config/aggregation-operators/objectToArray.yaml rename to generator/config/expression/objectToArray.yaml diff --git a/generator/config/aggregation-operators/or.yaml b/generator/config/expression/or.yaml similarity index 100% rename from generator/config/aggregation-operators/or.yaml rename to generator/config/expression/or.yaml diff --git a/generator/config/aggregation-operators/percentile.yaml b/generator/config/expression/percentile.yaml similarity index 90% rename from generator/config/aggregation-operators/percentile.yaml rename to generator/config/expression/percentile.yaml index 6de131fb6..a9f5ba98e 100644 --- a/generator/config/aggregation-operators/percentile.yaml +++ b/generator/config/expression/percentile.yaml @@ -5,8 +5,9 @@ category: - 'Accumulators (in Other Stages)' link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/percentile/' type: - - resolvesToArray + - resolvesToArray # of scalar - accumulator + - window encode: object description: | Returns an array of scalar values that correspond to specified percentile values. @@ -28,13 +29,13 @@ arguments: - name: p type: - - resolvesToArray + - 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 + - string # AccumulatorPercentile description: | The method that mongod uses to calculate the percentile value. The method must be 'approximate'. diff --git a/generator/config/aggregation-operators/pow.yaml b/generator/config/expression/pow.yaml similarity index 100% rename from generator/config/aggregation-operators/pow.yaml rename to generator/config/expression/pow.yaml diff --git a/generator/config/aggregation-operators/push.yaml b/generator/config/expression/push.yaml similarity index 97% rename from generator/config/aggregation-operators/push.yaml rename to generator/config/expression/push.yaml index 2a190ce5d..9a4294b59 100644 --- a/generator/config/aggregation-operators/push.yaml +++ b/generator/config/expression/push.yaml @@ -6,6 +6,7 @@ category: link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/push/' type: - accumulator + - window encode: single description: | Returns an array of values that result from applying an expression to each document. diff --git a/generator/config/aggregation-operators/radiansToDegrees.yaml b/generator/config/expression/radiansToDegrees.yaml similarity index 100% rename from generator/config/aggregation-operators/radiansToDegrees.yaml rename to generator/config/expression/radiansToDegrees.yaml diff --git a/generator/config/aggregation-operators/rand.yaml b/generator/config/expression/rand.yaml similarity index 100% rename from generator/config/aggregation-operators/rand.yaml rename to generator/config/expression/rand.yaml diff --git a/generator/config/aggregation-operators/range.yaml b/generator/config/expression/range.yaml similarity index 96% rename from generator/config/aggregation-operators/range.yaml rename to generator/config/expression/range.yaml index f121e3907..96a9ada74 100644 --- a/generator/config/aggregation-operators/range.yaml +++ b/generator/config/expression/range.yaml @@ -4,7 +4,7 @@ category: - 'Array Expression Operator' link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/range/' type: - - resolvesToArray + - resolvesToArray # of int encode: array description: | Outputs an array containing a sequence of integers according to user-defined inputs. diff --git a/generator/config/aggregation-operators/rank.yaml b/generator/config/expression/rank.yaml similarity index 100% rename from generator/config/aggregation-operators/rank.yaml rename to generator/config/expression/rank.yaml diff --git a/generator/config/aggregation-operators/reduce.yaml b/generator/config/expression/reduce.yaml similarity index 100% rename from generator/config/aggregation-operators/reduce.yaml rename to generator/config/expression/reduce.yaml diff --git a/generator/config/aggregation-operators/regexFind.yaml b/generator/config/expression/regexFind.yaml similarity index 100% rename from generator/config/aggregation-operators/regexFind.yaml rename to generator/config/expression/regexFind.yaml diff --git a/generator/config/aggregation-operators/regexFindAll.yaml b/generator/config/expression/regexFindAll.yaml similarity index 96% rename from generator/config/aggregation-operators/regexFindAll.yaml rename to generator/config/expression/regexFindAll.yaml index 498b0e2a1..a3d997f9f 100644 --- a/generator/config/aggregation-operators/regexFindAll.yaml +++ b/generator/config/expression/regexFindAll.yaml @@ -4,7 +4,7 @@ category: - 'String Expression Operator' link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/regexFindAll/' type: - - resolvesToArray + - resolvesToArray # of object encode: object description: | Applies a regular expression (regex) to a string and returns information on the all matched substrings. diff --git a/generator/config/aggregation-operators/regexMatch.yaml b/generator/config/expression/regexMatch.yaml similarity index 100% rename from generator/config/aggregation-operators/regexMatch.yaml rename to generator/config/expression/regexMatch.yaml diff --git a/generator/config/aggregation-operators/replaceAll.yaml b/generator/config/expression/replaceAll.yaml similarity index 100% rename from generator/config/aggregation-operators/replaceAll.yaml rename to generator/config/expression/replaceAll.yaml diff --git a/generator/config/aggregation-operators/replaceOne.yaml b/generator/config/expression/replaceOne.yaml similarity index 100% rename from generator/config/aggregation-operators/replaceOne.yaml rename to generator/config/expression/replaceOne.yaml diff --git a/generator/config/aggregation-operators/reverseArray.yaml b/generator/config/expression/reverseArray.yaml similarity index 100% rename from generator/config/aggregation-operators/reverseArray.yaml rename to generator/config/expression/reverseArray.yaml diff --git a/generator/config/aggregation-operators/round.yaml b/generator/config/expression/round.yaml similarity index 100% rename from generator/config/aggregation-operators/round.yaml rename to generator/config/expression/round.yaml diff --git a/generator/config/aggregation-operators/rtrim.yaml b/generator/config/expression/rtrim.yaml similarity index 100% rename from generator/config/aggregation-operators/rtrim.yaml rename to generator/config/expression/rtrim.yaml diff --git a/generator/config/aggregation-operators/sampleRate.yaml b/generator/config/expression/sampleRate.yaml similarity index 100% rename from generator/config/aggregation-operators/sampleRate.yaml rename to generator/config/expression/sampleRate.yaml diff --git a/generator/config/aggregation-operators/second.yaml b/generator/config/expression/second.yaml similarity index 100% rename from generator/config/aggregation-operators/second.yaml rename to generator/config/expression/second.yaml diff --git a/generator/config/aggregation-operators/setDifference.yaml b/generator/config/expression/setDifference.yaml similarity index 100% rename from generator/config/aggregation-operators/setDifference.yaml rename to generator/config/expression/setDifference.yaml diff --git a/generator/config/aggregation-operators/setEquals.yaml b/generator/config/expression/setEquals.yaml similarity index 100% rename from generator/config/aggregation-operators/setEquals.yaml rename to generator/config/expression/setEquals.yaml diff --git a/generator/config/aggregation-operators/setField.yaml b/generator/config/expression/setField.yaml similarity index 100% rename from generator/config/aggregation-operators/setField.yaml rename to generator/config/expression/setField.yaml diff --git a/generator/config/aggregation-operators/setIntersection.yaml b/generator/config/expression/setIntersection.yaml similarity index 100% rename from generator/config/aggregation-operators/setIntersection.yaml rename to generator/config/expression/setIntersection.yaml diff --git a/generator/config/aggregation-operators/setIsSubset.yaml b/generator/config/expression/setIsSubset.yaml similarity index 100% rename from generator/config/aggregation-operators/setIsSubset.yaml rename to generator/config/expression/setIsSubset.yaml diff --git a/generator/config/aggregation-operators/setUnion.yaml b/generator/config/expression/setUnion.yaml similarity index 100% rename from generator/config/aggregation-operators/setUnion.yaml rename to generator/config/expression/setUnion.yaml diff --git a/generator/config/aggregation-operators/shift.yaml b/generator/config/expression/shift.yaml similarity index 98% rename from generator/config/aggregation-operators/shift.yaml rename to generator/config/expression/shift.yaml index 99a0d7034..72a4a8fcb 100644 --- a/generator/config/aggregation-operators/shift.yaml +++ b/generator/config/expression/shift.yaml @@ -4,7 +4,7 @@ category: - 'Window Operator' link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/shift/' type: - - resolvesToAny + - window encode: object 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. diff --git a/generator/config/aggregation-operators/sin.yaml b/generator/config/expression/sin.yaml similarity index 100% rename from generator/config/aggregation-operators/sin.yaml rename to generator/config/expression/sin.yaml diff --git a/generator/config/aggregation-operators/sinh.yaml b/generator/config/expression/sinh.yaml similarity index 100% rename from generator/config/aggregation-operators/sinh.yaml rename to generator/config/expression/sinh.yaml diff --git a/generator/config/aggregation-operators/size.yaml b/generator/config/expression/size.yaml similarity index 100% rename from generator/config/aggregation-operators/size.yaml rename to generator/config/expression/size.yaml diff --git a/generator/config/aggregation-operators/slice.yaml b/generator/config/expression/slice.yaml similarity index 97% rename from generator/config/aggregation-operators/slice.yaml rename to generator/config/expression/slice.yaml index 7d6af314d..666a48eaf 100644 --- a/generator/config/aggregation-operators/slice.yaml +++ b/generator/config/expression/slice.yaml @@ -5,6 +5,7 @@ category: link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/slice/' type: - resolvesToArray + - projection encode: array description: | Returns a subset of an array. @@ -25,7 +26,7 @@ arguments: 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' + name: "n" type: - resolvesToInt description: | diff --git a/generator/config/aggregation-operators/sortArray.yaml b/generator/config/expression/sortArray.yaml similarity index 100% rename from generator/config/aggregation-operators/sortArray.yaml rename to generator/config/expression/sortArray.yaml diff --git a/generator/config/aggregation-operators/split.yaml b/generator/config/expression/split.yaml similarity index 96% rename from generator/config/aggregation-operators/split.yaml rename to generator/config/expression/split.yaml index 50b523328..921d883c9 100644 --- a/generator/config/aggregation-operators/split.yaml +++ b/generator/config/expression/split.yaml @@ -4,7 +4,7 @@ category: - 'String Expression Operator' link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/split/' type: - - resolvesToArray + - resolvesToArray # of string 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. diff --git a/generator/config/aggregation-operators/sqrt.yaml b/generator/config/expression/sqrt.yaml similarity index 100% rename from generator/config/aggregation-operators/sqrt.yaml rename to generator/config/expression/sqrt.yaml diff --git a/generator/config/aggregation-operators/stdDevPop.yaml b/generator/config/expression/stdDevPop.yaml similarity index 100% rename from generator/config/aggregation-operators/stdDevPop.yaml rename to generator/config/expression/stdDevPop.yaml diff --git a/generator/config/aggregation-operators/stdDevSamp.yaml b/generator/config/expression/stdDevSamp.yaml similarity index 100% rename from generator/config/aggregation-operators/stdDevSamp.yaml rename to generator/config/expression/stdDevSamp.yaml diff --git a/generator/config/aggregation-operators/strLenBytes.yaml b/generator/config/expression/strLenBytes.yaml similarity index 100% rename from generator/config/aggregation-operators/strLenBytes.yaml rename to generator/config/expression/strLenBytes.yaml diff --git a/generator/config/aggregation-operators/strLenCP.yaml b/generator/config/expression/strLenCP.yaml similarity index 100% rename from generator/config/aggregation-operators/strLenCP.yaml rename to generator/config/expression/strLenCP.yaml diff --git a/generator/config/aggregation-operators/strcasecmp.yaml b/generator/config/expression/strcasecmp.yaml similarity index 100% rename from generator/config/aggregation-operators/strcasecmp.yaml rename to generator/config/expression/strcasecmp.yaml diff --git a/generator/config/aggregation-operators/substr.yaml b/generator/config/expression/substr.yaml similarity index 100% rename from generator/config/aggregation-operators/substr.yaml rename to generator/config/expression/substr.yaml diff --git a/generator/config/aggregation-operators/substrBytes.yaml b/generator/config/expression/substrBytes.yaml similarity index 100% rename from generator/config/aggregation-operators/substrBytes.yaml rename to generator/config/expression/substrBytes.yaml diff --git a/generator/config/aggregation-operators/substrCP.yaml b/generator/config/expression/substrCP.yaml similarity index 100% rename from generator/config/aggregation-operators/substrCP.yaml rename to generator/config/expression/substrCP.yaml diff --git a/generator/config/aggregation-operators/subtract.yaml b/generator/config/expression/subtract.yaml similarity index 100% rename from generator/config/aggregation-operators/subtract.yaml rename to generator/config/expression/subtract.yaml diff --git a/generator/config/aggregation-operators/sum.yaml b/generator/config/expression/sum.yaml similarity index 100% rename from generator/config/aggregation-operators/sum.yaml rename to generator/config/expression/sum.yaml diff --git a/generator/config/aggregation-operators/switch.yaml b/generator/config/expression/switch.yaml similarity index 94% rename from generator/config/aggregation-operators/switch.yaml rename to generator/config/expression/switch.yaml index 9711e801a..1c714b61c 100644 --- a/generator/config/aggregation-operators/switch.yaml +++ b/generator/config/expression/switch.yaml @@ -12,7 +12,7 @@ arguments: - name: branches type: - - 'array{case:resolvesToBool, then:expression}' + - array # of object{case:resolvesToBool, then:expression} 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. diff --git a/generator/config/aggregation-operators/tan.yaml b/generator/config/expression/tan.yaml similarity index 100% rename from generator/config/aggregation-operators/tan.yaml rename to generator/config/expression/tan.yaml diff --git a/generator/config/aggregation-operators/tanh.yaml b/generator/config/expression/tanh.yaml similarity index 100% rename from generator/config/aggregation-operators/tanh.yaml rename to generator/config/expression/tanh.yaml diff --git a/generator/config/aggregation-operators/toBool.yaml b/generator/config/expression/toBool.yaml similarity index 100% rename from generator/config/aggregation-operators/toBool.yaml rename to generator/config/expression/toBool.yaml diff --git a/generator/config/aggregation-operators/toDate.yaml b/generator/config/expression/toDate.yaml similarity index 100% rename from generator/config/aggregation-operators/toDate.yaml rename to generator/config/expression/toDate.yaml diff --git a/generator/config/aggregation-operators/toDecimal.yaml b/generator/config/expression/toDecimal.yaml similarity index 100% rename from generator/config/aggregation-operators/toDecimal.yaml rename to generator/config/expression/toDecimal.yaml diff --git a/generator/config/aggregation-operators/toDouble.yaml b/generator/config/expression/toDouble.yaml similarity index 100% rename from generator/config/aggregation-operators/toDouble.yaml rename to generator/config/expression/toDouble.yaml diff --git a/generator/config/aggregation-operators/toInt.yaml b/generator/config/expression/toInt.yaml similarity index 100% rename from generator/config/aggregation-operators/toInt.yaml rename to generator/config/expression/toInt.yaml diff --git a/generator/config/aggregation-operators/toLong.yaml b/generator/config/expression/toLong.yaml similarity index 100% rename from generator/config/aggregation-operators/toLong.yaml rename to generator/config/expression/toLong.yaml diff --git a/generator/config/aggregation-operators/toLower.yaml b/generator/config/expression/toLower.yaml similarity index 100% rename from generator/config/aggregation-operators/toLower.yaml rename to generator/config/expression/toLower.yaml diff --git a/generator/config/aggregation-operators/toObjectId.yaml b/generator/config/expression/toObjectId.yaml similarity index 100% rename from generator/config/aggregation-operators/toObjectId.yaml rename to generator/config/expression/toObjectId.yaml diff --git a/generator/config/aggregation-operators/toString.yaml b/generator/config/expression/toString.yaml similarity index 100% rename from generator/config/aggregation-operators/toString.yaml rename to generator/config/expression/toString.yaml diff --git a/generator/config/aggregation-operators/toUpper.yaml b/generator/config/expression/toUpper.yaml similarity index 100% rename from generator/config/aggregation-operators/toUpper.yaml rename to generator/config/expression/toUpper.yaml diff --git a/generator/config/aggregation-operators/top.yaml b/generator/config/expression/top.yaml similarity index 100% rename from generator/config/aggregation-operators/top.yaml rename to generator/config/expression/top.yaml diff --git a/generator/config/aggregation-operators/topN.yaml b/generator/config/expression/topN.yaml similarity index 100% rename from generator/config/aggregation-operators/topN.yaml rename to generator/config/expression/topN.yaml diff --git a/generator/config/aggregation-operators/trim.yaml b/generator/config/expression/trim.yaml similarity index 100% rename from generator/config/aggregation-operators/trim.yaml rename to generator/config/expression/trim.yaml diff --git a/generator/config/aggregation-operators/trunc.yaml b/generator/config/expression/trunc.yaml similarity index 100% rename from generator/config/aggregation-operators/trunc.yaml rename to generator/config/expression/trunc.yaml diff --git a/generator/config/aggregation-operators/tsIncrement.yaml b/generator/config/expression/tsIncrement.yaml similarity index 100% rename from generator/config/aggregation-operators/tsIncrement.yaml rename to generator/config/expression/tsIncrement.yaml diff --git a/generator/config/aggregation-operators/tsSecond.yaml b/generator/config/expression/tsSecond.yaml similarity index 100% rename from generator/config/aggregation-operators/tsSecond.yaml rename to generator/config/expression/tsSecond.yaml diff --git a/generator/config/aggregation-operators/type.yaml b/generator/config/expression/type.yaml similarity index 100% rename from generator/config/aggregation-operators/type.yaml rename to generator/config/expression/type.yaml diff --git a/generator/config/aggregation-operators/unsetField.yaml b/generator/config/expression/unsetField.yaml similarity index 100% rename from generator/config/aggregation-operators/unsetField.yaml rename to generator/config/expression/unsetField.yaml diff --git a/generator/config/aggregation-operators/week.yaml b/generator/config/expression/week.yaml similarity index 100% rename from generator/config/aggregation-operators/week.yaml rename to generator/config/expression/week.yaml diff --git a/generator/config/aggregation-operators/year.yaml b/generator/config/expression/year.yaml similarity index 100% rename from generator/config/aggregation-operators/year.yaml rename to generator/config/expression/year.yaml diff --git a/generator/config/aggregation-operators/zip.yaml b/generator/config/expression/zip.yaml similarity index 95% rename from generator/config/aggregation-operators/zip.yaml rename to generator/config/expression/zip.yaml index 0985edb42..38911a0a8 100644 --- a/generator/config/aggregation-operators/zip.yaml +++ b/generator/config/expression/zip.yaml @@ -4,7 +4,7 @@ category: - 'Array Expression Operator' link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/zip/' type: - - resolvesToArray + - resolvesToArray # of array encode: object description: | Merge two arrays together. @@ -12,7 +12,7 @@ arguments: - name: inputs type: - - resolvesToArray + - 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. diff --git a/generator/config/expressions.php b/generator/config/expressions.php index 8bfef4e6b..3211195fa 100644 --- a/generator/config/expressions.php +++ b/generator/config/expressions.php @@ -23,7 +23,7 @@ 'double' => ['int', BSON\Int64::class, 'float'], 'string' => ['string'], 'object' => ['array', stdClass::class, BSON\Document::class, BSON\Serializable::class], - 'array' => ['list', BSONArray::class, BSON\PackedArray::class], + 'array' => ['array', BSONArray::class, BSON\PackedArray::class], 'binData' => ['string', BSON\Binary::class], 'objectId' => [BSON\ObjectId::class], 'bool' => ['bool'], @@ -41,13 +41,10 @@ $bsonTypes['any'] = array_unique(array_merge(...array_values($bsonTypes))); // "number" accepts all the numeric types -$bsonTypes['number'] = [ - 'int', 'float', BSON\Int64::class, BSON\Decimal128::class, - ResolvesToInt::class, ResolvesToDouble::class, ResolvesToLong::class, ResolvesToDecimal::class, -]; +$bsonTypes['number'] = array_unique(array_merge($bsonTypes['int'], $bsonTypes['double'], $bsonTypes['long'], $bsonTypes['decimal'])); $expressions = []; - +$resolvesToInterfaces = []; foreach ($bsonTypes as $name => $acceptedTypes) { $expressions[$name] = ['acceptedTypes' => $acceptedTypes]; @@ -55,22 +52,27 @@ $resolvesToInterface = __NAMESPACE__ . '\\' . ucfirst($resolvesTo); $expressions[$resolvesTo] = [ 'generate' => Generate::PhpInterface, - // @todo implement type hierarchy for resolvesToNumber 'implements' => [Type\ExpressionInterface::class], 'returnType' => $resolvesToInterface, 'acceptedTypes' => $acceptedTypes, ]; - $expressions[$name . 'FieldPath'] = [ - 'generate' => Generate::PhpClass, - 'extends' => FieldPath::class, - 'implements' => [$resolvesToInterface], - 'acceptedTypes' => ['string'], - ]; + if ($name !== 'any') { + $expressions[$name . 'FieldPath'] = [ + 'generate' => Generate::PhpClass, + 'extends' => FieldPath::class, + 'implements' => [$resolvesToInterface], + 'acceptedTypes' => ['string'], + ]; + $resolvesToInterfaces[] = $resolvesToInterface; + } } -// AnyFieldPath doesn't make sense. Use FieldPath instead. -unset($expressions['anyFieldPath']); +$expressions['resolvesToLong']['implements'] = [ResolvesToInt::class]; +$expressions['resolvesToInt']['implements'] = [ResolvesToNumber::class]; +$expressions['resolvesToDecimal']['implements'] = [ResolvesToDouble::class]; +$expressions['resolvesToDouble']['implements'] = [ResolvesToNumber::class]; +$expressions['resolvesToAny']['implements'] = $resolvesToInterfaces; return $expressions + [ 'expression' => [ @@ -89,6 +91,10 @@ 'returnType' => Type\AccumulatorInterface::class, 'acceptedTypes' => [Type\AccumulatorInterface::class, ...$bsonTypes['object']], ], + 'window' => [ + 'returnType' => Type\WindowInterface::class, + 'acceptedTypes' => [Type\WindowInterface::class, ...$bsonTypes['object']], + ], 'stage' => [ 'returnType' => Type\StageInterface::class, 'acceptedTypes' => [Type\StageInterface::class, ...$bsonTypes['object']], @@ -103,7 +109,7 @@ ], 'variable' => [ 'generate' => Generate::PhpClass, - 'implements' => [Type\ExpressionInterface::class], + 'implements' => [ResolvesToAny::class], 'acceptedTypes' => ['string'], ], diff --git a/generator/config/query-operators/all.yaml b/generator/config/query/all.yaml similarity index 100% rename from generator/config/query-operators/all.yaml rename to generator/config/query/all.yaml diff --git a/generator/config/query-operators/and.yaml b/generator/config/query/and.yaml similarity index 100% rename from generator/config/query-operators/and.yaml rename to generator/config/query/and.yaml diff --git a/generator/config/query-operators/bitsAllClear.yaml b/generator/config/query/bitsAllClear.yaml similarity index 93% rename from generator/config/query-operators/bitsAllClear.yaml rename to generator/config/query/bitsAllClear.yaml index 98b76ded8..898289095 100644 --- a/generator/config/query-operators/bitsAllClear.yaml +++ b/generator/config/query/bitsAllClear.yaml @@ -14,4 +14,4 @@ arguments: type: - int - binData - - list + - array # of int diff --git a/generator/config/query-operators/bitsAllSet.yaml b/generator/config/query/bitsAllSet.yaml similarity index 93% rename from generator/config/query-operators/bitsAllSet.yaml rename to generator/config/query/bitsAllSet.yaml index c7a795a86..04211aa21 100644 --- a/generator/config/query-operators/bitsAllSet.yaml +++ b/generator/config/query/bitsAllSet.yaml @@ -14,4 +14,4 @@ arguments: type: - int - binData - - list + - array # of int diff --git a/generator/config/query-operators/bitsAnyClear.yaml b/generator/config/query/bitsAnyClear.yaml similarity index 93% rename from generator/config/query-operators/bitsAnyClear.yaml rename to generator/config/query/bitsAnyClear.yaml index 9d66db22b..186a93994 100644 --- a/generator/config/query-operators/bitsAnyClear.yaml +++ b/generator/config/query/bitsAnyClear.yaml @@ -14,4 +14,4 @@ arguments: type: - int - binData - - list + - array # of int diff --git a/generator/config/query-operators/bitsAnySet.yaml b/generator/config/query/bitsAnySet.yaml similarity index 93% rename from generator/config/query-operators/bitsAnySet.yaml rename to generator/config/query/bitsAnySet.yaml index 20dc51d60..93eac60b5 100644 --- a/generator/config/query-operators/bitsAnySet.yaml +++ b/generator/config/query/bitsAnySet.yaml @@ -14,4 +14,4 @@ arguments: type: - int - binData - - list + - array # of int diff --git a/generator/config/query-operators/box.yaml b/generator/config/query/box.yaml similarity index 100% rename from generator/config/query-operators/box.yaml rename to generator/config/query/box.yaml diff --git a/generator/config/query-operators/center.yaml b/generator/config/query/center.yaml similarity index 100% rename from generator/config/query-operators/center.yaml rename to generator/config/query/center.yaml diff --git a/generator/config/query-operators/centerSphere.yaml b/generator/config/query/centerSphere.yaml similarity index 100% rename from generator/config/query-operators/centerSphere.yaml rename to generator/config/query/centerSphere.yaml diff --git a/generator/config/query-operators/comment.yaml b/generator/config/query/comment.yaml similarity index 100% rename from generator/config/query-operators/comment.yaml rename to generator/config/query/comment.yaml diff --git a/generator/config/query-operators/elemMatch.yaml b/generator/config/query/elemMatch.yaml similarity index 100% rename from generator/config/query-operators/elemMatch.yaml rename to generator/config/query/elemMatch.yaml diff --git a/generator/config/query-operators/eq.yaml b/generator/config/query/eq.yaml similarity index 100% rename from generator/config/query-operators/eq.yaml rename to generator/config/query/eq.yaml diff --git a/generator/config/query-operators/exists.yaml b/generator/config/query/exists.yaml similarity index 100% rename from generator/config/query-operators/exists.yaml rename to generator/config/query/exists.yaml diff --git a/generator/config/query-operators/expr.yaml b/generator/config/query/expr.yaml similarity index 100% rename from generator/config/query-operators/expr.yaml rename to generator/config/query/expr.yaml diff --git a/generator/config/query-operators/geoIntersects.yaml b/generator/config/query/geoIntersects.yaml similarity index 100% rename from generator/config/query-operators/geoIntersects.yaml rename to generator/config/query/geoIntersects.yaml diff --git a/generator/config/query-operators/geoWithin.yaml b/generator/config/query/geoWithin.yaml similarity index 100% rename from generator/config/query-operators/geoWithin.yaml rename to generator/config/query/geoWithin.yaml diff --git a/generator/config/query-operators/geometry.yaml b/generator/config/query/geometry.yaml similarity index 100% rename from generator/config/query-operators/geometry.yaml rename to generator/config/query/geometry.yaml diff --git a/generator/config/query-operators/gt.yaml b/generator/config/query/gt.yaml similarity index 100% rename from generator/config/query-operators/gt.yaml rename to generator/config/query/gt.yaml diff --git a/generator/config/query-operators/gte.yaml b/generator/config/query/gte.yaml similarity index 100% rename from generator/config/query-operators/gte.yaml rename to generator/config/query/gte.yaml diff --git a/generator/config/query-operators/in.yaml b/generator/config/query/in.yaml similarity index 89% rename from generator/config/query-operators/in.yaml rename to generator/config/query/in.yaml index 4d0c929d9..9af595424 100644 --- a/generator/config/query-operators/in.yaml +++ b/generator/config/query/in.yaml @@ -12,4 +12,4 @@ arguments: - name: value type: - - array + - array # of expression diff --git a/generator/config/query-operators/jsonSchema.yaml b/generator/config/query/jsonSchema.yaml similarity index 100% rename from generator/config/query-operators/jsonSchema.yaml rename to generator/config/query/jsonSchema.yaml diff --git a/generator/config/query-operators/lt.yaml b/generator/config/query/lt.yaml similarity index 100% rename from generator/config/query-operators/lt.yaml rename to generator/config/query/lt.yaml diff --git a/generator/config/query-operators/lte.yaml b/generator/config/query/lte.yaml similarity index 100% rename from generator/config/query-operators/lte.yaml rename to generator/config/query/lte.yaml diff --git a/generator/config/query-operators/maxDistance.yaml b/generator/config/query/maxDistance.yaml similarity index 100% rename from generator/config/query-operators/maxDistance.yaml rename to generator/config/query/maxDistance.yaml diff --git a/generator/config/query-operators/meta.yaml b/generator/config/query/meta.yaml similarity index 100% rename from generator/config/query-operators/meta.yaml rename to generator/config/query/meta.yaml diff --git a/generator/config/query-operators/minDistance.yaml b/generator/config/query/minDistance.yaml similarity index 100% rename from generator/config/query-operators/minDistance.yaml rename to generator/config/query/minDistance.yaml diff --git a/generator/config/query-operators/mod.yaml b/generator/config/query/mod.yaml similarity index 100% rename from generator/config/query-operators/mod.yaml rename to generator/config/query/mod.yaml diff --git a/generator/config/query-operators/natural.yaml b/generator/config/query/natural.yaml similarity index 100% rename from generator/config/query-operators/natural.yaml rename to generator/config/query/natural.yaml diff --git a/generator/config/query-operators/ne.yaml b/generator/config/query/ne.yaml similarity index 100% rename from generator/config/query-operators/ne.yaml rename to generator/config/query/ne.yaml diff --git a/generator/config/query-operators/near.yaml b/generator/config/query/near.yaml similarity index 100% rename from generator/config/query-operators/near.yaml rename to generator/config/query/near.yaml diff --git a/generator/config/query-operators/nearSphere.yaml b/generator/config/query/nearSphere.yaml similarity index 100% rename from generator/config/query-operators/nearSphere.yaml rename to generator/config/query/nearSphere.yaml diff --git a/generator/config/query-operators/nin.yaml b/generator/config/query/nin.yaml similarity index 89% rename from generator/config/query-operators/nin.yaml rename to generator/config/query/nin.yaml index 40b22e9f8..ded97c7c8 100644 --- a/generator/config/query-operators/nin.yaml +++ b/generator/config/query/nin.yaml @@ -12,4 +12,4 @@ arguments: - name: value type: - - array + - array # of expression diff --git a/generator/config/query-operators/nor.yaml b/generator/config/query/nor.yaml similarity index 100% rename from generator/config/query-operators/nor.yaml rename to generator/config/query/nor.yaml diff --git a/generator/config/query-operators/not.yaml b/generator/config/query/not.yaml similarity index 100% rename from generator/config/query-operators/not.yaml rename to generator/config/query/not.yaml diff --git a/generator/config/query-operators/or.yaml b/generator/config/query/or.yaml similarity index 100% rename from generator/config/query-operators/or.yaml rename to generator/config/query/or.yaml diff --git a/generator/config/query-operators/polygon.yaml b/generator/config/query/polygon.yaml similarity index 100% rename from generator/config/query-operators/polygon.yaml rename to generator/config/query/polygon.yaml diff --git a/generator/config/query-operators/positional.yaml b/generator/config/query/positional.yaml similarity index 100% rename from generator/config/query-operators/positional.yaml rename to generator/config/query/positional.yaml diff --git a/generator/config/query-operators/rand.yaml b/generator/config/query/rand.yaml similarity index 100% rename from generator/config/query-operators/rand.yaml rename to generator/config/query/rand.yaml diff --git a/generator/config/query-operators/regex.yaml b/generator/config/query/regex.yaml similarity index 100% rename from generator/config/query-operators/regex.yaml rename to generator/config/query/regex.yaml diff --git a/generator/config/query-operators/size.yaml b/generator/config/query/size.yaml similarity index 100% rename from generator/config/query-operators/size.yaml rename to generator/config/query/size.yaml diff --git a/generator/config/query-operators/slice.yaml b/generator/config/query/slice.yaml similarity index 100% rename from generator/config/query-operators/slice.yaml rename to generator/config/query/slice.yaml diff --git a/generator/config/query-operators/text.yaml b/generator/config/query/text.yaml similarity index 100% rename from generator/config/query-operators/text.yaml rename to generator/config/query/text.yaml diff --git a/generator/config/query-operators/type.yaml b/generator/config/query/type.yaml similarity index 86% rename from generator/config/query-operators/type.yaml rename to generator/config/query/type.yaml index 48d79f2e8..757647a03 100644 --- a/generator/config/query-operators/type.yaml +++ b/generator/config/query/type.yaml @@ -14,5 +14,4 @@ arguments: type: - int - string - - array - - array + - array # of int or string diff --git a/generator/config/query-operators/where.yaml b/generator/config/query/where.yaml similarity index 100% rename from generator/config/query-operators/where.yaml rename to generator/config/query/where.yaml diff --git a/generator/config/schema.json b/generator/config/schema.json index 8cd283fe7..8267ce80f 100644 --- a/generator/config/schema.json +++ b/generator/config/schema.json @@ -29,7 +29,31 @@ "type": { "type": "array", "items": { - "type": "string" + "type": "string", + "enum": [ + "accumulator", + "projection", + "stage", + "query", + "window", + "resolvesToAny", + "resolvesToNumber", + "resolvesToDouble", + "resolvesToString", + "resolvesToObject", + "resolvesToArray", + "resolvesToBinData", + "resolvesToObjectId", + "resolvesToBool", + "resolvesToDate", + "resolvesToNull", + "resolvesToRegex", + "resolvesToJavascript", + "resolvesToInt", + "resolvesToTimestamp", + "resolvesTolong", + "resolvesToDecimal" + ] } }, "encode": { @@ -74,12 +98,35 @@ "properties": { "name": { "type": "string", - "pattern": "^[a-z][a-zA-Z0-9]+$" + "pattern": "^([a-z][a-zA-Z0-9]*|N)$" }, "type": { "type": "array", "items": { - "type": "string" + "type": "string", + "enum": [ + "accumulator", + "query", + "pipeline", + "window", + "expression", + "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" + ] } }, "description": { diff --git a/generator/config/aggregation-stages/addFields.yaml b/generator/config/stage/addFields.yaml similarity index 100% rename from generator/config/aggregation-stages/addFields.yaml rename to generator/config/stage/addFields.yaml diff --git a/generator/config/aggregation-stages/bucket.yaml b/generator/config/stage/bucket.yaml similarity index 95% rename from generator/config/aggregation-stages/bucket.yaml rename to generator/config/stage/bucket.yaml index 14b9c9a4e..9e62481e8 100644 --- a/generator/config/aggregation-stages/bucket.yaml +++ b/generator/config/stage/bucket.yaml @@ -12,15 +12,14 @@ arguments: - name: groupBy type: - - expression - - fieldPath + - 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 + - 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: @@ -37,7 +36,7 @@ arguments: - name: output type: - - object + - 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. diff --git a/generator/config/aggregation-stages/bucketAuto.yaml b/generator/config/stage/bucketAuto.yaml similarity index 95% rename from generator/config/aggregation-stages/bucketAuto.yaml rename to generator/config/stage/bucketAuto.yaml index f15335400..08dcbaffb 100644 --- a/generator/config/aggregation-stages/bucketAuto.yaml +++ b/generator/config/stage/bucketAuto.yaml @@ -24,7 +24,7 @@ arguments: - name: output type: - - object + - 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. @@ -32,7 +32,7 @@ arguments: - name: granularity type: - - Granularity + - object # 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. diff --git a/generator/config/aggregation-stages/changeStream.yaml b/generator/config/stage/changeStream.yaml similarity index 100% rename from generator/config/aggregation-stages/changeStream.yaml rename to generator/config/stage/changeStream.yaml diff --git a/generator/config/aggregation-stages/changeStreamSplitLargeEvent.yaml b/generator/config/stage/changeStreamSplitLargeEvent.yaml similarity index 100% rename from generator/config/aggregation-stages/changeStreamSplitLargeEvent.yaml rename to generator/config/stage/changeStreamSplitLargeEvent.yaml diff --git a/generator/config/aggregation-stages/collStats.yaml b/generator/config/stage/collStats.yaml similarity index 100% rename from generator/config/aggregation-stages/collStats.yaml rename to generator/config/stage/collStats.yaml diff --git a/generator/config/aggregation-stages/count.yaml b/generator/config/stage/count.yaml similarity index 100% rename from generator/config/aggregation-stages/count.yaml rename to generator/config/stage/count.yaml diff --git a/generator/config/aggregation-stages/currentOp.yaml b/generator/config/stage/currentOp.yaml similarity index 100% rename from generator/config/aggregation-stages/currentOp.yaml rename to generator/config/stage/currentOp.yaml diff --git a/generator/config/aggregation-stages/densify.yaml b/generator/config/stage/densify.yaml similarity index 91% rename from generator/config/aggregation-stages/densify.yaml rename to generator/config/stage/densify.yaml index 18616bcce..c1580ff4e 100644 --- a/generator/config/aggregation-stages/densify.yaml +++ b/generator/config/stage/densify.yaml @@ -12,7 +12,7 @@ arguments: - name: field type: - - fieldPath + - 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. @@ -20,13 +20,13 @@ arguments: - name: partitionByFields type: - - array + - array # of string optional: true description: | The field(s) that will be used as the partition keys. - name: range type: - - Range + - object # Range description: | Specification for range based densification. diff --git a/generator/config/aggregation-stages/documents.yaml b/generator/config/stage/documents.yaml similarity index 94% rename from generator/config/aggregation-stages/documents.yaml rename to generator/config/stage/documents.yaml index 35559e63c..ce8b1dcf8 100644 --- a/generator/config/aggregation-stages/documents.yaml +++ b/generator/config/stage/documents.yaml @@ -12,7 +12,7 @@ arguments: - name: documents type: - - resolvesToArray + - 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 diff --git a/generator/config/aggregation-stages/facet.yaml b/generator/config/stage/facet.yaml similarity index 100% rename from generator/config/aggregation-stages/facet.yaml rename to generator/config/stage/facet.yaml diff --git a/generator/config/aggregation-stages/fill.yaml b/generator/config/stage/fill.yaml similarity index 90% rename from generator/config/aggregation-stages/fill.yaml rename to generator/config/stage/fill.yaml index 88b85e88e..a485e34f5 100644 --- a/generator/config/aggregation-stages/fill.yaml +++ b/generator/config/stage/fill.yaml @@ -12,7 +12,7 @@ arguments: - name: partitionBy type: - - object + - object # of expression - string optional: true description: | @@ -22,7 +22,7 @@ arguments: - name: partitionByFields type: - - list + - 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. @@ -31,14 +31,14 @@ arguments: - name: sortBy type: - - SortSpec + - object # SortSpec 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' + - 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. diff --git a/generator/config/aggregation-stages/geoNear.yaml b/generator/config/stage/geoNear.yaml similarity index 100% rename from generator/config/aggregation-stages/geoNear.yaml rename to generator/config/stage/geoNear.yaml diff --git a/generator/config/aggregation-stages/graphLookup.yaml b/generator/config/stage/graphLookup.yaml similarity index 98% rename from generator/config/aggregation-stages/graphLookup.yaml rename to generator/config/stage/graphLookup.yaml index f08810c21..869b47be5 100644 --- a/generator/config/aggregation-stages/graphLookup.yaml +++ b/generator/config/stage/graphLookup.yaml @@ -20,7 +20,7 @@ arguments: name: startWith type: - expression - - list + - 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. - diff --git a/generator/config/aggregation-stages/group.yaml b/generator/config/stage/group.yaml similarity index 100% rename from generator/config/aggregation-stages/group.yaml rename to generator/config/stage/group.yaml diff --git a/generator/config/aggregation-stages/indexStats.yaml b/generator/config/stage/indexStats.yaml similarity index 100% rename from generator/config/aggregation-stages/indexStats.yaml rename to generator/config/stage/indexStats.yaml diff --git a/generator/config/aggregation-stages/limit.yaml b/generator/config/stage/limit.yaml similarity index 100% rename from generator/config/aggregation-stages/limit.yaml rename to generator/config/stage/limit.yaml diff --git a/generator/config/aggregation-stages/listLocalSessions.yaml b/generator/config/stage/listLocalSessions.yaml similarity index 100% rename from generator/config/aggregation-stages/listLocalSessions.yaml rename to generator/config/stage/listLocalSessions.yaml diff --git a/generator/config/aggregation-stages/listSampledQueries.yaml b/generator/config/stage/listSampledQueries.yaml similarity index 100% rename from generator/config/aggregation-stages/listSampledQueries.yaml rename to generator/config/stage/listSampledQueries.yaml diff --git a/generator/config/aggregation-stages/listSearchIndexes.yaml b/generator/config/stage/listSearchIndexes.yaml similarity index 100% rename from generator/config/aggregation-stages/listSearchIndexes.yaml rename to generator/config/stage/listSearchIndexes.yaml diff --git a/generator/config/aggregation-stages/listSessions.yaml b/generator/config/stage/listSessions.yaml similarity index 100% rename from generator/config/aggregation-stages/listSessions.yaml rename to generator/config/stage/listSessions.yaml diff --git a/generator/config/aggregation-stages/lookup.yaml b/generator/config/stage/lookup.yaml similarity index 98% rename from generator/config/aggregation-stages/lookup.yaml rename to generator/config/stage/lookup.yaml index 1f52dc44d..f37682049 100644 --- a/generator/config/aggregation-stages/lookup.yaml +++ b/generator/config/stage/lookup.yaml @@ -35,7 +35,7 @@ arguments: - name: let type: - - object + - 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. diff --git a/generator/config/aggregation-stages/match.yaml b/generator/config/stage/match.yaml similarity index 100% rename from generator/config/aggregation-stages/match.yaml rename to generator/config/stage/match.yaml diff --git a/generator/config/aggregation-stages/merge.yaml b/generator/config/stage/merge.yaml similarity index 94% rename from generator/config/aggregation-stages/merge.yaml rename to generator/config/stage/merge.yaml index 6b5cc82e6..3c38539c5 100644 --- a/generator/config/aggregation-stages/merge.yaml +++ b/generator/config/stage/merge.yaml @@ -14,14 +14,14 @@ arguments: name: into type: - string - - OutCollection + #- OutCollection description: | The output collection. - name: 'on' type: - string - - list + - 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. @@ -35,7 +35,7 @@ arguments: - name: whenMatched type: - - WhenMatched + - string # WhenMatched 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). diff --git a/generator/config/aggregation-stages/out.yaml b/generator/config/stage/out.yaml similarity index 100% rename from generator/config/aggregation-stages/out.yaml rename to generator/config/stage/out.yaml diff --git a/generator/config/aggregation-stages/planCacheStats.yaml b/generator/config/stage/planCacheStats.yaml similarity index 100% rename from generator/config/aggregation-stages/planCacheStats.yaml rename to generator/config/stage/planCacheStats.yaml diff --git a/generator/config/aggregation-stages/project.yaml b/generator/config/stage/project.yaml similarity index 100% rename from generator/config/aggregation-stages/project.yaml rename to generator/config/stage/project.yaml diff --git a/generator/config/aggregation-stages/redact.yaml b/generator/config/stage/redact.yaml similarity index 100% rename from generator/config/aggregation-stages/redact.yaml rename to generator/config/stage/redact.yaml diff --git a/generator/config/aggregation-stages/replaceRoot.yaml b/generator/config/stage/replaceRoot.yaml similarity index 100% rename from generator/config/aggregation-stages/replaceRoot.yaml rename to generator/config/stage/replaceRoot.yaml diff --git a/generator/config/aggregation-stages/replaceWith.yaml b/generator/config/stage/replaceWith.yaml similarity index 100% rename from generator/config/aggregation-stages/replaceWith.yaml rename to generator/config/stage/replaceWith.yaml diff --git a/generator/config/aggregation-stages/sample.yaml b/generator/config/stage/sample.yaml similarity index 100% rename from generator/config/aggregation-stages/sample.yaml rename to generator/config/stage/sample.yaml diff --git a/generator/config/aggregation-stages/search.yaml b/generator/config/stage/search.yaml similarity index 100% rename from generator/config/aggregation-stages/search.yaml rename to generator/config/stage/search.yaml diff --git a/generator/config/aggregation-stages/searchMeta.yaml b/generator/config/stage/searchMeta.yaml similarity index 100% rename from generator/config/aggregation-stages/searchMeta.yaml rename to generator/config/stage/searchMeta.yaml diff --git a/generator/config/aggregation-stages/set.yaml b/generator/config/stage/set.yaml similarity index 100% rename from generator/config/aggregation-stages/set.yaml rename to generator/config/stage/set.yaml diff --git a/generator/config/aggregation-stages/setWindowFields.yaml b/generator/config/stage/setWindowFields.yaml similarity index 100% rename from generator/config/aggregation-stages/setWindowFields.yaml rename to generator/config/stage/setWindowFields.yaml diff --git a/generator/config/aggregation-stages/shardedDataDistribution.yaml b/generator/config/stage/shardedDataDistribution.yaml similarity index 100% rename from generator/config/aggregation-stages/shardedDataDistribution.yaml rename to generator/config/stage/shardedDataDistribution.yaml diff --git a/generator/config/aggregation-stages/skip.yaml b/generator/config/stage/skip.yaml similarity index 100% rename from generator/config/aggregation-stages/skip.yaml rename to generator/config/stage/skip.yaml diff --git a/generator/config/aggregation-stages/sort.yaml b/generator/config/stage/sort.yaml similarity index 100% rename from generator/config/aggregation-stages/sort.yaml rename to generator/config/stage/sort.yaml diff --git a/generator/config/aggregation-stages/sortByCount.yaml b/generator/config/stage/sortByCount.yaml similarity index 100% rename from generator/config/aggregation-stages/sortByCount.yaml rename to generator/config/stage/sortByCount.yaml diff --git a/generator/config/aggregation-stages/unionWith.yaml b/generator/config/stage/unionWith.yaml similarity index 100% rename from generator/config/aggregation-stages/unionWith.yaml rename to generator/config/stage/unionWith.yaml diff --git a/generator/config/aggregation-stages/unset.yaml b/generator/config/stage/unset.yaml similarity index 100% rename from generator/config/aggregation-stages/unset.yaml rename to generator/config/stage/unset.yaml diff --git a/generator/config/stage/unwind.yaml b/generator/config/stage/unwind.yaml new file mode 100644 index 000000000..bcd1526a2 --- /dev/null +++ b/generator/config/stage/unwind.yaml @@ -0,0 +1,33 @@ +# $schema: ../schema.json +name: $unwind +category: + - Stage +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. diff --git a/generator/src/CodecClassGenerator.php b/generator/src/CodecClassGenerator.php deleted file mode 100644 index 11fda216d..000000000 --- a/generator/src/CodecClassGenerator.php +++ /dev/null @@ -1,60 +0,0 @@ -getClassName($object)); - - $constuctor = $class->addMethod('__construct'); - - foreach ($object->arguments as $argument) { - ['native' => $nativeType, 'doc' => $docType] = $this->getAcceptedTypes($argument); - - // Property - $propertyComment = ''; - $property = $class->addProperty($argument->name); - if ($argument->isVariadic) { - $property->setType('array'); - $propertyComment .= '@param list<' . $docType . '> $' . $argument->name . PHP_EOL; - } else { - $property->setType($nativeType); - } - - $property->setComment($propertyComment); - - // Constructor - $constuctorParam = $constuctor->addParameter($argument->name); - $constuctorParam->setType($nativeType); - if ($argument->isVariadic) { - $constuctor->setVariadic(); - } - - $constuctor->addComment('@param ' . $docType . ' $' . $argument->name . PHP_EOL); - $constuctor->addBody('$this->' . $argument->name . ' = $' . $argument->name . ';' . PHP_EOL); - } - - return $class; - } - - public function generate(GeneratorDefinition $definition): void - { - // TODO: Implement generate() method. - } -} diff --git a/generator/src/Command/GenerateCommand.php b/generator/src/Command/GenerateCommand.php index 14e165b63..c4a607895 100644 --- a/generator/src/Command/GenerateCommand.php +++ b/generator/src/Command/GenerateCommand.php @@ -72,7 +72,7 @@ private function generateExpressionClasses(OutputInterface $output): array /** @param array, ExpressionDefinition> $expressions */ private function generateOperatorClasses(array $expressions, OutputInterface $output): void { - $config = require $this->configDir . '/operators.php'; + $config = require $this->configDir . '/definitions.php'; assert(is_array($config)); foreach ($config as $def) { diff --git a/generator/src/ExpressionFactoryGenerator.php b/generator/src/ExpressionFactoryGenerator.php index a5ed5791e..4c3dc6658 100644 --- a/generator/src/ExpressionFactoryGenerator.php +++ b/generator/src/ExpressionFactoryGenerator.php @@ -21,9 +21,9 @@ public function generate(array $expressions): void /** @param array $expressions */ private function createFactoryClass(array $expressions): PhpNamespace { - $namespace = new PhpNamespace('MongoDB\\Builder'); - $class = $namespace->addClass('Expression'); - $class->setFinal(); + $namespace = new PhpNamespace('MongoDB\\Builder\\Expression'); + $trait = $namespace->addTrait('ExpressionFactoryTrait'); + $trait->addComment('@internal'); // Pedantry requires methods to be ordered alphabetically usort($expressions, fn (ExpressionDefinition $a, ExpressionDefinition $b) => $a->name <=> $b->name); @@ -36,17 +36,13 @@ private function createFactoryClass(array $expressions): PhpNamespace $namespace->addUse($expression->returnType); $expressionShortClassName = $this->splitNamespaceAndClassName($expression->returnType)[1]; - $method = $class->addMethod(lcfirst($expressionShortClassName)); + $method = $trait->addMethod(lcfirst($expressionShortClassName)); $method->setStatic(); - $method->addParameter('expression')->setType('string'); - $method->addBody('return new ' . $expressionShortClassName . '($expression);'); + $method->addParameter('name')->setType('string'); + $method->addBody('return new ' . $expressionShortClassName . '($name);'); $method->setReturnType($expression->returnType); } - // Pedantry requires private methods to be at the end - $class->addMethod('__construct')->setPrivate() - ->setComment('This class cannot be instantiated.'); - return $namespace; } } diff --git a/generator/src/OperatorFactoryGenerator.php b/generator/src/OperatorFactoryGenerator.php index d1924cc64..36cbd4011 100644 --- a/generator/src/OperatorFactoryGenerator.php +++ b/generator/src/OperatorFactoryGenerator.php @@ -5,9 +5,9 @@ use MongoDB\CodeGenerator\Definition\GeneratorDefinition; use MongoDB\CodeGenerator\Definition\OperatorDefinition; -use Nette\PhpGenerator\ClassType; use Nette\PhpGenerator\Literal; use Nette\PhpGenerator\PhpNamespace; +use Nette\PhpGenerator\TraitType; use RuntimeException; use Throwable; @@ -23,16 +23,14 @@ final class OperatorFactoryGenerator extends OperatorGenerator { public function generate(GeneratorDefinition $definition): void { - $this->writeFile($this->createFactoryClass($definition)); + $this->writeFile($this->createFactoryTrait($definition)); } - private function createFactoryClass(GeneratorDefinition $definition): PhpNamespace + private function createFactoryTrait(GeneratorDefinition $definition): PhpNamespace { - // Use the operators namespace as factory class name. - [$namespace, $className] = $this->splitNamespaceAndClassName($definition->namespace); - $namespace = new PhpNamespace($namespace); - $class = $namespace->addClass($className); - $class->setFinal(); + $namespace = new PhpNamespace($definition->namespace); + $trait = $namespace->addTrait('FactoryTrait'); + $trait->addComment('@internal'); // Pedantry requires methods to be ordered alphabetically $operators = $this->getOperators($definition); @@ -40,25 +38,21 @@ private function createFactoryClass(GeneratorDefinition $definition): PhpNamespa foreach ($operators as $operator) { try { - $this->addMethod($definition, $operator, $namespace, $class); + $this->addMethod($definition, $operator, $namespace, $trait); } catch (Throwable $e) { throw new RuntimeException(sprintf('Failed to generate class for operator "%s"', $operator->name), 0, $e); } } - // Pedantry requires private methods to be at the end - $class->addMethod('__construct')->setPrivate() - ->setComment('This class cannot be instantiated.'); - return $namespace; } - private function addMethod(GeneratorDefinition $definition, OperatorDefinition $operator, PhpNamespace $namespace, ClassType $class): void + private function addMethod(GeneratorDefinition $definition, OperatorDefinition $operator, PhpNamespace $namespace, TraitType $trait): void { $operatorClassName = '\\' . $definition->namespace . '\\' . $this->getOperatorClassName($definition, $operator); $namespace->addUse($operatorClassName); - $method = $class->addMethod(ltrim($operator->name, '$')); + $method = $trait->addMethod(ltrim($operator->name, '$')); $method->setStatic(); $method->addComment($operator->description); $method->addComment('@see ' . $operator->link); diff --git a/generator/src/OperatorGenerator.php b/generator/src/OperatorGenerator.php index 866f10a8b..35fbdc3a5 100644 --- a/generator/src/OperatorGenerator.php +++ b/generator/src/OperatorGenerator.php @@ -3,7 +3,8 @@ namespace MongoDB\CodeGenerator; -use MongoDB\Builder\Expression\ExpressionType; +use MongoDB\BSON\Document; +use MongoDB\BSON\PackedArray; use MongoDB\Builder\Optional; use MongoDB\CodeGenerator\Definition\ArgumentDefinition; use MongoDB\CodeGenerator\Definition\ExpressionDefinition; @@ -11,6 +12,7 @@ use MongoDB\CodeGenerator\Definition\OperatorDefinition; use MongoDB\CodeGenerator\Definition\YamlReader; use Nette\PhpGenerator\Type; +use stdClass; use function array_filter; use function array_key_exists; @@ -18,13 +20,13 @@ use function array_unique; use function assert; use function class_exists; -use function explode; use function in_array; use function interface_exists; use function ltrim; use function sort; use function sprintf; use function ucfirst; +use function usort; abstract class OperatorGenerator extends AbstractGenerator { @@ -32,7 +34,7 @@ abstract class OperatorGenerator extends AbstractGenerator final public function __construct( string $rootDir, - /** @var array, ExpressionDefinition> */ + /** @var array */ private array $expressions ) { parent::__construct($rootDir); @@ -58,15 +60,6 @@ final protected function getOperatorClassName(GeneratorDefinition $definition, O final protected function getType(string $type): ExpressionDefinition { - // @todo handle generic types object and array - $type = explode('<', $type, 2)[0]; - $type = explode('{', $type, 2)[0]; - - $type = match ($type) { - 'list' => 'array', - default => $type, - }; - assert(array_key_exists($type, $this->expressions), sprintf('Invalid expression type "%s".', $type)); return $this->expressions[$type]; @@ -78,7 +71,7 @@ final protected function getType(string $type): ExpressionDefinition * * @return object{native:string,doc:string,use:list,list:bool} */ - final protected function getAcceptedTypes(ArgumentDefinition $arg): object + final protected function getAcceptedTypes(ArgumentDefinition $arg): stdClass { $nativeTypes = []; foreach ($arg->type as $type) { @@ -96,19 +89,9 @@ final protected function getAcceptedTypes(ArgumentDefinition $arg): object } $docTypes = $nativeTypes = array_unique($nativeTypes); - $listCheck = false; $use = []; foreach ($nativeTypes as $key => $typeName) { - // "list" is a special type of array that needs to be checked in the code - if ($typeName === 'list') { - $listCheck = true; - $nativeTypes[$key] = 'array'; - // @todo allow to specify the type of the elements in the list - $docTypes[$key] = 'array'; - continue; - } - // strings cannot be empty if ($typeName === 'string') { $docTypes[$key] = 'non-empty-string'; @@ -124,13 +107,17 @@ final protected function getAcceptedTypes(ArgumentDefinition $arg): object } } + // If an array is expected, but not an object, we can check for a list + $listCheck = in_array('\\' . PackedArray::class, $nativeTypes, true) + && ! in_array('\\' . Document::class, $nativeTypes, true); + // mixed can only be used as a standalone type if (in_array('mixed', $nativeTypes, true)) { $nativeTypes = ['mixed']; } - sort($nativeTypes); - sort($docTypes); + usort($nativeTypes, self::sortTypesCallback(...)); + usort($docTypes, self::sortTypesCallback(...)); sort($use); return (object) [ @@ -140,4 +127,22 @@ final protected function getAcceptedTypes(ArgumentDefinition $arg): object 'list' => $listCheck, ]; } + + /** + * usort() callback for sorting types. + * "Optional" is always first, for documentation of optional parameters, + * then types are sorted alphabetically. + */ + private static function sortTypesCallback(string $type1, string $type2): int + { + if ($type1 === 'Optional' || $type1 === '\\' . Optional::class) { + return -1; + } + + if ($type2 === 'Optional' || $type2 === '\\' . Optional::class) { + return 1; + } + + return $type1 <=> $type2; + } } diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 949748155..62f53dad8 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -20,8 +20,7 @@ rector.php - src/Builder/(Aggregation|Expression|Query|Stage)\.php - src/Builder/(Aggregation|Expression|Query|Stage)/*\.php + src/Builder/(Expression|Query|Stage)/*\.php diff --git a/src/Builder/Aggregation/AbsAggregation.php b/src/Builder/Aggregation/AbsAggregation.php deleted file mode 100644 index d51be0336..000000000 --- a/src/Builder/Aggregation/AbsAggregation.php +++ /dev/null @@ -1,39 +0,0 @@ -value = $value; - } -} diff --git a/src/Builder/Aggregation/AcosAggregation.php b/src/Builder/Aggregation/AcosAggregation.php deleted file mode 100644 index d3a5f79a0..000000000 --- a/src/Builder/Aggregation/AcosAggregation.php +++ /dev/null @@ -1,45 +0,0 @@ -expression = $expression; - } -} diff --git a/src/Builder/Aggregation/AcoshAggregation.php b/src/Builder/Aggregation/AcoshAggregation.php deleted file mode 100644 index 7f93c51e3..000000000 --- a/src/Builder/Aggregation/AcoshAggregation.php +++ /dev/null @@ -1,45 +0,0 @@ -expression = $expression; - } -} diff --git a/src/Builder/Aggregation/AddToSetAggregation.php b/src/Builder/Aggregation/AddToSetAggregation.php deleted file mode 100644 index 2cbb3df92..000000000 --- a/src/Builder/Aggregation/AddToSetAggregation.php +++ /dev/null @@ -1,53 +0,0 @@ -expression = $expression; - } -} diff --git a/src/Builder/Aggregation/AndAggregation.php b/src/Builder/Aggregation/AndAggregation.php deleted file mode 100644 index a40eb7290..000000000 --- a/src/Builder/Aggregation/AndAggregation.php +++ /dev/null @@ -1,60 +0,0 @@ - ...$expression */ - public array $expression; - - /** - * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToBool|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNull|ResolvesToNumber|ResolvesToString|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass ...$expression - * @no-named-arguments - */ - public function __construct( - Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToBool|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNull|ResolvesToNumber|ResolvesToString|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string ...$expression, - ) { - if (\count($expression) < 1) { - throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); - } - if (! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression arguments to be a list (array), named arguments are not supported'); - } - $this->expression = $expression; - } -} diff --git a/src/Builder/Aggregation/AsinAggregation.php b/src/Builder/Aggregation/AsinAggregation.php deleted file mode 100644 index 2d23ea597..000000000 --- a/src/Builder/Aggregation/AsinAggregation.php +++ /dev/null @@ -1,45 +0,0 @@ -expression = $expression; - } -} diff --git a/src/Builder/Aggregation/Atan2Aggregation.php b/src/Builder/Aggregation/Atan2Aggregation.php deleted file mode 100644 index f54998e7f..000000000 --- a/src/Builder/Aggregation/Atan2Aggregation.php +++ /dev/null @@ -1,51 +0,0 @@ -y = $y; - $this->x = $x; - } -} diff --git a/src/Builder/Aggregation/AtanhAggregation.php b/src/Builder/Aggregation/AtanhAggregation.php deleted file mode 100644 index a37abf92d..000000000 --- a/src/Builder/Aggregation/AtanhAggregation.php +++ /dev/null @@ -1,45 +0,0 @@ -expression = $expression; - } -} diff --git a/src/Builder/Aggregation/CeilAggregation.php b/src/Builder/Aggregation/CeilAggregation.php deleted file mode 100644 index 070230d0f..000000000 --- a/src/Builder/Aggregation/CeilAggregation.php +++ /dev/null @@ -1,39 +0,0 @@ -expression = $expression; - } -} diff --git a/src/Builder/Aggregation/CosAggregation.php b/src/Builder/Aggregation/CosAggregation.php deleted file mode 100644 index 86b90e242..000000000 --- a/src/Builder/Aggregation/CosAggregation.php +++ /dev/null @@ -1,43 +0,0 @@ - resolves to a 128-bit decimal value. - */ - public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression; - - /** - * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression $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. - */ - public function __construct( - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression, - ) { - $this->expression = $expression; - } -} diff --git a/src/Builder/Aggregation/CoshAggregation.php b/src/Builder/Aggregation/CoshAggregation.php deleted file mode 100644 index dcaaa94c7..000000000 --- a/src/Builder/Aggregation/CoshAggregation.php +++ /dev/null @@ -1,43 +0,0 @@ - resolves to a 128-bit decimal value. - */ - public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression; - - /** - * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression $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. - */ - public function __construct( - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression, - ) { - $this->expression = $expression; - } -} diff --git a/src/Builder/Aggregation/CovariancePopAggregation.php b/src/Builder/Aggregation/CovariancePopAggregation.php deleted file mode 100644 index 5fcfc0fbf..000000000 --- a/src/Builder/Aggregation/CovariancePopAggregation.php +++ /dev/null @@ -1,46 +0,0 @@ -expression1 = $expression1; - $this->expression2 = $expression2; - } -} diff --git a/src/Builder/Aggregation/CovarianceSampAggregation.php b/src/Builder/Aggregation/CovarianceSampAggregation.php deleted file mode 100644 index 8c65a909f..000000000 --- a/src/Builder/Aggregation/CovarianceSampAggregation.php +++ /dev/null @@ -1,46 +0,0 @@ -expression1 = $expression1; - $this->expression2 = $expression2; - } -} diff --git a/src/Builder/Aggregation/DateFromPartsAggregation.php b/src/Builder/Aggregation/DateFromPartsAggregation.php deleted file mode 100644 index b318bc3ef..000000000 --- a/src/Builder/Aggregation/DateFromPartsAggregation.php +++ /dev/null @@ -1,102 +0,0 @@ -year = $year; - $this->isoWeekYear = $isoWeekYear; - $this->month = $month; - $this->isoWeek = $isoWeek; - $this->day = $day; - $this->isoDayOfWeek = $isoDayOfWeek; - $this->hour = $hour; - $this->minute = $minute; - $this->second = $second; - $this->millisecond = $millisecond; - $this->timezone = $timezone; - } -} diff --git a/src/Builder/Aggregation/DegreesToRadiansAggregation.php b/src/Builder/Aggregation/DegreesToRadiansAggregation.php deleted file mode 100644 index f5cd7b5ed..000000000 --- a/src/Builder/Aggregation/DegreesToRadiansAggregation.php +++ /dev/null @@ -1,43 +0,0 @@ - resolves to a 128-bit decimal value. - */ - public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression; - - /** - * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression $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. - */ - public function __construct( - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression, - ) { - $this->expression = $expression; - } -} diff --git a/src/Builder/Aggregation/DivideAggregation.php b/src/Builder/Aggregation/DivideAggregation.php deleted file mode 100644 index 3ad6ffc44..000000000 --- a/src/Builder/Aggregation/DivideAggregation.php +++ /dev/null @@ -1,45 +0,0 @@ -dividend = $dividend; - $this->divisor = $divisor; - } -} diff --git a/src/Builder/Aggregation/ExpAggregation.php b/src/Builder/Aggregation/ExpAggregation.php deleted file mode 100644 index 955b5a45d..000000000 --- a/src/Builder/Aggregation/ExpAggregation.php +++ /dev/null @@ -1,39 +0,0 @@ -exponent = $exponent; - } -} diff --git a/src/Builder/Aggregation/FloorAggregation.php b/src/Builder/Aggregation/FloorAggregation.php deleted file mode 100644 index 5c6bdf63a..000000000 --- a/src/Builder/Aggregation/FloorAggregation.php +++ /dev/null @@ -1,39 +0,0 @@ -expression = $expression; - } -} diff --git a/src/Builder/Aggregation/LinearFillAggregation.php b/src/Builder/Aggregation/LinearFillAggregation.php deleted file mode 100644 index bf246f30c..000000000 --- a/src/Builder/Aggregation/LinearFillAggregation.php +++ /dev/null @@ -1,41 +0,0 @@ -expression = $expression; - } -} diff --git a/src/Builder/Aggregation/LnAggregation.php b/src/Builder/Aggregation/LnAggregation.php deleted file mode 100644 index 28a8659f4..000000000 --- a/src/Builder/Aggregation/LnAggregation.php +++ /dev/null @@ -1,40 +0,0 @@ -, Math.E ] expression, where Math.E is a JavaScript representation for Euler's number e. - * - * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/ln/ - */ -class LnAggregation implements ResolvesToDouble -{ - public const NAME = '$ln'; - public const ENCODE = \MongoDB\Builder\Encode::Single; - - /** @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $number Any valid expression as long as it resolves to a non-negative number. For more information on expressions, see Expressions. */ - public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $number; - - /** - * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $number Any valid expression as long as it resolves to a non-negative number. For more information on expressions, see Expressions. - */ - public function __construct( - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $number, - ) { - $this->number = $number; - } -} diff --git a/src/Builder/Aggregation/Log10Aggregation.php b/src/Builder/Aggregation/Log10Aggregation.php deleted file mode 100644 index 54a935e61..000000000 --- a/src/Builder/Aggregation/Log10Aggregation.php +++ /dev/null @@ -1,39 +0,0 @@ -number = $number; - } -} diff --git a/src/Builder/Aggregation/LogAggregation.php b/src/Builder/Aggregation/LogAggregation.php deleted file mode 100644 index d3315164e..000000000 --- a/src/Builder/Aggregation/LogAggregation.php +++ /dev/null @@ -1,45 +0,0 @@ -number = $number; - $this->base = $base; - } -} diff --git a/src/Builder/Aggregation/MedianAggregation.php b/src/Builder/Aggregation/MedianAggregation.php deleted file mode 100644 index 783f22868..000000000 --- a/src/Builder/Aggregation/MedianAggregation.php +++ /dev/null @@ -1,51 +0,0 @@ -input = $input; - $this->method = $method; - } -} diff --git a/src/Builder/Aggregation/ModAggregation.php b/src/Builder/Aggregation/ModAggregation.php deleted file mode 100644 index 84fc22c4e..000000000 --- a/src/Builder/Aggregation/ModAggregation.php +++ /dev/null @@ -1,45 +0,0 @@ -dividend = $dividend; - $this->divisor = $divisor; - } -} diff --git a/src/Builder/Aggregation/PowAggregation.php b/src/Builder/Aggregation/PowAggregation.php deleted file mode 100644 index e2f5b3763..000000000 --- a/src/Builder/Aggregation/PowAggregation.php +++ /dev/null @@ -1,45 +0,0 @@ -number = $number; - $this->exponent = $exponent; - } -} diff --git a/src/Builder/Aggregation/RadiansToDegreesAggregation.php b/src/Builder/Aggregation/RadiansToDegreesAggregation.php deleted file mode 100644 index 1e03ef516..000000000 --- a/src/Builder/Aggregation/RadiansToDegreesAggregation.php +++ /dev/null @@ -1,39 +0,0 @@ -expression = $expression; - } -} diff --git a/src/Builder/Aggregation/SinAggregation.php b/src/Builder/Aggregation/SinAggregation.php deleted file mode 100644 index 0f96b1aca..000000000 --- a/src/Builder/Aggregation/SinAggregation.php +++ /dev/null @@ -1,43 +0,0 @@ -expression = $expression; - } -} diff --git a/src/Builder/Aggregation/SinhAggregation.php b/src/Builder/Aggregation/SinhAggregation.php deleted file mode 100644 index 897d183af..000000000 --- a/src/Builder/Aggregation/SinhAggregation.php +++ /dev/null @@ -1,43 +0,0 @@ -expression = $expression; - } -} diff --git a/src/Builder/Aggregation/SqrtAggregation.php b/src/Builder/Aggregation/SqrtAggregation.php deleted file mode 100644 index d797c5291..000000000 --- a/src/Builder/Aggregation/SqrtAggregation.php +++ /dev/null @@ -1,39 +0,0 @@ -number = $number; - } -} diff --git a/src/Builder/Aggregation/SubtractAggregation.php b/src/Builder/Aggregation/SubtractAggregation.php deleted file mode 100644 index ffa736e36..000000000 --- a/src/Builder/Aggregation/SubtractAggregation.php +++ /dev/null @@ -1,47 +0,0 @@ -expression1 = $expression1; - $this->expression2 = $expression2; - } -} diff --git a/src/Builder/Aggregation/TanAggregation.php b/src/Builder/Aggregation/TanAggregation.php deleted file mode 100644 index a2e9de353..000000000 --- a/src/Builder/Aggregation/TanAggregation.php +++ /dev/null @@ -1,43 +0,0 @@ -expression = $expression; - } -} diff --git a/src/Builder/Aggregation/TanhAggregation.php b/src/Builder/Aggregation/TanhAggregation.php deleted file mode 100644 index d7a3c1c69..000000000 --- a/src/Builder/Aggregation/TanhAggregation.php +++ /dev/null @@ -1,43 +0,0 @@ -expression = $expression; - } -} diff --git a/src/Builder/Aggregation/TruncAggregation.php b/src/Builder/Aggregation/TruncAggregation.php deleted file mode 100644 index 619a9179c..000000000 --- a/src/Builder/Aggregation/TruncAggregation.php +++ /dev/null @@ -1,51 +0,0 @@ -number = $number; - $this->place = $place; - } -} diff --git a/src/Builder/BuilderEncoder.php b/src/Builder/BuilderEncoder.php index e13f89747..299a1c270 100644 --- a/src/Builder/BuilderEncoder.php +++ b/src/Builder/BuilderEncoder.php @@ -10,6 +10,7 @@ use MongoDB\Builder\Type\ExpressionInterface; use MongoDB\Builder\Type\QueryInterface; use MongoDB\Builder\Type\StageInterface; +use MongoDB\Builder\Type\WindowInterface; use MongoDB\Codec\EncodeIfSupported; use MongoDB\Codec\Encoder; use MongoDB\Exception\UnsupportedValueException; @@ -22,7 +23,7 @@ use function is_array; use function sprintf; -/** @template-implements Encoder */ +/** @template-implements Encoder */ class BuilderEncoder implements Encoder { use EncodeIfSupported; @@ -35,7 +36,9 @@ public function canEncode($value): bool return $value instanceof Pipeline || $value instanceof StageInterface || $value instanceof ExpressionInterface - || $value instanceof QueryInterface; + || $value instanceof QueryInterface + || $value instanceof AccumulatorInterface + || $value instanceof WindowInterface; } /** diff --git a/src/Builder/Encode.php b/src/Builder/Encode.php index 6a2752938..d1fe12b85 100644 --- a/src/Builder/Encode.php +++ b/src/Builder/Encode.php @@ -2,6 +2,11 @@ namespace MongoDB\Builder; +/** + * Defines how to encode a stage or an operator into BSON. + * + * @see BuilderEncoder + */ enum Encode { // @todo add comments (see schema.json) diff --git a/src/Builder/Expression.php b/src/Builder/Expression.php index 3ab38672a..50d5d5d95 100644 --- a/src/Builder/Expression.php +++ b/src/Builder/Expression.php @@ -6,121 +6,8 @@ namespace MongoDB\Builder; -use MongoDB\Builder\Expression\ArrayFieldPath; -use MongoDB\Builder\Expression\BinDataFieldPath; -use MongoDB\Builder\Expression\BoolFieldPath; -use MongoDB\Builder\Expression\DateFieldPath; -use MongoDB\Builder\Expression\DecimalFieldPath; -use MongoDB\Builder\Expression\DoubleFieldPath; -use MongoDB\Builder\Expression\FieldPath; -use MongoDB\Builder\Expression\IntFieldPath; -use MongoDB\Builder\Expression\JavascriptFieldPath; -use MongoDB\Builder\Expression\LongFieldPath; -use MongoDB\Builder\Expression\NullFieldPath; -use MongoDB\Builder\Expression\NumberFieldPath; -use MongoDB\Builder\Expression\ObjectFieldPath; -use MongoDB\Builder\Expression\ObjectIdFieldPath; -use MongoDB\Builder\Expression\RegexFieldPath; -use MongoDB\Builder\Expression\StringFieldPath; -use MongoDB\Builder\Expression\TimestampFieldPath; -use MongoDB\Builder\Expression\Variable; - -final class Expression +enum Expression { - public static function arrayFieldPath(string $expression): ArrayFieldPath - { - return new ArrayFieldPath($expression); - } - - public static function binDataFieldPath(string $expression): BinDataFieldPath - { - return new BinDataFieldPath($expression); - } - - public static function boolFieldPath(string $expression): BoolFieldPath - { - return new BoolFieldPath($expression); - } - - public static function dateFieldPath(string $expression): DateFieldPath - { - return new DateFieldPath($expression); - } - - public static function decimalFieldPath(string $expression): DecimalFieldPath - { - return new DecimalFieldPath($expression); - } - - public static function doubleFieldPath(string $expression): DoubleFieldPath - { - return new DoubleFieldPath($expression); - } - - public static function fieldPath(string $expression): FieldPath - { - return new FieldPath($expression); - } - - public static function intFieldPath(string $expression): IntFieldPath - { - return new IntFieldPath($expression); - } - - public static function javascriptFieldPath(string $expression): JavascriptFieldPath - { - return new JavascriptFieldPath($expression); - } - - public static function longFieldPath(string $expression): LongFieldPath - { - return new LongFieldPath($expression); - } - - public static function nullFieldPath(string $expression): NullFieldPath - { - return new NullFieldPath($expression); - } - - public static function numberFieldPath(string $expression): NumberFieldPath - { - return new NumberFieldPath($expression); - } - - public static function objectFieldPath(string $expression): ObjectFieldPath - { - return new ObjectFieldPath($expression); - } - - public static function objectIdFieldPath(string $expression): ObjectIdFieldPath - { - return new ObjectIdFieldPath($expression); - } - - public static function regexFieldPath(string $expression): RegexFieldPath - { - return new RegexFieldPath($expression); - } - - public static function stringFieldPath(string $expression): StringFieldPath - { - return new StringFieldPath($expression); - } - - public static function timestampFieldPath(string $expression): TimestampFieldPath - { - return new TimestampFieldPath($expression); - } - - public static function variable(string $expression): Variable - { - return new Variable($expression); - } - - /** - * This class cannot be instantiated. - */ - private function __construct() - { - } + use Expression\ExpressionFactoryTrait; + use Expression\FactoryTrait; } diff --git a/src/Builder/Expression/AbsOperator.php b/src/Builder/Expression/AbsOperator.php new file mode 100644 index 000000000..1dd958885 --- /dev/null +++ b/src/Builder/Expression/AbsOperator.php @@ -0,0 +1,33 @@ +value = $value; + } +} diff --git a/src/Builder/Aggregation/AccumulatorAggregation.php b/src/Builder/Expression/AccumulatorOperator.php similarity index 91% rename from src/Builder/Aggregation/AccumulatorAggregation.php rename to src/Builder/Expression/AccumulatorOperator.php index 0ee47f894..8ac073fd8 100644 --- a/src/Builder/Aggregation/AccumulatorAggregation.php +++ b/src/Builder/Expression/AccumulatorOperator.php @@ -4,11 +4,10 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\PackedArray; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToArray; use MongoDB\Builder\Optional; use MongoDB\Builder\Type\AccumulatorInterface; use MongoDB\Model\BSONArray; @@ -19,7 +18,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/accumulator/ */ -class AccumulatorAggregation implements AccumulatorInterface +class AccumulatorOperator implements AccumulatorInterface { public const NAME = '$accumulator'; public const ENCODE = \MongoDB\Builder\Encode::Object; @@ -39,8 +38,8 @@ class AccumulatorAggregation implements AccumulatorInterface /** @param non-empty-string $lang The language used in the $accumulator code. */ public string $lang; - /** @param BSONArray|Optional|PackedArray|ResolvesToArray|array $initArgs Arguments passed to the init function. */ - public PackedArray|ResolvesToArray|Optional|BSONArray|array $initArgs; + /** @param Optional|BSONArray|PackedArray|ResolvesToArray|array $initArgs Arguments passed to the init function. */ + public Optional|PackedArray|ResolvesToArray|BSONArray|array $initArgs; /** @param Optional|non-empty-string $finalize Function used to update the result of the accumulation. */ public Optional|string $finalize; @@ -51,7 +50,7 @@ class AccumulatorAggregation implements AccumulatorInterface * @param BSONArray|PackedArray|ResolvesToArray|array $accumulateArgs Arguments passed to the accumulate function. You can use accumulateArgs to specify what field value(s) to pass to the accumulate function. * @param non-empty-string $merge 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. * @param non-empty-string $lang The language used in the $accumulator code. - * @param BSONArray|Optional|PackedArray|ResolvesToArray|array $initArgs Arguments passed to the init function. + * @param Optional|BSONArray|PackedArray|ResolvesToArray|array $initArgs Arguments passed to the init function. * @param Optional|non-empty-string $finalize Function used to update the result of the accumulation. */ public function __construct( @@ -60,7 +59,7 @@ public function __construct( PackedArray|ResolvesToArray|BSONArray|array $accumulateArgs, string $merge, string $lang, - PackedArray|ResolvesToArray|Optional|BSONArray|array $initArgs = Optional::Undefined, + Optional|PackedArray|ResolvesToArray|BSONArray|array $initArgs = Optional::Undefined, Optional|string $finalize = Optional::Undefined, ) { $this->init = $init; diff --git a/src/Builder/Expression/AcosOperator.php b/src/Builder/Expression/AcosOperator.php new file mode 100644 index 000000000..3fb473c55 --- /dev/null +++ b/src/Builder/Expression/AcosOperator.php @@ -0,0 +1,39 @@ +expression = $expression; + } +} diff --git a/src/Builder/Expression/AcoshOperator.php b/src/Builder/Expression/AcoshOperator.php new file mode 100644 index 000000000..f9416a600 --- /dev/null +++ b/src/Builder/Expression/AcoshOperator.php @@ -0,0 +1,39 @@ +expression = $expression; + } +} diff --git a/src/Builder/Aggregation/AddAggregation.php b/src/Builder/Expression/AddOperator.php similarity index 50% rename from src/Builder/Aggregation/AddAggregation.php rename to src/Builder/Expression/AddOperator.php index 9d7a86223..c5b0a7193 100644 --- a/src/Builder/Aggregation/AddAggregation.php +++ b/src/Builder/Expression/AddOperator.php @@ -4,38 +4,32 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Decimal128; use MongoDB\BSON\Int64; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToDate; -use MongoDB\Builder\Expression\ResolvesToDecimal; -use MongoDB\Builder\Expression\ResolvesToDouble; -use MongoDB\Builder\Expression\ResolvesToInt; -use MongoDB\Builder\Expression\ResolvesToLong; -use MongoDB\Builder\Expression\ResolvesToNumber; /** * 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. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/add/ */ -class AddAggregation implements ResolvesToNumber, ResolvesToDate +class AddOperator implements ResolvesToNumber, ResolvesToDate { public const NAME = '$add'; public const ENCODE = \MongoDB\Builder\Encode::Array; - /** @param list ...$expression The arguments can be any valid expression as long as they resolve to either all numbers or to numbers and a date. */ + /** @param list ...$expression The arguments can be any valid expression as long as they resolve to either all numbers or to numbers and a date. */ public array $expression; /** - * @param Decimal128|Int64|ResolvesToDate|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|UTCDateTime|float|int ...$expression The arguments can be any valid expression as long as they resolve to either all numbers or to numbers and a date. + * @param Decimal128|Int64|ResolvesToDate|ResolvesToInt|ResolvesToNumber|UTCDateTime|float|int ...$expression The arguments can be any valid expression as long as they resolve to either all numbers or to numbers and a date. * @no-named-arguments */ public function __construct( - Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int ...$expression, + Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToInt|ResolvesToNumber|float|int ...$expression, ) { if (\count($expression) < 1) { throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); diff --git a/src/Builder/Expression/AddToSetOperator.php b/src/Builder/Expression/AddToSetOperator.php new file mode 100644 index 000000000..a92dc302e --- /dev/null +++ b/src/Builder/Expression/AddToSetOperator.php @@ -0,0 +1,48 @@ +expression = $expression; + } +} diff --git a/src/Builder/Aggregation/AllElementsTrueAggregation.php b/src/Builder/Expression/AllElementsTrueOperator.php similarity index 86% rename from src/Builder/Aggregation/AllElementsTrueAggregation.php rename to src/Builder/Expression/AllElementsTrueOperator.php index 8e319cf6f..1147e4c85 100644 --- a/src/Builder/Aggregation/AllElementsTrueAggregation.php +++ b/src/Builder/Expression/AllElementsTrueOperator.php @@ -4,12 +4,10 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\PackedArray; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToArray; -use MongoDB\Builder\Expression\ResolvesToBool; use MongoDB\Model\BSONArray; /** @@ -17,7 +15,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/allElementsTrue/ */ -class AllElementsTrueAggregation implements ResolvesToBool +class AllElementsTrueOperator implements ResolvesToBool { public const NAME = '$allElementsTrue'; public const ENCODE = \MongoDB\Builder\Encode::Array; diff --git a/src/Builder/Expression/AndOperator.php b/src/Builder/Expression/AndOperator.php new file mode 100644 index 000000000..474557b0a --- /dev/null +++ b/src/Builder/Expression/AndOperator.php @@ -0,0 +1,52 @@ + ...$expression */ + public array $expression; + + /** + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToBool|ResolvesToInt|ResolvesToNull|ResolvesToNumber|ResolvesToString|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass ...$expression + * @no-named-arguments + */ + public function __construct( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToBool|ResolvesToInt|ResolvesToNull|ResolvesToNumber|ResolvesToString|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string ...$expression, + ) { + if (\count($expression) < 1) { + throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); + } + if (! \array_is_list($expression)) { + throw new \InvalidArgumentException('Expected $expression arguments to be a list (array), named arguments are not supported'); + } + $this->expression = $expression; + } +} diff --git a/src/Builder/Aggregation/AnyElementTrueAggregation.php b/src/Builder/Expression/AnyElementTrueOperator.php similarity index 84% rename from src/Builder/Aggregation/AnyElementTrueAggregation.php rename to src/Builder/Expression/AnyElementTrueOperator.php index e7b865fbf..6869661ef 100644 --- a/src/Builder/Aggregation/AnyElementTrueAggregation.php +++ b/src/Builder/Expression/AnyElementTrueOperator.php @@ -4,12 +4,10 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\PackedArray; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToArray; -use MongoDB\Builder\Expression\ResolvesToBool; use MongoDB\Model\BSONArray; /** @@ -17,7 +15,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/anyElementTrue/ */ -class AnyElementTrueAggregation implements ResolvesToBool +class AnyElementTrueOperator implements ResolvesToBool { public const NAME = '$anyElementTrue'; public const ENCODE = \MongoDB\Builder\Encode::Array; diff --git a/src/Builder/Aggregation/ArrayElemAtAggregation.php b/src/Builder/Expression/ArrayElemAtOperator.php similarity index 82% rename from src/Builder/Aggregation/ArrayElemAtAggregation.php rename to src/Builder/Expression/ArrayElemAtOperator.php index 0f6aa3283..1ae7c6e67 100644 --- a/src/Builder/Aggregation/ArrayElemAtAggregation.php +++ b/src/Builder/Expression/ArrayElemAtOperator.php @@ -4,13 +4,10 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\PackedArray; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToAny; -use MongoDB\Builder\Expression\ResolvesToArray; -use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Model\BSONArray; /** @@ -18,7 +15,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/arrayElemAt/ */ -class ArrayElemAtAggregation implements ResolvesToAny +class ArrayElemAtOperator implements ResolvesToAny { public const NAME = '$arrayElemAt'; public const ENCODE = \MongoDB\Builder\Encode::Array; diff --git a/src/Builder/Aggregation/ArrayToObjectAggregation.php b/src/Builder/Expression/ArrayToObjectOperator.php similarity index 83% rename from src/Builder/Aggregation/ArrayToObjectAggregation.php rename to src/Builder/Expression/ArrayToObjectOperator.php index f41762d97..6ba1f4229 100644 --- a/src/Builder/Aggregation/ArrayToObjectAggregation.php +++ b/src/Builder/Expression/ArrayToObjectOperator.php @@ -4,12 +4,10 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\PackedArray; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToArray; -use MongoDB\Builder\Expression\ResolvesToObject; use MongoDB\Model\BSONArray; /** @@ -17,7 +15,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/arrayToObject/ */ -class ArrayToObjectAggregation implements ResolvesToObject +class ArrayToObjectOperator implements ResolvesToObject { public const NAME = '$arrayToObject'; public const ENCODE = \MongoDB\Builder\Encode::Array; diff --git a/src/Builder/Expression/AsinOperator.php b/src/Builder/Expression/AsinOperator.php new file mode 100644 index 000000000..2a3954781 --- /dev/null +++ b/src/Builder/Expression/AsinOperator.php @@ -0,0 +1,39 @@ +expression = $expression; + } +} diff --git a/src/Builder/Aggregation/AsinhAggregation.php b/src/Builder/Expression/AsinhOperator.php similarity index 51% rename from src/Builder/Aggregation/AsinhAggregation.php rename to src/Builder/Expression/AsinhOperator.php index 1524098e3..ffa0acdae 100644 --- a/src/Builder/Aggregation/AsinhAggregation.php +++ b/src/Builder/Expression/AsinhOperator.php @@ -4,42 +4,36 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Decimal128; use MongoDB\BSON\Int64; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToDecimal; -use MongoDB\Builder\Expression\ResolvesToDouble; -use MongoDB\Builder\Expression\ResolvesToInt; -use MongoDB\Builder\Expression\ResolvesToLong; -use MongoDB\Builder\Expression\ResolvesToNumber; /** * Returns the inverse hyperbolic sine (hyperbolic arc sine) of a value in radians. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/asinh/ */ -class AsinhAggregation implements ResolvesToDouble, ResolvesToDecimal +class AsinhOperator implements ResolvesToDouble, ResolvesToDecimal { public const NAME = '$asinh'; public const ENCODE = \MongoDB\Builder\Encode::Single; /** - * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression $asinh takes any valid expression that resolves to a number. + * @param Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $expression $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. */ - public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression; + public Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $expression; /** - * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression $asinh takes any valid expression that resolves to a number. + * @param Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $expression $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. */ - public function __construct( - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression, - ) { + public function __construct(Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $expression) + { $this->expression = $expression; } } diff --git a/src/Builder/Expression/Atan2Operator.php b/src/Builder/Expression/Atan2Operator.php new file mode 100644 index 000000000..8b9ab913d --- /dev/null +++ b/src/Builder/Expression/Atan2Operator.php @@ -0,0 +1,46 @@ +y = $y; + $this->x = $x; + } +} diff --git a/src/Builder/Aggregation/AtanAggregation.php b/src/Builder/Expression/AtanOperator.php similarity index 50% rename from src/Builder/Aggregation/AtanAggregation.php rename to src/Builder/Expression/AtanOperator.php index 4f5478282..a7659801e 100644 --- a/src/Builder/Aggregation/AtanAggregation.php +++ b/src/Builder/Expression/AtanOperator.php @@ -4,42 +4,36 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Decimal128; use MongoDB\BSON\Int64; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToDecimal; -use MongoDB\Builder\Expression\ResolvesToDouble; -use MongoDB\Builder\Expression\ResolvesToInt; -use MongoDB\Builder\Expression\ResolvesToLong; -use MongoDB\Builder\Expression\ResolvesToNumber; /** * Returns the inverse tangent (arc tangent) of a value in radians. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/atan/ */ -class AtanAggregation implements ResolvesToDouble, ResolvesToDecimal +class AtanOperator implements ResolvesToDouble, ResolvesToDecimal { public const NAME = '$atan'; public const ENCODE = \MongoDB\Builder\Encode::Single; /** - * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression $atan takes any valid expression that resolves to a number. + * @param Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $expression $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. */ - public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression; + public Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $expression; /** - * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression $atan takes any valid expression that resolves to a number. + * @param Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $expression $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. */ - public function __construct( - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression, - ) { + public function __construct(Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $expression) + { $this->expression = $expression; } } diff --git a/src/Builder/Expression/AtanhOperator.php b/src/Builder/Expression/AtanhOperator.php new file mode 100644 index 000000000..9b63cb50a --- /dev/null +++ b/src/Builder/Expression/AtanhOperator.php @@ -0,0 +1,39 @@ +expression = $expression; + } +} diff --git a/src/Builder/Aggregation/AvgAggregation.php b/src/Builder/Expression/AvgOperator.php similarity index 56% rename from src/Builder/Aggregation/AvgAggregation.php rename to src/Builder/Expression/AvgOperator.php index 0a1812765..8b58485f9 100644 --- a/src/Builder/Aggregation/AvgAggregation.php +++ b/src/Builder/Expression/AvgOperator.php @@ -4,17 +4,13 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Decimal128; use MongoDB\BSON\Int64; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToDecimal; -use MongoDB\Builder\Expression\ResolvesToDouble; -use MongoDB\Builder\Expression\ResolvesToInt; -use MongoDB\Builder\Expression\ResolvesToLong; -use MongoDB\Builder\Expression\ResolvesToNumber; use MongoDB\Builder\Type\AccumulatorInterface; +use MongoDB\Builder\Type\WindowInterface; /** * Returns an average of numerical values. Ignores non-numeric values. @@ -22,21 +18,20 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/avg/ */ -class AvgAggregation implements ResolvesToNumber, AccumulatorInterface +class AvgOperator implements ResolvesToNumber, AccumulatorInterface, WindowInterface { public const NAME = '$avg'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param list ...$expression */ + /** @param list ...$expression */ public array $expression; /** - * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int ...$expression + * @param Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int ...$expression * @no-named-arguments */ - public function __construct( - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int ...$expression, - ) { + public function __construct(Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int ...$expression) + { if (\count($expression) < 1) { throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); } diff --git a/src/Builder/Aggregation/BinarySizeAggregation.php b/src/Builder/Expression/BinarySizeOperator.php similarity index 76% rename from src/Builder/Aggregation/BinarySizeAggregation.php rename to src/Builder/Expression/BinarySizeOperator.php index 43c7d2aea..cdbba5ff0 100644 --- a/src/Builder/Aggregation/BinarySizeAggregation.php +++ b/src/Builder/Expression/BinarySizeOperator.php @@ -4,21 +4,17 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Binary; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToBinData; -use MongoDB\Builder\Expression\ResolvesToInt; -use MongoDB\Builder\Expression\ResolvesToNull; -use MongoDB\Builder\Expression\ResolvesToString; /** * Returns the size of a given string or binary data value's content in bytes. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/binarySize/ */ -class BinarySizeAggregation implements ResolvesToInt +class BinarySizeOperator implements ResolvesToInt { public const NAME = '$binarySize'; public const ENCODE = \MongoDB\Builder\Encode::Single; diff --git a/src/Builder/Aggregation/BitAndAggregation.php b/src/Builder/Expression/BitAndOperator.php similarity index 85% rename from src/Builder/Aggregation/BitAndAggregation.php rename to src/Builder/Expression/BitAndOperator.php index 97e448af4..62baeee97 100644 --- a/src/Builder/Aggregation/BitAndAggregation.php +++ b/src/Builder/Expression/BitAndOperator.php @@ -4,12 +4,10 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Int64; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToInt; -use MongoDB\Builder\Expression\ResolvesToLong; /** * Returns the result of a bitwise and operation on an array of int or long values. @@ -17,7 +15,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitAnd/ */ -class BitAndAggregation implements ResolvesToInt, ResolvesToLong +class BitAndOperator implements ResolvesToInt, ResolvesToLong { public const NAME = '$bitAnd'; public const ENCODE = \MongoDB\Builder\Encode::Single; diff --git a/src/Builder/Aggregation/BitNotAggregation.php b/src/Builder/Expression/BitNotOperator.php similarity index 80% rename from src/Builder/Aggregation/BitNotAggregation.php rename to src/Builder/Expression/BitNotOperator.php index 8997c25bf..65165ff98 100644 --- a/src/Builder/Aggregation/BitNotAggregation.php +++ b/src/Builder/Expression/BitNotOperator.php @@ -4,12 +4,10 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Int64; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToInt; -use MongoDB\Builder\Expression\ResolvesToLong; /** * Returns the result of a bitwise not operation on a single argument or an array that contains a single int or long value. @@ -17,7 +15,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitNot/ */ -class BitNotAggregation implements ResolvesToInt, ResolvesToLong +class BitNotOperator implements ResolvesToInt, ResolvesToLong { public const NAME = '$bitNot'; public const ENCODE = \MongoDB\Builder\Encode::Single; diff --git a/src/Builder/Aggregation/BitOrAggregation.php b/src/Builder/Expression/BitOrOperator.php similarity index 85% rename from src/Builder/Aggregation/BitOrAggregation.php rename to src/Builder/Expression/BitOrOperator.php index 85a5b7457..942700944 100644 --- a/src/Builder/Aggregation/BitOrAggregation.php +++ b/src/Builder/Expression/BitOrOperator.php @@ -4,12 +4,10 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Int64; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToInt; -use MongoDB\Builder\Expression\ResolvesToLong; /** * Returns the result of a bitwise or operation on an array of int or long values. @@ -17,7 +15,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitOr/ */ -class BitOrAggregation implements ResolvesToInt, ResolvesToLong +class BitOrOperator implements ResolvesToInt, ResolvesToLong { public const NAME = '$bitOr'; public const ENCODE = \MongoDB\Builder\Encode::Single; diff --git a/src/Builder/Aggregation/BitXorAggregation.php b/src/Builder/Expression/BitXorOperator.php similarity index 85% rename from src/Builder/Aggregation/BitXorAggregation.php rename to src/Builder/Expression/BitXorOperator.php index f91c70e39..17009981d 100644 --- a/src/Builder/Aggregation/BitXorAggregation.php +++ b/src/Builder/Expression/BitXorOperator.php @@ -4,12 +4,10 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Int64; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToInt; -use MongoDB\Builder\Expression\ResolvesToLong; /** * Returns the result of a bitwise xor (exclusive or) operation on an array of int and long values. @@ -17,7 +15,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitXor/ */ -class BitXorAggregation implements ResolvesToInt, ResolvesToLong +class BitXorOperator implements ResolvesToInt, ResolvesToLong { public const NAME = '$bitXor'; public const ENCODE = \MongoDB\Builder\Encode::Single; diff --git a/src/Builder/Aggregation/BottomNAggregation.php b/src/Builder/Expression/BottomNOperator.php similarity index 89% rename from src/Builder/Aggregation/BottomNAggregation.php rename to src/Builder/Expression/BottomNOperator.php index d72a394b7..c31c4b8e0 100644 --- a/src/Builder/Aggregation/BottomNAggregation.php +++ b/src/Builder/Expression/BottomNOperator.php @@ -4,7 +4,7 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Binary; use MongoDB\BSON\Decimal128; @@ -17,9 +17,9 @@ use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Type\AccumulatorInterface; use MongoDB\Builder\Type\ExpressionInterface; +use MongoDB\Builder\Type\WindowInterface; use MongoDB\Model\BSONArray; use stdClass; @@ -30,7 +30,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/bottomN/ */ -class BottomNAggregation implements AccumulatorInterface +class BottomNOperator implements AccumulatorInterface, WindowInterface { public const NAME = '$bottomN'; public const ENCODE = \MongoDB\Builder\Encode::Object; @@ -56,10 +56,6 @@ public function __construct( ) { $this->n = $n; $this->sortBy = $sortBy; - if (\is_array($output) && ! \array_is_list($output)) { - throw new \InvalidArgumentException('Expected $output argument to be a list, got an associative array.'); - } - $this->output = $output; } } diff --git a/src/Builder/Aggregation/BottomAggregation.php b/src/Builder/Expression/BottomOperator.php similarity index 87% rename from src/Builder/Aggregation/BottomAggregation.php rename to src/Builder/Expression/BottomOperator.php index dd0ee23cb..d273df440 100644 --- a/src/Builder/Aggregation/BottomAggregation.php +++ b/src/Builder/Expression/BottomOperator.php @@ -4,7 +4,7 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Binary; use MongoDB\BSON\Decimal128; @@ -17,9 +17,9 @@ use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Type\AccumulatorInterface; use MongoDB\Builder\Type\ExpressionInterface; +use MongoDB\Builder\Type\WindowInterface; use MongoDB\Model\BSONArray; use stdClass; @@ -31,7 +31,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/bottom/ */ -class BottomAggregation implements AccumulatorInterface +class BottomOperator implements AccumulatorInterface, WindowInterface { public const NAME = '$bottom'; public const ENCODE = \MongoDB\Builder\Encode::Object; @@ -51,10 +51,6 @@ public function __construct( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $output, ) { $this->sortBy = $sortBy; - if (\is_array($output) && ! \array_is_list($output)) { - throw new \InvalidArgumentException('Expected $output argument to be a list, got an associative array.'); - } - $this->output = $output; } } diff --git a/src/Builder/Aggregation/BsonSizeAggregation.php b/src/Builder/Expression/BsonSizeOperator.php similarity index 80% rename from src/Builder/Aggregation/BsonSizeAggregation.php rename to src/Builder/Expression/BsonSizeOperator.php index a4bdc9407..b228941f2 100644 --- a/src/Builder/Aggregation/BsonSizeAggregation.php +++ b/src/Builder/Expression/BsonSizeOperator.php @@ -4,14 +4,11 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Document; use MongoDB\BSON\Serializable; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToInt; -use MongoDB\Builder\Expression\ResolvesToNull; -use MongoDB\Builder\Expression\ResolvesToObject; use stdClass; /** @@ -19,7 +16,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/bsonSize/ */ -class BsonSizeAggregation implements ResolvesToInt +class BsonSizeOperator implements ResolvesToInt { public const NAME = '$bsonSize'; public const ENCODE = \MongoDB\Builder\Encode::Single; diff --git a/src/Builder/Expression/CeilOperator.php b/src/Builder/Expression/CeilOperator.php new file mode 100644 index 000000000..0b0653e4e --- /dev/null +++ b/src/Builder/Expression/CeilOperator.php @@ -0,0 +1,33 @@ +expression = $expression; + } +} diff --git a/src/Builder/Aggregation/CmpAggregation.php b/src/Builder/Expression/CmpOperator.php similarity index 82% rename from src/Builder/Aggregation/CmpAggregation.php rename to src/Builder/Expression/CmpOperator.php index 9424f79e1..2da7cd5e9 100644 --- a/src/Builder/Aggregation/CmpAggregation.php +++ b/src/Builder/Expression/CmpOperator.php @@ -4,7 +4,7 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Binary; use MongoDB\BSON\Decimal128; @@ -17,7 +17,6 @@ use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Type\ExpressionInterface; use MongoDB\Model\BSONArray; use stdClass; @@ -27,7 +26,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/cmp/ */ -class CmpAggregation implements ResolvesToInt +class CmpOperator implements ResolvesToInt { public const NAME = '$cmp'; public const ENCODE = \MongoDB\Builder\Encode::Array; @@ -46,15 +45,7 @@ public function __construct( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression1, Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression2, ) { - if (\is_array($expression1) && ! \array_is_list($expression1)) { - throw new \InvalidArgumentException('Expected $expression1 argument to be a list, got an associative array.'); - } - $this->expression1 = $expression1; - if (\is_array($expression2) && ! \array_is_list($expression2)) { - throw new \InvalidArgumentException('Expected $expression2 argument to be a list, got an associative array.'); - } - $this->expression2 = $expression2; } } diff --git a/src/Builder/Aggregation/ConcatArraysAggregation.php b/src/Builder/Expression/ConcatArraysOperator.php similarity index 88% rename from src/Builder/Aggregation/ConcatArraysAggregation.php rename to src/Builder/Expression/ConcatArraysOperator.php index d9ae07521..cff1d85f2 100644 --- a/src/Builder/Aggregation/ConcatArraysAggregation.php +++ b/src/Builder/Expression/ConcatArraysOperator.php @@ -4,11 +4,10 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\PackedArray; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToArray; use MongoDB\Model\BSONArray; /** @@ -16,7 +15,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/concatArrays/ */ -class ConcatArraysAggregation implements ResolvesToArray +class ConcatArraysOperator implements ResolvesToArray { public const NAME = '$concatArrays'; public const ENCODE = \MongoDB\Builder\Encode::Single; diff --git a/src/Builder/Aggregation/ConcatAggregation.php b/src/Builder/Expression/ConcatOperator.php similarity index 88% rename from src/Builder/Aggregation/ConcatAggregation.php rename to src/Builder/Expression/ConcatOperator.php index dbab898c7..2030f75a9 100644 --- a/src/Builder/Aggregation/ConcatAggregation.php +++ b/src/Builder/Expression/ConcatOperator.php @@ -4,17 +4,16 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToString; /** * Concatenates any number of strings. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/concat/ */ -class ConcatAggregation implements ResolvesToString +class ConcatOperator implements ResolvesToString { public const NAME = '$concat'; public const ENCODE = \MongoDB\Builder\Encode::Single; diff --git a/src/Builder/Aggregation/CondAggregation.php b/src/Builder/Expression/CondOperator.php similarity index 82% rename from src/Builder/Aggregation/CondAggregation.php rename to src/Builder/Expression/CondOperator.php index 36b616160..94fc58ba1 100644 --- a/src/Builder/Aggregation/CondAggregation.php +++ b/src/Builder/Expression/CondOperator.php @@ -4,7 +4,7 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Binary; use MongoDB\BSON\Decimal128; @@ -17,9 +17,6 @@ use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToAny; -use MongoDB\Builder\Expression\ResolvesToBool; -use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Type\ExpressionInterface; use MongoDB\Model\BSONArray; use stdClass; @@ -29,7 +26,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/cond/ */ -class CondAggregation implements ResolvesToAny +class CondOperator implements ResolvesToAny { public const NAME = '$cond'; public const ENCODE = \MongoDB\Builder\Encode::Object; @@ -54,15 +51,7 @@ public function __construct( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $else, ) { $this->if = $if; - if (\is_array($then) && ! \array_is_list($then)) { - throw new \InvalidArgumentException('Expected $then argument to be a list, got an associative array.'); - } - $this->then = $then; - if (\is_array($else) && ! \array_is_list($else)) { - throw new \InvalidArgumentException('Expected $else argument to be a list, got an associative array.'); - } - $this->else = $else; } } diff --git a/src/Builder/Aggregation/ConvertAggregation.php b/src/Builder/Expression/ConvertOperator.php similarity index 66% rename from src/Builder/Aggregation/ConvertAggregation.php rename to src/Builder/Expression/ConvertOperator.php index 4ca5881dd..ab5c88ada 100644 --- a/src/Builder/Aggregation/ConvertAggregation.php +++ b/src/Builder/Expression/ConvertOperator.php @@ -4,7 +4,7 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Binary; use MongoDB\BSON\Decimal128; @@ -17,9 +17,6 @@ use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToAny; -use MongoDB\Builder\Expression\ResolvesToInt; -use MongoDB\Builder\Expression\ResolvesToString; use MongoDB\Builder\Optional; use MongoDB\Builder\Type\ExpressionInterface; use MongoDB\Model\BSONArray; @@ -31,7 +28,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/convert/ */ -class ConvertAggregation implements ResolvesToAny +class ConvertOperator implements ResolvesToAny { public const NAME = '$convert'; public const ENCODE = \MongoDB\Builder\Encode::Object; @@ -43,46 +40,34 @@ class ConvertAggregation implements ResolvesToAny public ResolvesToInt|ResolvesToString|int|string $to; /** - * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|Optional|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $onError The value to return on encountering an error during conversion, including unsupported type conversions. The arguments can be any valid expression. + * @param Optional|BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $onError 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. */ - public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|Optional|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $onError; + public Optional|Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $onError; /** - * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|Optional|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $onNull The value to return if the input is null or missing. The arguments can be any valid expression. + * @param Optional|BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $onNull 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. */ - public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|Optional|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $onNull; + public Optional|Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $onNull; /** * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $input * @param ResolvesToInt|ResolvesToString|int|non-empty-string $to - * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|Optional|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $onError The value to return on encountering an error during conversion, including unsupported type conversions. The arguments can be any valid expression. + * @param Optional|BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $onError 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. - * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|Optional|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $onNull The value to return if the input is null or missing. The arguments can be any valid expression. + * @param Optional|BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $onNull 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. */ public function __construct( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $input, ResolvesToInt|ResolvesToString|int|string $to, - Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|Optional|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $onError = Optional::Undefined, - Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|Optional|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $onNull = Optional::Undefined, + Optional|Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $onError = Optional::Undefined, + Optional|Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $onNull = Optional::Undefined, ) { - if (\is_array($input) && ! \array_is_list($input)) { - throw new \InvalidArgumentException('Expected $input argument to be a list, got an associative array.'); - } - $this->input = $input; $this->to = $to; - if (\is_array($onError) && ! \array_is_list($onError)) { - throw new \InvalidArgumentException('Expected $onError argument to be a list, got an associative array.'); - } - $this->onError = $onError; - if (\is_array($onNull) && ! \array_is_list($onNull)) { - throw new \InvalidArgumentException('Expected $onNull argument to be a list, got an associative array.'); - } - $this->onNull = $onNull; } } diff --git a/src/Builder/Expression/CosOperator.php b/src/Builder/Expression/CosOperator.php new file mode 100644 index 000000000..c45a2d319 --- /dev/null +++ b/src/Builder/Expression/CosOperator.php @@ -0,0 +1,37 @@ + resolves to a 128-bit decimal value. + */ + public Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $expression; + + /** + * @param Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $expression $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. + */ + public function __construct(Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $expression) + { + $this->expression = $expression; + } +} diff --git a/src/Builder/Expression/CoshOperator.php b/src/Builder/Expression/CoshOperator.php new file mode 100644 index 000000000..594356eaa --- /dev/null +++ b/src/Builder/Expression/CoshOperator.php @@ -0,0 +1,37 @@ + resolves to a 128-bit decimal value. + */ + public Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $expression; + + /** + * @param Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $expression $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. + */ + public function __construct(Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $expression) + { + $this->expression = $expression; + } +} diff --git a/src/Builder/Aggregation/CountAggregation.php b/src/Builder/Expression/CountOperator.php similarity index 82% rename from src/Builder/Aggregation/CountAggregation.php rename to src/Builder/Expression/CountOperator.php index faba192a0..4b1989c3c 100644 --- a/src/Builder/Aggregation/CountAggregation.php +++ b/src/Builder/Expression/CountOperator.php @@ -4,10 +4,11 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\Builder\Encode; use MongoDB\Builder\Type\AccumulatorInterface; +use MongoDB\Builder\Type\WindowInterface; /** * Returns the number of documents in the group or window. @@ -16,7 +17,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/count/ */ -class CountAggregation implements AccumulatorInterface +class CountOperator implements AccumulatorInterface, WindowInterface { public const NAME = '$count'; public const ENCODE = \MongoDB\Builder\Encode::Object; diff --git a/src/Builder/Expression/CovariancePopOperator.php b/src/Builder/Expression/CovariancePopOperator.php new file mode 100644 index 000000000..257d23a24 --- /dev/null +++ b/src/Builder/Expression/CovariancePopOperator.php @@ -0,0 +1,42 @@ +expression1 = $expression1; + $this->expression2 = $expression2; + } +} diff --git a/src/Builder/Expression/CovarianceSampOperator.php b/src/Builder/Expression/CovarianceSampOperator.php new file mode 100644 index 000000000..c6e8540da --- /dev/null +++ b/src/Builder/Expression/CovarianceSampOperator.php @@ -0,0 +1,42 @@ +expression1 = $expression1; + $this->expression2 = $expression2; + } +} diff --git a/src/Builder/Aggregation/DateAddAggregation.php b/src/Builder/Expression/DateAddOperator.php similarity index 83% rename from src/Builder/Aggregation/DateAddAggregation.php rename to src/Builder/Expression/DateAddOperator.php index 3a252034a..97471b357 100644 --- a/src/Builder/Aggregation/DateAddAggregation.php +++ b/src/Builder/Expression/DateAddOperator.php @@ -4,19 +4,13 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Int64; use MongoDB\BSON\ObjectId; use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToDate; -use MongoDB\Builder\Expression\ResolvesToInt; -use MongoDB\Builder\Expression\ResolvesToLong; -use MongoDB\Builder\Expression\ResolvesToObjectId; -use MongoDB\Builder\Expression\ResolvesToString; -use MongoDB\Builder\Expression\ResolvesToTimestamp; use MongoDB\Builder\Optional; /** @@ -24,7 +18,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateAdd/ */ -class DateAddAggregation implements ResolvesToDate +class DateAddOperator implements ResolvesToDate { public const NAME = '$dateAdd'; public const ENCODE = \MongoDB\Builder\Encode::Object; @@ -39,7 +33,7 @@ class DateAddAggregation implements ResolvesToDate public Int64|ResolvesToInt|ResolvesToLong|int $amount; /** @param Optional|ResolvesToString|non-empty-string $timezone 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. */ - public ResolvesToString|Optional|string $timezone; + public Optional|ResolvesToString|string $timezone; /** * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $startDate 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. @@ -51,7 +45,7 @@ public function __construct( ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $startDate, ResolvesToString|string $unit, Int64|ResolvesToInt|ResolvesToLong|int $amount, - ResolvesToString|Optional|string $timezone = Optional::Undefined, + Optional|ResolvesToString|string $timezone = Optional::Undefined, ) { $this->startDate = $startDate; $this->unit = $unit; diff --git a/src/Builder/Aggregation/DateDiffAggregation.php b/src/Builder/Expression/DateDiffOperator.php similarity index 85% rename from src/Builder/Aggregation/DateDiffAggregation.php rename to src/Builder/Expression/DateDiffOperator.php index a5cb077a2..bf42540aa 100644 --- a/src/Builder/Aggregation/DateDiffAggregation.php +++ b/src/Builder/Expression/DateDiffOperator.php @@ -4,17 +4,12 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\ObjectId; use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToDate; -use MongoDB\Builder\Expression\ResolvesToInt; -use MongoDB\Builder\Expression\ResolvesToObjectId; -use MongoDB\Builder\Expression\ResolvesToString; -use MongoDB\Builder\Expression\ResolvesToTimestamp; use MongoDB\Builder\Optional; /** @@ -22,7 +17,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateDiff/ */ -class DateDiffAggregation implements ResolvesToInt +class DateDiffOperator implements ResolvesToInt { public const NAME = '$dateDiff'; public const ENCODE = \MongoDB\Builder\Encode::Object; @@ -37,10 +32,10 @@ class DateDiffAggregation implements ResolvesToInt public ResolvesToString|string $unit; /** @param Optional|ResolvesToString|non-empty-string $timezone 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. */ - public ResolvesToString|Optional|string $timezone; + public Optional|ResolvesToString|string $timezone; /** @param Optional|ResolvesToString|non-empty-string $startOfWeek Used when the unit is equal to week. Defaults to Sunday. The startOfWeek parameter is an expression that resolves to a case insensitive string */ - public ResolvesToString|Optional|string $startOfWeek; + public Optional|ResolvesToString|string $startOfWeek; /** * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $startDate The start of the time period. The startDate can be any expression that resolves to a Date, a Timestamp, or an ObjectID. @@ -53,8 +48,8 @@ public function __construct( ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $startDate, ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $endDate, ResolvesToString|string $unit, - ResolvesToString|Optional|string $timezone = Optional::Undefined, - ResolvesToString|Optional|string $startOfWeek = Optional::Undefined, + Optional|ResolvesToString|string $timezone = Optional::Undefined, + Optional|ResolvesToString|string $startOfWeek = Optional::Undefined, ) { $this->startDate = $startDate; $this->endDate = $endDate; diff --git a/src/Builder/Expression/DateFromPartsOperator.php b/src/Builder/Expression/DateFromPartsOperator.php new file mode 100644 index 000000000..2f4abbcfc --- /dev/null +++ b/src/Builder/Expression/DateFromPartsOperator.php @@ -0,0 +1,95 @@ +year = $year; + $this->isoWeekYear = $isoWeekYear; + $this->month = $month; + $this->isoWeek = $isoWeek; + $this->day = $day; + $this->isoDayOfWeek = $isoDayOfWeek; + $this->hour = $hour; + $this->minute = $minute; + $this->second = $second; + $this->millisecond = $millisecond; + $this->timezone = $timezone; + } +} diff --git a/src/Builder/Aggregation/DateFromStringAggregation.php b/src/Builder/Expression/DateFromStringOperator.php similarity index 69% rename from src/Builder/Aggregation/DateFromStringAggregation.php rename to src/Builder/Expression/DateFromStringOperator.php index a36e90c27..c6f5cb8a0 100644 --- a/src/Builder/Aggregation/DateFromStringAggregation.php +++ b/src/Builder/Expression/DateFromStringOperator.php @@ -4,7 +4,7 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Binary; use MongoDB\BSON\Decimal128; @@ -17,9 +17,6 @@ use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToDate; -use MongoDB\Builder\Expression\ResolvesToInt; -use MongoDB\Builder\Expression\ResolvesToString; use MongoDB\Builder\Optional; use MongoDB\Builder\Type\ExpressionInterface; use MongoDB\Model\BSONArray; @@ -30,7 +27,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateFromString/ */ -class DateFromStringAggregation implements ResolvesToDate +class DateFromStringOperator implements ResolvesToDate { public const NAME = '$dateFromString'; public const ENCODE = \MongoDB\Builder\Encode::Object; @@ -42,52 +39,44 @@ class DateFromStringAggregation implements ResolvesToDate * @param Optional|ResolvesToString|non-empty-string $format 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. */ - public ResolvesToString|Optional|string $format; + public Optional|ResolvesToString|string $format; /** @param Optional|ResolvesToString|non-empty-string $timezone The time zone to use to format the date. */ - public ResolvesToString|Optional|string $timezone; + public Optional|ResolvesToString|string $timezone; /** - * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|Optional|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $onError 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. + * @param Optional|BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $onError 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. */ - public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|Optional|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $onError; + public Optional|Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $onError; /** - * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|Optional|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $onNull 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. + * @param Optional|BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $onNull 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. */ - public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|Optional|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $onNull; + public Optional|Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $onNull; /** * @param ResolvesToString|non-empty-string $dateString The date/time string to convert to a date object. * @param Optional|ResolvesToString|non-empty-string $format 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. * @param Optional|ResolvesToString|non-empty-string $timezone The time zone to use to format the date. - * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|Optional|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $onError 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. + * @param Optional|BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $onError 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. - * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|Optional|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $onNull 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. + * @param Optional|BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $onNull 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. */ public function __construct( ResolvesToString|string $dateString, - ResolvesToString|Optional|string $format = Optional::Undefined, - ResolvesToString|Optional|string $timezone = Optional::Undefined, - Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|Optional|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $onError = Optional::Undefined, - Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|Optional|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $onNull = Optional::Undefined, + Optional|ResolvesToString|string $format = Optional::Undefined, + Optional|ResolvesToString|string $timezone = Optional::Undefined, + Optional|Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $onError = Optional::Undefined, + Optional|Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $onNull = Optional::Undefined, ) { $this->dateString = $dateString; $this->format = $format; $this->timezone = $timezone; - if (\is_array($onError) && ! \array_is_list($onError)) { - throw new \InvalidArgumentException('Expected $onError argument to be a list, got an associative array.'); - } - $this->onError = $onError; - if (\is_array($onNull) && ! \array_is_list($onNull)) { - throw new \InvalidArgumentException('Expected $onNull argument to be a list, got an associative array.'); - } - $this->onNull = $onNull; } } diff --git a/src/Builder/Aggregation/DateSubtractAggregation.php b/src/Builder/Expression/DateSubtractOperator.php similarity index 83% rename from src/Builder/Aggregation/DateSubtractAggregation.php rename to src/Builder/Expression/DateSubtractOperator.php index 4e0a4a5df..a7b7e7c61 100644 --- a/src/Builder/Aggregation/DateSubtractAggregation.php +++ b/src/Builder/Expression/DateSubtractOperator.php @@ -4,19 +4,13 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Int64; use MongoDB\BSON\ObjectId; use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToDate; -use MongoDB\Builder\Expression\ResolvesToInt; -use MongoDB\Builder\Expression\ResolvesToLong; -use MongoDB\Builder\Expression\ResolvesToObjectId; -use MongoDB\Builder\Expression\ResolvesToString; -use MongoDB\Builder\Expression\ResolvesToTimestamp; use MongoDB\Builder\Optional; /** @@ -24,7 +18,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateSubtract/ */ -class DateSubtractAggregation implements ResolvesToDate +class DateSubtractOperator implements ResolvesToDate { public const NAME = '$dateSubtract'; public const ENCODE = \MongoDB\Builder\Encode::Object; @@ -39,7 +33,7 @@ class DateSubtractAggregation implements ResolvesToDate public Int64|ResolvesToInt|ResolvesToLong|int $amount; /** @param Optional|ResolvesToString|non-empty-string $timezone 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. */ - public ResolvesToString|Optional|string $timezone; + public Optional|ResolvesToString|string $timezone; /** * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $startDate 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. @@ -51,7 +45,7 @@ public function __construct( ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $startDate, ResolvesToString|string $unit, Int64|ResolvesToInt|ResolvesToLong|int $amount, - ResolvesToString|Optional|string $timezone = Optional::Undefined, + Optional|ResolvesToString|string $timezone = Optional::Undefined, ) { $this->startDate = $startDate; $this->unit = $unit; diff --git a/src/Builder/Aggregation/DateToPartsAggregation.php b/src/Builder/Expression/DateToPartsOperator.php similarity index 83% rename from src/Builder/Aggregation/DateToPartsAggregation.php rename to src/Builder/Expression/DateToPartsOperator.php index 4251fa0a0..476f617c4 100644 --- a/src/Builder/Aggregation/DateToPartsAggregation.php +++ b/src/Builder/Expression/DateToPartsOperator.php @@ -4,17 +4,12 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\ObjectId; use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToDate; -use MongoDB\Builder\Expression\ResolvesToObject; -use MongoDB\Builder\Expression\ResolvesToObjectId; -use MongoDB\Builder\Expression\ResolvesToString; -use MongoDB\Builder\Expression\ResolvesToTimestamp; use MongoDB\Builder\Optional; /** @@ -22,7 +17,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateToParts/ */ -class DateToPartsAggregation implements ResolvesToObject +class DateToPartsOperator implements ResolvesToObject { public const NAME = '$dateToParts'; public const ENCODE = \MongoDB\Builder\Encode::Object; @@ -31,7 +26,7 @@ class DateToPartsAggregation implements ResolvesToObject public ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; /** @param Optional|ResolvesToString|non-empty-string $timezone 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. */ - public ResolvesToString|Optional|string $timezone; + public Optional|ResolvesToString|string $timezone; /** @param Optional|bool $iso8601 If set to true, modifies the output document to use ISO week date fields. Defaults to false. */ public Optional|bool $iso8601; @@ -43,7 +38,7 @@ class DateToPartsAggregation implements ResolvesToObject */ public function __construct( ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, - ResolvesToString|Optional|string $timezone = Optional::Undefined, + Optional|ResolvesToString|string $timezone = Optional::Undefined, Optional|bool $iso8601 = Optional::Undefined, ) { $this->date = $date; diff --git a/src/Builder/Aggregation/DateToStringAggregation.php b/src/Builder/Expression/DateToStringOperator.php similarity index 72% rename from src/Builder/Aggregation/DateToStringAggregation.php rename to src/Builder/Expression/DateToStringOperator.php index 2ed63b1d1..4f1c5dc82 100644 --- a/src/Builder/Aggregation/DateToStringAggregation.php +++ b/src/Builder/Expression/DateToStringOperator.php @@ -4,7 +4,7 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Binary; use MongoDB\BSON\Decimal128; @@ -17,11 +17,6 @@ use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToDate; -use MongoDB\Builder\Expression\ResolvesToInt; -use MongoDB\Builder\Expression\ResolvesToObjectId; -use MongoDB\Builder\Expression\ResolvesToString; -use MongoDB\Builder\Expression\ResolvesToTimestamp; use MongoDB\Builder\Optional; use MongoDB\Builder\Type\ExpressionInterface; use MongoDB\Model\BSONArray; @@ -32,7 +27,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateToString/ */ -class DateToStringAggregation implements ResolvesToString +class DateToStringOperator implements ResolvesToString { public const NAME = '$dateToString'; public const ENCODE = \MongoDB\Builder\Encode::Object; @@ -44,38 +39,34 @@ class DateToStringAggregation implements ResolvesToString * @param Optional|ResolvesToString|non-empty-string $format 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. */ - public ResolvesToString|Optional|string $format; + public Optional|ResolvesToString|string $format; /** @param Optional|ResolvesToString|non-empty-string $timezone The time zone to use to format the date. */ - public ResolvesToString|Optional|string $timezone; + public Optional|ResolvesToString|string $timezone; /** - * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|Optional|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $onNull The value to return if the date is null or missing. + * @param Optional|BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $onNull The value to return if the date is null or missing. * If unspecified, $dateToString returns null if the date is null or missing. */ - public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|Optional|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $onNull; + public Optional|Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $onNull; /** * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The date to convert to string. Must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. * @param Optional|ResolvesToString|non-empty-string $format 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. * @param Optional|ResolvesToString|non-empty-string $timezone The time zone to use to format the date. - * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|Optional|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $onNull The value to return if the date is null or missing. + * @param Optional|BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $onNull The value to return if the date is null or missing. * If unspecified, $dateToString returns null if the date is null or missing. */ public function __construct( ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, - ResolvesToString|Optional|string $format = Optional::Undefined, - ResolvesToString|Optional|string $timezone = Optional::Undefined, - Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|Optional|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $onNull = Optional::Undefined, + Optional|ResolvesToString|string $format = Optional::Undefined, + Optional|ResolvesToString|string $timezone = Optional::Undefined, + Optional|Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $onNull = Optional::Undefined, ) { $this->date = $date; $this->format = $format; $this->timezone = $timezone; - if (\is_array($onNull) && ! \array_is_list($onNull)) { - throw new \InvalidArgumentException('Expected $onNull argument to be a list, got an associative array.'); - } - $this->onNull = $onNull; } } diff --git a/src/Builder/Aggregation/DateTruncAggregation.php b/src/Builder/Expression/DateTruncOperator.php similarity index 69% rename from src/Builder/Aggregation/DateTruncAggregation.php rename to src/Builder/Expression/DateTruncOperator.php index 9a5816be5..b214d15e4 100644 --- a/src/Builder/Aggregation/DateTruncAggregation.php +++ b/src/Builder/Expression/DateTruncOperator.php @@ -4,7 +4,7 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Decimal128; use MongoDB\BSON\Int64; @@ -12,15 +12,6 @@ use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToDate; -use MongoDB\Builder\Expression\ResolvesToDecimal; -use MongoDB\Builder\Expression\ResolvesToDouble; -use MongoDB\Builder\Expression\ResolvesToInt; -use MongoDB\Builder\Expression\ResolvesToLong; -use MongoDB\Builder\Expression\ResolvesToNumber; -use MongoDB\Builder\Expression\ResolvesToObjectId; -use MongoDB\Builder\Expression\ResolvesToString; -use MongoDB\Builder\Expression\ResolvesToTimestamp; use MongoDB\Builder\Optional; /** @@ -28,7 +19,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateTrunc/ */ -class DateTruncAggregation implements ResolvesToDate +class DateTruncOperator implements ResolvesToDate { public const NAME = '$dateTrunc'; public const ENCODE = \MongoDB\Builder\Encode::Object; @@ -43,13 +34,13 @@ class DateTruncAggregation implements ResolvesToDate public ResolvesToString|string $unit; /** - * @param Decimal128|Int64|Optional|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $binSize The numeric time value, specified as an expression that must resolve to a positive non-zero number. Defaults to 1. + * @param Optional|Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $binSize 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. */ - public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|Optional|float|int $binSize; + public Optional|Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $binSize; /** @param Optional|ResolvesToString|non-empty-string $timezone 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. */ - public ResolvesToString|Optional|string $timezone; + public Optional|ResolvesToString|string $timezone; /** * @param Optional|non-empty-string $startOfWeek The start of the week. Used when @@ -61,7 +52,7 @@ class DateTruncAggregation implements ResolvesToDate * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The date to truncate, specified in UTC. The date can be any expression that resolves to a Date, a Timestamp, or an ObjectID. * @param ResolvesToString|non-empty-string $unit 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. - * @param Decimal128|Int64|Optional|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $binSize The numeric time value, specified as an expression that must resolve to a positive non-zero number. Defaults to 1. + * @param Optional|Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $binSize 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. * @param Optional|ResolvesToString|non-empty-string $timezone 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. * @param Optional|non-empty-string $startOfWeek The start of the week. Used when @@ -70,8 +61,8 @@ class DateTruncAggregation implements ResolvesToDate public function __construct( ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|string $unit, - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|Optional|float|int $binSize = Optional::Undefined, - ResolvesToString|Optional|string $timezone = Optional::Undefined, + Optional|Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $binSize = Optional::Undefined, + Optional|ResolvesToString|string $timezone = Optional::Undefined, Optional|string $startOfWeek = Optional::Undefined, ) { $this->date = $date; diff --git a/src/Builder/Aggregation/DayOfMonthAggregation.php b/src/Builder/Expression/DayOfMonthOperator.php similarity index 80% rename from src/Builder/Aggregation/DayOfMonthAggregation.php rename to src/Builder/Expression/DayOfMonthOperator.php index 600cb743b..0de7add0c 100644 --- a/src/Builder/Aggregation/DayOfMonthAggregation.php +++ b/src/Builder/Expression/DayOfMonthOperator.php @@ -4,17 +4,12 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\ObjectId; use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToDate; -use MongoDB\Builder\Expression\ResolvesToInt; -use MongoDB\Builder\Expression\ResolvesToObjectId; -use MongoDB\Builder\Expression\ResolvesToString; -use MongoDB\Builder\Expression\ResolvesToTimestamp; use MongoDB\Builder\Optional; /** @@ -22,7 +17,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/dayOfMonth/ */ -class DayOfMonthAggregation implements ResolvesToInt +class DayOfMonthOperator implements ResolvesToInt { public const NAME = '$dayOfMonth'; public const ENCODE = \MongoDB\Builder\Encode::Object; @@ -31,7 +26,7 @@ class DayOfMonthAggregation implements ResolvesToInt public ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; /** @param Optional|ResolvesToString|non-empty-string $timezone 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. */ - public ResolvesToString|Optional|string $timezone; + public Optional|ResolvesToString|string $timezone; /** * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. @@ -39,7 +34,7 @@ class DayOfMonthAggregation implements ResolvesToInt */ public function __construct( ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, - ResolvesToString|Optional|string $timezone = Optional::Undefined, + Optional|ResolvesToString|string $timezone = Optional::Undefined, ) { $this->date = $date; $this->timezone = $timezone; diff --git a/src/Builder/Aggregation/DayOfWeekAggregation.php b/src/Builder/Expression/DayOfWeekOperator.php similarity index 80% rename from src/Builder/Aggregation/DayOfWeekAggregation.php rename to src/Builder/Expression/DayOfWeekOperator.php index 4ed18f88f..086b6153b 100644 --- a/src/Builder/Aggregation/DayOfWeekAggregation.php +++ b/src/Builder/Expression/DayOfWeekOperator.php @@ -4,17 +4,12 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\ObjectId; use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToDate; -use MongoDB\Builder\Expression\ResolvesToInt; -use MongoDB\Builder\Expression\ResolvesToObjectId; -use MongoDB\Builder\Expression\ResolvesToString; -use MongoDB\Builder\Expression\ResolvesToTimestamp; use MongoDB\Builder\Optional; /** @@ -22,7 +17,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/dayOfWeek/ */ -class DayOfWeekAggregation implements ResolvesToInt +class DayOfWeekOperator implements ResolvesToInt { public const NAME = '$dayOfWeek'; public const ENCODE = \MongoDB\Builder\Encode::Object; @@ -31,7 +26,7 @@ class DayOfWeekAggregation implements ResolvesToInt public ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; /** @param Optional|ResolvesToString|non-empty-string $timezone 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. */ - public ResolvesToString|Optional|string $timezone; + public Optional|ResolvesToString|string $timezone; /** * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. @@ -39,7 +34,7 @@ class DayOfWeekAggregation implements ResolvesToInt */ public function __construct( ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, - ResolvesToString|Optional|string $timezone = Optional::Undefined, + Optional|ResolvesToString|string $timezone = Optional::Undefined, ) { $this->date = $date; $this->timezone = $timezone; diff --git a/src/Builder/Aggregation/DayOfYearAggregation.php b/src/Builder/Expression/DayOfYearOperator.php similarity index 80% rename from src/Builder/Aggregation/DayOfYearAggregation.php rename to src/Builder/Expression/DayOfYearOperator.php index e61aa75da..775b6d602 100644 --- a/src/Builder/Aggregation/DayOfYearAggregation.php +++ b/src/Builder/Expression/DayOfYearOperator.php @@ -4,17 +4,12 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\ObjectId; use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToDate; -use MongoDB\Builder\Expression\ResolvesToInt; -use MongoDB\Builder\Expression\ResolvesToObjectId; -use MongoDB\Builder\Expression\ResolvesToString; -use MongoDB\Builder\Expression\ResolvesToTimestamp; use MongoDB\Builder\Optional; /** @@ -22,7 +17,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/dayOfYear/ */ -class DayOfYearAggregation implements ResolvesToInt +class DayOfYearOperator implements ResolvesToInt { public const NAME = '$dayOfYear'; public const ENCODE = \MongoDB\Builder\Encode::Object; @@ -31,7 +26,7 @@ class DayOfYearAggregation implements ResolvesToInt public ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; /** @param Optional|ResolvesToString|non-empty-string $timezone 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. */ - public ResolvesToString|Optional|string $timezone; + public Optional|ResolvesToString|string $timezone; /** * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. @@ -39,7 +34,7 @@ class DayOfYearAggregation implements ResolvesToInt */ public function __construct( ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, - ResolvesToString|Optional|string $timezone = Optional::Undefined, + Optional|ResolvesToString|string $timezone = Optional::Undefined, ) { $this->date = $date; $this->timezone = $timezone; diff --git a/src/Builder/Expression/DegreesToRadiansOperator.php b/src/Builder/Expression/DegreesToRadiansOperator.php new file mode 100644 index 000000000..ea65ad7e4 --- /dev/null +++ b/src/Builder/Expression/DegreesToRadiansOperator.php @@ -0,0 +1,37 @@ + resolves to a 128-bit decimal value. + */ + public Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $expression; + + /** + * @param Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $expression $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. + */ + public function __construct(Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $expression) + { + $this->expression = $expression; + } +} diff --git a/src/Builder/Aggregation/DenseRankAggregation.php b/src/Builder/Expression/DenseRankOperator.php similarity index 80% rename from src/Builder/Aggregation/DenseRankAggregation.php rename to src/Builder/Expression/DenseRankOperator.php index 1578f7dc2..b332d709c 100644 --- a/src/Builder/Aggregation/DenseRankAggregation.php +++ b/src/Builder/Expression/DenseRankOperator.php @@ -4,10 +4,10 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Type\WindowInterface; /** * 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. @@ -15,7 +15,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/denseRank/ */ -class DenseRankAggregation implements ResolvesToInt +class DenseRankOperator implements WindowInterface { public const NAME = '$denseRank'; public const ENCODE = \MongoDB\Builder\Encode::Object; diff --git a/src/Builder/Aggregation/DerivativeAggregation.php b/src/Builder/Expression/DerivativeOperator.php similarity index 59% rename from src/Builder/Aggregation/DerivativeAggregation.php rename to src/Builder/Expression/DerivativeOperator.php index 9b35851af..af517494a 100644 --- a/src/Builder/Aggregation/DerivativeAggregation.php +++ b/src/Builder/Expression/DerivativeOperator.php @@ -4,19 +4,14 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Decimal128; use MongoDB\BSON\Int64; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToDate; -use MongoDB\Builder\Expression\ResolvesToDecimal; -use MongoDB\Builder\Expression\ResolvesToDouble; -use MongoDB\Builder\Expression\ResolvesToInt; -use MongoDB\Builder\Expression\ResolvesToLong; -use MongoDB\Builder\Expression\ResolvesToNumber; use MongoDB\Builder\Optional; +use MongoDB\Builder\Type\WindowInterface; /** * Returns the average rate of change within the specified window. @@ -24,13 +19,13 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/derivative/ */ -class DerivativeAggregation implements ResolvesToDouble +class DerivativeOperator implements WindowInterface { public const NAME = '$derivative'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param Decimal128|Int64|ResolvesToDate|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|UTCDateTime|float|int $input */ - public Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $input; + /** @param Decimal128|Int64|ResolvesToDate|ResolvesToInt|ResolvesToNumber|UTCDateTime|float|int $input */ + public Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToInt|ResolvesToNumber|float|int $input; /** * @param Optional|non-empty-string $unit A string that specifies the time unit. Use one of these strings: "week", "day","hour", "minute", "second", "millisecond". @@ -39,12 +34,12 @@ class DerivativeAggregation implements ResolvesToDouble public Optional|string $unit; /** - * @param Decimal128|Int64|ResolvesToDate|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|UTCDateTime|float|int $input + * @param Decimal128|Int64|ResolvesToDate|ResolvesToInt|ResolvesToNumber|UTCDateTime|float|int $input * @param Optional|non-empty-string $unit 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. */ public function __construct( - Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $input, + Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToInt|ResolvesToNumber|float|int $input, Optional|string $unit = Optional::Undefined, ) { $this->input = $input; diff --git a/src/Builder/Expression/DivideOperator.php b/src/Builder/Expression/DivideOperator.php new file mode 100644 index 000000000..e9e510d65 --- /dev/null +++ b/src/Builder/Expression/DivideOperator.php @@ -0,0 +1,40 @@ +dividend = $dividend; + $this->divisor = $divisor; + } +} diff --git a/src/Builder/Aggregation/DocumentNumberAggregation.php b/src/Builder/Expression/DocumentNumberOperator.php similarity index 79% rename from src/Builder/Aggregation/DocumentNumberAggregation.php rename to src/Builder/Expression/DocumentNumberOperator.php index 23d990792..d1afc36fb 100644 --- a/src/Builder/Aggregation/DocumentNumberAggregation.php +++ b/src/Builder/Expression/DocumentNumberOperator.php @@ -4,10 +4,10 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Type\WindowInterface; /** * Returns the position of a document (known as the document number) in the $setWindowFields stage partition. Ties result in different adjacent document numbers. @@ -15,7 +15,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/documentNumber/ */ -class DocumentNumberAggregation implements ResolvesToInt +class DocumentNumberOperator implements WindowInterface { public const NAME = '$documentNumber'; public const ENCODE = \MongoDB\Builder\Encode::Object; diff --git a/src/Builder/Aggregation/EqAggregation.php b/src/Builder/Expression/EqOperator.php similarity index 81% rename from src/Builder/Aggregation/EqAggregation.php rename to src/Builder/Expression/EqOperator.php index 180518007..51f336fb3 100644 --- a/src/Builder/Aggregation/EqAggregation.php +++ b/src/Builder/Expression/EqOperator.php @@ -4,7 +4,7 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Binary; use MongoDB\BSON\Decimal128; @@ -17,8 +17,6 @@ use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToBool; -use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Type\ExpressionInterface; use MongoDB\Model\BSONArray; use stdClass; @@ -28,7 +26,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/eq/ */ -class EqAggregation implements ResolvesToBool +class EqOperator implements ResolvesToBool { public const NAME = '$eq'; public const ENCODE = \MongoDB\Builder\Encode::Array; @@ -47,15 +45,7 @@ public function __construct( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression1, Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression2, ) { - if (\is_array($expression1) && ! \array_is_list($expression1)) { - throw new \InvalidArgumentException('Expected $expression1 argument to be a list, got an associative array.'); - } - $this->expression1 = $expression1; - if (\is_array($expression2) && ! \array_is_list($expression2)) { - throw new \InvalidArgumentException('Expected $expression2 argument to be a list, got an associative array.'); - } - $this->expression2 = $expression2; } } diff --git a/src/Builder/Aggregation/ExpMovingAvgAggregation.php b/src/Builder/Expression/ExpMovingAvgOperator.php similarity index 67% rename from src/Builder/Aggregation/ExpMovingAvgAggregation.php rename to src/Builder/Expression/ExpMovingAvgOperator.php index 6c3a5fc81..6953a19dd 100644 --- a/src/Builder/Aggregation/ExpMovingAvgAggregation.php +++ b/src/Builder/Expression/ExpMovingAvgOperator.php @@ -4,17 +4,13 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Decimal128; use MongoDB\BSON\Int64; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToDecimal; -use MongoDB\Builder\Expression\ResolvesToDouble; -use MongoDB\Builder\Expression\ResolvesToInt; -use MongoDB\Builder\Expression\ResolvesToLong; -use MongoDB\Builder\Expression\ResolvesToNumber; use MongoDB\Builder\Optional; +use MongoDB\Builder\Type\WindowInterface; /** * Returns the exponential moving average for the numeric expression. @@ -22,13 +18,13 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/expMovingAvg/ */ -class ExpMovingAvgAggregation implements ResolvesToDouble +class ExpMovingAvgOperator implements WindowInterface { public const NAME = '$expMovingAvg'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $input */ - public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $input; + /** @param Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $input */ + public Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $input; /** * @param Optional|int $N 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. @@ -38,23 +34,23 @@ class ExpMovingAvgAggregation implements ResolvesToDouble public Optional|int $N; /** - * @param Int64|Optional|float|int $alpha 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. + * @param Optional|Int64|float|int $alpha 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. */ - public Int64|Optional|float|int $alpha; + public Optional|Int64|float|int $alpha; /** - * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $input + * @param Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $input * @param Optional|int $N 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: - * @param Int64|Optional|float|int $alpha 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. + * @param Optional|Int64|float|int $alpha 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. */ public function __construct( - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $input, + Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $input, Optional|int $N = Optional::Undefined, - Int64|Optional|float|int $alpha = Optional::Undefined, + Optional|Int64|float|int $alpha = Optional::Undefined, ) { $this->input = $input; $this->N = $N; diff --git a/src/Builder/Expression/ExpOperator.php b/src/Builder/Expression/ExpOperator.php new file mode 100644 index 000000000..7ce403260 --- /dev/null +++ b/src/Builder/Expression/ExpOperator.php @@ -0,0 +1,33 @@ +exponent = $exponent; + } +} diff --git a/src/Builder/Expression/ExpressionFactoryTrait.php b/src/Builder/Expression/ExpressionFactoryTrait.php new file mode 100644 index 000000000..88b15061c --- /dev/null +++ b/src/Builder/Expression/ExpressionFactoryTrait.php @@ -0,0 +1,103 @@ + resolves to a 128-bit decimal value. */ - public static function cos( - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression, - ): CosAggregation + public static function cos(Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $expression): CosOperator { - return new CosAggregation($expression); + return new CosOperator($expression); } /** * Returns the hyperbolic cosine of a value that is measured in radians. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/cosh/ - * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression $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. + * @param Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $expression $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. */ - public static function cosh( - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression, - ): CoshAggregation + public static function cosh(Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $expression): CoshOperator { - return new CoshAggregation($expression); + return new CoshOperator($expression); } /** @@ -697,9 +492,9 @@ public static function cosh( * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/count/ * @param non-empty-string $field */ - public static function count(string $field): CountAggregation + public static function count(string $field): CountOperator { - return new CountAggregation($field); + return new CountOperator($field); } /** @@ -707,15 +502,15 @@ public static function count(string $field): CountAggregation * New in version 5.0. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/covariancePop/ - * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression1 - * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression2 + * @param Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $expression1 + * @param Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $expression2 */ public static function covariancePop( - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression1, - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression2, - ): CovariancePopAggregation + Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $expression1, + Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $expression2, + ): CovariancePopOperator { - return new CovariancePopAggregation($expression1, $expression2); + return new CovariancePopOperator($expression1, $expression2); } /** @@ -723,15 +518,15 @@ public static function covariancePop( * New in version 5.0. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/covarianceSamp/ - * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression1 - * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression2 + * @param Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $expression1 + * @param Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $expression2 */ public static function covarianceSamp( - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression1, - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression2, - ): CovarianceSampAggregation + Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $expression1, + Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $expression2, + ): CovarianceSampOperator { - return new CovarianceSampAggregation($expression1, $expression2); + return new CovarianceSampOperator($expression1, $expression2); } /** @@ -747,10 +542,10 @@ public static function dateAdd( ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $startDate, ResolvesToString|string $unit, Int64|ResolvesToInt|ResolvesToLong|int $amount, - ResolvesToString|Optional|string $timezone = Optional::Undefined, - ): DateAddAggregation + Optional|ResolvesToString|string $timezone = Optional::Undefined, + ): DateAddOperator { - return new DateAddAggregation($startDate, $unit, $amount, $timezone); + return new DateAddOperator($startDate, $unit, $amount, $timezone); } /** @@ -767,44 +562,44 @@ public static function dateDiff( ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $startDate, ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $endDate, ResolvesToString|string $unit, - ResolvesToString|Optional|string $timezone = Optional::Undefined, - ResolvesToString|Optional|string $startOfWeek = Optional::Undefined, - ): DateDiffAggregation + Optional|ResolvesToString|string $timezone = Optional::Undefined, + Optional|ResolvesToString|string $startOfWeek = Optional::Undefined, + ): DateDiffOperator { - return new DateDiffAggregation($startDate, $endDate, $unit, $timezone, $startOfWeek); + return new DateDiffOperator($startDate, $endDate, $unit, $timezone, $startOfWeek); } /** * Constructs a BSON Date object given the date's constituent parts. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateFromParts/ - * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $year Calendar year. Can be any expression that evaluates to a number. - * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $isoWeekYear ISO Week Date Year. Can be any expression that evaluates to a number. - * @param Decimal128|Int64|Optional|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $month Month. Defaults to 1. - * @param Decimal128|Int64|Optional|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $isoWeek Week of year. Defaults to 1. - * @param Decimal128|Int64|Optional|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $day Day of month. Defaults to 1. - * @param Decimal128|Int64|Optional|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $isoDayOfWeek Day of week (Monday 1 - Sunday 7). Defaults to 1. - * @param Decimal128|Int64|Optional|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $hour Hour. Defaults to 0. - * @param Decimal128|Int64|Optional|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $minute Minute. Defaults to 0. - * @param Decimal128|Int64|Optional|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $second Second. Defaults to 0. - * @param Decimal128|Int64|Optional|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $millisecond Millisecond. Defaults to 0. + * @param Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $year Calendar year. Can be any expression that evaluates to a number. + * @param Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $isoWeekYear ISO Week Date Year. Can be any expression that evaluates to a number. + * @param Optional|Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $month Month. Defaults to 1. + * @param Optional|Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $isoWeek Week of year. Defaults to 1. + * @param Optional|Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $day Day of month. Defaults to 1. + * @param Optional|Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $isoDayOfWeek Day of week (Monday 1 - Sunday 7). Defaults to 1. + * @param Optional|Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $hour Hour. Defaults to 0. + * @param Optional|Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $minute Minute. Defaults to 0. + * @param Optional|Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $second Second. Defaults to 0. + * @param Optional|Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $millisecond Millisecond. Defaults to 0. * @param Optional|ResolvesToString|non-empty-string $timezone 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. */ public static function dateFromParts( - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $year, - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $isoWeekYear, - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|Optional|float|int $month = Optional::Undefined, - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|Optional|float|int $isoWeek = Optional::Undefined, - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|Optional|float|int $day = Optional::Undefined, - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|Optional|float|int $isoDayOfWeek = Optional::Undefined, - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|Optional|float|int $hour = Optional::Undefined, - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|Optional|float|int $minute = Optional::Undefined, - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|Optional|float|int $second = Optional::Undefined, - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|Optional|float|int $millisecond = Optional::Undefined, - ResolvesToString|Optional|string $timezone = Optional::Undefined, - ): DateFromPartsAggregation + Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $year, + Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $isoWeekYear, + Optional|Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $month = Optional::Undefined, + Optional|Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $isoWeek = Optional::Undefined, + Optional|Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $day = Optional::Undefined, + Optional|Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $isoDayOfWeek = Optional::Undefined, + Optional|Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $hour = Optional::Undefined, + Optional|Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $minute = Optional::Undefined, + Optional|Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $second = Optional::Undefined, + Optional|Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $millisecond = Optional::Undefined, + Optional|ResolvesToString|string $timezone = Optional::Undefined, + ): DateFromPartsOperator { - return new DateFromPartsAggregation($year, $isoWeekYear, $month, $isoWeek, $day, $isoDayOfWeek, $hour, $minute, $second, $millisecond, $timezone); + return new DateFromPartsOperator($year, $isoWeekYear, $month, $isoWeek, $day, $isoDayOfWeek, $hour, $minute, $second, $millisecond, $timezone); } /** @@ -815,20 +610,20 @@ public static function dateFromParts( * @param Optional|ResolvesToString|non-empty-string $format 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. * @param Optional|ResolvesToString|non-empty-string $timezone The time zone to use to format the date. - * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|Optional|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $onError 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. + * @param Optional|BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $onError 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. - * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|Optional|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $onNull 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. + * @param Optional|BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $onNull 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. */ public static function dateFromString( ResolvesToString|string $dateString, - ResolvesToString|Optional|string $format = Optional::Undefined, - ResolvesToString|Optional|string $timezone = Optional::Undefined, - Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|Optional|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $onError = Optional::Undefined, - Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|Optional|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $onNull = Optional::Undefined, - ): DateFromStringAggregation + Optional|ResolvesToString|string $format = Optional::Undefined, + Optional|ResolvesToString|string $timezone = Optional::Undefined, + Optional|Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $onError = Optional::Undefined, + Optional|Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $onNull = Optional::Undefined, + ): DateFromStringOperator { - return new DateFromStringAggregation($dateString, $format, $timezone, $onError, $onNull); + return new DateFromStringOperator($dateString, $format, $timezone, $onError, $onNull); } /** @@ -844,10 +639,10 @@ public static function dateSubtract( ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $startDate, ResolvesToString|string $unit, Int64|ResolvesToInt|ResolvesToLong|int $amount, - ResolvesToString|Optional|string $timezone = Optional::Undefined, - ): DateSubtractAggregation + Optional|ResolvesToString|string $timezone = Optional::Undefined, + ): DateSubtractOperator { - return new DateSubtractAggregation($startDate, $unit, $amount, $timezone); + return new DateSubtractOperator($startDate, $unit, $amount, $timezone); } /** @@ -860,11 +655,11 @@ public static function dateSubtract( */ public static function dateToParts( ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, - ResolvesToString|Optional|string $timezone = Optional::Undefined, + Optional|ResolvesToString|string $timezone = Optional::Undefined, Optional|bool $iso8601 = Optional::Undefined, - ): DateToPartsAggregation + ): DateToPartsOperator { - return new DateToPartsAggregation($date, $timezone, $iso8601); + return new DateToPartsOperator($date, $timezone, $iso8601); } /** @@ -875,17 +670,17 @@ public static function dateToParts( * @param Optional|ResolvesToString|non-empty-string $format 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. * @param Optional|ResolvesToString|non-empty-string $timezone The time zone to use to format the date. - * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|Optional|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $onNull The value to return if the date is null or missing. + * @param Optional|BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $onNull The value to return if the date is null or missing. * If unspecified, $dateToString returns null if the date is null or missing. */ public static function dateToString( ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, - ResolvesToString|Optional|string $format = Optional::Undefined, - ResolvesToString|Optional|string $timezone = Optional::Undefined, - Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|Optional|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $onNull = Optional::Undefined, - ): DateToStringAggregation + Optional|ResolvesToString|string $format = Optional::Undefined, + Optional|ResolvesToString|string $timezone = Optional::Undefined, + Optional|Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $onNull = Optional::Undefined, + ): DateToStringOperator { - return new DateToStringAggregation($date, $format, $timezone, $onNull); + return new DateToStringOperator($date, $format, $timezone, $onNull); } /** @@ -895,7 +690,7 @@ public static function dateToString( * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The date to truncate, specified in UTC. The date can be any expression that resolves to a Date, a Timestamp, or an ObjectID. * @param ResolvesToString|non-empty-string $unit 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. - * @param Decimal128|Int64|Optional|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $binSize The numeric time value, specified as an expression that must resolve to a positive non-zero number. Defaults to 1. + * @param Optional|Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $binSize 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. * @param Optional|ResolvesToString|non-empty-string $timezone 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. * @param Optional|non-empty-string $startOfWeek The start of the week. Used when @@ -904,12 +699,12 @@ public static function dateToString( public static function dateTrunc( ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, ResolvesToString|string $unit, - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|Optional|float|int $binSize = Optional::Undefined, - ResolvesToString|Optional|string $timezone = Optional::Undefined, + Optional|Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $binSize = Optional::Undefined, + Optional|ResolvesToString|string $timezone = Optional::Undefined, Optional|string $startOfWeek = Optional::Undefined, - ): DateTruncAggregation + ): DateTruncOperator { - return new DateTruncAggregation($date, $unit, $binSize, $timezone, $startOfWeek); + return new DateTruncOperator($date, $unit, $binSize, $timezone, $startOfWeek); } /** @@ -921,10 +716,10 @@ public static function dateTrunc( */ public static function dayOfMonth( ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, - ResolvesToString|Optional|string $timezone = Optional::Undefined, - ): DayOfMonthAggregation + Optional|ResolvesToString|string $timezone = Optional::Undefined, + ): DayOfMonthOperator { - return new DayOfMonthAggregation($date, $timezone); + return new DayOfMonthOperator($date, $timezone); } /** @@ -936,10 +731,10 @@ public static function dayOfMonth( */ public static function dayOfWeek( ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, - ResolvesToString|Optional|string $timezone = Optional::Undefined, - ): DayOfWeekAggregation + Optional|ResolvesToString|string $timezone = Optional::Undefined, + ): DayOfWeekOperator { - return new DayOfWeekAggregation($date, $timezone); + return new DayOfWeekOperator($date, $timezone); } /** @@ -951,24 +746,24 @@ public static function dayOfWeek( */ public static function dayOfYear( ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, - ResolvesToString|Optional|string $timezone = Optional::Undefined, - ): DayOfYearAggregation + Optional|ResolvesToString|string $timezone = Optional::Undefined, + ): DayOfYearOperator { - return new DayOfYearAggregation($date, $timezone); + return new DayOfYearOperator($date, $timezone); } /** * Converts a value from degrees to radians. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/degreesToRadians/ - * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression $degreesToRadians takes any valid expression that resolves to a number. + * @param Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $expression $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. */ public static function degreesToRadians( - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression, - ): DegreesToRadiansAggregation + Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $expression, + ): DegreesToRadiansOperator { - return new DegreesToRadiansAggregation($expression); + return new DegreesToRadiansOperator($expression); } /** @@ -977,9 +772,9 @@ public static function degreesToRadians( * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/denseRank/ */ - public static function denseRank(): DenseRankAggregation + public static function denseRank(): DenseRankOperator { - return new DenseRankAggregation(); + return new DenseRankOperator(); } /** @@ -987,31 +782,31 @@ public static function denseRank(): DenseRankAggregation * New in version 5.0. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/derivative/ - * @param Decimal128|Int64|ResolvesToDate|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|UTCDateTime|float|int $input + * @param Decimal128|Int64|ResolvesToDate|ResolvesToInt|ResolvesToNumber|UTCDateTime|float|int $input * @param Optional|non-empty-string $unit 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. */ public static function derivative( - Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $input, + Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToInt|ResolvesToNumber|float|int $input, Optional|string $unit = Optional::Undefined, - ): DerivativeAggregation + ): DerivativeOperator { - return new DerivativeAggregation($input, $unit); + return new DerivativeOperator($input, $unit); } /** * Returns the result of dividing the first number by the second. Accepts two argument expressions. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/divide/ - * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $dividend The first argument is the dividend, and the second argument is the divisor; i.e. the first argument is divided by the second argument. - * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $divisor + * @param Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $dividend The first argument is the dividend, and the second argument is the divisor; i.e. the first argument is divided by the second argument. + * @param Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $divisor */ public static function divide( - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $dividend, - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $divisor, - ): DivideAggregation + Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $dividend, + Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $divisor, + ): DivideOperator { - return new DivideAggregation($dividend, $divisor); + return new DivideOperator($dividend, $divisor); } /** @@ -1020,9 +815,9 @@ public static function divide( * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/documentNumber/ */ - public static function documentNumber(): DocumentNumberAggregation + public static function documentNumber(): DocumentNumberOperator { - return new DocumentNumberAggregation(); + return new DocumentNumberOperator(); } /** @@ -1035,22 +830,20 @@ public static function documentNumber(): DocumentNumberAggregation public static function eq( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression1, Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression2, - ): EqAggregation + ): EqOperator { - return new EqAggregation($expression1, $expression2); + return new EqOperator($expression1, $expression2); } /** * Raises e to the specified exponent. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/exp/ - * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $exponent + * @param Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $exponent */ - public static function exp( - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $exponent, - ): ExpAggregation + public static function exp(Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $exponent): ExpOperator { - return new ExpAggregation($exponent); + return new ExpOperator($exponent); } /** @@ -1058,20 +851,20 @@ public static function exp( * New in version 5.0. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/expMovingAvg/ - * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $input + * @param Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $input * @param Optional|int $N 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: - * @param Int64|Optional|float|int $alpha 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. + * @param Optional|Int64|float|int $alpha 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. */ public static function expMovingAvg( - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $input, + Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $input, Optional|int $N = Optional::Undefined, - Int64|Optional|float|int $alpha = Optional::Undefined, - ): ExpMovingAvgAggregation + Optional|Int64|float|int $alpha = Optional::Undefined, + ): ExpMovingAvgOperator { - return new ExpMovingAvgAggregation($input, $N, $alpha); + return new ExpMovingAvgOperator($input, $N, $alpha); } /** @@ -1088,10 +881,10 @@ public static function filter( PackedArray|ResolvesToArray|BSONArray|array $input, ResolvesToBool|bool $cond, Optional|string $as = Optional::Undefined, - ResolvesToInt|Optional|int $limit = Optional::Undefined, - ): FilterAggregation + Optional|ResolvesToInt|int $limit = Optional::Undefined, + ): FilterOperator { - return new FilterAggregation($input, $cond, $as, $limit); + return new FilterOperator($input, $cond, $as, $limit); } /** @@ -1103,9 +896,9 @@ public static function filter( */ public static function first( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, - ): FirstAggregation + ): FirstOperator { - return new FirstAggregation($expression); + return new FirstOperator($expression); } /** @@ -1118,22 +911,20 @@ public static function first( public static function firstN( PackedArray|ResolvesToArray|BSONArray|array $input, ResolvesToInt|int $n, - ): FirstNAggregation + ): FirstNOperator { - return new FirstNAggregation($input, $n); + return new FirstNOperator($input, $n); } /** * Returns the largest integer less than or equal to the specified number. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/floor/ - * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression + * @param Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $expression */ - public static function floor( - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression, - ): FloorAggregation + public static function floor(Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $expression): FloorOperator { - return new FloorAggregation($expression); + return new FloorOperator($expression); } /** @@ -1145,13 +936,9 @@ public static function floor( * @param BSONArray|PackedArray|array $args Arguments passed to the function body. If the body function does not take an argument, you can specify an empty array [ ]. * @param non-empty-string $lang */ - public static function function( - string $body, - PackedArray|BSONArray|array $args, - string $lang, - ): FunctionAggregation + public static function function(string $body, PackedArray|BSONArray|array $args, string $lang): FunctionOperator { - return new FunctionAggregation($body, $args, $lang); + return new FunctionOperator($body, $args, $lang); } /** @@ -1161,15 +948,15 @@ public static function function( * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/getField/ * @param non-empty-string $field 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. - * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|Optional|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $input Default: $$CURRENT + * @param Optional|BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $input 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). */ public static function getField( string $field, - Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|Optional|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $input = Optional::Undefined, - ): GetFieldAggregation + Optional|Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $input = Optional::Undefined, + ): GetFieldOperator { - return new GetFieldAggregation($field, $input); + return new GetFieldOperator($field, $input); } /** @@ -1182,9 +969,9 @@ public static function getField( public static function gt( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression1, Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression2, - ): GtAggregation + ): GtOperator { - return new GtAggregation($expression1, $expression2); + return new GtOperator($expression1, $expression2); } /** @@ -1197,9 +984,9 @@ public static function gt( public static function gte( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression1, Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression2, - ): GteAggregation + ): GteOperator { - return new GteAggregation($expression1, $expression2); + return new GteOperator($expression1, $expression2); } /** @@ -1211,10 +998,10 @@ public static function gte( */ public static function hour( ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, - ResolvesToString|Optional|string $timezone = Optional::Undefined, - ): HourAggregation + Optional|ResolvesToString|string $timezone = Optional::Undefined, + ): HourOperator { - return new HourAggregation($date, $timezone); + return new HourOperator($date, $timezone); } /** @@ -1225,9 +1012,9 @@ public static function hour( */ public static function ifNull( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string ...$expression, - ): IfNullAggregation + ): IfNullOperator { - return new IfNullAggregation(...$expression); + return new IfNullOperator(...$expression); } /** @@ -1240,9 +1027,9 @@ public static function ifNull( public static function in( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, PackedArray|ResolvesToArray|BSONArray|array $array, - ): InAggregation + ): InOperator { - return new InAggregation($expression, $array); + return new InOperator($expression, $array); } /** @@ -1261,11 +1048,11 @@ public static function in( public static function indexOfArray( ResolvesToString|string $array, Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $search, - ResolvesToInt|Optional|int $start = Optional::Undefined, - ResolvesToInt|Optional|int $end = Optional::Undefined, - ): IndexOfArrayAggregation + Optional|ResolvesToInt|int $start = Optional::Undefined, + Optional|ResolvesToInt|int $end = Optional::Undefined, + ): IndexOfArrayOperator { - return new IndexOfArrayAggregation($array, $search, $start, $end); + return new IndexOfArrayOperator($array, $search, $start, $end); } /** @@ -1284,11 +1071,11 @@ public static function indexOfArray( public static function indexOfBytes( ResolvesToString|string $string, ResolvesToString|string $substring, - ResolvesToInt|Optional|int $start = Optional::Undefined, - ResolvesToInt|Optional|int $end = Optional::Undefined, - ): IndexOfBytesAggregation + Optional|ResolvesToInt|int $start = Optional::Undefined, + Optional|ResolvesToInt|int $end = Optional::Undefined, + ): IndexOfBytesOperator { - return new IndexOfBytesAggregation($string, $substring, $start, $end); + return new IndexOfBytesOperator($string, $substring, $start, $end); } /** @@ -1307,11 +1094,11 @@ public static function indexOfBytes( public static function indexOfCP( ResolvesToString|string $string, ResolvesToString|string $substring, - ResolvesToInt|Optional|int $start = Optional::Undefined, - ResolvesToInt|Optional|int $end = Optional::Undefined, - ): IndexOfCPAggregation + Optional|ResolvesToInt|int $start = Optional::Undefined, + Optional|ResolvesToInt|int $end = Optional::Undefined, + ): IndexOfCPOperator { - return new IndexOfCPAggregation($string, $substring, $start, $end); + return new IndexOfCPOperator($string, $substring, $start, $end); } /** @@ -1319,16 +1106,16 @@ public static function indexOfCP( * New in version 5.0. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/integral/ - * @param Decimal128|Int64|ResolvesToDate|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|UTCDateTime|float|int $input + * @param Decimal128|Int64|ResolvesToDate|ResolvesToInt|ResolvesToNumber|UTCDateTime|float|int $input * @param Optional|ResolvesToString|non-empty-string $unit 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. */ public static function integral( - Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $input, - ResolvesToString|Optional|string $unit = Optional::Undefined, - ): IntegralAggregation + Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToInt|ResolvesToNumber|float|int $input, + Optional|ResolvesToString|string $unit = Optional::Undefined, + ): IntegralOperator { - return new IntegralAggregation($input, $unit); + return new IntegralOperator($input, $unit); } /** @@ -1339,9 +1126,9 @@ public static function integral( */ public static function isArray( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string ...$expression, - ): IsArrayAggregation + ): IsArrayOperator { - return new IsArrayAggregation(...$expression); + return new IsArrayOperator(...$expression); } /** @@ -1354,9 +1141,9 @@ public static function isArray( */ public static function isNumber( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string ...$expression, - ): IsNumberAggregation + ): IsNumberOperator { - return new IsNumberAggregation(...$expression); + return new IsNumberOperator(...$expression); } /** @@ -1368,10 +1155,10 @@ public static function isNumber( */ public static function isoDayOfWeek( ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, - ResolvesToString|Optional|string $timezone = Optional::Undefined, - ): IsoDayOfWeekAggregation + Optional|ResolvesToString|string $timezone = Optional::Undefined, + ): IsoDayOfWeekOperator { - return new IsoDayOfWeekAggregation($date, $timezone); + return new IsoDayOfWeekOperator($date, $timezone); } /** @@ -1383,10 +1170,10 @@ public static function isoDayOfWeek( */ public static function isoWeek( ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, - ResolvesToString|Optional|string $timezone = Optional::Undefined, - ): IsoWeekAggregation + Optional|ResolvesToString|string $timezone = Optional::Undefined, + ): IsoWeekOperator { - return new IsoWeekAggregation($date, $timezone); + return new IsoWeekOperator($date, $timezone); } /** @@ -1398,10 +1185,10 @@ public static function isoWeek( */ public static function isoWeekYear( ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, - ResolvesToString|Optional|string $timezone = Optional::Undefined, - ): IsoWeekYearAggregation + Optional|ResolvesToString|string $timezone = Optional::Undefined, + ): IsoWeekYearOperator { - return new IsoWeekYearAggregation($date, $timezone); + return new IsoWeekYearOperator($date, $timezone); } /** @@ -1413,9 +1200,9 @@ public static function isoWeekYear( */ public static function last( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, - ): LastAggregation + ): LastOperator { - return new LastAggregation($expression); + return new LastOperator($expression); } /** @@ -1428,9 +1215,9 @@ public static function last( public static function lastN( PackedArray|ResolvesToArray|BSONArray|array $input, ResolvesToInt|int $n, - ): LastNAggregation + ): LastNOperator { - return new LastNAggregation($input, $n); + return new LastNOperator($input, $n); } /** @@ -1445,9 +1232,9 @@ public static function lastN( public static function let( Document|Serializable|stdClass|array $vars, Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $in, - ): LetAggregation + ): LetOperator { - return new LetAggregation($vars, $in); + return new LetOperator($vars, $in); } /** @@ -1456,13 +1243,13 @@ public static function let( * New in version 5.3. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/linearFill/ - * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression + * @param Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $expression */ public static function linearFill( - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression, - ): LinearFillAggregation + Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $expression, + ): LinearFillOperator { - return new LinearFillAggregation($expression); + return new LinearFillOperator($expression); } /** @@ -1473,9 +1260,9 @@ public static function linearFill( */ public static function literal( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|BSONArray|stdClass|array|bool|float|int|null|string $value, - ): LiteralAggregation + ): LiteralOperator { - return new LiteralAggregation($value); + return new LiteralOperator($value); } /** @@ -1483,13 +1270,11 @@ public static function literal( * $ln is equivalent to $log: [ , Math.E ] expression, where Math.E is a JavaScript representation for Euler's number e. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/ln/ - * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $number Any valid expression as long as it resolves to a non-negative number. For more information on expressions, see Expressions. + * @param Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $number Any valid expression as long as it resolves to a non-negative number. For more information on expressions, see Expressions. */ - public static function ln( - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $number, - ): LnAggregation + public static function ln(Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $number): LnOperator { - return new LnAggregation($number); + return new LnOperator($number); } /** @@ -1502,37 +1287,35 @@ public static function ln( */ public static function locf( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, - ): LocfAggregation + ): LocfOperator { - return new LocfAggregation($expression); + return new LocfOperator($expression); } /** * Calculates the log of a number in the specified base. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/log/ - * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $number Any valid expression as long as it resolves to a non-negative number. - * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $base Any valid expression as long as it resolves to a positive number greater than 1. + * @param Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $number Any valid expression as long as it resolves to a non-negative number. + * @param Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $base Any valid expression as long as it resolves to a positive number greater than 1. */ public static function log( - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $number, - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $base, - ): LogAggregation + Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $number, + Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $base, + ): LogOperator { - return new LogAggregation($number, $base); + return new LogOperator($number, $base); } /** * Calculates the log base 10 of a number. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/log10/ - * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $number Any valid expression as long as it resolves to a non-negative number. + * @param Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $number Any valid expression as long as it resolves to a non-negative number. */ - public static function log10( - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $number, - ): Log10Aggregation + public static function log10(Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $number): Log10Operator { - return new Log10Aggregation($number); + return new Log10Operator($number); } /** @@ -1545,9 +1328,9 @@ public static function log10( public static function lt( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression1, Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression2, - ): LtAggregation + ): LtOperator { - return new LtAggregation($expression1, $expression2); + return new LtOperator($expression1, $expression2); } /** @@ -1560,9 +1343,9 @@ public static function lt( public static function lte( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression1, Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression2, - ): LteAggregation + ): LteOperator { - return new LteAggregation($expression1, $expression2); + return new LteOperator($expression1, $expression2); } /** @@ -1577,10 +1360,10 @@ public static function lte( */ public static function ltrim( ResolvesToString|string $input, - ResolvesToString|Optional|string $chars = Optional::Undefined, - ): LtrimAggregation + Optional|ResolvesToString|string $chars = Optional::Undefined, + ): LtrimOperator { - return new LtrimAggregation($input, $chars); + return new LtrimOperator($input, $chars); } /** @@ -1594,10 +1377,10 @@ public static function ltrim( public static function map( PackedArray|ResolvesToArray|BSONArray|array $input, Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $in, - ResolvesToString|Optional|string $as = Optional::Undefined, - ): MapAggregation + Optional|ResolvesToString|string $as = Optional::Undefined, + ): MapOperator { - return new MapAggregation($input, $in, $as); + return new MapOperator($input, $in, $as); } /** @@ -1609,9 +1392,9 @@ public static function map( */ public static function max( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string ...$expression, - ): MaxAggregation + ): MaxOperator { - return new MaxAggregation(...$expression); + return new MaxOperator(...$expression); } /** @@ -1624,9 +1407,9 @@ public static function max( public static function maxN( PackedArray|ResolvesToArray|BSONArray|array $input, ResolvesToInt|int $n, - ): MaxNAggregation + ): MaxNOperator { - return new MaxNAggregation($input, $n); + return new MaxNOperator($input, $n); } /** @@ -1638,15 +1421,15 @@ public static function maxN( * It is also available as an aggregation expression. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/median/ - * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $input $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. + * @param Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $input $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. * @param non-empty-string $method The method that mongod uses to calculate the 50th percentile value. The method must be 'approximate'. */ public static function median( - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $input, + Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $input, string $method, - ): MedianAggregation + ): MedianOperator { - return new MedianAggregation($input, $method); + return new MedianOperator($input, $method); } /** @@ -1657,9 +1440,9 @@ public static function median( */ public static function mergeObjects( Document|Serializable|ResolvesToObject|stdClass|array ...$document, - ): MergeObjectsAggregation + ): MergeObjectsOperator { - return new MergeObjectsAggregation(...$document); + return new MergeObjectsOperator(...$document); } /** @@ -1668,9 +1451,9 @@ public static function mergeObjects( * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/meta/ * @param non-empty-string $keyword */ - public static function meta(string $keyword): MetaAggregation + public static function meta(string $keyword): MetaOperator { - return new MetaAggregation($keyword); + return new MetaOperator($keyword); } /** @@ -1682,10 +1465,10 @@ public static function meta(string $keyword): MetaAggregation */ public static function millisecond( ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, - ResolvesToString|Optional|string $timezone = Optional::Undefined, - ): MillisecondAggregation + Optional|ResolvesToString|string $timezone = Optional::Undefined, + ): MillisecondOperator { - return new MillisecondAggregation($date, $timezone); + return new MillisecondOperator($date, $timezone); } /** @@ -1697,9 +1480,9 @@ public static function millisecond( */ public static function min( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string ...$expression, - ): MinAggregation + ): MinOperator { - return new MinAggregation(...$expression); + return new MinOperator(...$expression); } /** @@ -1712,9 +1495,9 @@ public static function min( public static function minN( PackedArray|ResolvesToArray|BSONArray|array $input, ResolvesToInt|int $n, - ): MinNAggregation + ): MinNOperator { - return new MinNAggregation($input, $n); + return new MinNOperator($input, $n); } /** @@ -1726,25 +1509,25 @@ public static function minN( */ public static function minute( ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, - ResolvesToString|Optional|string $timezone = Optional::Undefined, - ): MinuteAggregation + Optional|ResolvesToString|string $timezone = Optional::Undefined, + ): MinuteOperator { - return new MinuteAggregation($date, $timezone); + return new MinuteOperator($date, $timezone); } /** * Returns the remainder of the first number divided by the second. Accepts two argument expressions. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/mod/ - * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $dividend The first argument is the dividend, and the second argument is the divisor; i.e. first argument is divided by the second argument. - * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $divisor + * @param Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $dividend The first argument is the dividend, and the second argument is the divisor; i.e. first argument is divided by the second argument. + * @param Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $divisor */ public static function mod( - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $dividend, - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $divisor, - ): ModAggregation + Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $dividend, + Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $divisor, + ): ModOperator { - return new ModAggregation($dividend, $divisor); + return new ModOperator($dividend, $divisor); } /** @@ -1756,24 +1539,24 @@ public static function mod( */ public static function month( ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, - ResolvesToString|Optional|string $timezone = Optional::Undefined, - ): MonthAggregation + Optional|ResolvesToString|string $timezone = Optional::Undefined, + ): MonthOperator { - return new MonthAggregation($date, $timezone); + return new MonthOperator($date, $timezone); } /** * Multiplies numbers to return the product. Accepts any number of argument expressions. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/multiply/ - * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int ...$expression The arguments can be any valid expression as long as they resolve to numbers. + * @param Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int ...$expression 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. */ public static function multiply( - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int ...$expression, - ): MultiplyAggregation + Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int ...$expression, + ): MultiplyOperator { - return new MultiplyAggregation(...$expression); + return new MultiplyOperator(...$expression); } /** @@ -1786,9 +1569,9 @@ public static function multiply( public static function ne( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression1, Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression2, - ): NeAggregation + ): NeOperator { - return new NeAggregation($expression1, $expression2); + return new NeOperator($expression1, $expression2); } /** @@ -1799,9 +1582,9 @@ public static function ne( */ public static function not( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToBool|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, - ): NotAggregation + ): NotOperator { - return new NotAggregation($expression); + return new NotOperator($expression); } /** @@ -1812,9 +1595,9 @@ public static function not( */ public static function objectToArray( Document|Serializable|ResolvesToObject|stdClass|array $object, - ): ObjectToArrayAggregation + ): ObjectToArrayOperator { - return new ObjectToArrayAggregation($object); + return new ObjectToArrayOperator($object); } /** @@ -1825,9 +1608,9 @@ public static function objectToArray( */ public static function or( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToBool|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string ...$expression, - ): OrAggregation + ): OrOperator { - return new OrAggregation(...$expression); + return new OrOperator(...$expression); } /** @@ -1842,33 +1625,33 @@ public static function or( * It is also available as an aggregation expression. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/percentile/ - * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $input $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. + * @param Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $input $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. * @param BSONArray|PackedArray|ResolvesToArray|array $p $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. * @param non-empty-string $method The method that mongod uses to calculate the percentile value. The method must be 'approximate'. */ public static function percentile( - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $input, + Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $input, PackedArray|ResolvesToArray|BSONArray|array $p, string $method, - ): PercentileAggregation + ): PercentileOperator { - return new PercentileAggregation($input, $p, $method); + return new PercentileOperator($input, $p, $method); } /** * Raises a number to the specified exponent. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/pow/ - * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $number - * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $exponent + * @param Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $number + * @param Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $exponent */ public static function pow( - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $number, - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $exponent, - ): PowAggregation + Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $number, + Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $exponent, + ): PowOperator { - return new PowAggregation($number, $exponent); + return new PowOperator($number, $exponent); } /** @@ -1880,22 +1663,22 @@ public static function pow( */ public static function push( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, - ): PushAggregation + ): PushOperator { - return new PushAggregation($expression); + return new PushOperator($expression); } /** * Converts a value from radians to degrees. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/radiansToDegrees/ - * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression + * @param Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $expression */ public static function radiansToDegrees( - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression, - ): RadiansToDegreesAggregation + Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $expression, + ): RadiansToDegreesOperator { - return new RadiansToDegreesAggregation($expression); + return new RadiansToDegreesOperator($expression); } /** @@ -1903,9 +1686,9 @@ public static function radiansToDegrees( * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/rand/ */ - public static function rand(): RandAggregation + public static function rand(): RandOperator { - return new RandAggregation(); + return new RandOperator(); } /** @@ -1919,10 +1702,10 @@ public static function rand(): RandAggregation public static function range( ResolvesToInt|int $start, ResolvesToInt|int $end, - ResolvesToInt|Optional|int $step = Optional::Undefined, - ): RangeAggregation + Optional|ResolvesToInt|int $step = Optional::Undefined, + ): RangeOperator { - return new RangeAggregation($start, $end, $step); + return new RangeOperator($start, $end, $step); } /** @@ -1931,9 +1714,9 @@ public static function range( * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/rank/ */ - public static function rank(): RankAggregation + public static function rank(): RankOperator { - return new RankAggregation(); + return new RankOperator(); } /** @@ -1953,9 +1736,9 @@ public static function reduce( PackedArray|ResolvesToArray|BSONArray|array $input, Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $initialValue, Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $in, - ): ReduceAggregation + ): ReduceOperator { - return new ReduceAggregation($input, $initialValue, $in); + return new ReduceOperator($input, $initialValue, $in); } /** @@ -1971,9 +1754,9 @@ public static function regexFind( ResolvesToString|string $input, Regex|ResolvesToString|string $regex, Optional|string $options = Optional::Undefined, - ): RegexFindAggregation + ): RegexFindOperator { - return new RegexFindAggregation($input, $regex, $options); + return new RegexFindOperator($input, $regex, $options); } /** @@ -1989,9 +1772,9 @@ public static function regexFindAll( ResolvesToString|string $input, Regex|ResolvesToString|string $regex, Optional|string $options = Optional::Undefined, - ): RegexFindAllAggregation + ): RegexFindAllOperator { - return new RegexFindAllAggregation($input, $regex, $options); + return new RegexFindAllOperator($input, $regex, $options); } /** @@ -2007,9 +1790,9 @@ public static function regexMatch( ResolvesToString|string $input, Regex|ResolvesToString|string $regex, Optional|string $options = Optional::Undefined, - ): RegexMatchAggregation + ): RegexMatchOperator { - return new RegexMatchAggregation($input, $regex, $options); + return new RegexMatchOperator($input, $regex, $options); } /** @@ -2026,9 +1809,9 @@ public static function replaceAll( ResolvesToNull|ResolvesToString|null|string $input, ResolvesToNull|ResolvesToString|null|string $find, ResolvesToNull|ResolvesToString|null|string $replacement, - ): ReplaceAllAggregation + ): ReplaceAllOperator { - return new ReplaceAllAggregation($input, $find, $replacement); + return new ReplaceAllOperator($input, $find, $replacement); } /** @@ -2044,9 +1827,9 @@ public static function replaceOne( ResolvesToNull|ResolvesToString|null|string $input, ResolvesToNull|ResolvesToString|null|string $find, ResolvesToNull|ResolvesToString|null|string $replacement, - ): ReplaceOneAggregation + ): ReplaceOneOperator { - return new ReplaceOneAggregation($input, $find, $replacement); + return new ReplaceOneOperator($input, $find, $replacement); } /** @@ -2055,11 +1838,9 @@ public static function replaceOne( * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/reverseArray/ * @param BSONArray|PackedArray|ResolvesToArray|array $expression The argument can be any valid expression as long as it resolves to an array. */ - public static function reverseArray( - PackedArray|ResolvesToArray|BSONArray|array $expression, - ): ReverseArrayAggregation + public static function reverseArray(PackedArray|ResolvesToArray|BSONArray|array $expression): ReverseArrayOperator { - return new ReverseArrayAggregation($expression); + return new ReverseArrayOperator($expression); } /** @@ -2072,10 +1853,10 @@ public static function reverseArray( */ public static function round( Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|float|int $number, - ResolvesToInt|Optional|int $place = Optional::Undefined, - ): RoundAggregation + Optional|ResolvesToInt|int $place = Optional::Undefined, + ): RoundOperator { - return new RoundAggregation($number, $place); + return new RoundOperator($number, $place); } /** @@ -2089,10 +1870,10 @@ public static function round( */ public static function rtrim( ResolvesToString|string $input, - ResolvesToString|Optional|string $chars = Optional::Undefined, - ): RtrimAggregation + Optional|ResolvesToString|string $chars = Optional::Undefined, + ): RtrimOperator { - return new RtrimAggregation($input, $chars); + return new RtrimOperator($input, $chars); } /** @@ -2102,9 +1883,9 @@ public static function rtrim( * @param Int64|ResolvesToDouble|float|int $rate 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. */ - public static function sampleRate(Int64|ResolvesToDouble|float|int $rate): SampleRateAggregation + public static function sampleRate(Int64|ResolvesToDouble|float|int $rate): SampleRateOperator { - return new SampleRateAggregation($rate); + return new SampleRateOperator($rate); } /** @@ -2116,10 +1897,10 @@ public static function sampleRate(Int64|ResolvesToDouble|float|int $rate): Sampl */ public static function second( ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, - ResolvesToString|Optional|string $timezone = Optional::Undefined, - ): SecondAggregation + Optional|ResolvesToString|string $timezone = Optional::Undefined, + ): SecondOperator { - return new SecondAggregation($date, $timezone); + return new SecondOperator($date, $timezone); } /** @@ -2132,9 +1913,9 @@ public static function second( public static function setDifference( PackedArray|ResolvesToArray|BSONArray|array $expression1, PackedArray|ResolvesToArray|BSONArray|array $expression2, - ): SetDifferenceAggregation + ): SetDifferenceOperator { - return new SetDifferenceAggregation($expression1, $expression2); + return new SetDifferenceOperator($expression1, $expression2); } /** @@ -2143,9 +1924,9 @@ public static function setDifference( * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/setEquals/ * @param BSONArray|PackedArray|ResolvesToArray|array ...$expression */ - public static function setEquals(PackedArray|ResolvesToArray|BSONArray|array ...$expression): SetEqualsAggregation + public static function setEquals(PackedArray|ResolvesToArray|BSONArray|array ...$expression): SetEqualsOperator { - return new SetEqualsAggregation(...$expression); + return new SetEqualsOperator(...$expression); } /** @@ -2162,9 +1943,9 @@ public static function setField( ResolvesToString|string $field, Document|Serializable|ResolvesToObject|stdClass|array $input, Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $value, - ): SetFieldAggregation + ): SetFieldOperator { - return new SetFieldAggregation($field, $input, $value); + return new SetFieldOperator($field, $input, $value); } /** @@ -2175,9 +1956,9 @@ public static function setField( */ public static function setIntersection( PackedArray|ResolvesToArray|BSONArray|array ...$expression, - ): SetIntersectionAggregation + ): SetIntersectionOperator { - return new SetIntersectionAggregation(...$expression); + return new SetIntersectionOperator(...$expression); } /** @@ -2190,9 +1971,9 @@ public static function setIntersection( public static function setIsSubset( PackedArray|ResolvesToArray|BSONArray|array $expression1, PackedArray|ResolvesToArray|BSONArray|array $expression2, - ): SetIsSubsetAggregation + ): SetIsSubsetOperator { - return new SetIsSubsetAggregation($expression1, $expression2); + return new SetIsSubsetOperator($expression1, $expression2); } /** @@ -2201,9 +1982,9 @@ public static function setIsSubset( * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/setUnion/ * @param BSONArray|PackedArray|ResolvesToArray|array ...$expression */ - public static function setUnion(PackedArray|ResolvesToArray|BSONArray|array ...$expression): SetUnionAggregation + public static function setUnion(PackedArray|ResolvesToArray|BSONArray|array ...$expression): SetUnionOperator { - return new SetUnionAggregation(...$expression); + return new SetUnionOperator(...$expression); } /** @@ -2225,37 +2006,33 @@ public static function shift( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $output, int $by, Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $default, - ): ShiftAggregation + ): ShiftOperator { - return new ShiftAggregation($output, $by, $default); + return new ShiftOperator($output, $by, $default); } /** * Returns the sine of a value that is measured in radians. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/sin/ - * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression $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. + * @param Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $expression $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. */ - public static function sin( - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression, - ): SinAggregation + public static function sin(Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $expression): SinOperator { - return new SinAggregation($expression); + return new SinOperator($expression); } /** * Returns the hyperbolic sine of a value that is measured in radians. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/sinh/ - * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression $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. + * @param Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $expression $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. */ - public static function sinh( - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression, - ): SinhAggregation + public static function sinh(Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $expression): SinhOperator { - return new SinhAggregation($expression); + return new SinhOperator($expression); } /** @@ -2264,9 +2041,9 @@ public static function sinh( * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/size/ * @param BSONArray|PackedArray|ResolvesToArray|array $expression The argument for $size can be any expression as long as it resolves to an array. */ - public static function size(PackedArray|ResolvesToArray|BSONArray|array $expression): SizeAggregation + public static function size(PackedArray|ResolvesToArray|BSONArray|array $expression): SizeOperator { - return new SizeAggregation($expression); + return new SizeOperator($expression); } /** @@ -2284,10 +2061,10 @@ public static function size(PackedArray|ResolvesToArray|BSONArray|array $express public static function slice( PackedArray|ResolvesToArray|BSONArray|array $expression, ResolvesToInt|int $n, - ResolvesToInt|Optional|int $position = Optional::Undefined, - ): SliceAggregation + Optional|ResolvesToInt|int $position = Optional::Undefined, + ): SliceOperator { - return new SliceAggregation($expression, $n, $position); + return new SliceOperator($expression, $n, $position); } /** @@ -2300,9 +2077,9 @@ public static function slice( public static function sortArray( PackedArray|ResolvesToArray|BSONArray|array $input, Document|Serializable|stdClass|array $sortBy, - ): SortArrayAggregation + ): SortArrayOperator { - return new SortArrayAggregation($input, $sortBy); + return new SortArrayOperator($input, $sortBy); } /** @@ -2312,25 +2089,20 @@ public static function sortArray( * @param ResolvesToString|non-empty-string $string The string to be split. string expression can be any valid expression as long as it resolves to a string. * @param ResolvesToString|non-empty-string $delimiter The delimiter to use when splitting the string expression. delimiter can be any valid expression as long as it resolves to a string. */ - public static function split( - ResolvesToString|string $string, - ResolvesToString|string $delimiter, - ): SplitAggregation + public static function split(ResolvesToString|string $string, ResolvesToString|string $delimiter): SplitOperator { - return new SplitAggregation($string, $delimiter); + return new SplitOperator($string, $delimiter); } /** * Calculates the square root. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/sqrt/ - * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $number The argument can be any valid expression as long as it resolves to a non-negative number. + * @param Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $number The argument can be any valid expression as long as it resolves to a non-negative number. */ - public static function sqrt( - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $number, - ): SqrtAggregation + public static function sqrt(Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $number): SqrtOperator { - return new SqrtAggregation($number); + return new SqrtOperator($number); } /** @@ -2339,13 +2111,13 @@ public static function sqrt( * Changed in version 5.0: Available in the $setWindowFields stage. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/stdDevPop/ - * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int ...$expression + * @param Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int ...$expression */ public static function stdDevPop( - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int ...$expression, - ): StdDevPopAggregation + Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int ...$expression, + ): StdDevPopOperator { - return new StdDevPopAggregation(...$expression); + return new StdDevPopOperator(...$expression); } /** @@ -2354,13 +2126,13 @@ public static function stdDevPop( * Changed in version 5.0: Available in the $setWindowFields stage. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/stdDevSamp/ - * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int ...$expression + * @param Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int ...$expression */ public static function stdDevSamp( - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int ...$expression, - ): StdDevSampAggregation + Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int ...$expression, + ): StdDevSampOperator { - return new StdDevSampAggregation(...$expression); + return new StdDevSampOperator(...$expression); } /** @@ -2373,9 +2145,9 @@ public static function stdDevSamp( public static function strcasecmp( ResolvesToString|string $expression1, ResolvesToString|string $expression2, - ): StrcasecmpAggregation + ): StrcasecmpOperator { - return new StrcasecmpAggregation($expression1, $expression2); + return new StrcasecmpOperator($expression1, $expression2); } /** @@ -2384,9 +2156,9 @@ public static function strcasecmp( * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/strLenBytes/ * @param ResolvesToString|non-empty-string $expression */ - public static function strLenBytes(ResolvesToString|string $expression): StrLenBytesAggregation + public static function strLenBytes(ResolvesToString|string $expression): StrLenBytesOperator { - return new StrLenBytesAggregation($expression); + return new StrLenBytesOperator($expression); } /** @@ -2395,9 +2167,9 @@ public static function strLenBytes(ResolvesToString|string $expression): StrLenB * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/strLenCP/ * @param ResolvesToString|non-empty-string $expression */ - public static function strLenCP(ResolvesToString|string $expression): StrLenCPAggregation + public static function strLenCP(ResolvesToString|string $expression): StrLenCPOperator { - return new StrLenCPAggregation($expression); + return new StrLenCPOperator($expression); } /** @@ -2412,9 +2184,9 @@ public static function substr( ResolvesToString|string $string, ResolvesToInt|int $start, ResolvesToInt|int $length, - ): SubstrAggregation + ): SubstrOperator { - return new SubstrAggregation($string, $start, $length); + return new SubstrOperator($string, $start, $length); } /** @@ -2429,9 +2201,9 @@ public static function substrBytes( ResolvesToString|string $string, ResolvesToInt|int $start, ResolvesToInt|int $length, - ): SubstrBytesAggregation + ): SubstrBytesOperator { - return new SubstrBytesAggregation($string, $start, $length); + return new SubstrBytesOperator($string, $start, $length); } /** @@ -2446,24 +2218,24 @@ public static function substrCP( ResolvesToString|string $string, ResolvesToInt|int $start, ResolvesToInt|int $length, - ): SubstrCPAggregation + ): SubstrCPOperator { - return new SubstrCPAggregation($string, $start, $length); + return new SubstrCPOperator($string, $start, $length); } /** * 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. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/subtract/ - * @param Decimal128|Int64|ResolvesToDate|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|UTCDateTime|float|int $expression1 - * @param Decimal128|Int64|ResolvesToDate|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|UTCDateTime|float|int $expression2 + * @param Decimal128|Int64|ResolvesToDate|ResolvesToInt|ResolvesToNumber|UTCDateTime|float|int $expression1 + * @param Decimal128|Int64|ResolvesToDate|ResolvesToInt|ResolvesToNumber|UTCDateTime|float|int $expression2 */ public static function subtract( - Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression1, - Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression2, - ): SubtractAggregation + Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToInt|ResolvesToNumber|float|int $expression1, + Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToInt|ResolvesToNumber|float|int $expression2, + ): SubtractOperator { - return new SubtractAggregation($expression1, $expression2); + return new SubtractOperator($expression1, $expression2); } /** @@ -2471,13 +2243,11 @@ public static function subtract( * Changed in version 5.0: Available in the $setWindowFields stage. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/sum/ - * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int ...$expression + * @param Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int ...$expression */ - public static function sum( - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int ...$expression, - ): SumAggregation + public static function sum(Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int ...$expression): SumOperator { - return new SumAggregation(...$expression); + return new SumOperator(...$expression); } /** @@ -2488,43 +2258,39 @@ public static function sum( * - 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. - * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|Optional|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $default The path to take if no branch case expression evaluates to true. + * @param Optional|BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $default 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. */ public static function switch( PackedArray|BSONArray|array $branches, - Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|Optional|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $default = Optional::Undefined, - ): SwitchAggregation + Optional|Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $default = Optional::Undefined, + ): SwitchOperator { - return new SwitchAggregation($branches, $default); + return new SwitchOperator($branches, $default); } /** * Returns the tangent of a value that is measured in radians. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/tan/ - * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression $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. + * @param Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $expression $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. */ - public static function tan( - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression, - ): TanAggregation + public static function tan(Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $expression): TanOperator { - return new TanAggregation($expression); + return new TanOperator($expression); } /** * Returns the hyperbolic tangent of a value that is measured in radians. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/tanh/ - * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression $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. + * @param Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $expression $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. */ - public static function tanh( - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $expression, - ): TanhAggregation + public static function tanh(Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $expression): TanhOperator { - return new TanhAggregation($expression); + return new TanhOperator($expression); } /** @@ -2536,9 +2302,9 @@ public static function tanh( */ public static function toBool( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, - ): ToBoolAggregation + ): ToBoolOperator { - return new ToBoolAggregation($expression); + return new ToBoolOperator($expression); } /** @@ -2550,9 +2316,9 @@ public static function toBool( */ public static function toDate( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, - ): ToDateAggregation + ): ToDateOperator { - return new ToDateAggregation($expression); + return new ToDateOperator($expression); } /** @@ -2564,9 +2330,9 @@ public static function toDate( */ public static function toDecimal( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, - ): ToDecimalAggregation + ): ToDecimalOperator { - return new ToDecimalAggregation($expression); + return new ToDecimalOperator($expression); } /** @@ -2578,9 +2344,9 @@ public static function toDecimal( */ public static function toDouble( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, - ): ToDoubleAggregation + ): ToDoubleOperator { - return new ToDoubleAggregation($expression); + return new ToDoubleOperator($expression); } /** @@ -2592,9 +2358,9 @@ public static function toDouble( */ public static function toInt( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, - ): ToIntAggregation + ): ToIntOperator { - return new ToIntAggregation($expression); + return new ToIntOperator($expression); } /** @@ -2606,9 +2372,9 @@ public static function toInt( */ public static function toLong( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, - ): ToLongAggregation + ): ToLongOperator { - return new ToLongAggregation($expression); + return new ToLongOperator($expression); } /** @@ -2617,9 +2383,9 @@ public static function toLong( * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toLower/ * @param ResolvesToString|non-empty-string $expression */ - public static function toLower(ResolvesToString|string $expression): ToLowerAggregation + public static function toLower(ResolvesToString|string $expression): ToLowerOperator { - return new ToLowerAggregation($expression); + return new ToLowerOperator($expression); } /** @@ -2631,9 +2397,9 @@ public static function toLower(ResolvesToString|string $expression): ToLowerAggr */ public static function toObjectId( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, - ): ToObjectIdAggregation + ): ToObjectIdOperator { - return new ToObjectIdAggregation($expression); + return new ToObjectIdOperator($expression); } /** @@ -2649,9 +2415,9 @@ public static function toObjectId( public static function top( Document|Serializable|stdClass|array $sortBy, Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $output, - ): TopAggregation + ): TopOperator { - return new TopAggregation($sortBy, $output); + return new TopOperator($sortBy, $output); } /** @@ -2669,9 +2435,9 @@ public static function topN( ResolvesToInt|int $n, Document|Serializable|stdClass|array $sortBy, Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $output, - ): TopNAggregation + ): TopNOperator { - return new TopNAggregation($n, $sortBy, $output); + return new TopNOperator($n, $sortBy, $output); } /** @@ -2683,9 +2449,9 @@ public static function topN( */ public static function toString( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, - ): ToStringAggregation + ): ToStringOperator { - return new ToStringAggregation($expression); + return new ToStringOperator($expression); } /** @@ -2694,9 +2460,9 @@ public static function toString( * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toUpper/ * @param ResolvesToString|non-empty-string $expression */ - public static function toUpper(ResolvesToString|string $expression): ToUpperAggregation + public static function toUpper(ResolvesToString|string $expression): ToUpperOperator { - return new ToUpperAggregation($expression); + return new ToUpperOperator($expression); } /** @@ -2711,26 +2477,26 @@ public static function toUpper(ResolvesToString|string $expression): ToUpperAggr */ public static function trim( ResolvesToString|string $input, - ResolvesToString|Optional|string $chars = Optional::Undefined, - ): TrimAggregation + Optional|ResolvesToString|string $chars = Optional::Undefined, + ): TrimOperator { - return new TrimAggregation($input, $chars); + return new TrimOperator($input, $chars); } /** * Truncates a number to a whole integer or to a specified decimal place. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/trunc/ - * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $number Can be any valid expression that resolves to a number. Specifically, the expression must resolve to an integer, double, decimal, or long. + * @param Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $number 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. * @param Optional|ResolvesToInt|int $place Can be any valid expression that resolves to an integer between -20 and 100, exclusive. e.g. -20 < place < 100. Defaults to 0. */ public static function trunc( - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $number, - ResolvesToInt|Optional|int $place = Optional::Undefined, - ): TruncAggregation + Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $number, + Optional|ResolvesToInt|int $place = Optional::Undefined, + ): TruncOperator { - return new TruncAggregation($number, $place); + return new TruncOperator($number, $place); } /** @@ -2740,9 +2506,9 @@ public static function trunc( * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/tsIncrement/ * @param ResolvesToTimestamp|Timestamp|int $expression */ - public static function tsIncrement(Timestamp|ResolvesToTimestamp|int $expression): TsIncrementAggregation + public static function tsIncrement(Timestamp|ResolvesToTimestamp|int $expression): TsIncrementOperator { - return new TsIncrementAggregation($expression); + return new TsIncrementOperator($expression); } /** @@ -2752,9 +2518,9 @@ public static function tsIncrement(Timestamp|ResolvesToTimestamp|int $expression * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/tsSecond/ * @param ResolvesToTimestamp|Timestamp|int $expression */ - public static function tsSecond(Timestamp|ResolvesToTimestamp|int $expression): TsSecondAggregation + public static function tsSecond(Timestamp|ResolvesToTimestamp|int $expression): TsSecondOperator { - return new TsSecondAggregation($expression); + return new TsSecondOperator($expression); } /** @@ -2765,9 +2531,9 @@ public static function tsSecond(Timestamp|ResolvesToTimestamp|int $expression): */ public static function type( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, - ): TypeAggregation + ): TypeOperator { - return new TypeAggregation($expression); + return new TypeOperator($expression); } /** @@ -2781,9 +2547,9 @@ public static function type( public static function unsetField( ResolvesToString|string $field, Document|Serializable|ResolvesToObject|stdClass|array $input, - ): UnsetFieldAggregation + ): UnsetFieldOperator { - return new UnsetFieldAggregation($field, $input); + return new UnsetFieldOperator($field, $input); } /** @@ -2795,10 +2561,10 @@ public static function unsetField( */ public static function week( ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, - ResolvesToString|Optional|string $timezone = Optional::Undefined, - ): WeekAggregation + Optional|ResolvesToString|string $timezone = Optional::Undefined, + ): WeekOperator { - return new WeekAggregation($date, $timezone); + return new WeekOperator($date, $timezone); } /** @@ -2810,10 +2576,10 @@ public static function week( */ public static function year( ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, - ResolvesToString|Optional|string $timezone = Optional::Undefined, - ): YearAggregation + Optional|ResolvesToString|string $timezone = Optional::Undefined, + ): YearOperator { - return new YearAggregation($date, $timezone); + return new YearOperator($date, $timezone); } /** @@ -2833,15 +2599,8 @@ public static function zip( PackedArray|ResolvesToArray|BSONArray|array $inputs, bool $useLongestLength, PackedArray|BSONArray|array $defaults, - ): ZipAggregation - { - return new ZipAggregation($inputs, $useLongestLength, $defaults); - } - - /** - * This class cannot be instantiated. - */ - private function __construct() + ): ZipOperator { + return new ZipOperator($inputs, $useLongestLength, $defaults); } } diff --git a/src/Builder/Aggregation/FilterAggregation.php b/src/Builder/Expression/FilterOperator.php similarity index 90% rename from src/Builder/Aggregation/FilterAggregation.php rename to src/Builder/Expression/FilterOperator.php index f1ff46d9e..8e81e34fd 100644 --- a/src/Builder/Aggregation/FilterAggregation.php +++ b/src/Builder/Expression/FilterOperator.php @@ -4,14 +4,12 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\PackedArray; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToArray; -use MongoDB\Builder\Expression\ResolvesToBool; -use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Optional; +use MongoDB\Builder\Type\ProjectionInterface; use MongoDB\Model\BSONArray; /** @@ -19,7 +17,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/filter/ */ -class FilterAggregation implements ResolvesToArray +class FilterOperator implements ResolvesToArray, ProjectionInterface { public const NAME = '$filter'; public const ENCODE = \MongoDB\Builder\Encode::Object; @@ -37,7 +35,7 @@ class FilterAggregation implements ResolvesToArray * @param Optional|ResolvesToInt|int $limit 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. */ - public ResolvesToInt|Optional|int $limit; + public Optional|ResolvesToInt|int $limit; /** * @param BSONArray|PackedArray|ResolvesToArray|array $input @@ -50,7 +48,7 @@ public function __construct( PackedArray|ResolvesToArray|BSONArray|array $input, ResolvesToBool|bool $cond, Optional|string $as = Optional::Undefined, - ResolvesToInt|Optional|int $limit = Optional::Undefined, + Optional|ResolvesToInt|int $limit = Optional::Undefined, ) { if (\is_array($input) && ! \array_is_list($input)) { throw new \InvalidArgumentException('Expected $input argument to be a list, got an associative array.'); diff --git a/src/Builder/Aggregation/FirstNAggregation.php b/src/Builder/Expression/FirstNOperator.php similarity index 89% rename from src/Builder/Aggregation/FirstNAggregation.php rename to src/Builder/Expression/FirstNOperator.php index 2c0340a89..811b023f5 100644 --- a/src/Builder/Aggregation/FirstNAggregation.php +++ b/src/Builder/Expression/FirstNOperator.php @@ -4,13 +4,12 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\PackedArray; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToArray; -use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Type\AccumulatorInterface; +use MongoDB\Builder\Type\WindowInterface; use MongoDB\Model\BSONArray; /** @@ -18,7 +17,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/firstN-array-element/ */ -class FirstNAggregation implements AccumulatorInterface +class FirstNOperator implements AccumulatorInterface, WindowInterface { public const NAME = '$firstN'; public const ENCODE = \MongoDB\Builder\Encode::Object; diff --git a/src/Builder/Aggregation/FirstAggregation.php b/src/Builder/Expression/FirstOperator.php similarity index 81% rename from src/Builder/Aggregation/FirstAggregation.php rename to src/Builder/Expression/FirstOperator.php index 6cf21dcc8..353712247 100644 --- a/src/Builder/Aggregation/FirstAggregation.php +++ b/src/Builder/Expression/FirstOperator.php @@ -4,7 +4,7 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Binary; use MongoDB\BSON\Decimal128; @@ -17,10 +17,9 @@ use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToAny; -use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Type\AccumulatorInterface; use MongoDB\Builder\Type\ExpressionInterface; +use MongoDB\Builder\Type\WindowInterface; use MongoDB\Model\BSONArray; use stdClass; @@ -30,7 +29,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/first/ */ -class FirstAggregation implements ResolvesToAny, AccumulatorInterface +class FirstOperator implements AccumulatorInterface, WindowInterface { public const NAME = '$first'; public const ENCODE = \MongoDB\Builder\Encode::Single; @@ -44,10 +43,6 @@ class FirstAggregation implements ResolvesToAny, AccumulatorInterface public function __construct( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, ) { - if (\is_array($expression) && ! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression argument to be a list, got an associative array.'); - } - $this->expression = $expression; } } diff --git a/src/Builder/Expression/FloorOperator.php b/src/Builder/Expression/FloorOperator.php new file mode 100644 index 000000000..f113ff5f7 --- /dev/null +++ b/src/Builder/Expression/FloorOperator.php @@ -0,0 +1,33 @@ +expression = $expression; + } +} diff --git a/src/Builder/Aggregation/FunctionAggregation.php b/src/Builder/Expression/FunctionOperator.php similarity index 92% rename from src/Builder/Aggregation/FunctionAggregation.php rename to src/Builder/Expression/FunctionOperator.php index c4241081c..1c6d3faab 100644 --- a/src/Builder/Aggregation/FunctionAggregation.php +++ b/src/Builder/Expression/FunctionOperator.php @@ -4,11 +4,10 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\PackedArray; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToAny; use MongoDB\Model\BSONArray; /** @@ -17,7 +16,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/function/ */ -class FunctionAggregation implements ResolvesToAny +class FunctionOperator implements ResolvesToAny { public const NAME = '$function'; public const ENCODE = \MongoDB\Builder\Encode::Object; diff --git a/src/Builder/Aggregation/GetFieldAggregation.php b/src/Builder/Expression/GetFieldOperator.php similarity index 74% rename from src/Builder/Aggregation/GetFieldAggregation.php rename to src/Builder/Expression/GetFieldOperator.php index 0a86988db..64b0140e9 100644 --- a/src/Builder/Aggregation/GetFieldAggregation.php +++ b/src/Builder/Expression/GetFieldOperator.php @@ -4,7 +4,7 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Binary; use MongoDB\BSON\Decimal128; @@ -17,8 +17,6 @@ use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToAny; -use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Optional; use MongoDB\Builder\Type\ExpressionInterface; use MongoDB\Model\BSONArray; @@ -30,7 +28,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/getField/ */ -class GetFieldAggregation implements ResolvesToAny +class GetFieldOperator implements ResolvesToAny { public const NAME = '$getField'; public const ENCODE = \MongoDB\Builder\Encode::Object; @@ -42,26 +40,22 @@ class GetFieldAggregation implements ResolvesToAny public string $field; /** - * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|Optional|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $input Default: $$CURRENT + * @param Optional|BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $input 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). */ - public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|Optional|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $input; + public Optional|Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $input; /** * @param non-empty-string $field 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. - * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|Optional|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $input Default: $$CURRENT + * @param Optional|BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $input 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). */ public function __construct( string $field, - Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|Optional|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $input = Optional::Undefined, + Optional|Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $input = Optional::Undefined, ) { $this->field = $field; - if (\is_array($input) && ! \array_is_list($input)) { - throw new \InvalidArgumentException('Expected $input argument to be a list, got an associative array.'); - } - $this->input = $input; } } diff --git a/src/Builder/Aggregation/GtAggregation.php b/src/Builder/Expression/GtOperator.php similarity index 81% rename from src/Builder/Aggregation/GtAggregation.php rename to src/Builder/Expression/GtOperator.php index 473046050..ab6ee3e40 100644 --- a/src/Builder/Aggregation/GtAggregation.php +++ b/src/Builder/Expression/GtOperator.php @@ -4,7 +4,7 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Binary; use MongoDB\BSON\Decimal128; @@ -17,8 +17,6 @@ use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToBool; -use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Type\ExpressionInterface; use MongoDB\Model\BSONArray; use stdClass; @@ -28,7 +26,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/gt/ */ -class GtAggregation implements ResolvesToBool +class GtOperator implements ResolvesToBool { public const NAME = '$gt'; public const ENCODE = \MongoDB\Builder\Encode::Array; @@ -47,15 +45,7 @@ public function __construct( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression1, Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression2, ) { - if (\is_array($expression1) && ! \array_is_list($expression1)) { - throw new \InvalidArgumentException('Expected $expression1 argument to be a list, got an associative array.'); - } - $this->expression1 = $expression1; - if (\is_array($expression2) && ! \array_is_list($expression2)) { - throw new \InvalidArgumentException('Expected $expression2 argument to be a list, got an associative array.'); - } - $this->expression2 = $expression2; } } diff --git a/src/Builder/Aggregation/GteAggregation.php b/src/Builder/Expression/GteOperator.php similarity index 81% rename from src/Builder/Aggregation/GteAggregation.php rename to src/Builder/Expression/GteOperator.php index 43e709fce..610ae616f 100644 --- a/src/Builder/Aggregation/GteAggregation.php +++ b/src/Builder/Expression/GteOperator.php @@ -4,7 +4,7 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Binary; use MongoDB\BSON\Decimal128; @@ -17,8 +17,6 @@ use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToBool; -use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Type\ExpressionInterface; use MongoDB\Model\BSONArray; use stdClass; @@ -28,7 +26,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/gte/ */ -class GteAggregation implements ResolvesToBool +class GteOperator implements ResolvesToBool { public const NAME = '$gte'; public const ENCODE = \MongoDB\Builder\Encode::Array; @@ -47,15 +45,7 @@ public function __construct( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression1, Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression2, ) { - if (\is_array($expression1) && ! \array_is_list($expression1)) { - throw new \InvalidArgumentException('Expected $expression1 argument to be a list, got an associative array.'); - } - $this->expression1 = $expression1; - if (\is_array($expression2) && ! \array_is_list($expression2)) { - throw new \InvalidArgumentException('Expected $expression2 argument to be a list, got an associative array.'); - } - $this->expression2 = $expression2; } } diff --git a/src/Builder/Aggregation/HourAggregation.php b/src/Builder/Expression/HourOperator.php similarity index 80% rename from src/Builder/Aggregation/HourAggregation.php rename to src/Builder/Expression/HourOperator.php index cb44ef497..04e175659 100644 --- a/src/Builder/Aggregation/HourAggregation.php +++ b/src/Builder/Expression/HourOperator.php @@ -4,17 +4,12 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\ObjectId; use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToDate; -use MongoDB\Builder\Expression\ResolvesToInt; -use MongoDB\Builder\Expression\ResolvesToObjectId; -use MongoDB\Builder\Expression\ResolvesToString; -use MongoDB\Builder\Expression\ResolvesToTimestamp; use MongoDB\Builder\Optional; /** @@ -22,7 +17,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/hour/ */ -class HourAggregation implements ResolvesToInt +class HourOperator implements ResolvesToInt { public const NAME = '$hour'; public const ENCODE = \MongoDB\Builder\Encode::Object; @@ -31,7 +26,7 @@ class HourAggregation implements ResolvesToInt public ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; /** @param Optional|ResolvesToString|non-empty-string $timezone 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. */ - public ResolvesToString|Optional|string $timezone; + public Optional|ResolvesToString|string $timezone; /** * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. @@ -39,7 +34,7 @@ class HourAggregation implements ResolvesToInt */ public function __construct( ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, - ResolvesToString|Optional|string $timezone = Optional::Undefined, + Optional|ResolvesToString|string $timezone = Optional::Undefined, ) { $this->date = $date; $this->timezone = $timezone; diff --git a/src/Builder/Aggregation/IfNullAggregation.php b/src/Builder/Expression/IfNullOperator.php similarity index 92% rename from src/Builder/Aggregation/IfNullAggregation.php rename to src/Builder/Expression/IfNullOperator.php index 52d949e7d..99e3d07fc 100644 --- a/src/Builder/Aggregation/IfNullAggregation.php +++ b/src/Builder/Expression/IfNullOperator.php @@ -4,7 +4,7 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Binary; use MongoDB\BSON\Decimal128; @@ -17,8 +17,6 @@ use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToAny; -use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Type\ExpressionInterface; use MongoDB\Model\BSONArray; use stdClass; @@ -28,7 +26,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/ifNull/ */ -class IfNullAggregation implements ResolvesToAny +class IfNullOperator implements ResolvesToAny { public const NAME = '$ifNull'; public const ENCODE = \MongoDB\Builder\Encode::Single; diff --git a/src/Builder/Aggregation/InAggregation.php b/src/Builder/Expression/InOperator.php similarity index 84% rename from src/Builder/Aggregation/InAggregation.php rename to src/Builder/Expression/InOperator.php index a35e185bc..2589c6cbd 100644 --- a/src/Builder/Aggregation/InAggregation.php +++ b/src/Builder/Expression/InOperator.php @@ -4,7 +4,7 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Binary; use MongoDB\BSON\Decimal128; @@ -17,9 +17,6 @@ use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToArray; -use MongoDB\Builder\Expression\ResolvesToBool; -use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Type\ExpressionInterface; use MongoDB\Model\BSONArray; use stdClass; @@ -29,7 +26,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/in/ */ -class InAggregation implements ResolvesToBool +class InOperator implements ResolvesToBool { public const NAME = '$in'; public const ENCODE = \MongoDB\Builder\Encode::Array; @@ -48,10 +45,6 @@ public function __construct( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, PackedArray|ResolvesToArray|BSONArray|array $array, ) { - if (\is_array($expression) && ! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression argument to be a list, got an associative array.'); - } - $this->expression = $expression; if (\is_array($array) && ! \array_is_list($array)) { throw new \InvalidArgumentException('Expected $array argument to be a list, got an associative array.'); diff --git a/src/Builder/Aggregation/IndexOfArrayAggregation.php b/src/Builder/Expression/IndexOfArrayOperator.php similarity index 88% rename from src/Builder/Aggregation/IndexOfArrayAggregation.php rename to src/Builder/Expression/IndexOfArrayOperator.php index 6f8ec09bb..ca5bc46ad 100644 --- a/src/Builder/Aggregation/IndexOfArrayAggregation.php +++ b/src/Builder/Expression/IndexOfArrayOperator.php @@ -4,7 +4,7 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Binary; use MongoDB\BSON\Decimal128; @@ -17,8 +17,6 @@ use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToInt; -use MongoDB\Builder\Expression\ResolvesToString; use MongoDB\Builder\Optional; use MongoDB\Builder\Type\ExpressionInterface; use MongoDB\Model\BSONArray; @@ -29,7 +27,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/indexOfArray/ */ -class IndexOfArrayAggregation implements ResolvesToInt +class IndexOfArrayOperator implements ResolvesToInt { public const NAME = '$indexOfArray'; public const ENCODE = \MongoDB\Builder\Encode::Array; @@ -48,13 +46,13 @@ class IndexOfArrayAggregation implements ResolvesToInt * @param Optional|ResolvesToInt|int $start 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. */ - public ResolvesToInt|Optional|int $start; + public Optional|ResolvesToInt|int $start; /** * @param Optional|ResolvesToInt|int $end 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. */ - public ResolvesToInt|Optional|int $end; + public Optional|ResolvesToInt|int $end; /** * @param ResolvesToString|non-empty-string $array Can be any valid expression as long as it resolves to an array. @@ -69,14 +67,10 @@ class IndexOfArrayAggregation implements ResolvesToInt public function __construct( ResolvesToString|string $array, Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $search, - ResolvesToInt|Optional|int $start = Optional::Undefined, - ResolvesToInt|Optional|int $end = Optional::Undefined, + Optional|ResolvesToInt|int $start = Optional::Undefined, + Optional|ResolvesToInt|int $end = Optional::Undefined, ) { $this->array = $array; - if (\is_array($search) && ! \array_is_list($search)) { - throw new \InvalidArgumentException('Expected $search argument to be a list, got an associative array.'); - } - $this->search = $search; $this->start = $start; $this->end = $end; diff --git a/src/Builder/Aggregation/IndexOfBytesAggregation.php b/src/Builder/Expression/IndexOfBytesOperator.php similarity index 90% rename from src/Builder/Aggregation/IndexOfBytesAggregation.php rename to src/Builder/Expression/IndexOfBytesOperator.php index fa19ae992..d86433c94 100644 --- a/src/Builder/Aggregation/IndexOfBytesAggregation.php +++ b/src/Builder/Expression/IndexOfBytesOperator.php @@ -4,11 +4,9 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToInt; -use MongoDB\Builder\Expression\ResolvesToString; use MongoDB\Builder\Optional; /** @@ -16,7 +14,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/indexOfBytes/ */ -class IndexOfBytesAggregation implements ResolvesToInt +class IndexOfBytesOperator implements ResolvesToInt { public const NAME = '$indexOfBytes'; public const ENCODE = \MongoDB\Builder\Encode::Array; @@ -35,13 +33,13 @@ class IndexOfBytesAggregation implements ResolvesToInt * @param Optional|ResolvesToInt|int $start 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. */ - public ResolvesToInt|Optional|int $start; + public Optional|ResolvesToInt|int $start; /** * @param Optional|ResolvesToInt|int $end 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. */ - public ResolvesToInt|Optional|int $end; + public Optional|ResolvesToInt|int $end; /** * @param ResolvesToString|non-empty-string $string Can be any valid expression as long as it resolves to a string. @@ -56,8 +54,8 @@ class IndexOfBytesAggregation implements ResolvesToInt public function __construct( ResolvesToString|string $string, ResolvesToString|string $substring, - ResolvesToInt|Optional|int $start = Optional::Undefined, - ResolvesToInt|Optional|int $end = Optional::Undefined, + Optional|ResolvesToInt|int $start = Optional::Undefined, + Optional|ResolvesToInt|int $end = Optional::Undefined, ) { $this->string = $string; $this->substring = $substring; diff --git a/src/Builder/Aggregation/IndexOfCPAggregation.php b/src/Builder/Expression/IndexOfCPOperator.php similarity index 90% rename from src/Builder/Aggregation/IndexOfCPAggregation.php rename to src/Builder/Expression/IndexOfCPOperator.php index 78b9dd331..bfa7337fd 100644 --- a/src/Builder/Aggregation/IndexOfCPAggregation.php +++ b/src/Builder/Expression/IndexOfCPOperator.php @@ -4,11 +4,9 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToInt; -use MongoDB\Builder\Expression\ResolvesToString; use MongoDB\Builder\Optional; /** @@ -16,7 +14,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/indexOfCP/ */ -class IndexOfCPAggregation implements ResolvesToInt +class IndexOfCPOperator implements ResolvesToInt { public const NAME = '$indexOfCP'; public const ENCODE = \MongoDB\Builder\Encode::Array; @@ -35,13 +33,13 @@ class IndexOfCPAggregation implements ResolvesToInt * @param Optional|ResolvesToInt|int $start 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. */ - public ResolvesToInt|Optional|int $start; + public Optional|ResolvesToInt|int $start; /** * @param Optional|ResolvesToInt|int $end 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. */ - public ResolvesToInt|Optional|int $end; + public Optional|ResolvesToInt|int $end; /** * @param ResolvesToString|non-empty-string $string Can be any valid expression as long as it resolves to a string. @@ -56,8 +54,8 @@ class IndexOfCPAggregation implements ResolvesToInt public function __construct( ResolvesToString|string $string, ResolvesToString|string $substring, - ResolvesToInt|Optional|int $start = Optional::Undefined, - ResolvesToInt|Optional|int $end = Optional::Undefined, + Optional|ResolvesToInt|int $start = Optional::Undefined, + Optional|ResolvesToInt|int $end = Optional::Undefined, ) { $this->string = $string; $this->substring = $substring; diff --git a/src/Builder/Aggregation/IntegralAggregation.php b/src/Builder/Expression/IntegralOperator.php similarity index 54% rename from src/Builder/Aggregation/IntegralAggregation.php rename to src/Builder/Expression/IntegralOperator.php index 8f39d9f73..056a5039f 100644 --- a/src/Builder/Aggregation/IntegralAggregation.php +++ b/src/Builder/Expression/IntegralOperator.php @@ -4,19 +4,12 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Decimal128; use MongoDB\BSON\Int64; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToDate; -use MongoDB\Builder\Expression\ResolvesToDecimal; -use MongoDB\Builder\Expression\ResolvesToDouble; -use MongoDB\Builder\Expression\ResolvesToInt; -use MongoDB\Builder\Expression\ResolvesToLong; -use MongoDB\Builder\Expression\ResolvesToNumber; -use MongoDB\Builder\Expression\ResolvesToString; use MongoDB\Builder\Optional; /** @@ -25,28 +18,28 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/integral/ */ -class IntegralAggregation implements ResolvesToDouble, ResolvesToDecimal +class IntegralOperator implements ResolvesToDouble, ResolvesToDecimal { public const NAME = '$integral'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param Decimal128|Int64|ResolvesToDate|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|UTCDateTime|float|int $input */ - public Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $input; + /** @param Decimal128|Int64|ResolvesToDate|ResolvesToInt|ResolvesToNumber|UTCDateTime|float|int $input */ + public Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToInt|ResolvesToNumber|float|int $input; /** * @param Optional|ResolvesToString|non-empty-string $unit 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. */ - public ResolvesToString|Optional|string $unit; + public Optional|ResolvesToString|string $unit; /** - * @param Decimal128|Int64|ResolvesToDate|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|UTCDateTime|float|int $input + * @param Decimal128|Int64|ResolvesToDate|ResolvesToInt|ResolvesToNumber|UTCDateTime|float|int $input * @param Optional|ResolvesToString|non-empty-string $unit 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. */ public function __construct( - Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $input, - ResolvesToString|Optional|string $unit = Optional::Undefined, + Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToInt|ResolvesToNumber|float|int $input, + Optional|ResolvesToString|string $unit = Optional::Undefined, ) { $this->input = $input; $this->unit = $unit; diff --git a/src/Builder/Aggregation/IsArrayAggregation.php b/src/Builder/Expression/IsArrayOperator.php similarity index 91% rename from src/Builder/Aggregation/IsArrayAggregation.php rename to src/Builder/Expression/IsArrayOperator.php index 990759f0d..c230541ff 100644 --- a/src/Builder/Aggregation/IsArrayAggregation.php +++ b/src/Builder/Expression/IsArrayOperator.php @@ -4,7 +4,7 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Binary; use MongoDB\BSON\Decimal128; @@ -17,8 +17,6 @@ use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToBool; -use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Type\ExpressionInterface; use MongoDB\Model\BSONArray; use stdClass; @@ -28,7 +26,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/isArray/ */ -class IsArrayAggregation implements ResolvesToBool +class IsArrayOperator implements ResolvesToBool { public const NAME = '$isArray'; public const ENCODE = \MongoDB\Builder\Encode::Array; diff --git a/src/Builder/Aggregation/IsNumberAggregation.php b/src/Builder/Expression/IsNumberOperator.php similarity index 91% rename from src/Builder/Aggregation/IsNumberAggregation.php rename to src/Builder/Expression/IsNumberOperator.php index aa63d1af8..bf6d86687 100644 --- a/src/Builder/Aggregation/IsNumberAggregation.php +++ b/src/Builder/Expression/IsNumberOperator.php @@ -4,7 +4,7 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Binary; use MongoDB\BSON\Decimal128; @@ -17,8 +17,6 @@ use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToBool; -use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Type\ExpressionInterface; use MongoDB\Model\BSONArray; use stdClass; @@ -30,7 +28,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/isNumber/ */ -class IsNumberAggregation implements ResolvesToBool +class IsNumberOperator implements ResolvesToBool { public const NAME = '$isNumber'; public const ENCODE = \MongoDB\Builder\Encode::Single; diff --git a/src/Builder/Aggregation/IsoDayOfWeekAggregation.php b/src/Builder/Expression/IsoDayOfWeekOperator.php similarity index 80% rename from src/Builder/Aggregation/IsoDayOfWeekAggregation.php rename to src/Builder/Expression/IsoDayOfWeekOperator.php index 42f604c39..643224d0d 100644 --- a/src/Builder/Aggregation/IsoDayOfWeekAggregation.php +++ b/src/Builder/Expression/IsoDayOfWeekOperator.php @@ -4,17 +4,12 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\ObjectId; use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToDate; -use MongoDB\Builder\Expression\ResolvesToInt; -use MongoDB\Builder\Expression\ResolvesToObjectId; -use MongoDB\Builder\Expression\ResolvesToString; -use MongoDB\Builder\Expression\ResolvesToTimestamp; use MongoDB\Builder\Optional; /** @@ -22,7 +17,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/isoDayOfWeek/ */ -class IsoDayOfWeekAggregation implements ResolvesToInt +class IsoDayOfWeekOperator implements ResolvesToInt { public const NAME = '$isoDayOfWeek'; public const ENCODE = \MongoDB\Builder\Encode::Object; @@ -31,7 +26,7 @@ class IsoDayOfWeekAggregation implements ResolvesToInt public ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; /** @param Optional|ResolvesToString|non-empty-string $timezone 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. */ - public ResolvesToString|Optional|string $timezone; + public Optional|ResolvesToString|string $timezone; /** * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. @@ -39,7 +34,7 @@ class IsoDayOfWeekAggregation implements ResolvesToInt */ public function __construct( ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, - ResolvesToString|Optional|string $timezone = Optional::Undefined, + Optional|ResolvesToString|string $timezone = Optional::Undefined, ) { $this->date = $date; $this->timezone = $timezone; diff --git a/src/Builder/Aggregation/IsoWeekAggregation.php b/src/Builder/Expression/IsoWeekOperator.php similarity index 81% rename from src/Builder/Aggregation/IsoWeekAggregation.php rename to src/Builder/Expression/IsoWeekOperator.php index a66db5585..da7d3dc36 100644 --- a/src/Builder/Aggregation/IsoWeekAggregation.php +++ b/src/Builder/Expression/IsoWeekOperator.php @@ -4,17 +4,12 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\ObjectId; use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToDate; -use MongoDB\Builder\Expression\ResolvesToInt; -use MongoDB\Builder\Expression\ResolvesToObjectId; -use MongoDB\Builder\Expression\ResolvesToString; -use MongoDB\Builder\Expression\ResolvesToTimestamp; use MongoDB\Builder\Optional; /** @@ -22,7 +17,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/isoWeek/ */ -class IsoWeekAggregation implements ResolvesToInt +class IsoWeekOperator implements ResolvesToInt { public const NAME = '$isoWeek'; public const ENCODE = \MongoDB\Builder\Encode::Object; @@ -31,7 +26,7 @@ class IsoWeekAggregation implements ResolvesToInt public ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; /** @param Optional|ResolvesToString|non-empty-string $timezone 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. */ - public ResolvesToString|Optional|string $timezone; + public Optional|ResolvesToString|string $timezone; /** * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. @@ -39,7 +34,7 @@ class IsoWeekAggregation implements ResolvesToInt */ public function __construct( ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, - ResolvesToString|Optional|string $timezone = Optional::Undefined, + Optional|ResolvesToString|string $timezone = Optional::Undefined, ) { $this->date = $date; $this->timezone = $timezone; diff --git a/src/Builder/Aggregation/IsoWeekYearAggregation.php b/src/Builder/Expression/IsoWeekYearOperator.php similarity index 81% rename from src/Builder/Aggregation/IsoWeekYearAggregation.php rename to src/Builder/Expression/IsoWeekYearOperator.php index 8eb7a1c97..b423d4390 100644 --- a/src/Builder/Aggregation/IsoWeekYearAggregation.php +++ b/src/Builder/Expression/IsoWeekYearOperator.php @@ -4,17 +4,12 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\ObjectId; use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToDate; -use MongoDB\Builder\Expression\ResolvesToInt; -use MongoDB\Builder\Expression\ResolvesToObjectId; -use MongoDB\Builder\Expression\ResolvesToString; -use MongoDB\Builder\Expression\ResolvesToTimestamp; use MongoDB\Builder\Optional; /** @@ -22,7 +17,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/isoWeekYear/ */ -class IsoWeekYearAggregation implements ResolvesToInt +class IsoWeekYearOperator implements ResolvesToInt { public const NAME = '$isoWeekYear'; public const ENCODE = \MongoDB\Builder\Encode::Object; @@ -31,7 +26,7 @@ class IsoWeekYearAggregation implements ResolvesToInt public ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; /** @param Optional|ResolvesToString|non-empty-string $timezone 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. */ - public ResolvesToString|Optional|string $timezone; + public Optional|ResolvesToString|string $timezone; /** * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. @@ -39,7 +34,7 @@ class IsoWeekYearAggregation implements ResolvesToInt */ public function __construct( ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, - ResolvesToString|Optional|string $timezone = Optional::Undefined, + Optional|ResolvesToString|string $timezone = Optional::Undefined, ) { $this->date = $date; $this->timezone = $timezone; diff --git a/src/Builder/Aggregation/LastNAggregation.php b/src/Builder/Expression/LastNOperator.php similarity index 89% rename from src/Builder/Aggregation/LastNAggregation.php rename to src/Builder/Expression/LastNOperator.php index bb119667e..9e8c0cbca 100644 --- a/src/Builder/Aggregation/LastNAggregation.php +++ b/src/Builder/Expression/LastNOperator.php @@ -4,12 +4,11 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\PackedArray; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToArray; -use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Type\WindowInterface; use MongoDB\Model\BSONArray; /** @@ -17,7 +16,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/lastN/ */ -class LastNAggregation implements ResolvesToArray +class LastNOperator implements ResolvesToArray, WindowInterface { public const NAME = '$lastN'; public const ENCODE = \MongoDB\Builder\Encode::Object; diff --git a/src/Builder/Aggregation/LastAggregation.php b/src/Builder/Expression/LastOperator.php similarity index 81% rename from src/Builder/Aggregation/LastAggregation.php rename to src/Builder/Expression/LastOperator.php index 0b4e43ee4..174bd54f6 100644 --- a/src/Builder/Aggregation/LastAggregation.php +++ b/src/Builder/Expression/LastOperator.php @@ -4,7 +4,7 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Binary; use MongoDB\BSON\Decimal128; @@ -17,10 +17,9 @@ use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToAny; -use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Type\AccumulatorInterface; use MongoDB\Builder\Type\ExpressionInterface; +use MongoDB\Builder\Type\WindowInterface; use MongoDB\Model\BSONArray; use stdClass; @@ -30,7 +29,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/last/ */ -class LastAggregation implements ResolvesToAny, AccumulatorInterface +class LastOperator implements AccumulatorInterface, WindowInterface { public const NAME = '$last'; public const ENCODE = \MongoDB\Builder\Encode::Single; @@ -44,10 +43,6 @@ class LastAggregation implements ResolvesToAny, AccumulatorInterface public function __construct( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, ) { - if (\is_array($expression) && ! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression argument to be a list, got an associative array.'); - } - $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/LetAggregation.php b/src/Builder/Expression/LetOperator.php similarity index 88% rename from src/Builder/Aggregation/LetAggregation.php rename to src/Builder/Expression/LetOperator.php index 19a71eb7d..f752ceffe 100644 --- a/src/Builder/Aggregation/LetAggregation.php +++ b/src/Builder/Expression/LetOperator.php @@ -4,7 +4,7 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Binary; use MongoDB\BSON\Decimal128; @@ -17,8 +17,6 @@ use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToAny; -use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Type\ExpressionInterface; use MongoDB\Model\BSONArray; use stdClass; @@ -29,7 +27,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/let/ */ -class LetAggregation implements ResolvesToAny +class LetOperator implements ResolvesToAny { public const NAME = '$let'; public const ENCODE = \MongoDB\Builder\Encode::Object; @@ -53,10 +51,6 @@ public function __construct( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $in, ) { $this->vars = $vars; - if (\is_array($in) && ! \array_is_list($in)) { - throw new \InvalidArgumentException('Expected $in argument to be a list, got an associative array.'); - } - $this->in = $in; } } diff --git a/src/Builder/Expression/LinearFillOperator.php b/src/Builder/Expression/LinearFillOperator.php new file mode 100644 index 000000000..4f1196659 --- /dev/null +++ b/src/Builder/Expression/LinearFillOperator.php @@ -0,0 +1,35 @@ +expression = $expression; + } +} diff --git a/src/Builder/Aggregation/LiteralAggregation.php b/src/Builder/Expression/LiteralOperator.php similarity index 83% rename from src/Builder/Aggregation/LiteralAggregation.php rename to src/Builder/Expression/LiteralOperator.php index 615803b01..946563a8b 100644 --- a/src/Builder/Aggregation/LiteralAggregation.php +++ b/src/Builder/Expression/LiteralOperator.php @@ -4,7 +4,7 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Binary; use MongoDB\BSON\Decimal128; @@ -17,8 +17,6 @@ use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToAny; -use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Model\BSONArray; use stdClass; @@ -27,7 +25,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/literal/ */ -class LiteralAggregation implements ResolvesToAny +class LiteralOperator implements ResolvesToAny { public const NAME = '$literal'; public const ENCODE = \MongoDB\Builder\Encode::Single; @@ -41,10 +39,6 @@ class LiteralAggregation implements ResolvesToAny public function __construct( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|BSONArray|stdClass|array|bool|float|int|null|string $value, ) { - if (\is_array($value) && ! \array_is_list($value)) { - throw new \InvalidArgumentException('Expected $value argument to be a list, got an associative array.'); - } - $this->value = $value; } } diff --git a/src/Builder/Expression/LnOperator.php b/src/Builder/Expression/LnOperator.php new file mode 100644 index 000000000..00e0edaa6 --- /dev/null +++ b/src/Builder/Expression/LnOperator.php @@ -0,0 +1,34 @@ +, Math.E ] expression, where Math.E is a JavaScript representation for Euler's number e. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/ln/ + */ +class LnOperator implements ResolvesToDouble +{ + public const NAME = '$ln'; + public const ENCODE = \MongoDB\Builder\Encode::Single; + + /** @param Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $number Any valid expression as long as it resolves to a non-negative number. For more information on expressions, see Expressions. */ + public Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $number; + + /** + * @param Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $number Any valid expression as long as it resolves to a non-negative number. For more information on expressions, see Expressions. + */ + public function __construct(Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $number) + { + $this->number = $number; + } +} diff --git a/src/Builder/Aggregation/LocfAggregation.php b/src/Builder/Expression/LocfOperator.php similarity index 82% rename from src/Builder/Aggregation/LocfAggregation.php rename to src/Builder/Expression/LocfOperator.php index 982658c3a..22531c497 100644 --- a/src/Builder/Aggregation/LocfAggregation.php +++ b/src/Builder/Expression/LocfOperator.php @@ -4,7 +4,7 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Binary; use MongoDB\BSON\Decimal128; @@ -17,8 +17,6 @@ use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToAny; -use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Type\ExpressionInterface; use MongoDB\Model\BSONArray; use stdClass; @@ -30,7 +28,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/locf/ */ -class LocfAggregation implements ResolvesToAny +class LocfOperator implements ResolvesToAny { public const NAME = '$locf'; public const ENCODE = \MongoDB\Builder\Encode::Single; @@ -44,10 +42,6 @@ class LocfAggregation implements ResolvesToAny public function __construct( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, ) { - if (\is_array($expression) && ! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression argument to be a list, got an associative array.'); - } - $this->expression = $expression; } } diff --git a/src/Builder/Expression/Log10Operator.php b/src/Builder/Expression/Log10Operator.php new file mode 100644 index 000000000..5517e1910 --- /dev/null +++ b/src/Builder/Expression/Log10Operator.php @@ -0,0 +1,33 @@ +number = $number; + } +} diff --git a/src/Builder/Expression/LogOperator.php b/src/Builder/Expression/LogOperator.php new file mode 100644 index 000000000..c79200061 --- /dev/null +++ b/src/Builder/Expression/LogOperator.php @@ -0,0 +1,40 @@ +number = $number; + $this->base = $base; + } +} diff --git a/src/Builder/Aggregation/LtAggregation.php b/src/Builder/Expression/LtOperator.php similarity index 81% rename from src/Builder/Aggregation/LtAggregation.php rename to src/Builder/Expression/LtOperator.php index 8a8e84808..53c42fdfd 100644 --- a/src/Builder/Aggregation/LtAggregation.php +++ b/src/Builder/Expression/LtOperator.php @@ -4,7 +4,7 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Binary; use MongoDB\BSON\Decimal128; @@ -17,8 +17,6 @@ use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToBool; -use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Type\ExpressionInterface; use MongoDB\Model\BSONArray; use stdClass; @@ -28,7 +26,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/lt/ */ -class LtAggregation implements ResolvesToBool +class LtOperator implements ResolvesToBool { public const NAME = '$lt'; public const ENCODE = \MongoDB\Builder\Encode::Array; @@ -47,15 +45,7 @@ public function __construct( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression1, Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression2, ) { - if (\is_array($expression1) && ! \array_is_list($expression1)) { - throw new \InvalidArgumentException('Expected $expression1 argument to be a list, got an associative array.'); - } - $this->expression1 = $expression1; - if (\is_array($expression2) && ! \array_is_list($expression2)) { - throw new \InvalidArgumentException('Expected $expression2 argument to be a list, got an associative array.'); - } - $this->expression2 = $expression2; } } diff --git a/src/Builder/Aggregation/LteAggregation.php b/src/Builder/Expression/LteOperator.php similarity index 81% rename from src/Builder/Aggregation/LteAggregation.php rename to src/Builder/Expression/LteOperator.php index 1335dc581..34238fb96 100644 --- a/src/Builder/Aggregation/LteAggregation.php +++ b/src/Builder/Expression/LteOperator.php @@ -4,7 +4,7 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Binary; use MongoDB\BSON\Decimal128; @@ -17,8 +17,6 @@ use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToBool; -use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Type\ExpressionInterface; use MongoDB\Model\BSONArray; use stdClass; @@ -28,7 +26,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/lte/ */ -class LteAggregation implements ResolvesToBool +class LteOperator implements ResolvesToBool { public const NAME = '$lte'; public const ENCODE = \MongoDB\Builder\Encode::Array; @@ -47,15 +45,7 @@ public function __construct( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression1, Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression2, ) { - if (\is_array($expression1) && ! \array_is_list($expression1)) { - throw new \InvalidArgumentException('Expected $expression1 argument to be a list, got an associative array.'); - } - $this->expression1 = $expression1; - if (\is_array($expression2) && ! \array_is_list($expression2)) { - throw new \InvalidArgumentException('Expected $expression2 argument to be a list, got an associative array.'); - } - $this->expression2 = $expression2; } } diff --git a/src/Builder/Aggregation/LtrimAggregation.php b/src/Builder/Expression/LtrimOperator.php similarity index 87% rename from src/Builder/Aggregation/LtrimAggregation.php rename to src/Builder/Expression/LtrimOperator.php index 4e2429954..5ce124b35 100644 --- a/src/Builder/Aggregation/LtrimAggregation.php +++ b/src/Builder/Expression/LtrimOperator.php @@ -4,10 +4,9 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToString; use MongoDB\Builder\Optional; /** @@ -16,7 +15,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/ltrim/ */ -class LtrimAggregation implements ResolvesToString +class LtrimOperator implements ResolvesToString { public const NAME = '$ltrim'; public const ENCODE = \MongoDB\Builder\Encode::Object; @@ -29,7 +28,7 @@ class LtrimAggregation implements ResolvesToString * 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. */ - public ResolvesToString|Optional|string $chars; + public Optional|ResolvesToString|string $chars; /** * @param ResolvesToString|non-empty-string $input The string to trim. The argument can be any valid expression that resolves to a string. @@ -39,7 +38,7 @@ class LtrimAggregation implements ResolvesToString */ public function __construct( ResolvesToString|string $input, - ResolvesToString|Optional|string $chars = Optional::Undefined, + Optional|ResolvesToString|string $chars = Optional::Undefined, ) { $this->input = $input; $this->chars = $chars; diff --git a/src/Builder/Aggregation/MapAggregation.php b/src/Builder/Expression/MapOperator.php similarity index 85% rename from src/Builder/Aggregation/MapAggregation.php rename to src/Builder/Expression/MapOperator.php index 6d07913b8..fb4a6db7a 100644 --- a/src/Builder/Aggregation/MapAggregation.php +++ b/src/Builder/Expression/MapOperator.php @@ -4,7 +4,7 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Binary; use MongoDB\BSON\Decimal128; @@ -17,9 +17,6 @@ use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToArray; -use MongoDB\Builder\Expression\ResolvesToInt; -use MongoDB\Builder\Expression\ResolvesToString; use MongoDB\Builder\Optional; use MongoDB\Builder\Type\ExpressionInterface; use MongoDB\Model\BSONArray; @@ -30,7 +27,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/map/ */ -class MapAggregation implements ResolvesToArray +class MapOperator implements ResolvesToArray { public const NAME = '$map'; public const ENCODE = \MongoDB\Builder\Encode::Object; @@ -42,7 +39,7 @@ class MapAggregation implements ResolvesToArray public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $in; /** @param Optional|ResolvesToString|non-empty-string $as 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. */ - public ResolvesToString|Optional|string $as; + public Optional|ResolvesToString|string $as; /** * @param BSONArray|PackedArray|ResolvesToArray|array $input An expression that resolves to an array. @@ -52,17 +49,13 @@ class MapAggregation implements ResolvesToArray public function __construct( PackedArray|ResolvesToArray|BSONArray|array $input, Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $in, - ResolvesToString|Optional|string $as = Optional::Undefined, + Optional|ResolvesToString|string $as = Optional::Undefined, ) { if (\is_array($input) && ! \array_is_list($input)) { throw new \InvalidArgumentException('Expected $input argument to be a list, got an associative array.'); } $this->input = $input; - if (\is_array($in) && ! \array_is_list($in)) { - throw new \InvalidArgumentException('Expected $in argument to be a list, got an associative array.'); - } - $this->in = $in; $this->as = $as; } diff --git a/src/Builder/Aggregation/MaxNAggregation.php b/src/Builder/Expression/MaxNOperator.php similarity index 87% rename from src/Builder/Aggregation/MaxNAggregation.php rename to src/Builder/Expression/MaxNOperator.php index 342edff8e..34ea614f8 100644 --- a/src/Builder/Aggregation/MaxNAggregation.php +++ b/src/Builder/Expression/MaxNOperator.php @@ -4,12 +4,12 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\PackedArray; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToArray; -use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Type\AccumulatorInterface; +use MongoDB\Builder\Type\WindowInterface; use MongoDB\Model\BSONArray; /** @@ -17,7 +17,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/maxN-array-element/ */ -class MaxNAggregation implements ResolvesToArray +class MaxNOperator implements ResolvesToArray, AccumulatorInterface, WindowInterface { public const NAME = '$maxN'; public const ENCODE = \MongoDB\Builder\Encode::Object; diff --git a/src/Builder/Aggregation/MaxAggregation.php b/src/Builder/Expression/MaxOperator.php similarity index 91% rename from src/Builder/Aggregation/MaxAggregation.php rename to src/Builder/Expression/MaxOperator.php index de01dfd9a..8b67aac2f 100644 --- a/src/Builder/Aggregation/MaxAggregation.php +++ b/src/Builder/Expression/MaxOperator.php @@ -4,7 +4,7 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Binary; use MongoDB\BSON\Decimal128; @@ -17,10 +17,9 @@ use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToAny; -use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Type\AccumulatorInterface; use MongoDB\Builder\Type\ExpressionInterface; +use MongoDB\Builder\Type\WindowInterface; use MongoDB\Model\BSONArray; use stdClass; @@ -30,7 +29,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/max/ */ -class MaxAggregation implements ResolvesToAny, AccumulatorInterface +class MaxOperator implements ResolvesToAny, AccumulatorInterface, WindowInterface { public const NAME = '$max'; public const ENCODE = \MongoDB\Builder\Encode::Single; diff --git a/src/Builder/Expression/MedianOperator.php b/src/Builder/Expression/MedianOperator.php new file mode 100644 index 000000000..3aee4d134 --- /dev/null +++ b/src/Builder/Expression/MedianOperator.php @@ -0,0 +1,45 @@ +input = $input; + $this->method = $method; + } +} diff --git a/src/Builder/Aggregation/MergeObjectsAggregation.php b/src/Builder/Expression/MergeObjectsOperator.php similarity index 89% rename from src/Builder/Aggregation/MergeObjectsAggregation.php rename to src/Builder/Expression/MergeObjectsOperator.php index 760f61bb4..09bcc4159 100644 --- a/src/Builder/Aggregation/MergeObjectsAggregation.php +++ b/src/Builder/Expression/MergeObjectsOperator.php @@ -4,12 +4,11 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Document; use MongoDB\BSON\Serializable; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToObject; use MongoDB\Builder\Type\AccumulatorInterface; use stdClass; @@ -18,7 +17,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/mergeObjects/ */ -class MergeObjectsAggregation implements AccumulatorInterface +class MergeObjectsOperator implements AccumulatorInterface { public const NAME = '$mergeObjects'; public const ENCODE = \MongoDB\Builder\Encode::Single; diff --git a/src/Builder/Aggregation/MetaAggregation.php b/src/Builder/Expression/MetaOperator.php similarity index 81% rename from src/Builder/Aggregation/MetaAggregation.php rename to src/Builder/Expression/MetaOperator.php index 99bc2a0e9..e4518a132 100644 --- a/src/Builder/Aggregation/MetaAggregation.php +++ b/src/Builder/Expression/MetaOperator.php @@ -4,17 +4,16 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToDecimal; /** * Access available per-document metadata related to the aggregation operation. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/meta/ */ -class MetaAggregation implements ResolvesToDecimal +class MetaOperator implements ResolvesToDecimal { public const NAME = '$meta'; public const ENCODE = \MongoDB\Builder\Encode::Single; diff --git a/src/Builder/Aggregation/MillisecondAggregation.php b/src/Builder/Expression/MillisecondOperator.php similarity index 80% rename from src/Builder/Aggregation/MillisecondAggregation.php rename to src/Builder/Expression/MillisecondOperator.php index 4b34b5696..c13c15003 100644 --- a/src/Builder/Aggregation/MillisecondAggregation.php +++ b/src/Builder/Expression/MillisecondOperator.php @@ -4,17 +4,12 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\ObjectId; use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToDate; -use MongoDB\Builder\Expression\ResolvesToInt; -use MongoDB\Builder\Expression\ResolvesToObjectId; -use MongoDB\Builder\Expression\ResolvesToString; -use MongoDB\Builder\Expression\ResolvesToTimestamp; use MongoDB\Builder\Optional; /** @@ -22,7 +17,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/millisecond/ */ -class MillisecondAggregation implements ResolvesToInt +class MillisecondOperator implements ResolvesToInt { public const NAME = '$millisecond'; public const ENCODE = \MongoDB\Builder\Encode::Object; @@ -31,7 +26,7 @@ class MillisecondAggregation implements ResolvesToInt public ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; /** @param Optional|ResolvesToString|non-empty-string $timezone 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. */ - public ResolvesToString|Optional|string $timezone; + public Optional|ResolvesToString|string $timezone; /** * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. @@ -39,7 +34,7 @@ class MillisecondAggregation implements ResolvesToInt */ public function __construct( ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, - ResolvesToString|Optional|string $timezone = Optional::Undefined, + Optional|ResolvesToString|string $timezone = Optional::Undefined, ) { $this->date = $date; $this->timezone = $timezone; diff --git a/src/Builder/Aggregation/MinNAggregation.php b/src/Builder/Expression/MinNOperator.php similarity index 87% rename from src/Builder/Aggregation/MinNAggregation.php rename to src/Builder/Expression/MinNOperator.php index 2f45dcc33..3485d634e 100644 --- a/src/Builder/Aggregation/MinNAggregation.php +++ b/src/Builder/Expression/MinNOperator.php @@ -4,12 +4,12 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\PackedArray; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToArray; -use MongoDB\Builder\Expression\ResolvesToInt; +use MongoDB\Builder\Type\AccumulatorInterface; +use MongoDB\Builder\Type\WindowInterface; use MongoDB\Model\BSONArray; /** @@ -17,7 +17,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/minN-array-element/ */ -class MinNAggregation implements ResolvesToArray +class MinNOperator implements ResolvesToArray, AccumulatorInterface, WindowInterface { public const NAME = '$minN'; public const ENCODE = \MongoDB\Builder\Encode::Object; diff --git a/src/Builder/Aggregation/MinAggregation.php b/src/Builder/Expression/MinOperator.php similarity index 91% rename from src/Builder/Aggregation/MinAggregation.php rename to src/Builder/Expression/MinOperator.php index c411ba6d6..bc629cd1e 100644 --- a/src/Builder/Aggregation/MinAggregation.php +++ b/src/Builder/Expression/MinOperator.php @@ -4,7 +4,7 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Binary; use MongoDB\BSON\Decimal128; @@ -17,10 +17,9 @@ use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToAny; -use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Type\AccumulatorInterface; use MongoDB\Builder\Type\ExpressionInterface; +use MongoDB\Builder\Type\WindowInterface; use MongoDB\Model\BSONArray; use stdClass; @@ -30,7 +29,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/min/ */ -class MinAggregation implements ResolvesToAny, AccumulatorInterface +class MinOperator implements ResolvesToAny, AccumulatorInterface, WindowInterface { public const NAME = '$min'; public const ENCODE = \MongoDB\Builder\Encode::Single; diff --git a/src/Builder/Aggregation/MinuteAggregation.php b/src/Builder/Expression/MinuteOperator.php similarity index 80% rename from src/Builder/Aggregation/MinuteAggregation.php rename to src/Builder/Expression/MinuteOperator.php index e4a527bc3..df3833666 100644 --- a/src/Builder/Aggregation/MinuteAggregation.php +++ b/src/Builder/Expression/MinuteOperator.php @@ -4,17 +4,12 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\ObjectId; use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToDate; -use MongoDB\Builder\Expression\ResolvesToInt; -use MongoDB\Builder\Expression\ResolvesToObjectId; -use MongoDB\Builder\Expression\ResolvesToString; -use MongoDB\Builder\Expression\ResolvesToTimestamp; use MongoDB\Builder\Optional; /** @@ -22,7 +17,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/minute/ */ -class MinuteAggregation implements ResolvesToInt +class MinuteOperator implements ResolvesToInt { public const NAME = '$minute'; public const ENCODE = \MongoDB\Builder\Encode::Object; @@ -31,7 +26,7 @@ class MinuteAggregation implements ResolvesToInt public ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; /** @param Optional|ResolvesToString|non-empty-string $timezone 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. */ - public ResolvesToString|Optional|string $timezone; + public Optional|ResolvesToString|string $timezone; /** * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. @@ -39,7 +34,7 @@ class MinuteAggregation implements ResolvesToInt */ public function __construct( ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, - ResolvesToString|Optional|string $timezone = Optional::Undefined, + Optional|ResolvesToString|string $timezone = Optional::Undefined, ) { $this->date = $date; $this->timezone = $timezone; diff --git a/src/Builder/Expression/ModOperator.php b/src/Builder/Expression/ModOperator.php new file mode 100644 index 000000000..d7a478ea4 --- /dev/null +++ b/src/Builder/Expression/ModOperator.php @@ -0,0 +1,40 @@ +dividend = $dividend; + $this->divisor = $divisor; + } +} diff --git a/src/Builder/Aggregation/MonthAggregation.php b/src/Builder/Expression/MonthOperator.php similarity index 80% rename from src/Builder/Aggregation/MonthAggregation.php rename to src/Builder/Expression/MonthOperator.php index 717b4fda5..ed7cd738b 100644 --- a/src/Builder/Aggregation/MonthAggregation.php +++ b/src/Builder/Expression/MonthOperator.php @@ -4,17 +4,12 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\ObjectId; use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToDate; -use MongoDB\Builder\Expression\ResolvesToInt; -use MongoDB\Builder\Expression\ResolvesToObjectId; -use MongoDB\Builder\Expression\ResolvesToString; -use MongoDB\Builder\Expression\ResolvesToTimestamp; use MongoDB\Builder\Optional; /** @@ -22,7 +17,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/month/ */ -class MonthAggregation implements ResolvesToInt +class MonthOperator implements ResolvesToInt { public const NAME = '$month'; public const ENCODE = \MongoDB\Builder\Encode::Object; @@ -31,7 +26,7 @@ class MonthAggregation implements ResolvesToInt public ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; /** @param Optional|ResolvesToString|non-empty-string $timezone 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. */ - public ResolvesToString|Optional|string $timezone; + public Optional|ResolvesToString|string $timezone; /** * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. @@ -39,7 +34,7 @@ class MonthAggregation implements ResolvesToInt */ public function __construct( ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, - ResolvesToString|Optional|string $timezone = Optional::Undefined, + Optional|ResolvesToString|string $timezone = Optional::Undefined, ) { $this->date = $date; $this->timezone = $timezone; diff --git a/src/Builder/Aggregation/MultiplyAggregation.php b/src/Builder/Expression/MultiplyOperator.php similarity index 57% rename from src/Builder/Aggregation/MultiplyAggregation.php rename to src/Builder/Expression/MultiplyOperator.php index 98ef93b78..cc8a8621c 100644 --- a/src/Builder/Aggregation/MultiplyAggregation.php +++ b/src/Builder/Expression/MultiplyOperator.php @@ -4,41 +4,35 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Decimal128; use MongoDB\BSON\Int64; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToDecimal; -use MongoDB\Builder\Expression\ResolvesToDouble; -use MongoDB\Builder\Expression\ResolvesToInt; -use MongoDB\Builder\Expression\ResolvesToLong; -use MongoDB\Builder\Expression\ResolvesToNumber; /** * Multiplies numbers to return the product. Accepts any number of argument expressions. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/multiply/ */ -class MultiplyAggregation implements ResolvesToDecimal +class MultiplyOperator implements ResolvesToDecimal { public const NAME = '$multiply'; public const ENCODE = \MongoDB\Builder\Encode::Single; /** - * @param list ...$expression The arguments can be any valid expression as long as they resolve to numbers. + * @param list ...$expression 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. */ public array $expression; /** - * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int ...$expression The arguments can be any valid expression as long as they resolve to numbers. + * @param Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int ...$expression 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. * @no-named-arguments */ - public function __construct( - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int ...$expression, - ) { + public function __construct(Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int ...$expression) + { if (\count($expression) < 1) { throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); } diff --git a/src/Builder/Aggregation/NeAggregation.php b/src/Builder/Expression/NeOperator.php similarity index 81% rename from src/Builder/Aggregation/NeAggregation.php rename to src/Builder/Expression/NeOperator.php index 175bf210b..b71362645 100644 --- a/src/Builder/Aggregation/NeAggregation.php +++ b/src/Builder/Expression/NeOperator.php @@ -4,7 +4,7 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Binary; use MongoDB\BSON\Decimal128; @@ -17,8 +17,6 @@ use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToBool; -use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Type\ExpressionInterface; use MongoDB\Model\BSONArray; use stdClass; @@ -28,7 +26,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/ne/ */ -class NeAggregation implements ResolvesToBool +class NeOperator implements ResolvesToBool { public const NAME = '$ne'; public const ENCODE = \MongoDB\Builder\Encode::Array; @@ -47,15 +45,7 @@ public function __construct( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression1, Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression2, ) { - if (\is_array($expression1) && ! \array_is_list($expression1)) { - throw new \InvalidArgumentException('Expected $expression1 argument to be a list, got an associative array.'); - } - $this->expression1 = $expression1; - if (\is_array($expression2) && ! \array_is_list($expression2)) { - throw new \InvalidArgumentException('Expected $expression2 argument to be a list, got an associative array.'); - } - $this->expression2 = $expression2; } } diff --git a/src/Builder/Aggregation/NotAggregation.php b/src/Builder/Expression/NotOperator.php similarity index 82% rename from src/Builder/Aggregation/NotAggregation.php rename to src/Builder/Expression/NotOperator.php index b901a00d8..c3b1624d7 100644 --- a/src/Builder/Aggregation/NotAggregation.php +++ b/src/Builder/Expression/NotOperator.php @@ -4,7 +4,7 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Binary; use MongoDB\BSON\Decimal128; @@ -17,8 +17,6 @@ use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToBool; -use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Type\ExpressionInterface; use MongoDB\Model\BSONArray; use stdClass; @@ -28,7 +26,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/not/ */ -class NotAggregation implements ResolvesToBool +class NotOperator implements ResolvesToBool { public const NAME = '$not'; public const ENCODE = \MongoDB\Builder\Encode::Single; @@ -42,10 +40,6 @@ class NotAggregation implements ResolvesToBool public function __construct( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToBool|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, ) { - if (\is_array($expression) && ! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression argument to be a list, got an associative array.'); - } - $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/ObjectToArrayAggregation.php b/src/Builder/Expression/ObjectToArrayOperator.php similarity index 87% rename from src/Builder/Aggregation/ObjectToArrayAggregation.php rename to src/Builder/Expression/ObjectToArrayOperator.php index d5afafc6f..5108fd22d 100644 --- a/src/Builder/Aggregation/ObjectToArrayAggregation.php +++ b/src/Builder/Expression/ObjectToArrayOperator.php @@ -4,13 +4,11 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Document; use MongoDB\BSON\Serializable; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToArray; -use MongoDB\Builder\Expression\ResolvesToObject; use stdClass; /** @@ -18,7 +16,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/objectToArray/ */ -class ObjectToArrayAggregation implements ResolvesToArray +class ObjectToArrayOperator implements ResolvesToArray { public const NAME = '$objectToArray'; public const ENCODE = \MongoDB\Builder\Encode::Single; diff --git a/src/Builder/Aggregation/OrAggregation.php b/src/Builder/Expression/OrOperator.php similarity index 91% rename from src/Builder/Aggregation/OrAggregation.php rename to src/Builder/Expression/OrOperator.php index 69db5010f..3740b59b1 100644 --- a/src/Builder/Aggregation/OrAggregation.php +++ b/src/Builder/Expression/OrOperator.php @@ -4,7 +4,7 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Binary; use MongoDB\BSON\Decimal128; @@ -17,8 +17,6 @@ use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToBool; -use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Type\ExpressionInterface; use MongoDB\Model\BSONArray; use stdClass; @@ -28,7 +26,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/or/ */ -class OrAggregation implements ResolvesToBool +class OrOperator implements ResolvesToBool { public const NAME = '$or'; public const ENCODE = \MongoDB\Builder\Encode::Single; diff --git a/src/Builder/Aggregation/PercentileAggregation.php b/src/Builder/Expression/PercentileOperator.php similarity index 60% rename from src/Builder/Aggregation/PercentileAggregation.php rename to src/Builder/Expression/PercentileOperator.php index 4c80ca1c2..c3bd9b448 100644 --- a/src/Builder/Aggregation/PercentileAggregation.php +++ b/src/Builder/Expression/PercentileOperator.php @@ -4,19 +4,14 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Decimal128; use MongoDB\BSON\Int64; use MongoDB\BSON\PackedArray; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToArray; -use MongoDB\Builder\Expression\ResolvesToDecimal; -use MongoDB\Builder\Expression\ResolvesToDouble; -use MongoDB\Builder\Expression\ResolvesToInt; -use MongoDB\Builder\Expression\ResolvesToLong; -use MongoDB\Builder\Expression\ResolvesToNumber; use MongoDB\Builder\Type\AccumulatorInterface; +use MongoDB\Builder\Type\WindowInterface; use MongoDB\Model\BSONArray; /** @@ -32,13 +27,13 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/percentile/ */ -class PercentileAggregation implements ResolvesToArray, AccumulatorInterface +class PercentileOperator implements ResolvesToArray, AccumulatorInterface, WindowInterface { public const NAME = '$percentile'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $input $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. */ - public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $input; + /** @param Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $input $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. */ + public Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $input; /** * @param BSONArray|PackedArray|ResolvesToArray|array $p $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. @@ -50,13 +45,13 @@ class PercentileAggregation implements ResolvesToArray, AccumulatorInterface public string $method; /** - * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $input $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. + * @param Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $input $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. * @param BSONArray|PackedArray|ResolvesToArray|array $p $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. * @param non-empty-string $method The method that mongod uses to calculate the percentile value. The method must be 'approximate'. */ public function __construct( - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int $input, + Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int $input, PackedArray|ResolvesToArray|BSONArray|array $p, string $method, ) { diff --git a/src/Builder/Expression/PowOperator.php b/src/Builder/Expression/PowOperator.php new file mode 100644 index 000000000..1c2696ca6 --- /dev/null +++ b/src/Builder/Expression/PowOperator.php @@ -0,0 +1,40 @@ +number = $number; + $this->exponent = $exponent; + } +} diff --git a/src/Builder/Aggregation/PushAggregation.php b/src/Builder/Expression/PushOperator.php similarity index 84% rename from src/Builder/Aggregation/PushAggregation.php rename to src/Builder/Expression/PushOperator.php index 9c550979d..b1a3fbb17 100644 --- a/src/Builder/Aggregation/PushAggregation.php +++ b/src/Builder/Expression/PushOperator.php @@ -4,7 +4,7 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Binary; use MongoDB\BSON\Decimal128; @@ -17,9 +17,9 @@ use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Type\AccumulatorInterface; use MongoDB\Builder\Type\ExpressionInterface; +use MongoDB\Builder\Type\WindowInterface; use MongoDB\Model\BSONArray; use stdClass; @@ -29,7 +29,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/push/ */ -class PushAggregation implements AccumulatorInterface +class PushOperator implements AccumulatorInterface, WindowInterface { public const NAME = '$push'; public const ENCODE = \MongoDB\Builder\Encode::Single; @@ -43,10 +43,6 @@ class PushAggregation implements AccumulatorInterface public function __construct( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, ) { - if (\is_array($expression) && ! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression argument to be a list, got an associative array.'); - } - $this->expression = $expression; } } diff --git a/src/Builder/Expression/RadiansToDegreesOperator.php b/src/Builder/Expression/RadiansToDegreesOperator.php new file mode 100644 index 000000000..5c0a7437a --- /dev/null +++ b/src/Builder/Expression/RadiansToDegreesOperator.php @@ -0,0 +1,33 @@ +expression = $expression; + } +} diff --git a/src/Builder/Aggregation/RandAggregation.php b/src/Builder/Expression/RandOperator.php similarity index 73% rename from src/Builder/Aggregation/RandAggregation.php rename to src/Builder/Expression/RandOperator.php index 3a65c2aa2..f1c0f8a19 100644 --- a/src/Builder/Aggregation/RandAggregation.php +++ b/src/Builder/Expression/RandOperator.php @@ -4,17 +4,16 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToDouble; /** * Returns a random float between 0 and 1 * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/rand/ */ -class RandAggregation implements ResolvesToDouble +class RandOperator implements ResolvesToDouble { public const NAME = '$rand'; public const ENCODE = \MongoDB\Builder\Encode::Object; diff --git a/src/Builder/Aggregation/RangeAggregation.php b/src/Builder/Expression/RangeOperator.php similarity index 85% rename from src/Builder/Aggregation/RangeAggregation.php rename to src/Builder/Expression/RangeOperator.php index d07de6aa9..fd806024a 100644 --- a/src/Builder/Aggregation/RangeAggregation.php +++ b/src/Builder/Expression/RangeOperator.php @@ -4,11 +4,9 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToArray; -use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Optional; /** @@ -16,7 +14,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/range/ */ -class RangeAggregation implements ResolvesToArray +class RangeOperator implements ResolvesToArray { public const NAME = '$range'; public const ENCODE = \MongoDB\Builder\Encode::Array; @@ -28,7 +26,7 @@ class RangeAggregation implements ResolvesToArray public ResolvesToInt|int $end; /** @param Optional|ResolvesToInt|int $step An integer that specifies the increment value. Can be any valid expression that resolves to a non-zero integer. Defaults to 1. */ - public ResolvesToInt|Optional|int $step; + public Optional|ResolvesToInt|int $step; /** * @param ResolvesToInt|int $start An integer that specifies the start of the sequence. Can be any valid expression that resolves to an integer. @@ -38,7 +36,7 @@ class RangeAggregation implements ResolvesToArray public function __construct( ResolvesToInt|int $start, ResolvesToInt|int $end, - ResolvesToInt|Optional|int $step = Optional::Undefined, + Optional|ResolvesToInt|int $step = Optional::Undefined, ) { $this->start = $start; $this->end = $end; diff --git a/src/Builder/Aggregation/RankAggregation.php b/src/Builder/Expression/RankOperator.php similarity index 78% rename from src/Builder/Aggregation/RankAggregation.php rename to src/Builder/Expression/RankOperator.php index f851022da..fe988517e 100644 --- a/src/Builder/Aggregation/RankAggregation.php +++ b/src/Builder/Expression/RankOperator.php @@ -4,10 +4,9 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToInt; /** * Returns the document position (known as the rank) relative to other documents in the $setWindowFields stage partition. @@ -15,7 +14,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/rank/ */ -class RankAggregation implements ResolvesToInt +class RankOperator implements ResolvesToInt { public const NAME = '$rank'; public const ENCODE = \MongoDB\Builder\Encode::Object; diff --git a/src/Builder/Aggregation/ReduceAggregation.php b/src/Builder/Expression/ReduceOperator.php similarity index 88% rename from src/Builder/Aggregation/ReduceAggregation.php rename to src/Builder/Expression/ReduceOperator.php index c2948fb61..e3ed0a029 100644 --- a/src/Builder/Aggregation/ReduceAggregation.php +++ b/src/Builder/Expression/ReduceOperator.php @@ -4,7 +4,7 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Binary; use MongoDB\BSON\Decimal128; @@ -17,9 +17,6 @@ use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToAny; -use MongoDB\Builder\Expression\ResolvesToArray; -use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Type\ExpressionInterface; use MongoDB\Model\BSONArray; use stdClass; @@ -29,7 +26,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/reduce/ */ -class ReduceAggregation implements ResolvesToAny +class ReduceOperator implements ResolvesToAny { public const NAME = '$reduce'; public const ENCODE = \MongoDB\Builder\Encode::Object; @@ -72,15 +69,7 @@ public function __construct( } $this->input = $input; - if (\is_array($initialValue) && ! \array_is_list($initialValue)) { - throw new \InvalidArgumentException('Expected $initialValue argument to be a list, got an associative array.'); - } - $this->initialValue = $initialValue; - if (\is_array($in) && ! \array_is_list($in)) { - throw new \InvalidArgumentException('Expected $in argument to be a list, got an associative array.'); - } - $this->in = $in; } } diff --git a/src/Builder/Aggregation/RegexFindAllAggregation.php b/src/Builder/Expression/RegexFindAllOperator.php similarity index 91% rename from src/Builder/Aggregation/RegexFindAllAggregation.php rename to src/Builder/Expression/RegexFindAllOperator.php index e6f763b33..a2a13f53b 100644 --- a/src/Builder/Aggregation/RegexFindAllAggregation.php +++ b/src/Builder/Expression/RegexFindAllOperator.php @@ -4,12 +4,10 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Regex; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToArray; -use MongoDB\Builder\Expression\ResolvesToString; use MongoDB\Builder\Optional; /** @@ -18,7 +16,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/regexFindAll/ */ -class RegexFindAllAggregation implements ResolvesToArray +class RegexFindAllOperator implements ResolvesToArray { public const NAME = '$regexFindAll'; public const ENCODE = \MongoDB\Builder\Encode::Object; diff --git a/src/Builder/Aggregation/RegexFindAggregation.php b/src/Builder/Expression/RegexFindOperator.php similarity index 91% rename from src/Builder/Aggregation/RegexFindAggregation.php rename to src/Builder/Expression/RegexFindOperator.php index 73e749cb6..59038457c 100644 --- a/src/Builder/Aggregation/RegexFindAggregation.php +++ b/src/Builder/Expression/RegexFindOperator.php @@ -4,12 +4,10 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Regex; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToObject; -use MongoDB\Builder\Expression\ResolvesToString; use MongoDB\Builder\Optional; /** @@ -18,7 +16,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/regexFind/ */ -class RegexFindAggregation implements ResolvesToObject +class RegexFindOperator implements ResolvesToObject { public const NAME = '$regexFind'; public const ENCODE = \MongoDB\Builder\Encode::Object; diff --git a/src/Builder/Aggregation/RegexMatchAggregation.php b/src/Builder/Expression/RegexMatchOperator.php similarity index 91% rename from src/Builder/Aggregation/RegexMatchAggregation.php rename to src/Builder/Expression/RegexMatchOperator.php index 10a3132ba..393e4b50d 100644 --- a/src/Builder/Aggregation/RegexMatchAggregation.php +++ b/src/Builder/Expression/RegexMatchOperator.php @@ -4,12 +4,10 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Regex; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToBool; -use MongoDB\Builder\Expression\ResolvesToString; use MongoDB\Builder\Optional; /** @@ -18,7 +16,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/regexMatch/ */ -class RegexMatchAggregation implements ResolvesToBool +class RegexMatchOperator implements ResolvesToBool { public const NAME = '$regexMatch'; public const ENCODE = \MongoDB\Builder\Encode::Object; diff --git a/src/Builder/Aggregation/ReplaceAllAggregation.php b/src/Builder/Expression/ReplaceAllOperator.php similarity index 93% rename from src/Builder/Aggregation/ReplaceAllAggregation.php rename to src/Builder/Expression/ReplaceAllOperator.php index 4da4108ed..0615e2fda 100644 --- a/src/Builder/Aggregation/ReplaceAllAggregation.php +++ b/src/Builder/Expression/ReplaceAllOperator.php @@ -4,11 +4,9 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToNull; -use MongoDB\Builder\Expression\ResolvesToString; /** * Replaces all instances of a search string in an input string with a replacement string. @@ -17,7 +15,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceAll/ */ -class ReplaceAllAggregation implements ResolvesToString +class ReplaceAllOperator implements ResolvesToString { public const NAME = '$replaceAll'; public const ENCODE = \MongoDB\Builder\Encode::Object; diff --git a/src/Builder/Aggregation/ReplaceOneAggregation.php b/src/Builder/Expression/ReplaceOneOperator.php similarity index 92% rename from src/Builder/Aggregation/ReplaceOneAggregation.php rename to src/Builder/Expression/ReplaceOneOperator.php index 20063d5ef..7a65dc468 100644 --- a/src/Builder/Aggregation/ReplaceOneAggregation.php +++ b/src/Builder/Expression/ReplaceOneOperator.php @@ -4,11 +4,9 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToNull; -use MongoDB\Builder\Expression\ResolvesToString; /** * Replaces the first instance of a matched string in a given input. @@ -16,7 +14,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceOne/ */ -class ReplaceOneAggregation implements ResolvesToString +class ReplaceOneOperator implements ResolvesToString { public const NAME = '$replaceOne'; public const ENCODE = \MongoDB\Builder\Encode::Object; diff --git a/src/Builder/Expression/ResolvesToAny.php b/src/Builder/Expression/ResolvesToAny.php index 0625e7658..1f65dac7e 100644 --- a/src/Builder/Expression/ResolvesToAny.php +++ b/src/Builder/Expression/ResolvesToAny.php @@ -6,8 +6,6 @@ namespace MongoDB\Builder\Expression; -use MongoDB\Builder\Type\ExpressionInterface; - -interface ResolvesToAny extends ExpressionInterface +interface ResolvesToAny extends ResolvesToDouble, ResolvesToString, ResolvesToObject, ResolvesToArray, ResolvesToBinData, ResolvesToObjectId, ResolvesToBool, ResolvesToDate, ResolvesToNull, ResolvesToRegex, ResolvesToJavascript, ResolvesToInt, ResolvesToTimestamp, ResolvesToLong, ResolvesToDecimal, ResolvesToNumber { } diff --git a/src/Builder/Expression/ResolvesToDecimal.php b/src/Builder/Expression/ResolvesToDecimal.php index 68afb3236..e9bc20ecb 100644 --- a/src/Builder/Expression/ResolvesToDecimal.php +++ b/src/Builder/Expression/ResolvesToDecimal.php @@ -6,8 +6,6 @@ namespace MongoDB\Builder\Expression; -use MongoDB\Builder\Type\ExpressionInterface; - -interface ResolvesToDecimal extends ExpressionInterface +interface ResolvesToDecimal extends ResolvesToDouble { } diff --git a/src/Builder/Expression/ResolvesToDouble.php b/src/Builder/Expression/ResolvesToDouble.php index 68b4f50dd..0c52ba433 100644 --- a/src/Builder/Expression/ResolvesToDouble.php +++ b/src/Builder/Expression/ResolvesToDouble.php @@ -6,8 +6,6 @@ namespace MongoDB\Builder\Expression; -use MongoDB\Builder\Type\ExpressionInterface; - -interface ResolvesToDouble extends ExpressionInterface +interface ResolvesToDouble extends ResolvesToNumber { } diff --git a/src/Builder/Expression/ResolvesToInt.php b/src/Builder/Expression/ResolvesToInt.php index 744afb8cd..6d1631e33 100644 --- a/src/Builder/Expression/ResolvesToInt.php +++ b/src/Builder/Expression/ResolvesToInt.php @@ -6,8 +6,6 @@ namespace MongoDB\Builder\Expression; -use MongoDB\Builder\Type\ExpressionInterface; - -interface ResolvesToInt extends ExpressionInterface +interface ResolvesToInt extends ResolvesToNumber { } diff --git a/src/Builder/Expression/ResolvesToLong.php b/src/Builder/Expression/ResolvesToLong.php index ca3d54230..32728842e 100644 --- a/src/Builder/Expression/ResolvesToLong.php +++ b/src/Builder/Expression/ResolvesToLong.php @@ -6,8 +6,6 @@ namespace MongoDB\Builder\Expression; -use MongoDB\Builder\Type\ExpressionInterface; - -interface ResolvesToLong extends ExpressionInterface +interface ResolvesToLong extends ResolvesToInt { } diff --git a/src/Builder/Aggregation/ReverseArrayAggregation.php b/src/Builder/Expression/ReverseArrayOperator.php similarity index 88% rename from src/Builder/Aggregation/ReverseArrayAggregation.php rename to src/Builder/Expression/ReverseArrayOperator.php index 8bcf7d4ff..6326db186 100644 --- a/src/Builder/Aggregation/ReverseArrayAggregation.php +++ b/src/Builder/Expression/ReverseArrayOperator.php @@ -4,11 +4,10 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\PackedArray; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToArray; use MongoDB\Model\BSONArray; /** @@ -16,7 +15,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/reverseArray/ */ -class ReverseArrayAggregation implements ResolvesToArray +class ReverseArrayOperator implements ResolvesToArray { public const NAME = '$reverseArray'; public const ENCODE = \MongoDB\Builder\Encode::Single; diff --git a/src/Builder/Aggregation/RoundAggregation.php b/src/Builder/Expression/RoundOperator.php similarity index 79% rename from src/Builder/Aggregation/RoundAggregation.php rename to src/Builder/Expression/RoundOperator.php index 00898b26d..7ff46458f 100644 --- a/src/Builder/Aggregation/RoundAggregation.php +++ b/src/Builder/Expression/RoundOperator.php @@ -4,15 +4,11 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Decimal128; use MongoDB\BSON\Int64; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToDecimal; -use MongoDB\Builder\Expression\ResolvesToDouble; -use MongoDB\Builder\Expression\ResolvesToInt; -use MongoDB\Builder\Expression\ResolvesToLong; use MongoDB\Builder\Optional; /** @@ -20,7 +16,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/round/ */ -class RoundAggregation implements ResolvesToInt, ResolvesToDouble, ResolvesToDecimal, ResolvesToLong +class RoundOperator implements ResolvesToInt, ResolvesToDouble, ResolvesToDecimal, ResolvesToLong { public const NAME = '$round'; public const ENCODE = \MongoDB\Builder\Encode::Array; @@ -32,7 +28,7 @@ class RoundAggregation implements ResolvesToInt, ResolvesToDouble, ResolvesToDec public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|float|int $number; /** @param Optional|ResolvesToInt|int $place Can be any valid expression that resolves to an integer between -20 and 100, exclusive. */ - public ResolvesToInt|Optional|int $place; + public Optional|ResolvesToInt|int $place; /** * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|float|int $number Can be any valid expression that resolves to a number. Specifically, the expression must resolve to an integer, double, decimal, or long. @@ -41,7 +37,7 @@ class RoundAggregation implements ResolvesToInt, ResolvesToDouble, ResolvesToDec */ public function __construct( Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|float|int $number, - ResolvesToInt|Optional|int $place = Optional::Undefined, + Optional|ResolvesToInt|int $place = Optional::Undefined, ) { $this->number = $number; $this->place = $place; diff --git a/src/Builder/Aggregation/RtrimAggregation.php b/src/Builder/Expression/RtrimOperator.php similarity index 87% rename from src/Builder/Aggregation/RtrimAggregation.php rename to src/Builder/Expression/RtrimOperator.php index 03bd1c7e4..b65d08823 100644 --- a/src/Builder/Aggregation/RtrimAggregation.php +++ b/src/Builder/Expression/RtrimOperator.php @@ -4,10 +4,9 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToString; use MongoDB\Builder\Optional; /** @@ -15,7 +14,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/rtrim/ */ -class RtrimAggregation implements ResolvesToString +class RtrimOperator implements ResolvesToString { public const NAME = '$rtrim'; public const ENCODE = \MongoDB\Builder\Encode::Object; @@ -28,7 +27,7 @@ class RtrimAggregation implements ResolvesToString * 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. */ - public ResolvesToString|Optional|string $chars; + public Optional|ResolvesToString|string $chars; /** * @param ResolvesToString|non-empty-string $input The string to trim. The argument can be any valid expression that resolves to a string. @@ -38,7 +37,7 @@ class RtrimAggregation implements ResolvesToString */ public function __construct( ResolvesToString|string $input, - ResolvesToString|Optional|string $chars = Optional::Undefined, + Optional|ResolvesToString|string $chars = Optional::Undefined, ) { $this->input = $input; $this->chars = $chars; diff --git a/src/Builder/Aggregation/SampleRateAggregation.php b/src/Builder/Expression/SampleRateOperator.php similarity index 88% rename from src/Builder/Aggregation/SampleRateAggregation.php rename to src/Builder/Expression/SampleRateOperator.php index ec1652f07..2f7409de1 100644 --- a/src/Builder/Aggregation/SampleRateAggregation.php +++ b/src/Builder/Expression/SampleRateOperator.php @@ -4,19 +4,17 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Int64; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToAny; -use MongoDB\Builder\Expression\ResolvesToDouble; /** * 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. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/sampleRate/ */ -class SampleRateAggregation implements ResolvesToAny +class SampleRateOperator implements ResolvesToAny { public const NAME = '$sampleRate'; public const ENCODE = \MongoDB\Builder\Encode::Single; diff --git a/src/Builder/Aggregation/SecondAggregation.php b/src/Builder/Expression/SecondOperator.php similarity index 80% rename from src/Builder/Aggregation/SecondAggregation.php rename to src/Builder/Expression/SecondOperator.php index 0e6a17d3d..7cca04108 100644 --- a/src/Builder/Aggregation/SecondAggregation.php +++ b/src/Builder/Expression/SecondOperator.php @@ -4,17 +4,12 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\ObjectId; use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToDate; -use MongoDB\Builder\Expression\ResolvesToInt; -use MongoDB\Builder\Expression\ResolvesToObjectId; -use MongoDB\Builder\Expression\ResolvesToString; -use MongoDB\Builder\Expression\ResolvesToTimestamp; use MongoDB\Builder\Optional; /** @@ -22,7 +17,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/second/ */ -class SecondAggregation implements ResolvesToInt +class SecondOperator implements ResolvesToInt { public const NAME = '$second'; public const ENCODE = \MongoDB\Builder\Encode::Object; @@ -31,7 +26,7 @@ class SecondAggregation implements ResolvesToInt public ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; /** @param Optional|ResolvesToString|non-empty-string $timezone 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. */ - public ResolvesToString|Optional|string $timezone; + public Optional|ResolvesToString|string $timezone; /** * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. @@ -39,7 +34,7 @@ class SecondAggregation implements ResolvesToInt */ public function __construct( ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, - ResolvesToString|Optional|string $timezone = Optional::Undefined, + Optional|ResolvesToString|string $timezone = Optional::Undefined, ) { $this->date = $date; $this->timezone = $timezone; diff --git a/src/Builder/Aggregation/SetDifferenceAggregation.php b/src/Builder/Expression/SetDifferenceOperator.php similarity index 93% rename from src/Builder/Aggregation/SetDifferenceAggregation.php rename to src/Builder/Expression/SetDifferenceOperator.php index e613a4f22..44ab89dbb 100644 --- a/src/Builder/Aggregation/SetDifferenceAggregation.php +++ b/src/Builder/Expression/SetDifferenceOperator.php @@ -4,11 +4,10 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\PackedArray; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToArray; use MongoDB\Model\BSONArray; /** @@ -16,7 +15,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/setDifference/ */ -class SetDifferenceAggregation implements ResolvesToArray +class SetDifferenceOperator implements ResolvesToArray { public const NAME = '$setDifference'; public const ENCODE = \MongoDB\Builder\Encode::Array; diff --git a/src/Builder/Aggregation/SetEqualsAggregation.php b/src/Builder/Expression/SetEqualsOperator.php similarity index 86% rename from src/Builder/Aggregation/SetEqualsAggregation.php rename to src/Builder/Expression/SetEqualsOperator.php index 11f865d3d..c52314d14 100644 --- a/src/Builder/Aggregation/SetEqualsAggregation.php +++ b/src/Builder/Expression/SetEqualsOperator.php @@ -4,12 +4,10 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\PackedArray; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToArray; -use MongoDB\Builder\Expression\ResolvesToBool; use MongoDB\Model\BSONArray; /** @@ -17,7 +15,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/setEquals/ */ -class SetEqualsAggregation implements ResolvesToBool +class SetEqualsOperator implements ResolvesToBool { public const NAME = '$setEquals'; public const ENCODE = \MongoDB\Builder\Encode::Single; diff --git a/src/Builder/Aggregation/SetFieldAggregation.php b/src/Builder/Expression/SetFieldOperator.php similarity index 88% rename from src/Builder/Aggregation/SetFieldAggregation.php rename to src/Builder/Expression/SetFieldOperator.php index 4f05611ed..9c8e93f72 100644 --- a/src/Builder/Aggregation/SetFieldAggregation.php +++ b/src/Builder/Expression/SetFieldOperator.php @@ -4,7 +4,7 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Binary; use MongoDB\BSON\Decimal128; @@ -17,9 +17,6 @@ use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToInt; -use MongoDB\Builder\Expression\ResolvesToObject; -use MongoDB\Builder\Expression\ResolvesToString; use MongoDB\Builder\Type\ExpressionInterface; use MongoDB\Model\BSONArray; use stdClass; @@ -30,7 +27,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/setField/ */ -class SetFieldAggregation implements ResolvesToObject +class SetFieldOperator implements ResolvesToObject { public const NAME = '$setField'; public const ENCODE = \MongoDB\Builder\Encode::Object; @@ -60,10 +57,6 @@ public function __construct( ) { $this->field = $field; $this->input = $input; - if (\is_array($value) && ! \array_is_list($value)) { - throw new \InvalidArgumentException('Expected $value argument to be a list, got an associative array.'); - } - $this->value = $value; } } diff --git a/src/Builder/Aggregation/SetIntersectionAggregation.php b/src/Builder/Expression/SetIntersectionOperator.php similarity index 89% rename from src/Builder/Aggregation/SetIntersectionAggregation.php rename to src/Builder/Expression/SetIntersectionOperator.php index 95ba07813..a15b2b638 100644 --- a/src/Builder/Aggregation/SetIntersectionAggregation.php +++ b/src/Builder/Expression/SetIntersectionOperator.php @@ -4,11 +4,10 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\PackedArray; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToArray; use MongoDB\Model\BSONArray; /** @@ -16,7 +15,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/setIntersection/ */ -class SetIntersectionAggregation implements ResolvesToArray +class SetIntersectionOperator implements ResolvesToArray { public const NAME = '$setIntersection'; public const ENCODE = \MongoDB\Builder\Encode::Single; diff --git a/src/Builder/Aggregation/SetIsSubsetAggregation.php b/src/Builder/Expression/SetIsSubsetOperator.php similarity index 89% rename from src/Builder/Aggregation/SetIsSubsetAggregation.php rename to src/Builder/Expression/SetIsSubsetOperator.php index 178150cda..c21955451 100644 --- a/src/Builder/Aggregation/SetIsSubsetAggregation.php +++ b/src/Builder/Expression/SetIsSubsetOperator.php @@ -4,12 +4,10 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\PackedArray; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToArray; -use MongoDB\Builder\Expression\ResolvesToBool; use MongoDB\Model\BSONArray; /** @@ -17,7 +15,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/setIsSubset/ */ -class SetIsSubsetAggregation implements ResolvesToBool +class SetIsSubsetOperator implements ResolvesToBool { public const NAME = '$setIsSubset'; public const ENCODE = \MongoDB\Builder\Encode::Array; diff --git a/src/Builder/Aggregation/SetUnionAggregation.php b/src/Builder/Expression/SetUnionOperator.php similarity index 89% rename from src/Builder/Aggregation/SetUnionAggregation.php rename to src/Builder/Expression/SetUnionOperator.php index 8804b4bbd..764cdc457 100644 --- a/src/Builder/Aggregation/SetUnionAggregation.php +++ b/src/Builder/Expression/SetUnionOperator.php @@ -4,11 +4,10 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\PackedArray; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToArray; use MongoDB\Model\BSONArray; /** @@ -16,7 +15,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/setUnion/ */ -class SetUnionAggregation implements ResolvesToArray +class SetUnionOperator implements ResolvesToArray { public const NAME = '$setUnion'; public const ENCODE = \MongoDB\Builder\Encode::Single; diff --git a/src/Builder/Aggregation/ShiftAggregation.php b/src/Builder/Expression/ShiftOperator.php similarity index 88% rename from src/Builder/Aggregation/ShiftAggregation.php rename to src/Builder/Expression/ShiftOperator.php index ad33cea5d..eaf5ac986 100644 --- a/src/Builder/Aggregation/ShiftAggregation.php +++ b/src/Builder/Expression/ShiftOperator.php @@ -4,7 +4,7 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Binary; use MongoDB\BSON\Decimal128; @@ -17,9 +17,8 @@ use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToAny; -use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Type\ExpressionInterface; +use MongoDB\Builder\Type\WindowInterface; use MongoDB\Model\BSONArray; use stdClass; @@ -29,7 +28,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/shift/ */ -class ShiftAggregation implements ResolvesToAny +class ShiftOperator implements WindowInterface { public const NAME = '$shift'; public const ENCODE = \MongoDB\Builder\Encode::Object; @@ -69,16 +68,8 @@ public function __construct( int $by, Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $default, ) { - if (\is_array($output) && ! \array_is_list($output)) { - throw new \InvalidArgumentException('Expected $output argument to be a list, got an associative array.'); - } - $this->output = $output; $this->by = $by; - if (\is_array($default) && ! \array_is_list($default)) { - throw new \InvalidArgumentException('Expected $default argument to be a list, got an associative array.'); - } - $this->default = $default; } } diff --git a/src/Builder/Expression/SinOperator.php b/src/Builder/Expression/SinOperator.php new file mode 100644 index 000000000..898c9f08a --- /dev/null +++ b/src/Builder/Expression/SinOperator.php @@ -0,0 +1,37 @@ +expression = $expression; + } +} diff --git a/src/Builder/Expression/SinhOperator.php b/src/Builder/Expression/SinhOperator.php new file mode 100644 index 000000000..2ea552657 --- /dev/null +++ b/src/Builder/Expression/SinhOperator.php @@ -0,0 +1,37 @@ +expression = $expression; + } +} diff --git a/src/Builder/Aggregation/SizeAggregation.php b/src/Builder/Expression/SizeOperator.php similarity index 86% rename from src/Builder/Aggregation/SizeAggregation.php rename to src/Builder/Expression/SizeOperator.php index ea1f8bb38..faed98981 100644 --- a/src/Builder/Aggregation/SizeAggregation.php +++ b/src/Builder/Expression/SizeOperator.php @@ -4,12 +4,10 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\PackedArray; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToArray; -use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Model\BSONArray; /** @@ -17,7 +15,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/size/ */ -class SizeAggregation implements ResolvesToInt +class SizeOperator implements ResolvesToInt { public const NAME = '$size'; public const ENCODE = \MongoDB\Builder\Encode::Single; diff --git a/src/Builder/Aggregation/SliceAggregation.php b/src/Builder/Expression/SliceOperator.php similarity index 91% rename from src/Builder/Aggregation/SliceAggregation.php rename to src/Builder/Expression/SliceOperator.php index 70f491fb6..1a4fe3f3f 100644 --- a/src/Builder/Aggregation/SliceAggregation.php +++ b/src/Builder/Expression/SliceOperator.php @@ -4,13 +4,12 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\PackedArray; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToArray; -use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Optional; +use MongoDB\Builder\Type\ProjectionInterface; use MongoDB\Model\BSONArray; /** @@ -18,7 +17,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/slice/ */ -class SliceAggregation implements ResolvesToArray +class SliceOperator implements ResolvesToArray, ProjectionInterface { public const NAME = '$slice'; public const ENCODE = \MongoDB\Builder\Encode::Array; @@ -38,7 +37,7 @@ class SliceAggregation implements ResolvesToArray * 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. */ - public ResolvesToInt|Optional|int $position; + public Optional|ResolvesToInt|int $position; /** * @param BSONArray|PackedArray|ResolvesToArray|array $expression Any valid expression as long as it resolves to an array. @@ -52,7 +51,7 @@ class SliceAggregation implements ResolvesToArray public function __construct( PackedArray|ResolvesToArray|BSONArray|array $expression, ResolvesToInt|int $n, - ResolvesToInt|Optional|int $position = Optional::Undefined, + Optional|ResolvesToInt|int $position = Optional::Undefined, ) { if (\is_array($expression) && ! \array_is_list($expression)) { throw new \InvalidArgumentException('Expected $expression argument to be a list, got an associative array.'); diff --git a/src/Builder/Aggregation/SortArrayAggregation.php b/src/Builder/Expression/SortArrayOperator.php similarity index 90% rename from src/Builder/Aggregation/SortArrayAggregation.php rename to src/Builder/Expression/SortArrayOperator.php index 6e1bfe561..7bfd9963b 100644 --- a/src/Builder/Aggregation/SortArrayAggregation.php +++ b/src/Builder/Expression/SortArrayOperator.php @@ -4,13 +4,12 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Document; use MongoDB\BSON\PackedArray; use MongoDB\BSON\Serializable; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToArray; use MongoDB\Model\BSONArray; use stdClass; @@ -19,7 +18,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/sortArray/ */ -class SortArrayAggregation implements ResolvesToArray +class SortArrayOperator implements ResolvesToArray { public const NAME = '$sortArray'; public const ENCODE = \MongoDB\Builder\Encode::Object; diff --git a/src/Builder/Aggregation/SplitAggregation.php b/src/Builder/Expression/SplitOperator.php similarity index 88% rename from src/Builder/Aggregation/SplitAggregation.php rename to src/Builder/Expression/SplitOperator.php index a8fd48b10..4d8ca6b65 100644 --- a/src/Builder/Aggregation/SplitAggregation.php +++ b/src/Builder/Expression/SplitOperator.php @@ -4,18 +4,16 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToArray; -use MongoDB\Builder\Expression\ResolvesToString; /** * 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. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/split/ */ -class SplitAggregation implements ResolvesToArray +class SplitOperator implements ResolvesToArray { public const NAME = '$split'; public const ENCODE = \MongoDB\Builder\Encode::Array; diff --git a/src/Builder/Expression/SqrtOperator.php b/src/Builder/Expression/SqrtOperator.php new file mode 100644 index 000000000..2266aa089 --- /dev/null +++ b/src/Builder/Expression/SqrtOperator.php @@ -0,0 +1,33 @@ +number = $number; + } +} diff --git a/src/Builder/Aggregation/StdDevPopAggregation.php b/src/Builder/Expression/StdDevPopOperator.php similarity index 62% rename from src/Builder/Aggregation/StdDevPopAggregation.php rename to src/Builder/Expression/StdDevPopOperator.php index c785007c8..a161ff97f 100644 --- a/src/Builder/Aggregation/StdDevPopAggregation.php +++ b/src/Builder/Expression/StdDevPopOperator.php @@ -4,16 +4,11 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Decimal128; use MongoDB\BSON\Int64; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToDecimal; -use MongoDB\Builder\Expression\ResolvesToDouble; -use MongoDB\Builder\Expression\ResolvesToInt; -use MongoDB\Builder\Expression\ResolvesToLong; -use MongoDB\Builder\Expression\ResolvesToNumber; use MongoDB\Builder\Type\AccumulatorInterface; /** @@ -23,21 +18,20 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/stdDevPop/ */ -class StdDevPopAggregation implements ResolvesToDouble, AccumulatorInterface +class StdDevPopOperator implements ResolvesToDouble, AccumulatorInterface { public const NAME = '$stdDevPop'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param list ...$expression */ + /** @param list ...$expression */ public array $expression; /** - * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int ...$expression + * @param Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int ...$expression * @no-named-arguments */ - public function __construct( - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int ...$expression, - ) { + public function __construct(Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int ...$expression) + { if (\count($expression) < 1) { throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); } diff --git a/src/Builder/Aggregation/StdDevSampAggregation.php b/src/Builder/Expression/StdDevSampOperator.php similarity index 62% rename from src/Builder/Aggregation/StdDevSampAggregation.php rename to src/Builder/Expression/StdDevSampOperator.php index 32b24e776..05806a563 100644 --- a/src/Builder/Aggregation/StdDevSampAggregation.php +++ b/src/Builder/Expression/StdDevSampOperator.php @@ -4,16 +4,11 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Decimal128; use MongoDB\BSON\Int64; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToDecimal; -use MongoDB\Builder\Expression\ResolvesToDouble; -use MongoDB\Builder\Expression\ResolvesToInt; -use MongoDB\Builder\Expression\ResolvesToLong; -use MongoDB\Builder\Expression\ResolvesToNumber; use MongoDB\Builder\Type\AccumulatorInterface; /** @@ -23,21 +18,20 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/stdDevSamp/ */ -class StdDevSampAggregation implements ResolvesToDouble, AccumulatorInterface +class StdDevSampOperator implements ResolvesToDouble, AccumulatorInterface { public const NAME = '$stdDevSamp'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param list ...$expression */ + /** @param list ...$expression */ public array $expression; /** - * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int ...$expression + * @param Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int ...$expression * @no-named-arguments */ - public function __construct( - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int ...$expression, - ) { + public function __construct(Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int ...$expression) + { if (\count($expression) < 1) { throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); } diff --git a/src/Builder/Aggregation/StrLenBytesAggregation.php b/src/Builder/Expression/StrLenBytesOperator.php similarity index 78% rename from src/Builder/Aggregation/StrLenBytesAggregation.php rename to src/Builder/Expression/StrLenBytesOperator.php index 2568a2c15..fb063f62b 100644 --- a/src/Builder/Aggregation/StrLenBytesAggregation.php +++ b/src/Builder/Expression/StrLenBytesOperator.php @@ -4,18 +4,16 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToInt; -use MongoDB\Builder\Expression\ResolvesToString; /** * Returns the number of UTF-8 encoded bytes in a string. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/strLenBytes/ */ -class StrLenBytesAggregation implements ResolvesToInt +class StrLenBytesOperator implements ResolvesToInt { public const NAME = '$strLenBytes'; public const ENCODE = \MongoDB\Builder\Encode::Single; diff --git a/src/Builder/Aggregation/StrLenCPAggregation.php b/src/Builder/Expression/StrLenCPOperator.php similarity index 78% rename from src/Builder/Aggregation/StrLenCPAggregation.php rename to src/Builder/Expression/StrLenCPOperator.php index 0377fd374..275253bd6 100644 --- a/src/Builder/Aggregation/StrLenCPAggregation.php +++ b/src/Builder/Expression/StrLenCPOperator.php @@ -4,18 +4,16 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToInt; -use MongoDB\Builder\Expression\ResolvesToString; /** * Returns the number of UTF-8 code points in a string. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/strLenCP/ */ -class StrLenCPAggregation implements ResolvesToInt +class StrLenCPOperator implements ResolvesToInt { public const NAME = '$strLenCP'; public const ENCODE = \MongoDB\Builder\Encode::Single; diff --git a/src/Builder/Aggregation/StrcasecmpAggregation.php b/src/Builder/Expression/StrcasecmpOperator.php similarity index 85% rename from src/Builder/Aggregation/StrcasecmpAggregation.php rename to src/Builder/Expression/StrcasecmpOperator.php index 3567c8b57..89527917d 100644 --- a/src/Builder/Aggregation/StrcasecmpAggregation.php +++ b/src/Builder/Expression/StrcasecmpOperator.php @@ -4,18 +4,16 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToInt; -use MongoDB\Builder\Expression\ResolvesToString; /** * 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. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/strcasecmp/ */ -class StrcasecmpAggregation implements ResolvesToInt +class StrcasecmpOperator implements ResolvesToInt { public const NAME = '$strcasecmp'; public const ENCODE = \MongoDB\Builder\Encode::Array; diff --git a/src/Builder/Aggregation/SubstrBytesAggregation.php b/src/Builder/Expression/SubstrBytesOperator.php similarity index 88% rename from src/Builder/Aggregation/SubstrBytesAggregation.php rename to src/Builder/Expression/SubstrBytesOperator.php index 7a168f558..836794223 100644 --- a/src/Builder/Aggregation/SubstrBytesAggregation.php +++ b/src/Builder/Expression/SubstrBytesOperator.php @@ -4,18 +4,16 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToInt; -use MongoDB\Builder\Expression\ResolvesToString; /** * 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. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/substrBytes/ */ -class SubstrBytesAggregation implements ResolvesToString +class SubstrBytesOperator implements ResolvesToString { public const NAME = '$substrBytes'; public const ENCODE = \MongoDB\Builder\Encode::Array; diff --git a/src/Builder/Aggregation/SubstrCPAggregation.php b/src/Builder/Expression/SubstrCPOperator.php similarity index 89% rename from src/Builder/Aggregation/SubstrCPAggregation.php rename to src/Builder/Expression/SubstrCPOperator.php index 734fcacab..007fd3e08 100644 --- a/src/Builder/Aggregation/SubstrCPAggregation.php +++ b/src/Builder/Expression/SubstrCPOperator.php @@ -4,18 +4,16 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToInt; -use MongoDB\Builder\Expression\ResolvesToString; /** * 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. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/substrCP/ */ -class SubstrCPAggregation implements ResolvesToString +class SubstrCPOperator implements ResolvesToString { public const NAME = '$substrCP'; public const ENCODE = \MongoDB\Builder\Encode::Array; diff --git a/src/Builder/Aggregation/SubstrAggregation.php b/src/Builder/Expression/SubstrOperator.php similarity index 88% rename from src/Builder/Aggregation/SubstrAggregation.php rename to src/Builder/Expression/SubstrOperator.php index fad3bd99d..a566eab7e 100644 --- a/src/Builder/Aggregation/SubstrAggregation.php +++ b/src/Builder/Expression/SubstrOperator.php @@ -4,18 +4,16 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToInt; -use MongoDB\Builder\Expression\ResolvesToString; /** * Deprecated. Use $substrBytes or $substrCP. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/substr/ */ -class SubstrAggregation implements ResolvesToString +class SubstrOperator implements ResolvesToString { public const NAME = '$substr'; public const ENCODE = \MongoDB\Builder\Encode::Array; diff --git a/src/Builder/Expression/SubtractOperator.php b/src/Builder/Expression/SubtractOperator.php new file mode 100644 index 000000000..10fbad20c --- /dev/null +++ b/src/Builder/Expression/SubtractOperator.php @@ -0,0 +1,41 @@ +expression1 = $expression1; + $this->expression2 = $expression2; + } +} diff --git a/src/Builder/Aggregation/SumAggregation.php b/src/Builder/Expression/SumOperator.php similarity index 55% rename from src/Builder/Aggregation/SumAggregation.php rename to src/Builder/Expression/SumOperator.php index b46ce52e1..5a033694d 100644 --- a/src/Builder/Aggregation/SumAggregation.php +++ b/src/Builder/Expression/SumOperator.php @@ -4,16 +4,11 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Decimal128; use MongoDB\BSON\Int64; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToDecimal; -use MongoDB\Builder\Expression\ResolvesToDouble; -use MongoDB\Builder\Expression\ResolvesToInt; -use MongoDB\Builder\Expression\ResolvesToLong; -use MongoDB\Builder\Expression\ResolvesToNumber; use MongoDB\Builder\Type\AccumulatorInterface; /** @@ -22,21 +17,20 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/sum/ */ -class SumAggregation implements ResolvesToNumber, AccumulatorInterface +class SumOperator implements ResolvesToNumber, AccumulatorInterface { public const NAME = '$sum'; public const ENCODE = \MongoDB\Builder\Encode::Single; - /** @param list ...$expression */ + /** @param list ...$expression */ public array $expression; /** - * @param Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int ...$expression + * @param Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int ...$expression * @no-named-arguments */ - public function __construct( - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|ResolvesToNumber|float|int ...$expression, - ) { + public function __construct(Decimal128|Int64|ResolvesToInt|ResolvesToNumber|float|int ...$expression) + { if (\count($expression) < 1) { throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $expression, got %d.', 1, \count($expression))); } diff --git a/src/Builder/Aggregation/SwitchAggregation.php b/src/Builder/Expression/SwitchOperator.php similarity index 77% rename from src/Builder/Aggregation/SwitchAggregation.php rename to src/Builder/Expression/SwitchOperator.php index eac030021..a9388e1b0 100644 --- a/src/Builder/Aggregation/SwitchAggregation.php +++ b/src/Builder/Expression/SwitchOperator.php @@ -4,7 +4,7 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Binary; use MongoDB\BSON\Decimal128; @@ -17,8 +17,6 @@ use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToAny; -use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Optional; use MongoDB\Builder\Type\ExpressionInterface; use MongoDB\Model\BSONArray; @@ -29,7 +27,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/switch/ */ -class SwitchAggregation implements ResolvesToAny +class SwitchOperator implements ResolvesToAny { public const NAME = '$switch'; public const ENCODE = \MongoDB\Builder\Encode::Object; @@ -43,32 +41,28 @@ class SwitchAggregation implements ResolvesToAny public PackedArray|BSONArray|array $branches; /** - * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|Optional|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $default The path to take if no branch case expression evaluates to true. + * @param Optional|BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $default 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. */ - public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|Optional|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $default; + public Optional|Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $default; /** * @param BSONArray|PackedArray|array $branches 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. - * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|Optional|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $default The path to take if no branch case expression evaluates to true. + * @param Optional|BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $default 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. */ public function __construct( PackedArray|BSONArray|array $branches, - Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|Optional|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $default = Optional::Undefined, + Optional|Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $default = Optional::Undefined, ) { if (\is_array($branches) && ! \array_is_list($branches)) { throw new \InvalidArgumentException('Expected $branches argument to be a list, got an associative array.'); } $this->branches = $branches; - if (\is_array($default) && ! \array_is_list($default)) { - throw new \InvalidArgumentException('Expected $default argument to be a list, got an associative array.'); - } - $this->default = $default; } } diff --git a/src/Builder/Expression/TanOperator.php b/src/Builder/Expression/TanOperator.php new file mode 100644 index 000000000..fd7e6d9a9 --- /dev/null +++ b/src/Builder/Expression/TanOperator.php @@ -0,0 +1,37 @@ +expression = $expression; + } +} diff --git a/src/Builder/Expression/TanhOperator.php b/src/Builder/Expression/TanhOperator.php new file mode 100644 index 000000000..bd2c6dede --- /dev/null +++ b/src/Builder/Expression/TanhOperator.php @@ -0,0 +1,37 @@ +expression = $expression; + } +} diff --git a/src/Builder/Aggregation/ToBoolAggregation.php b/src/Builder/Expression/ToBoolOperator.php similarity index 81% rename from src/Builder/Aggregation/ToBoolAggregation.php rename to src/Builder/Expression/ToBoolOperator.php index e39e03c3c..2a48612db 100644 --- a/src/Builder/Aggregation/ToBoolAggregation.php +++ b/src/Builder/Expression/ToBoolOperator.php @@ -4,7 +4,7 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Binary; use MongoDB\BSON\Decimal128; @@ -17,8 +17,6 @@ use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToBool; -use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Type\ExpressionInterface; use MongoDB\Model\BSONArray; use stdClass; @@ -29,7 +27,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toBool/ */ -class ToBoolAggregation implements ResolvesToBool +class ToBoolOperator implements ResolvesToBool { public const NAME = '$toBool'; public const ENCODE = \MongoDB\Builder\Encode::Single; @@ -43,10 +41,6 @@ class ToBoolAggregation implements ResolvesToBool public function __construct( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, ) { - if (\is_array($expression) && ! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression argument to be a list, got an associative array.'); - } - $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/ToDateAggregation.php b/src/Builder/Expression/ToDateOperator.php similarity index 81% rename from src/Builder/Aggregation/ToDateAggregation.php rename to src/Builder/Expression/ToDateOperator.php index dd2fab1ed..c65f86370 100644 --- a/src/Builder/Aggregation/ToDateAggregation.php +++ b/src/Builder/Expression/ToDateOperator.php @@ -4,7 +4,7 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Binary; use MongoDB\BSON\Decimal128; @@ -17,8 +17,6 @@ use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToDate; -use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Type\ExpressionInterface; use MongoDB\Model\BSONArray; use stdClass; @@ -29,7 +27,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toDate/ */ -class ToDateAggregation implements ResolvesToDate +class ToDateOperator implements ResolvesToDate { public const NAME = '$toDate'; public const ENCODE = \MongoDB\Builder\Encode::Single; @@ -43,10 +41,6 @@ class ToDateAggregation implements ResolvesToDate public function __construct( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, ) { - if (\is_array($expression) && ! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression argument to be a list, got an associative array.'); - } - $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/ToDecimalAggregation.php b/src/Builder/Expression/ToDecimalOperator.php similarity index 80% rename from src/Builder/Aggregation/ToDecimalAggregation.php rename to src/Builder/Expression/ToDecimalOperator.php index e712804d6..ed18db25f 100644 --- a/src/Builder/Aggregation/ToDecimalAggregation.php +++ b/src/Builder/Expression/ToDecimalOperator.php @@ -4,7 +4,7 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Binary; use MongoDB\BSON\Decimal128; @@ -17,8 +17,6 @@ use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToDecimal; -use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Type\ExpressionInterface; use MongoDB\Model\BSONArray; use stdClass; @@ -29,7 +27,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toDecimal/ */ -class ToDecimalAggregation implements ResolvesToDecimal +class ToDecimalOperator implements ResolvesToDecimal { public const NAME = '$toDecimal'; public const ENCODE = \MongoDB\Builder\Encode::Single; @@ -43,10 +41,6 @@ class ToDecimalAggregation implements ResolvesToDecimal public function __construct( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, ) { - if (\is_array($expression) && ! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression argument to be a list, got an associative array.'); - } - $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/ToDoubleAggregation.php b/src/Builder/Expression/ToDoubleOperator.php similarity index 80% rename from src/Builder/Aggregation/ToDoubleAggregation.php rename to src/Builder/Expression/ToDoubleOperator.php index 6893e85ba..5e529669f 100644 --- a/src/Builder/Aggregation/ToDoubleAggregation.php +++ b/src/Builder/Expression/ToDoubleOperator.php @@ -4,7 +4,7 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Binary; use MongoDB\BSON\Decimal128; @@ -17,8 +17,6 @@ use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToDouble; -use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Type\ExpressionInterface; use MongoDB\Model\BSONArray; use stdClass; @@ -29,7 +27,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toDouble/ */ -class ToDoubleAggregation implements ResolvesToDouble +class ToDoubleOperator implements ResolvesToDouble { public const NAME = '$toDouble'; public const ENCODE = \MongoDB\Builder\Encode::Single; @@ -43,10 +41,6 @@ class ToDoubleAggregation implements ResolvesToDouble public function __construct( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, ) { - if (\is_array($expression) && ! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression argument to be a list, got an associative array.'); - } - $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/ToIntAggregation.php b/src/Builder/Expression/ToIntOperator.php similarity index 83% rename from src/Builder/Aggregation/ToIntAggregation.php rename to src/Builder/Expression/ToIntOperator.php index b216d8a21..fa6da3725 100644 --- a/src/Builder/Aggregation/ToIntAggregation.php +++ b/src/Builder/Expression/ToIntOperator.php @@ -4,7 +4,7 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Binary; use MongoDB\BSON\Decimal128; @@ -17,7 +17,6 @@ use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Type\ExpressionInterface; use MongoDB\Model\BSONArray; use stdClass; @@ -28,7 +27,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toInt/ */ -class ToIntAggregation implements ResolvesToInt +class ToIntOperator implements ResolvesToInt { public const NAME = '$toInt'; public const ENCODE = \MongoDB\Builder\Encode::Single; @@ -42,10 +41,6 @@ class ToIntAggregation implements ResolvesToInt public function __construct( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, ) { - if (\is_array($expression) && ! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression argument to be a list, got an associative array.'); - } - $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/ToLongAggregation.php b/src/Builder/Expression/ToLongOperator.php similarity index 81% rename from src/Builder/Aggregation/ToLongAggregation.php rename to src/Builder/Expression/ToLongOperator.php index c05b1542d..7b0af8462 100644 --- a/src/Builder/Aggregation/ToLongAggregation.php +++ b/src/Builder/Expression/ToLongOperator.php @@ -4,7 +4,7 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Binary; use MongoDB\BSON\Decimal128; @@ -17,8 +17,6 @@ use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToInt; -use MongoDB\Builder\Expression\ResolvesToLong; use MongoDB\Builder\Type\ExpressionInterface; use MongoDB\Model\BSONArray; use stdClass; @@ -29,7 +27,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toLong/ */ -class ToLongAggregation implements ResolvesToLong +class ToLongOperator implements ResolvesToLong { public const NAME = '$toLong'; public const ENCODE = \MongoDB\Builder\Encode::Single; @@ -43,10 +41,6 @@ class ToLongAggregation implements ResolvesToLong public function __construct( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, ) { - if (\is_array($expression) && ! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression argument to be a list, got an associative array.'); - } - $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/ToLowerAggregation.php b/src/Builder/Expression/ToLowerOperator.php similarity index 82% rename from src/Builder/Aggregation/ToLowerAggregation.php rename to src/Builder/Expression/ToLowerOperator.php index 213f6b19f..d0c965610 100644 --- a/src/Builder/Aggregation/ToLowerAggregation.php +++ b/src/Builder/Expression/ToLowerOperator.php @@ -4,17 +4,16 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToString; /** * Converts a string to lowercase. Accepts a single argument expression. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toLower/ */ -class ToLowerAggregation implements ResolvesToString +class ToLowerOperator implements ResolvesToString { public const NAME = '$toLower'; public const ENCODE = \MongoDB\Builder\Encode::Single; diff --git a/src/Builder/Aggregation/ToObjectIdAggregation.php b/src/Builder/Expression/ToObjectIdOperator.php similarity index 80% rename from src/Builder/Aggregation/ToObjectIdAggregation.php rename to src/Builder/Expression/ToObjectIdOperator.php index cffc9a46d..97c1bc4d4 100644 --- a/src/Builder/Aggregation/ToObjectIdAggregation.php +++ b/src/Builder/Expression/ToObjectIdOperator.php @@ -4,7 +4,7 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Binary; use MongoDB\BSON\Decimal128; @@ -17,8 +17,6 @@ use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToInt; -use MongoDB\Builder\Expression\ResolvesToObjectId; use MongoDB\Builder\Type\ExpressionInterface; use MongoDB\Model\BSONArray; use stdClass; @@ -29,7 +27,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toObjectId/ */ -class ToObjectIdAggregation implements ResolvesToObjectId +class ToObjectIdOperator implements ResolvesToObjectId { public const NAME = '$toObjectId'; public const ENCODE = \MongoDB\Builder\Encode::Single; @@ -43,10 +41,6 @@ class ToObjectIdAggregation implements ResolvesToObjectId public function __construct( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, ) { - if (\is_array($expression) && ! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression argument to be a list, got an associative array.'); - } - $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/ToStringAggregation.php b/src/Builder/Expression/ToStringOperator.php similarity index 80% rename from src/Builder/Aggregation/ToStringAggregation.php rename to src/Builder/Expression/ToStringOperator.php index e43edd0ce..48a9dbf25 100644 --- a/src/Builder/Aggregation/ToStringAggregation.php +++ b/src/Builder/Expression/ToStringOperator.php @@ -4,7 +4,7 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Binary; use MongoDB\BSON\Decimal128; @@ -17,8 +17,6 @@ use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToInt; -use MongoDB\Builder\Expression\ResolvesToString; use MongoDB\Builder\Type\ExpressionInterface; use MongoDB\Model\BSONArray; use stdClass; @@ -29,7 +27,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toString/ */ -class ToStringAggregation implements ResolvesToString +class ToStringOperator implements ResolvesToString { public const NAME = '$toString'; public const ENCODE = \MongoDB\Builder\Encode::Single; @@ -43,10 +41,6 @@ class ToStringAggregation implements ResolvesToString public function __construct( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, ) { - if (\is_array($expression) && ! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression argument to be a list, got an associative array.'); - } - $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/ToUpperAggregation.php b/src/Builder/Expression/ToUpperOperator.php similarity index 82% rename from src/Builder/Aggregation/ToUpperAggregation.php rename to src/Builder/Expression/ToUpperOperator.php index f7152ff74..27a247d78 100644 --- a/src/Builder/Aggregation/ToUpperAggregation.php +++ b/src/Builder/Expression/ToUpperOperator.php @@ -4,17 +4,16 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToString; /** * Converts a string to uppercase. Accepts a single argument expression. * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toUpper/ */ -class ToUpperAggregation implements ResolvesToString +class ToUpperOperator implements ResolvesToString { public const NAME = '$toUpper'; public const ENCODE = \MongoDB\Builder\Encode::Single; diff --git a/src/Builder/Aggregation/TopNAggregation.php b/src/Builder/Expression/TopNOperator.php similarity index 89% rename from src/Builder/Aggregation/TopNAggregation.php rename to src/Builder/Expression/TopNOperator.php index d4b8bdb47..a50ea758b 100644 --- a/src/Builder/Aggregation/TopNAggregation.php +++ b/src/Builder/Expression/TopNOperator.php @@ -4,7 +4,7 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Binary; use MongoDB\BSON\Decimal128; @@ -17,7 +17,6 @@ use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Type\AccumulatorInterface; use MongoDB\Builder\Type\ExpressionInterface; use MongoDB\Model\BSONArray; @@ -31,7 +30,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/topN/ */ -class TopNAggregation implements AccumulatorInterface +class TopNOperator implements AccumulatorInterface { public const NAME = '$topN'; public const ENCODE = \MongoDB\Builder\Encode::Object; @@ -57,10 +56,6 @@ public function __construct( ) { $this->n = $n; $this->sortBy = $sortBy; - if (\is_array($output) && ! \array_is_list($output)) { - throw new \InvalidArgumentException('Expected $output argument to be a list, got an associative array.'); - } - $this->output = $output; } } diff --git a/src/Builder/Aggregation/TopAggregation.php b/src/Builder/Expression/TopOperator.php similarity index 87% rename from src/Builder/Aggregation/TopAggregation.php rename to src/Builder/Expression/TopOperator.php index 6c3744f6a..4d846c5b8 100644 --- a/src/Builder/Aggregation/TopAggregation.php +++ b/src/Builder/Expression/TopOperator.php @@ -4,7 +4,7 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Binary; use MongoDB\BSON\Decimal128; @@ -17,7 +17,6 @@ use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Type\AccumulatorInterface; use MongoDB\Builder\Type\ExpressionInterface; use MongoDB\Model\BSONArray; @@ -31,7 +30,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/top/ */ -class TopAggregation implements AccumulatorInterface +class TopOperator implements AccumulatorInterface { public const NAME = '$top'; public const ENCODE = \MongoDB\Builder\Encode::Object; @@ -51,10 +50,6 @@ public function __construct( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $output, ) { $this->sortBy = $sortBy; - if (\is_array($output) && ! \array_is_list($output)) { - throw new \InvalidArgumentException('Expected $output argument to be a list, got an associative array.'); - } - $this->output = $output; } } diff --git a/src/Builder/Aggregation/TrimAggregation.php b/src/Builder/Expression/TrimOperator.php similarity index 87% rename from src/Builder/Aggregation/TrimAggregation.php rename to src/Builder/Expression/TrimOperator.php index a695f6db3..83511dc63 100644 --- a/src/Builder/Aggregation/TrimAggregation.php +++ b/src/Builder/Expression/TrimOperator.php @@ -4,10 +4,9 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToString; use MongoDB\Builder\Optional; /** @@ -16,7 +15,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/trim/ */ -class TrimAggregation implements ResolvesToString +class TrimOperator implements ResolvesToString { public const NAME = '$trim'; public const ENCODE = \MongoDB\Builder\Encode::Object; @@ -29,7 +28,7 @@ class TrimAggregation implements ResolvesToString * 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. */ - public ResolvesToString|Optional|string $chars; + public Optional|ResolvesToString|string $chars; /** * @param ResolvesToString|non-empty-string $input The string to trim. The argument can be any valid expression that resolves to a string. @@ -39,7 +38,7 @@ class TrimAggregation implements ResolvesToString */ public function __construct( ResolvesToString|string $input, - ResolvesToString|Optional|string $chars = Optional::Undefined, + Optional|ResolvesToString|string $chars = Optional::Undefined, ) { $this->input = $input; $this->chars = $chars; diff --git a/src/Builder/Expression/TruncOperator.php b/src/Builder/Expression/TruncOperator.php new file mode 100644 index 000000000..30f51ac61 --- /dev/null +++ b/src/Builder/Expression/TruncOperator.php @@ -0,0 +1,45 @@ +number = $number; + $this->place = $place; + } +} diff --git a/src/Builder/Aggregation/TsIncrementAggregation.php b/src/Builder/Expression/TsIncrementOperator.php similarity index 79% rename from src/Builder/Aggregation/TsIncrementAggregation.php rename to src/Builder/Expression/TsIncrementOperator.php index afd4ff69e..4759fb92b 100644 --- a/src/Builder/Aggregation/TsIncrementAggregation.php +++ b/src/Builder/Expression/TsIncrementOperator.php @@ -4,12 +4,10 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Timestamp; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToLong; -use MongoDB\Builder\Expression\ResolvesToTimestamp; /** * Returns the incrementing ordinal from a timestamp as a long. @@ -17,7 +15,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/tsIncrement/ */ -class TsIncrementAggregation implements ResolvesToLong +class TsIncrementOperator implements ResolvesToLong { public const NAME = '$tsIncrement'; public const ENCODE = \MongoDB\Builder\Encode::Single; diff --git a/src/Builder/Aggregation/TsSecondAggregation.php b/src/Builder/Expression/TsSecondOperator.php similarity index 79% rename from src/Builder/Aggregation/TsSecondAggregation.php rename to src/Builder/Expression/TsSecondOperator.php index 12678baa1..d716afce7 100644 --- a/src/Builder/Aggregation/TsSecondAggregation.php +++ b/src/Builder/Expression/TsSecondOperator.php @@ -4,12 +4,10 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Timestamp; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToLong; -use MongoDB\Builder\Expression\ResolvesToTimestamp; /** * Returns the seconds from a timestamp as a long. @@ -17,7 +15,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/tsSecond/ */ -class TsSecondAggregation implements ResolvesToLong +class TsSecondOperator implements ResolvesToLong { public const NAME = '$tsSecond'; public const ENCODE = \MongoDB\Builder\Encode::Single; diff --git a/src/Builder/Aggregation/TypeAggregation.php b/src/Builder/Expression/TypeOperator.php similarity index 80% rename from src/Builder/Aggregation/TypeAggregation.php rename to src/Builder/Expression/TypeOperator.php index 0ceaa1bc9..fff12159a 100644 --- a/src/Builder/Aggregation/TypeAggregation.php +++ b/src/Builder/Expression/TypeOperator.php @@ -4,7 +4,7 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Binary; use MongoDB\BSON\Decimal128; @@ -17,8 +17,6 @@ use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToInt; -use MongoDB\Builder\Expression\ResolvesToString; use MongoDB\Builder\Type\ExpressionInterface; use MongoDB\Model\BSONArray; use stdClass; @@ -28,7 +26,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/type/ */ -class TypeAggregation implements ResolvesToString +class TypeOperator implements ResolvesToString { public const NAME = '$type'; public const ENCODE = \MongoDB\Builder\Encode::Single; @@ -42,10 +40,6 @@ class TypeAggregation implements ResolvesToString public function __construct( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, ) { - if (\is_array($expression) && ! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression argument to be a list, got an associative array.'); - } - $this->expression = $expression; } } diff --git a/src/Builder/Aggregation/UnsetFieldAggregation.php b/src/Builder/Expression/UnsetFieldOperator.php similarity index 89% rename from src/Builder/Aggregation/UnsetFieldAggregation.php rename to src/Builder/Expression/UnsetFieldOperator.php index db0210731..533f2680b 100644 --- a/src/Builder/Aggregation/UnsetFieldAggregation.php +++ b/src/Builder/Expression/UnsetFieldOperator.php @@ -4,13 +4,11 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\Document; use MongoDB\BSON\Serializable; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToObject; -use MongoDB\Builder\Expression\ResolvesToString; use stdClass; /** @@ -19,7 +17,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/unsetField/ */ -class UnsetFieldAggregation implements ResolvesToObject +class UnsetFieldOperator implements ResolvesToObject { public const NAME = '$unsetField'; public const ENCODE = \MongoDB\Builder\Encode::Object; diff --git a/src/Builder/Expression/Variable.php b/src/Builder/Expression/Variable.php index bdbfbcf76..dbb570092 100644 --- a/src/Builder/Expression/Variable.php +++ b/src/Builder/Expression/Variable.php @@ -6,9 +6,7 @@ namespace MongoDB\Builder\Expression; -use MongoDB\Builder\Type\ExpressionInterface; - -class Variable implements ExpressionInterface +class Variable implements ResolvesToAny { public string $expression; diff --git a/src/Builder/Aggregation/WeekAggregation.php b/src/Builder/Expression/WeekOperator.php similarity index 81% rename from src/Builder/Aggregation/WeekAggregation.php rename to src/Builder/Expression/WeekOperator.php index e3ae7d643..21717ca75 100644 --- a/src/Builder/Aggregation/WeekAggregation.php +++ b/src/Builder/Expression/WeekOperator.php @@ -4,17 +4,12 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\ObjectId; use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToDate; -use MongoDB\Builder\Expression\ResolvesToInt; -use MongoDB\Builder\Expression\ResolvesToObjectId; -use MongoDB\Builder\Expression\ResolvesToString; -use MongoDB\Builder\Expression\ResolvesToTimestamp; use MongoDB\Builder\Optional; /** @@ -22,7 +17,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/week/ */ -class WeekAggregation implements ResolvesToInt +class WeekOperator implements ResolvesToInt { public const NAME = '$week'; public const ENCODE = \MongoDB\Builder\Encode::Object; @@ -31,7 +26,7 @@ class WeekAggregation implements ResolvesToInt public ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; /** @param Optional|ResolvesToString|non-empty-string $timezone 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. */ - public ResolvesToString|Optional|string $timezone; + public Optional|ResolvesToString|string $timezone; /** * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. @@ -39,7 +34,7 @@ class WeekAggregation implements ResolvesToInt */ public function __construct( ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, - ResolvesToString|Optional|string $timezone = Optional::Undefined, + Optional|ResolvesToString|string $timezone = Optional::Undefined, ) { $this->date = $date; $this->timezone = $timezone; diff --git a/src/Builder/Aggregation/YearAggregation.php b/src/Builder/Expression/YearOperator.php similarity index 80% rename from src/Builder/Aggregation/YearAggregation.php rename to src/Builder/Expression/YearOperator.php index 178218dcc..62d18f70f 100644 --- a/src/Builder/Aggregation/YearAggregation.php +++ b/src/Builder/Expression/YearOperator.php @@ -4,17 +4,12 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\ObjectId; use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToDate; -use MongoDB\Builder\Expression\ResolvesToInt; -use MongoDB\Builder\Expression\ResolvesToObjectId; -use MongoDB\Builder\Expression\ResolvesToString; -use MongoDB\Builder\Expression\ResolvesToTimestamp; use MongoDB\Builder\Optional; /** @@ -22,7 +17,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/year/ */ -class YearAggregation implements ResolvesToInt +class YearOperator implements ResolvesToInt { public const NAME = '$year'; public const ENCODE = \MongoDB\Builder\Encode::Object; @@ -31,7 +26,7 @@ class YearAggregation implements ResolvesToInt public ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date; /** @param Optional|ResolvesToString|non-empty-string $timezone 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. */ - public ResolvesToString|Optional|string $timezone; + public Optional|ResolvesToString|string $timezone; /** * @param ObjectId|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|Timestamp|UTCDateTime|int $date The date to which the operator is applied. date must be a valid expression that resolves to a Date, a Timestamp, or an ObjectID. @@ -39,7 +34,7 @@ class YearAggregation implements ResolvesToInt */ public function __construct( ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date, - ResolvesToString|Optional|string $timezone = Optional::Undefined, + Optional|ResolvesToString|string $timezone = Optional::Undefined, ) { $this->date = $date; $this->timezone = $timezone; diff --git a/src/Builder/Aggregation/ZipAggregation.php b/src/Builder/Expression/ZipOperator.php similarity index 96% rename from src/Builder/Aggregation/ZipAggregation.php rename to src/Builder/Expression/ZipOperator.php index 7c1489e07..cdbe075e6 100644 --- a/src/Builder/Aggregation/ZipAggregation.php +++ b/src/Builder/Expression/ZipOperator.php @@ -4,11 +4,10 @@ * THIS FILE IS AUTO-GENERATED. ANY CHANGES WILL BE LOST! */ -namespace MongoDB\Builder\Aggregation; +namespace MongoDB\Builder\Expression; use MongoDB\BSON\PackedArray; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToArray; use MongoDB\Model\BSONArray; /** @@ -16,7 +15,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/zip/ */ -class ZipAggregation implements ResolvesToArray +class ZipOperator implements ResolvesToArray { public const NAME = '$zip'; public const ENCODE = \MongoDB\Builder\Encode::Object; diff --git a/src/Builder/Pipeline.php b/src/Builder/Pipeline.php index b0c770ae1..9fefbdc21 100644 --- a/src/Builder/Pipeline.php +++ b/src/Builder/Pipeline.php @@ -9,7 +9,6 @@ use Traversable; use function array_is_list; -use function array_merge; /** @template-implements IteratorAggregate */ class Pipeline implements IteratorAggregate @@ -17,19 +16,25 @@ class Pipeline implements IteratorAggregate /** @var StageInterface[] */ private array $stages = []; - public function __construct(StageInterface ...$stages) + public function __construct(StageInterface|Pipeline ...$stages) { $this->add(...$stages); } /** @return $this */ - public function add(StageInterface ...$stages): static + public function add(StageInterface|Pipeline ...$stages): static { if (! array_is_list($stages)) { throw new InvalidArgumentException('Expected $stages argument to be a list, got an associative array.'); } - $this->stages = array_merge($this->stages, $stages); + foreach ($stages as $stage) { + if ($stage instanceof Pipeline) { + $this->add(...$stage->stages); + } else { + $this->stages[] = $stage; + } + } return $this; } diff --git a/src/Builder/Query.php b/src/Builder/Query.php index 6d969e9a6..992929806 100644 --- a/src/Builder/Query.php +++ b/src/Builder/Query.php @@ -1,597 +1,8 @@ value = $value; } } diff --git a/src/Builder/Query/ExistsQuery.php b/src/Builder/Query/ExistsOperator.php similarity index 92% rename from src/Builder/Query/ExistsQuery.php rename to src/Builder/Query/ExistsOperator.php index 21d353c4a..d75f5116e 100644 --- a/src/Builder/Query/ExistsQuery.php +++ b/src/Builder/Query/ExistsOperator.php @@ -14,7 +14,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/query/exists/ */ -class ExistsQuery implements QueryInterface +class ExistsOperator implements QueryInterface { public const NAME = '$exists'; public const ENCODE = \MongoDB\Builder\Encode::Single; diff --git a/src/Builder/Query/ExprQuery.php b/src/Builder/Query/ExprOperator.php similarity index 87% rename from src/Builder/Query/ExprQuery.php rename to src/Builder/Query/ExprOperator.php index ff80b4f4e..3e6a56d04 100644 --- a/src/Builder/Query/ExprQuery.php +++ b/src/Builder/Query/ExprOperator.php @@ -28,7 +28,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/query/expr/ */ -class ExprQuery implements QueryInterface +class ExprOperator implements QueryInterface { public const NAME = '$expr'; public const ENCODE = \MongoDB\Builder\Encode::Single; @@ -42,10 +42,6 @@ class ExprQuery implements QueryInterface public function __construct( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, ) { - if (\is_array($expression) && ! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression argument to be a list, got an associative array.'); - } - $this->expression = $expression; } } diff --git a/src/Builder/Query/FactoryTrait.php b/src/Builder/Query/FactoryTrait.php new file mode 100644 index 000000000..a74f5f1ed --- /dev/null +++ b/src/Builder/Query/FactoryTrait.php @@ -0,0 +1,546 @@ +value = $value; } } diff --git a/src/Builder/Query/GteQuery.php b/src/Builder/Query/GteOperator.php similarity index 87% rename from src/Builder/Query/GteQuery.php rename to src/Builder/Query/GteOperator.php index 4fccdf020..5e84656fd 100644 --- a/src/Builder/Query/GteQuery.php +++ b/src/Builder/Query/GteOperator.php @@ -27,7 +27,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/query/gte/ */ -class GteQuery implements QueryInterface +class GteOperator implements QueryInterface { public const NAME = '$gte'; public const ENCODE = \MongoDB\Builder\Encode::Single; @@ -41,10 +41,6 @@ class GteQuery implements QueryInterface public function __construct( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|BSONArray|stdClass|array|bool|float|int|null|string $value, ) { - if (\is_array($value) && ! \array_is_list($value)) { - throw new \InvalidArgumentException('Expected $value argument to be a list, got an associative array.'); - } - $this->value = $value; } } diff --git a/src/Builder/Query/InQuery.php b/src/Builder/Query/InOperator.php similarity index 95% rename from src/Builder/Query/InQuery.php rename to src/Builder/Query/InOperator.php index 8dec39d76..ce8c58ff5 100644 --- a/src/Builder/Query/InQuery.php +++ b/src/Builder/Query/InOperator.php @@ -16,7 +16,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/query/in/ */ -class InQuery implements QueryInterface +class InOperator implements QueryInterface { public const NAME = '$in'; public const ENCODE = \MongoDB\Builder\Encode::Single; diff --git a/src/Builder/Query/JsonSchemaQuery.php b/src/Builder/Query/JsonSchemaOperator.php similarity index 94% rename from src/Builder/Query/JsonSchemaQuery.php rename to src/Builder/Query/JsonSchemaOperator.php index 7fbe37a5a..9417878cb 100644 --- a/src/Builder/Query/JsonSchemaQuery.php +++ b/src/Builder/Query/JsonSchemaOperator.php @@ -17,7 +17,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/query/jsonSchema/ */ -class JsonSchemaQuery implements QueryInterface +class JsonSchemaOperator implements QueryInterface { public const NAME = '$jsonSchema'; public const ENCODE = \MongoDB\Builder\Encode::Single; diff --git a/src/Builder/Query/LtQuery.php b/src/Builder/Query/LtOperator.php similarity index 87% rename from src/Builder/Query/LtQuery.php rename to src/Builder/Query/LtOperator.php index a59839103..51401cc22 100644 --- a/src/Builder/Query/LtQuery.php +++ b/src/Builder/Query/LtOperator.php @@ -27,7 +27,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/query/lt/ */ -class LtQuery implements QueryInterface +class LtOperator implements QueryInterface { public const NAME = '$lt'; public const ENCODE = \MongoDB\Builder\Encode::Single; @@ -41,10 +41,6 @@ class LtQuery implements QueryInterface public function __construct( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|BSONArray|stdClass|array|bool|float|int|null|string $value, ) { - if (\is_array($value) && ! \array_is_list($value)) { - throw new \InvalidArgumentException('Expected $value argument to be a list, got an associative array.'); - } - $this->value = $value; } } diff --git a/src/Builder/Query/LteQuery.php b/src/Builder/Query/LteOperator.php similarity index 87% rename from src/Builder/Query/LteQuery.php rename to src/Builder/Query/LteOperator.php index df207566f..fff584b18 100644 --- a/src/Builder/Query/LteQuery.php +++ b/src/Builder/Query/LteOperator.php @@ -27,7 +27,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/query/lte/ */ -class LteQuery implements QueryInterface +class LteOperator implements QueryInterface { public const NAME = '$lte'; public const ENCODE = \MongoDB\Builder\Encode::Single; @@ -41,10 +41,6 @@ class LteQuery implements QueryInterface public function __construct( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|BSONArray|stdClass|array|bool|float|int|null|string $value, ) { - if (\is_array($value) && ! \array_is_list($value)) { - throw new \InvalidArgumentException('Expected $value argument to be a list, got an associative array.'); - } - $this->value = $value; } } diff --git a/src/Builder/Query/MaxDistanceOperator.php b/src/Builder/Query/MaxDistanceOperator.php new file mode 100644 index 000000000..30b95033a --- /dev/null +++ b/src/Builder/Query/MaxDistanceOperator.php @@ -0,0 +1,35 @@ +value = $value; + } +} diff --git a/src/Builder/Query/MaxDistanceQuery.php b/src/Builder/Query/MaxDistanceQuery.php deleted file mode 100644 index e6116a92e..000000000 --- a/src/Builder/Query/MaxDistanceQuery.php +++ /dev/null @@ -1,39 +0,0 @@ -value = $value; - } -} diff --git a/src/Builder/Query/MetaQuery.php b/src/Builder/Query/MetaOperator.php similarity index 90% rename from src/Builder/Query/MetaQuery.php rename to src/Builder/Query/MetaOperator.php index 79f9defae..1861ef091 100644 --- a/src/Builder/Query/MetaQuery.php +++ b/src/Builder/Query/MetaOperator.php @@ -14,7 +14,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/query/meta/ */ -class MetaQuery implements ProjectionInterface +class MetaOperator implements ProjectionInterface { public const NAME = '$meta'; public const ENCODE = \MongoDB\Builder\Encode::Object; diff --git a/src/Builder/Query/MinDistanceQuery.php b/src/Builder/Query/MinDistanceOperator.php similarity index 93% rename from src/Builder/Query/MinDistanceQuery.php rename to src/Builder/Query/MinDistanceOperator.php index 831ccdcfb..714c20ff3 100644 --- a/src/Builder/Query/MinDistanceQuery.php +++ b/src/Builder/Query/MinDistanceOperator.php @@ -15,7 +15,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/query/minDistance/ */ -class MinDistanceQuery implements QueryInterface +class MinDistanceOperator implements QueryInterface { public const NAME = '$minDistance'; public const ENCODE = \MongoDB\Builder\Encode::Single; diff --git a/src/Builder/Query/ModQuery.php b/src/Builder/Query/ModOperator.php similarity index 94% rename from src/Builder/Query/ModQuery.php rename to src/Builder/Query/ModOperator.php index c0b1deb8e..7d127f3d7 100644 --- a/src/Builder/Query/ModQuery.php +++ b/src/Builder/Query/ModOperator.php @@ -14,7 +14,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/query/mod/ */ -class ModQuery implements QueryInterface +class ModOperator implements QueryInterface { public const NAME = '$mod'; public const ENCODE = \MongoDB\Builder\Encode::Array; diff --git a/src/Builder/Query/NaturalQuery.php b/src/Builder/Query/NaturalOperator.php similarity index 91% rename from src/Builder/Query/NaturalQuery.php rename to src/Builder/Query/NaturalOperator.php index 2a2dc6e09..90144769b 100644 --- a/src/Builder/Query/NaturalQuery.php +++ b/src/Builder/Query/NaturalOperator.php @@ -14,7 +14,7 @@ * * @see https://www.mongodb.com/docs/v7.0/reference/operator/meta/natural/ */ -class NaturalQuery implements ExpressionInterface +class NaturalOperator implements ExpressionInterface { public const NAME = '$natural'; public const ENCODE = \MongoDB\Builder\Encode::Object; diff --git a/src/Builder/Query/NeQuery.php b/src/Builder/Query/NeOperator.php similarity index 87% rename from src/Builder/Query/NeQuery.php rename to src/Builder/Query/NeOperator.php index cf5d56649..f492e66fd 100644 --- a/src/Builder/Query/NeQuery.php +++ b/src/Builder/Query/NeOperator.php @@ -27,7 +27,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/query/ne/ */ -class NeQuery implements QueryInterface +class NeOperator implements QueryInterface { public const NAME = '$ne'; public const ENCODE = \MongoDB\Builder\Encode::Single; @@ -41,10 +41,6 @@ class NeQuery implements QueryInterface public function __construct( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|BSONArray|stdClass|array|bool|float|int|null|string $value, ) { - if (\is_array($value) && ! \array_is_list($value)) { - throw new \InvalidArgumentException('Expected $value argument to be a list, got an associative array.'); - } - $this->value = $value; } } diff --git a/src/Builder/Query/NearQuery.php b/src/Builder/Query/NearOperator.php similarity index 97% rename from src/Builder/Query/NearQuery.php rename to src/Builder/Query/NearOperator.php index 49d414706..d84a5adef 100644 --- a/src/Builder/Query/NearQuery.php +++ b/src/Builder/Query/NearOperator.php @@ -18,7 +18,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/query/near/ */ -class NearQuery implements QueryInterface +class NearOperator implements QueryInterface { public const NAME = '$near'; public const ENCODE = \MongoDB\Builder\Encode::Object; diff --git a/src/Builder/Query/NearSphereQuery.php b/src/Builder/Query/NearSphereOperator.php similarity index 97% rename from src/Builder/Query/NearSphereQuery.php rename to src/Builder/Query/NearSphereOperator.php index b97512df6..c9759ee8a 100644 --- a/src/Builder/Query/NearSphereQuery.php +++ b/src/Builder/Query/NearSphereOperator.php @@ -18,7 +18,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/query/nearSphere/ */ -class NearSphereQuery implements QueryInterface +class NearSphereOperator implements QueryInterface { public const NAME = '$nearSphere'; public const ENCODE = \MongoDB\Builder\Encode::Object; diff --git a/src/Builder/Query/NinQuery.php b/src/Builder/Query/NinOperator.php similarity index 95% rename from src/Builder/Query/NinQuery.php rename to src/Builder/Query/NinOperator.php index 173c7aee1..5b35cf8bc 100644 --- a/src/Builder/Query/NinQuery.php +++ b/src/Builder/Query/NinOperator.php @@ -16,7 +16,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/query/nin/ */ -class NinQuery implements QueryInterface +class NinOperator implements QueryInterface { public const NAME = '$nin'; public const ENCODE = \MongoDB\Builder\Encode::Single; diff --git a/src/Builder/Query/NorQuery.php b/src/Builder/Query/NorOperator.php similarity index 96% rename from src/Builder/Query/NorQuery.php rename to src/Builder/Query/NorOperator.php index b2bf37aee..a483b1715 100644 --- a/src/Builder/Query/NorQuery.php +++ b/src/Builder/Query/NorOperator.php @@ -17,7 +17,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/query/nor/ */ -class NorQuery implements QueryInterface +class NorOperator implements QueryInterface { public const NAME = '$nor'; public const ENCODE = \MongoDB\Builder\Encode::Single; diff --git a/src/Builder/Query/NotQuery.php b/src/Builder/Query/NotOperator.php similarity index 95% rename from src/Builder/Query/NotQuery.php rename to src/Builder/Query/NotOperator.php index 327ac73fd..50c8f96d2 100644 --- a/src/Builder/Query/NotQuery.php +++ b/src/Builder/Query/NotOperator.php @@ -17,7 +17,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/query/not/ */ -class NotQuery implements QueryInterface +class NotOperator implements QueryInterface { public const NAME = '$not'; public const ENCODE = \MongoDB\Builder\Encode::Single; diff --git a/src/Builder/Query/OrQuery.php b/src/Builder/Query/OrOperator.php similarity index 96% rename from src/Builder/Query/OrQuery.php rename to src/Builder/Query/OrOperator.php index 8416fae83..cb1c5c040 100644 --- a/src/Builder/Query/OrQuery.php +++ b/src/Builder/Query/OrOperator.php @@ -17,7 +17,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/query/or/ */ -class OrQuery implements QueryInterface +class OrOperator implements QueryInterface { public const NAME = '$or'; public const ENCODE = \MongoDB\Builder\Encode::Single; diff --git a/src/Builder/Query/PolygonQuery.php b/src/Builder/Query/PolygonOperator.php similarity index 95% rename from src/Builder/Query/PolygonQuery.php rename to src/Builder/Query/PolygonOperator.php index ebea98f89..00e673f3e 100644 --- a/src/Builder/Query/PolygonQuery.php +++ b/src/Builder/Query/PolygonOperator.php @@ -16,7 +16,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/query/polygon/ */ -class PolygonQuery implements QueryInterface +class PolygonOperator implements QueryInterface { public const NAME = '$polygon'; public const ENCODE = \MongoDB\Builder\Encode::Single; diff --git a/src/Builder/Query/RandQuery.php b/src/Builder/Query/RandOperator.php similarity index 90% rename from src/Builder/Query/RandQuery.php rename to src/Builder/Query/RandOperator.php index 216d6eb49..70ddf98c2 100644 --- a/src/Builder/Query/RandQuery.php +++ b/src/Builder/Query/RandOperator.php @@ -14,7 +14,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/query/rand/ */ -class RandQuery implements ExpressionInterface +class RandOperator implements ExpressionInterface { public const NAME = '$rand'; public const ENCODE = \MongoDB\Builder\Encode::Object; diff --git a/src/Builder/Query/RegexQuery.php b/src/Builder/Query/RegexOperator.php similarity index 93% rename from src/Builder/Query/RegexQuery.php rename to src/Builder/Query/RegexOperator.php index 63029c326..170d9716d 100644 --- a/src/Builder/Query/RegexQuery.php +++ b/src/Builder/Query/RegexOperator.php @@ -15,7 +15,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/query/regex/ */ -class RegexQuery implements QueryInterface +class RegexOperator implements QueryInterface { public const NAME = '$regex'; public const ENCODE = \MongoDB\Builder\Encode::Single; diff --git a/src/Builder/Query/SizeQuery.php b/src/Builder/Query/SizeOperator.php similarity index 93% rename from src/Builder/Query/SizeQuery.php rename to src/Builder/Query/SizeOperator.php index e9b9786a6..6a02dc6e2 100644 --- a/src/Builder/Query/SizeQuery.php +++ b/src/Builder/Query/SizeOperator.php @@ -14,7 +14,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/query/size/ */ -class SizeQuery implements QueryInterface +class SizeOperator implements QueryInterface { public const NAME = '$size'; public const ENCODE = \MongoDB\Builder\Encode::Single; diff --git a/src/Builder/Query/SliceQuery.php b/src/Builder/Query/SliceOperator.php similarity index 92% rename from src/Builder/Query/SliceQuery.php rename to src/Builder/Query/SliceOperator.php index 84b748c14..db58eecc8 100644 --- a/src/Builder/Query/SliceQuery.php +++ b/src/Builder/Query/SliceOperator.php @@ -15,7 +15,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/query/slice/ */ -class SliceQuery implements QueryInterface, ProjectionInterface +class SliceOperator implements QueryInterface, ProjectionInterface { public const NAME = '$slice'; public const ENCODE = \MongoDB\Builder\Encode::Array; diff --git a/src/Builder/Query/TextQuery.php b/src/Builder/Query/TextOperator.php similarity index 98% rename from src/Builder/Query/TextQuery.php rename to src/Builder/Query/TextOperator.php index ecc1ef990..c70040357 100644 --- a/src/Builder/Query/TextQuery.php +++ b/src/Builder/Query/TextOperator.php @@ -15,7 +15,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/query/text/ */ -class TextQuery implements QueryInterface +class TextOperator implements QueryInterface { public const NAME = '$text'; public const ENCODE = \MongoDB\Builder\Encode::Object; diff --git a/src/Builder/Query/TypeQuery.php b/src/Builder/Query/TypeOperator.php similarity index 95% rename from src/Builder/Query/TypeQuery.php rename to src/Builder/Query/TypeOperator.php index 2f3f247e4..969f6d943 100644 --- a/src/Builder/Query/TypeQuery.php +++ b/src/Builder/Query/TypeOperator.php @@ -16,7 +16,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/query/type/ */ -class TypeQuery implements QueryInterface +class TypeOperator implements QueryInterface { public const NAME = '$type'; public const ENCODE = \MongoDB\Builder\Encode::Single; diff --git a/src/Builder/Query/WhereQuery.php b/src/Builder/Query/WhereOperator.php similarity index 93% rename from src/Builder/Query/WhereQuery.php rename to src/Builder/Query/WhereOperator.php index 4e7f10f08..0cccfb143 100644 --- a/src/Builder/Query/WhereQuery.php +++ b/src/Builder/Query/WhereOperator.php @@ -14,7 +14,7 @@ * * @see https://www.mongodb.com/docs/manual/reference/operator/query/where/ */ -class WhereQuery implements QueryInterface +class WhereOperator implements QueryInterface { public const NAME = '$where'; public const ENCODE = \MongoDB\Builder\Encode::Single; diff --git a/src/Builder/Stage.php b/src/Builder/Stage.php index 927da9d82..fc553bcb6 100644 --- a/src/Builder/Stage.php +++ b/src/Builder/Stage.php @@ -1,737 +1,8 @@ in an embedded document or in an array, use dot notation. - * @param Document|Serializable|array|stdClass $range Specification for range based densification. - * @param BSONArray|Optional|PackedArray|array $partitionByFields The field(s) that will be used as the partition keys. - */ - public static function densify( - FieldPath|string $field, - Document|Serializable|stdClass|array $range, - PackedArray|Optional|BSONArray|array $partitionByFields = Optional::Undefined, - ): DensifyStage - { - return new DensifyStage($field, $range, $partitionByFields); - } - - /** - * Returns literal documents from input values. - * - * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/documents/ - * @param BSONArray|PackedArray|ResolvesToArray|array $documents $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. - */ - public static function documents(PackedArray|ResolvesToArray|BSONArray|array $documents): DocumentsStage - { - return new DocumentsStage($documents); - } - - /** - * 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. - * - * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/facet/ - * @param BSONArray|PackedArray|Pipeline|array ...$facet - */ - public static function facet(PackedArray|Pipeline|BSONArray|array ...$facet): FacetStage - { - return new FacetStage(...$facet); - } - - /** - * Populates null and missing field values within documents. - * - * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/fill/ - * @param Document|Serializable|array|stdClass $output 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. - * @param Document|Optional|Serializable|array|non-empty-string|stdClass $partitionBy 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. - * @param BSONArray|Optional|PackedArray|array $partitionByFields 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. - * @param Document|Optional|Serializable|array|stdClass $sortBy Specifies the field or fields to sort the documents within each partition. Uses the same syntax as the $sort stage. - */ - public static function fill( - Document|Serializable|stdClass|array $output, - Document|Serializable|Optional|stdClass|array|string $partitionBy = Optional::Undefined, - PackedArray|Optional|BSONArray|array $partitionByFields = Optional::Undefined, - Document|Serializable|Optional|stdClass|array $sortBy = Optional::Undefined, - ): FillStage - { - return new FillStage($output, $partitionBy, $partitionByFields, $sortBy); - } - - /** - * 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. - * - * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/geoNear/ - * @param non-empty-string $distanceField The output field that contains the calculated distance. To specify a field within an embedded document, use dot notation. - * @param Document|Serializable|array|stdClass $near The point for which to find the closest documents. - * @param Decimal128|Int64|Optional|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|float|int $distanceMultiplier 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. - * @param Optional|non-empty-string $includeLocs 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. - * @param Optional|non-empty-string $key Specify the geospatial indexed field to use when calculating the distance. - * @param Decimal128|Int64|Optional|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|float|int $maxDistance 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. - * @param Decimal128|Int64|Optional|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|float|int $minDistance 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. - * @param Document|Optional|QueryInterface|Serializable|array|stdClass $query imits 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. - * @param Optional|bool $spherical 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. - */ - public static function geoNear( - string $distanceField, - Document|Serializable|stdClass|array $near, - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|Optional|float|int $distanceMultiplier = Optional::Undefined, - Optional|string $includeLocs = Optional::Undefined, - Optional|string $key = Optional::Undefined, - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|Optional|float|int $maxDistance = Optional::Undefined, - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|Optional|float|int $minDistance = Optional::Undefined, - Document|Serializable|Optional|QueryInterface|stdClass|array $query = Optional::Undefined, - Optional|bool $spherical = Optional::Undefined, - ): GeoNearStage - { - return new GeoNearStage($distanceField, $near, $distanceMultiplier, $includeLocs, $key, $maxDistance, $minDistance, $query, $spherical); - } - - /** - * 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. - * - * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/graphLookup/ - * @param non-empty-string $from 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. - * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $startWith 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. - * @param non-empty-string $connectFromField 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. - * @param non-empty-string $connectToField Field name in other documents against which to match the value of the field specified by the connectFromField parameter. - * @param non-empty-string $as Name of the array field added to each output document. Contains the documents traversed in the $graphLookup stage to reach the document. - * @param Optional|int $maxDepth Non-negative integral number specifying the maximum recursion depth. - * @param Optional|non-empty-string $depthField 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. - * @param Document|Optional|QueryInterface|Serializable|array|stdClass $restrictSearchWithMatch A document specifying additional conditions for the recursive search. The syntax is identical to query filter syntax. - */ - public static function graphLookup( - string $from, - Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $startWith, - string $connectFromField, - string $connectToField, - string $as, - Optional|int $maxDepth = Optional::Undefined, - Optional|string $depthField = Optional::Undefined, - Document|Serializable|Optional|QueryInterface|stdClass|array $restrictSearchWithMatch = Optional::Undefined, - ): GraphLookupStage - { - return new GraphLookupStage($from, $startWith, $connectFromField, $connectToField, $as, $maxDepth, $depthField, $restrictSearchWithMatch); - } - - /** - * 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. - * - * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/group/ - * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $_id 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. - * @param AccumulatorInterface|Document|Serializable|array|stdClass ...$field Computed using the accumulator operators. - */ - public static function group( - Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $_id, - Document|Serializable|AccumulatorInterface|stdClass|array ...$field, - ): GroupStage - { - return new GroupStage($_id, ...$field); - } - - /** - * Returns statistics regarding the use of each index for the collection. - * - * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/indexStats/ - */ - public static function indexStats(): IndexStatsStage - { - return new IndexStatsStage(); - } - - /** - * 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). - * - * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/limit/ - * @param int $limit - */ - public static function limit(int $limit): LimitStage - { - return new LimitStage($limit); - } - - /** - * 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. - * - * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/listLocalSessions/ - * @param BSONArray|Optional|PackedArray|array $users 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. - * @param Optional|bool $allUsers Returns all sessions for all users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster. - */ - public static function listLocalSessions( - PackedArray|Optional|BSONArray|array $users = Optional::Undefined, - Optional|bool $allUsers = Optional::Undefined, - ): ListLocalSessionsStage - { - return new ListLocalSessionsStage($users, $allUsers); - } - - /** - * Lists sampled queries for all collections or a specific collection. - * - * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSampledQueries/ - * @param Optional|non-empty-string $namespace - */ - public static function listSampledQueries( - Optional|string $namespace = Optional::Undefined, - ): ListSampledQueriesStage - { - return new ListSampledQueriesStage($namespace); - } - - /** - * Returns information about existing Atlas Search indexes on a specified collection. - * - * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSearchIndexes/ - * @param Optional|non-empty-string $id The id of the index to return information about. - * @param Optional|non-empty-string $name The name of the index to return information about. - */ - public static function listSearchIndexes( - Optional|string $id = Optional::Undefined, - Optional|string $name = Optional::Undefined, - ): ListSearchIndexesStage - { - return new ListSearchIndexesStage($id, $name); - } - - /** - * Lists all sessions that have been active long enough to propagate to the system.sessions collection. - * - * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSessions/ - * @param BSONArray|Optional|PackedArray|array $users 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. - * @param Optional|bool $allUsers Returns all sessions for all users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster. - */ - public static function listSessions( - PackedArray|Optional|BSONArray|array $users = Optional::Undefined, - Optional|bool $allUsers = Optional::Undefined, - ): ListSessionsStage - { - return new ListSessionsStage($users, $allUsers); - } - - /** - * Performs a left outer join to another collection in the same database to filter in documents from the "joined" collection for processing. - * - * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/lookup/ - * @param non-empty-string $as 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. - * @param Optional|non-empty-string $from 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. - * @param Optional|non-empty-string $localField 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. - * @param Optional|non-empty-string $foreignField 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. - * @param Document|Optional|Serializable|array|stdClass $let 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. - * @param BSONArray|Optional|PackedArray|Pipeline|array $pipeline 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 $mergestage. 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. - */ - public static function lookup( - string $as, - Optional|string $from = Optional::Undefined, - Optional|string $localField = Optional::Undefined, - Optional|string $foreignField = Optional::Undefined, - Document|Serializable|Optional|stdClass|array $let = Optional::Undefined, - PackedArray|Optional|Pipeline|BSONArray|array $pipeline = Optional::Undefined, - ): LookupStage - { - return new LookupStage($as, $from, $localField, $foreignField, $let, $pipeline); - } - - /** - * 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). - * - * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/match/ - * @param Document|QueryInterface|Serializable|array|stdClass $query - */ - public static function match(Document|Serializable|QueryInterface|stdClass|array $query): MatchStage - { - return new MatchStage($query); - } - - /** - * 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 version 4.2. - * - * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/ - * @param Document|Serializable|array|non-empty-string|stdClass $into The output collection. - * @param BSONArray|Optional|PackedArray|array|non-empty-string $on 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. - * @param Document|Optional|Serializable|array|stdClass $let Specifies variables for use in the whenMatched pipeline. - * @param Optional|non-empty-string $whenMatched 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). - * @param Optional|non-empty-string $whenNotMatched The behavior of $merge if a result document does not match an existing document in the out collection. - */ - public static function merge( - Document|Serializable|stdClass|array|string $into, - PackedArray|Optional|BSONArray|array|string $on = Optional::Undefined, - Document|Serializable|Optional|stdClass|array $let = Optional::Undefined, - Optional|string $whenMatched = Optional::Undefined, - Optional|string $whenNotMatched = Optional::Undefined, - ): MergeStage - { - return new MergeStage($into, $on, $let, $whenMatched, $whenNotMatched); - } - - /** - * Writes the resulting documents of the aggregation pipeline to a collection. To use the $out stage, it must be the last stage in the pipeline. - * - * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/out/ - * @param non-empty-string $db Target collection name to write documents from $out to. - * @param non-empty-string $coll Target database name to write documents from $out to. - * @param Document|Optional|Serializable|array|stdClass $timeseries If set, the aggregation stage will use these options to create or replace a time-series collection in the given namespace. - */ - public static function out( - string $db, - string $coll, - Document|Serializable|Optional|stdClass|array $timeseries = Optional::Undefined, - ): OutStage - { - return new OutStage($db, $coll, $timeseries); - } - - /** - * Returns plan cache information for a collection. - * - * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/planCacheStats/ - */ - public static function planCacheStats(): PlanCacheStatsStage - { - return new PlanCacheStatsStage(); - } - - /** - * Reshapes each document in the stream, such as by adding new fields or removing existing fields. For each input document, outputs one document. - * - * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/project/ - * @param Document|ProjectionInterface|ResolvesToBool|Serializable|array|bool|int|stdClass ...$specification - */ - public static function project( - Document|Serializable|ResolvesToBool|ProjectionInterface|stdClass|array|bool|int ...$specification, - ): ProjectStage - { - return new ProjectStage(...$specification); - } - - /** - * 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. - * - * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/redact/ - * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression - */ - public static function redact( - Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, - ): RedactStage - { - return new RedactStage($expression); - } - - /** - * 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. - * - * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceRoot/ - * @param Document|ResolvesToObject|Serializable|array|stdClass $newRoot - */ - public static function replaceRoot( - Document|Serializable|ResolvesToObject|stdClass|array $newRoot, - ): ReplaceRootStage - { - return new ReplaceRootStage($newRoot); - } - - /** - * 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. - * - * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceWith/ - * @param Document|ResolvesToObject|Serializable|array|stdClass $expression - */ - public static function replaceWith( - Document|Serializable|ResolvesToObject|stdClass|array $expression, - ): ReplaceWithStage - { - return new ReplaceWithStage($expression); - } - - /** - * Randomly selects the specified number of documents from its input. - * - * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/sample/ - * @param int $size The number of documents to randomly select. - */ - public static function sample(int $size): SampleStage - { - return new SampleStage($size); - } - - /** - * 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. - * - * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/search/ - * @param Document|Serializable|array|stdClass $search - */ - public static function search(Document|Serializable|stdClass|array $search): SearchStage - { - return new SearchStage($search); - } - - /** - * 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. - * - * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/searchMeta/ - * @param Document|Serializable|array|stdClass $meta - */ - public static function searchMeta(Document|Serializable|stdClass|array $meta): SearchMetaStage - { - return new SearchMetaStage($meta); - } - - /** - * Adds new fields to documents. Outputs documents that contain all existing fields from the input documents and newly added fields. - * Alias for $addFields. - * - * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/set/ - * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass ...$field - */ - public static function set( - Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string ...$field, - ): SetStage - { - return new SetStage(...$field); - } - - /** - * Groups documents into windows and applies one or more operators to the documents in each window. - * New in version 5.0. - * - * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/setWindowFields/ - * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $partitionBy 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. - * @param Document|Serializable|array|stdClass $sortBy Specifies the field(s) to sort the documents by in the partition. Uses the same syntax as the $sort stage. Default is no sorting. - * @param Document|Serializable|array|stdClass $output 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. - * @param Document|Optional|Serializable|array|stdClass $window Specifies the window boundaries and parameters. Window boundaries are inclusive. Default is an unbounded window, which includes all documents in the partition. - */ - public static function setWindowFields( - Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $partitionBy, - Document|Serializable|stdClass|array $sortBy, - Document|Serializable|stdClass|array $output, - Document|Serializable|Optional|stdClass|array $window = Optional::Undefined, - ): SetWindowFieldsStage - { - return new SetWindowFieldsStage($partitionBy, $sortBy, $output, $window); - } - - /** - * Provides data and size distribution information on sharded collections. - * New in version 6.0.3. - * - * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/shardedDataDistribution/ - */ - public static function shardedDataDistribution(): ShardedDataDistributionStage - { - return new ShardedDataDistributionStage(); - } - - /** - * 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). - * - * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/skip/ - * @param int $skip - */ - public static function skip(int $skip): SkipStage - { - return new SkipStage($skip); - } - - /** - * Reorders the document stream by a specified sort key. Only the order changes; the documents remain unmodified. For each input document, outputs one document. - * - * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/sort/ - * @param Document|Serializable|array|stdClass $sort - */ - public static function sort(Document|Serializable|stdClass|array $sort): SortStage - { - return new SortStage($sort); - } - - /** - * Groups incoming documents based on the value of a specified expression, then computes the count of documents in each distinct group. - * - * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/sortByCount/ - * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression - */ - public static function sortByCount( - Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, - ): SortByCountStage - { - return new SortByCountStage($expression); - } - - /** - * Performs a union of two collections; i.e. combines pipeline results from two collections into a single result set. - * New in version 4.4. - * - * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/unionWith/ - * @param non-empty-string $coll The collection or view whose pipeline results you wish to include in the result set. - * @param BSONArray|Optional|PackedArray|Pipeline|array $pipeline 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. - */ - public static function unionWith( - string $coll, - PackedArray|Optional|Pipeline|BSONArray|array $pipeline = Optional::Undefined, - ): UnionWithStage - { - return new UnionWithStage($coll, $pipeline); - } - - /** - * Removes or excludes fields from documents. - * Alias for $project stage that removes or excludes fields. - * - * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/unset/ - * @param FieldPath|non-empty-string ...$field - */ - public static function unset(FieldPath|string ...$field): UnsetStage - { - return new UnsetStage(...$field); - } - - /** - * 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. - * - * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/unwind/ - * @param ArrayFieldPath|non-empty-string $field - */ - public static function unwind(ArrayFieldPath|string $field): UnwindStage - { - return new UnwindStage($field); - } - - /** - * This class cannot be instantiated. - */ - private function __construct() - { - } + use Stage\FactoryTrait; } diff --git a/src/Builder/Stage/BucketAutoStage.php b/src/Builder/Stage/BucketAutoStage.php index fd28bbcb7..a664ab10a 100644 --- a/src/Builder/Stage/BucketAutoStage.php +++ b/src/Builder/Stage/BucketAutoStage.php @@ -41,35 +41,31 @@ class BucketAutoStage implements StageInterface public int $buckets; /** - * @param Document|Optional|Serializable|array|stdClass $output 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. + * @param Optional|Document|Serializable|array|stdClass $output 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. */ - public Document|Serializable|Optional|stdClass|array $output; + public Optional|Document|Serializable|stdClass|array $output; /** - * @param Optional|non-empty-string $granularity 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. + * @param Optional|Document|Serializable|array|stdClass $granularity 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. */ - public Optional|string $granularity; + public Optional|Document|Serializable|stdClass|array $granularity; /** * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $groupBy An expression to group documents by. To specify a field path, prefix the field name with a dollar sign $ and enclose it in quotes. * @param int $buckets A positive 32-bit integer that specifies the number of buckets into which input documents are grouped. - * @param Document|Optional|Serializable|array|stdClass $output 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. + * @param Optional|Document|Serializable|array|stdClass $output 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. - * @param Optional|non-empty-string $granularity 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. + * @param Optional|Document|Serializable|array|stdClass $granularity 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. */ public function __construct( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $groupBy, int $buckets, - Document|Serializable|Optional|stdClass|array $output = Optional::Undefined, - Optional|string $granularity = Optional::Undefined, + Optional|Document|Serializable|stdClass|array $output = Optional::Undefined, + Optional|Document|Serializable|stdClass|array $granularity = Optional::Undefined, ) { - if (\is_array($groupBy) && ! \array_is_list($groupBy)) { - throw new \InvalidArgumentException('Expected $groupBy argument to be a list, got an associative array.'); - } - $this->groupBy = $groupBy; $this->buckets = $buckets; $this->output = $output; diff --git a/src/Builder/Stage/BucketStage.php b/src/Builder/Stage/BucketStage.php index 3edbb37f9..2d862a737 100644 --- a/src/Builder/Stage/BucketStage.php +++ b/src/Builder/Stage/BucketStage.php @@ -17,7 +17,6 @@ use MongoDB\BSON\Timestamp; use MongoDB\BSON\UTCDateTime; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\FieldPath; use MongoDB\Builder\Expression\ResolvesToInt; use MongoDB\Builder\Optional; use MongoDB\Builder\Type\ExpressionInterface; @@ -36,10 +35,10 @@ class BucketStage implements StageInterface public const ENCODE = \MongoDB\Builder\Encode::Object; /** - * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|FieldPath|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $groupBy An expression to group documents by. To specify a field path, prefix the field name with a dollar sign $ and enclose it in quotes. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $groupBy 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. */ - public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|FieldPath|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $groupBy; + public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $groupBy; /** * @param BSONArray|PackedArray|array $boundaries 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. @@ -48,53 +47,45 @@ class BucketStage implements StageInterface public PackedArray|BSONArray|array $boundaries; /** - * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|Optional|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $default 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. + * @param Optional|BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $default 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. */ - public Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|Optional|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $default; + public Optional|Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $default; /** - * @param Document|Optional|Serializable|array|stdClass $output 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. + * @param Optional|Document|Serializable|array|stdClass $output 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. */ - public Document|Serializable|Optional|stdClass|array $output; + public Optional|Document|Serializable|stdClass|array $output; /** - * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|FieldPath|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $groupBy An expression to group documents by. To specify a field path, prefix the field name with a dollar sign $ and enclose it in quotes. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $groupBy 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. * @param BSONArray|PackedArray|array $boundaries 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: - * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|Optional|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $default 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. + * @param Optional|BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $default 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. - * @param Document|Optional|Serializable|array|stdClass $output 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. + * @param Optional|Document|Serializable|array|stdClass $output 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. */ public function __construct( - Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|FieldPath|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $groupBy, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $groupBy, PackedArray|BSONArray|array $boundaries, - Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|Optional|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $default = Optional::Undefined, - Document|Serializable|Optional|stdClass|array $output = Optional::Undefined, + Optional|Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $default = Optional::Undefined, + Optional|Document|Serializable|stdClass|array $output = Optional::Undefined, ) { - if (\is_array($groupBy) && ! \array_is_list($groupBy)) { - throw new \InvalidArgumentException('Expected $groupBy argument to be a list, got an associative array.'); - } - $this->groupBy = $groupBy; if (\is_array($boundaries) && ! \array_is_list($boundaries)) { throw new \InvalidArgumentException('Expected $boundaries argument to be a list, got an associative array.'); } $this->boundaries = $boundaries; - if (\is_array($default) && ! \array_is_list($default)) { - throw new \InvalidArgumentException('Expected $default argument to be a list, got an associative array.'); - } - $this->default = $default; $this->output = $output; } diff --git a/src/Builder/Stage/ChangeStreamStage.php b/src/Builder/Stage/ChangeStreamStage.php index 41bc299d6..82349bc01 100644 --- a/src/Builder/Stage/ChangeStreamStage.php +++ b/src/Builder/Stage/ChangeStreamStage.php @@ -42,11 +42,11 @@ class ChangeStreamStage implements StageInterface */ public Optional|bool $showExpandedEvents; - /** @param Document|Optional|Serializable|array|stdClass $startAfter Specifies a resume token as the logical starting point for the change stream. Cannot be used with resumeAfter or startAtOperationTime fields. */ - public Document|Serializable|Optional|stdClass|array $startAfter; + /** @param Optional|Document|Serializable|array|stdClass $startAfter Specifies a resume token as the logical starting point for the change stream. Cannot be used with resumeAfter or startAtOperationTime fields. */ + public Optional|Document|Serializable|stdClass|array $startAfter; /** @param Optional|Timestamp|int $startAtOperationTime Specifies a time as the logical starting point for the change stream. Cannot be used with resumeAfter or startAfter fields. */ - public Timestamp|Optional|int $startAtOperationTime; + public Optional|Timestamp|int $startAtOperationTime; /** * @param Optional|bool $allChangesForCluster A flag indicating whether the stream should report all changes that occur on the deployment, aside from those on internal databases or collections. @@ -55,7 +55,7 @@ class ChangeStreamStage implements StageInterface * @param Optional|int $resumeAfter Specifies a resume token as the logical starting point for the change stream. Cannot be used with startAfter or startAtOperationTime fields. * @param Optional|bool $showExpandedEvents Specifies whether to include additional change events, such as such as DDL and index operations. * New in version 6.0. - * @param Document|Optional|Serializable|array|stdClass $startAfter Specifies a resume token as the logical starting point for the change stream. Cannot be used with resumeAfter or startAtOperationTime fields. + * @param Optional|Document|Serializable|array|stdClass $startAfter Specifies a resume token as the logical starting point for the change stream. Cannot be used with resumeAfter or startAtOperationTime fields. * @param Optional|Timestamp|int $startAtOperationTime Specifies a time as the logical starting point for the change stream. Cannot be used with resumeAfter or startAfter fields. */ public function __construct( @@ -64,8 +64,8 @@ public function __construct( Optional|string $fullDocumentBeforeChange = Optional::Undefined, Optional|int $resumeAfter = Optional::Undefined, Optional|bool $showExpandedEvents = Optional::Undefined, - Document|Serializable|Optional|stdClass|array $startAfter = Optional::Undefined, - Timestamp|Optional|int $startAtOperationTime = Optional::Undefined, + Optional|Document|Serializable|stdClass|array $startAfter = Optional::Undefined, + Optional|Timestamp|int $startAtOperationTime = Optional::Undefined, ) { $this->allChangesForCluster = $allChangesForCluster; $this->fullDocument = $fullDocument; diff --git a/src/Builder/Stage/DensifyStage.php b/src/Builder/Stage/DensifyStage.php index 817c2ed66..59c56f446 100644 --- a/src/Builder/Stage/DensifyStage.php +++ b/src/Builder/Stage/DensifyStage.php @@ -10,7 +10,6 @@ use MongoDB\BSON\PackedArray; use MongoDB\BSON\Serializable; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\FieldPath; use MongoDB\Builder\Optional; use MongoDB\Builder\Type\StageInterface; use MongoDB\Model\BSONArray; @@ -27,29 +26,29 @@ class DensifyStage implements StageInterface public const ENCODE = \MongoDB\Builder\Encode::Object; /** - * @param FieldPath|non-empty-string $field The field to densify. The values of the specified field must either be all numeric values or all dates. + * @param non-empty-string $field 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. */ - public FieldPath|string $field; + public string $field; /** @param Document|Serializable|array|stdClass $range Specification for range based densification. */ public Document|Serializable|stdClass|array $range; - /** @param BSONArray|Optional|PackedArray|array $partitionByFields The field(s) that will be used as the partition keys. */ - public PackedArray|Optional|BSONArray|array $partitionByFields; + /** @param Optional|BSONArray|PackedArray|array $partitionByFields The field(s) that will be used as the partition keys. */ + public Optional|PackedArray|BSONArray|array $partitionByFields; /** - * @param FieldPath|non-empty-string $field The field to densify. The values of the specified field must either be all numeric values or all dates. + * @param non-empty-string $field 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. * @param Document|Serializable|array|stdClass $range Specification for range based densification. - * @param BSONArray|Optional|PackedArray|array $partitionByFields The field(s) that will be used as the partition keys. + * @param Optional|BSONArray|PackedArray|array $partitionByFields The field(s) that will be used as the partition keys. */ public function __construct( - FieldPath|string $field, + string $field, Document|Serializable|stdClass|array $range, - PackedArray|Optional|BSONArray|array $partitionByFields = Optional::Undefined, + Optional|PackedArray|BSONArray|array $partitionByFields = Optional::Undefined, ) { $this->field = $field; $this->range = $range; diff --git a/src/Builder/Stage/FactoryTrait.php b/src/Builder/Stage/FactoryTrait.php new file mode 100644 index 000000000..f64fa003a --- /dev/null +++ b/src/Builder/Stage/FactoryTrait.php @@ -0,0 +1,698 @@ + in an embedded document or in an array, use dot notation. + * @param Document|Serializable|array|stdClass $range Specification for range based densification. + * @param Optional|BSONArray|PackedArray|array $partitionByFields The field(s) that will be used as the partition keys. + */ + public static function densify( + string $field, + Document|Serializable|stdClass|array $range, + Optional|PackedArray|BSONArray|array $partitionByFields = Optional::Undefined, + ): DensifyStage + { + return new DensifyStage($field, $range, $partitionByFields); + } + + /** + * Returns literal documents from input values. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/documents/ + * @param BSONArray|PackedArray|ResolvesToArray|array $documents $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. + */ + public static function documents(PackedArray|ResolvesToArray|BSONArray|array $documents): DocumentsStage + { + return new DocumentsStage($documents); + } + + /** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/facet/ + * @param BSONArray|PackedArray|Pipeline|array ...$facet + */ + public static function facet(PackedArray|Pipeline|BSONArray|array ...$facet): FacetStage + { + return new FacetStage(...$facet); + } + + /** + * Populates null and missing field values within documents. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/fill/ + * @param Document|Serializable|array|stdClass $output 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. + * @param Optional|Document|Serializable|array|non-empty-string|stdClass $partitionBy 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. + * @param Optional|BSONArray|PackedArray|array $partitionByFields 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. + * @param Optional|Document|Serializable|array|stdClass $sortBy Specifies the field or fields to sort the documents within each partition. Uses the same syntax as the $sort stage. + */ + public static function fill( + Document|Serializable|stdClass|array $output, + Optional|Document|Serializable|stdClass|array|string $partitionBy = Optional::Undefined, + Optional|PackedArray|BSONArray|array $partitionByFields = Optional::Undefined, + Optional|Document|Serializable|stdClass|array $sortBy = Optional::Undefined, + ): FillStage + { + return new FillStage($output, $partitionBy, $partitionByFields, $sortBy); + } + + /** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/geoNear/ + * @param non-empty-string $distanceField The output field that contains the calculated distance. To specify a field within an embedded document, use dot notation. + * @param Document|Serializable|array|stdClass $near The point for which to find the closest documents. + * @param Optional|Decimal128|Int64|ResolvesToInt|float|int $distanceMultiplier 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. + * @param Optional|non-empty-string $includeLocs 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. + * @param Optional|non-empty-string $key Specify the geospatial indexed field to use when calculating the distance. + * @param Optional|Decimal128|Int64|ResolvesToInt|float|int $maxDistance 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. + * @param Optional|Decimal128|Int64|ResolvesToInt|float|int $minDistance 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. + * @param Optional|Document|QueryInterface|Serializable|array|stdClass $query imits 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. + * @param Optional|bool $spherical 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. + */ + public static function geoNear( + string $distanceField, + Document|Serializable|stdClass|array $near, + Optional|Decimal128|Int64|ResolvesToInt|float|int $distanceMultiplier = Optional::Undefined, + Optional|string $includeLocs = Optional::Undefined, + Optional|string $key = Optional::Undefined, + Optional|Decimal128|Int64|ResolvesToInt|float|int $maxDistance = Optional::Undefined, + Optional|Decimal128|Int64|ResolvesToInt|float|int $minDistance = Optional::Undefined, + Optional|Document|Serializable|QueryInterface|stdClass|array $query = Optional::Undefined, + Optional|bool $spherical = Optional::Undefined, + ): GeoNearStage + { + return new GeoNearStage($distanceField, $near, $distanceMultiplier, $includeLocs, $key, $maxDistance, $minDistance, $query, $spherical); + } + + /** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/graphLookup/ + * @param non-empty-string $from 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. + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $startWith 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. + * @param non-empty-string $connectFromField 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. + * @param non-empty-string $connectToField Field name in other documents against which to match the value of the field specified by the connectFromField parameter. + * @param non-empty-string $as Name of the array field added to each output document. Contains the documents traversed in the $graphLookup stage to reach the document. + * @param Optional|int $maxDepth Non-negative integral number specifying the maximum recursion depth. + * @param Optional|non-empty-string $depthField 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. + * @param Optional|Document|QueryInterface|Serializable|array|stdClass $restrictSearchWithMatch A document specifying additional conditions for the recursive search. The syntax is identical to query filter syntax. + */ + public static function graphLookup( + string $from, + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $startWith, + string $connectFromField, + string $connectToField, + string $as, + Optional|int $maxDepth = Optional::Undefined, + Optional|string $depthField = Optional::Undefined, + Optional|Document|Serializable|QueryInterface|stdClass|array $restrictSearchWithMatch = Optional::Undefined, + ): GraphLookupStage + { + return new GraphLookupStage($from, $startWith, $connectFromField, $connectToField, $as, $maxDepth, $depthField, $restrictSearchWithMatch); + } + + /** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/group/ + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $_id 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. + * @param AccumulatorInterface|Document|Serializable|array|stdClass ...$field Computed using the accumulator operators. + */ + public static function group( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $_id, + Document|Serializable|AccumulatorInterface|stdClass|array ...$field, + ): GroupStage + { + return new GroupStage($_id, ...$field); + } + + /** + * Returns statistics regarding the use of each index for the collection. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/indexStats/ + */ + public static function indexStats(): IndexStatsStage + { + return new IndexStatsStage(); + } + + /** + * 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). + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/limit/ + * @param int $limit + */ + public static function limit(int $limit): LimitStage + { + return new LimitStage($limit); + } + + /** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/listLocalSessions/ + * @param Optional|BSONArray|PackedArray|array $users 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. + * @param Optional|bool $allUsers Returns all sessions for all users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster. + */ + public static function listLocalSessions( + Optional|PackedArray|BSONArray|array $users = Optional::Undefined, + Optional|bool $allUsers = Optional::Undefined, + ): ListLocalSessionsStage + { + return new ListLocalSessionsStage($users, $allUsers); + } + + /** + * Lists sampled queries for all collections or a specific collection. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSampledQueries/ + * @param Optional|non-empty-string $namespace + */ + public static function listSampledQueries( + Optional|string $namespace = Optional::Undefined, + ): ListSampledQueriesStage + { + return new ListSampledQueriesStage($namespace); + } + + /** + * Returns information about existing Atlas Search indexes on a specified collection. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSearchIndexes/ + * @param Optional|non-empty-string $id The id of the index to return information about. + * @param Optional|non-empty-string $name The name of the index to return information about. + */ + public static function listSearchIndexes( + Optional|string $id = Optional::Undefined, + Optional|string $name = Optional::Undefined, + ): ListSearchIndexesStage + { + return new ListSearchIndexesStage($id, $name); + } + + /** + * Lists all sessions that have been active long enough to propagate to the system.sessions collection. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSessions/ + * @param Optional|BSONArray|PackedArray|array $users 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. + * @param Optional|bool $allUsers Returns all sessions for all users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster. + */ + public static function listSessions( + Optional|PackedArray|BSONArray|array $users = Optional::Undefined, + Optional|bool $allUsers = Optional::Undefined, + ): ListSessionsStage + { + return new ListSessionsStage($users, $allUsers); + } + + /** + * Performs a left outer join to another collection in the same database to filter in documents from the "joined" collection for processing. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/lookup/ + * @param non-empty-string $as 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. + * @param Optional|non-empty-string $from 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. + * @param Optional|non-empty-string $localField 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. + * @param Optional|non-empty-string $foreignField 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. + * @param Optional|Document|Serializable|array|stdClass $let 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. + * @param Optional|BSONArray|PackedArray|Pipeline|array $pipeline 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 $mergestage. 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. + */ + public static function lookup( + string $as, + Optional|string $from = Optional::Undefined, + Optional|string $localField = Optional::Undefined, + Optional|string $foreignField = Optional::Undefined, + Optional|Document|Serializable|stdClass|array $let = Optional::Undefined, + Optional|PackedArray|Pipeline|BSONArray|array $pipeline = Optional::Undefined, + ): LookupStage + { + return new LookupStage($as, $from, $localField, $foreignField, $let, $pipeline); + } + + /** + * 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). + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/match/ + * @param Document|QueryInterface|Serializable|array|stdClass $query + */ + public static function match(Document|Serializable|QueryInterface|stdClass|array $query): MatchStage + { + return new MatchStage($query); + } + + /** + * 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 version 4.2. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/ + * @param non-empty-string $into The output collection. + * @param Optional|BSONArray|PackedArray|array|non-empty-string $on 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. + * @param Optional|Document|Serializable|array|stdClass $let Specifies variables for use in the whenMatched pipeline. + * @param Optional|non-empty-string $whenMatched 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). + * @param Optional|non-empty-string $whenNotMatched The behavior of $merge if a result document does not match an existing document in the out collection. + */ + public static function merge( + string $into, + Optional|PackedArray|BSONArray|array|string $on = Optional::Undefined, + Optional|Document|Serializable|stdClass|array $let = Optional::Undefined, + Optional|string $whenMatched = Optional::Undefined, + Optional|string $whenNotMatched = Optional::Undefined, + ): MergeStage + { + return new MergeStage($into, $on, $let, $whenMatched, $whenNotMatched); + } + + /** + * Writes the resulting documents of the aggregation pipeline to a collection. To use the $out stage, it must be the last stage in the pipeline. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/out/ + * @param non-empty-string $db Target collection name to write documents from $out to. + * @param non-empty-string $coll Target database name to write documents from $out to. + * @param Optional|Document|Serializable|array|stdClass $timeseries If set, the aggregation stage will use these options to create or replace a time-series collection in the given namespace. + */ + public static function out( + string $db, + string $coll, + Optional|Document|Serializable|stdClass|array $timeseries = Optional::Undefined, + ): OutStage + { + return new OutStage($db, $coll, $timeseries); + } + + /** + * Returns plan cache information for a collection. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/planCacheStats/ + */ + public static function planCacheStats(): PlanCacheStatsStage + { + return new PlanCacheStatsStage(); + } + + /** + * Reshapes each document in the stream, such as by adding new fields or removing existing fields. For each input document, outputs one document. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/project/ + * @param Document|ProjectionInterface|ResolvesToBool|Serializable|array|bool|int|stdClass ...$specification + */ + public static function project( + Document|Serializable|ResolvesToBool|ProjectionInterface|stdClass|array|bool|int ...$specification, + ): ProjectStage + { + return new ProjectStage(...$specification); + } + + /** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/redact/ + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression + */ + public static function redact( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, + ): RedactStage + { + return new RedactStage($expression); + } + + /** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceRoot/ + * @param Document|ResolvesToObject|Serializable|array|stdClass $newRoot + */ + public static function replaceRoot( + Document|Serializable|ResolvesToObject|stdClass|array $newRoot, + ): ReplaceRootStage + { + return new ReplaceRootStage($newRoot); + } + + /** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceWith/ + * @param Document|ResolvesToObject|Serializable|array|stdClass $expression + */ + public static function replaceWith( + Document|Serializable|ResolvesToObject|stdClass|array $expression, + ): ReplaceWithStage + { + return new ReplaceWithStage($expression); + } + + /** + * Randomly selects the specified number of documents from its input. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/sample/ + * @param int $size The number of documents to randomly select. + */ + public static function sample(int $size): SampleStage + { + return new SampleStage($size); + } + + /** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/search/ + * @param Document|Serializable|array|stdClass $search + */ + public static function search(Document|Serializable|stdClass|array $search): SearchStage + { + return new SearchStage($search); + } + + /** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/searchMeta/ + * @param Document|Serializable|array|stdClass $meta + */ + public static function searchMeta(Document|Serializable|stdClass|array $meta): SearchMetaStage + { + return new SearchMetaStage($meta); + } + + /** + * Adds new fields to documents. Outputs documents that contain all existing fields from the input documents and newly added fields. + * Alias for $addFields. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/set/ + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass ...$field + */ + public static function set( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string ...$field, + ): SetStage + { + return new SetStage(...$field); + } + + /** + * Groups documents into windows and applies one or more operators to the documents in each window. + * New in version 5.0. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/setWindowFields/ + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $partitionBy 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. + * @param Document|Serializable|array|stdClass $sortBy Specifies the field(s) to sort the documents by in the partition. Uses the same syntax as the $sort stage. Default is no sorting. + * @param Document|Serializable|array|stdClass $output 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. + * @param Optional|Document|Serializable|array|stdClass $window Specifies the window boundaries and parameters. Window boundaries are inclusive. Default is an unbounded window, which includes all documents in the partition. + */ + public static function setWindowFields( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $partitionBy, + Document|Serializable|stdClass|array $sortBy, + Document|Serializable|stdClass|array $output, + Optional|Document|Serializable|stdClass|array $window = Optional::Undefined, + ): SetWindowFieldsStage + { + return new SetWindowFieldsStage($partitionBy, $sortBy, $output, $window); + } + + /** + * Provides data and size distribution information on sharded collections. + * New in version 6.0.3. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/shardedDataDistribution/ + */ + public static function shardedDataDistribution(): ShardedDataDistributionStage + { + return new ShardedDataDistributionStage(); + } + + /** + * 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). + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/skip/ + * @param int $skip + */ + public static function skip(int $skip): SkipStage + { + return new SkipStage($skip); + } + + /** + * Reorders the document stream by a specified sort key. Only the order changes; the documents remain unmodified. For each input document, outputs one document. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/sort/ + * @param Document|Serializable|array|stdClass $sort + */ + public static function sort(Document|Serializable|stdClass|array $sort): SortStage + { + return new SortStage($sort); + } + + /** + * Groups incoming documents based on the value of a specified expression, then computes the count of documents in each distinct group. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/sortByCount/ + * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $expression + */ + public static function sortByCount( + Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, + ): SortByCountStage + { + return new SortByCountStage($expression); + } + + /** + * Performs a union of two collections; i.e. combines pipeline results from two collections into a single result set. + * New in version 4.4. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/unionWith/ + * @param non-empty-string $coll The collection or view whose pipeline results you wish to include in the result set. + * @param Optional|BSONArray|PackedArray|Pipeline|array $pipeline 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. + */ + public static function unionWith( + string $coll, + Optional|PackedArray|Pipeline|BSONArray|array $pipeline = Optional::Undefined, + ): UnionWithStage + { + return new UnionWithStage($coll, $pipeline); + } + + /** + * Removes or excludes fields from documents. + * Alias for $project stage that removes or excludes fields. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/unset/ + * @param FieldPath|non-empty-string ...$field + */ + public static function unset(FieldPath|string ...$field): UnsetStage + { + return new UnsetStage(...$field); + } + + /** + * 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. + * + * @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/unwind/ + * @param ArrayFieldPath|non-empty-string $path Field path to an array field. + * @param Optional|non-empty-string $includeArrayIndex The name of a new field to hold the array index of the element. The name cannot start with a dollar sign $. + * @param Optional|bool $preserveNullAndEmptyArrays 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. + */ + public static function unwind( + ArrayFieldPath|string $path, + Optional|string $includeArrayIndex = Optional::Undefined, + Optional|bool $preserveNullAndEmptyArrays = Optional::Undefined, + ): UnwindStage + { + return new UnwindStage($path, $includeArrayIndex, $preserveNullAndEmptyArrays); + } +} diff --git a/src/Builder/Stage/FillStage.php b/src/Builder/Stage/FillStage.php index 666417d89..9a826e13f 100644 --- a/src/Builder/Stage/FillStage.php +++ b/src/Builder/Stage/FillStage.php @@ -32,38 +32,38 @@ class FillStage implements StageInterface public Document|Serializable|stdClass|array $output; /** - * @param Document|Optional|Serializable|array|non-empty-string|stdClass $partitionBy Specifies an expression to group the documents. In the $fill stage, a group of documents is known as a partition. + * @param Optional|Document|Serializable|array|non-empty-string|stdClass $partitionBy 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. */ - public Document|Serializable|Optional|stdClass|array|string $partitionBy; + public Optional|Document|Serializable|stdClass|array|string $partitionBy; /** - * @param BSONArray|Optional|PackedArray|array $partitionByFields 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. + * @param Optional|BSONArray|PackedArray|array $partitionByFields 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. */ - public PackedArray|Optional|BSONArray|array $partitionByFields; + public Optional|PackedArray|BSONArray|array $partitionByFields; - /** @param Document|Optional|Serializable|array|stdClass $sortBy Specifies the field or fields to sort the documents within each partition. Uses the same syntax as the $sort stage. */ - public Document|Serializable|Optional|stdClass|array $sortBy; + /** @param Optional|Document|Serializable|array|stdClass $sortBy Specifies the field or fields to sort the documents within each partition. Uses the same syntax as the $sort stage. */ + public Optional|Document|Serializable|stdClass|array $sortBy; /** * @param Document|Serializable|array|stdClass $output 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. - * @param Document|Optional|Serializable|array|non-empty-string|stdClass $partitionBy Specifies an expression to group the documents. In the $fill stage, a group of documents is known as a partition. + * @param Optional|Document|Serializable|array|non-empty-string|stdClass $partitionBy 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. - * @param BSONArray|Optional|PackedArray|array $partitionByFields 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. + * @param Optional|BSONArray|PackedArray|array $partitionByFields 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. - * @param Document|Optional|Serializable|array|stdClass $sortBy Specifies the field or fields to sort the documents within each partition. Uses the same syntax as the $sort stage. + * @param Optional|Document|Serializable|array|stdClass $sortBy Specifies the field or fields to sort the documents within each partition. Uses the same syntax as the $sort stage. */ public function __construct( Document|Serializable|stdClass|array $output, - Document|Serializable|Optional|stdClass|array|string $partitionBy = Optional::Undefined, - PackedArray|Optional|BSONArray|array $partitionByFields = Optional::Undefined, - Document|Serializable|Optional|stdClass|array $sortBy = Optional::Undefined, + Optional|Document|Serializable|stdClass|array|string $partitionBy = Optional::Undefined, + Optional|PackedArray|BSONArray|array $partitionByFields = Optional::Undefined, + Optional|Document|Serializable|stdClass|array $sortBy = Optional::Undefined, ) { $this->output = $output; $this->partitionBy = $partitionBy; diff --git a/src/Builder/Stage/GeoNearStage.php b/src/Builder/Stage/GeoNearStage.php index 9ea3cee6a..cfe44ffc7 100644 --- a/src/Builder/Stage/GeoNearStage.php +++ b/src/Builder/Stage/GeoNearStage.php @@ -11,10 +11,7 @@ use MongoDB\BSON\Int64; use MongoDB\BSON\Serializable; use MongoDB\Builder\Encode; -use MongoDB\Builder\Expression\ResolvesToDecimal; -use MongoDB\Builder\Expression\ResolvesToDouble; use MongoDB\Builder\Expression\ResolvesToInt; -use MongoDB\Builder\Expression\ResolvesToLong; use MongoDB\Builder\Optional; use MongoDB\Builder\Type\QueryInterface; use MongoDB\Builder\Type\StageInterface; @@ -36,8 +33,8 @@ class GeoNearStage implements StageInterface /** @param Document|Serializable|array|stdClass $near The point for which to find the closest documents. */ public Document|Serializable|stdClass|array $near; - /** @param Decimal128|Int64|Optional|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|float|int $distanceMultiplier 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. */ - public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|Optional|float|int $distanceMultiplier; + /** @param Optional|Decimal128|Int64|ResolvesToInt|float|int $distanceMultiplier 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. */ + public Optional|Decimal128|Int64|ResolvesToInt|float|int $distanceMultiplier; /** @param Optional|non-empty-string $includeLocs 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. */ public Optional|string $includeLocs; @@ -46,22 +43,22 @@ class GeoNearStage implements StageInterface public Optional|string $key; /** - * @param Decimal128|Int64|Optional|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|float|int $maxDistance 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. + * @param Optional|Decimal128|Int64|ResolvesToInt|float|int $maxDistance 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. */ - public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|Optional|float|int $maxDistance; + public Optional|Decimal128|Int64|ResolvesToInt|float|int $maxDistance; /** - * @param Decimal128|Int64|Optional|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|float|int $minDistance 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. + * @param Optional|Decimal128|Int64|ResolvesToInt|float|int $minDistance 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. */ - public Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|Optional|float|int $minDistance; + public Optional|Decimal128|Int64|ResolvesToInt|float|int $minDistance; /** - * @param Document|Optional|QueryInterface|Serializable|array|stdClass $query imits the results to the documents that match the query. The query syntax is the usual MongoDB read operation query syntax. + * @param Optional|Document|QueryInterface|Serializable|array|stdClass $query imits 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. */ - public Document|Serializable|Optional|QueryInterface|stdClass|array $query; + public Optional|Document|Serializable|QueryInterface|stdClass|array $query; /** * @param Optional|bool $spherical Determines how MongoDB calculates the distance between two points: @@ -74,14 +71,14 @@ class GeoNearStage implements StageInterface /** * @param non-empty-string $distanceField The output field that contains the calculated distance. To specify a field within an embedded document, use dot notation. * @param Document|Serializable|array|stdClass $near The point for which to find the closest documents. - * @param Decimal128|Int64|Optional|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|float|int $distanceMultiplier 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. + * @param Optional|Decimal128|Int64|ResolvesToInt|float|int $distanceMultiplier 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. * @param Optional|non-empty-string $includeLocs 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. * @param Optional|non-empty-string $key Specify the geospatial indexed field to use when calculating the distance. - * @param Decimal128|Int64|Optional|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|float|int $maxDistance 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. + * @param Optional|Decimal128|Int64|ResolvesToInt|float|int $maxDistance 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. - * @param Decimal128|Int64|Optional|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|float|int $minDistance 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. + * @param Optional|Decimal128|Int64|ResolvesToInt|float|int $minDistance 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. - * @param Document|Optional|QueryInterface|Serializable|array|stdClass $query imits the results to the documents that match the query. The query syntax is the usual MongoDB read operation query syntax. + * @param Optional|Document|QueryInterface|Serializable|array|stdClass $query imits 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. * @param Optional|bool $spherical Determines how MongoDB calculates the distance between two points: * - When true, MongoDB uses $nearSphere semantics and calculates distances using spherical geometry. @@ -91,12 +88,12 @@ class GeoNearStage implements StageInterface public function __construct( string $distanceField, Document|Serializable|stdClass|array $near, - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|Optional|float|int $distanceMultiplier = Optional::Undefined, + Optional|Decimal128|Int64|ResolvesToInt|float|int $distanceMultiplier = Optional::Undefined, Optional|string $includeLocs = Optional::Undefined, Optional|string $key = Optional::Undefined, - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|Optional|float|int $maxDistance = Optional::Undefined, - Decimal128|Int64|ResolvesToDecimal|ResolvesToDouble|ResolvesToInt|ResolvesToLong|Optional|float|int $minDistance = Optional::Undefined, - Document|Serializable|Optional|QueryInterface|stdClass|array $query = Optional::Undefined, + Optional|Decimal128|Int64|ResolvesToInt|float|int $maxDistance = Optional::Undefined, + Optional|Decimal128|Int64|ResolvesToInt|float|int $minDistance = Optional::Undefined, + Optional|Document|Serializable|QueryInterface|stdClass|array $query = Optional::Undefined, Optional|bool $spherical = Optional::Undefined, ) { $this->distanceField = $distanceField; diff --git a/src/Builder/Stage/GraphLookupStage.php b/src/Builder/Stage/GraphLookupStage.php index effa015d7..adc137a03 100644 --- a/src/Builder/Stage/GraphLookupStage.php +++ b/src/Builder/Stage/GraphLookupStage.php @@ -59,8 +59,8 @@ class GraphLookupStage implements StageInterface /** @param Optional|non-empty-string $depthField 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. */ public Optional|string $depthField; - /** @param Document|Optional|QueryInterface|Serializable|array|stdClass $restrictSearchWithMatch A document specifying additional conditions for the recursive search. The syntax is identical to query filter syntax. */ - public Document|Serializable|Optional|QueryInterface|stdClass|array $restrictSearchWithMatch; + /** @param Optional|Document|QueryInterface|Serializable|array|stdClass $restrictSearchWithMatch A document specifying additional conditions for the recursive search. The syntax is identical to query filter syntax. */ + public Optional|Document|Serializable|QueryInterface|stdClass|array $restrictSearchWithMatch; /** * @param non-empty-string $from 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. @@ -71,7 +71,7 @@ class GraphLookupStage implements StageInterface * @param non-empty-string $as Name of the array field added to each output document. Contains the documents traversed in the $graphLookup stage to reach the document. * @param Optional|int $maxDepth Non-negative integral number specifying the maximum recursion depth. * @param Optional|non-empty-string $depthField 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. - * @param Document|Optional|QueryInterface|Serializable|array|stdClass $restrictSearchWithMatch A document specifying additional conditions for the recursive search. The syntax is identical to query filter syntax. + * @param Optional|Document|QueryInterface|Serializable|array|stdClass $restrictSearchWithMatch A document specifying additional conditions for the recursive search. The syntax is identical to query filter syntax. */ public function __construct( string $from, @@ -81,13 +81,9 @@ public function __construct( string $as, Optional|int $maxDepth = Optional::Undefined, Optional|string $depthField = Optional::Undefined, - Document|Serializable|Optional|QueryInterface|stdClass|array $restrictSearchWithMatch = Optional::Undefined, + Optional|Document|Serializable|QueryInterface|stdClass|array $restrictSearchWithMatch = Optional::Undefined, ) { $this->from = $from; - if (\is_array($startWith) && ! \array_is_list($startWith)) { - throw new \InvalidArgumentException('Expected $startWith argument to be a list, got an associative array.'); - } - $this->startWith = $startWith; $this->connectFromField = $connectFromField; $this->connectToField = $connectToField; diff --git a/src/Builder/Stage/GroupStage.php b/src/Builder/Stage/GroupStage.php index f67f84478..fb9f95839 100644 --- a/src/Builder/Stage/GroupStage.php +++ b/src/Builder/Stage/GroupStage.php @@ -48,10 +48,6 @@ public function __construct( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $_id, Document|Serializable|AccumulatorInterface|stdClass|array ...$field, ) { - if (\is_array($_id) && ! \array_is_list($_id)) { - throw new \InvalidArgumentException('Expected $_id argument to be a list, got an associative array.'); - } - $this->_id = $_id; if (\count($field) < 1) { throw new \InvalidArgumentException(\sprintf('Expected at least %d values for $field, got %d.', 1, \count($field))); diff --git a/src/Builder/Stage/ListLocalSessionsStage.php b/src/Builder/Stage/ListLocalSessionsStage.php index fcd4cf9cb..5abfb8ec7 100644 --- a/src/Builder/Stage/ListLocalSessionsStage.php +++ b/src/Builder/Stage/ListLocalSessionsStage.php @@ -22,18 +22,18 @@ class ListLocalSessionsStage implements StageInterface public const NAME = '$listLocalSessions'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param BSONArray|Optional|PackedArray|array $users 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. */ - public PackedArray|Optional|BSONArray|array $users; + /** @param Optional|BSONArray|PackedArray|array $users 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. */ + public Optional|PackedArray|BSONArray|array $users; /** @param Optional|bool $allUsers Returns all sessions for all users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster. */ public Optional|bool $allUsers; /** - * @param BSONArray|Optional|PackedArray|array $users 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. + * @param Optional|BSONArray|PackedArray|array $users 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. * @param Optional|bool $allUsers Returns all sessions for all users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster. */ public function __construct( - PackedArray|Optional|BSONArray|array $users = Optional::Undefined, + Optional|PackedArray|BSONArray|array $users = Optional::Undefined, Optional|bool $allUsers = Optional::Undefined, ) { if (\is_array($users) && ! \array_is_list($users)) { diff --git a/src/Builder/Stage/ListSessionsStage.php b/src/Builder/Stage/ListSessionsStage.php index 7496c629c..14534d5dc 100644 --- a/src/Builder/Stage/ListSessionsStage.php +++ b/src/Builder/Stage/ListSessionsStage.php @@ -22,18 +22,18 @@ class ListSessionsStage implements StageInterface public const NAME = '$listSessions'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param BSONArray|Optional|PackedArray|array $users 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. */ - public PackedArray|Optional|BSONArray|array $users; + /** @param Optional|BSONArray|PackedArray|array $users 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. */ + public Optional|PackedArray|BSONArray|array $users; /** @param Optional|bool $allUsers Returns all sessions for all users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster. */ public Optional|bool $allUsers; /** - * @param BSONArray|Optional|PackedArray|array $users 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. + * @param Optional|BSONArray|PackedArray|array $users 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. * @param Optional|bool $allUsers Returns all sessions for all users. If running with access control, the authenticated user must have privileges with listSessions action on the cluster. */ public function __construct( - PackedArray|Optional|BSONArray|array $users = Optional::Undefined, + Optional|PackedArray|BSONArray|array $users = Optional::Undefined, Optional|bool $allUsers = Optional::Undefined, ) { if (\is_array($users) && ! \array_is_list($users)) { diff --git a/src/Builder/Stage/LookupStage.php b/src/Builder/Stage/LookupStage.php index daf81eaec..96c832d02 100644 --- a/src/Builder/Stage/LookupStage.php +++ b/src/Builder/Stage/LookupStage.php @@ -42,15 +42,15 @@ class LookupStage implements StageInterface /** @param Optional|non-empty-string $foreignField 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. */ public Optional|string $foreignField; - /** @param Document|Optional|Serializable|array|stdClass $let 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. */ - public Document|Serializable|Optional|stdClass|array $let; + /** @param Optional|Document|Serializable|array|stdClass $let 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. */ + public Optional|Document|Serializable|stdClass|array $let; /** - * @param BSONArray|Optional|PackedArray|Pipeline|array $pipeline 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 []. + * @param Optional|BSONArray|PackedArray|Pipeline|array $pipeline 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 $mergestage. 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. */ - public PackedArray|Optional|Pipeline|BSONArray|array $pipeline; + public Optional|PackedArray|Pipeline|BSONArray|array $pipeline; /** * @param non-empty-string $as 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. @@ -59,8 +59,8 @@ class LookupStage implements StageInterface * Starting in MongoDB 5.1, the collection specified in the from parameter can be sharded. * @param Optional|non-empty-string $localField 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. * @param Optional|non-empty-string $foreignField 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. - * @param Document|Optional|Serializable|array|stdClass $let 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. - * @param BSONArray|Optional|PackedArray|Pipeline|array $pipeline 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 []. + * @param Optional|Document|Serializable|array|stdClass $let 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. + * @param Optional|BSONArray|PackedArray|Pipeline|array $pipeline 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 $mergestage. 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. */ @@ -69,8 +69,8 @@ public function __construct( Optional|string $from = Optional::Undefined, Optional|string $localField = Optional::Undefined, Optional|string $foreignField = Optional::Undefined, - Document|Serializable|Optional|stdClass|array $let = Optional::Undefined, - PackedArray|Optional|Pipeline|BSONArray|array $pipeline = Optional::Undefined, + Optional|Document|Serializable|stdClass|array $let = Optional::Undefined, + Optional|PackedArray|Pipeline|BSONArray|array $pipeline = Optional::Undefined, ) { $this->as = $as; $this->from = $from; diff --git a/src/Builder/Stage/MergeStage.php b/src/Builder/Stage/MergeStage.php index bc9d17ab4..ef938304b 100644 --- a/src/Builder/Stage/MergeStage.php +++ b/src/Builder/Stage/MergeStage.php @@ -26,14 +26,14 @@ class MergeStage implements StageInterface public const NAME = '$merge'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param Document|Serializable|array|non-empty-string|stdClass $into The output collection. */ - public Document|Serializable|stdClass|array|string $into; + /** @param non-empty-string $into The output collection. */ + public string $into; - /** @param BSONArray|Optional|PackedArray|array|non-empty-string $on 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. */ - public PackedArray|Optional|BSONArray|array|string $on; + /** @param Optional|BSONArray|PackedArray|array|non-empty-string $on 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. */ + public Optional|PackedArray|BSONArray|array|string $on; - /** @param Document|Optional|Serializable|array|stdClass $let Specifies variables for use in the whenMatched pipeline. */ - public Document|Serializable|Optional|stdClass|array $let; + /** @param Optional|Document|Serializable|array|stdClass $let Specifies variables for use in the whenMatched pipeline. */ + public Optional|Document|Serializable|stdClass|array $let; /** @param Optional|non-empty-string $whenMatched 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). */ public Optional|string $whenMatched; @@ -42,16 +42,16 @@ class MergeStage implements StageInterface public Optional|string $whenNotMatched; /** - * @param Document|Serializable|array|non-empty-string|stdClass $into The output collection. - * @param BSONArray|Optional|PackedArray|array|non-empty-string $on 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. - * @param Document|Optional|Serializable|array|stdClass $let Specifies variables for use in the whenMatched pipeline. + * @param non-empty-string $into The output collection. + * @param Optional|BSONArray|PackedArray|array|non-empty-string $on 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. + * @param Optional|Document|Serializable|array|stdClass $let Specifies variables for use in the whenMatched pipeline. * @param Optional|non-empty-string $whenMatched 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). * @param Optional|non-empty-string $whenNotMatched The behavior of $merge if a result document does not match an existing document in the out collection. */ public function __construct( - Document|Serializable|stdClass|array|string $into, - PackedArray|Optional|BSONArray|array|string $on = Optional::Undefined, - Document|Serializable|Optional|stdClass|array $let = Optional::Undefined, + string $into, + Optional|PackedArray|BSONArray|array|string $on = Optional::Undefined, + Optional|Document|Serializable|stdClass|array $let = Optional::Undefined, Optional|string $whenMatched = Optional::Undefined, Optional|string $whenNotMatched = Optional::Undefined, ) { diff --git a/src/Builder/Stage/OutStage.php b/src/Builder/Stage/OutStage.php index fc05b03b7..541e34f5b 100644 --- a/src/Builder/Stage/OutStage.php +++ b/src/Builder/Stage/OutStage.php @@ -29,18 +29,18 @@ class OutStage implements StageInterface /** @param non-empty-string $coll Target database name to write documents from $out to. */ public string $coll; - /** @param Document|Optional|Serializable|array|stdClass $timeseries If set, the aggregation stage will use these options to create or replace a time-series collection in the given namespace. */ - public Document|Serializable|Optional|stdClass|array $timeseries; + /** @param Optional|Document|Serializable|array|stdClass $timeseries If set, the aggregation stage will use these options to create or replace a time-series collection in the given namespace. */ + public Optional|Document|Serializable|stdClass|array $timeseries; /** * @param non-empty-string $db Target collection name to write documents from $out to. * @param non-empty-string $coll Target database name to write documents from $out to. - * @param Document|Optional|Serializable|array|stdClass $timeseries If set, the aggregation stage will use these options to create or replace a time-series collection in the given namespace. + * @param Optional|Document|Serializable|array|stdClass $timeseries If set, the aggregation stage will use these options to create or replace a time-series collection in the given namespace. */ public function __construct( string $db, string $coll, - Document|Serializable|Optional|stdClass|array $timeseries = Optional::Undefined, + Optional|Document|Serializable|stdClass|array $timeseries = Optional::Undefined, ) { $this->db = $db; $this->coll = $coll; diff --git a/src/Builder/Stage/RedactStage.php b/src/Builder/Stage/RedactStage.php index fc9cc68e1..5135cb445 100644 --- a/src/Builder/Stage/RedactStage.php +++ b/src/Builder/Stage/RedactStage.php @@ -42,10 +42,6 @@ class RedactStage implements StageInterface public function __construct( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, ) { - if (\is_array($expression) && ! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression argument to be a list, got an associative array.'); - } - $this->expression = $expression; } } diff --git a/src/Builder/Stage/SetWindowFieldsStage.php b/src/Builder/Stage/SetWindowFieldsStage.php index 886e4a771..288f3f795 100644 --- a/src/Builder/Stage/SetWindowFieldsStage.php +++ b/src/Builder/Stage/SetWindowFieldsStage.php @@ -47,26 +47,22 @@ class SetWindowFieldsStage implements StageInterface */ public Document|Serializable|stdClass|array $output; - /** @param Document|Optional|Serializable|array|stdClass $window Specifies the window boundaries and parameters. Window boundaries are inclusive. Default is an unbounded window, which includes all documents in the partition. */ - public Document|Serializable|Optional|stdClass|array $window; + /** @param Optional|Document|Serializable|array|stdClass $window Specifies the window boundaries and parameters. Window boundaries are inclusive. Default is an unbounded window, which includes all documents in the partition. */ + public Optional|Document|Serializable|stdClass|array $window; /** * @param BSONArray|Binary|Decimal128|Document|ExpressionInterface|Int64|ObjectId|PackedArray|Regex|ResolvesToInt|Serializable|Timestamp|UTCDateTime|array|bool|float|int|non-empty-string|null|stdClass $partitionBy 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. * @param Document|Serializable|array|stdClass $sortBy Specifies the field(s) to sort the documents by in the partition. Uses the same syntax as the $sort stage. Default is no sorting. * @param Document|Serializable|array|stdClass $output 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. - * @param Document|Optional|Serializable|array|stdClass $window Specifies the window boundaries and parameters. Window boundaries are inclusive. Default is an unbounded window, which includes all documents in the partition. + * @param Optional|Document|Serializable|array|stdClass $window Specifies the window boundaries and parameters. Window boundaries are inclusive. Default is an unbounded window, which includes all documents in the partition. */ public function __construct( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $partitionBy, Document|Serializable|stdClass|array $sortBy, Document|Serializable|stdClass|array $output, - Document|Serializable|Optional|stdClass|array $window = Optional::Undefined, + Optional|Document|Serializable|stdClass|array $window = Optional::Undefined, ) { - if (\is_array($partitionBy) && ! \array_is_list($partitionBy)) { - throw new \InvalidArgumentException('Expected $partitionBy argument to be a list, got an associative array.'); - } - $this->partitionBy = $partitionBy; $this->sortBy = $sortBy; $this->output = $output; diff --git a/src/Builder/Stage/SortByCountStage.php b/src/Builder/Stage/SortByCountStage.php index 32d093510..97a0d1056 100644 --- a/src/Builder/Stage/SortByCountStage.php +++ b/src/Builder/Stage/SortByCountStage.php @@ -42,10 +42,6 @@ class SortByCountStage implements StageInterface public function __construct( Binary|Decimal128|Document|Int64|ObjectId|PackedArray|Regex|Serializable|Timestamp|UTCDateTime|ResolvesToInt|ExpressionInterface|BSONArray|stdClass|array|bool|float|int|null|string $expression, ) { - if (\is_array($expression) && ! \array_is_list($expression)) { - throw new \InvalidArgumentException('Expected $expression argument to be a list, got an associative array.'); - } - $this->expression = $expression; } } diff --git a/src/Builder/Stage/UnionWithStage.php b/src/Builder/Stage/UnionWithStage.php index b427f6736..88c136c1e 100644 --- a/src/Builder/Stage/UnionWithStage.php +++ b/src/Builder/Stage/UnionWithStage.php @@ -28,19 +28,19 @@ class UnionWithStage implements StageInterface public string $coll; /** - * @param BSONArray|Optional|PackedArray|Pipeline|array $pipeline An aggregation pipeline to apply to the specified coll. + * @param Optional|BSONArray|PackedArray|Pipeline|array $pipeline 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. */ - public PackedArray|Optional|Pipeline|BSONArray|array $pipeline; + public Optional|PackedArray|Pipeline|BSONArray|array $pipeline; /** * @param non-empty-string $coll The collection or view whose pipeline results you wish to include in the result set. - * @param BSONArray|Optional|PackedArray|Pipeline|array $pipeline An aggregation pipeline to apply to the specified coll. + * @param Optional|BSONArray|PackedArray|Pipeline|array $pipeline 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. */ public function __construct( string $coll, - PackedArray|Optional|Pipeline|BSONArray|array $pipeline = Optional::Undefined, + Optional|PackedArray|Pipeline|BSONArray|array $pipeline = Optional::Undefined, ) { $this->coll = $coll; if (\is_array($pipeline) && ! \array_is_list($pipeline)) { diff --git a/src/Builder/Stage/UnwindStage.php b/src/Builder/Stage/UnwindStage.php index efe5a830f..af205df9e 100644 --- a/src/Builder/Stage/UnwindStage.php +++ b/src/Builder/Stage/UnwindStage.php @@ -8,6 +8,7 @@ use MongoDB\Builder\Encode; use MongoDB\Builder\Expression\ArrayFieldPath; +use MongoDB\Builder\Optional; use MongoDB\Builder\Type\StageInterface; /** @@ -20,14 +21,33 @@ class UnwindStage implements StageInterface public const NAME = '$unwind'; public const ENCODE = \MongoDB\Builder\Encode::Object; - /** @param ArrayFieldPath|non-empty-string $field */ - public ArrayFieldPath|string $field; + /** @param ArrayFieldPath|non-empty-string $path Field path to an array field. */ + public ArrayFieldPath|string $path; + + /** @param Optional|non-empty-string $includeArrayIndex The name of a new field to hold the array index of the element. The name cannot start with a dollar sign $. */ + public Optional|string $includeArrayIndex; + + /** + * @param Optional|bool $preserveNullAndEmptyArrays 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. + */ + public Optional|bool $preserveNullAndEmptyArrays; /** - * @param ArrayFieldPath|non-empty-string $field + * @param ArrayFieldPath|non-empty-string $path Field path to an array field. + * @param Optional|non-empty-string $includeArrayIndex The name of a new field to hold the array index of the element. The name cannot start with a dollar sign $. + * @param Optional|bool $preserveNullAndEmptyArrays 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. */ - public function __construct(ArrayFieldPath|string $field) - { - $this->field = $field; + public function __construct( + ArrayFieldPath|string $path, + Optional|string $includeArrayIndex = Optional::Undefined, + Optional|bool $preserveNullAndEmptyArrays = Optional::Undefined, + ) { + $this->path = $path; + $this->includeArrayIndex = $includeArrayIndex; + $this->preserveNullAndEmptyArrays = $preserveNullAndEmptyArrays; } } diff --git a/src/Builder/Type/WindowInterface.php b/src/Builder/Type/WindowInterface.php new file mode 100644 index 000000000..f2a36aabb --- /dev/null +++ b/src/Builder/Type/WindowInterface.php @@ -0,0 +1,16 @@ +getStage() +); +``` +We explicitly don't allow to inject a pipeline in the list of stages as pipelines are not immutable: if `$pipeline1` +is modified, `$pipeline2` get the modifications. Using the array unpacking operator, make it clear the stages are +extracted. + +## Stage + +A stage is a root operator of an aggregation pipeline. They are not expressions and can't be used in other stages +without being wrapped in a pipeline. + +## Expression + +Expression namespace contains all the aggregation pipeline operators, the field paths, literal and variable. + +For each BSON type, we have a `resolvesTo` interface that is implemented by the corresponding expression operators, +and a `FieldName` class that is used to build field paths assuming the field is of the given type. + +### Object + +Object expression doesn't accept any PHP `object`, but only `stdClass` and BSON serializable objects. `array` are accepted +because that's the most common way to represent maps in PHP. But we recommend to use `object(... $fields)` helper to +create `stdClass`. It ensures the type is correct for empty arrays or list that would be converted to array instead of +object. + +### Type hierarchy + +The most specific interface implements the less specific one. For example, `resolvesToInt` implements `resolvesToLong`, +which implements `resolvesToNumber`, which implements `expression`. + +The type hierarchy is designed with two aspects in mind: the operator parameters and the operator results. + +#### Number + +If an operator resolves to a `number`, we don't know if it is an `int`, a `float`, a `decimal` or a `long`. +But if it resolves to an `int`, we know it is a `long`, a `number` and an `expression`. + +If an operator accepts a `number`, it also accepts an `int`, a `float`, a `decimal` or a `long`. +So we use the `resolvesToNumber` type. As `resolvesToInt` implements `resolvesToNumber`, it is also accepted. + +### Any + +The `resolvesToAny` type means that we don't know the type of the expression. This interface implements all the other +`ResovesTo` interfaces because we can't restrict the expression from being used as parameter for parameters +that requires more specific types. +`resolvesToAny` is only used as result type (as interface for operators class). For parameters, we use the generic +`expression` interface, otherwise only operator resulting in `any` would be eligible, the operators with more specific +result types would be rejected. + +We rely on the server will reject the query if the expression is not of the expected type. + + + + + +The type system is different for parameters and results. We use interfaces to describe + +- As parameter, `expression` accepts any scalar, array, `stdClass`, or BSON type but not `object` or `mixed` that are too generic. +- As result, `expression` is eligible to any operator that requires one of `resolvesToDouble`, `resolvesToFloat`, `resolvesToDecimal`, `resolvesToLong` + +- As parameter, resolvesToNumber accepts any expression that resolves to a number (resolvesToInt, resolvesToFloat, resolvesToDecimal, resolvesToLong) +- As result, resolvesToNumber is eligible to any operator that requires one of resolvesToDouble, resolvesToFloat, resolvesToDecimal, resolvesToLong + + + + + +# Query + +Issues with using a map of `fieldName: { $operator: value }`: + +MongoDB allows for short syntax that mixes query operators (`$and`, `$nor`, `or`) with field names to query operators. +To normalize the output and mixin things, + + +`Query` are not expression. They are used in a `$match` stage associated with a field name. + +```php +$pipeline = [ + matchStage( + Query::or(), + name: 'John' + nor(eq('name', 'John'), gte('age', 18)) + ) +]; +``` + +`$not` cannot be implemented. + + + + + +# Projection + + + + + + +# Specificities + +Some operators have specificities that are not covered by the generic builder. + +## `$group` stage: required and variadic parameters in the same object + +To encode, the required `_id` parameter is renderred at the same level of the list for fields. + +**Implementation:** The `GroupStage` has a special `Encode::Group` value exploited by the encoder. + +## `$slice` expression operator and `$slice` projection operator: optional values in an array + +These operators are encoded as an array of values. The meaning of the values depends on the number of values. + +https://www.mongodb.com/docs/v7.0/reference/operator/projection/slice/ +https://www.mongodb.com/docs/v7.0/reference/operator/aggregation/slice/ + +## Date Expression Operators + +Concerned operators are: `$dayOfMonth`, `$dayOfWeek`, `$dayOfYear`, `$hour`, `$isoDayOfWeek`, `$isoWeek`, `$isoWeekYear`, +`$millisecond`, `$minute`, `$month`, `$second`, `$week`, `$year`. + +These date expression operators accept have a "date expression" as parameter or an object with +a `date` and an optional `timezone` properties. + +``` +{ : } +{ : { date: , timezone: } } +``` + + +In order to normalize encoding, we always use an object with `date` and `timezone` properties and never the short form +even if the timezone is not specified. + +Date Expression can be `ResolveToDate`, `ResolveToTimestamp` or `ResolveToObjectId`. But we don't introduce a new +meta type like `number` or `any` as we can list this types directly in the config. + +## `$setWindowFields` stage's output + +The output parameter of the `$setWindowFields` stage is an object which mixes a "window operator" and the optional `window` +parameter at the same level. + +Window operators implement the `WindowInterface` interface and are encoded like other operators. + +``` +output: { + : { + : , + window: { + documents: [ , ], + range: [ , ], + unit: