diff --git a/.gitattributes b/.gitattributes
index 7f54ebe53..7309afd20 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -22,6 +22,6 @@ rector.php export-ignore
/src/Builder/Accumulator/*.php linguist-generated=true
/src/Builder/Expression/*.php linguist-generated=true
/src/Builder/Query/*.php linguist-generated=true
-/src/Builder/Projection/*.php linguist-generated=true
+/src/Builder/Search/*.php linguist-generated=true
/src/Builder/Stage/*.php linguist-generated=true
/tests/Builder/*/Pipelines.php linguist-generated=true
diff --git a/generator/README.md b/generator/README.md
index 5b6449543..02a3be4ec 100644
--- a/generator/README.md
+++ b/generator/README.md
@@ -10,17 +10,31 @@ Updating the generated code can be done only by modifying the code generator, or
To run the generator, you need to have PHP 8.1+ installed and Composer.
1. Move to the `generator` directory: `cd generator`
-1. Install dependencies: `composer install`
-1. Run the generator: `./generate`
+2. Install dependencies: `composer install`
+3. Run the generator: `./generate`
## Configuration
The `generator/config/*.yaml` files contains the list of operators and stages that are supported by the library.
+### Arguments
+
+| Field | Type | Description |
+|---------------|---------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
+| `name` | `string` | The name of the argument. If it starts with `$`, the dollar is trimmed from the class property name |
+| `type` | list of `string` | The list of accepted types |
+| `description` | `string` | The description of the argument from MongoDB's documentation |
+| `optional` | `boolean` | Whether the argument is optional or not |
+| `valueMin` | `number` | The minimum value for a numeric argument |
+| `valueMax` | `number` | The maximum value for a numeric argument |
+| `variadic` | `string` | If sent, the argument is variadic. Defines the format `array` for a list or `object` for a map |
+| `variadicMin` | `integer` | The minimum number of arguments for a variadic parameter |
+| `default` | `scalar` or `array` | The default value for the argument |
+| `mergeObject` | `bool` | Default `false`. If `true`, the value must be an object and the properties of the value object are merged into the parent operator. `$group` stage uses it for the fields |
+
### Test pipelines
-Each operator can contain a `tests` section with a list if pipelines. To represent specific BSON objects,
-it is necessary to use Yaml tags:
+Each operator can contain a `tests` section with a list if pipelines. To represent specific BSON objects, it is necessary to use Yaml tags:
| BSON Type | Example |
|-------------|--------------------------------------------------------|
@@ -28,7 +42,8 @@ it is necessary to use Yaml tags:
| Int64 | `!bson_int64 '123456789'` |
| Decimal128 | `!bson_decimal128 '0.9'` |
| UTCDateTime | `!bson_utcdatetime 0` |
+| ObjectId | `!bson_ObjectId '5a9427648b0beebeb69589a1` |
| Binary | `!bson_binary 'IA=='` |
+| Binary UUID | `!bson_uuid 'fac32260-b511-4c69-8485-a2be5b7dda9e'` |
-To add new test cases to operators, you can get inspiration from the official MongoDB documentation and use
-the `generator/js2yaml.html` web page to manually convert a pipeline array from JS to Yaml.
+To add new test cases to operators, you can get inspiration from the official MongoDB documentation and use the `generator/js2yaml.html` web page to manually convert a pipeline array from JS to Yaml.
diff --git a/generator/composer.json b/generator/composer.json
index 2deb4ae95..c4dedcfb7 100644
--- a/generator/composer.json
+++ b/generator/composer.json
@@ -4,7 +4,7 @@
"repositories": [
{
"type": "path",
- "url": "../",
+ "url": "..",
"symlink": true
}
],
diff --git a/generator/config/definitions.php b/generator/config/definitions.php
index a4f952d39..06d9b44ed 100644
--- a/generator/config/definitions.php
+++ b/generator/config/definitions.php
@@ -58,4 +58,16 @@
OperatorTestGenerator::class,
],
],
+
+ // Search Operators
+ [
+ 'configFiles' => __DIR__ . '/search',
+ 'namespace' => 'MongoDB\\Builder\\Search',
+ 'classNameSuffix' => 'Operator',
+ 'generators' => [
+ OperatorClassGenerator::class,
+ OperatorFactoryGenerator::class,
+ OperatorTestGenerator::class,
+ ],
+ ],
];
diff --git a/generator/config/expression/case.yaml b/generator/config/expression/case.yaml
index b86aef878..ccf463c90 100644
--- a/generator/config/expression/case.yaml
+++ b/generator/config/expression/case.yaml
@@ -3,7 +3,8 @@ name: $case
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/switch/'
type:
- switchBranch
-encode: flat_object
+encode: object
+wrapObject: false
description: |
Represents a single case in a $switch expression
arguments:
diff --git a/generator/config/expressions.php b/generator/config/expressions.php
index f731234b2..a2c649e8e 100644
--- a/generator/config/expressions.php
+++ b/generator/config/expressions.php
@@ -109,6 +109,10 @@
'implements' => [ResolvesToAny::class],
'acceptedTypes' => ['string'],
],
+ 'searchOperator' => [
+ 'returnType' => Type\SearchOperatorInterface::class,
+ 'acceptedTypes' => [Type\SearchOperatorInterface::class, ...$bsonTypes['object']],
+ ],
'geometry' => [
'returnType' => Type\GeometryInterface::class,
'acceptedTypes' => [Type\GeometryInterface::class, ...$bsonTypes['object']],
@@ -168,4 +172,12 @@
'GeoPoint' => [
'acceptedTypes' => [...$bsonTypes['object']],
],
+
+ // Search
+ 'searchPath' => [
+ 'acceptedTypes' => ['string', 'array'],
+ ],
+ 'searchScore' => [
+ 'acceptedTypes' => [...$bsonTypes['object']],
+ ],
];
diff --git a/generator/config/query/geoIntersects.yaml b/generator/config/query/geoIntersects.yaml
index ca1eda02f..4df3a43de 100644
--- a/generator/config/query/geoIntersects.yaml
+++ b/generator/config/query/geoIntersects.yaml
@@ -3,12 +3,13 @@ name: $geoIntersects
link: 'https://www.mongodb.com/docs/manual/reference/operator/query/geoIntersects/'
type:
- fieldQuery
-encode: single
+encode: object
description: |
Selects geometries that intersect with a GeoJSON geometry. The 2dsphere index supports $geoIntersects.
arguments:
-
name: geometry
+ mergeObject: true
type:
- geometry
tests:
diff --git a/generator/config/query/geoWithin.yaml b/generator/config/query/geoWithin.yaml
index 3a87e4b72..f9f6204d0 100644
--- a/generator/config/query/geoWithin.yaml
+++ b/generator/config/query/geoWithin.yaml
@@ -3,12 +3,13 @@ name: $geoWithin
link: 'https://www.mongodb.com/docs/manual/reference/operator/query/geoWithin/'
type:
- fieldQuery
-encode: single
+encode: object
description: |
Selects geometries within a bounding GeoJSON geometry. The 2dsphere and 2d indexes support $geoWithin.
arguments:
-
name: geometry
+ mergeObject: true
type:
- geometry
tests:
diff --git a/generator/config/query/near.yaml b/generator/config/query/near.yaml
index f2c791630..89d7f511f 100644
--- a/generator/config/query/near.yaml
+++ b/generator/config/query/near.yaml
@@ -3,23 +3,24 @@ name: $near
link: 'https://www.mongodb.com/docs/manual/reference/operator/query/near/'
type:
- fieldQuery
-encode: dollar_object
+encode: object
description: |
Returns geospatial objects in proximity to a point. Requires a geospatial index. The 2dsphere and 2d indexes support $near.
arguments:
-
name: geometry
+ mergeObject: true
type:
- geometry
-
- name: maxDistance
+ name: $maxDistance
type:
- number
optional: true
description: |
Distance in meters. Limits the results to those documents that are at most the specified distance from the center point.
-
- name: minDistance
+ name: $minDistance
type:
- number
optional: true
diff --git a/generator/config/query/nearSphere.yaml b/generator/config/query/nearSphere.yaml
index 3411127ad..72e8e18e9 100644
--- a/generator/config/query/nearSphere.yaml
+++ b/generator/config/query/nearSphere.yaml
@@ -3,23 +3,24 @@ name: $nearSphere
link: 'https://www.mongodb.com/docs/manual/reference/operator/query/nearSphere/'
type:
- fieldQuery
-encode: dollar_object
+encode: object
description: |
Returns geospatial objects in proximity to a point on a sphere. Requires a geospatial index. The 2dsphere and 2d indexes support $nearSphere.
arguments:
-
name: geometry
+ mergeObject: true
type:
- geometry
-
- name: maxDistance
+ name: $maxDistance
type:
- number
optional: true
description: |
Distance in meters.
-
- name: minDistance
+ name: $minDistance
type:
- number
optional: true
diff --git a/generator/config/query/text.yaml b/generator/config/query/text.yaml
index 5ec26aaec..574ee4508 100644
--- a/generator/config/query/text.yaml
+++ b/generator/config/query/text.yaml
@@ -3,18 +3,18 @@ name: $text
link: 'https://www.mongodb.com/docs/manual/reference/operator/query/text/'
type:
- query
-encode: dollar_object
+encode: object
description: |
Performs text search.
arguments:
-
- name: search
+ 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
+ name: $language
type:
- string
optional: true
@@ -22,14 +22,14 @@ arguments:
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
+ 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
+ name: $diacriticSensitive
type:
- bool
optional: true
diff --git a/generator/config/schema.json b/generator/config/schema.json
index a68564e8e..c92e6ddb7 100644
--- a/generator/config/schema.json
+++ b/generator/config/schema.json
@@ -46,7 +46,8 @@
"resolvesToInt",
"resolvesToTimestamp",
"resolvesToLong",
- "resolvesToDecimal"
+ "resolvesToDecimal",
+ "searchOperator"
]
}
},
@@ -60,16 +61,19 @@
"enum": [
"array",
"object",
- "flat_object",
- "dollar_object",
"single",
- "group"
+ "search"
]
},
"description": {
"$comment": "The description of the argument from MongoDB's documentation.",
"type": "string"
},
+ "wrapObject": {
+ "$comment": "Wrap the properties in an object with the operator name",
+ "type": "boolean",
+ "default": true
+ },
"arguments": {
"$comment": "An optional list of arguments for the operator.",
"type": "array",
@@ -100,7 +104,7 @@
"properties": {
"name": {
"type": "string",
- "pattern": "^(_?[a-z][a-zA-Z0-9]*|N)$"
+ "pattern": "^([_$]?[a-z][a-zA-Z0-9]*|N)$"
},
"type": {
"type": "array",
@@ -133,7 +137,8 @@
"resolvesToInt", "intFieldPath", "int",
"resolvesToTimestamp", "timestampFieldPath", "timestamp",
"resolvesToLong", "longFieldPath", "long",
- "resolvesToDecimal", "decimalFieldPath", "decimal"
+ "resolvesToDecimal", "decimalFieldPath", "decimal",
+ "searchPath", "searchScore", "searchOperator"
]
}
},
@@ -150,7 +155,7 @@
"type": "number"
},
"valueMax": {
- "$comment": "The minimum value for a numeric argument.",
+ "$comment": "The maximum value for a numeric argument.",
"type": "number"
},
"variadic": {
@@ -169,6 +174,11 @@
"default": {
"$comment": "The default value for the argument.",
"type": ["array", "boolean", "number", "string"]
+ },
+ "mergeObject": {
+ "$comment": "Skip the name in object encoding and merge the properties of the value into the operator",
+ "type": "boolean",
+ "default": false
}
},
"required": [
diff --git a/generator/config/search/autocomplete.yaml b/generator/config/search/autocomplete.yaml
new file mode 100644
index 000000000..a984b9a39
--- /dev/null
+++ b/generator/config/search/autocomplete.yaml
@@ -0,0 +1,152 @@
+# $schema: ../schema.json
+name: autocomplete
+link: 'https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/'
+type:
+ - searchOperator
+encode: object
+description: |
+ The autocomplete operator performs a search for a word or phrase that
+ contains a sequence of characters from an incomplete input string. The
+ fields that you intend to query with the autocomplete operator must be
+ indexed with the autocomplete data type in the collection's index definition.
+arguments:
+ -
+ name: path
+ type:
+ - searchPath
+ -
+ name: query
+ type:
+ - string
+ -
+ name: tokenOrder
+ optional: true
+ type:
+ - string # any|sequential
+ -
+ name: fuzzy
+ optional: true
+ type:
+ - object
+ -
+ name: score
+ optional: true
+ type:
+ - searchScore
+tests:
+ -
+ name: 'Basic'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/#basic-example'
+ pipeline:
+ -
+ $search:
+ autocomplete:
+ query: 'off'
+ path: 'title'
+ -
+ $limit: 10
+ -
+ $project:
+ _id: 0
+ title: 1
+
+ -
+ name: 'Fuzzy'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/#fuzzy-example'
+ pipeline:
+ -
+ $search:
+ autocomplete:
+ query: 'pre'
+ path: 'title'
+ fuzzy:
+ maxEdits: 1
+ prefixLength: 1
+ maxExpansions: 256
+ -
+ $limit: 10
+ -
+ $project:
+ _id: 0
+ title: 1
+
+ -
+ name: 'Token Order any'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/#simple-any-example'
+ pipeline:
+ -
+ $search:
+ autocomplete:
+ query: 'men with'
+ path: 'title'
+ tokenOrder: 'any'
+ -
+ $limit: 4
+ -
+ $project:
+ _id: 0
+ title: 1
+
+ -
+ name: 'Token Order sequential'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/#simple-sequential-example'
+ pipeline:
+ -
+ $search:
+ autocomplete:
+ query: 'men with'
+ path: 'title'
+ tokenOrder: 'sequential'
+ -
+ $limit: 4
+ -
+ $project:
+ _id: 0
+ title: 1
+
+ -
+ name: 'Highlighting'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/#highlighting-example'
+ pipeline:
+ -
+ $search:
+ autocomplete:
+ query: 'ger'
+ path: 'title'
+ highlight:
+ path: 'title'
+ -
+ $limit: 5
+ -
+ $project:
+ score:
+ $meta: 'searchScore'
+ _id: 0
+ title: 1
+ highlights:
+ $meta: 'searchHighlights'
+
+ -
+ name: 'Across Multiple Fields'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/#search-across-multiple-fields'
+ pipeline:
+ -
+ $search:
+ compound:
+ should:
+ -
+ autocomplete:
+ query: 'inter'
+ path: 'title'
+ -
+ autocomplete:
+ query: 'inter'
+ path: 'plot'
+ minimumShouldMatch: 1
+ -
+ $limit: 10
+ -
+ $project:
+ _id: 0
+ title: 1
+ plot: 1
diff --git a/generator/config/search/compound.yaml b/generator/config/search/compound.yaml
new file mode 100644
index 000000000..7a1d9f419
--- /dev/null
+++ b/generator/config/search/compound.yaml
@@ -0,0 +1,156 @@
+# $schema: ../schema.json
+name: compound
+link: 'https://www.mongodb.com/docs/atlas/atlas-search/compound/'
+type:
+ - searchOperator
+encode: object
+description: |
+ The compound operator combines two or more operators into a single query.
+ Each element of a compound query is called a clause, and each clause
+ consists of one or more sub-queries.
+arguments:
+ -
+ name: must
+ optional: true
+ type:
+ - searchOperator
+ - array # of searchOperator
+ -
+ name: mustNot
+ optional: true
+ type:
+ - searchOperator
+ - array # of searchOperator
+ -
+ name: should
+ optional: true
+ type:
+ - searchOperator
+ - array # of searchOperator
+ -
+ name: filter
+ optional: true
+ type:
+ - searchOperator
+ - array # of searchOperator
+ -
+ name: minimumShouldMatch
+ optional: true
+ type:
+ - int
+ -
+ name: score
+ optional: true
+ type:
+ - searchScore
+tests:
+ -
+ name: 'must and mustNot'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/compound/#must-and-mustnot-example'
+ pipeline:
+ -
+ $search:
+ compound:
+ must:
+ -
+ text:
+ query: 'varieties'
+ path: 'description'
+ mustNot:
+ -
+ text:
+ query: 'apples'
+ path: 'description'
+
+ -
+ name: 'must and should'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/compound/#must-and-should-example'
+ pipeline:
+ -
+ $search:
+ compound:
+ must:
+ -
+ text:
+ query: 'varieties'
+ path: 'description'
+ should:
+ -
+ text:
+ query: 'Fuji'
+ path: 'description'
+ -
+ $project:
+ score:
+ $meta: 'searchScore'
+
+ -
+ name: 'minimumShouldMatch'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/compound/#minimumshouldmatch-example'
+ pipeline:
+ -
+ $search:
+ compound:
+ must:
+ -
+ text:
+ query: 'varieties'
+ path: 'description'
+ should:
+ -
+ text:
+ query: 'Fuji'
+ path: 'description'
+ -
+ text:
+ query: 'Golden Delicious'
+ path: 'description'
+ minimumShouldMatch: 1
+
+ -
+ name: 'Filter'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/compound/#filter-examples'
+ pipeline:
+ -
+ $search:
+ compound:
+ must:
+ -
+ text:
+ query: 'varieties'
+ path: 'description'
+ should:
+ -
+ text:
+ query: 'banana'
+ path: 'description'
+ filter:
+ -
+ text:
+ query: 'granny'
+ path: 'description'
+
+ -
+ name: 'Nested'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/compound/#nested-example'
+ pipeline:
+ -
+ $search:
+ compound:
+ should:
+ -
+ text:
+ query: 'apple'
+ path: 'type'
+ -
+ compound:
+ must:
+ -
+ text:
+ query: 'organic'
+ path: 'category'
+ -
+ equals:
+ value: true
+ path: 'in_stock'
+ minimumShouldMatch: 1
diff --git a/generator/config/search/embeddedDocument.yaml b/generator/config/search/embeddedDocument.yaml
new file mode 100644
index 000000000..19c804625
--- /dev/null
+++ b/generator/config/search/embeddedDocument.yaml
@@ -0,0 +1,155 @@
+# $schema: ../schema.json
+name: embeddedDocument
+link: 'https://www.mongodb.com/docs/atlas/atlas-search/embedded-document/'
+type:
+ - searchOperator
+encode: object
+description: |
+ The embeddedDocument operator is similar to $elemMatch operator.
+ It constrains multiple query predicates to be satisfied from a single
+ element of an array of embedded documents. embeddedDocument can be used only
+ for queries over fields of the embeddedDocuments
+arguments:
+ -
+ name: path
+ type:
+ - searchPath
+ -
+ name: operator
+ type:
+ - searchOperator
+ -
+ name: score
+ optional: true
+ type:
+ - searchScore
+tests:
+ -
+ name: 'Basic'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/embedded-document/#index-definition'
+ pipeline:
+ -
+ $search:
+ embeddedDocument:
+ path: 'items'
+ operator:
+ compound:
+ must:
+ -
+ text:
+ path: 'items.tags'
+ query: 'school'
+ should:
+ -
+ text:
+ path: 'items.name'
+ query: 'backpack'
+ score:
+ embedded:
+ aggregate: 'mean'
+ -
+ $limit: 5
+ -
+ $project:
+ _id: 0
+ items.name: 1
+ items.tags: 1
+ score:
+ $meta: 'searchScore'
+
+ -
+ name: 'Facet'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/embedded-document/#facet-query'
+ pipeline:
+ -
+ $searchMeta:
+ facet:
+ operator:
+ embeddedDocument:
+ path: 'items'
+ operator:
+ compound:
+ must:
+ -
+ text:
+ path: 'items.tags'
+ query: 'school'
+ should:
+ -
+ text:
+ path: 'items.name'
+ query: 'backpack'
+ facets:
+ purchaseMethodFacet:
+ type: 'string'
+ path: 'purchaseMethod'
+
+ -
+ name: 'Query and Sort'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/embedded-document/#query-and-sort'
+ pipeline:
+ -
+ $search:
+ embeddedDocument:
+ path: 'items'
+ operator:
+ text:
+ path: 'items.name'
+ query: 'laptop'
+ sort:
+ items.tags: 1
+ -
+ $limit: 5
+ -
+ $project:
+ _id: 0
+ items.name: 1
+ items.tags: 1
+ score:
+ $meta: 'searchScore'
+
+ -
+ name: 'Query for Matching Embedded Documents Only'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/embedded-document/#query-for-matching-embedded-documents-only'
+ pipeline:
+ -
+ $search:
+ embeddedDocument:
+ path: 'items'
+ operator:
+ compound:
+ must:
+ -
+ range:
+ path: 'items.quantity'
+ gt: 2
+ -
+ exists:
+ path: 'items.price'
+ -
+ text:
+ path: 'items.tags'
+ query: 'school'
+ -
+ $limit: 2
+ -
+ $project:
+ _id: 0
+ storeLocation: 1
+ items:
+ $filter:
+ input: '$items'
+ cond:
+ $and:
+ -
+ $ifNull:
+ - '$$this.price'
+ - 'false'
+ -
+ $gt:
+ - '$$this.quantity'
+ - 2
+ -
+ $in:
+ - 'office'
+ - '$$this.tags'
diff --git a/generator/config/search/equals.yaml b/generator/config/search/equals.yaml
new file mode 100644
index 000000000..b3e50c641
--- /dev/null
+++ b/generator/config/search/equals.yaml
@@ -0,0 +1,104 @@
+# $schema: ../schema.json
+name: equals
+link: 'https://www.mongodb.com/docs/atlas/atlas-search/equals/'
+type:
+ - searchOperator
+encode: object
+description: |
+ The equals operator checks whether a field matches a value you specify.
+arguments:
+ -
+ name: path
+ type:
+ - searchPath
+ -
+ name: value
+ type:
+ - binData
+ - bool
+ - date
+ - objectId
+ - 'null'
+ - number
+ - string
+ -
+ name: score
+ optional: true
+ type:
+ - searchScore
+tests:
+ -
+ name: 'Boolean'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/equals/#boolean-examples'
+ pipeline:
+ -
+ $search:
+ equals:
+ path: 'verified_user'
+ value: true
+ -
+ $project:
+ name: 1
+ _id: 0
+ score:
+ $meta: 'searchScore'
+
+ -
+ name: 'ObjectId'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/equals/#objectid-example'
+ pipeline:
+ -
+ $search:
+ equals:
+ path: 'teammates'
+ value: !bson_objectId '5a9427648b0beebeb69589a1'
+
+ -
+ name: 'Date'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/equals/#date-example'
+ pipeline:
+ -
+ $search:
+ equals:
+ path: 'account_created'
+ value: !bson_utcdatetime '2022-05-04T05:01:08.000+00:00'
+
+ -
+ name: 'Number'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/equals/#number-example'
+ pipeline:
+ -
+ $search:
+ equals:
+ path: 'employee_number'
+ value: 259
+
+ -
+ name: 'String'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/equals/#string-example'
+ pipeline:
+ -
+ $search:
+ equals:
+ path: 'name'
+ value: 'jim hall'
+
+ -
+ name: 'UUID'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/equals/#uuid-example'
+ pipeline:
+ -
+ $search:
+ equals:
+ path: 'uuid'
+ value: !bson_uuid 'fac32260-b511-4c69-8485-a2be5b7dda9e'
+
+ -
+ name: 'Null'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/equals/#null-example'
+ pipeline:
+ -
+ $search:
+ equals:
+ path: 'job_title'
+ value: ~
diff --git a/generator/config/search/exists.yaml b/generator/config/search/exists.yaml
new file mode 100644
index 000000000..062e8ba59
--- /dev/null
+++ b/generator/config/search/exists.yaml
@@ -0,0 +1,56 @@
+# $schema: ../schema.json
+name: exists
+link: 'https://www.mongodb.com/docs/atlas/atlas-search/exists/'
+type:
+ - searchOperator
+encode: object
+description: |
+ The exists operator tests if a path to a specified indexed field name exists in a document.
+arguments:
+ -
+ name: path
+ type:
+ - searchPath
+ -
+ name: score
+ optional: true
+ type:
+ - searchScore
+tests:
+ -
+ name: 'Basic'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/exists/#basic-example'
+ pipeline:
+ -
+ $search:
+ exists:
+ path: 'type'
+
+ -
+ name: 'Embedded'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/exists/#embedded-example'
+ pipeline:
+ -
+ $search:
+ exists:
+ path: 'quantities.lemons'
+
+ -
+ name: 'Compound'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/exists/#compound-example'
+ pipeline:
+ -
+ $search:
+ compound:
+ must:
+ -
+ exists:
+ path: 'type'
+ -
+ text:
+ query: 'apple'
+ path: 'type'
+ should:
+ text:
+ query: 'fuji'
+ path: 'description'
diff --git a/generator/config/search/facet.yaml b/generator/config/search/facet.yaml
new file mode 100644
index 000000000..53dc8cba9
--- /dev/null
+++ b/generator/config/search/facet.yaml
@@ -0,0 +1,56 @@
+# $schema: ../schema.json
+name: facet
+link: 'https://www.mongodb.com/docs/atlas/atlas-search/facet/'
+type:
+ - searchOperator # should be searchCollector
+encode: object
+description: |
+ The facet collector groups results by values or ranges in the specified
+ faceted fields and returns the count for each of those groups.
+arguments:
+ -
+ name: facets
+ type:
+ - object # map of facetDefinition
+ -
+ name: operator
+ optional: true
+ type:
+ - searchOperator
+tests:
+ -
+ name: 'Facet'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/facet/#examples'
+ pipeline:
+ -
+ $search:
+ facet:
+ operator:
+ near:
+ path: 'released'
+ origin: !bson_utcdatetime '1999-07-01T00:00:00.000+00:00'
+ pivot: 7776000000
+ facets:
+ genresFacet:
+ type: 'string'
+ path: 'genres'
+ -
+ $limit: 2
+ -
+ $facet:
+ docs:
+ -
+ $project:
+ title: 1
+ released: 1
+ meta:
+ -
+ $replaceWith: '$$SEARCH_META'
+ -
+ $limit: 1
+ -
+ $set:
+ meta:
+ $arrayElemAt:
+ - '$meta'
+ - 0
diff --git a/generator/config/search/geoShape.yaml b/generator/config/search/geoShape.yaml
new file mode 100644
index 000000000..4da121e45
--- /dev/null
+++ b/generator/config/search/geoShape.yaml
@@ -0,0 +1,123 @@
+# $schema: ../schema.json
+name: geoShape
+link: 'https://www.mongodb.com/docs/atlas/atlas-search/geoShape/'
+type:
+ - searchOperator
+encode: object
+description: |
+ The geoShape operator supports querying shapes with a relation to a given
+ geometry if indexShapes is set to true in the index definition.
+arguments:
+ -
+ name: path
+ type:
+ - searchPath
+ -
+ name: relation
+ type:
+ - string # contains | disjoint | intersects | within
+ -
+ name: geometry
+ type:
+ - geometry
+ -
+ name: score
+ optional: true
+ type:
+ - searchScore
+tests:
+ -
+ name: 'Disjoint'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/geoShape/#disjoint-example'
+ pipeline:
+ -
+ $search:
+ geoShape:
+ relation: 'disjoint'
+ geometry:
+ type: 'Polygon'
+ coordinates:
+ -
+ - [-161.323242, 22.512557]
+ - [-152.446289, 22.065278]
+ - [-156.09375, 17.811456]
+ - [-161.323242, 22.512557]
+ path: 'address.location'
+ -
+ $limit: 3
+ -
+ $project:
+ _id: 0
+ name: 1
+ address: 1
+ score:
+ $meta: 'searchScore'
+
+ -
+ name: 'Intersect'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/geoShape/#intersects-example'
+ pipeline:
+ -
+ $search:
+ geoShape:
+ relation: 'intersects'
+ geometry:
+ type: 'MultiPolygon'
+ coordinates:
+ -
+ -
+ - [2.16942, 41.40082]
+ - [2.17963, 41.40087]
+ - [2.18146, 41.39716]
+ - [2.15533, 41.40686]
+ - [2.14596, 41.38475]
+ - [2.17519, 41.41035]
+ - [2.16942, 41.40082]
+ -
+ -
+ - [2.16365, 41.39416]
+ - [2.16963, 41.39726]
+ - [2.15395, 41.38005]
+ - [2.17935, 41.43038]
+ - [2.16365, 41.39416]
+ path: 'address.location'
+ -
+ $limit: 3
+ -
+ $project:
+ _id: 0
+ name: 1
+ address: 1
+ score:
+ $meta: 'searchScore'
+
+ -
+ name: 'Within'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/geoShape/#within-example'
+ pipeline:
+ -
+ $search:
+ geoShape:
+ relation: 'within'
+ geometry:
+ type: 'Polygon'
+ coordinates:
+ -
+ - [-74.3994140625, 40.5305017757]
+ - [-74.7290039063, 40.5805846641]
+ - [-74.7729492188, 40.9467136651]
+ - [-74.0698242188, 41.1290213475]
+ - [-73.65234375, 40.9964840144]
+ - [-72.6416015625, 40.9467136651]
+ - [-72.3559570313, 40.7971774152]
+ - [-74.3994140625, 40.5305017757]
+ path: 'address.location'
+ -
+ $limit: 3
+ -
+ $project:
+ _id: 0
+ name: 1
+ address: 1
+ score:
+ $meta: 'searchScore'
diff --git a/generator/config/search/geoWithin.yaml b/generator/config/search/geoWithin.yaml
new file mode 100644
index 000000000..1739f1997
--- /dev/null
+++ b/generator/config/search/geoWithin.yaml
@@ -0,0 +1,103 @@
+# $schema: ../schema.json
+name: geoWithin
+link: 'https://www.mongodb.com/docs/atlas/atlas-search/geoWithin/'
+type:
+ - searchOperator
+encode: object
+description: |
+ The geoWithin operator supports querying geographic points within a given
+ geometry. Only points are returned, even if indexShapes value is true in
+ the index definition.
+arguments:
+ -
+ name: path
+ type:
+ - searchPath
+ -
+ name: box
+ optional: true
+ type:
+ - object
+ -
+ name: circle
+ optional: true
+ type:
+ - object
+ -
+ name: geometry
+ optional: true
+ type:
+ - geometry
+ -
+ name: score
+ optional: true
+ type:
+ - searchScore
+tests:
+ -
+ name: 'box'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/geoWithin/#box-example'
+ pipeline:
+ -
+ $search:
+ geoWithin:
+ path: 'address.location'
+ box:
+ bottomLeft:
+ type: 'Point'
+ coordinates: [112.467, -55.05]
+ topRight:
+ type: 'Point'
+ coordinates: [168, -9.133]
+ -
+ $limit: 3
+ -
+ $project:
+ _id: 0
+ name: 1
+ address: 1
+
+ -
+ name: 'circle'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/geoWithin/#circle-example'
+ pipeline:
+ -
+ $search:
+ geoWithin:
+ circle:
+ center:
+ type: 'Point'
+ coordinates: [-73.54, 45.54]
+ radius: 1600
+ path: 'address.location'
+ -
+ $limit: 3
+ -
+ $project:
+ _id: 0
+ name: 1
+ address: 1
+
+ -
+ name: 'geometry'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/geoWithin/#geometry-examples'
+ pipeline:
+ -
+ $search:
+ geoWithin:
+ geometry:
+ type: 'Polygon'
+ coordinates:
+ -
+ - [-161.323242, 22.512557]
+ - [-152.446289, 22.065278]
+ - [-156.09375, 17.811456]
+ - [-161.323242, 22.512557]
+ path: 'address.location'
+ -
+ $limit: 3
+ -
+ $project:
+ _id: 0
+ name: 1
+ address: 1
diff --git a/generator/config/search/in.yaml b/generator/config/search/in.yaml
new file mode 100644
index 000000000..cc1aa6c33
--- /dev/null
+++ b/generator/config/search/in.yaml
@@ -0,0 +1,89 @@
+# $schema: ../schema.json
+name: in
+link: 'https://www.mongodb.com/docs/atlas/atlas-search/in/'
+type:
+ - searchOperator
+encode: object
+description: |
+ The in operator performs a search for an array of BSON values in a field.
+arguments:
+ -
+ name: path
+ type:
+ - searchPath
+ -
+ name: value
+ type:
+ - any
+ - array # of any
+ -
+ name: score
+ optional: true
+ type:
+ - searchScore
+tests:
+ -
+ name: 'Single Value Field Match'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/in/#examples'
+ pipeline:
+ -
+ $search:
+ in:
+ path: 'birthdate'
+ value:
+ - !bson_utcdatetime '1977-03-02T02:20:31.000+00:00'
+ - !bson_utcdatetime '1977-03-01T00:00:00.000+00:00'
+ - !bson_utcdatetime '1977-05-06T21:57:35.000+00:00'
+ -
+ $project:
+ _id: 0
+ name: 1
+ birthdate: 1
+
+ -
+ name: 'Array Value Field Match'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/in/#examples'
+ pipeline:
+ -
+ $search:
+ in:
+ path: 'accounts'
+ value:
+ - 371138
+ - 371139
+ - 371140
+ -
+ $project:
+ _id: 0
+ name: 1
+ accounts: 1
+
+ -
+ name: 'Compound Query Match'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/in/#examples'
+ pipeline:
+ -
+ $search:
+ compound:
+ must:
+ -
+ in:
+ path: 'name'
+ value:
+ - 'james sanchez'
+ - 'jennifer lawrence'
+ should:
+ -
+ in:
+ path: '_id'
+ value:
+ - !bson_objectId '5ca4bbcea2dd94ee58162a72'
+ - !bson_objectId '5ca4bbcea2dd94ee58162a91'
+ -
+ $limit: 5
+ -
+ $project:
+ _id: 1
+ name: 1
+ score:
+ $meta: 'searchScore'
diff --git a/generator/config/search/moreLikeThis.yaml b/generator/config/search/moreLikeThis.yaml
new file mode 100644
index 000000000..8c4803bdd
--- /dev/null
+++ b/generator/config/search/moreLikeThis.yaml
@@ -0,0 +1,99 @@
+# $schema: ../schema.json
+name: moreLikeThis
+link: 'https://www.mongodb.com/docs/atlas/atlas-search/moreLikeThis/'
+type:
+ - searchOperator
+encode: object
+description: |
+ The moreLikeThis operator returns documents similar to input documents.
+ The moreLikeThis operator allows you to build features for your applications
+ that display similar or alternative results based on one or more given documents.
+arguments:
+ -
+ name: like
+ type:
+ - object
+ - array # of object
+ -
+ name: score
+ optional: true
+ type:
+ - searchScore
+tests:
+ -
+ name: 'Single Document with Multiple Fields'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/morelikethis/#example-1--single-document-with-multiple-fields'
+ pipeline:
+ -
+ $search:
+ moreLikeThis:
+ like:
+ title: 'The Godfather'
+ genres: 'action'
+ -
+ $limit: 5
+ -
+ $project:
+ _id: 0
+ title: 1
+ released: 1
+ genres: 1
+
+ -
+ name: 'Input Document Excluded in Results'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/morelikethis/#example-2--input-document-excluded-in-results'
+ pipeline:
+ -
+ $search:
+ compound:
+ must:
+ -
+ moreLikeThis:
+ like:
+ _id: !bson_objectId '573a1396f29313caabce4a9a'
+ genres:
+ - 'Crime'
+ - 'Drama'
+ title: 'The Godfather'
+ mustNot:
+ -
+ equals:
+ path: '_id'
+ value: !bson_objectId '573a1396f29313caabce4a9a'
+ -
+ $limit: 5
+ -
+ $project:
+ _id: 1
+ title: 1
+ released: 1
+ genres: 1
+
+ -
+ name: 'Multiple Analyzers'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/morelikethis/#example-3--multiple-analyzers'
+ pipeline:
+ -
+ $search:
+ compound:
+ should:
+ -
+ moreLikeThis:
+ like:
+ _id: !bson_objectId '573a1396f29313caabce4a9a'
+ genres:
+ - 'Crime'
+ - 'Drama'
+ title: 'The Godfather'
+ mustNot:
+ -
+ equals:
+ path: '_id'
+ value: !bson_objectId '573a1394f29313caabcde9ef'
+ -
+ $limit: 10
+ -
+ $project:
+ title: 1
+ genres: 1
+ _id: 1
diff --git a/generator/config/search/near.yaml b/generator/config/search/near.yaml
new file mode 100644
index 000000000..bd4119cf9
--- /dev/null
+++ b/generator/config/search/near.yaml
@@ -0,0 +1,124 @@
+# $schema: ../schema.json
+name: near
+link: 'https://www.mongodb.com/docs/atlas/atlas-search/near/'
+type:
+ - searchOperator
+encode: object
+description: |
+ The near operator supports querying and scoring numeric, date, and GeoJSON point values.
+arguments:
+ -
+ name: path
+ type:
+ - searchPath
+ -
+ name: origin
+ type:
+ - date
+ - number
+ - geometry
+ -
+ name: pivot
+ type:
+ - number
+ -
+ name: score
+ optional: true
+ type:
+ - searchScore
+tests:
+ -
+ name: 'Number'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/near/#number-example'
+ pipeline:
+ -
+ $search:
+ index: 'runtimes'
+ near:
+ path: 'runtime'
+ origin: 279
+ pivot: 2
+ -
+ $limit: 7
+ -
+ $project:
+ _id: 0
+ title: 1
+ runtime: 1
+ score:
+ $meta: 'searchScore'
+
+ -
+ name: 'Date'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/near/#date-example'
+ pipeline:
+ -
+ $search:
+ index: 'releaseddate'
+ near:
+ path: 'released'
+ origin: !bson_utcdatetime '1915-09-13T00:00:00.000+00:00'
+ pivot: 7776000000
+ -
+ $limit: 3
+ -
+ $project:
+ _id: 0
+ title: 1
+ released: 1
+ score:
+ $meta: 'searchScore'
+
+ -
+ name: 'GeoJSON Point'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/near/#geojson-point-examples'
+ pipeline:
+ -
+ $search:
+ near:
+ origin:
+ type: 'Point'
+ coordinates:
+ - -8.61308
+ - 41.1413
+ pivot: 1000
+ path: 'address.location'
+ -
+ $limit: 3
+ -
+ $project:
+ _id: 0
+ name: 1
+ address: 1
+ score:
+ $meta: 'searchScore'
+
+ -
+ name: 'Compound'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/near/#compound-example'
+ pipeline:
+ -
+ $search:
+ compound:
+ must:
+ text:
+ query: 'Apartment'
+ path: 'property_type'
+ should:
+ near:
+ origin:
+ type: 'Point'
+ coordinates:
+ - 114.15027
+ - 22.28158
+ pivot: 1000
+ path: 'address.location'
+ -
+ $limit: 3
+ -
+ $project:
+ _id: 0
+ property_type: 1
+ address: 1
+ score:
+ $meta: 'searchScore'
diff --git a/generator/config/search/phrase.yaml b/generator/config/search/phrase.yaml
new file mode 100644
index 000000000..4d9b75c4e
--- /dev/null
+++ b/generator/config/search/phrase.yaml
@@ -0,0 +1,109 @@
+# $schema: ../schema.json
+name: phrase
+link: 'https://www.mongodb.com/docs/atlas/atlas-search/phrase/'
+type:
+ - searchOperator
+encode: object
+description: |
+ The phrase operator performs search for documents containing an ordered sequence of terms using the analyzer specified in the index configuration.
+arguments:
+ -
+ name: path
+ type:
+ - searchPath
+ -
+ name: query
+ type:
+ - string
+ - array # of string
+ -
+ name: slop
+ optional: true
+ type:
+ - int
+ -
+ name: synonyms
+ optional: true
+ type:
+ - string
+ -
+ name: score
+ optional: true
+ type:
+ - searchScore
+tests:
+ -
+ name: 'Single Phrase'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/phrase/#single-phrase-example'
+ pipeline:
+ -
+ $search:
+ phrase:
+ path: 'title'
+ query: 'new york'
+ -
+ $limit: 10
+ -
+ $project:
+ _id: 0
+ title: 1
+ score:
+ $meta: 'searchScore'
+
+ -
+ name: 'Multiple Phrase'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/phrase/#multiple-phrases-example'
+ pipeline:
+ -
+ $search:
+ phrase:
+ path: 'title'
+ query:
+ - 'the man'
+ - 'the moon'
+ -
+ $limit: 10
+ -
+ $project:
+ _id: 0
+ title: 1
+ score:
+ $meta: 'searchScore'
+
+ -
+ name: 'Phrase Slop'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/phrase/#slop-example'
+ pipeline:
+ -
+ $search:
+ phrase:
+ path: 'title'
+ query: 'men women'
+ slop: 5
+ -
+ $project:
+ _id: 0
+ title: 1
+ score:
+ $meta: 'searchScore'
+
+ -
+ name: 'Phrase Synonyms'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/phrase/#synonyms-example'
+ pipeline:
+ -
+ $search:
+ phrase:
+ path: 'plot'
+ query: 'automobile race'
+ slop: 5
+ synonyms: 'my_synonyms'
+ -
+ $limit: 5
+ -
+ $project:
+ _id: 0
+ plot: 1
+ title: 1
+ score:
+ $meta: 'searchScore'
diff --git a/generator/config/search/queryString.yaml b/generator/config/search/queryString.yaml
new file mode 100644
index 000000000..8202771c9
--- /dev/null
+++ b/generator/config/search/queryString.yaml
@@ -0,0 +1,35 @@
+# $schema: ../schema.json
+name: queryString
+link: 'https://www.mongodb.com/docs/atlas/atlas-search/queryString/'
+type:
+ - searchOperator
+encode: object
+description: |
+
+arguments:
+ -
+ name: defaultPath
+ type:
+ - searchPath
+ -
+ name: query
+ type:
+ - string
+
+# The various example from the doc are variations of the "query" parameter
+# this is not pertinent for testing the aggregation builder, unless we create
+# a queryString builder.
+tests:
+ -
+ name: 'Boolean Operator Queries'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/queryString/#boolean-operator-queries'
+ pipeline:
+ -
+ $search:
+ queryString:
+ defaultPath: 'title'
+ query: 'Rocky AND (IV OR 4 OR Four)'
+ -
+ $project:
+ _id: 0
+ title: 1
diff --git a/generator/config/search/range.yaml b/generator/config/search/range.yaml
new file mode 100644
index 000000000..f42c69176
--- /dev/null
+++ b/generator/config/search/range.yaml
@@ -0,0 +1,139 @@
+# $schema: ../schema.json
+name: range
+link: 'https://www.mongodb.com/docs/atlas/atlas-search/range/'
+type:
+ - searchOperator
+encode: object
+description: |
+ The range operator supports querying and scoring numeric, date, and string values.
+ You can use this operator to find results that are within a given numeric, date, objectId, or letter (from the English alphabet) range.
+arguments:
+ -
+ name: path
+ type:
+ - searchPath
+ -
+ name: gt
+ optional: true
+ type:
+ - date
+ - number
+ - string
+ - objectId
+ -
+ name: gte
+ optional: true
+ type:
+ - date
+ - number
+ - string
+ - objectId
+ -
+ name: lt
+ optional: true
+ type:
+ - date
+ - number
+ - string
+ - objectId
+ -
+ name: lte
+ optional: true
+ type:
+ - date
+ - number
+ - string
+ - objectId
+ -
+ name: score
+ optional: true
+ type:
+ - searchScore
+tests:
+ -
+ name: 'Number gte lte'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/range/#number-example'
+ pipeline:
+ -
+ $search:
+ range:
+ path: 'runtime'
+ gte: 2
+ lte: 3
+ -
+ $limit: 5
+ -
+ $project:
+ _id: 0
+ title: 1
+ runtime: 1
+
+ -
+ name: 'Number lte'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/range/#number-example'
+ pipeline:
+ -
+ $search:
+ range:
+ path: 'runtime'
+ lte: 2
+ -
+ $limit: 5
+ -
+ $project:
+ _id: 0
+ title: 1
+ runtime: 1
+ score:
+ $meta: 'searchScore'
+
+ -
+ name: 'Date'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/range/#date-example'
+ pipeline:
+ -
+ $search:
+ range:
+ path: 'released'
+ gt: !bson_utcdatetime '2010-01-01T00:00:00.000Z'
+ lt: !bson_utcdatetime '2015-01-01T00:00:00.000Z'
+ -
+ $limit: 5
+ -
+ $project:
+ _id: 0
+ title: 1
+ released: 1
+
+ -
+ name: 'ObjectId'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/range/#objectid-example'
+ pipeline:
+ -
+ $search:
+ range:
+ path: '_id'
+ gte: !bson_objectId '573a1396f29313caabce4a9a'
+ lte: !bson_objectId '573a1396f29313caabce4ae7'
+ -
+ $project:
+ _id: 1
+ title: 1
+ released: 1
+
+ -
+ name: 'String'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/range/#string-example'
+ pipeline:
+ -
+ $search:
+ range:
+ path: 'title'
+ gt: 'city'
+ lt: 'country'
+ -
+ $limit: 5
+ -
+ $project:
+ _id: 0
+ title: 1
diff --git a/generator/config/search/regex.yaml b/generator/config/search/regex.yaml
new file mode 100644
index 000000000..869ffabde
--- /dev/null
+++ b/generator/config/search/regex.yaml
@@ -0,0 +1,42 @@
+# $schema: ../schema.json
+name: regex
+link: 'https://www.mongodb.com/docs/atlas/atlas-search/regex/'
+type:
+ - searchOperator
+encode: object
+description: |
+ regex interprets the query field as a regular expression.
+ regex is a term-level operator, meaning that the query field isn't analyzed.
+arguments:
+ -
+ name: path
+ type:
+ - searchPath
+ -
+ name: query
+ type:
+ - string
+ -
+ name: allowAnalyzedField
+ optional: true
+ type:
+ - bool
+ -
+ name: score
+ optional: true
+ type:
+ - searchScore
+tests:
+ -
+ name: 'Regex'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/regex/#examples'
+ pipeline:
+ -
+ $search:
+ regex:
+ path: 'title'
+ query: '[0-9]{2} (.){4}s'
+ -
+ $project:
+ _id: 0
+ title: 1
diff --git a/generator/config/search/text.yaml b/generator/config/search/text.yaml
new file mode 100644
index 000000000..dbd48cdd0
--- /dev/null
+++ b/generator/config/search/text.yaml
@@ -0,0 +1,194 @@
+# $schema: ../schema.json
+name: text
+link: 'https://www.mongodb.com/docs/atlas/atlas-search/text/'
+type:
+ - searchOperator
+encode: object
+description: |
+ The text operator performs a full-text search using the analyzer that you specify in the index configuration.
+ If you omit an analyzer, the text operator uses the default standard analyzer.
+arguments:
+ -
+ name: path
+ type:
+ - searchPath
+ -
+ name: query
+ type:
+ - string
+ -
+ name: fuzzy
+ optional: true
+ type:
+ - object
+ -
+ name: matchCriteria
+ optional: true
+ type:
+ - string # "any" | "all"
+ -
+ name: synonyms
+ optional: true
+ type:
+ - string
+ -
+ name: score
+ optional: true
+ type:
+ - searchScore
+tests:
+ -
+ name: 'Basic'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/text/#basic-example'
+ pipeline:
+ -
+ $search:
+ text:
+ path: 'title'
+ query: 'surfer'
+ -
+ $project:
+ _id: 0
+ title: 1
+ score:
+ $meta: 'searchScore'
+ -
+ name: 'Fuzzy Default'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/text/#fuzzy-examples'
+ pipeline:
+ -
+ $search:
+ text:
+ path: 'title'
+ query: 'naw yark'
+ fuzzy: {}
+ -
+ $limit: 10
+ -
+ $project:
+ _id: 0
+ title: 1
+ score:
+ $meta: 'searchScore'
+
+ -
+ name: 'Fuzzy maxExpansions'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/text/#fuzzy-examples'
+ pipeline:
+ -
+ $search:
+ text:
+ path: 'title'
+ query: 'naw yark'
+ fuzzy:
+ maxEdits: 1
+ maxExpansions: 100
+ -
+ $limit: 10
+ -
+ $project:
+ _id: 0
+ title: 1
+ score:
+ $meta: 'searchScore'
+
+ -
+ name: 'Fuzzy prefixLength'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/text/#fuzzy-examples'
+ pipeline:
+ -
+ $search:
+ text:
+ path: 'title'
+ query: 'naw yark'
+ fuzzy:
+ maxEdits: 1
+ prefixLength: 2
+ -
+ $limit: 8
+ -
+ $project:
+ _id: 1
+ title: 1
+ score:
+ $meta: 'searchScore'
+
+ -
+ name: 'Match any Using equivalent Mapping'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/text/#match-any-using-equivalent-mapping'
+ pipeline:
+ -
+ $search:
+ text:
+ path: 'plot'
+ query: 'attire'
+ synonyms: 'my_synonyms'
+ matchCriteria: 'any'
+ -
+ $limit: 5
+ -
+ $project:
+ _id: 0
+ plot: 1
+ title: 1
+ score:
+ $meta: 'searchScore'
+
+ -
+ name: 'Match any Using explicit Mapping'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/text/#match-any-using-explicit-mapping'
+ pipeline:
+ -
+ $search:
+ text:
+ path: 'plot'
+ query: 'boat race'
+ synonyms: 'my_synonyms'
+ matchCriteria: 'any'
+ -
+ $limit: 10
+ -
+ $project:
+ _id: 0
+ plot: 1
+ title: 1
+ score:
+ $meta: 'searchScore'
+
+ -
+ name: 'Match all Using Synonyms'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/text/#match-all-using-synonyms'
+ pipeline:
+ -
+ $search:
+ text:
+ path: 'plot'
+ query: 'automobile race'
+ matchCriteria: 'all'
+ synonyms: 'my_synonyms'
+ -
+ $limit: 20
+ -
+ $project:
+ _id: 0
+ plot: 1
+ title: 1
+ score:
+ $meta: 'searchScore'
+
+ -
+ name: 'Wildcard Path'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/text/'
+ pipeline:
+ -
+ $search:
+ text:
+ path:
+ wildcard: '*'
+ query: 'surfer'
+ -
+ $project:
+ _id: 0
+ title: 1
+ score:
+ $meta: 'searchScore'
diff --git a/generator/config/search/wildcard.yaml b/generator/config/search/wildcard.yaml
new file mode 100644
index 000000000..d17fb4803
--- /dev/null
+++ b/generator/config/search/wildcard.yaml
@@ -0,0 +1,60 @@
+# $schema: ../schema.json
+name: wildcard
+link: 'https://www.mongodb.com/docs/atlas/atlas-search/wildcard/'
+type:
+ - searchOperator
+encode: object
+description: |
+ The wildcard operator enables queries which use special characters in the search string that can match any character.
+arguments:
+ -
+ name: path
+ type:
+ - searchPath
+ -
+ name: query
+ type:
+ - string
+ -
+ name: allowAnalyzedField
+ optional: true
+ type:
+ - bool
+ -
+ name: score
+ optional: true
+ type:
+ - searchScore
+tests:
+ -
+ name: 'Wildcard Path'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/wildcard/#index-definition'
+ pipeline:
+ -
+ $search:
+ wildcard:
+ query: 'Wom?n *'
+ path:
+ wildcard: '*'
+ -
+ $limit: 5
+ -
+ $project:
+ _id: 0
+ title: 1
+
+ -
+ name: 'Escape Character Example'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/wildcard/#escape-character-example'
+ pipeline:
+ -
+ $search:
+ wildcard:
+ query: '*\?'
+ path: 'title'
+ -
+ $limit: 5
+ -
+ $project:
+ _id: 0
+ title: 1
diff --git a/generator/config/stage/group.yaml b/generator/config/stage/group.yaml
index 3e93588e9..a4bae60c2 100644
--- a/generator/config/stage/group.yaml
+++ b/generator/config/stage/group.yaml
@@ -3,7 +3,7 @@ name: $group
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/group/'
type:
- stage
-encode: group
+encode: object
description: |
Groups input documents by a specified identifier expression and applies the accumulator expression(s), if specified, to each group. Consumes all input documents and outputs one document per each distinct group. The output documents only contain the identifier field and, if specified, accumulated fields.
arguments:
@@ -15,6 +15,7 @@ arguments:
The _id expression specifies the group key. If you specify an _id value of null, or any other constant value, the $group stage returns a single document that aggregates values across all of the input documents.
-
name: field
+ mergeObject: true
type:
- accumulator
variadic: object
diff --git a/generator/config/stage/search.yaml b/generator/config/stage/search.yaml
index 2531e75f6..34bf57a34 100644
--- a/generator/config/stage/search.yaml
+++ b/generator/config/stage/search.yaml
@@ -3,16 +3,93 @@ name: $search
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/search/'
type:
- stage
-encode: single
+encode: object
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
+ name: operator
+ mergeObject: true
+ type:
+ - searchOperator
+ description: |
+ Operator to search with. You can provide a specific operator or use
+ the compound operator to run a compound query with multiple operators.
+ -
+ name: index
+ optional: true
+ type:
+ - string
+ description: |
+ Name of the Atlas Search index to use. If omitted, defaults to "default".
+ -
+ name: highlight
+ optional: true
+ type:
+ # @todo support "highlight" type object
+ # https://www.mongodb.com/docs/atlas/atlas-search/highlighting/
+ - object
+ description: |
+ Specifies the highlighting options for displaying search terms in their original context.
+ -
+ name: concurrent
+ optional: true
+ type:
+ - bool
+ description: |
+ Parallelize search across segments on dedicated search nodes.
+ If you don't have separate search nodes on your cluster,
+ Atlas Search ignores this flag. If omitted, defaults to false.
+ -
+ name: count
+ optional: true
+ type:
+ - string
+ description: |
+ Document that specifies the count options for retrieving a count of the results.
+ -
+ name: searchAfter
+ optional: true
+ type:
+ - string
+ description: |
+ Reference point for retrieving results. searchAfter returns documents starting immediately following the specified reference point.
+ -
+ name: searchBefore
+ optional: true
+ type:
+ - string
+ description: |
+ Reference point for retrieving results. searchBefore returns documents starting immediately before the specified reference point.
+ -
+ name: scoreDetails
+ optional: true
+ type:
+ - bool
+ description: |
+ Flag that specifies whether to retrieve a detailed breakdown of the score for the documents in the results. If omitted, defaults to false.
+ -
+ name: sort
+ optional: true
+ type:
+ - object
+ description: |
+ Document that specifies the fields to sort the Atlas Search results by in ascending or descending order.
+ -
+ name: returnStoredSource
+ optional: true
+ type:
+ - bool
+ description: |
+ Flag that specifies whether to perform a full document lookup on the backend database or return only stored source fields directly from Atlas Search.
+ -
+ name: tracking
+ optional: true
type:
- object
-
+ description: |
+ Document that specifies the tracking option to retrieve analytics information on the search terms.
tests:
-
name: 'Example'
diff --git a/generator/config/stage/searchMeta.yaml b/generator/config/stage/searchMeta.yaml
index 322d048eb..a7d92c272 100644
--- a/generator/config/stage/searchMeta.yaml
+++ b/generator/config/stage/searchMeta.yaml
@@ -3,16 +3,34 @@ name: $searchMeta
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/searchMeta/'
type:
- stage
-encode: single
+encode: object
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
+ name: operator
+ mergeObject: true
type:
- - object
+ - searchOperator
+ description: |
+ Operator to search with. You can provide a specific operator or use
+ the compound operator to run a compound query with multiple operators.
+ -
+ name: index
+ optional: true
+ type:
+ - string
+ description: |
+ Name of the Atlas Search index to use. If omitted, defaults to default.
+ -
+ name: count
+ optional: true
+ type:
+ - object
+ description: |
+ Document that specifies the count options for retrieving a count of the results.
tests:
-
name: 'Example'
@@ -26,3 +44,89 @@ tests:
lt: 1999
count:
type: 'total'
+
+ -
+ name: 'Year Facet'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/facet/#example-1'
+ pipeline:
+ - $searchMeta:
+ facet:
+ operator:
+ range:
+ path: 'year'
+ gte: 1980
+ lte: 2000
+ facets:
+ yearFacet:
+ type: 'number'
+ path: 'year'
+ boundaries:
+ - 1980
+ - 1990
+ - 2000
+ default: 'other'
+
+ -
+ name: 'Date Facet'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/facet/#example-2'
+ pipeline:
+ -
+ $searchMeta:
+ facet:
+ operator:
+ range:
+ path: 'released'
+ gte: !bson_utcdatetime '2000-01-01T00:00:00.000Z'
+ lte: !bson_utcdatetime '2015-01-31T00:00:00.000Z'
+ facets:
+ yearFacet:
+ type: 'date'
+ path: 'released'
+ boundaries:
+ - !bson_utcdatetime '2000-01-01'
+ - !bson_utcdatetime '2005-01-01'
+ - !bson_utcdatetime '2010-01-01'
+ - !bson_utcdatetime '2015-01-01'
+ default: 'other'
+
+ -
+ name: 'Metadata Results'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/facet/#examples'
+ pipeline:
+ -
+ $searchMeta:
+ facet:
+ operator:
+ range:
+ path: 'released'
+ gte: !bson_utcdatetime '2000-01-01T00:00:00.000Z'
+ lte: !bson_utcdatetime '2015-01-31T00:00:00.000Z'
+ facets:
+ directorsFacet:
+ type: 'string'
+ path: 'directors'
+ numBuckets: 7
+ yearFacet:
+ type: 'number'
+ path: 'year'
+ boundaries:
+ - 2000
+ - 2005
+ - 2010
+ - 2015
+
+ -
+ name: 'Autocomplete Bucket Results through Facet Queries'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/#bucket-results-through-facet-queries'
+ pipeline:
+ -
+ $searchMeta:
+ facet:
+ operator:
+ autocomplete:
+ path: 'title'
+ query: 'Gravity'
+ facets:
+ titleFacet:
+ type: 'string'
+ path: 'title'
diff --git a/generator/config/stage/vectorSearch.yaml b/generator/config/stage/vectorSearch.yaml
new file mode 100644
index 000000000..ec4b4ff4b
--- /dev/null
+++ b/generator/config/stage/vectorSearch.yaml
@@ -0,0 +1,119 @@
+# $schema: ../schema.json
+name: $vectorSearch
+link: 'https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-stage/'
+type:
+ - stage
+encode: object
+description: |
+ The $vectorSearch stage performs an ANN or ENN search on a vector in the specified field.
+arguments:
+ -
+ name: index
+ type:
+ - string
+ description: |
+ Name of the Atlas Vector Search index to use.
+ -
+ name: limit
+ type:
+ - int
+ description: |
+ Number of documents to return in the results. This value can't exceed the value of numCandidates if you specify numCandidates.
+ -
+ name: path
+ type:
+ - searchPath
+ description: |
+ Indexed vector type field to search.
+ -
+ name: queryVector
+ type:
+ - array # of numbers
+ description: |
+ Array of numbers that represent the query vector. The number type must match the indexed field value type.
+ -
+ name: exact
+ optional: true
+ type:
+ - bool
+ description: |
+ This is required if numCandidates is omitted. false to run ANN search. true to run ENN search.
+ -
+ name: filter
+ optional: true
+ type:
+ - query
+ description: |
+ Any match query that compares an indexed field with a boolean, date, objectId, number (not decimals), string, or UUID to use as a pre-filter.
+ -
+ name: numCandidates
+ optional: true
+ type:
+ - int
+ description: |
+ This field is required if exact is false or omitted.
+ Number of nearest neighbors to use during the search. Value must be less than or equal to (<=) 10000. You can't specify a number less than the number of documents to return (limit).
+
+tests:
+ -
+ name: 'ANN Basic'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-stage/#ann-examples'
+ pipeline:
+ -
+ $vectorSearch:
+ index: 'vector_index'
+ path: 'plot_embedding'
+ queryVector: [-0.0016261312, -0.028070757, -0.011342932] # skip other numbers, not relevant to the test
+ numCandidates: 150
+ limit: 10
+ -
+ $project:
+ _id: 0
+ plot: 1
+ title: 1
+ score:
+ $meta: 'vectorSearchScore'
+
+ -
+ name: 'ANN Filter'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-stage/#ann-examples'
+ pipeline:
+ -
+ $vectorSearch:
+ index: 'vector_index'
+ path: 'plot_embedding'
+ filter:
+ $and:
+ -
+ year:
+ $lt: 1975
+ queryVector: [0.02421053, -0.022372592, -0.006231137] # skip other numbers, not relevant to the test
+ numCandidates: 150
+ limit: 10
+ -
+ $project:
+ _id: 0
+ title: 1
+ plot: 1
+ year: 1
+ score:
+ $meta: 'vectorSearchScore'
+
+ -
+ name: 'ENN'
+ link: 'https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-stage/#enn-examples'
+ pipeline:
+ -
+ $vectorSearch:
+ index: 'vector_index'
+ path: 'plot_embedding'
+ queryVector: [-0.006954097, -0.009932499, -0.001311474] # skip other numbers, not relevant to the test
+ exact: true
+ limit: 10
+ -
+ $project:
+ _id: 0
+ plot: 1
+ title: 1
+ score:
+ $meta: 'vectorSearchScore'
diff --git a/generator/js2yaml.html b/generator/js2yaml.html
index a0f8654af..31241adb1 100644
--- a/generator/js2yaml.html
+++ b/generator/js2yaml.html
@@ -28,6 +28,9 @@
Convert JS examples into Yaml
binary: BinData(0, "IA=="),
empty_object: {},
empty_array: [],
+ objectId: ObjectId("5f0f1d9b1c9d440000f3f3f3"),
+ uuid: UUID("fac32260-b511-4c69-8485-a2be5b7dda9e"),
+ list: [1, 2, 3],
}
},
// First Stage
@@ -90,6 +93,14 @@ Convert JS examples into Yaml
return new TaggedValue('bson_int64', value)
}
+ function ObjectId(value) {
+ return new TaggedValue('bson_objectId', value)
+ }
+
+ function UUID(value) {
+ return new TaggedValue('bson_uuid', value)
+ }
+
function convert(jsString) {
try {
return toYaml(eval(jsString), 1);
@@ -109,6 +120,11 @@ Convert JS examples into Yaml
return ' []';
}
+ // Inline list of numbers
+ if (object.every(item => typeof item === 'number')) {
+ return ' [' + object.join(', ') + ']';
+ }
+
return newline + '-' + object.map((item) => toYaml(item, indent + 1)).join(newline + '-');
}
diff --git a/generator/src/Definition/ArgumentDefinition.php b/generator/src/Definition/ArgumentDefinition.php
index e45ea0da3..7cdd7d321 100644
--- a/generator/src/Definition/ArgumentDefinition.php
+++ b/generator/src/Definition/ArgumentDefinition.php
@@ -9,10 +9,12 @@
use function get_debug_type;
use function is_array;
use function is_string;
+use function ltrim;
use function sprintf;
final class ArgumentDefinition
{
+ public string $propertyName;
public VariadicType|null $variadic;
public int|null $variadicMin;
@@ -25,6 +27,7 @@ public function __construct(
string|null $variadic = null,
int|null $variadicMin = null,
public mixed $default = null,
+ public bool $mergeObject = false,
) {
assert($this->optional === false || $this->default === null, 'Optional arguments cannot have a default value');
if (is_array($type)) {
@@ -34,6 +37,8 @@ public function __construct(
}
}
+ $this->propertyName = ltrim($this->name, '$');
+
if ($variadic) {
$this->variadic = VariadicType::from($variadic);
if ($variadicMin === null) {
diff --git a/generator/src/Definition/OperatorDefinition.php b/generator/src/Definition/OperatorDefinition.php
index ce39fe4d7..5468b7917 100644
--- a/generator/src/Definition/OperatorDefinition.php
+++ b/generator/src/Definition/OperatorDefinition.php
@@ -32,6 +32,7 @@ public function __construct(
/** @var list */
public array $type,
public string|null $description = null,
+ public bool $wrapObject = true,
array $arguments = [],
array $tests = [],
) {
@@ -39,12 +40,13 @@ public function __construct(
'single' => Encode::Single,
'array' => Encode::Array,
'object' => Encode::Object,
- 'flat_object' => Encode::FlatObject,
- 'dollar_object' => Encode::DollarObject,
- 'group' => Encode::Group,
default => throw new UnexpectedValueException(sprintf('Unexpected "encode" value for operator "%s". Got "%s"', $name, $encode)),
};
+ if (! $wrapObject && $this->encode !== Encode::Object) {
+ throw new UnexpectedValueException(sprintf('Operator "%s" cannot have wrapObject set to false when encode is not "object"', $name));
+ }
+
// Convert arguments to ArgumentDefinition objects
// Optional arguments must be after required arguments
$requiredArgs = $optionalArgs = [];
diff --git a/generator/src/OperatorClassGenerator.php b/generator/src/OperatorClassGenerator.php
index 73fcf09bf..7f8667751 100644
--- a/generator/src/OperatorClassGenerator.php
+++ b/generator/src/OperatorClassGenerator.php
@@ -22,7 +22,6 @@
use function interface_exists;
use function rtrim;
use function sprintf;
-use function var_export;
/**
* Generates a value object class for stages and operators.
@@ -50,6 +49,7 @@ public function createClass(GeneratorDefinition $definition, OperatorDefinition
}
$class = $namespace->addClass($this->getOperatorClassName($definition, $operator));
+ $class->setFinal();
$class->setImplements($interfaces);
$namespace->addUse(OperatorInterface::class);
$class->addImplement(OperatorInterface::class);
@@ -58,30 +58,35 @@ public function createClass(GeneratorDefinition $definition, OperatorDefinition
// @todo move to encoder class
$class->addComment($operator->description);
$class->addComment('@see ' . $operator->link);
+ $class->addComment('@internal');
$namespace->addUse(Encode::class);
$class->addConstant('ENCODE', new Literal('Encode::' . $operator->encode->name));
+ $class->addConstant('NAME', $operator->wrapObject ? $operator->name : null);
- $constuctor = $class->addMethod('__construct');
+ $encodeNames = [];
+ $constructor = $class->addMethod('__construct');
foreach ($operator->arguments as $argument) {
+ $encodeNames[$argument->propertyName] = $argument->mergeObject ? null : $argument->name;
+
$type = $this->getAcceptedTypes($argument);
foreach ($type->use as $use) {
$namespace->addUse($use);
}
- $property = $class->addProperty($argument->name);
+ $property = $class->addProperty($argument->propertyName);
$property->setReadOnly();
- $constuctorParam = $constuctor->addParameter($argument->name);
- $constuctorParam->setType($type->native);
+ $constructorParam = $constructor->addParameter($argument->propertyName);
+ $constructorParam->setType($type->native);
if ($argument->variadic) {
- $constuctor->setVariadic();
- $constuctor->addComment('@param ' . $type->doc . ' ...$' . $argument->name . rtrim(' ' . $argument->description));
+ $constructor->setVariadic();
+ $constructor->addComment('@param ' . $type->doc . ' ...$' . $argument->propertyName . rtrim(' ' . $argument->description));
if ($argument->variadicMin > 0) {
$namespace->addUse(InvalidArgumentException::class);
- $constuctor->addBody(<<name}) < {$argument->variadicMin}) {
- throw new InvalidArgumentException(\sprintf('Expected at least %d values for \${$argument->name}, got %d.', {$argument->variadicMin}, \count(\${$argument->name})));
+ $constructor->addBody(<<propertyName}) < {$argument->variadicMin}) {
+ throw new InvalidArgumentException(\sprintf('Expected at least %d values for \${$argument->propertyName}, got %d.', {$argument->variadicMin}, \count(\${$argument->propertyName})));
}
PHP);
@@ -89,45 +94,45 @@ public function createClass(GeneratorDefinition $definition, OperatorDefinition
if ($argument->variadic === VariadicType::Array) {
$property->setType('array');
- $property->addComment('@var list<' . $type->doc . '> $' . $argument->name . rtrim(' ' . $argument->description));
+ $property->addComment('@var list<' . $type->doc . '> $' . $argument->propertyName . rtrim(' ' . $argument->description));
// Warn that named arguments are not supported
// @see https://psalm.dev/docs/running_psalm/issues/NamedArgumentNotAllowed/
- $constuctor->addComment('@no-named-arguments');
+ $constructor->addComment('@no-named-arguments');
$namespace->addUseFunction('array_is_list');
$namespace->addUse(InvalidArgumentException::class);
- $constuctor->addBody(<<name})) {
- throw new InvalidArgumentException('Expected \${$argument->name} arguments to be a list (array), named arguments are not supported');
+ $constructor->addBody(<<propertyName})) {
+ throw new InvalidArgumentException('Expected \${$argument->propertyName} arguments to be a list (array), named arguments are not supported');
}
PHP);
} elseif ($argument->variadic === VariadicType::Object) {
$namespace->addUse(stdClass::class);
$property->setType(stdClass::class);
- $property->addComment('@var stdClass<' . $type->doc . '> $' . $argument->name . rtrim(' ' . $argument->description));
+ $property->addComment('@var stdClass<' . $type->doc . '> $' . $argument->propertyName . rtrim(' ' . $argument->description));
$namespace->addUseFunction('is_string');
$namespace->addUse(InvalidArgumentException::class);
- $constuctor->addBody(<<name} as \$key => \$value) {
+ $constructor->addBody(<<propertyName} as \$key => \$value) {
if (! is_string(\$key)) {
- throw new InvalidArgumentException('Expected \${$argument->name} arguments to be a map (object), named arguments (:) or array unpacking ...[\'\' => ] must be used');
+ throw new InvalidArgumentException('Expected \${$argument->propertyName} arguments to be a map (object), named arguments (:) or array unpacking ...[\'\' => ] must be used');
}
}
- \${$argument->name} = (object) \${$argument->name};
+ \${$argument->propertyName} = (object) \${$argument->propertyName};
PHP);
}
} else {
// Non-variadic arguments
- $property->addComment('@var ' . $type->doc . ' $' . $argument->name . rtrim(' ' . $argument->description));
+ $property->addComment('@var ' . $type->doc . ' $' . $argument->propertyName . rtrim(' ' . $argument->description));
$property->setType($type->native);
- $constuctor->addComment('@param ' . $type->doc . ' $' . $argument->name . rtrim(' ' . $argument->description));
+ $constructor->addComment('@param ' . $type->doc . ' $' . $argument->propertyName . rtrim(' ' . $argument->description));
if ($argument->optional) {
// We use a special Optional::Undefined type to differentiate between null and undefined
- $constuctorParam->setDefaultValue(new Literal('Optional::Undefined'));
+ $constructorParam->setDefaultValue(new Literal('Optional::Undefined'));
} elseif ($argument->default !== null) {
- $constuctorParam->setDefaultValue($argument->default);
+ $constructorParam->setDefaultValue($argument->default);
}
// List type must be validated with array_is_list()
@@ -135,9 +140,9 @@ public function createClass(GeneratorDefinition $definition, OperatorDefinition
$namespace->addUseFunction('is_array');
$namespace->addUseFunction('array_is_list');
$namespace->addUse(InvalidArgumentException::class);
- $constuctor->addBody(<<name}) && ! array_is_list(\${$argument->name})) {
- throw new InvalidArgumentException('Expected \${$argument->name} argument to be a list, got an associative array.');
+ $constructor->addBody(<<propertyName}) && ! array_is_list(\${$argument->propertyName})) {
+ throw new InvalidArgumentException('Expected \${$argument->propertyName} argument to be a list, got an associative array.');
}
PHP);
@@ -146,9 +151,9 @@ public function createClass(GeneratorDefinition $definition, OperatorDefinition
if ($type->query) {
$namespace->addUseFunction('is_array');
$namespace->addUse(QueryObject::class);
- $constuctor->addBody(<<name})) {
- \${$argument->name} = QueryObject::create(\${$argument->name});
+ $constructor->addBody(<<propertyName})) {
+ \${$argument->propertyName} = QueryObject::create(\${$argument->propertyName});
}
PHP);
@@ -157,9 +162,9 @@ public function createClass(GeneratorDefinition $definition, OperatorDefinition
if ($type->javascript) {
$namespace->addUseFunction('is_string');
$namespace->addUse(Javascript::class);
- $constuctor->addBody(<<name})) {
- \${$argument->name} = new Javascript(\${$argument->name});
+ $constructor->addBody(<<propertyName})) {
+ \${$argument->propertyName} = new Javascript(\${$argument->propertyName});
}
PHP);
@@ -167,12 +172,12 @@ public function createClass(GeneratorDefinition $definition, OperatorDefinition
}
// Set property from constructor argument
- $constuctor->addBody('$this->' . $argument->name . ' = $' . $argument->name . ';');
+ $constructor->addBody('$this->' . $argument->propertyName . ' = $' . $argument->propertyName . ';');
}
- $class->addMethod('getOperator')
- ->setReturnType('string')
- ->setBody('return ' . var_export($operator->name, true) . ';');
+ if ($encodeNames !== []) {
+ $class->addConstant('PROPERTIES', $encodeNames);
+ }
return $namespace;
}
diff --git a/generator/src/OperatorFactoryGenerator.php b/generator/src/OperatorFactoryGenerator.php
index 0bc27620f..e60804ad8 100644
--- a/generator/src/OperatorFactoryGenerator.php
+++ b/generator/src/OperatorFactoryGenerator.php
@@ -65,7 +65,7 @@ private function addMethod(GeneratorDefinition $definition, OperatorDefinition $
$namespace->addUse($use);
}
- $parameter = $method->addParameter($argument->name);
+ $parameter = $method->addParameter($argument->propertyName);
$parameter->setType($type->native);
if ($argument->variadic) {
if ($argument->variadic === VariadicType::Array) {
@@ -75,8 +75,8 @@ private function addMethod(GeneratorDefinition $definition, OperatorDefinition $
}
$method->setVariadic();
- $method->addComment('@param ' . $type->doc . ' ...$' . $argument->name . rtrim(' ' . $argument->description));
- $args[] = '...$' . $argument->name;
+ $method->addComment('@param ' . $type->doc . ' ...$' . $argument->propertyName . rtrim(' ' . $argument->description));
+ $args[] = '...$' . $argument->propertyName;
} else {
if ($argument->optional) {
$parameter->setDefaultValue(new Literal('Optional::Undefined'));
@@ -84,8 +84,8 @@ private function addMethod(GeneratorDefinition $definition, OperatorDefinition $
$parameter->setDefaultValue($argument->default);
}
- $method->addComment('@param ' . $type->doc . ' $' . $argument->name . rtrim(' ' . $argument->description));
- $args[] = '$' . $argument->name;
+ $method->addComment('@param ' . $type->doc . ' $' . $argument->propertyName . rtrim(' ' . $argument->description));
+ $args[] = '$' . $argument->propertyName;
}
}
diff --git a/generator/src/OperatorTestGenerator.php b/generator/src/OperatorTestGenerator.php
index a8e6e91cc..f665b9210 100644
--- a/generator/src/OperatorTestGenerator.php
+++ b/generator/src/OperatorTestGenerator.php
@@ -10,6 +10,7 @@
use MongoDB\BSON\Decimal128;
use MongoDB\BSON\Document;
use MongoDB\BSON\Int64;
+use MongoDB\BSON\ObjectId;
use MongoDB\BSON\Regex;
use MongoDB\BSON\UTCDateTime;
use MongoDB\Builder\Pipeline;
@@ -27,6 +28,7 @@
use function base64_decode;
use function basename;
use function get_object_vars;
+use function hex2bin;
use function is_array;
use function is_numeric;
use function is_object;
@@ -145,6 +147,8 @@ private function convertYamlTaggedValues(mixed $object): mixed
'bson_decimal128' => new Decimal128($value),
'bson_utcdatetime' => new UTCDateTime(is_numeric($value) ? $value : new DateTimeImmutable($value)),
'bson_binary' => new Binary(base64_decode($value)),
+ 'bson_objectId' => new ObjectId($value),
+ 'bson_uuid' => new Binary(hex2bin(str_replace('-', '', $value)), Binary::TYPE_UUID),
default => throw new InvalidArgumentException(sprintf('Yaml tag "%s" is not supported.', $object->getTag())),
};
}
@@ -158,6 +162,7 @@ private function convertYamlTaggedValues(mixed $object): mixed
}
if (is_object($object)) {
+ $object = clone $object;
foreach (get_object_vars($object) as $key => $value) {
$object->{$key} = $this->convertYamlTaggedValues($value);
}
diff --git a/phpcs.xml.dist b/phpcs.xml.dist
index 3c2b9441b..fe0dc3819 100644
--- a/phpcs.xml.dist
+++ b/phpcs.xml.dist
@@ -19,7 +19,7 @@
rector.php
- src/Builder/(Accumulator|Expression|Query|Projection|Stage)/*\.php
+ src/Builder/(Accumulator|Expression|Query|Projection|Search|Stage)/*\.php
@@ -152,4 +152,7 @@
/tests/SpecTests/*/Prose*
+
+ src/Builder/Type/OperatorInterface.php
+
diff --git a/psalm-baseline.xml b/psalm-baseline.xml
index 6521b8544..ce07a15c6 100644
--- a/psalm-baseline.xml
+++ b/psalm-baseline.xml
@@ -60,14 +60,23 @@
+
+
+
+
+
+
+
-
-
+
+
+
+
@@ -89,11 +98,6 @@
-
-
-
-
-
@@ -167,7 +171,31 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -178,6 +206,11 @@
is_array($queriesOrArrayOfQueries[0]) &&
count($queriesOrArrayOfQueries[0]) > 0]]>
+
+
+
+
+
diff --git a/src/Builder/Accumulator/AccumulatorAccumulator.php b/src/Builder/Accumulator/AccumulatorAccumulator.php
index a12b57c7c..a49390fd6 100644
--- a/src/Builder/Accumulator/AccumulatorAccumulator.php
+++ b/src/Builder/Accumulator/AccumulatorAccumulator.php
@@ -27,10 +27,22 @@
* New in MongoDB 4.4.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/accumulator/
+ * @internal
*/
-class AccumulatorAccumulator implements AccumulatorInterface, OperatorInterface
+final class AccumulatorAccumulator implements AccumulatorInterface, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$accumulator';
+
+ public const PROPERTIES = [
+ 'init' => 'init',
+ 'accumulate' => 'accumulate',
+ 'accumulateArgs' => 'accumulateArgs',
+ 'merge' => 'merge',
+ 'lang' => 'lang',
+ 'initArgs' => 'initArgs',
+ 'finalize' => 'finalize',
+ ];
/** @var Javascript|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. */
public readonly Javascript|string $init;
@@ -103,9 +115,4 @@ public function __construct(
$this->finalize = $finalize;
}
-
- public function getOperator(): string
- {
- return '$accumulator';
- }
}
diff --git a/src/Builder/Accumulator/AddToSetAccumulator.php b/src/Builder/Accumulator/AddToSetAccumulator.php
index 08bda8cea..2c77a7458 100644
--- a/src/Builder/Accumulator/AddToSetAccumulator.php
+++ b/src/Builder/Accumulator/AddToSetAccumulator.php
@@ -21,10 +21,13 @@
* Changed in MongoDB 5.0: Available in the $setWindowFields stage.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/addToSet/
+ * @internal
*/
-class AddToSetAccumulator implements AccumulatorInterface, WindowInterface, OperatorInterface
+final class AddToSetAccumulator implements AccumulatorInterface, WindowInterface, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$addToSet';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */
public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression;
@@ -36,9 +39,4 @@ public function __construct(Type|ExpressionInterface|stdClass|array|bool|float|i
{
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$addToSet';
- }
}
diff --git a/src/Builder/Accumulator/AvgAccumulator.php b/src/Builder/Accumulator/AvgAccumulator.php
index da0b7730a..4b9050117 100644
--- a/src/Builder/Accumulator/AvgAccumulator.php
+++ b/src/Builder/Accumulator/AvgAccumulator.php
@@ -21,10 +21,13 @@
* Changed in MongoDB 5.0: Available in the $setWindowFields stage.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/avg/
+ * @internal
*/
-class AvgAccumulator implements AccumulatorInterface, WindowInterface, OperatorInterface
+final class AvgAccumulator implements AccumulatorInterface, WindowInterface, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$avg';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var Decimal128|Int64|ResolvesToNumber|float|int $expression */
public readonly Decimal128|Int64|ResolvesToNumber|float|int $expression;
@@ -36,9 +39,4 @@ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int $express
{
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$avg';
- }
}
diff --git a/src/Builder/Accumulator/BottomAccumulator.php b/src/Builder/Accumulator/BottomAccumulator.php
index c8408bafc..eecf0a013 100644
--- a/src/Builder/Accumulator/BottomAccumulator.php
+++ b/src/Builder/Accumulator/BottomAccumulator.php
@@ -23,10 +23,13 @@
* New in MongoDB 5.2: Available in the $group and $setWindowFields stages.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/bottom/
+ * @internal
*/
-class BottomAccumulator implements AccumulatorInterface, WindowInterface, OperatorInterface
+final class BottomAccumulator implements AccumulatorInterface, WindowInterface, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$bottom';
+ public const PROPERTIES = ['sortBy' => 'sortBy', 'output' => 'output'];
/** @var Document|Serializable|array|stdClass $sortBy Specifies the order of results, with syntax similar to $sort. */
public readonly Document|Serializable|stdClass|array $sortBy;
@@ -45,9 +48,4 @@ public function __construct(
$this->sortBy = $sortBy;
$this->output = $output;
}
-
- public function getOperator(): string
- {
- return '$bottom';
- }
}
diff --git a/src/Builder/Accumulator/BottomNAccumulator.php b/src/Builder/Accumulator/BottomNAccumulator.php
index 47e51852a..94911d25e 100644
--- a/src/Builder/Accumulator/BottomNAccumulator.php
+++ b/src/Builder/Accumulator/BottomNAccumulator.php
@@ -25,10 +25,13 @@
* Available in the $group and $setWindowFields stages.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/bottomN/
+ * @internal
*/
-class BottomNAccumulator implements AccumulatorInterface, WindowInterface, OperatorInterface
+final class BottomNAccumulator implements AccumulatorInterface, WindowInterface, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$bottomN';
+ public const PROPERTIES = ['n' => 'n', 'sortBy' => 'sortBy', 'output' => 'output'];
/** @var 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 readonly ResolvesToInt|int $n;
@@ -53,9 +56,4 @@ public function __construct(
$this->sortBy = $sortBy;
$this->output = $output;
}
-
- public function getOperator(): string
- {
- return '$bottomN';
- }
}
diff --git a/src/Builder/Accumulator/CountAccumulator.php b/src/Builder/Accumulator/CountAccumulator.php
index 384996417..933d86c6d 100644
--- a/src/Builder/Accumulator/CountAccumulator.php
+++ b/src/Builder/Accumulator/CountAccumulator.php
@@ -19,17 +19,14 @@
* New in MongoDB 5.0.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/count-accumulator/
+ * @internal
*/
-class CountAccumulator implements AccumulatorInterface, WindowInterface, OperatorInterface
+final class CountAccumulator implements AccumulatorInterface, WindowInterface, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$count';
public function __construct()
{
}
-
- public function getOperator(): string
- {
- return '$count';
- }
}
diff --git a/src/Builder/Accumulator/CovariancePopAccumulator.php b/src/Builder/Accumulator/CovariancePopAccumulator.php
index 459ed5c6e..d9bd9173e 100644
--- a/src/Builder/Accumulator/CovariancePopAccumulator.php
+++ b/src/Builder/Accumulator/CovariancePopAccumulator.php
@@ -20,10 +20,13 @@
* New in MongoDB 5.0.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/covariancePop/
+ * @internal
*/
-class CovariancePopAccumulator implements WindowInterface, OperatorInterface
+final class CovariancePopAccumulator implements WindowInterface, OperatorInterface
{
public const ENCODE = Encode::Array;
+ public const NAME = '$covariancePop';
+ public const PROPERTIES = ['expression1' => 'expression1', 'expression2' => 'expression2'];
/** @var Decimal128|Int64|ResolvesToNumber|float|int $expression1 */
public readonly Decimal128|Int64|ResolvesToNumber|float|int $expression1;
@@ -42,9 +45,4 @@ public function __construct(
$this->expression1 = $expression1;
$this->expression2 = $expression2;
}
-
- public function getOperator(): string
- {
- return '$covariancePop';
- }
}
diff --git a/src/Builder/Accumulator/CovarianceSampAccumulator.php b/src/Builder/Accumulator/CovarianceSampAccumulator.php
index 1266b263e..85ba2cf28 100644
--- a/src/Builder/Accumulator/CovarianceSampAccumulator.php
+++ b/src/Builder/Accumulator/CovarianceSampAccumulator.php
@@ -20,10 +20,13 @@
* New in MongoDB 5.0.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/covarianceSamp/
+ * @internal
*/
-class CovarianceSampAccumulator implements WindowInterface, OperatorInterface
+final class CovarianceSampAccumulator implements WindowInterface, OperatorInterface
{
public const ENCODE = Encode::Array;
+ public const NAME = '$covarianceSamp';
+ public const PROPERTIES = ['expression1' => 'expression1', 'expression2' => 'expression2'];
/** @var Decimal128|Int64|ResolvesToNumber|float|int $expression1 */
public readonly Decimal128|Int64|ResolvesToNumber|float|int $expression1;
@@ -42,9 +45,4 @@ public function __construct(
$this->expression1 = $expression1;
$this->expression2 = $expression2;
}
-
- public function getOperator(): string
- {
- return '$covarianceSamp';
- }
}
diff --git a/src/Builder/Accumulator/DenseRankAccumulator.php b/src/Builder/Accumulator/DenseRankAccumulator.php
index 7dea1de67..c5bc4bee9 100644
--- a/src/Builder/Accumulator/DenseRankAccumulator.php
+++ b/src/Builder/Accumulator/DenseRankAccumulator.php
@@ -17,17 +17,14 @@
* New in MongoDB 5.0.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/denseRank/
+ * @internal
*/
-class DenseRankAccumulator implements WindowInterface, OperatorInterface
+final class DenseRankAccumulator implements WindowInterface, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$denseRank';
public function __construct()
{
}
-
- public function getOperator(): string
- {
- return '$denseRank';
- }
}
diff --git a/src/Builder/Accumulator/DerivativeAccumulator.php b/src/Builder/Accumulator/DerivativeAccumulator.php
index 8010050d9..9ede80357 100644
--- a/src/Builder/Accumulator/DerivativeAccumulator.php
+++ b/src/Builder/Accumulator/DerivativeAccumulator.php
@@ -25,10 +25,13 @@
* New in MongoDB 5.0.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/derivative/
+ * @internal
*/
-class DerivativeAccumulator implements WindowInterface, OperatorInterface
+final class DerivativeAccumulator implements WindowInterface, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$derivative';
+ public const PROPERTIES = ['input' => 'input', 'unit' => 'unit'];
/** @var Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int $input */
public readonly Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int $input;
@@ -51,9 +54,4 @@ public function __construct(
$this->input = $input;
$this->unit = $unit;
}
-
- public function getOperator(): string
- {
- return '$derivative';
- }
}
diff --git a/src/Builder/Accumulator/DocumentNumberAccumulator.php b/src/Builder/Accumulator/DocumentNumberAccumulator.php
index 4318dbd81..a44f63475 100644
--- a/src/Builder/Accumulator/DocumentNumberAccumulator.php
+++ b/src/Builder/Accumulator/DocumentNumberAccumulator.php
@@ -17,17 +17,14 @@
* New in MongoDB 5.0.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/documentNumber/
+ * @internal
*/
-class DocumentNumberAccumulator implements WindowInterface, OperatorInterface
+final class DocumentNumberAccumulator implements WindowInterface, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$documentNumber';
public function __construct()
{
}
-
- public function getOperator(): string
- {
- return '$documentNumber';
- }
}
diff --git a/src/Builder/Accumulator/ExpMovingAvgAccumulator.php b/src/Builder/Accumulator/ExpMovingAvgAccumulator.php
index af12c817e..2bfe285f8 100644
--- a/src/Builder/Accumulator/ExpMovingAvgAccumulator.php
+++ b/src/Builder/Accumulator/ExpMovingAvgAccumulator.php
@@ -21,10 +21,13 @@
* New in MongoDB 5.0.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/expMovingAvg/
+ * @internal
*/
-class ExpMovingAvgAccumulator implements WindowInterface, OperatorInterface
+final class ExpMovingAvgAccumulator implements WindowInterface, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$expMovingAvg';
+ public const PROPERTIES = ['input' => 'input', 'N' => 'N', 'alpha' => 'alpha'];
/** @var Decimal128|Int64|ResolvesToNumber|float|int $input */
public readonly Decimal128|Int64|ResolvesToNumber|float|int $input;
@@ -59,9 +62,4 @@ public function __construct(
$this->N = $N;
$this->alpha = $alpha;
}
-
- public function getOperator(): string
- {
- return '$expMovingAvg';
- }
}
diff --git a/src/Builder/Accumulator/FirstAccumulator.php b/src/Builder/Accumulator/FirstAccumulator.php
index 559305d52..20e3b4ee2 100644
--- a/src/Builder/Accumulator/FirstAccumulator.php
+++ b/src/Builder/Accumulator/FirstAccumulator.php
@@ -21,10 +21,13 @@
* Changed in MongoDB 5.0: Available in the $setWindowFields stage.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/first/
+ * @internal
*/
-class FirstAccumulator implements AccumulatorInterface, WindowInterface, OperatorInterface
+final class FirstAccumulator implements AccumulatorInterface, WindowInterface, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$first';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */
public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression;
@@ -36,9 +39,4 @@ public function __construct(Type|ExpressionInterface|stdClass|array|bool|float|i
{
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$first';
- }
}
diff --git a/src/Builder/Accumulator/FirstNAccumulator.php b/src/Builder/Accumulator/FirstNAccumulator.php
index 0100f1aed..740ebc7ae 100644
--- a/src/Builder/Accumulator/FirstNAccumulator.php
+++ b/src/Builder/Accumulator/FirstNAccumulator.php
@@ -23,10 +23,13 @@
* If the group contains fewer than n elements, $firstN returns all elements in the group.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/firstN/
+ * @internal
*/
-class FirstNAccumulator implements AccumulatorInterface, WindowInterface, OperatorInterface
+final class FirstNAccumulator implements AccumulatorInterface, WindowInterface, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$firstN';
+ public const PROPERTIES = ['input' => 'input', 'n' => 'n'];
/** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $input An expression that resolves to the array from which to return n elements. */
public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $input;
@@ -45,9 +48,4 @@ public function __construct(
$this->input = $input;
$this->n = $n;
}
-
- public function getOperator(): string
- {
- return '$firstN';
- }
}
diff --git a/src/Builder/Accumulator/IntegralAccumulator.php b/src/Builder/Accumulator/IntegralAccumulator.php
index 5a5280ba2..be34f57a2 100644
--- a/src/Builder/Accumulator/IntegralAccumulator.php
+++ b/src/Builder/Accumulator/IntegralAccumulator.php
@@ -25,10 +25,13 @@
* New in MongoDB 5.0.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/integral/
+ * @internal
*/
-class IntegralAccumulator implements WindowInterface, OperatorInterface
+final class IntegralAccumulator implements WindowInterface, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$integral';
+ public const PROPERTIES = ['input' => 'input', 'unit' => 'unit'];
/** @var Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int $input */
public readonly Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int $input;
@@ -51,9 +54,4 @@ public function __construct(
$this->input = $input;
$this->unit = $unit;
}
-
- public function getOperator(): string
- {
- return '$integral';
- }
}
diff --git a/src/Builder/Accumulator/LastAccumulator.php b/src/Builder/Accumulator/LastAccumulator.php
index ab01fecdb..dd495538a 100644
--- a/src/Builder/Accumulator/LastAccumulator.php
+++ b/src/Builder/Accumulator/LastAccumulator.php
@@ -21,10 +21,13 @@
* Changed in MongoDB 5.0: Available in the $setWindowFields stage.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/last/
+ * @internal
*/
-class LastAccumulator implements AccumulatorInterface, WindowInterface, OperatorInterface
+final class LastAccumulator implements AccumulatorInterface, WindowInterface, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$last';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */
public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression;
@@ -36,9 +39,4 @@ public function __construct(Type|ExpressionInterface|stdClass|array|bool|float|i
{
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$last';
- }
}
diff --git a/src/Builder/Accumulator/LastNAccumulator.php b/src/Builder/Accumulator/LastNAccumulator.php
index d0752f58d..c0ddbd9bb 100644
--- a/src/Builder/Accumulator/LastNAccumulator.php
+++ b/src/Builder/Accumulator/LastNAccumulator.php
@@ -27,10 +27,13 @@
* If the group contains fewer than n elements, $lastN returns all elements in the group.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/lastN/
+ * @internal
*/
-class LastNAccumulator implements AccumulatorInterface, WindowInterface, OperatorInterface
+final class LastNAccumulator implements AccumulatorInterface, WindowInterface, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$lastN';
+ public const PROPERTIES = ['input' => 'input', 'n' => 'n'];
/** @var BSONArray|PackedArray|ResolvesToArray|array $input An expression that resolves to the array from which to return n elements. */
public readonly PackedArray|ResolvesToArray|BSONArray|array $input;
@@ -51,9 +54,4 @@ public function __construct(PackedArray|ResolvesToArray|BSONArray|array $input,
$this->input = $input;
$this->n = $n;
}
-
- public function getOperator(): string
- {
- return '$lastN';
- }
}
diff --git a/src/Builder/Accumulator/LinearFillAccumulator.php b/src/Builder/Accumulator/LinearFillAccumulator.php
index e203f7ff9..59aade4a1 100644
--- a/src/Builder/Accumulator/LinearFillAccumulator.php
+++ b/src/Builder/Accumulator/LinearFillAccumulator.php
@@ -21,10 +21,13 @@
* New in MongoDB 5.3.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/linearFill/
+ * @internal
*/
-class LinearFillAccumulator implements WindowInterface, OperatorInterface
+final class LinearFillAccumulator implements WindowInterface, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$linearFill';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var Decimal128|Int64|ResolvesToNumber|float|int $expression */
public readonly Decimal128|Int64|ResolvesToNumber|float|int $expression;
@@ -36,9 +39,4 @@ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int $express
{
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$linearFill';
- }
}
diff --git a/src/Builder/Accumulator/LocfAccumulator.php b/src/Builder/Accumulator/LocfAccumulator.php
index e133cc4c9..15ee21740 100644
--- a/src/Builder/Accumulator/LocfAccumulator.php
+++ b/src/Builder/Accumulator/LocfAccumulator.php
@@ -21,10 +21,13 @@
* New in MongoDB 5.2.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/locf/
+ * @internal
*/
-class LocfAccumulator implements WindowInterface, OperatorInterface
+final class LocfAccumulator implements WindowInterface, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$locf';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */
public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression;
@@ -36,9 +39,4 @@ public function __construct(Type|ExpressionInterface|stdClass|array|bool|float|i
{
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$locf';
- }
}
diff --git a/src/Builder/Accumulator/MaxAccumulator.php b/src/Builder/Accumulator/MaxAccumulator.php
index 0258eb82b..cf53cb8cd 100644
--- a/src/Builder/Accumulator/MaxAccumulator.php
+++ b/src/Builder/Accumulator/MaxAccumulator.php
@@ -21,10 +21,13 @@
* Changed in MongoDB 5.0: Available in the $setWindowFields stage.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/max/
+ * @internal
*/
-class MaxAccumulator implements AccumulatorInterface, WindowInterface, OperatorInterface
+final class MaxAccumulator implements AccumulatorInterface, WindowInterface, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$max';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */
public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression;
@@ -36,9 +39,4 @@ public function __construct(Type|ExpressionInterface|stdClass|array|bool|float|i
{
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$max';
- }
}
diff --git a/src/Builder/Accumulator/MaxNAccumulator.php b/src/Builder/Accumulator/MaxNAccumulator.php
index c952eedfa..04530f24e 100644
--- a/src/Builder/Accumulator/MaxNAccumulator.php
+++ b/src/Builder/Accumulator/MaxNAccumulator.php
@@ -25,10 +25,13 @@
* Returns the n largest values in an array. Distinct from the $maxN accumulator.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/maxN/
+ * @internal
*/
-class MaxNAccumulator implements AccumulatorInterface, WindowInterface, OperatorInterface
+final class MaxNAccumulator implements AccumulatorInterface, WindowInterface, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$maxN';
+ public const PROPERTIES = ['input' => 'input', 'n' => 'n'];
/** @var BSONArray|PackedArray|ResolvesToArray|array $input An expression that resolves to the array from which to return the maximal n elements. */
public readonly PackedArray|ResolvesToArray|BSONArray|array $input;
@@ -49,9 +52,4 @@ public function __construct(PackedArray|ResolvesToArray|BSONArray|array $input,
$this->input = $input;
$this->n = $n;
}
-
- public function getOperator(): string
- {
- return '$maxN';
- }
}
diff --git a/src/Builder/Accumulator/MedianAccumulator.php b/src/Builder/Accumulator/MedianAccumulator.php
index a81070700..358be201b 100644
--- a/src/Builder/Accumulator/MedianAccumulator.php
+++ b/src/Builder/Accumulator/MedianAccumulator.php
@@ -25,10 +25,13 @@
* It is also available as an aggregation expression.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/median/
+ * @internal
*/
-class MedianAccumulator implements AccumulatorInterface, WindowInterface, OperatorInterface
+final class MedianAccumulator implements AccumulatorInterface, WindowInterface, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$median';
+ public const PROPERTIES = ['input' => 'input', 'method' => 'method'];
/** @var 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 readonly Decimal128|Int64|ResolvesToNumber|float|int $input;
@@ -45,9 +48,4 @@ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int $input,
$this->input = $input;
$this->method = $method;
}
-
- public function getOperator(): string
- {
- return '$median';
- }
}
diff --git a/src/Builder/Accumulator/MergeObjectsAccumulator.php b/src/Builder/Accumulator/MergeObjectsAccumulator.php
index 7f163e023..87a8e6a00 100644
--- a/src/Builder/Accumulator/MergeObjectsAccumulator.php
+++ b/src/Builder/Accumulator/MergeObjectsAccumulator.php
@@ -20,10 +20,13 @@
* Combines multiple documents into a single document.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/mergeObjects/
+ * @internal
*/
-class MergeObjectsAccumulator implements AccumulatorInterface, OperatorInterface
+final class MergeObjectsAccumulator implements AccumulatorInterface, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$mergeObjects';
+ public const PROPERTIES = ['document' => 'document'];
/** @var Document|ResolvesToObject|Serializable|array|stdClass $document Any valid expression that resolves to a document. */
public readonly Document|Serializable|ResolvesToObject|stdClass|array $document;
@@ -35,9 +38,4 @@ public function __construct(Document|Serializable|ResolvesToObject|stdClass|arra
{
$this->document = $document;
}
-
- public function getOperator(): string
- {
- return '$mergeObjects';
- }
}
diff --git a/src/Builder/Accumulator/MinAccumulator.php b/src/Builder/Accumulator/MinAccumulator.php
index 9194c8866..b90ef761b 100644
--- a/src/Builder/Accumulator/MinAccumulator.php
+++ b/src/Builder/Accumulator/MinAccumulator.php
@@ -21,10 +21,13 @@
* Changed in MongoDB 5.0: Available in the $setWindowFields stage.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/min/
+ * @internal
*/
-class MinAccumulator implements AccumulatorInterface, WindowInterface, OperatorInterface
+final class MinAccumulator implements AccumulatorInterface, WindowInterface, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$min';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */
public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression;
@@ -36,9 +39,4 @@ public function __construct(Type|ExpressionInterface|stdClass|array|bool|float|i
{
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$min';
- }
}
diff --git a/src/Builder/Accumulator/MinNAccumulator.php b/src/Builder/Accumulator/MinNAccumulator.php
index dab804cc5..7a7dbcb37 100644
--- a/src/Builder/Accumulator/MinNAccumulator.php
+++ b/src/Builder/Accumulator/MinNAccumulator.php
@@ -25,10 +25,13 @@
* Returns the n smallest values in an array. Distinct from the $minN accumulator.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/minN/
+ * @internal
*/
-class MinNAccumulator implements AccumulatorInterface, WindowInterface, OperatorInterface
+final class MinNAccumulator implements AccumulatorInterface, WindowInterface, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$minN';
+ public const PROPERTIES = ['input' => 'input', 'n' => 'n'];
/** @var BSONArray|PackedArray|ResolvesToArray|array $input An expression that resolves to the array from which to return the maximal n elements. */
public readonly PackedArray|ResolvesToArray|BSONArray|array $input;
@@ -49,9 +52,4 @@ public function __construct(PackedArray|ResolvesToArray|BSONArray|array $input,
$this->input = $input;
$this->n = $n;
}
-
- public function getOperator(): string
- {
- return '$minN';
- }
}
diff --git a/src/Builder/Accumulator/PercentileAccumulator.php b/src/Builder/Accumulator/PercentileAccumulator.php
index 85128f024..3766d8f1d 100644
--- a/src/Builder/Accumulator/PercentileAccumulator.php
+++ b/src/Builder/Accumulator/PercentileAccumulator.php
@@ -35,10 +35,13 @@
* It is also available as an aggregation expression.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/percentile/
+ * @internal
*/
-class PercentileAccumulator implements AccumulatorInterface, WindowInterface, OperatorInterface
+final class PercentileAccumulator implements AccumulatorInterface, WindowInterface, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$percentile';
+ public const PROPERTIES = ['input' => 'input', 'p' => 'p', 'method' => 'method'];
/** @var 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 readonly Decimal128|Int64|ResolvesToNumber|float|int $input;
@@ -71,9 +74,4 @@ public function __construct(
$this->p = $p;
$this->method = $method;
}
-
- public function getOperator(): string
- {
- return '$percentile';
- }
}
diff --git a/src/Builder/Accumulator/PushAccumulator.php b/src/Builder/Accumulator/PushAccumulator.php
index 3eb095670..8f04023a9 100644
--- a/src/Builder/Accumulator/PushAccumulator.php
+++ b/src/Builder/Accumulator/PushAccumulator.php
@@ -21,10 +21,13 @@
* Changed in MongoDB 5.0: Available in the $setWindowFields stage.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/push/
+ * @internal
*/
-class PushAccumulator implements AccumulatorInterface, WindowInterface, OperatorInterface
+final class PushAccumulator implements AccumulatorInterface, WindowInterface, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$push';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */
public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression;
@@ -36,9 +39,4 @@ public function __construct(Type|ExpressionInterface|stdClass|array|bool|float|i
{
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$push';
- }
}
diff --git a/src/Builder/Accumulator/RankAccumulator.php b/src/Builder/Accumulator/RankAccumulator.php
index dd274dceb..ddf2f665c 100644
--- a/src/Builder/Accumulator/RankAccumulator.php
+++ b/src/Builder/Accumulator/RankAccumulator.php
@@ -17,17 +17,14 @@
* New in MongoDB 5.0.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/rank/
+ * @internal
*/
-class RankAccumulator implements WindowInterface, OperatorInterface
+final class RankAccumulator implements WindowInterface, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$rank';
public function __construct()
{
}
-
- public function getOperator(): string
- {
- return '$rank';
- }
}
diff --git a/src/Builder/Accumulator/ShiftAccumulator.php b/src/Builder/Accumulator/ShiftAccumulator.php
index c8533c140..5f4200307 100644
--- a/src/Builder/Accumulator/ShiftAccumulator.php
+++ b/src/Builder/Accumulator/ShiftAccumulator.php
@@ -20,10 +20,13 @@
* New in MongoDB 5.0.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/shift/
+ * @internal
*/
-class ShiftAccumulator implements WindowInterface, OperatorInterface
+final class ShiftAccumulator implements WindowInterface, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$shift';
+ public const PROPERTIES = ['output' => 'output', 'by' => 'by', 'default' => 'default'];
/** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $output Specifies an expression to evaluate and return in the output. */
public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $output;
@@ -64,9 +67,4 @@ public function __construct(
$this->by = $by;
$this->default = $default;
}
-
- public function getOperator(): string
- {
- return '$shift';
- }
}
diff --git a/src/Builder/Accumulator/StdDevPopAccumulator.php b/src/Builder/Accumulator/StdDevPopAccumulator.php
index 01fe39dff..efa166707 100644
--- a/src/Builder/Accumulator/StdDevPopAccumulator.php
+++ b/src/Builder/Accumulator/StdDevPopAccumulator.php
@@ -22,10 +22,13 @@
* Changed in MongoDB 5.0: Available in the $setWindowFields stage.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/stdDevPop/
+ * @internal
*/
-class StdDevPopAccumulator implements AccumulatorInterface, WindowInterface, OperatorInterface
+final class StdDevPopAccumulator implements AccumulatorInterface, WindowInterface, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$stdDevPop';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var Decimal128|Int64|ResolvesToNumber|float|int $expression */
public readonly Decimal128|Int64|ResolvesToNumber|float|int $expression;
@@ -37,9 +40,4 @@ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int $express
{
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$stdDevPop';
- }
}
diff --git a/src/Builder/Accumulator/StdDevSampAccumulator.php b/src/Builder/Accumulator/StdDevSampAccumulator.php
index 54adb4170..d02f9e485 100644
--- a/src/Builder/Accumulator/StdDevSampAccumulator.php
+++ b/src/Builder/Accumulator/StdDevSampAccumulator.php
@@ -22,10 +22,13 @@
* Changed in MongoDB 5.0: Available in the $setWindowFields stage.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/stdDevSamp/
+ * @internal
*/
-class StdDevSampAccumulator implements AccumulatorInterface, WindowInterface, OperatorInterface
+final class StdDevSampAccumulator implements AccumulatorInterface, WindowInterface, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$stdDevSamp';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var Decimal128|Int64|ResolvesToNumber|float|int $expression */
public readonly Decimal128|Int64|ResolvesToNumber|float|int $expression;
@@ -37,9 +40,4 @@ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int $express
{
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$stdDevSamp';
- }
}
diff --git a/src/Builder/Accumulator/SumAccumulator.php b/src/Builder/Accumulator/SumAccumulator.php
index faf0ace44..172915e2c 100644
--- a/src/Builder/Accumulator/SumAccumulator.php
+++ b/src/Builder/Accumulator/SumAccumulator.php
@@ -21,10 +21,13 @@
* Changed in MongoDB 5.0: Available in the $setWindowFields stage.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/sum/
+ * @internal
*/
-class SumAccumulator implements AccumulatorInterface, WindowInterface, OperatorInterface
+final class SumAccumulator implements AccumulatorInterface, WindowInterface, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$sum';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var Decimal128|Int64|ResolvesToNumber|float|int $expression */
public readonly Decimal128|Int64|ResolvesToNumber|float|int $expression;
@@ -36,9 +39,4 @@ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int $express
{
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$sum';
- }
}
diff --git a/src/Builder/Accumulator/TopAccumulator.php b/src/Builder/Accumulator/TopAccumulator.php
index 135b8eb0a..7fac97efc 100644
--- a/src/Builder/Accumulator/TopAccumulator.php
+++ b/src/Builder/Accumulator/TopAccumulator.php
@@ -24,10 +24,13 @@
* Available in the $group and $setWindowFields stages.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/top/
+ * @internal
*/
-class TopAccumulator implements AccumulatorInterface, OperatorInterface
+final class TopAccumulator implements AccumulatorInterface, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$top';
+ public const PROPERTIES = ['sortBy' => 'sortBy', 'output' => 'output'];
/** @var Document|Serializable|array|stdClass $sortBy Specifies the order of results, with syntax similar to $sort. */
public readonly Document|Serializable|stdClass|array $sortBy;
@@ -46,9 +49,4 @@ public function __construct(
$this->sortBy = $sortBy;
$this->output = $output;
}
-
- public function getOperator(): string
- {
- return '$top';
- }
}
diff --git a/src/Builder/Accumulator/TopNAccumulator.php b/src/Builder/Accumulator/TopNAccumulator.php
index ab8009121..ea0ae9bc0 100644
--- a/src/Builder/Accumulator/TopNAccumulator.php
+++ b/src/Builder/Accumulator/TopNAccumulator.php
@@ -25,10 +25,13 @@
* Available in the $group and $setWindowFields stages.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/topN/
+ * @internal
*/
-class TopNAccumulator implements AccumulatorInterface, OperatorInterface
+final class TopNAccumulator implements AccumulatorInterface, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$topN';
+ public const PROPERTIES = ['n' => 'n', 'sortBy' => 'sortBy', 'output' => 'output'];
/** @var 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 readonly ResolvesToInt|int $n;
@@ -53,9 +56,4 @@ public function __construct(
$this->sortBy = $sortBy;
$this->output = $output;
}
-
- public function getOperator(): string
- {
- return '$topN';
- }
}
diff --git a/src/Builder/BuilderEncoder.php b/src/Builder/BuilderEncoder.php
index 8b25325ce..0d7a5a90c 100644
--- a/src/Builder/BuilderEncoder.php
+++ b/src/Builder/BuilderEncoder.php
@@ -32,7 +32,7 @@
use function is_object;
/** @template-implements Encoder */
-class BuilderEncoder implements Encoder
+final class BuilderEncoder implements Encoder
{
/** @template-use EncodeIfSupported */
use EncodeIfSupported;
diff --git a/src/Builder/Encoder/AbstractExpressionEncoder.php b/src/Builder/Encoder/AbstractExpressionEncoder.php
index 49d7a34f1..d593f4e3b 100644
--- a/src/Builder/Encoder/AbstractExpressionEncoder.php
+++ b/src/Builder/Encoder/AbstractExpressionEncoder.php
@@ -14,6 +14,7 @@
* @template BSONType of stdClass|array|string|int
* @template NativeType
* @template-implements ExpressionEncoder
+ * @internal
*/
abstract class AbstractExpressionEncoder implements ExpressionEncoder
{
diff --git a/src/Builder/Encoder/CombinedFieldQueryEncoder.php b/src/Builder/Encoder/CombinedFieldQueryEncoder.php
index 4ad42396b..b933953be 100644
--- a/src/Builder/Encoder/CombinedFieldQueryEncoder.php
+++ b/src/Builder/Encoder/CombinedFieldQueryEncoder.php
@@ -16,8 +16,11 @@
use function is_object;
use function sprintf;
-/** @template-extends AbstractExpressionEncoder */
-class CombinedFieldQueryEncoder extends AbstractExpressionEncoder
+/**
+ * @template-extends AbstractExpressionEncoder
+ * @internal
+ */
+final class CombinedFieldQueryEncoder extends AbstractExpressionEncoder
{
/** @template-use EncodeIfSupported */
use EncodeIfSupported;
diff --git a/src/Builder/Encoder/DictionaryEncoder.php b/src/Builder/Encoder/DictionaryEncoder.php
index 078db76ed..f228fa2d7 100644
--- a/src/Builder/Encoder/DictionaryEncoder.php
+++ b/src/Builder/Encoder/DictionaryEncoder.php
@@ -9,8 +9,11 @@
use MongoDB\Exception\UnsupportedValueException;
use stdClass;
-/** @template-extends AbstractExpressionEncoder */
-class DictionaryEncoder extends AbstractExpressionEncoder
+/**
+ * @template-extends AbstractExpressionEncoder
+ * @internal
+ */
+final class DictionaryEncoder extends AbstractExpressionEncoder
{
/** @template-use EncodeIfSupported */
use EncodeIfSupported;
diff --git a/src/Builder/Encoder/ExpressionEncoder.php b/src/Builder/Encoder/ExpressionEncoder.php
index 1fe94790e..b1acab2ee 100644
--- a/src/Builder/Encoder/ExpressionEncoder.php
+++ b/src/Builder/Encoder/ExpressionEncoder.php
@@ -12,6 +12,7 @@
* @template BSONType of stdClass|array|string|int
* @template NativeType
* @template-extends Encoder
+ * @internal
*/
interface ExpressionEncoder extends Encoder
{
diff --git a/src/Builder/Encoder/FieldPathEncoder.php b/src/Builder/Encoder/FieldPathEncoder.php
index 8fe7381c2..4dc7b6f2c 100644
--- a/src/Builder/Encoder/FieldPathEncoder.php
+++ b/src/Builder/Encoder/FieldPathEncoder.php
@@ -8,8 +8,11 @@
use MongoDB\Codec\EncodeIfSupported;
use MongoDB\Exception\UnsupportedValueException;
-/** @template-extends AbstractExpressionEncoder */
-class FieldPathEncoder extends AbstractExpressionEncoder
+/**
+ * @template-extends AbstractExpressionEncoder
+ * @internal
+ */
+final class FieldPathEncoder extends AbstractExpressionEncoder
{
/** @template-use EncodeIfSupported */
use EncodeIfSupported;
@@ -25,7 +28,6 @@ public function encode(mixed $value): string
throw UnsupportedValueException::invalidEncodableValue($value);
}
- // TODO: needs method because interfaces can't have properties
return '$' . $value->name;
}
}
diff --git a/src/Builder/Encoder/OperatorEncoder.php b/src/Builder/Encoder/OperatorEncoder.php
index 69ef27c24..5c18d7c0b 100644
--- a/src/Builder/Encoder/OperatorEncoder.php
+++ b/src/Builder/Encoder/OperatorEncoder.php
@@ -5,7 +5,6 @@
namespace MongoDB\Builder\Encoder;
use LogicException;
-use MongoDB\Builder\Stage\GroupStage;
use MongoDB\Builder\Type\Encode;
use MongoDB\Builder\Type\OperatorInterface;
use MongoDB\Builder\Type\Optional;
@@ -13,16 +12,15 @@
use MongoDB\Exception\UnsupportedValueException;
use stdClass;
-use function array_key_exists;
use function assert;
-use function get_object_vars;
-use function is_array;
-use function is_object;
-use function property_exists;
+use function is_string;
use function sprintf;
-/** @template-extends AbstractExpressionEncoder */
-class OperatorEncoder extends AbstractExpressionEncoder
+/**
+ * @template-extends AbstractExpressionEncoder
+ * @internal
+ */
+final class OperatorEncoder extends AbstractExpressionEncoder
{
/** @template-use EncodeIfSupported */
use EncodeIfSupported;
@@ -41,9 +39,7 @@ public function encode(mixed $value): stdClass
return match ($value::ENCODE) {
Encode::Single => $this->encodeAsSingle($value),
Encode::Array => $this->encodeAsArray($value),
- Encode::Object, Encode::FlatObject => $this->encodeAsObject($value),
- Encode::DollarObject => $this->encodeAsDollarObject($value),
- Encode::Group => $this->encodeAsGroup($value),
+ Encode::Object => $this->encodeAsObject($value),
default => throw new LogicException(sprintf('Class "%s" does not have a valid ENCODE constant.', $value::class)),
};
}
@@ -54,8 +50,8 @@ public function encode(mixed $value): stdClass
private function encodeAsArray(OperatorInterface $value): stdClass
{
$result = [];
- /** @var mixed $val */
- foreach (get_object_vars($value) as $val) {
+ foreach ($value::PROPERTIES as $prop => $name) {
+ $val = $value->$prop;
// Skip optional arguments. For example, the $slice expression operator has an optional argument
// in the middle of the array.
if ($val === Optional::Undefined) {
@@ -68,74 +64,47 @@ private function encodeAsArray(OperatorInterface $value): stdClass
return $this->wrap($value, $result);
}
- private function encodeAsDollarObject(OperatorInterface $value): stdClass
+ /**
+ * Encode the value as an object with properties. Property names are
+ * mapped by the PROPERTIES constant.
+ */
+ private function encodeAsObject(OperatorInterface $value): stdClass
{
$result = new stdClass();
- foreach (get_object_vars($value) as $key => $val) {
+ foreach ($value::PROPERTIES as $prop => $name) {
+ $val = $value->$prop;
+
// Skip optional arguments. If they have a default value, it is resolved by the server.
if ($val === Optional::Undefined) {
continue;
}
- $val = $this->recursiveEncode($val);
-
- if ($key === 'geometry') {
- if (is_object($val) && property_exists($val, '$geometry')) {
- $result->{'$geometry'} = $val->{'$geometry'};
- } elseif (is_array($val) && array_key_exists('$geometry', $val)) {
- $result->{'$geometry'} = $val['$geometry'];
- } else {
- $result->{'$geometry'} = $val;
+ // The name is null for arguments with "mergeObject: true" in the YAML file,
+ // the value properties are merged into the parent object.
+ if ($name === null) {
+ $val = $this->recursiveEncode($val);
+ foreach ($val as $k => $v) {
+ $result->{$k} = $v;
}
} else {
- $result->{'$' . $key} = $val;
+ $result->{$name} = $this->recursiveEncode($val);
}
}
- return $this->wrap($value, $result);
- }
-
- /**
- * $group stage have a specific encoding because the _id argument is required and others are variadic
- */
- private function encodeAsGroup(OperatorInterface $value): stdClass
- {
- assert($value instanceof GroupStage);
-
- $result = new stdClass();
- $result->_id = $this->recursiveEncode($value->_id);
-
- foreach (get_object_vars($value->field) as $key => $val) {
- $result->{$key} = $this->recursiveEncode($val);
+ if ($value::NAME === null) {
+ return $result;
}
return $this->wrap($value, $result);
}
- private function encodeAsObject(OperatorInterface $value): stdClass
- {
- $result = new stdClass();
- foreach (get_object_vars($value) as $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 $value::ENCODE === Encode::FlatObject
- ? $result
- : $this->wrap($value, $result);
- }
-
/**
* Get the unique property of the operator as value
*/
private function encodeAsSingle(OperatorInterface $value): stdClass
{
- foreach (get_object_vars($value) as $val) {
- $result = $this->recursiveEncode($val);
+ foreach ($value::PROPERTIES as $prop => $name) {
+ $result = $this->recursiveEncode($value->$prop);
return $this->wrap($value, $result);
}
@@ -145,8 +114,10 @@ private function encodeAsSingle(OperatorInterface $value): stdClass
private function wrap(OperatorInterface $value, mixed $result): stdClass
{
+ assert(is_string($value::NAME));
+
$object = new stdClass();
- $object->{$value->getOperator()} = $result;
+ $object->{$value::NAME} = $result;
return $object;
}
diff --git a/src/Builder/Encoder/OutputWindowEncoder.php b/src/Builder/Encoder/OutputWindowEncoder.php
index 9db567386..830c2cacb 100644
--- a/src/Builder/Encoder/OutputWindowEncoder.php
+++ b/src/Builder/Encoder/OutputWindowEncoder.php
@@ -17,8 +17,11 @@
use function MongoDB\is_first_key_operator;
use function sprintf;
-/** @template-extends AbstractExpressionEncoder */
-class OutputWindowEncoder extends AbstractExpressionEncoder
+/**
+ * @template-extends AbstractExpressionEncoder
+ * @internal
+ */
+final class OutputWindowEncoder extends AbstractExpressionEncoder
{
/** @template-use EncodeIfSupported */
use EncodeIfSupported;
diff --git a/src/Builder/Encoder/PipelineEncoder.php b/src/Builder/Encoder/PipelineEncoder.php
index f0b319e9c..5a343e0fb 100644
--- a/src/Builder/Encoder/PipelineEncoder.php
+++ b/src/Builder/Encoder/PipelineEncoder.php
@@ -8,8 +8,11 @@
use MongoDB\Codec\EncodeIfSupported;
use MongoDB\Exception\UnsupportedValueException;
-/** @template-extends AbstractExpressionEncoder, Pipeline> */
-class PipelineEncoder extends AbstractExpressionEncoder
+/**
+ * @template-extends AbstractExpressionEncoder, Pipeline>
+ * @internal
+ */
+final class PipelineEncoder extends AbstractExpressionEncoder
{
/** @template-use EncodeIfSupported, Pipeline> */
use EncodeIfSupported;
diff --git a/src/Builder/Encoder/QueryEncoder.php b/src/Builder/Encoder/QueryEncoder.php
index d5890506c..2193edb02 100644
--- a/src/Builder/Encoder/QueryEncoder.php
+++ b/src/Builder/Encoder/QueryEncoder.php
@@ -15,8 +15,11 @@
use function property_exists;
use function sprintf;
-/** @template-extends AbstractExpressionEncoder */
-class QueryEncoder extends AbstractExpressionEncoder
+/**
+ * @template-extends AbstractExpressionEncoder
+ * @internal
+ */
+final class QueryEncoder extends AbstractExpressionEncoder
{
/** @template-use EncodeIfSupported */
use EncodeIfSupported;
diff --git a/src/Builder/Encoder/VariableEncoder.php b/src/Builder/Encoder/VariableEncoder.php
index 726acb9ee..31f73b6d8 100644
--- a/src/Builder/Encoder/VariableEncoder.php
+++ b/src/Builder/Encoder/VariableEncoder.php
@@ -8,8 +8,11 @@
use MongoDB\Codec\EncodeIfSupported;
use MongoDB\Exception\UnsupportedValueException;
-/** @template-extends AbstractExpressionEncoder */
-class VariableEncoder extends AbstractExpressionEncoder
+/**
+ * @template-extends AbstractExpressionEncoder
+ * @internal
+ */
+final class VariableEncoder extends AbstractExpressionEncoder
{
/** @template-use EncodeIfSupported */
use EncodeIfSupported;
diff --git a/src/Builder/Expression/AbsOperator.php b/src/Builder/Expression/AbsOperator.php
index df28a0d3d..977a05a44 100644
--- a/src/Builder/Expression/AbsOperator.php
+++ b/src/Builder/Expression/AbsOperator.php
@@ -17,10 +17,13 @@
* Returns the absolute value of a number.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/abs/
+ * @internal
*/
-class AbsOperator implements ResolvesToNumber, OperatorInterface
+final class AbsOperator implements ResolvesToNumber, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$abs';
+ public const PROPERTIES = ['value' => 'value'];
/** @var Decimal128|Int64|ResolvesToNumber|float|int $value */
public readonly Decimal128|Int64|ResolvesToNumber|float|int $value;
@@ -32,9 +35,4 @@ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int $value)
{
$this->value = $value;
}
-
- public function getOperator(): string
- {
- return '$abs';
- }
}
diff --git a/src/Builder/Expression/AcosOperator.php b/src/Builder/Expression/AcosOperator.php
index 38a12b6c4..47ae210d3 100644
--- a/src/Builder/Expression/AcosOperator.php
+++ b/src/Builder/Expression/AcosOperator.php
@@ -17,10 +17,13 @@
* Returns the inverse cosine (arc cosine) of a value in radians.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/acos/
+ * @internal
*/
-class AcosOperator implements ResolvesToDouble, ResolvesToDecimal, OperatorInterface
+final class AcosOperator implements ResolvesToDouble, ResolvesToDecimal, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$acos';
+ public const PROPERTIES = ['expression' => 'expression'];
/**
* @var 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.
@@ -38,9 +41,4 @@ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int $express
{
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$acos';
- }
}
diff --git a/src/Builder/Expression/AcoshOperator.php b/src/Builder/Expression/AcoshOperator.php
index ba956df43..8be5bc4a7 100644
--- a/src/Builder/Expression/AcoshOperator.php
+++ b/src/Builder/Expression/AcoshOperator.php
@@ -17,10 +17,13 @@
* Returns the inverse hyperbolic cosine (hyperbolic arc cosine) of a value in radians.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/acosh/
+ * @internal
*/
-class AcoshOperator implements ResolvesToDouble, ResolvesToDecimal, OperatorInterface
+final class AcoshOperator implements ResolvesToDouble, ResolvesToDecimal, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$acosh';
+ public const PROPERTIES = ['expression' => 'expression'];
/**
* @var 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.
@@ -38,9 +41,4 @@ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int $express
{
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$acosh';
- }
}
diff --git a/src/Builder/Expression/AddOperator.php b/src/Builder/Expression/AddOperator.php
index 580731680..259e64b08 100644
--- a/src/Builder/Expression/AddOperator.php
+++ b/src/Builder/Expression/AddOperator.php
@@ -21,10 +21,13 @@
* 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/
+ * @internal
*/
-class AddOperator implements ResolvesToInt, ResolvesToLong, ResolvesToDouble, ResolvesToDecimal, ResolvesToDate, OperatorInterface
+final class AddOperator implements ResolvesToInt, ResolvesToLong, ResolvesToDouble, ResolvesToDecimal, ResolvesToDate, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$add';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var 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 readonly array $expression;
@@ -45,9 +48,4 @@ public function __construct(Decimal128|Int64|UTCDateTime|ResolvesToDate|Resolves
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$add';
- }
}
diff --git a/src/Builder/Expression/AllElementsTrueOperator.php b/src/Builder/Expression/AllElementsTrueOperator.php
index dbfebe75c..dbb74d967 100644
--- a/src/Builder/Expression/AllElementsTrueOperator.php
+++ b/src/Builder/Expression/AllElementsTrueOperator.php
@@ -21,10 +21,13 @@
* 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/
+ * @internal
*/
-class AllElementsTrueOperator implements ResolvesToBool, OperatorInterface
+final class AllElementsTrueOperator implements ResolvesToBool, OperatorInterface
{
public const ENCODE = Encode::Array;
+ public const NAME = '$allElementsTrue';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var BSONArray|PackedArray|ResolvesToArray|array $expression */
public readonly PackedArray|ResolvesToArray|BSONArray|array $expression;
@@ -40,9 +43,4 @@ public function __construct(PackedArray|ResolvesToArray|BSONArray|array $express
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$allElementsTrue';
- }
}
diff --git a/src/Builder/Expression/AndOperator.php b/src/Builder/Expression/AndOperator.php
index c4f3d7e6c..8e3364ab3 100644
--- a/src/Builder/Expression/AndOperator.php
+++ b/src/Builder/Expression/AndOperator.php
@@ -23,10 +23,13 @@
* 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/
+ * @internal
*/
-class AndOperator implements ResolvesToBool, OperatorInterface
+final class AndOperator implements ResolvesToBool, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$and';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var list $expression */
public readonly array $expression;
@@ -48,9 +51,4 @@ public function __construct(
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$and';
- }
}
diff --git a/src/Builder/Expression/AnyElementTrueOperator.php b/src/Builder/Expression/AnyElementTrueOperator.php
index 68cef3242..c8dd665b6 100644
--- a/src/Builder/Expression/AnyElementTrueOperator.php
+++ b/src/Builder/Expression/AnyElementTrueOperator.php
@@ -21,10 +21,13 @@
* 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/
+ * @internal
*/
-class AnyElementTrueOperator implements ResolvesToBool, OperatorInterface
+final class AnyElementTrueOperator implements ResolvesToBool, OperatorInterface
{
public const ENCODE = Encode::Array;
+ public const NAME = '$anyElementTrue';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var BSONArray|PackedArray|ResolvesToArray|array $expression */
public readonly PackedArray|ResolvesToArray|BSONArray|array $expression;
@@ -40,9 +43,4 @@ public function __construct(PackedArray|ResolvesToArray|BSONArray|array $express
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$anyElementTrue';
- }
}
diff --git a/src/Builder/Expression/ArrayElemAtOperator.php b/src/Builder/Expression/ArrayElemAtOperator.php
index e7fd09073..a5f333359 100644
--- a/src/Builder/Expression/ArrayElemAtOperator.php
+++ b/src/Builder/Expression/ArrayElemAtOperator.php
@@ -21,10 +21,13 @@
* Returns the element at the specified array index.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/arrayElemAt/
+ * @internal
*/
-class ArrayElemAtOperator implements ResolvesToAny, OperatorInterface
+final class ArrayElemAtOperator implements ResolvesToAny, OperatorInterface
{
public const ENCODE = Encode::Array;
+ public const NAME = '$arrayElemAt';
+ public const PROPERTIES = ['array' => 'array', 'idx' => 'idx'];
/** @var BSONArray|PackedArray|ResolvesToArray|array $array */
public readonly PackedArray|ResolvesToArray|BSONArray|array $array;
@@ -45,9 +48,4 @@ public function __construct(PackedArray|ResolvesToArray|BSONArray|array $array,
$this->array = $array;
$this->idx = $idx;
}
-
- public function getOperator(): string
- {
- return '$arrayElemAt';
- }
}
diff --git a/src/Builder/Expression/ArrayToObjectOperator.php b/src/Builder/Expression/ArrayToObjectOperator.php
index 4c6935875..657f67676 100644
--- a/src/Builder/Expression/ArrayToObjectOperator.php
+++ b/src/Builder/Expression/ArrayToObjectOperator.php
@@ -21,10 +21,13 @@
* Converts an array of key value pairs to a document.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/arrayToObject/
+ * @internal
*/
-class ArrayToObjectOperator implements ResolvesToObject, OperatorInterface
+final class ArrayToObjectOperator implements ResolvesToObject, OperatorInterface
{
public const ENCODE = Encode::Array;
+ public const NAME = '$arrayToObject';
+ public const PROPERTIES = ['array' => 'array'];
/** @var BSONArray|PackedArray|ResolvesToArray|array $array */
public readonly PackedArray|ResolvesToArray|BSONArray|array $array;
@@ -40,9 +43,4 @@ public function __construct(PackedArray|ResolvesToArray|BSONArray|array $array)
$this->array = $array;
}
-
- public function getOperator(): string
- {
- return '$arrayToObject';
- }
}
diff --git a/src/Builder/Expression/AsinOperator.php b/src/Builder/Expression/AsinOperator.php
index f46031231..4f9a205e3 100644
--- a/src/Builder/Expression/AsinOperator.php
+++ b/src/Builder/Expression/AsinOperator.php
@@ -17,10 +17,13 @@
* Returns the inverse sin (arc sine) of a value in radians.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/asin/
+ * @internal
*/
-class AsinOperator implements ResolvesToDouble, ResolvesToDecimal, OperatorInterface
+final class AsinOperator implements ResolvesToDouble, ResolvesToDecimal, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$asin';
+ public const PROPERTIES = ['expression' => 'expression'];
/**
* @var 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.
@@ -38,9 +41,4 @@ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int $express
{
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$asin';
- }
}
diff --git a/src/Builder/Expression/AsinhOperator.php b/src/Builder/Expression/AsinhOperator.php
index ab466a0d8..4e5c72ef3 100644
--- a/src/Builder/Expression/AsinhOperator.php
+++ b/src/Builder/Expression/AsinhOperator.php
@@ -17,10 +17,13 @@
* Returns the inverse hyperbolic sine (hyperbolic arc sine) of a value in radians.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/asinh/
+ * @internal
*/
-class AsinhOperator implements ResolvesToDouble, ResolvesToDecimal, OperatorInterface
+final class AsinhOperator implements ResolvesToDouble, ResolvesToDecimal, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$asinh';
+ public const PROPERTIES = ['expression' => 'expression'];
/**
* @var Decimal128|Int64|ResolvesToNumber|float|int $expression $asinh takes any valid expression that resolves to a number.
@@ -38,9 +41,4 @@ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int $express
{
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$asinh';
- }
}
diff --git a/src/Builder/Expression/Atan2Operator.php b/src/Builder/Expression/Atan2Operator.php
index c08e7fbf8..78f56c8a8 100644
--- a/src/Builder/Expression/Atan2Operator.php
+++ b/src/Builder/Expression/Atan2Operator.php
@@ -17,10 +17,13 @@
* 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/
+ * @internal
*/
-class Atan2Operator implements ResolvesToDouble, ResolvesToDecimal, OperatorInterface
+final class Atan2Operator implements ResolvesToDouble, ResolvesToDecimal, OperatorInterface
{
public const ENCODE = Encode::Array;
+ public const NAME = '$atan2';
+ public const PROPERTIES = ['y' => 'y', 'x' => 'x'];
/**
* @var Decimal128|Int64|ResolvesToNumber|float|int $y $atan2 takes any valid expression that resolves to a number.
@@ -45,9 +48,4 @@ public function __construct(
$this->y = $y;
$this->x = $x;
}
-
- public function getOperator(): string
- {
- return '$atan2';
- }
}
diff --git a/src/Builder/Expression/AtanOperator.php b/src/Builder/Expression/AtanOperator.php
index b6d99973d..6362570d6 100644
--- a/src/Builder/Expression/AtanOperator.php
+++ b/src/Builder/Expression/AtanOperator.php
@@ -17,10 +17,13 @@
* Returns the inverse tangent (arc tangent) of a value in radians.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/atan/
+ * @internal
*/
-class AtanOperator implements ResolvesToDouble, ResolvesToDecimal, OperatorInterface
+final class AtanOperator implements ResolvesToDouble, ResolvesToDecimal, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$atan';
+ public const PROPERTIES = ['expression' => 'expression'];
/**
* @var Decimal128|Int64|ResolvesToNumber|float|int $expression $atan takes any valid expression that resolves to a number.
@@ -38,9 +41,4 @@ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int $express
{
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$atan';
- }
}
diff --git a/src/Builder/Expression/AtanhOperator.php b/src/Builder/Expression/AtanhOperator.php
index 38b9208f6..bdfba8ad9 100644
--- a/src/Builder/Expression/AtanhOperator.php
+++ b/src/Builder/Expression/AtanhOperator.php
@@ -17,10 +17,13 @@
* Returns the inverse hyperbolic tangent (hyperbolic arc tangent) of a value in radians.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/atanh/
+ * @internal
*/
-class AtanhOperator implements ResolvesToDouble, ResolvesToDecimal, OperatorInterface
+final class AtanhOperator implements ResolvesToDouble, ResolvesToDecimal, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$atanh';
+ public const PROPERTIES = ['expression' => 'expression'];
/**
* @var 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.
@@ -38,9 +41,4 @@ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int $express
{
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$atanh';
- }
}
diff --git a/src/Builder/Expression/AvgOperator.php b/src/Builder/Expression/AvgOperator.php
index 898bbe252..31745f14a 100644
--- a/src/Builder/Expression/AvgOperator.php
+++ b/src/Builder/Expression/AvgOperator.php
@@ -21,10 +21,13 @@
* Changed in MongoDB 5.0: Available in the $setWindowFields stage.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/avg/
+ * @internal
*/
-class AvgOperator implements ResolvesToNumber, OperatorInterface
+final class AvgOperator implements ResolvesToNumber, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$avg';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var list $expression */
public readonly array $expression;
@@ -45,9 +48,4 @@ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int ...$expr
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$avg';
- }
}
diff --git a/src/Builder/Expression/BinarySizeOperator.php b/src/Builder/Expression/BinarySizeOperator.php
index 28293cc88..792da66b0 100644
--- a/src/Builder/Expression/BinarySizeOperator.php
+++ b/src/Builder/Expression/BinarySizeOperator.php
@@ -16,10 +16,13 @@
* 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/
+ * @internal
*/
-class BinarySizeOperator implements ResolvesToInt, OperatorInterface
+final class BinarySizeOperator implements ResolvesToInt, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$binarySize';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var Binary|ResolvesToBinData|ResolvesToNull|ResolvesToString|null|string $expression */
public readonly Binary|ResolvesToBinData|ResolvesToNull|ResolvesToString|null|string $expression;
@@ -31,9 +34,4 @@ public function __construct(Binary|ResolvesToBinData|ResolvesToNull|ResolvesToSt
{
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$binarySize';
- }
}
diff --git a/src/Builder/Expression/BitAndOperator.php b/src/Builder/Expression/BitAndOperator.php
index 97b910a3f..bf0e3cd73 100644
--- a/src/Builder/Expression/BitAndOperator.php
+++ b/src/Builder/Expression/BitAndOperator.php
@@ -20,10 +20,13 @@
* New in MongoDB 6.3.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitAnd/
+ * @internal
*/
-class BitAndOperator implements ResolvesToInt, ResolvesToLong, OperatorInterface
+final class BitAndOperator implements ResolvesToInt, ResolvesToLong, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$bitAnd';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var list $expression */
public readonly array $expression;
@@ -44,9 +47,4 @@ public function __construct(Int64|ResolvesToInt|ResolvesToLong|int ...$expressio
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$bitAnd';
- }
}
diff --git a/src/Builder/Expression/BitNotOperator.php b/src/Builder/Expression/BitNotOperator.php
index d75322971..6f388919f 100644
--- a/src/Builder/Expression/BitNotOperator.php
+++ b/src/Builder/Expression/BitNotOperator.php
@@ -17,10 +17,13 @@
* New in MongoDB 6.3.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitNot/
+ * @internal
*/
-class BitNotOperator implements ResolvesToInt, ResolvesToLong, OperatorInterface
+final class BitNotOperator implements ResolvesToInt, ResolvesToLong, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$bitNot';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var Int64|ResolvesToInt|ResolvesToLong|int $expression */
public readonly Int64|ResolvesToInt|ResolvesToLong|int $expression;
@@ -32,9 +35,4 @@ public function __construct(Int64|ResolvesToInt|ResolvesToLong|int $expression)
{
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$bitNot';
- }
}
diff --git a/src/Builder/Expression/BitOrOperator.php b/src/Builder/Expression/BitOrOperator.php
index f14ac9583..b2490a4f6 100644
--- a/src/Builder/Expression/BitOrOperator.php
+++ b/src/Builder/Expression/BitOrOperator.php
@@ -20,10 +20,13 @@
* New in MongoDB 6.3.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitOr/
+ * @internal
*/
-class BitOrOperator implements ResolvesToInt, ResolvesToLong, OperatorInterface
+final class BitOrOperator implements ResolvesToInt, ResolvesToLong, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$bitOr';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var list $expression */
public readonly array $expression;
@@ -44,9 +47,4 @@ public function __construct(Int64|ResolvesToInt|ResolvesToLong|int ...$expressio
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$bitOr';
- }
}
diff --git a/src/Builder/Expression/BitXorOperator.php b/src/Builder/Expression/BitXorOperator.php
index 5382065b6..0f0bc0e5a 100644
--- a/src/Builder/Expression/BitXorOperator.php
+++ b/src/Builder/Expression/BitXorOperator.php
@@ -20,10 +20,13 @@
* New in MongoDB 6.3.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/bitXor/
+ * @internal
*/
-class BitXorOperator implements ResolvesToInt, ResolvesToLong, OperatorInterface
+final class BitXorOperator implements ResolvesToInt, ResolvesToLong, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$bitXor';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var list $expression */
public readonly array $expression;
@@ -44,9 +47,4 @@ public function __construct(Int64|ResolvesToInt|ResolvesToLong|int ...$expressio
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$bitXor';
- }
}
diff --git a/src/Builder/Expression/BsonSizeOperator.php b/src/Builder/Expression/BsonSizeOperator.php
index bdfb6f694..962d8c6db 100644
--- a/src/Builder/Expression/BsonSizeOperator.php
+++ b/src/Builder/Expression/BsonSizeOperator.php
@@ -18,10 +18,13 @@
* Returns the size in bytes of a given document (i.e. BSON type Object) when encoded as BSON.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/bsonSize/
+ * @internal
*/
-class BsonSizeOperator implements ResolvesToInt, OperatorInterface
+final class BsonSizeOperator implements ResolvesToInt, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$bsonSize';
+ public const PROPERTIES = ['object' => 'object'];
/** @var Document|ResolvesToNull|ResolvesToObject|Serializable|array|null|stdClass $object */
public readonly Document|Serializable|ResolvesToNull|ResolvesToObject|stdClass|array|null $object;
@@ -33,9 +36,4 @@ public function __construct(Document|Serializable|ResolvesToNull|ResolvesToObjec
{
$this->object = $object;
}
-
- public function getOperator(): string
- {
- return '$bsonSize';
- }
}
diff --git a/src/Builder/Expression/CaseOperator.php b/src/Builder/Expression/CaseOperator.php
index 463a3b741..27da77d71 100644
--- a/src/Builder/Expression/CaseOperator.php
+++ b/src/Builder/Expression/CaseOperator.php
@@ -19,10 +19,13 @@
* Represents a single case in a $switch expression
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/switch/
+ * @internal
*/
-class CaseOperator implements SwitchBranchInterface, OperatorInterface
+final class CaseOperator implements SwitchBranchInterface, OperatorInterface
{
- public const ENCODE = Encode::FlatObject;
+ public const ENCODE = Encode::Object;
+ public const NAME = null;
+ public const PROPERTIES = ['case' => 'case', 'then' => 'then'];
/** @var ResolvesToBool|bool $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. */
public readonly ResolvesToBool|bool $case;
@@ -41,9 +44,4 @@ public function __construct(
$this->case = $case;
$this->then = $then;
}
-
- public function getOperator(): string
- {
- return '$case';
- }
}
diff --git a/src/Builder/Expression/CeilOperator.php b/src/Builder/Expression/CeilOperator.php
index 95a01aa14..c6771b81f 100644
--- a/src/Builder/Expression/CeilOperator.php
+++ b/src/Builder/Expression/CeilOperator.php
@@ -17,10 +17,13 @@
* Returns the smallest integer greater than or equal to the specified number.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/ceil/
+ * @internal
*/
-class CeilOperator implements ResolvesToInt, OperatorInterface
+final class CeilOperator implements ResolvesToInt, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$ceil';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var 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 readonly Decimal128|Int64|ResolvesToNumber|float|int $expression;
@@ -32,9 +35,4 @@ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int $express
{
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$ceil';
- }
}
diff --git a/src/Builder/Expression/CmpOperator.php b/src/Builder/Expression/CmpOperator.php
index 78354cb20..72f27face 100644
--- a/src/Builder/Expression/CmpOperator.php
+++ b/src/Builder/Expression/CmpOperator.php
@@ -18,10 +18,13 @@
* 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/
+ * @internal
*/
-class CmpOperator implements ResolvesToInt, OperatorInterface
+final class CmpOperator implements ResolvesToInt, OperatorInterface
{
public const ENCODE = Encode::Array;
+ public const NAME = '$cmp';
+ public const PROPERTIES = ['expression1' => 'expression1', 'expression2' => 'expression2'];
/** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression1 */
public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression1;
@@ -40,9 +43,4 @@ public function __construct(
$this->expression1 = $expression1;
$this->expression2 = $expression2;
}
-
- public function getOperator(): string
- {
- return '$cmp';
- }
}
diff --git a/src/Builder/Expression/ConcatArraysOperator.php b/src/Builder/Expression/ConcatArraysOperator.php
index f8b790d52..17e736a78 100644
--- a/src/Builder/Expression/ConcatArraysOperator.php
+++ b/src/Builder/Expression/ConcatArraysOperator.php
@@ -20,10 +20,13 @@
* Concatenates arrays to return the concatenated array.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/concatArrays/
+ * @internal
*/
-class ConcatArraysOperator implements ResolvesToArray, OperatorInterface
+final class ConcatArraysOperator implements ResolvesToArray, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$concatArrays';
+ public const PROPERTIES = ['array' => 'array'];
/** @var list $array */
public readonly array $array;
@@ -44,9 +47,4 @@ public function __construct(PackedArray|ResolvesToArray|BSONArray|array ...$arra
$this->array = $array;
}
-
- public function getOperator(): string
- {
- return '$concatArrays';
- }
}
diff --git a/src/Builder/Expression/ConcatOperator.php b/src/Builder/Expression/ConcatOperator.php
index d9f0d9168..c8497be08 100644
--- a/src/Builder/Expression/ConcatOperator.php
+++ b/src/Builder/Expression/ConcatOperator.php
@@ -18,10 +18,13 @@
* Concatenates any number of strings.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/concat/
+ * @internal
*/
-class ConcatOperator implements ResolvesToString, OperatorInterface
+final class ConcatOperator implements ResolvesToString, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$concat';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var list $expression */
public readonly array $expression;
@@ -42,9 +45,4 @@ public function __construct(ResolvesToString|string ...$expression)
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$concat';
- }
}
diff --git a/src/Builder/Expression/CondOperator.php b/src/Builder/Expression/CondOperator.php
index 1d3a44c58..26ca336f5 100644
--- a/src/Builder/Expression/CondOperator.php
+++ b/src/Builder/Expression/CondOperator.php
@@ -18,10 +18,13 @@
* 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/
+ * @internal
*/
-class CondOperator implements ResolvesToAny, OperatorInterface
+final class CondOperator implements ResolvesToAny, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$cond';
+ public const PROPERTIES = ['if' => 'if', 'then' => 'then', 'else' => 'else'];
/** @var ResolvesToBool|bool $if */
public readonly ResolvesToBool|bool $if;
@@ -46,9 +49,4 @@ public function __construct(
$this->then = $then;
$this->else = $else;
}
-
- public function getOperator(): string
- {
- return '$cond';
- }
}
diff --git a/src/Builder/Expression/ConvertOperator.php b/src/Builder/Expression/ConvertOperator.php
index f8cb5210e..92bfecb02 100644
--- a/src/Builder/Expression/ConvertOperator.php
+++ b/src/Builder/Expression/ConvertOperator.php
@@ -20,10 +20,13 @@
* New in MongoDB 4.0.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/convert/
+ * @internal
*/
-class ConvertOperator implements ResolvesToAny, OperatorInterface
+final class ConvertOperator implements ResolvesToAny, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$convert';
+ public const PROPERTIES = ['input' => 'input', 'to' => 'to', 'onError' => 'onError', 'onNull' => 'onNull'];
/** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $input */
public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $input;
@@ -62,9 +65,4 @@ public function __construct(
$this->onError = $onError;
$this->onNull = $onNull;
}
-
- public function getOperator(): string
- {
- return '$convert';
- }
}
diff --git a/src/Builder/Expression/CosOperator.php b/src/Builder/Expression/CosOperator.php
index d3fe010e2..e06afa635 100644
--- a/src/Builder/Expression/CosOperator.php
+++ b/src/Builder/Expression/CosOperator.php
@@ -17,10 +17,13 @@
* Returns the cosine of a value that is measured in radians.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/cos/
+ * @internal
*/
-class CosOperator implements ResolvesToDouble, ResolvesToDecimal, OperatorInterface
+final class CosOperator implements ResolvesToDouble, ResolvesToDecimal, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$cos';
+ public const PROPERTIES = ['expression' => 'expression'];
/**
* @var 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.
@@ -36,9 +39,4 @@ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int $express
{
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$cos';
- }
}
diff --git a/src/Builder/Expression/CoshOperator.php b/src/Builder/Expression/CoshOperator.php
index 53530064f..c44dccb0b 100644
--- a/src/Builder/Expression/CoshOperator.php
+++ b/src/Builder/Expression/CoshOperator.php
@@ -17,10 +17,13 @@
* Returns the hyperbolic cosine of a value that is measured in radians.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/cosh/
+ * @internal
*/
-class CoshOperator implements ResolvesToDouble, ResolvesToDecimal, OperatorInterface
+final class CoshOperator implements ResolvesToDouble, ResolvesToDecimal, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$cosh';
+ public const PROPERTIES = ['expression' => 'expression'];
/**
* @var 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.
@@ -36,9 +39,4 @@ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int $express
{
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$cosh';
- }
}
diff --git a/src/Builder/Expression/DateAddOperator.php b/src/Builder/Expression/DateAddOperator.php
index b68484663..0c0bbf100 100644
--- a/src/Builder/Expression/DateAddOperator.php
+++ b/src/Builder/Expression/DateAddOperator.php
@@ -21,10 +21,13 @@
* Adds a number of time units to a date object.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateAdd/
+ * @internal
*/
-class DateAddOperator implements ResolvesToDate, OperatorInterface
+final class DateAddOperator implements ResolvesToDate, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$dateAdd';
+ public const PROPERTIES = ['startDate' => 'startDate', 'unit' => 'unit', 'amount' => 'amount', 'timezone' => 'timezone'];
/** @var 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 readonly ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $startDate;
@@ -55,9 +58,4 @@ public function __construct(
$this->amount = $amount;
$this->timezone = $timezone;
}
-
- public function getOperator(): string
- {
- return '$dateAdd';
- }
}
diff --git a/src/Builder/Expression/DateDiffOperator.php b/src/Builder/Expression/DateDiffOperator.php
index a13e484fc..a12ea935c 100644
--- a/src/Builder/Expression/DateDiffOperator.php
+++ b/src/Builder/Expression/DateDiffOperator.php
@@ -20,10 +20,20 @@
* Returns the difference between two dates.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateDiff/
+ * @internal
*/
-class DateDiffOperator implements ResolvesToInt, OperatorInterface
+final class DateDiffOperator implements ResolvesToInt, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$dateDiff';
+
+ public const PROPERTIES = [
+ 'startDate' => 'startDate',
+ 'endDate' => 'endDate',
+ 'unit' => 'unit',
+ 'timezone' => 'timezone',
+ 'startOfWeek' => 'startOfWeek',
+ ];
/** @var 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 readonly ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $startDate;
@@ -60,9 +70,4 @@ public function __construct(
$this->timezone = $timezone;
$this->startOfWeek = $startOfWeek;
}
-
- public function getOperator(): string
- {
- return '$dateDiff';
- }
}
diff --git a/src/Builder/Expression/DateFromPartsOperator.php b/src/Builder/Expression/DateFromPartsOperator.php
index f8b7ad639..877bfdd65 100644
--- a/src/Builder/Expression/DateFromPartsOperator.php
+++ b/src/Builder/Expression/DateFromPartsOperator.php
@@ -18,10 +18,26 @@
* Constructs a BSON Date object given the date's constituent parts.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateFromParts/
+ * @internal
*/
-class DateFromPartsOperator implements ResolvesToDate, OperatorInterface
+final class DateFromPartsOperator implements ResolvesToDate, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$dateFromParts';
+
+ public const PROPERTIES = [
+ 'year' => 'year',
+ 'isoWeekYear' => 'isoWeekYear',
+ 'month' => 'month',
+ 'isoWeek' => 'isoWeek',
+ 'day' => 'day',
+ 'isoDayOfWeek' => 'isoDayOfWeek',
+ 'hour' => 'hour',
+ 'minute' => 'minute',
+ 'second' => 'second',
+ 'millisecond' => 'millisecond',
+ 'timezone' => 'timezone',
+ ];
/** @var Optional|Decimal128|Int64|ResolvesToNumber|float|int $year Calendar year. Can be any expression that evaluates to a number. */
public readonly Optional|Decimal128|Int64|ResolvesToNumber|float|int $year;
@@ -94,9 +110,4 @@ public function __construct(
$this->millisecond = $millisecond;
$this->timezone = $timezone;
}
-
- public function getOperator(): string
- {
- return '$dateFromParts';
- }
}
diff --git a/src/Builder/Expression/DateFromStringOperator.php b/src/Builder/Expression/DateFromStringOperator.php
index 5a3f808f0..60c20fed1 100644
--- a/src/Builder/Expression/DateFromStringOperator.php
+++ b/src/Builder/Expression/DateFromStringOperator.php
@@ -19,10 +19,20 @@
* Converts a date/time string to a date object.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateFromString/
+ * @internal
*/
-class DateFromStringOperator implements ResolvesToDate, OperatorInterface
+final class DateFromStringOperator implements ResolvesToDate, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$dateFromString';
+
+ public const PROPERTIES = [
+ 'dateString' => 'dateString',
+ 'format' => 'format',
+ 'timezone' => 'timezone',
+ 'onError' => 'onError',
+ 'onNull' => 'onNull',
+ ];
/** @var ResolvesToString|string $dateString The date/time string to convert to a date object. */
public readonly ResolvesToString|string $dateString;
@@ -71,9 +81,4 @@ public function __construct(
$this->onError = $onError;
$this->onNull = $onNull;
}
-
- public function getOperator(): string
- {
- return '$dateFromString';
- }
}
diff --git a/src/Builder/Expression/DateSubtractOperator.php b/src/Builder/Expression/DateSubtractOperator.php
index 90efa4846..11fbfdcfd 100644
--- a/src/Builder/Expression/DateSubtractOperator.php
+++ b/src/Builder/Expression/DateSubtractOperator.php
@@ -21,10 +21,13 @@
* Subtracts a number of time units from a date object.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateSubtract/
+ * @internal
*/
-class DateSubtractOperator implements ResolvesToDate, OperatorInterface
+final class DateSubtractOperator implements ResolvesToDate, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$dateSubtract';
+ public const PROPERTIES = ['startDate' => 'startDate', 'unit' => 'unit', 'amount' => 'amount', 'timezone' => 'timezone'];
/** @var 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 readonly ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $startDate;
@@ -55,9 +58,4 @@ public function __construct(
$this->amount = $amount;
$this->timezone = $timezone;
}
-
- public function getOperator(): string
- {
- return '$dateSubtract';
- }
}
diff --git a/src/Builder/Expression/DateToPartsOperator.php b/src/Builder/Expression/DateToPartsOperator.php
index c0f637259..3573e59c8 100644
--- a/src/Builder/Expression/DateToPartsOperator.php
+++ b/src/Builder/Expression/DateToPartsOperator.php
@@ -19,10 +19,13 @@
* Returns a document containing the constituent parts of a date.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateToParts/
+ * @internal
*/
-class DateToPartsOperator implements ResolvesToObject, OperatorInterface
+final class DateToPartsOperator implements ResolvesToObject, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$dateToParts';
+ public const PROPERTIES = ['date' => 'date', 'timezone' => 'timezone', 'iso8601' => 'iso8601'];
/** @var 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 readonly ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date;
@@ -47,9 +50,4 @@ public function __construct(
$this->timezone = $timezone;
$this->iso8601 = $iso8601;
}
-
- public function getOperator(): string
- {
- return '$dateToParts';
- }
}
diff --git a/src/Builder/Expression/DateToStringOperator.php b/src/Builder/Expression/DateToStringOperator.php
index e33c519fd..7f9ede2d9 100644
--- a/src/Builder/Expression/DateToStringOperator.php
+++ b/src/Builder/Expression/DateToStringOperator.php
@@ -22,10 +22,13 @@
* Returns the date as a formatted string.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateToString/
+ * @internal
*/
-class DateToStringOperator implements ResolvesToString, OperatorInterface
+final class DateToStringOperator implements ResolvesToString, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$dateToString';
+ public const PROPERTIES = ['date' => 'date', 'format' => 'format', 'timezone' => 'timezone', 'onNull' => 'onNull'];
/** @var 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 readonly ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date;
@@ -64,9 +67,4 @@ public function __construct(
$this->timezone = $timezone;
$this->onNull = $onNull;
}
-
- public function getOperator(): string
- {
- return '$dateToString';
- }
}
diff --git a/src/Builder/Expression/DateTruncOperator.php b/src/Builder/Expression/DateTruncOperator.php
index 78be17040..b5e162bba 100644
--- a/src/Builder/Expression/DateTruncOperator.php
+++ b/src/Builder/Expression/DateTruncOperator.php
@@ -22,10 +22,20 @@
* Truncates a date.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/dateTrunc/
+ * @internal
*/
-class DateTruncOperator implements ResolvesToDate, OperatorInterface
+final class DateTruncOperator implements ResolvesToDate, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$dateTrunc';
+
+ public const PROPERTIES = [
+ 'date' => 'date',
+ 'unit' => 'unit',
+ 'binSize' => 'binSize',
+ 'timezone' => 'timezone',
+ 'startOfWeek' => 'startOfWeek',
+ ];
/** @var 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 readonly ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date;
@@ -74,9 +84,4 @@ public function __construct(
$this->timezone = $timezone;
$this->startOfWeek = $startOfWeek;
}
-
- public function getOperator(): string
- {
- return '$dateTrunc';
- }
}
diff --git a/src/Builder/Expression/DayOfMonthOperator.php b/src/Builder/Expression/DayOfMonthOperator.php
index a1a06db6b..bc0ccb28f 100644
--- a/src/Builder/Expression/DayOfMonthOperator.php
+++ b/src/Builder/Expression/DayOfMonthOperator.php
@@ -19,10 +19,13 @@
* 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/
+ * @internal
*/
-class DayOfMonthOperator implements ResolvesToInt, OperatorInterface
+final class DayOfMonthOperator implements ResolvesToInt, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$dayOfMonth';
+ public const PROPERTIES = ['date' => 'date', 'timezone' => 'timezone'];
/** @var 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 readonly ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date;
@@ -41,9 +44,4 @@ public function __construct(
$this->date = $date;
$this->timezone = $timezone;
}
-
- public function getOperator(): string
- {
- return '$dayOfMonth';
- }
}
diff --git a/src/Builder/Expression/DayOfWeekOperator.php b/src/Builder/Expression/DayOfWeekOperator.php
index 8b439c02c..e9dbbfa08 100644
--- a/src/Builder/Expression/DayOfWeekOperator.php
+++ b/src/Builder/Expression/DayOfWeekOperator.php
@@ -19,10 +19,13 @@
* 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/
+ * @internal
*/
-class DayOfWeekOperator implements ResolvesToInt, OperatorInterface
+final class DayOfWeekOperator implements ResolvesToInt, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$dayOfWeek';
+ public const PROPERTIES = ['date' => 'date', 'timezone' => 'timezone'];
/** @var 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 readonly ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date;
@@ -41,9 +44,4 @@ public function __construct(
$this->date = $date;
$this->timezone = $timezone;
}
-
- public function getOperator(): string
- {
- return '$dayOfWeek';
- }
}
diff --git a/src/Builder/Expression/DayOfYearOperator.php b/src/Builder/Expression/DayOfYearOperator.php
index d97be270d..86c20ab20 100644
--- a/src/Builder/Expression/DayOfYearOperator.php
+++ b/src/Builder/Expression/DayOfYearOperator.php
@@ -19,10 +19,13 @@
* 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/
+ * @internal
*/
-class DayOfYearOperator implements ResolvesToInt, OperatorInterface
+final class DayOfYearOperator implements ResolvesToInt, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$dayOfYear';
+ public const PROPERTIES = ['date' => 'date', 'timezone' => 'timezone'];
/** @var 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 readonly ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date;
@@ -41,9 +44,4 @@ public function __construct(
$this->date = $date;
$this->timezone = $timezone;
}
-
- public function getOperator(): string
- {
- return '$dayOfYear';
- }
}
diff --git a/src/Builder/Expression/DegreesToRadiansOperator.php b/src/Builder/Expression/DegreesToRadiansOperator.php
index a9329e16e..b8d2bb07a 100644
--- a/src/Builder/Expression/DegreesToRadiansOperator.php
+++ b/src/Builder/Expression/DegreesToRadiansOperator.php
@@ -17,10 +17,13 @@
* Converts a value from degrees to radians.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/degreesToRadians/
+ * @internal
*/
-class DegreesToRadiansOperator implements ResolvesToDouble, ResolvesToDecimal, OperatorInterface
+final class DegreesToRadiansOperator implements ResolvesToDouble, ResolvesToDecimal, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$degreesToRadians';
+ public const PROPERTIES = ['expression' => 'expression'];
/**
* @var Decimal128|Int64|ResolvesToNumber|float|int $expression $degreesToRadians takes any valid expression that resolves to a number.
@@ -36,9 +39,4 @@ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int $express
{
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$degreesToRadians';
- }
}
diff --git a/src/Builder/Expression/DivideOperator.php b/src/Builder/Expression/DivideOperator.php
index bda2f503a..74de49c20 100644
--- a/src/Builder/Expression/DivideOperator.php
+++ b/src/Builder/Expression/DivideOperator.php
@@ -17,10 +17,13 @@
* 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/
+ * @internal
*/
-class DivideOperator implements ResolvesToDouble, OperatorInterface
+final class DivideOperator implements ResolvesToDouble, OperatorInterface
{
public const ENCODE = Encode::Array;
+ public const NAME = '$divide';
+ public const PROPERTIES = ['dividend' => 'dividend', 'divisor' => 'divisor'];
/** @var 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 readonly Decimal128|Int64|ResolvesToNumber|float|int $dividend;
@@ -39,9 +42,4 @@ public function __construct(
$this->dividend = $dividend;
$this->divisor = $divisor;
}
-
- public function getOperator(): string
- {
- return '$divide';
- }
}
diff --git a/src/Builder/Expression/EqOperator.php b/src/Builder/Expression/EqOperator.php
index 5da15a3c3..f78d0ff3b 100644
--- a/src/Builder/Expression/EqOperator.php
+++ b/src/Builder/Expression/EqOperator.php
@@ -18,10 +18,13 @@
* Returns true if the values are equivalent.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/eq/
+ * @internal
*/
-class EqOperator implements ResolvesToBool, OperatorInterface
+final class EqOperator implements ResolvesToBool, OperatorInterface
{
public const ENCODE = Encode::Array;
+ public const NAME = '$eq';
+ public const PROPERTIES = ['expression1' => 'expression1', 'expression2' => 'expression2'];
/** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression1 */
public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression1;
@@ -40,9 +43,4 @@ public function __construct(
$this->expression1 = $expression1;
$this->expression2 = $expression2;
}
-
- public function getOperator(): string
- {
- return '$eq';
- }
}
diff --git a/src/Builder/Expression/ExpOperator.php b/src/Builder/Expression/ExpOperator.php
index a168a6acd..78037fb9e 100644
--- a/src/Builder/Expression/ExpOperator.php
+++ b/src/Builder/Expression/ExpOperator.php
@@ -17,10 +17,13 @@
* Raises e to the specified exponent.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/exp/
+ * @internal
*/
-class ExpOperator implements ResolvesToDouble, OperatorInterface
+final class ExpOperator implements ResolvesToDouble, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$exp';
+ public const PROPERTIES = ['exponent' => 'exponent'];
/** @var Decimal128|Int64|ResolvesToNumber|float|int $exponent */
public readonly Decimal128|Int64|ResolvesToNumber|float|int $exponent;
@@ -32,9 +35,4 @@ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int $exponen
{
$this->exponent = $exponent;
}
-
- public function getOperator(): string
- {
- return '$exp';
- }
}
diff --git a/src/Builder/Expression/FilterOperator.php b/src/Builder/Expression/FilterOperator.php
index 6fc372e06..9bd522572 100644
--- a/src/Builder/Expression/FilterOperator.php
+++ b/src/Builder/Expression/FilterOperator.php
@@ -22,10 +22,13 @@
* 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/
+ * @internal
*/
-class FilterOperator implements ResolvesToArray, OperatorInterface
+final class FilterOperator implements ResolvesToArray, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$filter';
+ public const PROPERTIES = ['input' => 'input', 'cond' => 'cond', 'as' => 'as', 'limit' => 'limit'];
/** @var BSONArray|PackedArray|ResolvesToArray|array $input */
public readonly PackedArray|ResolvesToArray|BSONArray|array $input;
@@ -64,9 +67,4 @@ public function __construct(
$this->as = $as;
$this->limit = $limit;
}
-
- public function getOperator(): string
- {
- return '$filter';
- }
}
diff --git a/src/Builder/Expression/FirstNOperator.php b/src/Builder/Expression/FirstNOperator.php
index 7aeb04eba..769c38118 100644
--- a/src/Builder/Expression/FirstNOperator.php
+++ b/src/Builder/Expression/FirstNOperator.php
@@ -21,10 +21,13 @@
* Returns a specified number of elements from the beginning of an array.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/firstN-array-element/
+ * @internal
*/
-class FirstNOperator implements ResolvesToArray, OperatorInterface
+final class FirstNOperator implements ResolvesToArray, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$firstN';
+ public const PROPERTIES = ['n' => 'n', 'input' => 'input'];
/** @var ResolvesToInt|int $n An expression that resolves to a positive integer. The integer specifies the number of array elements that $firstN returns. */
public readonly ResolvesToInt|int $n;
@@ -45,9 +48,4 @@ public function __construct(ResolvesToInt|int $n, PackedArray|ResolvesToArray|BS
$this->input = $input;
}
-
- public function getOperator(): string
- {
- return '$firstN';
- }
}
diff --git a/src/Builder/Expression/FirstOperator.php b/src/Builder/Expression/FirstOperator.php
index 5453af68f..994de7bee 100644
--- a/src/Builder/Expression/FirstOperator.php
+++ b/src/Builder/Expression/FirstOperator.php
@@ -21,10 +21,13 @@
* Returns the result of an expression for the first document in an array.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/first/
+ * @internal
*/
-class FirstOperator implements ResolvesToAny, OperatorInterface
+final class FirstOperator implements ResolvesToAny, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$first';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var BSONArray|PackedArray|ResolvesToArray|array $expression */
public readonly PackedArray|ResolvesToArray|BSONArray|array $expression;
@@ -40,9 +43,4 @@ public function __construct(PackedArray|ResolvesToArray|BSONArray|array $express
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$first';
- }
}
diff --git a/src/Builder/Expression/FloorOperator.php b/src/Builder/Expression/FloorOperator.php
index 4dfac2de1..741412330 100644
--- a/src/Builder/Expression/FloorOperator.php
+++ b/src/Builder/Expression/FloorOperator.php
@@ -17,10 +17,13 @@
* Returns the largest integer less than or equal to the specified number.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/floor/
+ * @internal
*/
-class FloorOperator implements ResolvesToInt, OperatorInterface
+final class FloorOperator implements ResolvesToInt, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$floor';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var Decimal128|Int64|ResolvesToNumber|float|int $expression */
public readonly Decimal128|Int64|ResolvesToNumber|float|int $expression;
@@ -32,9 +35,4 @@ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int $express
{
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$floor';
- }
}
diff --git a/src/Builder/Expression/FunctionOperator.php b/src/Builder/Expression/FunctionOperator.php
index 2a59fd6a3..516729e3a 100644
--- a/src/Builder/Expression/FunctionOperator.php
+++ b/src/Builder/Expression/FunctionOperator.php
@@ -24,10 +24,13 @@
* New in MongoDB 4.4.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/function/
+ * @internal
*/
-class FunctionOperator implements ResolvesToAny, OperatorInterface
+final class FunctionOperator implements ResolvesToAny, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$function';
+ public const PROPERTIES = ['body' => 'body', 'args' => 'args', 'lang' => 'lang'];
/**
* @var Javascript|string $body The function definition. You can specify the function definition as either BSON\JavaScript or string.
@@ -61,9 +64,4 @@ public function __construct(Javascript|string $body, PackedArray|BSONArray|array
$this->args = $args;
$this->lang = $lang;
}
-
- public function getOperator(): string
- {
- return '$function';
- }
}
diff --git a/src/Builder/Expression/GetFieldOperator.php b/src/Builder/Expression/GetFieldOperator.php
index 45007b3fd..622bacb85 100644
--- a/src/Builder/Expression/GetFieldOperator.php
+++ b/src/Builder/Expression/GetFieldOperator.php
@@ -20,10 +20,13 @@
* New in MongoDB 5.0.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/getField/
+ * @internal
*/
-class GetFieldOperator implements ResolvesToAny, OperatorInterface
+final class GetFieldOperator implements ResolvesToAny, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$getField';
+ public const PROPERTIES = ['field' => 'field', 'input' => 'input'];
/**
* @var ResolvesToString|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.
@@ -50,9 +53,4 @@ public function __construct(
$this->field = $field;
$this->input = $input;
}
-
- public function getOperator(): string
- {
- return '$getField';
- }
}
diff --git a/src/Builder/Expression/GtOperator.php b/src/Builder/Expression/GtOperator.php
index 1f4287eaa..fda780fff 100644
--- a/src/Builder/Expression/GtOperator.php
+++ b/src/Builder/Expression/GtOperator.php
@@ -18,10 +18,13 @@
* Returns true if the first value is greater than the second.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/gt/
+ * @internal
*/
-class GtOperator implements ResolvesToBool, OperatorInterface
+final class GtOperator implements ResolvesToBool, OperatorInterface
{
public const ENCODE = Encode::Array;
+ public const NAME = '$gt';
+ public const PROPERTIES = ['expression1' => 'expression1', 'expression2' => 'expression2'];
/** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression1 */
public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression1;
@@ -40,9 +43,4 @@ public function __construct(
$this->expression1 = $expression1;
$this->expression2 = $expression2;
}
-
- public function getOperator(): string
- {
- return '$gt';
- }
}
diff --git a/src/Builder/Expression/GteOperator.php b/src/Builder/Expression/GteOperator.php
index 8ed633ae8..8f5792770 100644
--- a/src/Builder/Expression/GteOperator.php
+++ b/src/Builder/Expression/GteOperator.php
@@ -18,10 +18,13 @@
* 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/
+ * @internal
*/
-class GteOperator implements ResolvesToBool, OperatorInterface
+final class GteOperator implements ResolvesToBool, OperatorInterface
{
public const ENCODE = Encode::Array;
+ public const NAME = '$gte';
+ public const PROPERTIES = ['expression1' => 'expression1', 'expression2' => 'expression2'];
/** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression1 */
public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression1;
@@ -40,9 +43,4 @@ public function __construct(
$this->expression1 = $expression1;
$this->expression2 = $expression2;
}
-
- public function getOperator(): string
- {
- return '$gte';
- }
}
diff --git a/src/Builder/Expression/HourOperator.php b/src/Builder/Expression/HourOperator.php
index 2d0598589..5c68b7446 100644
--- a/src/Builder/Expression/HourOperator.php
+++ b/src/Builder/Expression/HourOperator.php
@@ -19,10 +19,13 @@
* Returns the hour for a date as a number between 0 and 23.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/hour/
+ * @internal
*/
-class HourOperator implements ResolvesToInt, OperatorInterface
+final class HourOperator implements ResolvesToInt, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$hour';
+ public const PROPERTIES = ['date' => 'date', 'timezone' => 'timezone'];
/** @var 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 readonly ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date;
@@ -41,9 +44,4 @@ public function __construct(
$this->date = $date;
$this->timezone = $timezone;
}
-
- public function getOperator(): string
- {
- return '$hour';
- }
}
diff --git a/src/Builder/Expression/IfNullOperator.php b/src/Builder/Expression/IfNullOperator.php
index f0a6a9ced..51c393d28 100644
--- a/src/Builder/Expression/IfNullOperator.php
+++ b/src/Builder/Expression/IfNullOperator.php
@@ -21,10 +21,13 @@
* 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/
+ * @internal
*/
-class IfNullOperator implements ResolvesToAny, OperatorInterface
+final class IfNullOperator implements ResolvesToAny, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$ifNull';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var list $expression */
public readonly array $expression;
@@ -45,9 +48,4 @@ public function __construct(Type|ExpressionInterface|stdClass|array|bool|float|i
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$ifNull';
- }
}
diff --git a/src/Builder/Expression/InOperator.php b/src/Builder/Expression/InOperator.php
index 90ddab23b..c2e24b9dc 100644
--- a/src/Builder/Expression/InOperator.php
+++ b/src/Builder/Expression/InOperator.php
@@ -24,10 +24,13 @@
* Returns a boolean indicating whether a specified value is in an array.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/in/
+ * @internal
*/
-class InOperator implements ResolvesToBool, OperatorInterface
+final class InOperator implements ResolvesToBool, OperatorInterface
{
public const ENCODE = Encode::Array;
+ public const NAME = '$in';
+ public const PROPERTIES = ['expression' => 'expression', 'array' => 'array'];
/** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression Any valid expression expression. */
public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression;
@@ -50,9 +53,4 @@ public function __construct(
$this->array = $array;
}
-
- public function getOperator(): string
- {
- return '$in';
- }
}
diff --git a/src/Builder/Expression/IndexOfArrayOperator.php b/src/Builder/Expression/IndexOfArrayOperator.php
index d04497fb5..15e3e4626 100644
--- a/src/Builder/Expression/IndexOfArrayOperator.php
+++ b/src/Builder/Expression/IndexOfArrayOperator.php
@@ -25,10 +25,13 @@
* 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/
+ * @internal
*/
-class IndexOfArrayOperator implements ResolvesToInt, OperatorInterface
+final class IndexOfArrayOperator implements ResolvesToInt, OperatorInterface
{
public const ENCODE = Encode::Array;
+ public const NAME = '$indexOfArray';
+ public const PROPERTIES = ['array' => 'array', 'search' => 'search', 'start' => 'start', 'end' => 'end'];
/**
* @var BSONArray|PackedArray|ResolvesToArray|array $array Can be any valid expression as long as it resolves to an array.
@@ -77,9 +80,4 @@ public function __construct(
$this->start = $start;
$this->end = $end;
}
-
- public function getOperator(): string
- {
- return '$indexOfArray';
- }
}
diff --git a/src/Builder/Expression/IndexOfBytesOperator.php b/src/Builder/Expression/IndexOfBytesOperator.php
index ce778fa25..9f3d07533 100644
--- a/src/Builder/Expression/IndexOfBytesOperator.php
+++ b/src/Builder/Expression/IndexOfBytesOperator.php
@@ -16,10 +16,13 @@
* 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/
+ * @internal
*/
-class IndexOfBytesOperator implements ResolvesToInt, OperatorInterface
+final class IndexOfBytesOperator implements ResolvesToInt, OperatorInterface
{
public const ENCODE = Encode::Array;
+ public const NAME = '$indexOfBytes';
+ public const PROPERTIES = ['string' => 'string', 'substring' => 'substring', 'start' => 'start', 'end' => 'end'];
/**
* @var ResolvesToString|string $string Can be any valid expression as long as it resolves to a string.
@@ -64,9 +67,4 @@ public function __construct(
$this->start = $start;
$this->end = $end;
}
-
- public function getOperator(): string
- {
- return '$indexOfBytes';
- }
}
diff --git a/src/Builder/Expression/IndexOfCPOperator.php b/src/Builder/Expression/IndexOfCPOperator.php
index c4fd80d88..735de9759 100644
--- a/src/Builder/Expression/IndexOfCPOperator.php
+++ b/src/Builder/Expression/IndexOfCPOperator.php
@@ -16,10 +16,13 @@
* 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/
+ * @internal
*/
-class IndexOfCPOperator implements ResolvesToInt, OperatorInterface
+final class IndexOfCPOperator implements ResolvesToInt, OperatorInterface
{
public const ENCODE = Encode::Array;
+ public const NAME = '$indexOfCP';
+ public const PROPERTIES = ['string' => 'string', 'substring' => 'substring', 'start' => 'start', 'end' => 'end'];
/**
* @var ResolvesToString|string $string Can be any valid expression as long as it resolves to a string.
@@ -64,9 +67,4 @@ public function __construct(
$this->start = $start;
$this->end = $end;
}
-
- public function getOperator(): string
- {
- return '$indexOfCP';
- }
}
diff --git a/src/Builder/Expression/IsArrayOperator.php b/src/Builder/Expression/IsArrayOperator.php
index bb15c0102..abd075103 100644
--- a/src/Builder/Expression/IsArrayOperator.php
+++ b/src/Builder/Expression/IsArrayOperator.php
@@ -18,10 +18,13 @@
* Determines if the operand is an array. Returns a boolean.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/isArray/
+ * @internal
*/
-class IsArrayOperator implements ResolvesToBool, OperatorInterface
+final class IsArrayOperator implements ResolvesToBool, OperatorInterface
{
public const ENCODE = Encode::Array;
+ public const NAME = '$isArray';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */
public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression;
@@ -33,9 +36,4 @@ public function __construct(Type|ExpressionInterface|stdClass|array|bool|float|i
{
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$isArray';
- }
}
diff --git a/src/Builder/Expression/IsNumberOperator.php b/src/Builder/Expression/IsNumberOperator.php
index 9d778f66f..a76530242 100644
--- a/src/Builder/Expression/IsNumberOperator.php
+++ b/src/Builder/Expression/IsNumberOperator.php
@@ -20,10 +20,13 @@
* New in MongoDB 4.4.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/isNumber/
+ * @internal
*/
-class IsNumberOperator implements ResolvesToBool, OperatorInterface
+final class IsNumberOperator implements ResolvesToBool, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$isNumber';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */
public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression;
@@ -35,9 +38,4 @@ public function __construct(Type|ExpressionInterface|stdClass|array|bool|float|i
{
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$isNumber';
- }
}
diff --git a/src/Builder/Expression/IsoDayOfWeekOperator.php b/src/Builder/Expression/IsoDayOfWeekOperator.php
index ac55ea6ba..8bbc8dfe9 100644
--- a/src/Builder/Expression/IsoDayOfWeekOperator.php
+++ b/src/Builder/Expression/IsoDayOfWeekOperator.php
@@ -19,10 +19,13 @@
* 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/
+ * @internal
*/
-class IsoDayOfWeekOperator implements ResolvesToInt, OperatorInterface
+final class IsoDayOfWeekOperator implements ResolvesToInt, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$isoDayOfWeek';
+ public const PROPERTIES = ['date' => 'date', 'timezone' => 'timezone'];
/** @var 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 readonly ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date;
@@ -41,9 +44,4 @@ public function __construct(
$this->date = $date;
$this->timezone = $timezone;
}
-
- public function getOperator(): string
- {
- return '$isoDayOfWeek';
- }
}
diff --git a/src/Builder/Expression/IsoWeekOperator.php b/src/Builder/Expression/IsoWeekOperator.php
index af6cca475..726c53537 100644
--- a/src/Builder/Expression/IsoWeekOperator.php
+++ b/src/Builder/Expression/IsoWeekOperator.php
@@ -19,10 +19,13 @@
* 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/
+ * @internal
*/
-class IsoWeekOperator implements ResolvesToInt, OperatorInterface
+final class IsoWeekOperator implements ResolvesToInt, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$isoWeek';
+ public const PROPERTIES = ['date' => 'date', 'timezone' => 'timezone'];
/** @var 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 readonly ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date;
@@ -41,9 +44,4 @@ public function __construct(
$this->date = $date;
$this->timezone = $timezone;
}
-
- public function getOperator(): string
- {
- return '$isoWeek';
- }
}
diff --git a/src/Builder/Expression/IsoWeekYearOperator.php b/src/Builder/Expression/IsoWeekYearOperator.php
index a23d90696..a29e2e8a6 100644
--- a/src/Builder/Expression/IsoWeekYearOperator.php
+++ b/src/Builder/Expression/IsoWeekYearOperator.php
@@ -19,10 +19,13 @@
* 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/
+ * @internal
*/
-class IsoWeekYearOperator implements ResolvesToInt, OperatorInterface
+final class IsoWeekYearOperator implements ResolvesToInt, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$isoWeekYear';
+ public const PROPERTIES = ['date' => 'date', 'timezone' => 'timezone'];
/** @var 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 readonly ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date;
@@ -41,9 +44,4 @@ public function __construct(
$this->date = $date;
$this->timezone = $timezone;
}
-
- public function getOperator(): string
- {
- return '$isoWeekYear';
- }
}
diff --git a/src/Builder/Expression/LastNOperator.php b/src/Builder/Expression/LastNOperator.php
index f1bbaab11..0517f92d8 100644
--- a/src/Builder/Expression/LastNOperator.php
+++ b/src/Builder/Expression/LastNOperator.php
@@ -21,10 +21,13 @@
* Returns a specified number of elements from the end of an array.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/lastN-array-element/
+ * @internal
*/
-class LastNOperator implements ResolvesToArray, OperatorInterface
+final class LastNOperator implements ResolvesToArray, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$lastN';
+ public const PROPERTIES = ['n' => 'n', 'input' => 'input'];
/** @var ResolvesToInt|int $n An expression that resolves to a positive integer. The integer specifies the number of array elements that $firstN returns. */
public readonly ResolvesToInt|int $n;
@@ -45,9 +48,4 @@ public function __construct(ResolvesToInt|int $n, PackedArray|ResolvesToArray|BS
$this->input = $input;
}
-
- public function getOperator(): string
- {
- return '$lastN';
- }
}
diff --git a/src/Builder/Expression/LastOperator.php b/src/Builder/Expression/LastOperator.php
index ea622018c..e7f2b7d46 100644
--- a/src/Builder/Expression/LastOperator.php
+++ b/src/Builder/Expression/LastOperator.php
@@ -21,10 +21,13 @@
* Returns the result of an expression for the last document in an array.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/last/
+ * @internal
*/
-class LastOperator implements ResolvesToAny, OperatorInterface
+final class LastOperator implements ResolvesToAny, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$last';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var BSONArray|PackedArray|ResolvesToArray|array $expression */
public readonly PackedArray|ResolvesToArray|BSONArray|array $expression;
@@ -40,9 +43,4 @@ public function __construct(PackedArray|ResolvesToArray|BSONArray|array $express
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$last';
- }
}
diff --git a/src/Builder/Expression/LetOperator.php b/src/Builder/Expression/LetOperator.php
index 541b0b8ff..3f0fde195 100644
--- a/src/Builder/Expression/LetOperator.php
+++ b/src/Builder/Expression/LetOperator.php
@@ -21,10 +21,13 @@
* Accepts any number of argument expressions.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/let/
+ * @internal
*/
-class LetOperator implements ResolvesToAny, OperatorInterface
+final class LetOperator implements ResolvesToAny, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$let';
+ public const PROPERTIES = ['vars' => 'vars', 'in' => 'in'];
/**
* @var 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.
@@ -47,9 +50,4 @@ public function __construct(
$this->vars = $vars;
$this->in = $in;
}
-
- public function getOperator(): string
- {
- return '$let';
- }
}
diff --git a/src/Builder/Expression/LiteralOperator.php b/src/Builder/Expression/LiteralOperator.php
index 95e942b2f..fc80506e4 100644
--- a/src/Builder/Expression/LiteralOperator.php
+++ b/src/Builder/Expression/LiteralOperator.php
@@ -17,10 +17,13 @@
* 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/
+ * @internal
*/
-class LiteralOperator implements ResolvesToAny, OperatorInterface
+final class LiteralOperator implements ResolvesToAny, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$literal';
+ public const PROPERTIES = ['value' => 'value'];
/** @var Type|array|bool|float|int|null|stdClass|string $value If the value is an expression, $literal does not evaluate the expression but instead returns the unparsed expression. */
public readonly Type|stdClass|array|bool|float|int|null|string $value;
@@ -32,9 +35,4 @@ public function __construct(Type|stdClass|array|bool|float|int|null|string $valu
{
$this->value = $value;
}
-
- public function getOperator(): string
- {
- return '$literal';
- }
}
diff --git a/src/Builder/Expression/LnOperator.php b/src/Builder/Expression/LnOperator.php
index 43d0de15b..6fe5993e9 100644
--- a/src/Builder/Expression/LnOperator.php
+++ b/src/Builder/Expression/LnOperator.php
@@ -18,10 +18,13 @@
* $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/
+ * @internal
*/
-class LnOperator implements ResolvesToDouble, OperatorInterface
+final class LnOperator implements ResolvesToDouble, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$ln';
+ public const PROPERTIES = ['number' => 'number'];
/** @var 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 readonly Decimal128|Int64|ResolvesToNumber|float|int $number;
@@ -33,9 +36,4 @@ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int $number)
{
$this->number = $number;
}
-
- public function getOperator(): string
- {
- return '$ln';
- }
}
diff --git a/src/Builder/Expression/Log10Operator.php b/src/Builder/Expression/Log10Operator.php
index ccdc67666..ef4a5ec3e 100644
--- a/src/Builder/Expression/Log10Operator.php
+++ b/src/Builder/Expression/Log10Operator.php
@@ -17,10 +17,13 @@
* Calculates the log base 10 of a number.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/log10/
+ * @internal
*/
-class Log10Operator implements ResolvesToDouble, OperatorInterface
+final class Log10Operator implements ResolvesToDouble, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$log10';
+ public const PROPERTIES = ['number' => 'number'];
/** @var Decimal128|Int64|ResolvesToNumber|float|int $number Any valid expression as long as it resolves to a non-negative number. */
public readonly Decimal128|Int64|ResolvesToNumber|float|int $number;
@@ -32,9 +35,4 @@ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int $number)
{
$this->number = $number;
}
-
- public function getOperator(): string
- {
- return '$log10';
- }
}
diff --git a/src/Builder/Expression/LogOperator.php b/src/Builder/Expression/LogOperator.php
index 8359e1a53..99bbfd812 100644
--- a/src/Builder/Expression/LogOperator.php
+++ b/src/Builder/Expression/LogOperator.php
@@ -17,10 +17,13 @@
* Calculates the log of a number in the specified base.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/log/
+ * @internal
*/
-class LogOperator implements ResolvesToDouble, OperatorInterface
+final class LogOperator implements ResolvesToDouble, OperatorInterface
{
public const ENCODE = Encode::Array;
+ public const NAME = '$log';
+ public const PROPERTIES = ['number' => 'number', 'base' => 'base'];
/** @var Decimal128|Int64|ResolvesToNumber|float|int $number Any valid expression as long as it resolves to a non-negative number. */
public readonly Decimal128|Int64|ResolvesToNumber|float|int $number;
@@ -39,9 +42,4 @@ public function __construct(
$this->number = $number;
$this->base = $base;
}
-
- public function getOperator(): string
- {
- return '$log';
- }
}
diff --git a/src/Builder/Expression/LtOperator.php b/src/Builder/Expression/LtOperator.php
index a3cbad988..7ea54defa 100644
--- a/src/Builder/Expression/LtOperator.php
+++ b/src/Builder/Expression/LtOperator.php
@@ -18,10 +18,13 @@
* Returns true if the first value is less than the second.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/lt/
+ * @internal
*/
-class LtOperator implements ResolvesToBool, OperatorInterface
+final class LtOperator implements ResolvesToBool, OperatorInterface
{
public const ENCODE = Encode::Array;
+ public const NAME = '$lt';
+ public const PROPERTIES = ['expression1' => 'expression1', 'expression2' => 'expression2'];
/** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression1 */
public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression1;
@@ -40,9 +43,4 @@ public function __construct(
$this->expression1 = $expression1;
$this->expression2 = $expression2;
}
-
- public function getOperator(): string
- {
- return '$lt';
- }
}
diff --git a/src/Builder/Expression/LteOperator.php b/src/Builder/Expression/LteOperator.php
index 10e3d299a..caeec2165 100644
--- a/src/Builder/Expression/LteOperator.php
+++ b/src/Builder/Expression/LteOperator.php
@@ -18,10 +18,13 @@
* 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/
+ * @internal
*/
-class LteOperator implements ResolvesToBool, OperatorInterface
+final class LteOperator implements ResolvesToBool, OperatorInterface
{
public const ENCODE = Encode::Array;
+ public const NAME = '$lte';
+ public const PROPERTIES = ['expression1' => 'expression1', 'expression2' => 'expression2'];
/** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression1 */
public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression1;
@@ -40,9 +43,4 @@ public function __construct(
$this->expression1 = $expression1;
$this->expression2 = $expression2;
}
-
- public function getOperator(): string
- {
- return '$lte';
- }
}
diff --git a/src/Builder/Expression/LtrimOperator.php b/src/Builder/Expression/LtrimOperator.php
index a0f4b7a5a..0dd94eaab 100644
--- a/src/Builder/Expression/LtrimOperator.php
+++ b/src/Builder/Expression/LtrimOperator.php
@@ -17,10 +17,13 @@
* New in MongoDB 4.0.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/ltrim/
+ * @internal
*/
-class LtrimOperator implements ResolvesToString, OperatorInterface
+final class LtrimOperator implements ResolvesToString, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$ltrim';
+ public const PROPERTIES = ['input' => 'input', 'chars' => 'chars'];
/** @var ResolvesToString|string $input The string to trim. The argument can be any valid expression that resolves to a string. */
public readonly ResolvesToString|string $input;
@@ -45,9 +48,4 @@ public function __construct(
$this->input = $input;
$this->chars = $chars;
}
-
- public function getOperator(): string
- {
- return '$ltrim';
- }
}
diff --git a/src/Builder/Expression/MapOperator.php b/src/Builder/Expression/MapOperator.php
index 98274395c..a63685a88 100644
--- a/src/Builder/Expression/MapOperator.php
+++ b/src/Builder/Expression/MapOperator.php
@@ -25,10 +25,13 @@
* 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/
+ * @internal
*/
-class MapOperator implements ResolvesToArray, OperatorInterface
+final class MapOperator implements ResolvesToArray, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$map';
+ public const PROPERTIES = ['input' => 'input', 'in' => 'in', 'as' => 'as'];
/** @var BSONArray|PackedArray|ResolvesToArray|array $input An expression that resolves to an array. */
public readonly PackedArray|ResolvesToArray|BSONArray|array $input;
@@ -57,9 +60,4 @@ public function __construct(
$this->in = $in;
$this->as = $as;
}
-
- public function getOperator(): string
- {
- return '$map';
- }
}
diff --git a/src/Builder/Expression/MaxNOperator.php b/src/Builder/Expression/MaxNOperator.php
index 2cda849d7..f8d387257 100644
--- a/src/Builder/Expression/MaxNOperator.php
+++ b/src/Builder/Expression/MaxNOperator.php
@@ -21,10 +21,13 @@
* 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/
+ * @internal
*/
-class MaxNOperator implements ResolvesToArray, OperatorInterface
+final class MaxNOperator implements ResolvesToArray, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$maxN';
+ public const PROPERTIES = ['input' => 'input', 'n' => 'n'];
/** @var BSONArray|PackedArray|ResolvesToArray|array $input An expression that resolves to the array from which to return the maximal n elements. */
public readonly PackedArray|ResolvesToArray|BSONArray|array $input;
@@ -45,9 +48,4 @@ public function __construct(PackedArray|ResolvesToArray|BSONArray|array $input,
$this->input = $input;
$this->n = $n;
}
-
- public function getOperator(): string
- {
- return '$maxN';
- }
}
diff --git a/src/Builder/Expression/MaxOperator.php b/src/Builder/Expression/MaxOperator.php
index 0573929b6..5c1923377 100644
--- a/src/Builder/Expression/MaxOperator.php
+++ b/src/Builder/Expression/MaxOperator.php
@@ -22,10 +22,13 @@
* Changed in MongoDB 5.0: Available in the $setWindowFields stage.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/max/
+ * @internal
*/
-class MaxOperator implements ResolvesToAny, OperatorInterface
+final class MaxOperator implements ResolvesToAny, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$max';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var list $expression */
public readonly array $expression;
@@ -46,9 +49,4 @@ public function __construct(Type|ExpressionInterface|stdClass|array|bool|float|i
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$max';
- }
}
diff --git a/src/Builder/Expression/MedianOperator.php b/src/Builder/Expression/MedianOperator.php
index f9c4f458d..bae54c838 100644
--- a/src/Builder/Expression/MedianOperator.php
+++ b/src/Builder/Expression/MedianOperator.php
@@ -28,10 +28,13 @@
* It is also available as an aggregation expression.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/median/
+ * @internal
*/
-class MedianOperator implements ResolvesToDouble, OperatorInterface
+final class MedianOperator implements ResolvesToDouble, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$median';
+ public const PROPERTIES = ['input' => 'input', 'method' => 'method'];
/** @var BSONArray|Decimal128|Int64|PackedArray|ResolvesToNumber|array|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 readonly Decimal128|Int64|PackedArray|ResolvesToNumber|BSONArray|array|float|int $input;
@@ -54,9 +57,4 @@ public function __construct(
$this->input = $input;
$this->method = $method;
}
-
- public function getOperator(): string
- {
- return '$median';
- }
}
diff --git a/src/Builder/Expression/MergeObjectsOperator.php b/src/Builder/Expression/MergeObjectsOperator.php
index 162f2cd49..45e73a59e 100644
--- a/src/Builder/Expression/MergeObjectsOperator.php
+++ b/src/Builder/Expression/MergeObjectsOperator.php
@@ -21,10 +21,13 @@
* Combines multiple documents into a single document.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/mergeObjects/
+ * @internal
*/
-class MergeObjectsOperator implements ResolvesToObject, OperatorInterface
+final class MergeObjectsOperator implements ResolvesToObject, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$mergeObjects';
+ public const PROPERTIES = ['document' => 'document'];
/** @var list $document Any valid expression that resolves to a document. */
public readonly array $document;
@@ -45,9 +48,4 @@ public function __construct(Document|Serializable|ResolvesToObject|stdClass|arra
$this->document = $document;
}
-
- public function getOperator(): string
- {
- return '$mergeObjects';
- }
}
diff --git a/src/Builder/Expression/MetaOperator.php b/src/Builder/Expression/MetaOperator.php
index a02b54ee9..ec1fd63e6 100644
--- a/src/Builder/Expression/MetaOperator.php
+++ b/src/Builder/Expression/MetaOperator.php
@@ -15,10 +15,13 @@
* Access available per-document metadata related to the aggregation operation.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/meta/
+ * @internal
*/
-class MetaOperator implements ResolvesToAny, OperatorInterface
+final class MetaOperator implements ResolvesToAny, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$meta';
+ public const PROPERTIES = ['keyword' => 'keyword'];
/** @var string $keyword */
public readonly string $keyword;
@@ -30,9 +33,4 @@ public function __construct(string $keyword)
{
$this->keyword = $keyword;
}
-
- public function getOperator(): string
- {
- return '$meta';
- }
}
diff --git a/src/Builder/Expression/MillisecondOperator.php b/src/Builder/Expression/MillisecondOperator.php
index 63b53b460..06d8a4bd8 100644
--- a/src/Builder/Expression/MillisecondOperator.php
+++ b/src/Builder/Expression/MillisecondOperator.php
@@ -19,10 +19,13 @@
* Returns the milliseconds of a date as a number between 0 and 999.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/millisecond/
+ * @internal
*/
-class MillisecondOperator implements ResolvesToInt, OperatorInterface
+final class MillisecondOperator implements ResolvesToInt, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$millisecond';
+ public const PROPERTIES = ['date' => 'date', 'timezone' => 'timezone'];
/** @var 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 readonly ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date;
@@ -41,9 +44,4 @@ public function __construct(
$this->date = $date;
$this->timezone = $timezone;
}
-
- public function getOperator(): string
- {
- return '$millisecond';
- }
}
diff --git a/src/Builder/Expression/MinNOperator.php b/src/Builder/Expression/MinNOperator.php
index f47976cb5..9d032fe3e 100644
--- a/src/Builder/Expression/MinNOperator.php
+++ b/src/Builder/Expression/MinNOperator.php
@@ -21,10 +21,13 @@
* 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/
+ * @internal
*/
-class MinNOperator implements ResolvesToArray, OperatorInterface
+final class MinNOperator implements ResolvesToArray, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$minN';
+ public const PROPERTIES = ['input' => 'input', 'n' => 'n'];
/** @var BSONArray|PackedArray|ResolvesToArray|array $input An expression that resolves to the array from which to return the maximal n elements. */
public readonly PackedArray|ResolvesToArray|BSONArray|array $input;
@@ -45,9 +48,4 @@ public function __construct(PackedArray|ResolvesToArray|BSONArray|array $input,
$this->input = $input;
$this->n = $n;
}
-
- public function getOperator(): string
- {
- return '$minN';
- }
}
diff --git a/src/Builder/Expression/MinOperator.php b/src/Builder/Expression/MinOperator.php
index c3fa2ed4b..31f30e807 100644
--- a/src/Builder/Expression/MinOperator.php
+++ b/src/Builder/Expression/MinOperator.php
@@ -22,10 +22,13 @@
* Changed in MongoDB 5.0: Available in the $setWindowFields stage.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/min/
+ * @internal
*/
-class MinOperator implements ResolvesToAny, OperatorInterface
+final class MinOperator implements ResolvesToAny, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$min';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var list $expression */
public readonly array $expression;
@@ -46,9 +49,4 @@ public function __construct(Type|ExpressionInterface|stdClass|array|bool|float|i
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$min';
- }
}
diff --git a/src/Builder/Expression/MinuteOperator.php b/src/Builder/Expression/MinuteOperator.php
index 7ab514ed0..2be3b337d 100644
--- a/src/Builder/Expression/MinuteOperator.php
+++ b/src/Builder/Expression/MinuteOperator.php
@@ -19,10 +19,13 @@
* Returns the minute for a date as a number between 0 and 59.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/minute/
+ * @internal
*/
-class MinuteOperator implements ResolvesToInt, OperatorInterface
+final class MinuteOperator implements ResolvesToInt, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$minute';
+ public const PROPERTIES = ['date' => 'date', 'timezone' => 'timezone'];
/** @var 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 readonly ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date;
@@ -41,9 +44,4 @@ public function __construct(
$this->date = $date;
$this->timezone = $timezone;
}
-
- public function getOperator(): string
- {
- return '$minute';
- }
}
diff --git a/src/Builder/Expression/ModOperator.php b/src/Builder/Expression/ModOperator.php
index 1a01019d7..8a2134fac 100644
--- a/src/Builder/Expression/ModOperator.php
+++ b/src/Builder/Expression/ModOperator.php
@@ -17,10 +17,13 @@
* 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/
+ * @internal
*/
-class ModOperator implements ResolvesToInt, OperatorInterface
+final class ModOperator implements ResolvesToInt, OperatorInterface
{
public const ENCODE = Encode::Array;
+ public const NAME = '$mod';
+ public const PROPERTIES = ['dividend' => 'dividend', 'divisor' => 'divisor'];
/** @var 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 readonly Decimal128|Int64|ResolvesToNumber|float|int $dividend;
@@ -39,9 +42,4 @@ public function __construct(
$this->dividend = $dividend;
$this->divisor = $divisor;
}
-
- public function getOperator(): string
- {
- return '$mod';
- }
}
diff --git a/src/Builder/Expression/MonthOperator.php b/src/Builder/Expression/MonthOperator.php
index 531bc946a..36d1c2b17 100644
--- a/src/Builder/Expression/MonthOperator.php
+++ b/src/Builder/Expression/MonthOperator.php
@@ -19,10 +19,13 @@
* 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/
+ * @internal
*/
-class MonthOperator implements ResolvesToInt, OperatorInterface
+final class MonthOperator implements ResolvesToInt, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$month';
+ public const PROPERTIES = ['date' => 'date', 'timezone' => 'timezone'];
/** @var 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 readonly ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date;
@@ -41,9 +44,4 @@ public function __construct(
$this->date = $date;
$this->timezone = $timezone;
}
-
- public function getOperator(): string
- {
- return '$month';
- }
}
diff --git a/src/Builder/Expression/MultiplyOperator.php b/src/Builder/Expression/MultiplyOperator.php
index 9f15aeb39..ba2f5882e 100644
--- a/src/Builder/Expression/MultiplyOperator.php
+++ b/src/Builder/Expression/MultiplyOperator.php
@@ -20,10 +20,13 @@
* Multiplies numbers to return the product. Accepts any number of argument expressions.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/multiply/
+ * @internal
*/
-class MultiplyOperator implements ResolvesToDecimal, OperatorInterface
+final class MultiplyOperator implements ResolvesToDecimal, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$multiply';
+ public const PROPERTIES = ['expression' => 'expression'];
/**
* @var list $expression The arguments can be any valid expression as long as they resolve to numbers.
@@ -48,9 +51,4 @@ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int ...$expr
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$multiply';
- }
}
diff --git a/src/Builder/Expression/NeOperator.php b/src/Builder/Expression/NeOperator.php
index 7bc322571..1688d7406 100644
--- a/src/Builder/Expression/NeOperator.php
+++ b/src/Builder/Expression/NeOperator.php
@@ -18,10 +18,13 @@
* Returns true if the values are not equivalent.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/ne/
+ * @internal
*/
-class NeOperator implements ResolvesToBool, OperatorInterface
+final class NeOperator implements ResolvesToBool, OperatorInterface
{
public const ENCODE = Encode::Array;
+ public const NAME = '$ne';
+ public const PROPERTIES = ['expression1' => 'expression1', 'expression2' => 'expression2'];
/** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression1 */
public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression1;
@@ -40,9 +43,4 @@ public function __construct(
$this->expression1 = $expression1;
$this->expression2 = $expression2;
}
-
- public function getOperator(): string
- {
- return '$ne';
- }
}
diff --git a/src/Builder/Expression/NotOperator.php b/src/Builder/Expression/NotOperator.php
index 170538e15..983fabc80 100644
--- a/src/Builder/Expression/NotOperator.php
+++ b/src/Builder/Expression/NotOperator.php
@@ -18,10 +18,13 @@
* 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/
+ * @internal
*/
-class NotOperator implements ResolvesToBool, OperatorInterface
+final class NotOperator implements ResolvesToBool, OperatorInterface
{
public const ENCODE = Encode::Array;
+ public const NAME = '$not';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var ExpressionInterface|ResolvesToBool|Type|array|bool|float|int|null|stdClass|string $expression */
public readonly Type|ResolvesToBool|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression;
@@ -34,9 +37,4 @@ public function __construct(
) {
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$not';
- }
}
diff --git a/src/Builder/Expression/ObjectToArrayOperator.php b/src/Builder/Expression/ObjectToArrayOperator.php
index 1ce5c5c11..0685bed27 100644
--- a/src/Builder/Expression/ObjectToArrayOperator.php
+++ b/src/Builder/Expression/ObjectToArrayOperator.php
@@ -18,10 +18,13 @@
* Converts a document to an array of documents representing key-value pairs.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/objectToArray/
+ * @internal
*/
-class ObjectToArrayOperator implements ResolvesToArray, OperatorInterface
+final class ObjectToArrayOperator implements ResolvesToArray, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$objectToArray';
+ public const PROPERTIES = ['object' => 'object'];
/** @var 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 readonly Document|Serializable|ResolvesToObject|stdClass|array $object;
@@ -33,9 +36,4 @@ public function __construct(Document|Serializable|ResolvesToObject|stdClass|arra
{
$this->object = $object;
}
-
- public function getOperator(): string
- {
- return '$objectToArray';
- }
}
diff --git a/src/Builder/Expression/OrOperator.php b/src/Builder/Expression/OrOperator.php
index a34896116..758e73a70 100644
--- a/src/Builder/Expression/OrOperator.php
+++ b/src/Builder/Expression/OrOperator.php
@@ -21,10 +21,13 @@
* 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/
+ * @internal
*/
-class OrOperator implements ResolvesToBool, OperatorInterface
+final class OrOperator implements ResolvesToBool, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$or';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var list $expression */
public readonly array $expression;
@@ -46,9 +49,4 @@ public function __construct(
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$or';
- }
}
diff --git a/src/Builder/Expression/PercentileOperator.php b/src/Builder/Expression/PercentileOperator.php
index 981719772..ab956bac5 100644
--- a/src/Builder/Expression/PercentileOperator.php
+++ b/src/Builder/Expression/PercentileOperator.php
@@ -31,10 +31,13 @@
* It is also available as an aggregation expression.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/percentile/
+ * @internal
*/
-class PercentileOperator implements ResolvesToArray, OperatorInterface
+final class PercentileOperator implements ResolvesToArray, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$percentile';
+ public const PROPERTIES = ['input' => 'input', 'p' => 'p', 'method' => 'method'];
/** @var BSONArray|Decimal128|Int64|PackedArray|ResolvesToNumber|array|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 readonly Decimal128|Int64|PackedArray|ResolvesToNumber|BSONArray|array|float|int $input;
@@ -71,9 +74,4 @@ public function __construct(
$this->p = $p;
$this->method = $method;
}
-
- public function getOperator(): string
- {
- return '$percentile';
- }
}
diff --git a/src/Builder/Expression/PowOperator.php b/src/Builder/Expression/PowOperator.php
index 1def31e7a..8cf024023 100644
--- a/src/Builder/Expression/PowOperator.php
+++ b/src/Builder/Expression/PowOperator.php
@@ -17,10 +17,13 @@
* Raises a number to the specified exponent.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/pow/
+ * @internal
*/
-class PowOperator implements ResolvesToNumber, OperatorInterface
+final class PowOperator implements ResolvesToNumber, OperatorInterface
{
public const ENCODE = Encode::Array;
+ public const NAME = '$pow';
+ public const PROPERTIES = ['number' => 'number', 'exponent' => 'exponent'];
/** @var Decimal128|Int64|ResolvesToNumber|float|int $number */
public readonly Decimal128|Int64|ResolvesToNumber|float|int $number;
@@ -39,9 +42,4 @@ public function __construct(
$this->number = $number;
$this->exponent = $exponent;
}
-
- public function getOperator(): string
- {
- return '$pow';
- }
}
diff --git a/src/Builder/Expression/RadiansToDegreesOperator.php b/src/Builder/Expression/RadiansToDegreesOperator.php
index 670c26d92..b3764f0ed 100644
--- a/src/Builder/Expression/RadiansToDegreesOperator.php
+++ b/src/Builder/Expression/RadiansToDegreesOperator.php
@@ -17,10 +17,13 @@
* Converts a value from radians to degrees.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/radiansToDegrees/
+ * @internal
*/
-class RadiansToDegreesOperator implements ResolvesToDouble, ResolvesToDecimal, OperatorInterface
+final class RadiansToDegreesOperator implements ResolvesToDouble, ResolvesToDecimal, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$radiansToDegrees';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var Decimal128|Int64|ResolvesToNumber|float|int $expression */
public readonly Decimal128|Int64|ResolvesToNumber|float|int $expression;
@@ -32,9 +35,4 @@ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int $express
{
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$radiansToDegrees';
- }
}
diff --git a/src/Builder/Expression/RandOperator.php b/src/Builder/Expression/RandOperator.php
index dd52b877a..26da27637 100644
--- a/src/Builder/Expression/RandOperator.php
+++ b/src/Builder/Expression/RandOperator.php
@@ -15,17 +15,14 @@
* Returns a random float between 0 and 1
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/rand/
+ * @internal
*/
-class RandOperator implements ResolvesToDouble, OperatorInterface
+final class RandOperator implements ResolvesToDouble, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$rand';
public function __construct()
{
}
-
- public function getOperator(): string
- {
- return '$rand';
- }
}
diff --git a/src/Builder/Expression/RangeOperator.php b/src/Builder/Expression/RangeOperator.php
index d3d243188..cbb0e32e7 100644
--- a/src/Builder/Expression/RangeOperator.php
+++ b/src/Builder/Expression/RangeOperator.php
@@ -16,10 +16,13 @@
* Outputs an array containing a sequence of integers according to user-defined inputs.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/range/
+ * @internal
*/
-class RangeOperator implements ResolvesToArray, OperatorInterface
+final class RangeOperator implements ResolvesToArray, OperatorInterface
{
public const ENCODE = Encode::Array;
+ public const NAME = '$range';
+ public const PROPERTIES = ['start' => 'start', 'end' => 'end', 'step' => 'step'];
/** @var ResolvesToInt|int $start An integer that specifies the start of the sequence. Can be any valid expression that resolves to an integer. */
public readonly ResolvesToInt|int $start;
@@ -44,9 +47,4 @@ public function __construct(
$this->end = $end;
$this->step = $step;
}
-
- public function getOperator(): string
- {
- return '$range';
- }
}
diff --git a/src/Builder/Expression/ReduceOperator.php b/src/Builder/Expression/ReduceOperator.php
index f57ef2dac..c35b2b530 100644
--- a/src/Builder/Expression/ReduceOperator.php
+++ b/src/Builder/Expression/ReduceOperator.php
@@ -24,10 +24,13 @@
* 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/
+ * @internal
*/
-class ReduceOperator implements ResolvesToAny, OperatorInterface
+final class ReduceOperator implements ResolvesToAny, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$reduce';
+ public const PROPERTIES = ['input' => 'input', 'initialValue' => 'initialValue', 'in' => 'in'];
/**
* @var BSONArray|PackedArray|ResolvesToArray|array $input Can be any valid expression that resolves to an array.
@@ -70,9 +73,4 @@ public function __construct(
$this->initialValue = $initialValue;
$this->in = $in;
}
-
- public function getOperator(): string
- {
- return '$reduce';
- }
}
diff --git a/src/Builder/Expression/RegexFindAllOperator.php b/src/Builder/Expression/RegexFindAllOperator.php
index e4d2a8d0d..e6e36a9fb 100644
--- a/src/Builder/Expression/RegexFindAllOperator.php
+++ b/src/Builder/Expression/RegexFindAllOperator.php
@@ -18,10 +18,13 @@
* New in MongoDB 4.2.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/regexFindAll/
+ * @internal
*/
-class RegexFindAllOperator implements ResolvesToArray, OperatorInterface
+final class RegexFindAllOperator implements ResolvesToArray, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$regexFindAll';
+ public const PROPERTIES = ['input' => 'input', 'regex' => 'regex', 'options' => 'options'];
/** @var ResolvesToString|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. */
public readonly ResolvesToString|string $input;
@@ -46,9 +49,4 @@ public function __construct(
$this->regex = $regex;
$this->options = $options;
}
-
- public function getOperator(): string
- {
- return '$regexFindAll';
- }
}
diff --git a/src/Builder/Expression/RegexFindOperator.php b/src/Builder/Expression/RegexFindOperator.php
index 0b5f30f08..81f713f35 100644
--- a/src/Builder/Expression/RegexFindOperator.php
+++ b/src/Builder/Expression/RegexFindOperator.php
@@ -18,10 +18,13 @@
* New in MongoDB 4.2.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/regexFind/
+ * @internal
*/
-class RegexFindOperator implements ResolvesToObject, OperatorInterface
+final class RegexFindOperator implements ResolvesToObject, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$regexFind';
+ public const PROPERTIES = ['input' => 'input', 'regex' => 'regex', 'options' => 'options'];
/** @var ResolvesToString|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. */
public readonly ResolvesToString|string $input;
@@ -46,9 +49,4 @@ public function __construct(
$this->regex = $regex;
$this->options = $options;
}
-
- public function getOperator(): string
- {
- return '$regexFind';
- }
}
diff --git a/src/Builder/Expression/RegexMatchOperator.php b/src/Builder/Expression/RegexMatchOperator.php
index ed9707b53..50fbb1766 100644
--- a/src/Builder/Expression/RegexMatchOperator.php
+++ b/src/Builder/Expression/RegexMatchOperator.php
@@ -18,10 +18,13 @@
* New in MongoDB 4.2.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/regexMatch/
+ * @internal
*/
-class RegexMatchOperator implements ResolvesToBool, OperatorInterface
+final class RegexMatchOperator implements ResolvesToBool, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$regexMatch';
+ public const PROPERTIES = ['input' => 'input', 'regex' => 'regex', 'options' => 'options'];
/** @var ResolvesToString|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. */
public readonly ResolvesToString|string $input;
@@ -46,9 +49,4 @@ public function __construct(
$this->regex = $regex;
$this->options = $options;
}
-
- public function getOperator(): string
- {
- return '$regexMatch';
- }
}
diff --git a/src/Builder/Expression/ReplaceAllOperator.php b/src/Builder/Expression/ReplaceAllOperator.php
index d2fa2a602..14cfb17ea 100644
--- a/src/Builder/Expression/ReplaceAllOperator.php
+++ b/src/Builder/Expression/ReplaceAllOperator.php
@@ -17,10 +17,13 @@
* New in MongoDB 4.4.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceAll/
+ * @internal
*/
-class ReplaceAllOperator implements ResolvesToString, OperatorInterface
+final class ReplaceAllOperator implements ResolvesToString, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$replaceAll';
+ public const PROPERTIES = ['input' => 'input', 'find' => 'find', 'replacement' => 'replacement'];
/** @var ResolvesToNull|ResolvesToString|null|string $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. */
public readonly ResolvesToNull|ResolvesToString|null|string $input;
@@ -45,9 +48,4 @@ public function __construct(
$this->find = $find;
$this->replacement = $replacement;
}
-
- public function getOperator(): string
- {
- return '$replaceAll';
- }
}
diff --git a/src/Builder/Expression/ReplaceOneOperator.php b/src/Builder/Expression/ReplaceOneOperator.php
index 609a0060d..0237aacc0 100644
--- a/src/Builder/Expression/ReplaceOneOperator.php
+++ b/src/Builder/Expression/ReplaceOneOperator.php
@@ -16,10 +16,13 @@
* New in MongoDB 4.4.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceOne/
+ * @internal
*/
-class ReplaceOneOperator implements ResolvesToString, OperatorInterface
+final class ReplaceOneOperator implements ResolvesToString, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$replaceOne';
+ public const PROPERTIES = ['input' => 'input', 'find' => 'find', 'replacement' => 'replacement'];
/** @var ResolvesToNull|ResolvesToString|null|string $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. */
public readonly ResolvesToNull|ResolvesToString|null|string $input;
@@ -44,9 +47,4 @@ public function __construct(
$this->find = $find;
$this->replacement = $replacement;
}
-
- public function getOperator(): string
- {
- return '$replaceOne';
- }
}
diff --git a/src/Builder/Expression/ReverseArrayOperator.php b/src/Builder/Expression/ReverseArrayOperator.php
index c5bca62b4..be6a910d4 100644
--- a/src/Builder/Expression/ReverseArrayOperator.php
+++ b/src/Builder/Expression/ReverseArrayOperator.php
@@ -21,10 +21,13 @@
* Returns an array with the elements in reverse order.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/reverseArray/
+ * @internal
*/
-class ReverseArrayOperator implements ResolvesToArray, OperatorInterface
+final class ReverseArrayOperator implements ResolvesToArray, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$reverseArray';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var BSONArray|PackedArray|ResolvesToArray|array $expression The argument can be any valid expression as long as it resolves to an array. */
public readonly PackedArray|ResolvesToArray|BSONArray|array $expression;
@@ -40,9 +43,4 @@ public function __construct(PackedArray|ResolvesToArray|BSONArray|array $express
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$reverseArray';
- }
}
diff --git a/src/Builder/Expression/RoundOperator.php b/src/Builder/Expression/RoundOperator.php
index 323ae99eb..21638126d 100644
--- a/src/Builder/Expression/RoundOperator.php
+++ b/src/Builder/Expression/RoundOperator.php
@@ -18,10 +18,13 @@
* Rounds a number to a whole integer or to a specified decimal place.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/round/
+ * @internal
*/
-class RoundOperator implements ResolvesToInt, ResolvesToDouble, ResolvesToDecimal, ResolvesToLong, OperatorInterface
+final class RoundOperator implements ResolvesToInt, ResolvesToDouble, ResolvesToDecimal, ResolvesToLong, OperatorInterface
{
public const ENCODE = Encode::Array;
+ public const NAME = '$round';
+ public const PROPERTIES = ['number' => 'number', 'place' => 'place'];
/**
* @var 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.
@@ -44,9 +47,4 @@ public function __construct(
$this->number = $number;
$this->place = $place;
}
-
- public function getOperator(): string
- {
- return '$round';
- }
}
diff --git a/src/Builder/Expression/RtrimOperator.php b/src/Builder/Expression/RtrimOperator.php
index f9a6bc145..46824f98a 100644
--- a/src/Builder/Expression/RtrimOperator.php
+++ b/src/Builder/Expression/RtrimOperator.php
@@ -16,10 +16,13 @@
* 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/
+ * @internal
*/
-class RtrimOperator implements ResolvesToString, OperatorInterface
+final class RtrimOperator implements ResolvesToString, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$rtrim';
+ public const PROPERTIES = ['input' => 'input', 'chars' => 'chars'];
/** @var ResolvesToString|string $input The string to trim. The argument can be any valid expression that resolves to a string. */
public readonly ResolvesToString|string $input;
@@ -44,9 +47,4 @@ public function __construct(
$this->input = $input;
$this->chars = $chars;
}
-
- public function getOperator(): string
- {
- return '$rtrim';
- }
}
diff --git a/src/Builder/Expression/SecondOperator.php b/src/Builder/Expression/SecondOperator.php
index 4c9da6db6..720d57a92 100644
--- a/src/Builder/Expression/SecondOperator.php
+++ b/src/Builder/Expression/SecondOperator.php
@@ -19,10 +19,13 @@
* 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/
+ * @internal
*/
-class SecondOperator implements ResolvesToInt, OperatorInterface
+final class SecondOperator implements ResolvesToInt, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$second';
+ public const PROPERTIES = ['date' => 'date', 'timezone' => 'timezone'];
/** @var 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 readonly ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date;
@@ -41,9 +44,4 @@ public function __construct(
$this->date = $date;
$this->timezone = $timezone;
}
-
- public function getOperator(): string
- {
- return '$second';
- }
}
diff --git a/src/Builder/Expression/SetDifferenceOperator.php b/src/Builder/Expression/SetDifferenceOperator.php
index ec7e4ff60..2b4fde506 100644
--- a/src/Builder/Expression/SetDifferenceOperator.php
+++ b/src/Builder/Expression/SetDifferenceOperator.php
@@ -21,10 +21,13 @@
* 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/
+ * @internal
*/
-class SetDifferenceOperator implements ResolvesToArray, OperatorInterface
+final class SetDifferenceOperator implements ResolvesToArray, OperatorInterface
{
public const ENCODE = Encode::Array;
+ public const NAME = '$setDifference';
+ public const PROPERTIES = ['expression1' => 'expression1', 'expression2' => 'expression2'];
/** @var BSONArray|PackedArray|ResolvesToArray|array $expression1 The arguments can be any valid expression as long as they each resolve to an array. */
public readonly PackedArray|ResolvesToArray|BSONArray|array $expression1;
@@ -51,9 +54,4 @@ public function __construct(
$this->expression2 = $expression2;
}
-
- public function getOperator(): string
- {
- return '$setDifference';
- }
}
diff --git a/src/Builder/Expression/SetEqualsOperator.php b/src/Builder/Expression/SetEqualsOperator.php
index 051da408d..b7eca0089 100644
--- a/src/Builder/Expression/SetEqualsOperator.php
+++ b/src/Builder/Expression/SetEqualsOperator.php
@@ -20,10 +20,13 @@
* 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/
+ * @internal
*/
-class SetEqualsOperator implements ResolvesToBool, OperatorInterface
+final class SetEqualsOperator implements ResolvesToBool, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$setEquals';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var list $expression */
public readonly array $expression;
@@ -44,9 +47,4 @@ public function __construct(PackedArray|ResolvesToArray|BSONArray|array ...$expr
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$setEquals';
- }
}
diff --git a/src/Builder/Expression/SetFieldOperator.php b/src/Builder/Expression/SetFieldOperator.php
index f4449ded1..08559253e 100644
--- a/src/Builder/Expression/SetFieldOperator.php
+++ b/src/Builder/Expression/SetFieldOperator.php
@@ -21,10 +21,13 @@
* New in MongoDB 5.0.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/setField/
+ * @internal
*/
-class SetFieldOperator implements ResolvesToObject, OperatorInterface
+final class SetFieldOperator implements ResolvesToObject, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$setField';
+ public const PROPERTIES = ['field' => 'field', 'input' => 'input', 'value' => 'value'];
/** @var ResolvesToString|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 readonly ResolvesToString|string $field;
@@ -53,9 +56,4 @@ public function __construct(
$this->input = $input;
$this->value = $value;
}
-
- public function getOperator(): string
- {
- return '$setField';
- }
}
diff --git a/src/Builder/Expression/SetIntersectionOperator.php b/src/Builder/Expression/SetIntersectionOperator.php
index 42e3257d6..3ec2c03dd 100644
--- a/src/Builder/Expression/SetIntersectionOperator.php
+++ b/src/Builder/Expression/SetIntersectionOperator.php
@@ -20,10 +20,13 @@
* 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/
+ * @internal
*/
-class SetIntersectionOperator implements ResolvesToArray, OperatorInterface
+final class SetIntersectionOperator implements ResolvesToArray, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$setIntersection';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var list $expression */
public readonly array $expression;
@@ -44,9 +47,4 @@ public function __construct(PackedArray|ResolvesToArray|BSONArray|array ...$expr
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$setIntersection';
- }
}
diff --git a/src/Builder/Expression/SetIsSubsetOperator.php b/src/Builder/Expression/SetIsSubsetOperator.php
index cf2011a0e..76263d138 100644
--- a/src/Builder/Expression/SetIsSubsetOperator.php
+++ b/src/Builder/Expression/SetIsSubsetOperator.php
@@ -21,10 +21,13 @@
* 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/
+ * @internal
*/
-class SetIsSubsetOperator implements ResolvesToBool, OperatorInterface
+final class SetIsSubsetOperator implements ResolvesToBool, OperatorInterface
{
public const ENCODE = Encode::Array;
+ public const NAME = '$setIsSubset';
+ public const PROPERTIES = ['expression1' => 'expression1', 'expression2' => 'expression2'];
/** @var BSONArray|PackedArray|ResolvesToArray|array $expression1 */
public readonly PackedArray|ResolvesToArray|BSONArray|array $expression1;
@@ -51,9 +54,4 @@ public function __construct(
$this->expression2 = $expression2;
}
-
- public function getOperator(): string
- {
- return '$setIsSubset';
- }
}
diff --git a/src/Builder/Expression/SetUnionOperator.php b/src/Builder/Expression/SetUnionOperator.php
index 80080fc5a..62f2cb871 100644
--- a/src/Builder/Expression/SetUnionOperator.php
+++ b/src/Builder/Expression/SetUnionOperator.php
@@ -20,10 +20,13 @@
* Returns a set with elements that appear in any of the input sets.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/setUnion/
+ * @internal
*/
-class SetUnionOperator implements ResolvesToArray, OperatorInterface
+final class SetUnionOperator implements ResolvesToArray, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$setUnion';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var list $expression */
public readonly array $expression;
@@ -44,9 +47,4 @@ public function __construct(PackedArray|ResolvesToArray|BSONArray|array ...$expr
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$setUnion';
- }
}
diff --git a/src/Builder/Expression/SinOperator.php b/src/Builder/Expression/SinOperator.php
index 1976065f1..9ba0d998e 100644
--- a/src/Builder/Expression/SinOperator.php
+++ b/src/Builder/Expression/SinOperator.php
@@ -17,10 +17,13 @@
* Returns the sine of a value that is measured in radians.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/sin/
+ * @internal
*/
-class SinOperator implements ResolvesToDouble, ResolvesToDecimal, OperatorInterface
+final class SinOperator implements ResolvesToDouble, ResolvesToDecimal, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$sin';
+ public const PROPERTIES = ['expression' => 'expression'];
/**
* @var 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.
@@ -36,9 +39,4 @@ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int $express
{
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$sin';
- }
}
diff --git a/src/Builder/Expression/SinhOperator.php b/src/Builder/Expression/SinhOperator.php
index de97f2c8c..e04ff231d 100644
--- a/src/Builder/Expression/SinhOperator.php
+++ b/src/Builder/Expression/SinhOperator.php
@@ -17,10 +17,13 @@
* Returns the hyperbolic sine of a value that is measured in radians.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/sinh/
+ * @internal
*/
-class SinhOperator implements ResolvesToDouble, ResolvesToDecimal, OperatorInterface
+final class SinhOperator implements ResolvesToDouble, ResolvesToDecimal, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$sinh';
+ public const PROPERTIES = ['expression' => 'expression'];
/**
* @var 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.
@@ -36,9 +39,4 @@ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int $express
{
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$sinh';
- }
}
diff --git a/src/Builder/Expression/SizeOperator.php b/src/Builder/Expression/SizeOperator.php
index 5ea541226..7ff3b83f7 100644
--- a/src/Builder/Expression/SizeOperator.php
+++ b/src/Builder/Expression/SizeOperator.php
@@ -21,10 +21,13 @@
* 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/
+ * @internal
*/
-class SizeOperator implements ResolvesToInt, OperatorInterface
+final class SizeOperator implements ResolvesToInt, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$size';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var BSONArray|PackedArray|ResolvesToArray|array $expression The argument for $size can be any expression as long as it resolves to an array. */
public readonly PackedArray|ResolvesToArray|BSONArray|array $expression;
@@ -40,9 +43,4 @@ public function __construct(PackedArray|ResolvesToArray|BSONArray|array $express
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$size';
- }
}
diff --git a/src/Builder/Expression/SliceOperator.php b/src/Builder/Expression/SliceOperator.php
index df9172133..220810428 100644
--- a/src/Builder/Expression/SliceOperator.php
+++ b/src/Builder/Expression/SliceOperator.php
@@ -22,10 +22,13 @@
* Returns a subset of an array.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/slice/
+ * @internal
*/
-class SliceOperator implements ResolvesToArray, OperatorInterface
+final class SliceOperator implements ResolvesToArray, OperatorInterface
{
public const ENCODE = Encode::Array;
+ public const NAME = '$slice';
+ public const PROPERTIES = ['expression' => 'expression', 'n' => 'n', 'position' => 'position'];
/** @var BSONArray|PackedArray|ResolvesToArray|array $expression Any valid expression as long as it resolves to an array. */
public readonly PackedArray|ResolvesToArray|BSONArray|array $expression;
@@ -66,9 +69,4 @@ public function __construct(
$this->n = $n;
$this->position = $position;
}
-
- public function getOperator(): string
- {
- return '$slice';
- }
}
diff --git a/src/Builder/Expression/SortArrayOperator.php b/src/Builder/Expression/SortArrayOperator.php
index 983408432..b58e2b65e 100644
--- a/src/Builder/Expression/SortArrayOperator.php
+++ b/src/Builder/Expression/SortArrayOperator.php
@@ -25,10 +25,13 @@
* Sorts the elements of an array.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/sortArray/
+ * @internal
*/
-class SortArrayOperator implements ResolvesToArray, OperatorInterface
+final class SortArrayOperator implements ResolvesToArray, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$sortArray';
+ public const PROPERTIES = ['input' => 'input', 'sortBy' => 'sortBy'];
/**
* @var BSONArray|PackedArray|ResolvesToArray|array $input The array to be sorted.
@@ -57,9 +60,4 @@ public function __construct(
$this->input = $input;
$this->sortBy = $sortBy;
}
-
- public function getOperator(): string
- {
- return '$sortArray';
- }
}
diff --git a/src/Builder/Expression/SplitOperator.php b/src/Builder/Expression/SplitOperator.php
index 6453cbfe5..2e54ef5a5 100644
--- a/src/Builder/Expression/SplitOperator.php
+++ b/src/Builder/Expression/SplitOperator.php
@@ -15,10 +15,13 @@
* 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/
+ * @internal
*/
-class SplitOperator implements ResolvesToArray, OperatorInterface
+final class SplitOperator implements ResolvesToArray, OperatorInterface
{
public const ENCODE = Encode::Array;
+ public const NAME = '$split';
+ public const PROPERTIES = ['string' => 'string', 'delimiter' => 'delimiter'];
/** @var ResolvesToString|string $string The string to be split. string expression can be any valid expression as long as it resolves to a string. */
public readonly ResolvesToString|string $string;
@@ -35,9 +38,4 @@ public function __construct(ResolvesToString|string $string, ResolvesToString|st
$this->string = $string;
$this->delimiter = $delimiter;
}
-
- public function getOperator(): string
- {
- return '$split';
- }
}
diff --git a/src/Builder/Expression/SqrtOperator.php b/src/Builder/Expression/SqrtOperator.php
index e396c986c..90a907ef5 100644
--- a/src/Builder/Expression/SqrtOperator.php
+++ b/src/Builder/Expression/SqrtOperator.php
@@ -17,10 +17,13 @@
* Calculates the square root.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/sqrt/
+ * @internal
*/
-class SqrtOperator implements ResolvesToDouble, OperatorInterface
+final class SqrtOperator implements ResolvesToDouble, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$sqrt';
+ public const PROPERTIES = ['number' => 'number'];
/** @var Decimal128|Int64|ResolvesToNumber|float|int $number The argument can be any valid expression as long as it resolves to a non-negative number. */
public readonly Decimal128|Int64|ResolvesToNumber|float|int $number;
@@ -32,9 +35,4 @@ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int $number)
{
$this->number = $number;
}
-
- public function getOperator(): string
- {
- return '$sqrt';
- }
}
diff --git a/src/Builder/Expression/StdDevPopOperator.php b/src/Builder/Expression/StdDevPopOperator.php
index 3845f7a24..e966f8e84 100644
--- a/src/Builder/Expression/StdDevPopOperator.php
+++ b/src/Builder/Expression/StdDevPopOperator.php
@@ -22,10 +22,13 @@
* Changed in MongoDB 5.0: Available in the $setWindowFields stage.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/stdDevPop/
+ * @internal
*/
-class StdDevPopOperator implements ResolvesToDouble, OperatorInterface
+final class StdDevPopOperator implements ResolvesToDouble, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$stdDevPop';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var list $expression */
public readonly array $expression;
@@ -46,9 +49,4 @@ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int ...$expr
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$stdDevPop';
- }
}
diff --git a/src/Builder/Expression/StdDevSampOperator.php b/src/Builder/Expression/StdDevSampOperator.php
index 3b6a3c0a7..1c897728b 100644
--- a/src/Builder/Expression/StdDevSampOperator.php
+++ b/src/Builder/Expression/StdDevSampOperator.php
@@ -21,10 +21,13 @@
* If the values represent the entire population of data or you do not wish to generalize about a larger population, use $stdDevPop instead.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/stdDevSamp/
+ * @internal
*/
-class StdDevSampOperator implements ResolvesToDouble, OperatorInterface
+final class StdDevSampOperator implements ResolvesToDouble, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$stdDevSamp';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var list $expression */
public readonly array $expression;
@@ -45,9 +48,4 @@ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int ...$expr
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$stdDevSamp';
- }
}
diff --git a/src/Builder/Expression/StrLenBytesOperator.php b/src/Builder/Expression/StrLenBytesOperator.php
index 1f859fce9..39ae8dbe8 100644
--- a/src/Builder/Expression/StrLenBytesOperator.php
+++ b/src/Builder/Expression/StrLenBytesOperator.php
@@ -15,10 +15,13 @@
* Returns the number of UTF-8 encoded bytes in a string.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/strLenBytes/
+ * @internal
*/
-class StrLenBytesOperator implements ResolvesToInt, OperatorInterface
+final class StrLenBytesOperator implements ResolvesToInt, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$strLenBytes';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var ResolvesToString|string $expression */
public readonly ResolvesToString|string $expression;
@@ -30,9 +33,4 @@ public function __construct(ResolvesToString|string $expression)
{
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$strLenBytes';
- }
}
diff --git a/src/Builder/Expression/StrLenCPOperator.php b/src/Builder/Expression/StrLenCPOperator.php
index 7b63f98ff..8add7c3f8 100644
--- a/src/Builder/Expression/StrLenCPOperator.php
+++ b/src/Builder/Expression/StrLenCPOperator.php
@@ -15,10 +15,13 @@
* Returns the number of UTF-8 code points in a string.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/strLenCP/
+ * @internal
*/
-class StrLenCPOperator implements ResolvesToInt, OperatorInterface
+final class StrLenCPOperator implements ResolvesToInt, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$strLenCP';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var ResolvesToString|string $expression */
public readonly ResolvesToString|string $expression;
@@ -30,9 +33,4 @@ public function __construct(ResolvesToString|string $expression)
{
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$strLenCP';
- }
}
diff --git a/src/Builder/Expression/StrcasecmpOperator.php b/src/Builder/Expression/StrcasecmpOperator.php
index ff6f54423..efcb0e41b 100644
--- a/src/Builder/Expression/StrcasecmpOperator.php
+++ b/src/Builder/Expression/StrcasecmpOperator.php
@@ -15,10 +15,13 @@
* 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/
+ * @internal
*/
-class StrcasecmpOperator implements ResolvesToInt, OperatorInterface
+final class StrcasecmpOperator implements ResolvesToInt, OperatorInterface
{
public const ENCODE = Encode::Array;
+ public const NAME = '$strcasecmp';
+ public const PROPERTIES = ['expression1' => 'expression1', 'expression2' => 'expression2'];
/** @var ResolvesToString|string $expression1 */
public readonly ResolvesToString|string $expression1;
@@ -35,9 +38,4 @@ public function __construct(ResolvesToString|string $expression1, ResolvesToStri
$this->expression1 = $expression1;
$this->expression2 = $expression2;
}
-
- public function getOperator(): string
- {
- return '$strcasecmp';
- }
}
diff --git a/src/Builder/Expression/SubstrBytesOperator.php b/src/Builder/Expression/SubstrBytesOperator.php
index 3ff54354c..72d5ee8c5 100644
--- a/src/Builder/Expression/SubstrBytesOperator.php
+++ b/src/Builder/Expression/SubstrBytesOperator.php
@@ -15,10 +15,13 @@
* 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/
+ * @internal
*/
-class SubstrBytesOperator implements ResolvesToString, OperatorInterface
+final class SubstrBytesOperator implements ResolvesToString, OperatorInterface
{
public const ENCODE = Encode::Array;
+ public const NAME = '$substrBytes';
+ public const PROPERTIES = ['string' => 'string', 'start' => 'start', 'length' => 'length'];
/** @var ResolvesToString|string $string */
public readonly ResolvesToString|string $string;
@@ -40,9 +43,4 @@ public function __construct(ResolvesToString|string $string, ResolvesToInt|int $
$this->start = $start;
$this->length = $length;
}
-
- public function getOperator(): string
- {
- return '$substrBytes';
- }
}
diff --git a/src/Builder/Expression/SubstrCPOperator.php b/src/Builder/Expression/SubstrCPOperator.php
index 85baea910..ee01339d2 100644
--- a/src/Builder/Expression/SubstrCPOperator.php
+++ b/src/Builder/Expression/SubstrCPOperator.php
@@ -15,10 +15,13 @@
* 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/
+ * @internal
*/
-class SubstrCPOperator implements ResolvesToString, OperatorInterface
+final class SubstrCPOperator implements ResolvesToString, OperatorInterface
{
public const ENCODE = Encode::Array;
+ public const NAME = '$substrCP';
+ public const PROPERTIES = ['string' => 'string', 'start' => 'start', 'length' => 'length'];
/** @var ResolvesToString|string $string */
public readonly ResolvesToString|string $string;
@@ -40,9 +43,4 @@ public function __construct(ResolvesToString|string $string, ResolvesToInt|int $
$this->start = $start;
$this->length = $length;
}
-
- public function getOperator(): string
- {
- return '$substrCP';
- }
}
diff --git a/src/Builder/Expression/SubstrOperator.php b/src/Builder/Expression/SubstrOperator.php
index 9ef174060..10ece1704 100644
--- a/src/Builder/Expression/SubstrOperator.php
+++ b/src/Builder/Expression/SubstrOperator.php
@@ -15,10 +15,13 @@
* Deprecated. Use $substrBytes or $substrCP.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/substr/
+ * @internal
*/
-class SubstrOperator implements ResolvesToString, OperatorInterface
+final class SubstrOperator implements ResolvesToString, OperatorInterface
{
public const ENCODE = Encode::Array;
+ public const NAME = '$substr';
+ public const PROPERTIES = ['string' => 'string', 'start' => 'start', 'length' => 'length'];
/** @var ResolvesToString|string $string */
public readonly ResolvesToString|string $string;
@@ -40,9 +43,4 @@ public function __construct(ResolvesToString|string $string, ResolvesToInt|int $
$this->start = $start;
$this->length = $length;
}
-
- public function getOperator(): string
- {
- return '$substr';
- }
}
diff --git a/src/Builder/Expression/SubtractOperator.php b/src/Builder/Expression/SubtractOperator.php
index b8cf78387..8a7187b78 100644
--- a/src/Builder/Expression/SubtractOperator.php
+++ b/src/Builder/Expression/SubtractOperator.php
@@ -18,10 +18,13 @@
* 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/
+ * @internal
*/
-class SubtractOperator implements ResolvesToInt, ResolvesToLong, ResolvesToDouble, ResolvesToDecimal, ResolvesToDate, OperatorInterface
+final class SubtractOperator implements ResolvesToInt, ResolvesToLong, ResolvesToDouble, ResolvesToDecimal, ResolvesToDate, OperatorInterface
{
public const ENCODE = Encode::Array;
+ public const NAME = '$subtract';
+ public const PROPERTIES = ['expression1' => 'expression1', 'expression2' => 'expression2'];
/** @var Decimal128|Int64|ResolvesToDate|ResolvesToNumber|UTCDateTime|float|int $expression1 */
public readonly Decimal128|Int64|UTCDateTime|ResolvesToDate|ResolvesToNumber|float|int $expression1;
@@ -40,9 +43,4 @@ public function __construct(
$this->expression1 = $expression1;
$this->expression2 = $expression2;
}
-
- public function getOperator(): string
- {
- return '$subtract';
- }
}
diff --git a/src/Builder/Expression/SumOperator.php b/src/Builder/Expression/SumOperator.php
index dde3535ee..99d90de28 100644
--- a/src/Builder/Expression/SumOperator.php
+++ b/src/Builder/Expression/SumOperator.php
@@ -23,10 +23,13 @@
* Changed in MongoDB 5.0: Available in the $setWindowFields stage.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/sum/
+ * @internal
*/
-class SumOperator implements ResolvesToNumber, OperatorInterface
+final class SumOperator implements ResolvesToNumber, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$sum';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var list $expression */
public readonly array $expression;
@@ -48,9 +51,4 @@ public function __construct(
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$sum';
- }
}
diff --git a/src/Builder/Expression/SwitchOperator.php b/src/Builder/Expression/SwitchOperator.php
index 3545477ea..4179a5d52 100644
--- a/src/Builder/Expression/SwitchOperator.php
+++ b/src/Builder/Expression/SwitchOperator.php
@@ -25,10 +25,13 @@
* 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/
+ * @internal
*/
-class SwitchOperator implements ResolvesToAny, OperatorInterface
+final class SwitchOperator implements ResolvesToAny, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$switch';
+ public const PROPERTIES = ['branches' => 'branches', 'default' => 'default'];
/**
* @var BSONArray|PackedArray|array $branches An array of control branch documents. Each branch is a document with the following fields:
@@ -63,9 +66,4 @@ public function __construct(
$this->branches = $branches;
$this->default = $default;
}
-
- public function getOperator(): string
- {
- return '$switch';
- }
}
diff --git a/src/Builder/Expression/TanOperator.php b/src/Builder/Expression/TanOperator.php
index 75bc2e00a..bab27a3a5 100644
--- a/src/Builder/Expression/TanOperator.php
+++ b/src/Builder/Expression/TanOperator.php
@@ -17,10 +17,13 @@
* Returns the tangent of a value that is measured in radians.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/tan/
+ * @internal
*/
-class TanOperator implements ResolvesToDouble, ResolvesToDecimal, OperatorInterface
+final class TanOperator implements ResolvesToDouble, ResolvesToDecimal, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$tan';
+ public const PROPERTIES = ['expression' => 'expression'];
/**
* @var 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.
@@ -36,9 +39,4 @@ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int $express
{
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$tan';
- }
}
diff --git a/src/Builder/Expression/TanhOperator.php b/src/Builder/Expression/TanhOperator.php
index d78a3d42b..5e31a67d1 100644
--- a/src/Builder/Expression/TanhOperator.php
+++ b/src/Builder/Expression/TanhOperator.php
@@ -17,10 +17,13 @@
* Returns the hyperbolic tangent of a value that is measured in radians.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/tanh/
+ * @internal
*/
-class TanhOperator implements ResolvesToDouble, ResolvesToDecimal, OperatorInterface
+final class TanhOperator implements ResolvesToDouble, ResolvesToDecimal, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$tanh';
+ public const PROPERTIES = ['expression' => 'expression'];
/**
* @var 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.
@@ -36,9 +39,4 @@ public function __construct(Decimal128|Int64|ResolvesToNumber|float|int $express
{
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$tanh';
- }
}
diff --git a/src/Builder/Expression/ToBoolOperator.php b/src/Builder/Expression/ToBoolOperator.php
index 2986fc8d3..15416abc6 100644
--- a/src/Builder/Expression/ToBoolOperator.php
+++ b/src/Builder/Expression/ToBoolOperator.php
@@ -19,10 +19,13 @@
* New in MongoDB 4.0.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toBool/
+ * @internal
*/
-class ToBoolOperator implements ResolvesToBool, OperatorInterface
+final class ToBoolOperator implements ResolvesToBool, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$toBool';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */
public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression;
@@ -34,9 +37,4 @@ public function __construct(Type|ExpressionInterface|stdClass|array|bool|float|i
{
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$toBool';
- }
}
diff --git a/src/Builder/Expression/ToDateOperator.php b/src/Builder/Expression/ToDateOperator.php
index d6ff4b2bd..10e36c4af 100644
--- a/src/Builder/Expression/ToDateOperator.php
+++ b/src/Builder/Expression/ToDateOperator.php
@@ -19,10 +19,13 @@
* New in MongoDB 4.0.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toDate/
+ * @internal
*/
-class ToDateOperator implements ResolvesToDate, OperatorInterface
+final class ToDateOperator implements ResolvesToDate, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$toDate';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */
public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression;
@@ -34,9 +37,4 @@ public function __construct(Type|ExpressionInterface|stdClass|array|bool|float|i
{
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$toDate';
- }
}
diff --git a/src/Builder/Expression/ToDecimalOperator.php b/src/Builder/Expression/ToDecimalOperator.php
index d8dd60379..a10075ef6 100644
--- a/src/Builder/Expression/ToDecimalOperator.php
+++ b/src/Builder/Expression/ToDecimalOperator.php
@@ -19,10 +19,13 @@
* New in MongoDB 4.0.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toDecimal/
+ * @internal
*/
-class ToDecimalOperator implements ResolvesToDecimal, OperatorInterface
+final class ToDecimalOperator implements ResolvesToDecimal, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$toDecimal';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */
public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression;
@@ -34,9 +37,4 @@ public function __construct(Type|ExpressionInterface|stdClass|array|bool|float|i
{
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$toDecimal';
- }
}
diff --git a/src/Builder/Expression/ToDoubleOperator.php b/src/Builder/Expression/ToDoubleOperator.php
index a21fe9ad5..0b90d8732 100644
--- a/src/Builder/Expression/ToDoubleOperator.php
+++ b/src/Builder/Expression/ToDoubleOperator.php
@@ -19,10 +19,13 @@
* New in MongoDB 4.0.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toDouble/
+ * @internal
*/
-class ToDoubleOperator implements ResolvesToDouble, OperatorInterface
+final class ToDoubleOperator implements ResolvesToDouble, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$toDouble';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */
public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression;
@@ -34,9 +37,4 @@ public function __construct(Type|ExpressionInterface|stdClass|array|bool|float|i
{
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$toDouble';
- }
}
diff --git a/src/Builder/Expression/ToHashedIndexKeyOperator.php b/src/Builder/Expression/ToHashedIndexKeyOperator.php
index e3038832a..c6219e0dd 100644
--- a/src/Builder/Expression/ToHashedIndexKeyOperator.php
+++ b/src/Builder/Expression/ToHashedIndexKeyOperator.php
@@ -18,10 +18,13 @@
* Computes and returns the hash value of the input expression using the same hash function that MongoDB uses to create a hashed index. A hash function maps a key or string to a fixed-size numeric value.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toHashedIndexKey/
+ * @internal
*/
-class ToHashedIndexKeyOperator implements ResolvesToLong, OperatorInterface
+final class ToHashedIndexKeyOperator implements ResolvesToLong, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$toHashedIndexKey';
+ public const PROPERTIES = ['value' => 'value'];
/** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $value key or string to hash */
public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $value;
@@ -33,9 +36,4 @@ public function __construct(Type|ExpressionInterface|stdClass|array|bool|float|i
{
$this->value = $value;
}
-
- public function getOperator(): string
- {
- return '$toHashedIndexKey';
- }
}
diff --git a/src/Builder/Expression/ToIntOperator.php b/src/Builder/Expression/ToIntOperator.php
index d03980572..b4cd77f20 100644
--- a/src/Builder/Expression/ToIntOperator.php
+++ b/src/Builder/Expression/ToIntOperator.php
@@ -19,10 +19,13 @@
* New in MongoDB 4.0.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toInt/
+ * @internal
*/
-class ToIntOperator implements ResolvesToInt, OperatorInterface
+final class ToIntOperator implements ResolvesToInt, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$toInt';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */
public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression;
@@ -34,9 +37,4 @@ public function __construct(Type|ExpressionInterface|stdClass|array|bool|float|i
{
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$toInt';
- }
}
diff --git a/src/Builder/Expression/ToLongOperator.php b/src/Builder/Expression/ToLongOperator.php
index 301113251..a386d0c63 100644
--- a/src/Builder/Expression/ToLongOperator.php
+++ b/src/Builder/Expression/ToLongOperator.php
@@ -19,10 +19,13 @@
* New in MongoDB 4.0.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toLong/
+ * @internal
*/
-class ToLongOperator implements ResolvesToLong, OperatorInterface
+final class ToLongOperator implements ResolvesToLong, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$toLong';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */
public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression;
@@ -34,9 +37,4 @@ public function __construct(Type|ExpressionInterface|stdClass|array|bool|float|i
{
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$toLong';
- }
}
diff --git a/src/Builder/Expression/ToLowerOperator.php b/src/Builder/Expression/ToLowerOperator.php
index d680f3296..500605889 100644
--- a/src/Builder/Expression/ToLowerOperator.php
+++ b/src/Builder/Expression/ToLowerOperator.php
@@ -15,10 +15,13 @@
* Converts a string to lowercase. Accepts a single argument expression.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toLower/
+ * @internal
*/
-class ToLowerOperator implements ResolvesToString, OperatorInterface
+final class ToLowerOperator implements ResolvesToString, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$toLower';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var ResolvesToString|string $expression */
public readonly ResolvesToString|string $expression;
@@ -30,9 +33,4 @@ public function __construct(ResolvesToString|string $expression)
{
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$toLower';
- }
}
diff --git a/src/Builder/Expression/ToObjectIdOperator.php b/src/Builder/Expression/ToObjectIdOperator.php
index 8e204f67a..cdc95d275 100644
--- a/src/Builder/Expression/ToObjectIdOperator.php
+++ b/src/Builder/Expression/ToObjectIdOperator.php
@@ -19,10 +19,13 @@
* New in MongoDB 4.0.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toObjectId/
+ * @internal
*/
-class ToObjectIdOperator implements ResolvesToObjectId, OperatorInterface
+final class ToObjectIdOperator implements ResolvesToObjectId, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$toObjectId';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */
public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression;
@@ -34,9 +37,4 @@ public function __construct(Type|ExpressionInterface|stdClass|array|bool|float|i
{
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$toObjectId';
- }
}
diff --git a/src/Builder/Expression/ToStringOperator.php b/src/Builder/Expression/ToStringOperator.php
index c549a6f22..802112cb6 100644
--- a/src/Builder/Expression/ToStringOperator.php
+++ b/src/Builder/Expression/ToStringOperator.php
@@ -19,10 +19,13 @@
* New in MongoDB 4.0.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toString/
+ * @internal
*/
-class ToStringOperator implements ResolvesToString, OperatorInterface
+final class ToStringOperator implements ResolvesToString, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$toString';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */
public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression;
@@ -34,9 +37,4 @@ public function __construct(Type|ExpressionInterface|stdClass|array|bool|float|i
{
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$toString';
- }
}
diff --git a/src/Builder/Expression/ToUpperOperator.php b/src/Builder/Expression/ToUpperOperator.php
index f57c2cbbf..604711964 100644
--- a/src/Builder/Expression/ToUpperOperator.php
+++ b/src/Builder/Expression/ToUpperOperator.php
@@ -15,10 +15,13 @@
* Converts a string to uppercase. Accepts a single argument expression.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/toUpper/
+ * @internal
*/
-class ToUpperOperator implements ResolvesToString, OperatorInterface
+final class ToUpperOperator implements ResolvesToString, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$toUpper';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var ResolvesToString|string $expression */
public readonly ResolvesToString|string $expression;
@@ -30,9 +33,4 @@ public function __construct(ResolvesToString|string $expression)
{
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$toUpper';
- }
}
diff --git a/src/Builder/Expression/TrimOperator.php b/src/Builder/Expression/TrimOperator.php
index def9d3a5a..0b210e467 100644
--- a/src/Builder/Expression/TrimOperator.php
+++ b/src/Builder/Expression/TrimOperator.php
@@ -17,10 +17,13 @@
* New in MongoDB 4.0.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/trim/
+ * @internal
*/
-class TrimOperator implements ResolvesToString, OperatorInterface
+final class TrimOperator implements ResolvesToString, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$trim';
+ public const PROPERTIES = ['input' => 'input', 'chars' => 'chars'];
/** @var ResolvesToString|string $input The string to trim. The argument can be any valid expression that resolves to a string. */
public readonly ResolvesToString|string $input;
@@ -45,9 +48,4 @@ public function __construct(
$this->input = $input;
$this->chars = $chars;
}
-
- public function getOperator(): string
- {
- return '$trim';
- }
}
diff --git a/src/Builder/Expression/TruncOperator.php b/src/Builder/Expression/TruncOperator.php
index 926d2e11a..c6db92b34 100644
--- a/src/Builder/Expression/TruncOperator.php
+++ b/src/Builder/Expression/TruncOperator.php
@@ -18,10 +18,13 @@
* Truncates a number to a whole integer or to a specified decimal place.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/trunc/
+ * @internal
*/
-class TruncOperator implements ResolvesToString, OperatorInterface
+final class TruncOperator implements ResolvesToString, OperatorInterface
{
public const ENCODE = Encode::Array;
+ public const NAME = '$trunc';
+ public const PROPERTIES = ['number' => 'number', 'place' => 'place'];
/**
* @var 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.
@@ -44,9 +47,4 @@ public function __construct(
$this->number = $number;
$this->place = $place;
}
-
- public function getOperator(): string
- {
- return '$trunc';
- }
}
diff --git a/src/Builder/Expression/TsIncrementOperator.php b/src/Builder/Expression/TsIncrementOperator.php
index 3bf5a933a..b39d897bc 100644
--- a/src/Builder/Expression/TsIncrementOperator.php
+++ b/src/Builder/Expression/TsIncrementOperator.php
@@ -17,10 +17,13 @@
* New in MongoDB 5.1.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/tsIncrement/
+ * @internal
*/
-class TsIncrementOperator implements ResolvesToLong, OperatorInterface
+final class TsIncrementOperator implements ResolvesToLong, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$tsIncrement';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var ResolvesToTimestamp|Timestamp|int $expression */
public readonly Timestamp|ResolvesToTimestamp|int $expression;
@@ -32,9 +35,4 @@ public function __construct(Timestamp|ResolvesToTimestamp|int $expression)
{
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$tsIncrement';
- }
}
diff --git a/src/Builder/Expression/TsSecondOperator.php b/src/Builder/Expression/TsSecondOperator.php
index c0dcbe631..71af2b803 100644
--- a/src/Builder/Expression/TsSecondOperator.php
+++ b/src/Builder/Expression/TsSecondOperator.php
@@ -17,10 +17,13 @@
* New in MongoDB 5.1.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/tsSecond/
+ * @internal
*/
-class TsSecondOperator implements ResolvesToLong, OperatorInterface
+final class TsSecondOperator implements ResolvesToLong, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$tsSecond';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var ResolvesToTimestamp|Timestamp|int $expression */
public readonly Timestamp|ResolvesToTimestamp|int $expression;
@@ -32,9 +35,4 @@ public function __construct(Timestamp|ResolvesToTimestamp|int $expression)
{
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$tsSecond';
- }
}
diff --git a/src/Builder/Expression/TypeOperator.php b/src/Builder/Expression/TypeOperator.php
index a65d1dd2e..34457be7c 100644
--- a/src/Builder/Expression/TypeOperator.php
+++ b/src/Builder/Expression/TypeOperator.php
@@ -18,10 +18,13 @@
* Return the BSON data type of the field.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/type/
+ * @internal
*/
-class TypeOperator implements ResolvesToString, OperatorInterface
+final class TypeOperator implements ResolvesToString, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$type';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */
public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression;
@@ -33,9 +36,4 @@ public function __construct(Type|ExpressionInterface|stdClass|array|bool|float|i
{
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$type';
- }
}
diff --git a/src/Builder/Expression/UnsetFieldOperator.php b/src/Builder/Expression/UnsetFieldOperator.php
index 45e9c41e2..6b040e2c4 100644
--- a/src/Builder/Expression/UnsetFieldOperator.php
+++ b/src/Builder/Expression/UnsetFieldOperator.php
@@ -19,10 +19,13 @@
* $unsetField is an alias for $setField using $$REMOVE to remove fields.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/unsetField/
+ * @internal
*/
-class UnsetFieldOperator implements ResolvesToObject, OperatorInterface
+final class UnsetFieldOperator implements ResolvesToObject, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$unsetField';
+ public const PROPERTIES = ['field' => 'field', 'input' => 'input'];
/** @var ResolvesToString|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 readonly ResolvesToString|string $field;
@@ -41,9 +44,4 @@ public function __construct(
$this->field = $field;
$this->input = $input;
}
-
- public function getOperator(): string
- {
- return '$unsetField';
- }
}
diff --git a/src/Builder/Expression/WeekOperator.php b/src/Builder/Expression/WeekOperator.php
index a24ee935d..2d58d0509 100644
--- a/src/Builder/Expression/WeekOperator.php
+++ b/src/Builder/Expression/WeekOperator.php
@@ -19,10 +19,13 @@
* 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/
+ * @internal
*/
-class WeekOperator implements ResolvesToInt, OperatorInterface
+final class WeekOperator implements ResolvesToInt, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$week';
+ public const PROPERTIES = ['date' => 'date', 'timezone' => 'timezone'];
/** @var 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 readonly ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date;
@@ -41,9 +44,4 @@ public function __construct(
$this->date = $date;
$this->timezone = $timezone;
}
-
- public function getOperator(): string
- {
- return '$week';
- }
}
diff --git a/src/Builder/Expression/YearOperator.php b/src/Builder/Expression/YearOperator.php
index c2b869260..57fcb35ae 100644
--- a/src/Builder/Expression/YearOperator.php
+++ b/src/Builder/Expression/YearOperator.php
@@ -19,10 +19,13 @@
* Returns the year for a date as a number (e.g. 2014).
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/year/
+ * @internal
*/
-class YearOperator implements ResolvesToInt, OperatorInterface
+final class YearOperator implements ResolvesToInt, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$year';
+ public const PROPERTIES = ['date' => 'date', 'timezone' => 'timezone'];
/** @var 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 readonly ObjectId|Timestamp|UTCDateTime|ResolvesToDate|ResolvesToObjectId|ResolvesToTimestamp|int $date;
@@ -41,9 +44,4 @@ public function __construct(
$this->date = $date;
$this->timezone = $timezone;
}
-
- public function getOperator(): string
- {
- return '$year';
- }
}
diff --git a/src/Builder/Expression/ZipOperator.php b/src/Builder/Expression/ZipOperator.php
index 0c23bbd4f..742b7e6bf 100644
--- a/src/Builder/Expression/ZipOperator.php
+++ b/src/Builder/Expression/ZipOperator.php
@@ -22,10 +22,13 @@
* Merge two arrays together.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/zip/
+ * @internal
*/
-class ZipOperator implements ResolvesToArray, OperatorInterface
+final class ZipOperator implements ResolvesToArray, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$zip';
+ public const PROPERTIES = ['inputs' => 'inputs', 'useLongestLength' => 'useLongestLength', 'defaults' => 'defaults'];
/**
* @var 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.
@@ -74,9 +77,4 @@ public function __construct(
$this->defaults = $defaults;
}
-
- public function getOperator(): string
- {
- return '$zip';
- }
}
diff --git a/src/Builder/Projection.php b/src/Builder/Projection.php
deleted file mode 100644
index e8e90f7f6..000000000
--- a/src/Builder/Projection.php
+++ /dev/null
@@ -1,22 +0,0 @@
-query = $query;
- }
-
- public function getOperator(): string
- {
- return '$elemMatch';
- }
-}
diff --git a/src/Builder/Projection/FactoryTrait.php b/src/Builder/Projection/FactoryTrait.php
deleted file mode 100644
index 359926ded..000000000
--- a/src/Builder/Projection/FactoryTrait.php
+++ /dev/null
@@ -1,28 +0,0 @@
- 'value'];
/** @var list $value */
public readonly array $value;
@@ -45,9 +48,4 @@ public function __construct(Type|FieldQueryInterface|stdClass|array|bool|float|i
$this->value = $value;
}
-
- public function getOperator(): string
- {
- return '$all';
- }
}
diff --git a/src/Builder/Query/AndOperator.php b/src/Builder/Query/AndOperator.php
index 40337e870..8738591be 100644
--- a/src/Builder/Query/AndOperator.php
+++ b/src/Builder/Query/AndOperator.php
@@ -19,10 +19,13 @@
* 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/
+ * @internal
*/
-class AndOperator implements QueryInterface, OperatorInterface
+final class AndOperator implements QueryInterface, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$and';
+ public const PROPERTIES = ['queries' => 'queries'];
/** @var list $queries */
public readonly array $queries;
@@ -43,9 +46,4 @@ public function __construct(QueryInterface|array ...$queries)
$this->queries = $queries;
}
-
- public function getOperator(): string
- {
- return '$and';
- }
}
diff --git a/src/Builder/Query/BitsAllClearOperator.php b/src/Builder/Query/BitsAllClearOperator.php
index 6f056d30b..072c031bb 100644
--- a/src/Builder/Query/BitsAllClearOperator.php
+++ b/src/Builder/Query/BitsAllClearOperator.php
@@ -23,10 +23,13 @@
* 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/
+ * @internal
*/
-class BitsAllClearOperator implements FieldQueryInterface, OperatorInterface
+final class BitsAllClearOperator implements FieldQueryInterface, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$bitsAllClear';
+ public const PROPERTIES = ['bitmask' => 'bitmask'];
/** @var BSONArray|Binary|PackedArray|array|int|string $bitmask */
public readonly Binary|PackedArray|BSONArray|array|int|string $bitmask;
@@ -42,9 +45,4 @@ public function __construct(Binary|PackedArray|BSONArray|array|int|string $bitma
$this->bitmask = $bitmask;
}
-
- public function getOperator(): string
- {
- return '$bitsAllClear';
- }
}
diff --git a/src/Builder/Query/BitsAllSetOperator.php b/src/Builder/Query/BitsAllSetOperator.php
index 0278b81ee..a90e12f35 100644
--- a/src/Builder/Query/BitsAllSetOperator.php
+++ b/src/Builder/Query/BitsAllSetOperator.php
@@ -23,10 +23,13 @@
* 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/
+ * @internal
*/
-class BitsAllSetOperator implements FieldQueryInterface, OperatorInterface
+final class BitsAllSetOperator implements FieldQueryInterface, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$bitsAllSet';
+ public const PROPERTIES = ['bitmask' => 'bitmask'];
/** @var BSONArray|Binary|PackedArray|array|int|string $bitmask */
public readonly Binary|PackedArray|BSONArray|array|int|string $bitmask;
@@ -42,9 +45,4 @@ public function __construct(Binary|PackedArray|BSONArray|array|int|string $bitma
$this->bitmask = $bitmask;
}
-
- public function getOperator(): string
- {
- return '$bitsAllSet';
- }
}
diff --git a/src/Builder/Query/BitsAnyClearOperator.php b/src/Builder/Query/BitsAnyClearOperator.php
index c2b899ea7..0ae56d93a 100644
--- a/src/Builder/Query/BitsAnyClearOperator.php
+++ b/src/Builder/Query/BitsAnyClearOperator.php
@@ -23,10 +23,13 @@
* 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/
+ * @internal
*/
-class BitsAnyClearOperator implements FieldQueryInterface, OperatorInterface
+final class BitsAnyClearOperator implements FieldQueryInterface, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$bitsAnyClear';
+ public const PROPERTIES = ['bitmask' => 'bitmask'];
/** @var BSONArray|Binary|PackedArray|array|int|string $bitmask */
public readonly Binary|PackedArray|BSONArray|array|int|string $bitmask;
@@ -42,9 +45,4 @@ public function __construct(Binary|PackedArray|BSONArray|array|int|string $bitma
$this->bitmask = $bitmask;
}
-
- public function getOperator(): string
- {
- return '$bitsAnyClear';
- }
}
diff --git a/src/Builder/Query/BitsAnySetOperator.php b/src/Builder/Query/BitsAnySetOperator.php
index 4dcf3c33e..5a202c9d4 100644
--- a/src/Builder/Query/BitsAnySetOperator.php
+++ b/src/Builder/Query/BitsAnySetOperator.php
@@ -23,10 +23,13 @@
* 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/
+ * @internal
*/
-class BitsAnySetOperator implements FieldQueryInterface, OperatorInterface
+final class BitsAnySetOperator implements FieldQueryInterface, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$bitsAnySet';
+ public const PROPERTIES = ['bitmask' => 'bitmask'];
/** @var BSONArray|Binary|PackedArray|array|int|string $bitmask */
public readonly Binary|PackedArray|BSONArray|array|int|string $bitmask;
@@ -42,9 +45,4 @@ public function __construct(Binary|PackedArray|BSONArray|array|int|string $bitma
$this->bitmask = $bitmask;
}
-
- public function getOperator(): string
- {
- return '$bitsAnySet';
- }
}
diff --git a/src/Builder/Query/BoxOperator.php b/src/Builder/Query/BoxOperator.php
index 30a55d1c8..cce9cf8d8 100644
--- a/src/Builder/Query/BoxOperator.php
+++ b/src/Builder/Query/BoxOperator.php
@@ -22,10 +22,13 @@
* 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/
+ * @internal
*/
-class BoxOperator implements GeometryInterface, OperatorInterface
+final class BoxOperator implements GeometryInterface, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$box';
+ public const PROPERTIES = ['value' => 'value'];
/** @var BSONArray|PackedArray|array $value */
public readonly PackedArray|BSONArray|array $value;
@@ -41,9 +44,4 @@ public function __construct(PackedArray|BSONArray|array $value)
$this->value = $value;
}
-
- public function getOperator(): string
- {
- return '$box';
- }
}
diff --git a/src/Builder/Query/CenterOperator.php b/src/Builder/Query/CenterOperator.php
index d5bc395f0..f3a0b890a 100644
--- a/src/Builder/Query/CenterOperator.php
+++ b/src/Builder/Query/CenterOperator.php
@@ -22,10 +22,13 @@
* 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/
+ * @internal
*/
-class CenterOperator implements GeometryInterface, OperatorInterface
+final class CenterOperator implements GeometryInterface, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$center';
+ public const PROPERTIES = ['value' => 'value'];
/** @var BSONArray|PackedArray|array $value */
public readonly PackedArray|BSONArray|array $value;
@@ -41,9 +44,4 @@ public function __construct(PackedArray|BSONArray|array $value)
$this->value = $value;
}
-
- public function getOperator(): string
- {
- return '$center';
- }
}
diff --git a/src/Builder/Query/CenterSphereOperator.php b/src/Builder/Query/CenterSphereOperator.php
index 0975417a9..350f535f0 100644
--- a/src/Builder/Query/CenterSphereOperator.php
+++ b/src/Builder/Query/CenterSphereOperator.php
@@ -22,10 +22,13 @@
* 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/
+ * @internal
*/
-class CenterSphereOperator implements GeometryInterface, OperatorInterface
+final class CenterSphereOperator implements GeometryInterface, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$centerSphere';
+ public const PROPERTIES = ['value' => 'value'];
/** @var BSONArray|PackedArray|array $value */
public readonly PackedArray|BSONArray|array $value;
@@ -41,9 +44,4 @@ public function __construct(PackedArray|BSONArray|array $value)
$this->value = $value;
}
-
- public function getOperator(): string
- {
- return '$centerSphere';
- }
}
diff --git a/src/Builder/Query/CommentOperator.php b/src/Builder/Query/CommentOperator.php
index 121c0e3b6..938498039 100644
--- a/src/Builder/Query/CommentOperator.php
+++ b/src/Builder/Query/CommentOperator.php
@@ -16,10 +16,13 @@
* Adds a comment to a query predicate.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/query/comment/
+ * @internal
*/
-class CommentOperator implements QueryInterface, OperatorInterface
+final class CommentOperator implements QueryInterface, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$comment';
+ public const PROPERTIES = ['comment' => 'comment'];
/** @var string $comment */
public readonly string $comment;
@@ -31,9 +34,4 @@ public function __construct(string $comment)
{
$this->comment = $comment;
}
-
- public function getOperator(): string
- {
- return '$comment';
- }
}
diff --git a/src/Builder/Query/ElemMatchOperator.php b/src/Builder/Query/ElemMatchOperator.php
index 073619874..b2195d269 100644
--- a/src/Builder/Query/ElemMatchOperator.php
+++ b/src/Builder/Query/ElemMatchOperator.php
@@ -22,10 +22,13 @@
* The $elemMatch operator matches documents that contain an array field with at least one element that matches all the specified query criteria.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/query/elemMatch/
+ * @internal
*/
-class ElemMatchOperator implements FieldQueryInterface, OperatorInterface
+final class ElemMatchOperator implements FieldQueryInterface, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$elemMatch';
+ public const PROPERTIES = ['query' => 'query'];
/** @var FieldQueryInterface|QueryInterface|Type|array|bool|float|int|null|stdClass|string $query */
public readonly Type|FieldQueryInterface|QueryInterface|stdClass|array|bool|float|int|null|string $query;
@@ -42,9 +45,4 @@ public function __construct(
$this->query = $query;
}
-
- public function getOperator(): string
- {
- return '$elemMatch';
- }
}
diff --git a/src/Builder/Query/EqOperator.php b/src/Builder/Query/EqOperator.php
index 2dcd605fd..2b38feed8 100644
--- a/src/Builder/Query/EqOperator.php
+++ b/src/Builder/Query/EqOperator.php
@@ -18,10 +18,13 @@
* Matches values that are equal to a specified value.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/query/eq/
+ * @internal
*/
-class EqOperator implements FieldQueryInterface, OperatorInterface
+final class EqOperator implements FieldQueryInterface, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$eq';
+ public const PROPERTIES = ['value' => 'value'];
/** @var Type|array|bool|float|int|null|stdClass|string $value */
public readonly Type|stdClass|array|bool|float|int|null|string $value;
@@ -33,9 +36,4 @@ public function __construct(Type|stdClass|array|bool|float|int|null|string $valu
{
$this->value = $value;
}
-
- public function getOperator(): string
- {
- return '$eq';
- }
}
diff --git a/src/Builder/Query/ExistsOperator.php b/src/Builder/Query/ExistsOperator.php
index 92c04f066..1d0b0a292 100644
--- a/src/Builder/Query/ExistsOperator.php
+++ b/src/Builder/Query/ExistsOperator.php
@@ -16,10 +16,13 @@
* Matches documents that have the specified field.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/query/exists/
+ * @internal
*/
-class ExistsOperator implements FieldQueryInterface, OperatorInterface
+final class ExistsOperator implements FieldQueryInterface, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$exists';
+ public const PROPERTIES = ['exists' => 'exists'];
/** @var bool $exists */
public readonly bool $exists;
@@ -31,9 +34,4 @@ public function __construct(bool $exists = true)
{
$this->exists = $exists;
}
-
- public function getOperator(): string
- {
- return '$exists';
- }
}
diff --git a/src/Builder/Query/ExprOperator.php b/src/Builder/Query/ExprOperator.php
index a6235cb67..9e8350a98 100644
--- a/src/Builder/Query/ExprOperator.php
+++ b/src/Builder/Query/ExprOperator.php
@@ -19,10 +19,13 @@
* Allows use of aggregation expressions within the query language.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/query/expr/
+ * @internal
*/
-class ExprOperator implements QueryInterface, OperatorInterface
+final class ExprOperator implements QueryInterface, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$expr';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */
public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression;
@@ -34,9 +37,4 @@ public function __construct(Type|ExpressionInterface|stdClass|array|bool|float|i
{
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$expr';
- }
}
diff --git a/src/Builder/Query/GeoIntersectsOperator.php b/src/Builder/Query/GeoIntersectsOperator.php
index 2ae07a182..37cad3eae 100644
--- a/src/Builder/Query/GeoIntersectsOperator.php
+++ b/src/Builder/Query/GeoIntersectsOperator.php
@@ -20,10 +20,13 @@
* Selects geometries that intersect with a GeoJSON geometry. The 2dsphere index supports $geoIntersects.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/query/geoIntersects/
+ * @internal
*/
-class GeoIntersectsOperator implements FieldQueryInterface, OperatorInterface
+final class GeoIntersectsOperator implements FieldQueryInterface, OperatorInterface
{
- public const ENCODE = Encode::Single;
+ public const ENCODE = Encode::Object;
+ public const NAME = '$geoIntersects';
+ public const PROPERTIES = ['geometry' => null];
/** @var Document|GeometryInterface|Serializable|array|stdClass $geometry */
public readonly Document|Serializable|GeometryInterface|stdClass|array $geometry;
@@ -35,9 +38,4 @@ public function __construct(Document|Serializable|GeometryInterface|stdClass|arr
{
$this->geometry = $geometry;
}
-
- public function getOperator(): string
- {
- return '$geoIntersects';
- }
}
diff --git a/src/Builder/Query/GeoWithinOperator.php b/src/Builder/Query/GeoWithinOperator.php
index 939e13d4a..258592f00 100644
--- a/src/Builder/Query/GeoWithinOperator.php
+++ b/src/Builder/Query/GeoWithinOperator.php
@@ -20,10 +20,13 @@
* 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/
+ * @internal
*/
-class GeoWithinOperator implements FieldQueryInterface, OperatorInterface
+final class GeoWithinOperator implements FieldQueryInterface, OperatorInterface
{
- public const ENCODE = Encode::Single;
+ public const ENCODE = Encode::Object;
+ public const NAME = '$geoWithin';
+ public const PROPERTIES = ['geometry' => null];
/** @var Document|GeometryInterface|Serializable|array|stdClass $geometry */
public readonly Document|Serializable|GeometryInterface|stdClass|array $geometry;
@@ -35,9 +38,4 @@ public function __construct(Document|Serializable|GeometryInterface|stdClass|arr
{
$this->geometry = $geometry;
}
-
- public function getOperator(): string
- {
- return '$geoWithin';
- }
}
diff --git a/src/Builder/Query/GeometryOperator.php b/src/Builder/Query/GeometryOperator.php
index efdd38a1f..fe52be973 100644
--- a/src/Builder/Query/GeometryOperator.php
+++ b/src/Builder/Query/GeometryOperator.php
@@ -26,10 +26,13 @@
* Specifies a geometry in GeoJSON format to geospatial query operators.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/query/geometry/
+ * @internal
*/
-class GeometryOperator implements GeometryInterface, OperatorInterface
+final class GeometryOperator implements GeometryInterface, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$geometry';
+ public const PROPERTIES = ['type' => 'type', 'coordinates' => 'coordinates', 'crs' => 'crs'];
/** @var string $type */
public readonly string $type;
@@ -58,9 +61,4 @@ public function __construct(
$this->coordinates = $coordinates;
$this->crs = $crs;
}
-
- public function getOperator(): string
- {
- return '$geometry';
- }
}
diff --git a/src/Builder/Query/GtOperator.php b/src/Builder/Query/GtOperator.php
index 31c03e485..5f79cd078 100644
--- a/src/Builder/Query/GtOperator.php
+++ b/src/Builder/Query/GtOperator.php
@@ -18,10 +18,13 @@
* Matches values that are greater than a specified value.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/query/gt/
+ * @internal
*/
-class GtOperator implements FieldQueryInterface, OperatorInterface
+final class GtOperator implements FieldQueryInterface, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$gt';
+ public const PROPERTIES = ['value' => 'value'];
/** @var Type|array|bool|float|int|null|stdClass|string $value */
public readonly Type|stdClass|array|bool|float|int|null|string $value;
@@ -33,9 +36,4 @@ public function __construct(Type|stdClass|array|bool|float|int|null|string $valu
{
$this->value = $value;
}
-
- public function getOperator(): string
- {
- return '$gt';
- }
}
diff --git a/src/Builder/Query/GteOperator.php b/src/Builder/Query/GteOperator.php
index 2ef771f1d..00606e571 100644
--- a/src/Builder/Query/GteOperator.php
+++ b/src/Builder/Query/GteOperator.php
@@ -18,10 +18,13 @@
* Matches values that are greater than or equal to a specified value.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/query/gte/
+ * @internal
*/
-class GteOperator implements FieldQueryInterface, OperatorInterface
+final class GteOperator implements FieldQueryInterface, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$gte';
+ public const PROPERTIES = ['value' => 'value'];
/** @var Type|array|bool|float|int|null|stdClass|string $value */
public readonly Type|stdClass|array|bool|float|int|null|string $value;
@@ -33,9 +36,4 @@ public function __construct(Type|stdClass|array|bool|float|int|null|string $valu
{
$this->value = $value;
}
-
- public function getOperator(): string
- {
- return '$gte';
- }
}
diff --git a/src/Builder/Query/InOperator.php b/src/Builder/Query/InOperator.php
index 605a90b92..e6f1456a4 100644
--- a/src/Builder/Query/InOperator.php
+++ b/src/Builder/Query/InOperator.php
@@ -22,10 +22,13 @@
* Matches any of the values specified in an array.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/query/in/
+ * @internal
*/
-class InOperator implements FieldQueryInterface, OperatorInterface
+final class InOperator implements FieldQueryInterface, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$in';
+ public const PROPERTIES = ['value' => 'value'];
/** @var BSONArray|PackedArray|array $value */
public readonly PackedArray|BSONArray|array $value;
@@ -41,9 +44,4 @@ public function __construct(PackedArray|BSONArray|array $value)
$this->value = $value;
}
-
- public function getOperator(): string
- {
- return '$in';
- }
}
diff --git a/src/Builder/Query/JsonSchemaOperator.php b/src/Builder/Query/JsonSchemaOperator.php
index cce8438be..3dc8b918e 100644
--- a/src/Builder/Query/JsonSchemaOperator.php
+++ b/src/Builder/Query/JsonSchemaOperator.php
@@ -19,10 +19,13 @@
* Validate documents against the given JSON Schema.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/query/jsonSchema/
+ * @internal
*/
-class JsonSchemaOperator implements QueryInterface, OperatorInterface
+final class JsonSchemaOperator implements QueryInterface, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$jsonSchema';
+ public const PROPERTIES = ['schema' => 'schema'];
/** @var Document|Serializable|array|stdClass $schema */
public readonly Document|Serializable|stdClass|array $schema;
@@ -34,9 +37,4 @@ public function __construct(Document|Serializable|stdClass|array $schema)
{
$this->schema = $schema;
}
-
- public function getOperator(): string
- {
- return '$jsonSchema';
- }
}
diff --git a/src/Builder/Query/LtOperator.php b/src/Builder/Query/LtOperator.php
index f29c73b57..ac4e88a95 100644
--- a/src/Builder/Query/LtOperator.php
+++ b/src/Builder/Query/LtOperator.php
@@ -18,10 +18,13 @@
* Matches values that are less than a specified value.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/query/lt/
+ * @internal
*/
-class LtOperator implements FieldQueryInterface, OperatorInterface
+final class LtOperator implements FieldQueryInterface, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$lt';
+ public const PROPERTIES = ['value' => 'value'];
/** @var Type|array|bool|float|int|null|stdClass|string $value */
public readonly Type|stdClass|array|bool|float|int|null|string $value;
@@ -33,9 +36,4 @@ public function __construct(Type|stdClass|array|bool|float|int|null|string $valu
{
$this->value = $value;
}
-
- public function getOperator(): string
- {
- return '$lt';
- }
}
diff --git a/src/Builder/Query/LteOperator.php b/src/Builder/Query/LteOperator.php
index 18453cb58..2c8a7cf6f 100644
--- a/src/Builder/Query/LteOperator.php
+++ b/src/Builder/Query/LteOperator.php
@@ -18,10 +18,13 @@
* Matches values that are less than or equal to a specified value.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/query/lte/
+ * @internal
*/
-class LteOperator implements FieldQueryInterface, OperatorInterface
+final class LteOperator implements FieldQueryInterface, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$lte';
+ public const PROPERTIES = ['value' => 'value'];
/** @var Type|array|bool|float|int|null|stdClass|string $value */
public readonly Type|stdClass|array|bool|float|int|null|string $value;
@@ -33,9 +36,4 @@ public function __construct(Type|stdClass|array|bool|float|int|null|string $valu
{
$this->value = $value;
}
-
- public function getOperator(): string
- {
- return '$lte';
- }
}
diff --git a/src/Builder/Query/MaxDistanceOperator.php b/src/Builder/Query/MaxDistanceOperator.php
index 864f1b60f..2aea7d4c8 100644
--- a/src/Builder/Query/MaxDistanceOperator.php
+++ b/src/Builder/Query/MaxDistanceOperator.php
@@ -18,10 +18,13 @@
* 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/
+ * @internal
*/
-class MaxDistanceOperator implements FieldQueryInterface, OperatorInterface
+final class MaxDistanceOperator implements FieldQueryInterface, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$maxDistance';
+ public const PROPERTIES = ['value' => 'value'];
/** @var Decimal128|Int64|float|int $value */
public readonly Decimal128|Int64|float|int $value;
@@ -33,9 +36,4 @@ public function __construct(Decimal128|Int64|float|int $value)
{
$this->value = $value;
}
-
- public function getOperator(): string
- {
- return '$maxDistance';
- }
}
diff --git a/src/Builder/Query/MinDistanceOperator.php b/src/Builder/Query/MinDistanceOperator.php
index ea57b8e3b..74aadb397 100644
--- a/src/Builder/Query/MinDistanceOperator.php
+++ b/src/Builder/Query/MinDistanceOperator.php
@@ -17,10 +17,13 @@
* 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/
+ * @internal
*/
-class MinDistanceOperator implements FieldQueryInterface, OperatorInterface
+final class MinDistanceOperator implements FieldQueryInterface, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$minDistance';
+ public const PROPERTIES = ['value' => 'value'];
/** @var Int64|float|int $value */
public readonly Int64|float|int $value;
@@ -32,9 +35,4 @@ public function __construct(Int64|float|int $value)
{
$this->value = $value;
}
-
- public function getOperator(): string
- {
- return '$minDistance';
- }
}
diff --git a/src/Builder/Query/ModOperator.php b/src/Builder/Query/ModOperator.php
index e608bf9c9..bbabdfdc9 100644
--- a/src/Builder/Query/ModOperator.php
+++ b/src/Builder/Query/ModOperator.php
@@ -18,10 +18,13 @@
* 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/
+ * @internal
*/
-class ModOperator implements FieldQueryInterface, OperatorInterface
+final class ModOperator implements FieldQueryInterface, OperatorInterface
{
public const ENCODE = Encode::Array;
+ public const NAME = '$mod';
+ public const PROPERTIES = ['divisor' => 'divisor', 'remainder' => 'remainder'];
/** @var Decimal128|Int64|float|int $divisor */
public readonly Decimal128|Int64|float|int $divisor;
@@ -38,9 +41,4 @@ public function __construct(Decimal128|Int64|float|int $divisor, Decimal128|Int6
$this->divisor = $divisor;
$this->remainder = $remainder;
}
-
- public function getOperator(): string
- {
- return '$mod';
- }
}
diff --git a/src/Builder/Query/NeOperator.php b/src/Builder/Query/NeOperator.php
index 9c12c851c..58cdc129c 100644
--- a/src/Builder/Query/NeOperator.php
+++ b/src/Builder/Query/NeOperator.php
@@ -18,10 +18,13 @@
* Matches all values that are not equal to a specified value.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/query/ne/
+ * @internal
*/
-class NeOperator implements FieldQueryInterface, OperatorInterface
+final class NeOperator implements FieldQueryInterface, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$ne';
+ public const PROPERTIES = ['value' => 'value'];
/** @var Type|array|bool|float|int|null|stdClass|string $value */
public readonly Type|stdClass|array|bool|float|int|null|string $value;
@@ -33,9 +36,4 @@ public function __construct(Type|stdClass|array|bool|float|int|null|string $valu
{
$this->value = $value;
}
-
- public function getOperator(): string
- {
- return '$ne';
- }
}
diff --git a/src/Builder/Query/NearOperator.php b/src/Builder/Query/NearOperator.php
index 68b99aa5e..85be90ac4 100644
--- a/src/Builder/Query/NearOperator.php
+++ b/src/Builder/Query/NearOperator.php
@@ -23,10 +23,13 @@
* 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/
+ * @internal
*/
-class NearOperator implements FieldQueryInterface, OperatorInterface
+final class NearOperator implements FieldQueryInterface, OperatorInterface
{
- public const ENCODE = Encode::DollarObject;
+ public const ENCODE = Encode::Object;
+ public const NAME = '$near';
+ public const PROPERTIES = ['geometry' => null, 'maxDistance' => '$maxDistance', 'minDistance' => '$minDistance'];
/** @var Document|GeometryInterface|Serializable|array|stdClass $geometry */
public readonly Document|Serializable|GeometryInterface|stdClass|array $geometry;
@@ -51,9 +54,4 @@ public function __construct(
$this->maxDistance = $maxDistance;
$this->minDistance = $minDistance;
}
-
- public function getOperator(): string
- {
- return '$near';
- }
}
diff --git a/src/Builder/Query/NearSphereOperator.php b/src/Builder/Query/NearSphereOperator.php
index aab04903d..5494048b0 100644
--- a/src/Builder/Query/NearSphereOperator.php
+++ b/src/Builder/Query/NearSphereOperator.php
@@ -23,10 +23,13 @@
* 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/
+ * @internal
*/
-class NearSphereOperator implements FieldQueryInterface, OperatorInterface
+final class NearSphereOperator implements FieldQueryInterface, OperatorInterface
{
- public const ENCODE = Encode::DollarObject;
+ public const ENCODE = Encode::Object;
+ public const NAME = '$nearSphere';
+ public const PROPERTIES = ['geometry' => null, 'maxDistance' => '$maxDistance', 'minDistance' => '$minDistance'];
/** @var Document|GeometryInterface|Serializable|array|stdClass $geometry */
public readonly Document|Serializable|GeometryInterface|stdClass|array $geometry;
@@ -51,9 +54,4 @@ public function __construct(
$this->maxDistance = $maxDistance;
$this->minDistance = $minDistance;
}
-
- public function getOperator(): string
- {
- return '$nearSphere';
- }
}
diff --git a/src/Builder/Query/NinOperator.php b/src/Builder/Query/NinOperator.php
index 8b348b733..5c82c3fd8 100644
--- a/src/Builder/Query/NinOperator.php
+++ b/src/Builder/Query/NinOperator.php
@@ -22,10 +22,13 @@
* Matches none of the values specified in an array.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/query/nin/
+ * @internal
*/
-class NinOperator implements FieldQueryInterface, OperatorInterface
+final class NinOperator implements FieldQueryInterface, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$nin';
+ public const PROPERTIES = ['value' => 'value'];
/** @var BSONArray|PackedArray|array $value */
public readonly PackedArray|BSONArray|array $value;
@@ -41,9 +44,4 @@ public function __construct(PackedArray|BSONArray|array $value)
$this->value = $value;
}
-
- public function getOperator(): string
- {
- return '$nin';
- }
}
diff --git a/src/Builder/Query/NorOperator.php b/src/Builder/Query/NorOperator.php
index 4ff7f41a4..06bdc7e39 100644
--- a/src/Builder/Query/NorOperator.php
+++ b/src/Builder/Query/NorOperator.php
@@ -19,10 +19,13 @@
* 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/
+ * @internal
*/
-class NorOperator implements QueryInterface, OperatorInterface
+final class NorOperator implements QueryInterface, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$nor';
+ public const PROPERTIES = ['queries' => 'queries'];
/** @var list $queries */
public readonly array $queries;
@@ -43,9 +46,4 @@ public function __construct(QueryInterface|array ...$queries)
$this->queries = $queries;
}
-
- public function getOperator(): string
- {
- return '$nor';
- }
}
diff --git a/src/Builder/Query/NotOperator.php b/src/Builder/Query/NotOperator.php
index c6d135445..f3b422f24 100644
--- a/src/Builder/Query/NotOperator.php
+++ b/src/Builder/Query/NotOperator.php
@@ -18,10 +18,13 @@
* 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/
+ * @internal
*/
-class NotOperator implements FieldQueryInterface, OperatorInterface
+final class NotOperator implements FieldQueryInterface, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$not';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var FieldQueryInterface|Type|array|bool|float|int|null|stdClass|string $expression */
public readonly Type|FieldQueryInterface|stdClass|array|bool|float|int|null|string $expression;
@@ -33,9 +36,4 @@ public function __construct(Type|FieldQueryInterface|stdClass|array|bool|float|i
{
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$not';
- }
}
diff --git a/src/Builder/Query/OrOperator.php b/src/Builder/Query/OrOperator.php
index f7ae64279..1b922fdb4 100644
--- a/src/Builder/Query/OrOperator.php
+++ b/src/Builder/Query/OrOperator.php
@@ -19,10 +19,13 @@
* 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/
+ * @internal
*/
-class OrOperator implements QueryInterface, OperatorInterface
+final class OrOperator implements QueryInterface, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$or';
+ public const PROPERTIES = ['queries' => 'queries'];
/** @var list $queries */
public readonly array $queries;
@@ -43,9 +46,4 @@ public function __construct(QueryInterface|array ...$queries)
$this->queries = $queries;
}
-
- public function getOperator(): string
- {
- return '$or';
- }
}
diff --git a/src/Builder/Query/PolygonOperator.php b/src/Builder/Query/PolygonOperator.php
index 6c829e076..bba3aac08 100644
--- a/src/Builder/Query/PolygonOperator.php
+++ b/src/Builder/Query/PolygonOperator.php
@@ -22,10 +22,13 @@
* 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/
+ * @internal
*/
-class PolygonOperator implements GeometryInterface, OperatorInterface
+final class PolygonOperator implements GeometryInterface, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$polygon';
+ public const PROPERTIES = ['points' => 'points'];
/** @var BSONArray|PackedArray|array $points */
public readonly PackedArray|BSONArray|array $points;
@@ -41,9 +44,4 @@ public function __construct(PackedArray|BSONArray|array $points)
$this->points = $points;
}
-
- public function getOperator(): string
- {
- return '$polygon';
- }
}
diff --git a/src/Builder/Query/RandOperator.php b/src/Builder/Query/RandOperator.php
index 251f50ea1..ccf8a8d28 100644
--- a/src/Builder/Query/RandOperator.php
+++ b/src/Builder/Query/RandOperator.php
@@ -16,17 +16,14 @@
* Generates a random float between 0 and 1.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/query/rand/
+ * @internal
*/
-class RandOperator implements ResolvesToDouble, OperatorInterface
+final class RandOperator implements ResolvesToDouble, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$rand';
public function __construct()
{
}
-
- public function getOperator(): string
- {
- return '$rand';
- }
}
diff --git a/src/Builder/Query/RegexOperator.php b/src/Builder/Query/RegexOperator.php
index 48c9788e8..cf9ee31ff 100644
--- a/src/Builder/Query/RegexOperator.php
+++ b/src/Builder/Query/RegexOperator.php
@@ -17,10 +17,13 @@
* Selects documents where values match a specified regular expression.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/query/regex/
+ * @internal
*/
-class RegexOperator implements FieldQueryInterface, OperatorInterface
+final class RegexOperator implements FieldQueryInterface, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$regex';
+ public const PROPERTIES = ['regex' => 'regex'];
/** @var Regex $regex */
public readonly Regex $regex;
@@ -32,9 +35,4 @@ public function __construct(Regex $regex)
{
$this->regex = $regex;
}
-
- public function getOperator(): string
- {
- return '$regex';
- }
}
diff --git a/src/Builder/Query/SampleRateOperator.php b/src/Builder/Query/SampleRateOperator.php
index a21a1ba5a..42879cead 100644
--- a/src/Builder/Query/SampleRateOperator.php
+++ b/src/Builder/Query/SampleRateOperator.php
@@ -18,10 +18,13 @@
* 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/
+ * @internal
*/
-class SampleRateOperator implements QueryInterface, OperatorInterface
+final class SampleRateOperator implements QueryInterface, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$sampleRate';
+ public const PROPERTIES = ['rate' => 'rate'];
/**
* @var 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.
@@ -37,9 +40,4 @@ public function __construct(Int64|ResolvesToDouble|float|int $rate)
{
$this->rate = $rate;
}
-
- public function getOperator(): string
- {
- return '$sampleRate';
- }
}
diff --git a/src/Builder/Query/SizeOperator.php b/src/Builder/Query/SizeOperator.php
index db9176c82..8ec123b11 100644
--- a/src/Builder/Query/SizeOperator.php
+++ b/src/Builder/Query/SizeOperator.php
@@ -16,10 +16,13 @@
* Selects documents if the array field is a specified size.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/query/size/
+ * @internal
*/
-class SizeOperator implements FieldQueryInterface, OperatorInterface
+final class SizeOperator implements FieldQueryInterface, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$size';
+ public const PROPERTIES = ['value' => 'value'];
/** @var int $value */
public readonly int $value;
@@ -31,9 +34,4 @@ public function __construct(int $value)
{
$this->value = $value;
}
-
- public function getOperator(): string
- {
- return '$size';
- }
}
diff --git a/src/Builder/Query/TextOperator.php b/src/Builder/Query/TextOperator.php
index 47b88ede1..7c1c0a7ba 100644
--- a/src/Builder/Query/TextOperator.php
+++ b/src/Builder/Query/TextOperator.php
@@ -17,10 +17,19 @@
* Performs text search.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/query/text/
+ * @internal
*/
-class TextOperator implements QueryInterface, OperatorInterface
+final class TextOperator implements QueryInterface, OperatorInterface
{
- public const ENCODE = Encode::DollarObject;
+ public const ENCODE = Encode::Object;
+ public const NAME = '$text';
+
+ public const PROPERTIES = [
+ 'search' => '$search',
+ 'language' => '$language',
+ 'caseSensitive' => '$caseSensitive',
+ 'diacriticSensitive' => '$diacriticSensitive',
+ ];
/** @var 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. */
public readonly string $search;
@@ -59,9 +68,4 @@ public function __construct(
$this->caseSensitive = $caseSensitive;
$this->diacriticSensitive = $diacriticSensitive;
}
-
- public function getOperator(): string
- {
- return '$text';
- }
}
diff --git a/src/Builder/Query/TypeOperator.php b/src/Builder/Query/TypeOperator.php
index cffe79092..e539ebfc8 100644
--- a/src/Builder/Query/TypeOperator.php
+++ b/src/Builder/Query/TypeOperator.php
@@ -19,10 +19,13 @@
* Selects documents if a field is of the specified type.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/query/type/
+ * @internal
*/
-class TypeOperator implements FieldQueryInterface, OperatorInterface
+final class TypeOperator implements FieldQueryInterface, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$type';
+ public const PROPERTIES = ['type' => 'type'];
/** @var list $type */
public readonly array $type;
@@ -43,9 +46,4 @@ public function __construct(int|string ...$type)
$this->type = $type;
}
-
- public function getOperator(): string
- {
- return '$type';
- }
}
diff --git a/src/Builder/Query/WhereOperator.php b/src/Builder/Query/WhereOperator.php
index 5a38eb8c6..e679f7347 100644
--- a/src/Builder/Query/WhereOperator.php
+++ b/src/Builder/Query/WhereOperator.php
@@ -19,10 +19,13 @@
* Matches documents that satisfy a JavaScript expression.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/query/where/
+ * @internal
*/
-class WhereOperator implements QueryInterface, OperatorInterface
+final class WhereOperator implements QueryInterface, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$where';
+ public const PROPERTIES = ['function' => 'function'];
/** @var Javascript|string $function */
public readonly Javascript|string $function;
@@ -38,9 +41,4 @@ public function __construct(Javascript|string $function)
$this->function = $function;
}
-
- public function getOperator(): string
- {
- return '$where';
- }
}
diff --git a/src/Builder/Search.php b/src/Builder/Search.php
new file mode 100644
index 000000000..7cab84641
--- /dev/null
+++ b/src/Builder/Search.php
@@ -0,0 +1,10 @@
+ 'path',
+ 'query' => 'query',
+ 'tokenOrder' => 'tokenOrder',
+ 'fuzzy' => 'fuzzy',
+ 'score' => 'score',
+ ];
+
+ /** @var array|string $path */
+ public readonly array|string $path;
+
+ /** @var string $query */
+ public readonly string $query;
+
+ /** @var Optional|string $tokenOrder */
+ public readonly Optional|string $tokenOrder;
+
+ /** @var Optional|Document|Serializable|array|stdClass $fuzzy */
+ public readonly Optional|Document|Serializable|stdClass|array $fuzzy;
+
+ /** @var Optional|Document|Serializable|array|stdClass $score */
+ public readonly Optional|Document|Serializable|stdClass|array $score;
+
+ /**
+ * @param array|string $path
+ * @param string $query
+ * @param Optional|string $tokenOrder
+ * @param Optional|Document|Serializable|array|stdClass $fuzzy
+ * @param Optional|Document|Serializable|array|stdClass $score
+ */
+ public function __construct(
+ array|string $path,
+ string $query,
+ Optional|string $tokenOrder = Optional::Undefined,
+ Optional|Document|Serializable|stdClass|array $fuzzy = Optional::Undefined,
+ Optional|Document|Serializable|stdClass|array $score = Optional::Undefined,
+ ) {
+ $this->path = $path;
+ $this->query = $query;
+ $this->tokenOrder = $tokenOrder;
+ $this->fuzzy = $fuzzy;
+ $this->score = $score;
+ }
+}
diff --git a/src/Builder/Search/CompoundOperator.php b/src/Builder/Search/CompoundOperator.php
new file mode 100644
index 000000000..27b8c2aeb
--- /dev/null
+++ b/src/Builder/Search/CompoundOperator.php
@@ -0,0 +1,84 @@
+ 'must',
+ 'mustNot' => 'mustNot',
+ 'should' => 'should',
+ 'filter' => 'filter',
+ 'minimumShouldMatch' => 'minimumShouldMatch',
+ 'score' => 'score',
+ ];
+
+ /** @var Optional|BSONArray|Document|PackedArray|SearchOperatorInterface|Serializable|array|stdClass $must */
+ public readonly Optional|Document|PackedArray|Serializable|SearchOperatorInterface|BSONArray|stdClass|array $must;
+
+ /** @var Optional|BSONArray|Document|PackedArray|SearchOperatorInterface|Serializable|array|stdClass $mustNot */
+ public readonly Optional|Document|PackedArray|Serializable|SearchOperatorInterface|BSONArray|stdClass|array $mustNot;
+
+ /** @var Optional|BSONArray|Document|PackedArray|SearchOperatorInterface|Serializable|array|stdClass $should */
+ public readonly Optional|Document|PackedArray|Serializable|SearchOperatorInterface|BSONArray|stdClass|array $should;
+
+ /** @var Optional|BSONArray|Document|PackedArray|SearchOperatorInterface|Serializable|array|stdClass $filter */
+ public readonly Optional|Document|PackedArray|Serializable|SearchOperatorInterface|BSONArray|stdClass|array $filter;
+
+ /** @var Optional|int $minimumShouldMatch */
+ public readonly Optional|int $minimumShouldMatch;
+
+ /** @var Optional|Document|Serializable|array|stdClass $score */
+ public readonly Optional|Document|Serializable|stdClass|array $score;
+
+ /**
+ * @param Optional|BSONArray|Document|PackedArray|SearchOperatorInterface|Serializable|array|stdClass $must
+ * @param Optional|BSONArray|Document|PackedArray|SearchOperatorInterface|Serializable|array|stdClass $mustNot
+ * @param Optional|BSONArray|Document|PackedArray|SearchOperatorInterface|Serializable|array|stdClass $should
+ * @param Optional|BSONArray|Document|PackedArray|SearchOperatorInterface|Serializable|array|stdClass $filter
+ * @param Optional|int $minimumShouldMatch
+ * @param Optional|Document|Serializable|array|stdClass $score
+ */
+ public function __construct(
+ Optional|Document|PackedArray|Serializable|SearchOperatorInterface|BSONArray|stdClass|array $must = Optional::Undefined,
+ Optional|Document|PackedArray|Serializable|SearchOperatorInterface|BSONArray|stdClass|array $mustNot = Optional::Undefined,
+ Optional|Document|PackedArray|Serializable|SearchOperatorInterface|BSONArray|stdClass|array $should = Optional::Undefined,
+ Optional|Document|PackedArray|Serializable|SearchOperatorInterface|BSONArray|stdClass|array $filter = Optional::Undefined,
+ Optional|int $minimumShouldMatch = Optional::Undefined,
+ Optional|Document|Serializable|stdClass|array $score = Optional::Undefined,
+ ) {
+ $this->must = $must;
+ $this->mustNot = $mustNot;
+ $this->should = $should;
+ $this->filter = $filter;
+ $this->minimumShouldMatch = $minimumShouldMatch;
+ $this->score = $score;
+ }
+}
diff --git a/src/Builder/Search/EmbeddedDocumentOperator.php b/src/Builder/Search/EmbeddedDocumentOperator.php
new file mode 100644
index 000000000..91f6c1f96
--- /dev/null
+++ b/src/Builder/Search/EmbeddedDocumentOperator.php
@@ -0,0 +1,57 @@
+ 'path', 'operator' => 'operator', 'score' => 'score'];
+
+ /** @var array|string $path */
+ public readonly array|string $path;
+
+ /** @var Document|SearchOperatorInterface|Serializable|array|stdClass $operator */
+ public readonly Document|Serializable|SearchOperatorInterface|stdClass|array $operator;
+
+ /** @var Optional|Document|Serializable|array|stdClass $score */
+ public readonly Optional|Document|Serializable|stdClass|array $score;
+
+ /**
+ * @param array|string $path
+ * @param Document|SearchOperatorInterface|Serializable|array|stdClass $operator
+ * @param Optional|Document|Serializable|array|stdClass $score
+ */
+ public function __construct(
+ array|string $path,
+ Document|Serializable|SearchOperatorInterface|stdClass|array $operator,
+ Optional|Document|Serializable|stdClass|array $score = Optional::Undefined,
+ ) {
+ $this->path = $path;
+ $this->operator = $operator;
+ $this->score = $score;
+ }
+}
diff --git a/src/Builder/Search/EqualsOperator.php b/src/Builder/Search/EqualsOperator.php
new file mode 100644
index 000000000..bbfe75b8e
--- /dev/null
+++ b/src/Builder/Search/EqualsOperator.php
@@ -0,0 +1,59 @@
+ 'path', 'value' => 'value', 'score' => 'score'];
+
+ /** @var array|string $path */
+ public readonly array|string $path;
+
+ /** @var Binary|Decimal128|Int64|ObjectId|UTCDateTime|bool|float|int|null|string $value */
+ public readonly Binary|Decimal128|Int64|ObjectId|UTCDateTime|bool|float|int|null|string $value;
+
+ /** @var Optional|Document|Serializable|array|stdClass $score */
+ public readonly Optional|Document|Serializable|stdClass|array $score;
+
+ /**
+ * @param array|string $path
+ * @param Binary|Decimal128|Int64|ObjectId|UTCDateTime|bool|float|int|null|string $value
+ * @param Optional|Document|Serializable|array|stdClass $score
+ */
+ public function __construct(
+ array|string $path,
+ Binary|Decimal128|Int64|ObjectId|UTCDateTime|bool|float|int|null|string $value,
+ Optional|Document|Serializable|stdClass|array $score = Optional::Undefined,
+ ) {
+ $this->path = $path;
+ $this->value = $value;
+ $this->score = $score;
+ }
+}
diff --git a/src/Builder/Search/ExistsOperator.php b/src/Builder/Search/ExistsOperator.php
new file mode 100644
index 000000000..4330f130f
--- /dev/null
+++ b/src/Builder/Search/ExistsOperator.php
@@ -0,0 +1,48 @@
+ 'path', 'score' => 'score'];
+
+ /** @var array|string $path */
+ public readonly array|string $path;
+
+ /** @var Optional|Document|Serializable|array|stdClass $score */
+ public readonly Optional|Document|Serializable|stdClass|array $score;
+
+ /**
+ * @param array|string $path
+ * @param Optional|Document|Serializable|array|stdClass $score
+ */
+ public function __construct(
+ array|string $path,
+ Optional|Document|Serializable|stdClass|array $score = Optional::Undefined,
+ ) {
+ $this->path = $path;
+ $this->score = $score;
+ }
+}
diff --git a/src/Builder/Search/FacetOperator.php b/src/Builder/Search/FacetOperator.php
new file mode 100644
index 000000000..15fc10830
--- /dev/null
+++ b/src/Builder/Search/FacetOperator.php
@@ -0,0 +1,49 @@
+ 'facets', 'operator' => 'operator'];
+
+ /** @var Document|Serializable|array|stdClass $facets */
+ public readonly Document|Serializable|stdClass|array $facets;
+
+ /** @var Optional|Document|SearchOperatorInterface|Serializable|array|stdClass $operator */
+ public readonly Optional|Document|Serializable|SearchOperatorInterface|stdClass|array $operator;
+
+ /**
+ * @param Document|Serializable|array|stdClass $facets
+ * @param Optional|Document|SearchOperatorInterface|Serializable|array|stdClass $operator
+ */
+ public function __construct(
+ Document|Serializable|stdClass|array $facets,
+ Optional|Document|Serializable|SearchOperatorInterface|stdClass|array $operator = Optional::Undefined,
+ ) {
+ $this->facets = $facets;
+ $this->operator = $operator;
+ }
+}
diff --git a/src/Builder/Search/FactoryTrait.php b/src/Builder/Search/FactoryTrait.php
new file mode 100644
index 000000000..3a7762521
--- /dev/null
+++ b/src/Builder/Search/FactoryTrait.php
@@ -0,0 +1,345 @@
+ 'path', 'relation' => 'relation', 'geometry' => 'geometry', 'score' => 'score'];
+
+ /** @var array|string $path */
+ public readonly array|string $path;
+
+ /** @var string $relation */
+ public readonly string $relation;
+
+ /** @var Document|GeometryInterface|Serializable|array|stdClass $geometry */
+ public readonly Document|Serializable|GeometryInterface|stdClass|array $geometry;
+
+ /** @var Optional|Document|Serializable|array|stdClass $score */
+ public readonly Optional|Document|Serializable|stdClass|array $score;
+
+ /**
+ * @param array|string $path
+ * @param string $relation
+ * @param Document|GeometryInterface|Serializable|array|stdClass $geometry
+ * @param Optional|Document|Serializable|array|stdClass $score
+ */
+ public function __construct(
+ array|string $path,
+ string $relation,
+ Document|Serializable|GeometryInterface|stdClass|array $geometry,
+ Optional|Document|Serializable|stdClass|array $score = Optional::Undefined,
+ ) {
+ $this->path = $path;
+ $this->relation = $relation;
+ $this->geometry = $geometry;
+ $this->score = $score;
+ }
+}
diff --git a/src/Builder/Search/GeoWithinOperator.php b/src/Builder/Search/GeoWithinOperator.php
new file mode 100644
index 000000000..dcf605697
--- /dev/null
+++ b/src/Builder/Search/GeoWithinOperator.php
@@ -0,0 +1,76 @@
+ 'path',
+ 'box' => 'box',
+ 'circle' => 'circle',
+ 'geometry' => 'geometry',
+ 'score' => 'score',
+ ];
+
+ /** @var array|string $path */
+ public readonly array|string $path;
+
+ /** @var Optional|Document|Serializable|array|stdClass $box */
+ public readonly Optional|Document|Serializable|stdClass|array $box;
+
+ /** @var Optional|Document|Serializable|array|stdClass $circle */
+ public readonly Optional|Document|Serializable|stdClass|array $circle;
+
+ /** @var Optional|Document|GeometryInterface|Serializable|array|stdClass $geometry */
+ public readonly Optional|Document|Serializable|GeometryInterface|stdClass|array $geometry;
+
+ /** @var Optional|Document|Serializable|array|stdClass $score */
+ public readonly Optional|Document|Serializable|stdClass|array $score;
+
+ /**
+ * @param array|string $path
+ * @param Optional|Document|Serializable|array|stdClass $box
+ * @param Optional|Document|Serializable|array|stdClass $circle
+ * @param Optional|Document|GeometryInterface|Serializable|array|stdClass $geometry
+ * @param Optional|Document|Serializable|array|stdClass $score
+ */
+ public function __construct(
+ array|string $path,
+ Optional|Document|Serializable|stdClass|array $box = Optional::Undefined,
+ Optional|Document|Serializable|stdClass|array $circle = Optional::Undefined,
+ Optional|Document|Serializable|GeometryInterface|stdClass|array $geometry = Optional::Undefined,
+ Optional|Document|Serializable|stdClass|array $score = Optional::Undefined,
+ ) {
+ $this->path = $path;
+ $this->box = $box;
+ $this->circle = $circle;
+ $this->geometry = $geometry;
+ $this->score = $score;
+ }
+}
diff --git a/src/Builder/Search/InOperator.php b/src/Builder/Search/InOperator.php
new file mode 100644
index 000000000..f050a1679
--- /dev/null
+++ b/src/Builder/Search/InOperator.php
@@ -0,0 +1,65 @@
+ 'path', 'value' => 'value', 'score' => 'score'];
+
+ /** @var array|string $path */
+ public readonly array|string $path;
+
+ /** @var BSONArray|PackedArray|Type|array|bool|float|int|null|stdClass|string $value */
+ public readonly PackedArray|Type|BSONArray|stdClass|array|bool|float|int|null|string $value;
+
+ /** @var Optional|Document|Serializable|array|stdClass $score */
+ public readonly Optional|Document|Serializable|stdClass|array $score;
+
+ /**
+ * @param array|string $path
+ * @param BSONArray|PackedArray|Type|array|bool|float|int|null|stdClass|string $value
+ * @param Optional|Document|Serializable|array|stdClass $score
+ */
+ public function __construct(
+ array|string $path,
+ PackedArray|Type|BSONArray|stdClass|array|bool|float|int|null|string $value,
+ Optional|Document|Serializable|stdClass|array $score = Optional::Undefined,
+ ) {
+ $this->path = $path;
+ 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;
+ $this->score = $score;
+ }
+}
diff --git a/src/Builder/Search/MoreLikeThisOperator.php b/src/Builder/Search/MoreLikeThisOperator.php
new file mode 100644
index 000000000..689508d53
--- /dev/null
+++ b/src/Builder/Search/MoreLikeThisOperator.php
@@ -0,0 +1,52 @@
+ 'like', 'score' => 'score'];
+
+ /** @var BSONArray|Document|PackedArray|Serializable|array|stdClass $like */
+ public readonly Document|PackedArray|Serializable|BSONArray|stdClass|array $like;
+
+ /** @var Optional|Document|Serializable|array|stdClass $score */
+ public readonly Optional|Document|Serializable|stdClass|array $score;
+
+ /**
+ * @param BSONArray|Document|PackedArray|Serializable|array|stdClass $like
+ * @param Optional|Document|Serializable|array|stdClass $score
+ */
+ public function __construct(
+ Document|PackedArray|Serializable|BSONArray|stdClass|array $like,
+ Optional|Document|Serializable|stdClass|array $score = Optional::Undefined,
+ ) {
+ $this->like = $like;
+ $this->score = $score;
+ }
+}
diff --git a/src/Builder/Search/NearOperator.php b/src/Builder/Search/NearOperator.php
new file mode 100644
index 000000000..ab1b9b0c1
--- /dev/null
+++ b/src/Builder/Search/NearOperator.php
@@ -0,0 +1,64 @@
+ 'path', 'origin' => 'origin', 'pivot' => 'pivot', 'score' => 'score'];
+
+ /** @var array|string $path */
+ public readonly array|string $path;
+
+ /** @var Decimal128|Document|GeometryInterface|Int64|Serializable|UTCDateTime|array|float|int|stdClass $origin */
+ public readonly Decimal128|Document|Int64|Serializable|UTCDateTime|GeometryInterface|stdClass|array|float|int $origin;
+
+ /** @var Decimal128|Int64|float|int $pivot */
+ public readonly Decimal128|Int64|float|int $pivot;
+
+ /** @var Optional|Document|Serializable|array|stdClass $score */
+ public readonly Optional|Document|Serializable|stdClass|array $score;
+
+ /**
+ * @param array|string $path
+ * @param Decimal128|Document|GeometryInterface|Int64|Serializable|UTCDateTime|array|float|int|stdClass $origin
+ * @param Decimal128|Int64|float|int $pivot
+ * @param Optional|Document|Serializable|array|stdClass $score
+ */
+ public function __construct(
+ array|string $path,
+ Decimal128|Document|Int64|Serializable|UTCDateTime|GeometryInterface|stdClass|array|float|int $origin,
+ Decimal128|Int64|float|int $pivot,
+ Optional|Document|Serializable|stdClass|array $score = Optional::Undefined,
+ ) {
+ $this->path = $path;
+ $this->origin = $origin;
+ $this->pivot = $pivot;
+ $this->score = $score;
+ }
+}
diff --git a/src/Builder/Search/PhraseOperator.php b/src/Builder/Search/PhraseOperator.php
new file mode 100644
index 000000000..2bbb707a9
--- /dev/null
+++ b/src/Builder/Search/PhraseOperator.php
@@ -0,0 +1,83 @@
+ 'path',
+ 'query' => 'query',
+ 'slop' => 'slop',
+ 'synonyms' => 'synonyms',
+ 'score' => 'score',
+ ];
+
+ /** @var array|string $path */
+ public readonly array|string $path;
+
+ /** @var BSONArray|PackedArray|array|string $query */
+ public readonly PackedArray|BSONArray|array|string $query;
+
+ /** @var Optional|int $slop */
+ public readonly Optional|int $slop;
+
+ /** @var Optional|string $synonyms */
+ public readonly Optional|string $synonyms;
+
+ /** @var Optional|Document|Serializable|array|stdClass $score */
+ public readonly Optional|Document|Serializable|stdClass|array $score;
+
+ /**
+ * @param array|string $path
+ * @param BSONArray|PackedArray|array|string $query
+ * @param Optional|int $slop
+ * @param Optional|string $synonyms
+ * @param Optional|Document|Serializable|array|stdClass $score
+ */
+ public function __construct(
+ array|string $path,
+ PackedArray|BSONArray|array|string $query,
+ Optional|int $slop = Optional::Undefined,
+ Optional|string $synonyms = Optional::Undefined,
+ Optional|Document|Serializable|stdClass|array $score = Optional::Undefined,
+ ) {
+ $this->path = $path;
+ if (is_array($query) && ! array_is_list($query)) {
+ throw new InvalidArgumentException('Expected $query argument to be a list, got an associative array.');
+ }
+
+ $this->query = $query;
+ $this->slop = $slop;
+ $this->synonyms = $synonyms;
+ $this->score = $score;
+ }
+}
diff --git a/src/Builder/Search/QueryStringOperator.php b/src/Builder/Search/QueryStringOperator.php
new file mode 100644
index 000000000..edc4d3471
--- /dev/null
+++ b/src/Builder/Search/QueryStringOperator.php
@@ -0,0 +1,40 @@
+ 'defaultPath', 'query' => 'query'];
+
+ /** @var array|string $defaultPath */
+ public readonly array|string $defaultPath;
+
+ /** @var string $query */
+ public readonly string $query;
+
+ /**
+ * @param array|string $defaultPath
+ * @param string $query
+ */
+ public function __construct(array|string $defaultPath, string $query)
+ {
+ $this->defaultPath = $defaultPath;
+ $this->query = $query;
+ }
+}
diff --git a/src/Builder/Search/RangeOperator.php b/src/Builder/Search/RangeOperator.php
new file mode 100644
index 000000000..a728d7477
--- /dev/null
+++ b/src/Builder/Search/RangeOperator.php
@@ -0,0 +1,85 @@
+ 'path',
+ 'gt' => 'gt',
+ 'gte' => 'gte',
+ 'lt' => 'lt',
+ 'lte' => 'lte',
+ 'score' => 'score',
+ ];
+
+ /** @var array|string $path */
+ public readonly array|string $path;
+
+ /** @var Optional|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $gt */
+ public readonly Optional|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $gt;
+
+ /** @var Optional|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $gte */
+ public readonly Optional|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $gte;
+
+ /** @var Optional|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $lt */
+ public readonly Optional|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $lt;
+
+ /** @var Optional|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $lte */
+ public readonly Optional|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $lte;
+
+ /** @var Optional|Document|Serializable|array|stdClass $score */
+ public readonly Optional|Document|Serializable|stdClass|array $score;
+
+ /**
+ * @param array|string $path
+ * @param Optional|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $gt
+ * @param Optional|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $gte
+ * @param Optional|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $lt
+ * @param Optional|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $lte
+ * @param Optional|Document|Serializable|array|stdClass $score
+ */
+ public function __construct(
+ array|string $path,
+ Optional|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $gt = Optional::Undefined,
+ Optional|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $gte = Optional::Undefined,
+ Optional|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $lt = Optional::Undefined,
+ Optional|Decimal128|Int64|ObjectId|UTCDateTime|float|int|string $lte = Optional::Undefined,
+ Optional|Document|Serializable|stdClass|array $score = Optional::Undefined,
+ ) {
+ $this->path = $path;
+ $this->gt = $gt;
+ $this->gte = $gte;
+ $this->lt = $lt;
+ $this->lte = $lte;
+ $this->score = $score;
+ }
+}
diff --git a/src/Builder/Search/RegexOperator.php b/src/Builder/Search/RegexOperator.php
new file mode 100644
index 000000000..6b2c2d63a
--- /dev/null
+++ b/src/Builder/Search/RegexOperator.php
@@ -0,0 +1,67 @@
+ 'path',
+ 'query' => 'query',
+ 'allowAnalyzedField' => 'allowAnalyzedField',
+ 'score' => 'score',
+ ];
+
+ /** @var array|string $path */
+ public readonly array|string $path;
+
+ /** @var string $query */
+ public readonly string $query;
+
+ /** @var Optional|bool $allowAnalyzedField */
+ public readonly Optional|bool $allowAnalyzedField;
+
+ /** @var Optional|Document|Serializable|array|stdClass $score */
+ public readonly Optional|Document|Serializable|stdClass|array $score;
+
+ /**
+ * @param array|string $path
+ * @param string $query
+ * @param Optional|bool $allowAnalyzedField
+ * @param Optional|Document|Serializable|array|stdClass $score
+ */
+ public function __construct(
+ array|string $path,
+ string $query,
+ Optional|bool $allowAnalyzedField = Optional::Undefined,
+ Optional|Document|Serializable|stdClass|array $score = Optional::Undefined,
+ ) {
+ $this->path = $path;
+ $this->query = $query;
+ $this->allowAnalyzedField = $allowAnalyzedField;
+ $this->score = $score;
+ }
+}
diff --git a/src/Builder/Search/TextOperator.php b/src/Builder/Search/TextOperator.php
new file mode 100644
index 000000000..4ade6b434
--- /dev/null
+++ b/src/Builder/Search/TextOperator.php
@@ -0,0 +1,81 @@
+ 'path',
+ 'query' => 'query',
+ 'fuzzy' => 'fuzzy',
+ 'matchCriteria' => 'matchCriteria',
+ 'synonyms' => 'synonyms',
+ 'score' => 'score',
+ ];
+
+ /** @var array|string $path */
+ public readonly array|string $path;
+
+ /** @var string $query */
+ public readonly string $query;
+
+ /** @var Optional|Document|Serializable|array|stdClass $fuzzy */
+ public readonly Optional|Document|Serializable|stdClass|array $fuzzy;
+
+ /** @var Optional|string $matchCriteria */
+ public readonly Optional|string $matchCriteria;
+
+ /** @var Optional|string $synonyms */
+ public readonly Optional|string $synonyms;
+
+ /** @var Optional|Document|Serializable|array|stdClass $score */
+ public readonly Optional|Document|Serializable|stdClass|array $score;
+
+ /**
+ * @param array|string $path
+ * @param string $query
+ * @param Optional|Document|Serializable|array|stdClass $fuzzy
+ * @param Optional|string $matchCriteria
+ * @param Optional|string $synonyms
+ * @param Optional|Document|Serializable|array|stdClass $score
+ */
+ public function __construct(
+ array|string $path,
+ string $query,
+ Optional|Document|Serializable|stdClass|array $fuzzy = Optional::Undefined,
+ Optional|string $matchCriteria = Optional::Undefined,
+ Optional|string $synonyms = Optional::Undefined,
+ Optional|Document|Serializable|stdClass|array $score = Optional::Undefined,
+ ) {
+ $this->path = $path;
+ $this->query = $query;
+ $this->fuzzy = $fuzzy;
+ $this->matchCriteria = $matchCriteria;
+ $this->synonyms = $synonyms;
+ $this->score = $score;
+ }
+}
diff --git a/src/Builder/Search/WildcardOperator.php b/src/Builder/Search/WildcardOperator.php
new file mode 100644
index 000000000..ee481910e
--- /dev/null
+++ b/src/Builder/Search/WildcardOperator.php
@@ -0,0 +1,66 @@
+ 'path',
+ 'query' => 'query',
+ 'allowAnalyzedField' => 'allowAnalyzedField',
+ 'score' => 'score',
+ ];
+
+ /** @var array|string $path */
+ public readonly array|string $path;
+
+ /** @var string $query */
+ public readonly string $query;
+
+ /** @var Optional|bool $allowAnalyzedField */
+ public readonly Optional|bool $allowAnalyzedField;
+
+ /** @var Optional|Document|Serializable|array|stdClass $score */
+ public readonly Optional|Document|Serializable|stdClass|array $score;
+
+ /**
+ * @param array|string $path
+ * @param string $query
+ * @param Optional|bool $allowAnalyzedField
+ * @param Optional|Document|Serializable|array|stdClass $score
+ */
+ public function __construct(
+ array|string $path,
+ string $query,
+ Optional|bool $allowAnalyzedField = Optional::Undefined,
+ Optional|Document|Serializable|stdClass|array $score = Optional::Undefined,
+ ) {
+ $this->path = $path;
+ $this->query = $query;
+ $this->allowAnalyzedField = $allowAnalyzedField;
+ $this->score = $score;
+ }
+}
diff --git a/src/Builder/Stage/AddFieldsStage.php b/src/Builder/Stage/AddFieldsStage.php
index 15f509264..7fedc8b2c 100644
--- a/src/Builder/Stage/AddFieldsStage.php
+++ b/src/Builder/Stage/AddFieldsStage.php
@@ -22,10 +22,13 @@
* 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/
+ * @internal
*/
-class AddFieldsStage implements StageInterface, OperatorInterface
+final class AddFieldsStage implements StageInterface, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$addFields';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var stdClass $expression Specify the name of each field to add and set its value to an aggregation expression or an empty object. */
public readonly stdClass $expression;
@@ -48,9 +51,4 @@ public function __construct(Type|ExpressionInterface|stdClass|array|bool|float|i
$expression = (object) $expression;
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$addFields';
- }
}
diff --git a/src/Builder/Stage/BucketAutoStage.php b/src/Builder/Stage/BucketAutoStage.php
index 341421f44..2de5b3c20 100644
--- a/src/Builder/Stage/BucketAutoStage.php
+++ b/src/Builder/Stage/BucketAutoStage.php
@@ -22,10 +22,19 @@
* 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/
+ * @internal
*/
-class BucketAutoStage implements StageInterface, OperatorInterface
+final class BucketAutoStage implements StageInterface, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$bucketAuto';
+
+ public const PROPERTIES = [
+ 'groupBy' => 'groupBy',
+ 'buckets' => 'buckets',
+ 'output' => 'output',
+ 'granularity' => 'granularity',
+ ];
/** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|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. */
public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $groupBy;
@@ -64,9 +73,4 @@ public function __construct(
$this->output = $output;
$this->granularity = $granularity;
}
-
- public function getOperator(): string
- {
- return '$bucketAuto';
- }
}
diff --git a/src/Builder/Stage/BucketStage.php b/src/Builder/Stage/BucketStage.php
index 47a497153..211987c66 100644
--- a/src/Builder/Stage/BucketStage.php
+++ b/src/Builder/Stage/BucketStage.php
@@ -28,10 +28,19 @@
* 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/
+ * @internal
*/
-class BucketStage implements StageInterface, OperatorInterface
+final class BucketStage implements StageInterface, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$bucket';
+
+ public const PROPERTIES = [
+ 'groupBy' => 'groupBy',
+ 'boundaries' => 'boundaries',
+ 'default' => 'default',
+ 'output' => 'output',
+ ];
/**
* @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|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.
@@ -88,9 +97,4 @@ public function __construct(
$this->default = $default;
$this->output = $output;
}
-
- public function getOperator(): string
- {
- return '$bucket';
- }
}
diff --git a/src/Builder/Stage/ChangeStreamSplitLargeEventStage.php b/src/Builder/Stage/ChangeStreamSplitLargeEventStage.php
index eb0c8ce76..2539ddb19 100644
--- a/src/Builder/Stage/ChangeStreamSplitLargeEventStage.php
+++ b/src/Builder/Stage/ChangeStreamSplitLargeEventStage.php
@@ -17,17 +17,14 @@
* 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/
+ * @internal
*/
-class ChangeStreamSplitLargeEventStage implements StageInterface, OperatorInterface
+final class ChangeStreamSplitLargeEventStage implements StageInterface, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$changeStreamSplitLargeEvent';
public function __construct()
{
}
-
- public function getOperator(): string
- {
- return '$changeStreamSplitLargeEvent';
- }
}
diff --git a/src/Builder/Stage/ChangeStreamStage.php b/src/Builder/Stage/ChangeStreamStage.php
index 184ae96ee..d9c22eaa4 100644
--- a/src/Builder/Stage/ChangeStreamStage.php
+++ b/src/Builder/Stage/ChangeStreamStage.php
@@ -21,10 +21,22 @@
* 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/
+ * @internal
*/
-class ChangeStreamStage implements StageInterface, OperatorInterface
+final class ChangeStreamStage implements StageInterface, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$changeStream';
+
+ public const PROPERTIES = [
+ 'allChangesForCluster' => 'allChangesForCluster',
+ 'fullDocument' => 'fullDocument',
+ 'fullDocumentBeforeChange' => 'fullDocumentBeforeChange',
+ 'resumeAfter' => 'resumeAfter',
+ 'showExpandedEvents' => 'showExpandedEvents',
+ 'startAfter' => 'startAfter',
+ 'startAtOperationTime' => 'startAtOperationTime',
+ ];
/** @var 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. */
public readonly Optional|bool $allChangesForCluster;
@@ -77,9 +89,4 @@ public function __construct(
$this->startAfter = $startAfter;
$this->startAtOperationTime = $startAtOperationTime;
}
-
- public function getOperator(): string
- {
- return '$changeStream';
- }
}
diff --git a/src/Builder/Stage/CollStatsStage.php b/src/Builder/Stage/CollStatsStage.php
index 96f048f46..d84245320 100644
--- a/src/Builder/Stage/CollStatsStage.php
+++ b/src/Builder/Stage/CollStatsStage.php
@@ -20,10 +20,19 @@
* Returns statistics regarding a collection or view.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/collStats/
+ * @internal
*/
-class CollStatsStage implements StageInterface, OperatorInterface
+final class CollStatsStage implements StageInterface, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$collStats';
+
+ public const PROPERTIES = [
+ 'latencyStats' => 'latencyStats',
+ 'storageStats' => 'storageStats',
+ 'count' => 'count',
+ 'queryExecStats' => 'queryExecStats',
+ ];
/** @var Optional|Document|Serializable|array|stdClass $latencyStats */
public readonly Optional|Document|Serializable|stdClass|array $latencyStats;
@@ -54,9 +63,4 @@ public function __construct(
$this->count = $count;
$this->queryExecStats = $queryExecStats;
}
-
- public function getOperator(): string
- {
- return '$collStats';
- }
}
diff --git a/src/Builder/Stage/CountStage.php b/src/Builder/Stage/CountStage.php
index 3864f00c5..387da5efc 100644
--- a/src/Builder/Stage/CountStage.php
+++ b/src/Builder/Stage/CountStage.php
@@ -17,10 +17,13 @@
* Distinct from the $count aggregation accumulator.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/count/
+ * @internal
*/
-class CountStage implements StageInterface, OperatorInterface
+final class CountStage implements StageInterface, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$count';
+ public const PROPERTIES = ['field' => 'field'];
/** @var string $field Name of the output field which has the count as its value. It must be a non-empty string, must not start with $ and must not contain the . character. */
public readonly string $field;
@@ -32,9 +35,4 @@ public function __construct(string $field)
{
$this->field = $field;
}
-
- public function getOperator(): string
- {
- return '$count';
- }
}
diff --git a/src/Builder/Stage/CurrentOpStage.php b/src/Builder/Stage/CurrentOpStage.php
index 3b5930d32..3d0d6abb2 100644
--- a/src/Builder/Stage/CurrentOpStage.php
+++ b/src/Builder/Stage/CurrentOpStage.php
@@ -17,10 +17,20 @@
* 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/
+ * @internal
*/
-class CurrentOpStage implements StageInterface, OperatorInterface
+final class CurrentOpStage implements StageInterface, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$currentOp';
+
+ public const PROPERTIES = [
+ 'allUsers' => 'allUsers',
+ 'idleConnections' => 'idleConnections',
+ 'idleCursors' => 'idleCursors',
+ 'idleSessions' => 'idleSessions',
+ 'localOps' => 'localOps',
+ ];
/** @var Optional|bool $allUsers */
public readonly Optional|bool $allUsers;
@@ -57,9 +67,4 @@ public function __construct(
$this->idleSessions = $idleSessions;
$this->localOps = $localOps;
}
-
- public function getOperator(): string
- {
- return '$currentOp';
- }
}
diff --git a/src/Builder/Stage/DensifyStage.php b/src/Builder/Stage/DensifyStage.php
index 3abfcb3fe..9ecff7bbc 100644
--- a/src/Builder/Stage/DensifyStage.php
+++ b/src/Builder/Stage/DensifyStage.php
@@ -26,10 +26,13 @@
* 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/
+ * @internal
*/
-class DensifyStage implements StageInterface, OperatorInterface
+final class DensifyStage implements StageInterface, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$densify';
+ public const PROPERTIES = ['field' => 'field', 'range' => 'range', 'partitionByFields' => 'partitionByFields'];
/**
* @var string $field The field to densify. The values of the specified field must either be all numeric values or all dates.
@@ -64,9 +67,4 @@ public function __construct(
$this->partitionByFields = $partitionByFields;
}
-
- public function getOperator(): string
- {
- return '$densify';
- }
}
diff --git a/src/Builder/Stage/DocumentsStage.php b/src/Builder/Stage/DocumentsStage.php
index 1ca0a3f9c..d49585ef7 100644
--- a/src/Builder/Stage/DocumentsStage.php
+++ b/src/Builder/Stage/DocumentsStage.php
@@ -23,10 +23,13 @@
* Returns literal documents from input values.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/documents/
+ * @internal
*/
-class DocumentsStage implements StageInterface, OperatorInterface
+final class DocumentsStage implements StageInterface, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$documents';
+ public const PROPERTIES = ['documents' => 'documents'];
/**
* @var BSONArray|PackedArray|ResolvesToArray|array $documents $documents accepts any valid expression that resolves to an array of objects. This includes:
@@ -52,9 +55,4 @@ public function __construct(PackedArray|ResolvesToArray|BSONArray|array $documen
$this->documents = $documents;
}
-
- public function getOperator(): string
- {
- return '$documents';
- }
}
diff --git a/src/Builder/Stage/FacetStage.php b/src/Builder/Stage/FacetStage.php
index e334167bf..6dc36bebd 100644
--- a/src/Builder/Stage/FacetStage.php
+++ b/src/Builder/Stage/FacetStage.php
@@ -23,10 +23,13 @@
* 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/
+ * @internal
*/
-class FacetStage implements StageInterface, OperatorInterface
+final class FacetStage implements StageInterface, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$facet';
+ public const PROPERTIES = ['facet' => 'facet'];
/** @var stdClass $facet */
public readonly stdClass $facet;
@@ -49,9 +52,4 @@ public function __construct(PackedArray|Pipeline|BSONArray|array ...$facet)
$facet = (object) $facet;
$this->facet = $facet;
}
-
- public function getOperator(): string
- {
- return '$facet';
- }
}
diff --git a/src/Builder/Stage/FactoryTrait.php b/src/Builder/Stage/FactoryTrait.php
index 199cf64ef..95b0e6e37 100644
--- a/src/Builder/Stage/FactoryTrait.php
+++ b/src/Builder/Stage/FactoryTrait.php
@@ -24,6 +24,7 @@
use MongoDB\Builder\Type\ExpressionInterface;
use MongoDB\Builder\Type\Optional;
use MongoDB\Builder\Type\QueryInterface;
+use MongoDB\Builder\Type\SearchOperatorInterface;
use MongoDB\Builder\Type\Sort;
use MongoDB\Model\BSONArray;
use stdClass;
@@ -537,11 +538,35 @@ public static function sample(int $size): SampleStage
* 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);
+ * @param Document|SearchOperatorInterface|Serializable|array|stdClass $operator Operator to search with. You can provide a specific operator or use
+ * the compound operator to run a compound query with multiple operators.
+ * @param Optional|string $index Name of the Atlas Search index to use. If omitted, defaults to "default".
+ * @param Optional|Document|Serializable|array|stdClass $highlight Specifies the highlighting options for displaying search terms in their original context.
+ * @param Optional|bool $concurrent Parallelize search across segments on dedicated search nodes.
+ * If you don't have separate search nodes on your cluster,
+ * Atlas Search ignores this flag. If omitted, defaults to false.
+ * @param Optional|string $count Document that specifies the count options for retrieving a count of the results.
+ * @param Optional|string $searchAfter Reference point for retrieving results. searchAfter returns documents starting immediately following the specified reference point.
+ * @param Optional|string $searchBefore Reference point for retrieving results. searchBefore returns documents starting immediately before the specified reference point.
+ * @param Optional|bool $scoreDetails Flag that specifies whether to retrieve a detailed breakdown of the score for the documents in the results. If omitted, defaults to false.
+ * @param Optional|Document|Serializable|array|stdClass $sort Document that specifies the fields to sort the Atlas Search results by in ascending or descending order.
+ * @param Optional|bool $returnStoredSource Flag that specifies whether to perform a full document lookup on the backend database or return only stored source fields directly from Atlas Search.
+ * @param Optional|Document|Serializable|array|stdClass $tracking Document that specifies the tracking option to retrieve analytics information on the search terms.
+ */
+ public static function search(
+ Document|Serializable|SearchOperatorInterface|stdClass|array $operator,
+ Optional|string $index = Optional::Undefined,
+ Optional|Document|Serializable|stdClass|array $highlight = Optional::Undefined,
+ Optional|bool $concurrent = Optional::Undefined,
+ Optional|string $count = Optional::Undefined,
+ Optional|string $searchAfter = Optional::Undefined,
+ Optional|string $searchBefore = Optional::Undefined,
+ Optional|bool $scoreDetails = Optional::Undefined,
+ Optional|Document|Serializable|stdClass|array $sort = Optional::Undefined,
+ Optional|bool $returnStoredSource = Optional::Undefined,
+ Optional|Document|Serializable|stdClass|array $tracking = Optional::Undefined,
+ ): SearchStage {
+ return new SearchStage($operator, $index, $highlight, $concurrent, $count, $searchAfter, $searchBefore, $scoreDetails, $sort, $returnStoredSource, $tracking);
}
/**
@@ -549,11 +574,17 @@ public static function search(Document|Serializable|stdClass|array $search): Sea
* 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);
+ * @param Document|SearchOperatorInterface|Serializable|array|stdClass $operator Operator to search with. You can provide a specific operator or use
+ * the compound operator to run a compound query with multiple operators.
+ * @param Optional|string $index Name of the Atlas Search index to use. If omitted, defaults to default.
+ * @param Optional|Document|Serializable|array|stdClass $count Document that specifies the count options for retrieving a count of the results.
+ */
+ public static function searchMeta(
+ Document|Serializable|SearchOperatorInterface|stdClass|array $operator,
+ Optional|string $index = Optional::Undefined,
+ Optional|Document|Serializable|stdClass|array $count = Optional::Undefined,
+ ): SearchMetaStage {
+ return new SearchMetaStage($operator, $index, $count);
}
/**
@@ -678,4 +709,29 @@ public static function unwind(
): UnwindStage {
return new UnwindStage($path, $includeArrayIndex, $preserveNullAndEmptyArrays);
}
+
+ /**
+ * The $vectorSearch stage performs an ANN or ENN search on a vector in the specified field.
+ *
+ * @see https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-stage/
+ * @param string $index Name of the Atlas Vector Search index to use.
+ * @param int $limit Number of documents to return in the results. This value can't exceed the value of numCandidates if you specify numCandidates.
+ * @param array|string $path Indexed vector type field to search.
+ * @param BSONArray|PackedArray|array $queryVector Array of numbers that represent the query vector. The number type must match the indexed field value type.
+ * @param Optional|bool $exact This is required if numCandidates is omitted. false to run ANN search. true to run ENN search.
+ * @param Optional|QueryInterface|array $filter Any match query that compares an indexed field with a boolean, date, objectId, number (not decimals), string, or UUID to use as a pre-filter.
+ * @param Optional|int $numCandidates This field is required if exact is false or omitted.
+ * Number of nearest neighbors to use during the search. Value must be less than or equal to (<=) 10000. You can't specify a number less than the number of documents to return (limit).
+ */
+ public static function vectorSearch(
+ string $index,
+ int $limit,
+ array|string $path,
+ PackedArray|BSONArray|array $queryVector,
+ Optional|bool $exact = Optional::Undefined,
+ Optional|QueryInterface|array $filter = Optional::Undefined,
+ Optional|int $numCandidates = Optional::Undefined,
+ ): VectorSearchStage {
+ return new VectorSearchStage($index, $limit, $path, $queryVector, $exact, $filter, $numCandidates);
+ }
}
diff --git a/src/Builder/Stage/FillStage.php b/src/Builder/Stage/FillStage.php
index 634c05b8d..f7b3b35e2 100644
--- a/src/Builder/Stage/FillStage.php
+++ b/src/Builder/Stage/FillStage.php
@@ -26,10 +26,19 @@
* Populates null and missing field values within documents.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/fill/
+ * @internal
*/
-class FillStage implements StageInterface, OperatorInterface
+final class FillStage implements StageInterface, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$fill';
+
+ public const PROPERTIES = [
+ 'output' => 'output',
+ 'partitionBy' => 'partitionBy',
+ 'partitionByFields' => 'partitionByFields',
+ 'sortBy' => 'sortBy',
+ ];
/**
* @var 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.
@@ -80,9 +89,4 @@ public function __construct(
$this->partitionByFields = $partitionByFields;
$this->sortBy = $sortBy;
}
-
- public function getOperator(): string
- {
- return '$fill';
- }
}
diff --git a/src/Builder/Stage/FluentFactoryTrait.php b/src/Builder/Stage/FluentFactoryTrait.php
index 6f468322d..757a09a0b 100644
--- a/src/Builder/Stage/FluentFactoryTrait.php
+++ b/src/Builder/Stage/FluentFactoryTrait.php
@@ -26,6 +26,7 @@
use MongoDB\Builder\Type\FieldQueryInterface;
use MongoDB\Builder\Type\Optional;
use MongoDB\Builder\Type\QueryInterface;
+use MongoDB\Builder\Type\SearchOperatorInterface;
use MongoDB\Builder\Type\Sort;
use MongoDB\Builder\Type\StageInterface;
use MongoDB\Model\BSONArray;
@@ -605,11 +606,35 @@ public function sample(int $size): static
* 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 function search(Document|Serializable|stdClass|array $search): static
- {
- $this->pipeline[] = Stage::search($search);
+ * @param Document|SearchOperatorInterface|Serializable|array|stdClass $operator Operator to search with. You can provide a specific operator or use
+ * the compound operator to run a compound query with multiple operators.
+ * @param Optional|string $index Name of the Atlas Search index to use. If omitted, defaults to "default".
+ * @param Optional|Document|Serializable|array|stdClass $highlight Specifies the highlighting options for displaying search terms in their original context.
+ * @param Optional|bool $concurrent Parallelize search across segments on dedicated search nodes.
+ * If you don't have separate search nodes on your cluster,
+ * Atlas Search ignores this flag. If omitted, defaults to false.
+ * @param Optional|string $count Document that specifies the count options for retrieving a count of the results.
+ * @param Optional|string $searchAfter Reference point for retrieving results. searchAfter returns documents starting immediately following the specified reference point.
+ * @param Optional|string $searchBefore Reference point for retrieving results. searchBefore returns documents starting immediately before the specified reference point.
+ * @param Optional|bool $scoreDetails Flag that specifies whether to retrieve a detailed breakdown of the score for the documents in the results. If omitted, defaults to false.
+ * @param Optional|Document|Serializable|array|stdClass $sort Document that specifies the fields to sort the Atlas Search results by in ascending or descending order.
+ * @param Optional|bool $returnStoredSource Flag that specifies whether to perform a full document lookup on the backend database or return only stored source fields directly from Atlas Search.
+ * @param Optional|Document|Serializable|array|stdClass $tracking Document that specifies the tracking option to retrieve analytics information on the search terms.
+ */
+ public function search(
+ Document|Serializable|SearchOperatorInterface|stdClass|array $operator,
+ Optional|string $index = Optional::Undefined,
+ Optional|Document|Serializable|stdClass|array $highlight = Optional::Undefined,
+ Optional|bool $concurrent = Optional::Undefined,
+ Optional|string $count = Optional::Undefined,
+ Optional|string $searchAfter = Optional::Undefined,
+ Optional|string $searchBefore = Optional::Undefined,
+ Optional|bool $scoreDetails = Optional::Undefined,
+ Optional|Document|Serializable|stdClass|array $sort = Optional::Undefined,
+ Optional|bool $returnStoredSource = Optional::Undefined,
+ Optional|Document|Serializable|stdClass|array $tracking = Optional::Undefined,
+ ): static {
+ $this->pipeline[] = Stage::search($operator, $index, $highlight, $concurrent, $count, $searchAfter, $searchBefore, $scoreDetails, $sort, $returnStoredSource, $tracking);
return $this;
}
@@ -619,11 +644,17 @@ public function search(Document|Serializable|stdClass|array $search): static
* 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 function searchMeta(Document|Serializable|stdClass|array $meta): static
- {
- $this->pipeline[] = Stage::searchMeta($meta);
+ * @param Document|SearchOperatorInterface|Serializable|array|stdClass $operator Operator to search with. You can provide a specific operator or use
+ * the compound operator to run a compound query with multiple operators.
+ * @param Optional|string $index Name of the Atlas Search index to use. If omitted, defaults to default.
+ * @param Optional|Document|Serializable|array|stdClass $count Document that specifies the count options for retrieving a count of the results.
+ */
+ public function searchMeta(
+ Document|Serializable|SearchOperatorInterface|stdClass|array $operator,
+ Optional|string $index = Optional::Undefined,
+ Optional|Document|Serializable|stdClass|array $count = Optional::Undefined,
+ ): static {
+ $this->pipeline[] = Stage::searchMeta($operator, $index, $count);
return $this;
}
@@ -767,4 +798,31 @@ public function unwind(
return $this;
}
+
+ /**
+ * The $vectorSearch stage performs an ANN or ENN search on a vector in the specified field.
+ *
+ * @see https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-stage/
+ * @param string $index Name of the Atlas Vector Search index to use.
+ * @param int $limit Number of documents to return in the results. This value can't exceed the value of numCandidates if you specify numCandidates.
+ * @param array|string $path Indexed vector type field to search.
+ * @param BSONArray|PackedArray|array $queryVector Array of numbers that represent the query vector. The number type must match the indexed field value type.
+ * @param Optional|bool $exact This is required if numCandidates is omitted. false to run ANN search. true to run ENN search.
+ * @param Optional|QueryInterface|array $filter Any match query that compares an indexed field with a boolean, date, objectId, number (not decimals), string, or UUID to use as a pre-filter.
+ * @param Optional|int $numCandidates This field is required if exact is false or omitted.
+ * Number of nearest neighbors to use during the search. Value must be less than or equal to (<=) 10000. You can't specify a number less than the number of documents to return (limit).
+ */
+ public function vectorSearch(
+ string $index,
+ int $limit,
+ array|string $path,
+ PackedArray|BSONArray|array $queryVector,
+ Optional|bool $exact = Optional::Undefined,
+ Optional|QueryInterface|array $filter = Optional::Undefined,
+ Optional|int $numCandidates = Optional::Undefined,
+ ): static {
+ $this->pipeline[] = Stage::vectorSearch($index, $limit, $path, $queryVector, $exact, $filter, $numCandidates);
+
+ return $this;
+ }
}
diff --git a/src/Builder/Stage/GeoNearStage.php b/src/Builder/Stage/GeoNearStage.php
index d39766dc5..b2aa6588e 100644
--- a/src/Builder/Stage/GeoNearStage.php
+++ b/src/Builder/Stage/GeoNearStage.php
@@ -27,10 +27,24 @@
* 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/
+ * @internal
*/
-class GeoNearStage implements StageInterface, OperatorInterface
+final class GeoNearStage implements StageInterface, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$geoNear';
+
+ public const PROPERTIES = [
+ 'distanceField' => 'distanceField',
+ 'near' => 'near',
+ 'distanceMultiplier' => 'distanceMultiplier',
+ 'includeLocs' => 'includeLocs',
+ 'key' => 'key',
+ 'maxDistance' => 'maxDistance',
+ 'minDistance' => 'minDistance',
+ 'query' => 'query',
+ 'spherical' => 'spherical',
+ ];
/** @var string $distanceField The output field that contains the calculated distance. To specify a field within an embedded document, use dot notation. */
public readonly string $distanceField;
@@ -115,9 +129,4 @@ public function __construct(
$this->query = $query;
$this->spherical = $spherical;
}
-
- public function getOperator(): string
- {
- return '$geoNear';
- }
}
diff --git a/src/Builder/Stage/GraphLookupStage.php b/src/Builder/Stage/GraphLookupStage.php
index ceaa7a4b1..936b59861 100644
--- a/src/Builder/Stage/GraphLookupStage.php
+++ b/src/Builder/Stage/GraphLookupStage.php
@@ -28,10 +28,23 @@
* 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/
+ * @internal
*/
-class GraphLookupStage implements StageInterface, OperatorInterface
+final class GraphLookupStage implements StageInterface, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$graphLookup';
+
+ public const PROPERTIES = [
+ 'from' => 'from',
+ 'startWith' => 'startWith',
+ 'connectFromField' => 'connectFromField',
+ 'connectToField' => 'connectToField',
+ 'as' => 'as',
+ 'maxDepth' => 'maxDepth',
+ 'depthField' => 'depthField',
+ 'restrictSearchWithMatch' => 'restrictSearchWithMatch',
+ ];
/**
* @var 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.
@@ -98,9 +111,4 @@ public function __construct(
$this->restrictSearchWithMatch = $restrictSearchWithMatch;
}
-
- public function getOperator(): string
- {
- return '$graphLookup';
- }
}
diff --git a/src/Builder/Stage/GroupStage.php b/src/Builder/Stage/GroupStage.php
index a16038007..b44cbc764 100644
--- a/src/Builder/Stage/GroupStage.php
+++ b/src/Builder/Stage/GroupStage.php
@@ -25,10 +25,13 @@
* 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/
+ * @internal
*/
-class GroupStage implements StageInterface, OperatorInterface
+final class GroupStage implements StageInterface, OperatorInterface
{
- public const ENCODE = Encode::Group;
+ public const ENCODE = Encode::Object;
+ public const NAME = '$group';
+ public const PROPERTIES = ['_id' => '_id', 'field' => null];
/** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $_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 readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $_id;
@@ -54,9 +57,4 @@ public function __construct(
$field = (object) $field;
$this->field = $field;
}
-
- public function getOperator(): string
- {
- return '$group';
- }
}
diff --git a/src/Builder/Stage/IndexStatsStage.php b/src/Builder/Stage/IndexStatsStage.php
index 4fca140bb..0baaf8a18 100644
--- a/src/Builder/Stage/IndexStatsStage.php
+++ b/src/Builder/Stage/IndexStatsStage.php
@@ -16,17 +16,14 @@
* Returns statistics regarding the use of each index for the collection.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/indexStats/
+ * @internal
*/
-class IndexStatsStage implements StageInterface, OperatorInterface
+final class IndexStatsStage implements StageInterface, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$indexStats';
public function __construct()
{
}
-
- public function getOperator(): string
- {
- return '$indexStats';
- }
}
diff --git a/src/Builder/Stage/LimitStage.php b/src/Builder/Stage/LimitStage.php
index 593fc2c70..ec765fa8a 100644
--- a/src/Builder/Stage/LimitStage.php
+++ b/src/Builder/Stage/LimitStage.php
@@ -16,10 +16,13 @@
* 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/
+ * @internal
*/
-class LimitStage implements StageInterface, OperatorInterface
+final class LimitStage implements StageInterface, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$limit';
+ public const PROPERTIES = ['limit' => 'limit'];
/** @var int $limit */
public readonly int $limit;
@@ -31,9 +34,4 @@ public function __construct(int $limit)
{
$this->limit = $limit;
}
-
- public function getOperator(): string
- {
- return '$limit';
- }
}
diff --git a/src/Builder/Stage/ListLocalSessionsStage.php b/src/Builder/Stage/ListLocalSessionsStage.php
index de60e49f4..f438b0148 100644
--- a/src/Builder/Stage/ListLocalSessionsStage.php
+++ b/src/Builder/Stage/ListLocalSessionsStage.php
@@ -23,10 +23,13 @@
* 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/
+ * @internal
*/
-class ListLocalSessionsStage implements StageInterface, OperatorInterface
+final class ListLocalSessionsStage implements StageInterface, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$listLocalSessions';
+ public const PROPERTIES = ['users' => 'users', 'allUsers' => 'allUsers'];
/** @var 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 readonly Optional|PackedArray|BSONArray|array $users;
@@ -49,9 +52,4 @@ public function __construct(
$this->users = $users;
$this->allUsers = $allUsers;
}
-
- public function getOperator(): string
- {
- return '$listLocalSessions';
- }
}
diff --git a/src/Builder/Stage/ListSampledQueriesStage.php b/src/Builder/Stage/ListSampledQueriesStage.php
index 8669c0fe8..afa242591 100644
--- a/src/Builder/Stage/ListSampledQueriesStage.php
+++ b/src/Builder/Stage/ListSampledQueriesStage.php
@@ -17,10 +17,13 @@
* Lists sampled queries for all collections or a specific collection.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSampledQueries/
+ * @internal
*/
-class ListSampledQueriesStage implements StageInterface, OperatorInterface
+final class ListSampledQueriesStage implements StageInterface, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$listSampledQueries';
+ public const PROPERTIES = ['namespace' => 'namespace'];
/** @var Optional|string $namespace */
public readonly Optional|string $namespace;
@@ -32,9 +35,4 @@ public function __construct(Optional|string $namespace = Optional::Undefined)
{
$this->namespace = $namespace;
}
-
- public function getOperator(): string
- {
- return '$listSampledQueries';
- }
}
diff --git a/src/Builder/Stage/ListSearchIndexesStage.php b/src/Builder/Stage/ListSearchIndexesStage.php
index a2850eab2..c6643ad33 100644
--- a/src/Builder/Stage/ListSearchIndexesStage.php
+++ b/src/Builder/Stage/ListSearchIndexesStage.php
@@ -17,10 +17,13 @@
* Returns information about existing Atlas Search indexes on a specified collection.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/listSearchIndexes/
+ * @internal
*/
-class ListSearchIndexesStage implements StageInterface, OperatorInterface
+final class ListSearchIndexesStage implements StageInterface, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$listSearchIndexes';
+ public const PROPERTIES = ['id' => 'id', 'name' => 'name'];
/** @var Optional|string $id The id of the index to return information about. */
public readonly Optional|string $id;
@@ -39,9 +42,4 @@ public function __construct(
$this->id = $id;
$this->name = $name;
}
-
- public function getOperator(): string
- {
- return '$listSearchIndexes';
- }
}
diff --git a/src/Builder/Stage/ListSessionsStage.php b/src/Builder/Stage/ListSessionsStage.php
index f299874db..687425ce1 100644
--- a/src/Builder/Stage/ListSessionsStage.php
+++ b/src/Builder/Stage/ListSessionsStage.php
@@ -23,10 +23,13 @@
* 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/
+ * @internal
*/
-class ListSessionsStage implements StageInterface, OperatorInterface
+final class ListSessionsStage implements StageInterface, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$listSessions';
+ public const PROPERTIES = ['users' => 'users', 'allUsers' => 'allUsers'];
/** @var 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 readonly Optional|PackedArray|BSONArray|array $users;
@@ -49,9 +52,4 @@ public function __construct(
$this->users = $users;
$this->allUsers = $allUsers;
}
-
- public function getOperator(): string
- {
- return '$listSessions';
- }
}
diff --git a/src/Builder/Stage/LookupStage.php b/src/Builder/Stage/LookupStage.php
index 34f0fb66f..a9bf0d7ee 100644
--- a/src/Builder/Stage/LookupStage.php
+++ b/src/Builder/Stage/LookupStage.php
@@ -27,10 +27,21 @@
* 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/
+ * @internal
*/
-class LookupStage implements StageInterface, OperatorInterface
+final class LookupStage implements StageInterface, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$lookup';
+
+ public const PROPERTIES = [
+ 'as' => 'as',
+ 'from' => 'from',
+ 'localField' => 'localField',
+ 'foreignField' => 'foreignField',
+ 'let' => 'let',
+ 'pipeline' => 'pipeline',
+ ];
/** @var 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. */
public readonly string $as;
@@ -89,9 +100,4 @@ public function __construct(
$this->pipeline = $pipeline;
}
-
- public function getOperator(): string
- {
- return '$lookup';
- }
}
diff --git a/src/Builder/Stage/MatchStage.php b/src/Builder/Stage/MatchStage.php
index 9590763ae..0c88db2cf 100644
--- a/src/Builder/Stage/MatchStage.php
+++ b/src/Builder/Stage/MatchStage.php
@@ -20,10 +20,13 @@
* 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/
+ * @internal
*/
-class MatchStage implements StageInterface, OperatorInterface
+final class MatchStage implements StageInterface, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$match';
+ public const PROPERTIES = ['query' => 'query'];
/** @var QueryInterface|array $query */
public readonly QueryInterface|array $query;
@@ -39,9 +42,4 @@ public function __construct(QueryInterface|array $query)
$this->query = $query;
}
-
- public function getOperator(): string
- {
- return '$match';
- }
}
diff --git a/src/Builder/Stage/MergeStage.php b/src/Builder/Stage/MergeStage.php
index 271c012ac..2fc3e94da 100644
--- a/src/Builder/Stage/MergeStage.php
+++ b/src/Builder/Stage/MergeStage.php
@@ -28,10 +28,20 @@
* New in MongoDB 4.2.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/merge/
+ * @internal
*/
-class MergeStage implements StageInterface, OperatorInterface
+final class MergeStage implements StageInterface, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$merge';
+
+ public const PROPERTIES = [
+ 'into' => 'into',
+ 'on' => 'on',
+ 'let' => 'let',
+ 'whenMatched' => 'whenMatched',
+ 'whenNotMatched' => 'whenNotMatched',
+ ];
/** @var Document|Serializable|array|stdClass|string $into The output collection. */
public readonly Document|Serializable|stdClass|array|string $into;
@@ -76,9 +86,4 @@ public function __construct(
$this->whenMatched = $whenMatched;
$this->whenNotMatched = $whenNotMatched;
}
-
- public function getOperator(): string
- {
- return '$merge';
- }
}
diff --git a/src/Builder/Stage/OutStage.php b/src/Builder/Stage/OutStage.php
index 5e99d578a..77959edc8 100644
--- a/src/Builder/Stage/OutStage.php
+++ b/src/Builder/Stage/OutStage.php
@@ -19,10 +19,13 @@
* 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/
+ * @internal
*/
-class OutStage implements StageInterface, OperatorInterface
+final class OutStage implements StageInterface, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$out';
+ public const PROPERTIES = ['coll' => 'coll'];
/** @var Document|Serializable|array|stdClass|string $coll Target database name to write documents from $out to. */
public readonly Document|Serializable|stdClass|array|string $coll;
@@ -34,9 +37,4 @@ public function __construct(Document|Serializable|stdClass|array|string $coll)
{
$this->coll = $coll;
}
-
- public function getOperator(): string
- {
- return '$out';
- }
}
diff --git a/src/Builder/Stage/PlanCacheStatsStage.php b/src/Builder/Stage/PlanCacheStatsStage.php
index 98755095f..5cfd75674 100644
--- a/src/Builder/Stage/PlanCacheStatsStage.php
+++ b/src/Builder/Stage/PlanCacheStatsStage.php
@@ -16,17 +16,14 @@
* Returns plan cache information for a collection.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/planCacheStats/
+ * @internal
*/
-class PlanCacheStatsStage implements StageInterface, OperatorInterface
+final class PlanCacheStatsStage implements StageInterface, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$planCacheStats';
public function __construct()
{
}
-
- public function getOperator(): string
- {
- return '$planCacheStats';
- }
}
diff --git a/src/Builder/Stage/ProjectStage.php b/src/Builder/Stage/ProjectStage.php
index c8cd58c04..4b1c0f350 100644
--- a/src/Builder/Stage/ProjectStage.php
+++ b/src/Builder/Stage/ProjectStage.php
@@ -22,10 +22,13 @@
* 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/
+ * @internal
*/
-class ProjectStage implements StageInterface, OperatorInterface
+final class ProjectStage implements StageInterface, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$project';
+ public const PROPERTIES = ['specification' => 'specification'];
/** @var stdClass $specification */
public readonly stdClass $specification;
@@ -48,9 +51,4 @@ public function __construct(Type|ExpressionInterface|stdClass|array|bool|float|i
$specification = (object) $specification;
$this->specification = $specification;
}
-
- public function getOperator(): string
- {
- return '$project';
- }
}
diff --git a/src/Builder/Stage/RedactStage.php b/src/Builder/Stage/RedactStage.php
index 96dcab949..a1db25265 100644
--- a/src/Builder/Stage/RedactStage.php
+++ b/src/Builder/Stage/RedactStage.php
@@ -19,10 +19,13 @@
* 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/
+ * @internal
*/
-class RedactStage implements StageInterface, OperatorInterface
+final class RedactStage implements StageInterface, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$redact';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */
public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression;
@@ -34,9 +37,4 @@ public function __construct(Type|ExpressionInterface|stdClass|array|bool|float|i
{
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$redact';
- }
}
diff --git a/src/Builder/Stage/ReplaceRootStage.php b/src/Builder/Stage/ReplaceRootStage.php
index 5c97b1f15..f88bf07b2 100644
--- a/src/Builder/Stage/ReplaceRootStage.php
+++ b/src/Builder/Stage/ReplaceRootStage.php
@@ -20,10 +20,13 @@
* 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/
+ * @internal
*/
-class ReplaceRootStage implements StageInterface, OperatorInterface
+final class ReplaceRootStage implements StageInterface, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$replaceRoot';
+ public const PROPERTIES = ['newRoot' => 'newRoot'];
/** @var Document|ResolvesToObject|Serializable|array|stdClass $newRoot */
public readonly Document|Serializable|ResolvesToObject|stdClass|array $newRoot;
@@ -35,9 +38,4 @@ public function __construct(Document|Serializable|ResolvesToObject|stdClass|arra
{
$this->newRoot = $newRoot;
}
-
- public function getOperator(): string
- {
- return '$replaceRoot';
- }
}
diff --git a/src/Builder/Stage/ReplaceWithStage.php b/src/Builder/Stage/ReplaceWithStage.php
index 6741a38fc..84d6ffda4 100644
--- a/src/Builder/Stage/ReplaceWithStage.php
+++ b/src/Builder/Stage/ReplaceWithStage.php
@@ -21,10 +21,13 @@
* Alias for $replaceRoot.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/replaceWith/
+ * @internal
*/
-class ReplaceWithStage implements StageInterface, OperatorInterface
+final class ReplaceWithStage implements StageInterface, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$replaceWith';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var Document|ResolvesToObject|Serializable|array|stdClass $expression */
public readonly Document|Serializable|ResolvesToObject|stdClass|array $expression;
@@ -36,9 +39,4 @@ public function __construct(Document|Serializable|ResolvesToObject|stdClass|arra
{
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$replaceWith';
- }
}
diff --git a/src/Builder/Stage/SampleStage.php b/src/Builder/Stage/SampleStage.php
index 9cf433eb5..c00b2bb26 100644
--- a/src/Builder/Stage/SampleStage.php
+++ b/src/Builder/Stage/SampleStage.php
@@ -16,10 +16,13 @@
* Randomly selects the specified number of documents from its input.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/sample/
+ * @internal
*/
-class SampleStage implements StageInterface, OperatorInterface
+final class SampleStage implements StageInterface, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$sample';
+ public const PROPERTIES = ['size' => 'size'];
/** @var int $size The number of documents to randomly select. */
public readonly int $size;
@@ -31,9 +34,4 @@ public function __construct(int $size)
{
$this->size = $size;
}
-
- public function getOperator(): string
- {
- return '$sample';
- }
}
diff --git a/src/Builder/Stage/SearchMetaStage.php b/src/Builder/Stage/SearchMetaStage.php
index c27b230eb..14687161b 100644
--- a/src/Builder/Stage/SearchMetaStage.php
+++ b/src/Builder/Stage/SearchMetaStage.php
@@ -12,6 +12,8 @@
use MongoDB\BSON\Serializable;
use MongoDB\Builder\Type\Encode;
use MongoDB\Builder\Type\OperatorInterface;
+use MongoDB\Builder\Type\Optional;
+use MongoDB\Builder\Type\SearchOperatorInterface;
use MongoDB\Builder\Type\StageInterface;
use stdClass;
@@ -20,24 +22,39 @@
* 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/
+ * @internal
*/
-class SearchMetaStage implements StageInterface, OperatorInterface
+final class SearchMetaStage implements StageInterface, OperatorInterface
{
- public const ENCODE = Encode::Single;
-
- /** @var Document|Serializable|array|stdClass $meta */
- public readonly Document|Serializable|stdClass|array $meta;
+ public const ENCODE = Encode::Object;
+ public const NAME = '$searchMeta';
+ public const PROPERTIES = ['operator' => null, 'index' => 'index', 'count' => 'count'];
/**
- * @param Document|Serializable|array|stdClass $meta
+ * @var Document|SearchOperatorInterface|Serializable|array|stdClass $operator Operator to search with. You can provide a specific operator or use
+ * the compound operator to run a compound query with multiple operators.
*/
- public function __construct(Document|Serializable|stdClass|array $meta)
- {
- $this->meta = $meta;
- }
+ public readonly Document|Serializable|SearchOperatorInterface|stdClass|array $operator;
+
+ /** @var Optional|string $index Name of the Atlas Search index to use. If omitted, defaults to default. */
+ public readonly Optional|string $index;
- public function getOperator(): string
- {
- return '$searchMeta';
+ /** @var Optional|Document|Serializable|array|stdClass $count Document that specifies the count options for retrieving a count of the results. */
+ public readonly Optional|Document|Serializable|stdClass|array $count;
+
+ /**
+ * @param Document|SearchOperatorInterface|Serializable|array|stdClass $operator Operator to search with. You can provide a specific operator or use
+ * the compound operator to run a compound query with multiple operators.
+ * @param Optional|string $index Name of the Atlas Search index to use. If omitted, defaults to default.
+ * @param Optional|Document|Serializable|array|stdClass $count Document that specifies the count options for retrieving a count of the results.
+ */
+ public function __construct(
+ Document|Serializable|SearchOperatorInterface|stdClass|array $operator,
+ Optional|string $index = Optional::Undefined,
+ Optional|Document|Serializable|stdClass|array $count = Optional::Undefined,
+ ) {
+ $this->operator = $operator;
+ $this->index = $index;
+ $this->count = $count;
}
}
diff --git a/src/Builder/Stage/SearchStage.php b/src/Builder/Stage/SearchStage.php
index 3eed9c17d..bd224dba9 100644
--- a/src/Builder/Stage/SearchStage.php
+++ b/src/Builder/Stage/SearchStage.php
@@ -12,6 +12,8 @@
use MongoDB\BSON\Serializable;
use MongoDB\Builder\Type\Encode;
use MongoDB\Builder\Type\OperatorInterface;
+use MongoDB\Builder\Type\Optional;
+use MongoDB\Builder\Type\SearchOperatorInterface;
use MongoDB\Builder\Type\StageInterface;
use stdClass;
@@ -20,24 +22,106 @@
* 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/
+ * @internal
*/
-class SearchStage implements StageInterface, OperatorInterface
+final class SearchStage implements StageInterface, OperatorInterface
{
- public const ENCODE = Encode::Single;
+ public const ENCODE = Encode::Object;
+ public const NAME = '$search';
- /** @var Document|Serializable|array|stdClass $search */
- public readonly Document|Serializable|stdClass|array $search;
+ public const PROPERTIES = [
+ 'operator' => null,
+ 'index' => 'index',
+ 'highlight' => 'highlight',
+ 'concurrent' => 'concurrent',
+ 'count' => 'count',
+ 'searchAfter' => 'searchAfter',
+ 'searchBefore' => 'searchBefore',
+ 'scoreDetails' => 'scoreDetails',
+ 'sort' => 'sort',
+ 'returnStoredSource' => 'returnStoredSource',
+ 'tracking' => 'tracking',
+ ];
/**
- * @param Document|Serializable|array|stdClass $search
+ * @var Document|SearchOperatorInterface|Serializable|array|stdClass $operator Operator to search with. You can provide a specific operator or use
+ * the compound operator to run a compound query with multiple operators.
*/
- public function __construct(Document|Serializable|stdClass|array $search)
- {
- $this->search = $search;
- }
+ public readonly Document|Serializable|SearchOperatorInterface|stdClass|array $operator;
+
+ /** @var Optional|string $index Name of the Atlas Search index to use. If omitted, defaults to "default". */
+ public readonly Optional|string $index;
+
+ /** @var Optional|Document|Serializable|array|stdClass $highlight Specifies the highlighting options for displaying search terms in their original context. */
+ public readonly Optional|Document|Serializable|stdClass|array $highlight;
+
+ /**
+ * @var Optional|bool $concurrent Parallelize search across segments on dedicated search nodes.
+ * If you don't have separate search nodes on your cluster,
+ * Atlas Search ignores this flag. If omitted, defaults to false.
+ */
+ public readonly Optional|bool $concurrent;
+
+ /** @var Optional|string $count Document that specifies the count options for retrieving a count of the results. */
+ public readonly Optional|string $count;
+
+ /** @var Optional|string $searchAfter Reference point for retrieving results. searchAfter returns documents starting immediately following the specified reference point. */
+ public readonly Optional|string $searchAfter;
- public function getOperator(): string
- {
- return '$search';
+ /** @var Optional|string $searchBefore Reference point for retrieving results. searchBefore returns documents starting immediately before the specified reference point. */
+ public readonly Optional|string $searchBefore;
+
+ /** @var Optional|bool $scoreDetails Flag that specifies whether to retrieve a detailed breakdown of the score for the documents in the results. If omitted, defaults to false. */
+ public readonly Optional|bool $scoreDetails;
+
+ /** @var Optional|Document|Serializable|array|stdClass $sort Document that specifies the fields to sort the Atlas Search results by in ascending or descending order. */
+ public readonly Optional|Document|Serializable|stdClass|array $sort;
+
+ /** @var Optional|bool $returnStoredSource Flag that specifies whether to perform a full document lookup on the backend database or return only stored source fields directly from Atlas Search. */
+ public readonly Optional|bool $returnStoredSource;
+
+ /** @var Optional|Document|Serializable|array|stdClass $tracking Document that specifies the tracking option to retrieve analytics information on the search terms. */
+ public readonly Optional|Document|Serializable|stdClass|array $tracking;
+
+ /**
+ * @param Document|SearchOperatorInterface|Serializable|array|stdClass $operator Operator to search with. You can provide a specific operator or use
+ * the compound operator to run a compound query with multiple operators.
+ * @param Optional|string $index Name of the Atlas Search index to use. If omitted, defaults to "default".
+ * @param Optional|Document|Serializable|array|stdClass $highlight Specifies the highlighting options for displaying search terms in their original context.
+ * @param Optional|bool $concurrent Parallelize search across segments on dedicated search nodes.
+ * If you don't have separate search nodes on your cluster,
+ * Atlas Search ignores this flag. If omitted, defaults to false.
+ * @param Optional|string $count Document that specifies the count options for retrieving a count of the results.
+ * @param Optional|string $searchAfter Reference point for retrieving results. searchAfter returns documents starting immediately following the specified reference point.
+ * @param Optional|string $searchBefore Reference point for retrieving results. searchBefore returns documents starting immediately before the specified reference point.
+ * @param Optional|bool $scoreDetails Flag that specifies whether to retrieve a detailed breakdown of the score for the documents in the results. If omitted, defaults to false.
+ * @param Optional|Document|Serializable|array|stdClass $sort Document that specifies the fields to sort the Atlas Search results by in ascending or descending order.
+ * @param Optional|bool $returnStoredSource Flag that specifies whether to perform a full document lookup on the backend database or return only stored source fields directly from Atlas Search.
+ * @param Optional|Document|Serializable|array|stdClass $tracking Document that specifies the tracking option to retrieve analytics information on the search terms.
+ */
+ public function __construct(
+ Document|Serializable|SearchOperatorInterface|stdClass|array $operator,
+ Optional|string $index = Optional::Undefined,
+ Optional|Document|Serializable|stdClass|array $highlight = Optional::Undefined,
+ Optional|bool $concurrent = Optional::Undefined,
+ Optional|string $count = Optional::Undefined,
+ Optional|string $searchAfter = Optional::Undefined,
+ Optional|string $searchBefore = Optional::Undefined,
+ Optional|bool $scoreDetails = Optional::Undefined,
+ Optional|Document|Serializable|stdClass|array $sort = Optional::Undefined,
+ Optional|bool $returnStoredSource = Optional::Undefined,
+ Optional|Document|Serializable|stdClass|array $tracking = Optional::Undefined,
+ ) {
+ $this->operator = $operator;
+ $this->index = $index;
+ $this->highlight = $highlight;
+ $this->concurrent = $concurrent;
+ $this->count = $count;
+ $this->searchAfter = $searchAfter;
+ $this->searchBefore = $searchBefore;
+ $this->scoreDetails = $scoreDetails;
+ $this->sort = $sort;
+ $this->returnStoredSource = $returnStoredSource;
+ $this->tracking = $tracking;
}
}
diff --git a/src/Builder/Stage/SetStage.php b/src/Builder/Stage/SetStage.php
index ca929a2b8..45c545474 100644
--- a/src/Builder/Stage/SetStage.php
+++ b/src/Builder/Stage/SetStage.php
@@ -23,10 +23,13 @@
* Alias for $addFields.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/set/
+ * @internal
*/
-class SetStage implements StageInterface, OperatorInterface
+final class SetStage implements StageInterface, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$set';
+ public const PROPERTIES = ['field' => 'field'];
/** @var stdClass $field */
public readonly stdClass $field;
@@ -49,9 +52,4 @@ public function __construct(Type|ExpressionInterface|stdClass|array|bool|float|i
$field = (object) $field;
$this->field = $field;
}
-
- public function getOperator(): string
- {
- return '$set';
- }
}
diff --git a/src/Builder/Stage/SetWindowFieldsStage.php b/src/Builder/Stage/SetWindowFieldsStage.php
index cb1354e66..ba8d63edf 100644
--- a/src/Builder/Stage/SetWindowFieldsStage.php
+++ b/src/Builder/Stage/SetWindowFieldsStage.php
@@ -23,10 +23,13 @@
* New in MongoDB 5.0.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/setWindowFields/
+ * @internal
*/
-class SetWindowFieldsStage implements StageInterface, OperatorInterface
+final class SetWindowFieldsStage implements StageInterface, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$setWindowFields';
+ public const PROPERTIES = ['sortBy' => 'sortBy', 'output' => 'output', 'partitionBy' => 'partitionBy'];
/** @var 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 readonly Document|Serializable|stdClass|array $sortBy;
@@ -55,9 +58,4 @@ public function __construct(
$this->output = $output;
$this->partitionBy = $partitionBy;
}
-
- public function getOperator(): string
- {
- return '$setWindowFields';
- }
}
diff --git a/src/Builder/Stage/ShardedDataDistributionStage.php b/src/Builder/Stage/ShardedDataDistributionStage.php
index de3c3f3a0..fe07d282a 100644
--- a/src/Builder/Stage/ShardedDataDistributionStage.php
+++ b/src/Builder/Stage/ShardedDataDistributionStage.php
@@ -17,17 +17,14 @@
* New in MongoDB 6.0.3.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/shardedDataDistribution/
+ * @internal
*/
-class ShardedDataDistributionStage implements StageInterface, OperatorInterface
+final class ShardedDataDistributionStage implements StageInterface, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$shardedDataDistribution';
public function __construct()
{
}
-
- public function getOperator(): string
- {
- return '$shardedDataDistribution';
- }
}
diff --git a/src/Builder/Stage/SkipStage.php b/src/Builder/Stage/SkipStage.php
index 171ee515a..aab0242d8 100644
--- a/src/Builder/Stage/SkipStage.php
+++ b/src/Builder/Stage/SkipStage.php
@@ -16,10 +16,13 @@
* 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/
+ * @internal
*/
-class SkipStage implements StageInterface, OperatorInterface
+final class SkipStage implements StageInterface, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$skip';
+ public const PROPERTIES = ['skip' => 'skip'];
/** @var int $skip */
public readonly int $skip;
@@ -31,9 +34,4 @@ public function __construct(int $skip)
{
$this->skip = $skip;
}
-
- public function getOperator(): string
- {
- return '$skip';
- }
}
diff --git a/src/Builder/Stage/SortByCountStage.php b/src/Builder/Stage/SortByCountStage.php
index 9c7160b8c..5e8f8821a 100644
--- a/src/Builder/Stage/SortByCountStage.php
+++ b/src/Builder/Stage/SortByCountStage.php
@@ -19,10 +19,13 @@
* 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/
+ * @internal
*/
-class SortByCountStage implements StageInterface, OperatorInterface
+final class SortByCountStage implements StageInterface, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$sortByCount';
+ public const PROPERTIES = ['expression' => 'expression'];
/** @var ExpressionInterface|Type|array|bool|float|int|null|stdClass|string $expression */
public readonly Type|ExpressionInterface|stdClass|array|bool|float|int|null|string $expression;
@@ -34,9 +37,4 @@ public function __construct(Type|ExpressionInterface|stdClass|array|bool|float|i
{
$this->expression = $expression;
}
-
- public function getOperator(): string
- {
- return '$sortByCount';
- }
}
diff --git a/src/Builder/Stage/SortStage.php b/src/Builder/Stage/SortStage.php
index 5f4de9e19..f913d2897 100644
--- a/src/Builder/Stage/SortStage.php
+++ b/src/Builder/Stage/SortStage.php
@@ -23,10 +23,13 @@
* 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/
+ * @internal
*/
-class SortStage implements StageInterface, OperatorInterface
+final class SortStage implements StageInterface, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$sort';
+ public const PROPERTIES = ['sort' => 'sort'];
/** @var stdClass $sort */
public readonly stdClass $sort;
@@ -49,9 +52,4 @@ public function __construct(Type|ExpressionInterface|Sort|stdClass|array|bool|fl
$sort = (object) $sort;
$this->sort = $sort;
}
-
- public function getOperator(): string
- {
- return '$sort';
- }
}
diff --git a/src/Builder/Stage/UnionWithStage.php b/src/Builder/Stage/UnionWithStage.php
index 0882f74cb..25ced13de 100644
--- a/src/Builder/Stage/UnionWithStage.php
+++ b/src/Builder/Stage/UnionWithStage.php
@@ -25,10 +25,13 @@
* New in MongoDB 4.4.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/unionWith/
+ * @internal
*/
-class UnionWithStage implements StageInterface, OperatorInterface
+final class UnionWithStage implements StageInterface, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$unionWith';
+ public const PROPERTIES = ['coll' => 'coll', 'pipeline' => 'pipeline'];
/** @var string $coll The collection or view whose pipeline results you wish to include in the result set. */
public readonly string $coll;
@@ -55,9 +58,4 @@ public function __construct(
$this->pipeline = $pipeline;
}
-
- public function getOperator(): string
- {
- return '$unionWith';
- }
}
diff --git a/src/Builder/Stage/UnsetStage.php b/src/Builder/Stage/UnsetStage.php
index f75546ed0..43575d8d5 100644
--- a/src/Builder/Stage/UnsetStage.php
+++ b/src/Builder/Stage/UnsetStage.php
@@ -21,10 +21,13 @@
* Alias for $project stage that removes or excludes fields.
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/unset/
+ * @internal
*/
-class UnsetStage implements StageInterface, OperatorInterface
+final class UnsetStage implements StageInterface, OperatorInterface
{
public const ENCODE = Encode::Single;
+ public const NAME = '$unset';
+ public const PROPERTIES = ['field' => 'field'];
/** @var list $field */
public readonly array $field;
@@ -45,9 +48,4 @@ public function __construct(FieldPath|string ...$field)
$this->field = $field;
}
-
- public function getOperator(): string
- {
- return '$unset';
- }
}
diff --git a/src/Builder/Stage/UnwindStage.php b/src/Builder/Stage/UnwindStage.php
index 09c9f1e82..9959f462b 100644
--- a/src/Builder/Stage/UnwindStage.php
+++ b/src/Builder/Stage/UnwindStage.php
@@ -18,10 +18,18 @@
* 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/
+ * @internal
*/
-class UnwindStage implements StageInterface, OperatorInterface
+final class UnwindStage implements StageInterface, OperatorInterface
{
public const ENCODE = Encode::Object;
+ public const NAME = '$unwind';
+
+ public const PROPERTIES = [
+ 'path' => 'path',
+ 'includeArrayIndex' => 'includeArrayIndex',
+ 'preserveNullAndEmptyArrays' => 'preserveNullAndEmptyArrays',
+ ];
/** @var ArrayFieldPath|string $path Field path to an array field. */
public readonly ArrayFieldPath|string $path;
@@ -52,9 +60,4 @@ public function __construct(
$this->includeArrayIndex = $includeArrayIndex;
$this->preserveNullAndEmptyArrays = $preserveNullAndEmptyArrays;
}
-
- public function getOperator(): string
- {
- return '$unwind';
- }
}
diff --git a/src/Builder/Stage/VectorSearchStage.php b/src/Builder/Stage/VectorSearchStage.php
new file mode 100644
index 000000000..e8f7738cc
--- /dev/null
+++ b/src/Builder/Stage/VectorSearchStage.php
@@ -0,0 +1,104 @@
+ 'index',
+ 'limit' => 'limit',
+ 'path' => 'path',
+ 'queryVector' => 'queryVector',
+ 'exact' => 'exact',
+ 'filter' => 'filter',
+ 'numCandidates' => 'numCandidates',
+ ];
+
+ /** @var string $index Name of the Atlas Vector Search index to use. */
+ public readonly string $index;
+
+ /** @var int $limit Number of documents to return in the results. This value can't exceed the value of numCandidates if you specify numCandidates. */
+ public readonly int $limit;
+
+ /** @var array|string $path Indexed vector type field to search. */
+ public readonly array|string $path;
+
+ /** @var BSONArray|PackedArray|array $queryVector Array of numbers that represent the query vector. The number type must match the indexed field value type. */
+ public readonly PackedArray|BSONArray|array $queryVector;
+
+ /** @var Optional|bool $exact This is required if numCandidates is omitted. false to run ANN search. true to run ENN search. */
+ public readonly Optional|bool $exact;
+
+ /** @var Optional|QueryInterface|array $filter Any match query that compares an indexed field with a boolean, date, objectId, number (not decimals), string, or UUID to use as a pre-filter. */
+ public readonly Optional|QueryInterface|array $filter;
+
+ /**
+ * @var Optional|int $numCandidates This field is required if exact is false or omitted.
+ * Number of nearest neighbors to use during the search. Value must be less than or equal to (<=) 10000. You can't specify a number less than the number of documents to return (limit).
+ */
+ public readonly Optional|int $numCandidates;
+
+ /**
+ * @param string $index Name of the Atlas Vector Search index to use.
+ * @param int $limit Number of documents to return in the results. This value can't exceed the value of numCandidates if you specify numCandidates.
+ * @param array|string $path Indexed vector type field to search.
+ * @param BSONArray|PackedArray|array $queryVector Array of numbers that represent the query vector. The number type must match the indexed field value type.
+ * @param Optional|bool $exact This is required if numCandidates is omitted. false to run ANN search. true to run ENN search.
+ * @param Optional|QueryInterface|array $filter Any match query that compares an indexed field with a boolean, date, objectId, number (not decimals), string, or UUID to use as a pre-filter.
+ * @param Optional|int $numCandidates This field is required if exact is false or omitted.
+ * Number of nearest neighbors to use during the search. Value must be less than or equal to (<=) 10000. You can't specify a number less than the number of documents to return (limit).
+ */
+ public function __construct(
+ string $index,
+ int $limit,
+ array|string $path,
+ PackedArray|BSONArray|array $queryVector,
+ Optional|bool $exact = Optional::Undefined,
+ Optional|QueryInterface|array $filter = Optional::Undefined,
+ Optional|int $numCandidates = Optional::Undefined,
+ ) {
+ $this->index = $index;
+ $this->limit = $limit;
+ $this->path = $path;
+ if (is_array($queryVector) && ! array_is_list($queryVector)) {
+ throw new InvalidArgumentException('Expected $queryVector argument to be a list, got an associative array.');
+ }
+
+ $this->queryVector = $queryVector;
+ $this->exact = $exact;
+ if (is_array($filter)) {
+ $filter = QueryObject::create($filter);
+ }
+
+ $this->filter = $filter;
+ $this->numCandidates = $numCandidates;
+ }
+}
diff --git a/src/Builder/Type/CombinedFieldQuery.php b/src/Builder/Type/CombinedFieldQuery.php
index 7619d0ccc..59f5a8554 100644
--- a/src/Builder/Type/CombinedFieldQuery.php
+++ b/src/Builder/Type/CombinedFieldQuery.php
@@ -23,8 +23,10 @@
/**
* List of field queries that apply to the same field path.
+ *
+ * @internal
*/
-class CombinedFieldQuery implements FieldQueryInterface
+final class CombinedFieldQuery implements FieldQueryInterface
{
/** @var list $fieldQueries */
public readonly array $fieldQueries;
@@ -57,6 +59,7 @@ static function (array $fieldQueries, QueryInterface|FieldQueryInterface|Type|st
);
// Validate FieldQuery types and non-duplicate operators
+ /** @var array $seenOperators */
$seenOperators = [];
foreach ($this->fieldQueries as $fieldQuery) {
if ($fieldQuery instanceof stdClass) {
@@ -64,7 +67,7 @@ static function (array $fieldQueries, QueryInterface|FieldQueryInterface|Type|st
}
if ($fieldQuery instanceof FieldQueryInterface && $fieldQuery instanceof OperatorInterface) {
- $operator = $fieldQuery->getOperator();
+ $operator = $fieldQuery::NAME;
} elseif (is_array($fieldQuery)) {
if (count($fieldQuery) !== 1) {
throw new InvalidArgumentException(sprintf('Operator must contain exactly one key, %d given', count($fieldQuery)));
diff --git a/src/Builder/Type/Encode.php b/src/Builder/Type/Encode.php
index 85a5eaf66..120c2ee46 100644
--- a/src/Builder/Type/Encode.php
+++ b/src/Builder/Type/Encode.php
@@ -10,6 +10,7 @@
* Defines how to encode a stage or an operator into BSON.
*
* @see BuilderEncoder
+ * @internal
*/
enum Encode
{
@@ -23,16 +24,6 @@ enum Encode
*/
case Object;
- /**
- * Same as Object, but only parameters are returned. The operator name will not be used.
- */
- case FlatObject;
-
- /**
- * Parameters are encoded as an object with keys matching the parameter names prefixed with a dollar sign ($)
- */
- case DollarObject;
-
/**
* Get the single parameter value
*/
diff --git a/src/Builder/Type/OperatorInterface.php b/src/Builder/Type/OperatorInterface.php
index f219fb52b..43d9f3f84 100644
--- a/src/Builder/Type/OperatorInterface.php
+++ b/src/Builder/Type/OperatorInterface.php
@@ -9,8 +9,12 @@
*/
interface OperatorInterface
{
- /** To be overridden by implementing classes */
+ /** @var Encode */
public const ENCODE = Encode::Undefined;
- public function getOperator(): string;
+ /** @var array */
+ public const PROPERTIES = [];
+
+ /** @var string|null */
+ public const NAME = null;
}
diff --git a/src/Builder/Type/OutputWindow.php b/src/Builder/Type/OutputWindow.php
index 2f6b791a4..72d433ca8 100644
--- a/src/Builder/Type/OutputWindow.php
+++ b/src/Builder/Type/OutputWindow.php
@@ -23,7 +23,7 @@
*
* @see https://www.mongodb.com/docs/manual/reference/operator/aggregation/setWindowFields/
*/
-class OutputWindow implements WindowInterface
+final class OutputWindow implements WindowInterface
{
/**
* Function used to initialize the state. The init function receives its arguments from the initArgs array expression.
diff --git a/src/Builder/Type/ProjectionInterface.php b/src/Builder/Type/ProjectionInterface.php
deleted file mode 100644
index e411dde60..000000000
--- a/src/Builder/Type/ProjectionInterface.php
+++ /dev/null
@@ -1,14 +0,0 @@
- $query) {
if ($query instanceof QueryInterface) {
if ($query instanceof OperatorInterface) {
- if (isset($seenQueryOperators[$query->getOperator()])) {
- throw new InvalidArgumentException(sprintf('Query operator "%s" cannot be used multiple times in the same query.', $query->getOperator()));
+ if (isset($seenQueryOperators[$query::NAME])) {
+ throw new InvalidArgumentException(sprintf('Query operator "%s" cannot be used multiple times in the same query.', $query::NAME));
}
- $seenQueryOperators[$query->getOperator()] = true;
+ $seenQueryOperators[$query::NAME] = true;
}
$queries[] = $query;
diff --git a/src/Builder/Type/SearchOperatorInterface.php b/src/Builder/Type/SearchOperatorInterface.php
new file mode 100644
index 000000000..c144d4ebe
--- /dev/null
+++ b/src/Builder/Type/SearchOperatorInterface.php
@@ -0,0 +1,7 @@
+assertSamePipeline(Pipelines::AutocompleteAcrossMultipleFields, $pipeline);
+ }
+
+ public function testBasic(): void
+ {
+ $pipeline = new Pipeline(
+ Stage::search(
+ Search::autocomplete(
+ query: 'off',
+ path: 'title',
+ ),
+ ),
+ Stage::limit(10),
+ Stage::project(_id: 0, title: 1),
+ );
+
+ $this->assertSamePipeline(Pipelines::AutocompleteBasic, $pipeline);
+ }
+
+ public function testFuzzy(): void
+ {
+ $pipeline = new Pipeline(
+ Stage::search(
+ Search::autocomplete(
+ query: 'pre',
+ path: 'title',
+ fuzzy: object(
+ maxEdits: 1,
+ prefixLength: 1,
+ maxExpansions: 256,
+ ),
+ ),
+ ),
+ Stage::limit(10),
+ Stage::project(_id: 0, title: 1),
+ );
+
+ $this->assertSamePipeline(Pipelines::AutocompleteFuzzy, $pipeline);
+ }
+
+ public function testHighlighting(): void
+ {
+ $pipeline = new Pipeline(
+ Stage::search(
+ Search::autocomplete(
+ query: 'ger',
+ path: 'title',
+ ),
+ highlight: object(
+ path: 'title',
+ ),
+ ),
+ Stage::limit(5),
+ Stage::project(
+ score: ['$meta' => 'searchScore'],
+ _id: 0,
+ title: 1,
+ highlights: ['$meta' => 'searchHighlights'],
+ ),
+ );
+
+ $this->assertSamePipeline(Pipelines::AutocompleteHighlighting, $pipeline);
+ }
+
+ public function testTokenOrderAny(): void
+ {
+ $pipeline = new Pipeline(
+ Stage::search(
+ Search::autocomplete(
+ query: 'men with',
+ path: 'title',
+ tokenOrder: 'any',
+ ),
+ ),
+ Stage::limit(4),
+ Stage::project(_id: 0, title: 1),
+ );
+
+ $this->assertSamePipeline(Pipelines::AutocompleteTokenOrderAny, $pipeline);
+ }
+
+ public function testTokenOrderSequential(): void
+ {
+ $pipeline = new Pipeline(
+ Stage::search(
+ Search::autocomplete(
+ query: 'men with',
+ path: 'title',
+ tokenOrder: 'sequential',
+ ),
+ ),
+ Stage::limit(4),
+ Stage::project(_id: 0, title: 1),
+ );
+
+ $this->assertSamePipeline(Pipelines::AutocompleteTokenOrderSequential, $pipeline);
+ }
+}
diff --git a/tests/Builder/Search/CompoundOperatorTest.php b/tests/Builder/Search/CompoundOperatorTest.php
new file mode 100644
index 000000000..8d5d69aed
--- /dev/null
+++ b/tests/Builder/Search/CompoundOperatorTest.php
@@ -0,0 +1,157 @@
+assertSamePipeline(Pipelines::CompoundFilter, $pipeline);
+ }
+
+ public function testMinimumShouldMatch(): void
+ {
+ $pipeline = new Pipeline(
+ Stage::search(
+ Search::compound(
+ must: [
+ Search::text(
+ path: 'description',
+ query: 'varieties',
+ ),
+ ],
+ should: [
+ Search::text(
+ path: 'description',
+ query: 'Fuji',
+ ),
+ Search::text(
+ path: 'description',
+ query: 'Golden Delicious',
+ ),
+ ],
+ minimumShouldMatch: 1,
+ ),
+ ),
+ );
+
+ $this->assertSamePipeline(Pipelines::CompoundMinimumShouldMatch, $pipeline);
+ }
+
+ public function testMustAndMustNot(): void
+ {
+ $pipeline = new Pipeline(
+ Stage::search(
+ Search::compound(
+ must: [
+ Search::text(
+ path: 'description',
+ query: 'varieties',
+ ),
+ ],
+ mustNot: [
+ Search::text(
+ path: 'description',
+ query: 'apples',
+ ),
+ ],
+ ),
+ ),
+ );
+
+ $this->assertSamePipeline(Pipelines::CompoundMustAndMustNot, $pipeline);
+ }
+
+ public function testMustAndShould(): void
+ {
+ $pipeline = new Pipeline(
+ Stage::search(
+ Search::compound(
+ must: [
+ Search::text(
+ path: 'description',
+ query: 'varieties',
+ ),
+ ],
+ should: [
+ Search::text(
+ path: 'description',
+ query: 'Fuji',
+ ),
+ ],
+ ),
+ ),
+ Stage::project(
+ score: ['$meta' => 'searchScore'],
+ ),
+ );
+
+ $this->assertSamePipeline(Pipelines::CompoundMustAndShould, $pipeline);
+ }
+
+ public function testNested(): void
+ {
+ $pipeline = new Pipeline(
+ Stage::search(
+ Search::compound(
+ should: [
+ Search::text(
+ path: 'type',
+ query: 'apple',
+ ),
+ Search::compound(
+ must: [
+ Search::text(
+ path: 'category',
+ query: 'organic',
+ ),
+ Search::equals(
+ path: 'in_stock',
+ value: true,
+ ),
+ ],
+ ),
+ ],
+ minimumShouldMatch: 1,
+ ),
+ ),
+ );
+
+ $this->assertSamePipeline(Pipelines::CompoundNested, $pipeline);
+ }
+}
diff --git a/tests/Builder/Search/EmbeddedDocumentOperatorTest.php b/tests/Builder/Search/EmbeddedDocumentOperatorTest.php
new file mode 100644
index 000000000..b83790c83
--- /dev/null
+++ b/tests/Builder/Search/EmbeddedDocumentOperatorTest.php
@@ -0,0 +1,167 @@
+ 1,
+ 'items.tags' => 1,
+ ],
+ _id: 0,
+ score: ['$meta' => 'searchScore'],
+ ),
+ );
+
+ $this->assertSamePipeline(Pipelines::EmbeddedDocumentBasic, $pipeline);
+ }
+
+ public function testFacet(): void
+ {
+ $pipeline = new Pipeline(
+ Stage::searchMeta(
+ Search::facet(
+ facets: object(
+ purchaseMethodFacet: object(
+ type: 'string',
+ path: 'purchaseMethod',
+ ),
+ ),
+ operator: Search::embeddedDocument(
+ path: 'items',
+ operator: Search::compound(
+ must: [
+ Search::text(
+ path: 'items.tags',
+ query: 'school',
+ ),
+ ],
+ should: [
+ Search::text(
+ path: 'items.name',
+ query: 'backpack',
+ ),
+ ],
+ ),
+ ),
+ ),
+ ),
+ );
+
+ $this->assertSamePipeline(Pipelines::EmbeddedDocumentFacet, $pipeline);
+ }
+
+ public function testQueryAndSort(): void
+ {
+ $pipeline = new Pipeline(
+ Stage::search(
+ Search::embeddedDocument(
+ path: 'items',
+ operator:
+ Search::text(
+ path: 'items.name',
+ query: 'laptop',
+ ),
+ ),
+ sort: ['items.tags' => Sort::Asc],
+ ),
+ Stage::limit(5),
+ Stage::project(
+ ...[
+ 'items.name' => 1,
+ 'items.tags' => 1,
+ ],
+ _id: 0,
+ score: ['$meta' => 'searchScore'],
+ ),
+ );
+
+ $this->assertSamePipeline(Pipelines::EmbeddedDocumentQueryAndSort, $pipeline);
+ }
+
+ public function testQueryForMatchingEmbeddedDocumentsOnly(): void
+ {
+ $pipeline = new Pipeline(
+ Stage::search(
+ Search::embeddedDocument(
+ path: 'items',
+ operator:
+ Search::compound(
+ must: [
+ Search::range(
+ path: 'items.quantity',
+ gt: 2,
+ ),
+ Search::exists(
+ path: 'items.price',
+ ),
+ Search::text(
+ path: 'items.tags',
+ query: 'school',
+ ),
+ ],
+ ),
+ ),
+ ),
+ Stage::limit(2),
+ Stage::project(
+ _id: 0,
+ storeLocation: 1,
+ items: Expression::filter(
+ input: Expression::arrayFieldPath('items'),
+ cond: Expression::and(
+ Expression::ifNull('$$this.price', 'false'),
+ Expression::gt(Expression::variable('this.quantity'), 2),
+ Expression::in('office', Expression::variable('this.tags')),
+ ),
+ ),
+ ),
+ );
+
+ $this->assertSamePipeline(Pipelines::EmbeddedDocumentQueryForMatchingEmbeddedDocumentsOnly, $pipeline);
+ }
+}
diff --git a/tests/Builder/Search/EqualsOperatorTest.php b/tests/Builder/Search/EqualsOperatorTest.php
new file mode 100644
index 000000000..6cd8ae9e1
--- /dev/null
+++ b/tests/Builder/Search/EqualsOperatorTest.php
@@ -0,0 +1,125 @@
+ 'searchScore'],
+ ),
+ );
+
+ $this->assertSamePipeline(Pipelines::EqualsBoolean, $pipeline);
+ }
+
+ public function testDate(): void
+ {
+ $pipeline = new Pipeline(
+ Stage::search(
+ Search::equals(
+ path: 'account_created',
+ value: new UTCDateTime(new DateTimeImmutable('2022-05-04T05:01:08')),
+ ),
+ ),
+ );
+
+ $this->assertSamePipeline(Pipelines::EqualsDate, $pipeline);
+ }
+
+ public function testNull(): void
+ {
+ $pipeline = new Pipeline(
+ Stage::search(
+ Search::equals(
+ path: 'job_title',
+ value: null,
+ ),
+ ),
+ );
+
+ $this->assertSamePipeline(Pipelines::EqualsNull, $pipeline);
+ }
+
+ public function testNumber(): void
+ {
+ $pipeline = new Pipeline(
+ Stage::search(
+ Search::equals(
+ path: 'employee_number',
+ value: 259,
+ ),
+ ),
+ );
+
+ $this->assertSamePipeline(Pipelines::EqualsNumber, $pipeline);
+ }
+
+ public function testObjectId(): void
+ {
+ $pipeline = new Pipeline(
+ Stage::search(
+ Search::equals(
+ path: 'teammates',
+ value: new ObjectId('5a9427648b0beebeb69589a1'),
+ ),
+ ),
+ );
+
+ $this->assertSamePipeline(Pipelines::EqualsObjectId, $pipeline);
+ }
+
+ public function testString(): void
+ {
+ $pipeline = new Pipeline(
+ Stage::search(
+ Search::equals(
+ path: 'name',
+ value: 'jim hall',
+ ),
+ ),
+ );
+
+ $this->assertSamePipeline(Pipelines::EqualsString, $pipeline);
+ }
+
+ public function testUUID(): void
+ {
+ $pipeline = new Pipeline(
+ Stage::search(
+ Search::equals(
+ path: 'uuid',
+ value: new Binary(hex2bin('fac32260b5114c698485a2be5b7dda9e'), Binary::TYPE_UUID),
+ ),
+ ),
+ );
+
+ $this->assertSamePipeline(Pipelines::EqualsUUID, $pipeline);
+ }
+}
diff --git a/tests/Builder/Search/ExistsOperatorTest.php b/tests/Builder/Search/ExistsOperatorTest.php
new file mode 100644
index 000000000..5666a1099
--- /dev/null
+++ b/tests/Builder/Search/ExistsOperatorTest.php
@@ -0,0 +1,67 @@
+assertSamePipeline(Pipelines::ExistsBasic, $pipeline);
+ }
+
+ public function testCompound(): void
+ {
+ $pipeline = new Pipeline(
+ Stage::search(
+ Search::compound(
+ must: [
+ Search::exists(
+ path: 'type',
+ ),
+ Search::text(
+ path: 'type',
+ query: 'apple',
+ ),
+ ],
+ should: Search::text(
+ path: 'description',
+ query: 'fuji',
+ ),
+ ),
+ ),
+ );
+
+ $this->assertSamePipeline(Pipelines::ExistsCompound, $pipeline);
+ }
+
+ public function testEmbedded(): void
+ {
+ $pipeline = new Pipeline(
+ Stage::search(
+ Search::exists(
+ path: 'quantities.lemons',
+ ),
+ ),
+ );
+
+ $this->assertSamePipeline(Pipelines::ExistsEmbedded, $pipeline);
+ }
+}
diff --git a/tests/Builder/Search/FacetOperatorTest.php b/tests/Builder/Search/FacetOperatorTest.php
new file mode 100644
index 000000000..3be124bec
--- /dev/null
+++ b/tests/Builder/Search/FacetOperatorTest.php
@@ -0,0 +1,61 @@
+assertSamePipeline(Pipelines::FacetFacet, $pipeline);
+ }
+}
diff --git a/tests/Builder/Search/GeoShapeOperatorTest.php b/tests/Builder/Search/GeoShapeOperatorTest.php
new file mode 100644
index 000000000..b5e748660
--- /dev/null
+++ b/tests/Builder/Search/GeoShapeOperatorTest.php
@@ -0,0 +1,204 @@
+ 'searchScore'],
+ ),
+ );
+
+ $this->assertSamePipeline(Pipelines::GeoShapeDisjoint, $pipeline);
+ }
+
+ public function testIntersect(): void
+ {
+ $pipeline = new Pipeline(
+ Stage::search(
+ Search::geoShape(
+ relation: 'intersects',
+ geometry: object(
+ type: 'MultiPolygon',
+ coordinates: [
+ [
+ [
+ [
+ 2.16942,
+ 41.40082,
+ ],
+ [
+ 2.17963,
+ 41.40087,
+ ],
+ [
+ 2.18146,
+ 41.39716,
+ ],
+ [
+ 2.15533,
+ 41.40686,
+ ],
+ [
+ 2.14596,
+ 41.38475,
+ ],
+ [
+ 2.17519,
+ 41.41035,
+ ],
+ [
+ 2.16942,
+ 41.40082,
+ ],
+ ],
+ ],
+ [
+ [
+ [
+ 2.16365,
+ 41.39416,
+ ],
+ [
+ 2.16963,
+ 41.39726,
+ ],
+ [
+ 2.15395,
+ 41.38005,
+ ],
+ [
+ 2.17935,
+ 41.43038,
+ ],
+ [
+ 2.16365,
+ 41.39416,
+ ],
+ ],
+ ],
+ ],
+ ),
+ path: 'address.location',
+ ),
+ ),
+ Stage::limit(3),
+ Stage::project(
+ _id: 0,
+ name: 1,
+ address: 1,
+ score: ['$meta' => 'searchScore'],
+ ),
+ );
+
+ $this->assertSamePipeline(Pipelines::GeoShapeIntersect, $pipeline);
+ }
+
+ public function testWithin(): void
+ {
+ $pipeline = new Pipeline(
+ Stage::search(
+ Search::geoShape(
+ relation: 'within',
+ geometry: object(
+ type: 'Polygon',
+ coordinates: [
+ [
+ [
+ -74.3994140625,
+ 40.5305017757,
+ ],
+ [
+ -74.7290039063,
+ 40.5805846641,
+ ],
+ [
+ -74.7729492188,
+ 40.9467136651,
+ ],
+ [
+ -74.0698242188,
+ 41.1290213475,
+ ],
+ [
+ -73.65234375,
+ 40.9964840144,
+ ],
+ [
+ -72.6416015625,
+ 40.9467136651,
+ ],
+ [
+ -72.3559570313,
+ 40.7971774152,
+ ],
+ [
+ -74.3994140625,
+ 40.5305017757,
+ ],
+ ],
+ ],
+ ),
+ path: 'address.location',
+ ),
+ ),
+ Stage::limit(3),
+ Stage::project(
+ _id: 0,
+ name: 1,
+ address: 1,
+ score: ['$meta' => 'searchScore'],
+ ),
+ );
+
+ $this->assertSamePipeline(Pipelines::GeoShapeWithin, $pipeline);
+ }
+}
diff --git a/tests/Builder/Search/GeoWithinOperatorTest.php b/tests/Builder/Search/GeoWithinOperatorTest.php
new file mode 100644
index 000000000..3a6a6b0af
--- /dev/null
+++ b/tests/Builder/Search/GeoWithinOperatorTest.php
@@ -0,0 +1,124 @@
+assertSamePipeline(Pipelines::GeoWithinBox, $pipeline);
+ }
+
+ public function testCircle(): void
+ {
+ $pipeline = new Pipeline(
+ Stage::search(
+ Search::geoWithin(
+ path: 'address.location',
+ circle: object(
+ center: object(
+ type: 'Point',
+ coordinates: [
+ -73.54,
+ 45.54,
+ ],
+ ),
+ radius: 1600,
+ ),
+ ),
+ ),
+ Stage::limit(3),
+ Stage::project(
+ _id: 0,
+ name: 1,
+ address: 1,
+ ),
+ );
+
+ $this->assertSamePipeline(Pipelines::GeoWithinCircle, $pipeline);
+ }
+
+ public function testGeometry(): void
+ {
+ $pipeline = new Pipeline(
+ Stage::search(
+ Search::geoWithin(
+ path: 'address.location',
+ geometry: object(
+ type: 'Polygon',
+ coordinates: [
+ [
+ [
+ -161.323242,
+ 22.512557,
+ ],
+ [
+ -152.446289,
+ 22.065278,
+ ],
+ [
+ -156.09375,
+ 17.811456,
+ ],
+ [
+ -161.323242,
+ 22.512557,
+ ],
+ ],
+ ],
+ ),
+ ),
+ ),
+ Stage::limit(3),
+ Stage::project(
+ _id: 0,
+ name: 1,
+ address: 1,
+ ),
+ );
+
+ $this->assertSamePipeline(Pipelines::GeoWithinGeometry, $pipeline);
+ }
+}
diff --git a/tests/Builder/Search/InOperatorTest.php b/tests/Builder/Search/InOperatorTest.php
new file mode 100644
index 000000000..e6d1af57c
--- /dev/null
+++ b/tests/Builder/Search/InOperatorTest.php
@@ -0,0 +1,101 @@
+assertSamePipeline(Pipelines::InArrayValueFieldMatch, $pipeline);
+ }
+
+ public function testCompoundQueryMatch(): void
+ {
+ $pipeline = new Pipeline(
+ Stage::search(
+ Search::compound(
+ must: [
+ Search::in(
+ path: 'name',
+ value: [
+ 'james sanchez',
+ 'jennifer lawrence',
+ ],
+ ),
+ ],
+ should: [
+ Search::in(
+ path: '_id',
+ value: [
+ new ObjectId('5ca4bbcea2dd94ee58162a72'),
+ new ObjectId('5ca4bbcea2dd94ee58162a91'),
+ ],
+ ),
+ ],
+ ),
+ ),
+ Stage::limit(5),
+ Stage::project(
+ _id: 1,
+ name: 1,
+ score: ['$meta' => 'searchScore'],
+ ),
+ );
+
+ $this->assertSamePipeline(Pipelines::InCompoundQueryMatch, $pipeline);
+ }
+
+ public function testSingleValueFieldMatch(): void
+ {
+ $pipeline = new Pipeline(
+ Stage::search(
+ Search::in(
+ path: 'birthdate',
+ value: [
+ new UTCDateTime(new DateTimeImmutable('1977-03-02T02:20:31')),
+ new UTCDateTime(new DateTimeImmutable('1977-03-01T00:00:00')),
+ new UTCDateTime(new DateTimeImmutable('1977-05-06T21:57:35')),
+ ],
+ ),
+ ),
+ Stage::project(
+ _id: 0,
+ name: 1,
+ birthdate: 1,
+ ),
+ );
+
+ $this->assertSamePipeline(Pipelines::InSingleValueFieldMatch, $pipeline);
+ }
+}
diff --git a/tests/Builder/Search/MoreLikeThisOperatorTest.php b/tests/Builder/Search/MoreLikeThisOperatorTest.php
new file mode 100644
index 000000000..a83c03559
--- /dev/null
+++ b/tests/Builder/Search/MoreLikeThisOperatorTest.php
@@ -0,0 +1,115 @@
+assertSamePipeline(Pipelines::MoreLikeThisInputDocumentExcludedInResults, $pipeline);
+ }
+
+ public function testMultipleAnalyzers(): void
+ {
+ $pipeline = new Pipeline(
+ Stage::search(
+ Search::compound(
+ mustNot: [
+ Search::equals(
+ path: '_id',
+ value: new ObjectId('573a1394f29313caabcde9ef'),
+ ),
+ ],
+ should: [
+ Search::moreLikeThis(
+ like: object(
+ _id: new ObjectId('573a1396f29313caabce4a9a'),
+ genres: [
+ 'Crime',
+ 'Drama',
+ ],
+ title: 'The Godfather',
+ ),
+ ),
+ ],
+ ),
+ ),
+ Stage::limit(10),
+ Stage::project(
+ title: 1,
+ genres: 1,
+ _id: 1,
+ ),
+ );
+
+ $this->assertSamePipeline(Pipelines::MoreLikeThisMultipleAnalyzers, $pipeline);
+ }
+
+ public function testSingleDocumentWithMultipleFields(): void
+ {
+ $pipeline = new Pipeline(
+ Stage::search(
+ Search::moreLikeThis(
+ like: object(
+ title: 'The Godfather',
+ genres: 'action',
+ ),
+ ),
+ ),
+ Stage::limit(5),
+ Stage::project(
+ _id: 0,
+ title: 1,
+ released: 1,
+ genres: 1,
+ ),
+ );
+
+ $this->assertSamePipeline(Pipelines::MoreLikeThisSingleDocumentWithMultipleFields, $pipeline);
+ }
+}
diff --git a/tests/Builder/Search/NearOperatorTest.php b/tests/Builder/Search/NearOperatorTest.php
new file mode 100644
index 000000000..45a48e0d5
--- /dev/null
+++ b/tests/Builder/Search/NearOperatorTest.php
@@ -0,0 +1,128 @@
+ 'searchScore'],
+ ),
+ );
+
+ $this->assertSamePipeline(Pipelines::NearCompound, $pipeline);
+ }
+
+ public function testDate(): void
+ {
+ $pipeline = new Pipeline(
+ Stage::search(
+ Search::near(
+ path: 'released',
+ origin: new UTCDateTime(new DateTimeImmutable('1915-09-13T00:00:00.000+00:00')),
+ pivot: 7776000000,
+ ),
+ index: 'releaseddate',
+ ),
+ Stage::limit(3),
+ Stage::project(
+ _id: 0,
+ title: 1,
+ released: 1,
+ score: ['$meta' => 'searchScore'],
+ ),
+ );
+
+ $this->assertSamePipeline(Pipelines::NearDate, $pipeline);
+ }
+
+ public function testGeoJSONPoint(): void
+ {
+ $pipeline = new Pipeline(
+ Stage::search(
+ Search::near(
+ path: 'address.location',
+ origin: object(
+ type: 'Point',
+ coordinates: [
+ -8.61308,
+ 41.1413,
+ ],
+ ),
+ pivot: 1000,
+ ),
+ ),
+ Stage::limit(3),
+ Stage::project(
+ _id: 0,
+ name: 1,
+ address: 1,
+ score: ['$meta' => 'searchScore'],
+ ),
+ );
+
+ $this->assertSamePipeline(Pipelines::NearGeoJSONPoint, $pipeline);
+ }
+
+ public function testNumber(): void
+ {
+ $pipeline = new Pipeline(
+ Stage::search(
+ Search::near(
+ path: 'runtime',
+ origin: 279,
+ pivot: 2,
+ ),
+ index: 'runtimes',
+ ),
+ Stage::limit(7),
+ Stage::project(
+ _id: 0,
+ title: 1,
+ runtime: 1,
+ score: ['$meta' => 'searchScore'],
+ ),
+ );
+
+ $this->assertSamePipeline(Pipelines::NearNumber, $pipeline);
+ }
+}
diff --git a/tests/Builder/Search/PhraseOperatorTest.php b/tests/Builder/Search/PhraseOperatorTest.php
new file mode 100644
index 000000000..a045e9c12
--- /dev/null
+++ b/tests/Builder/Search/PhraseOperatorTest.php
@@ -0,0 +1,102 @@
+ 'searchScore'],
+ ),
+ );
+
+ $this->assertSamePipeline(Pipelines::PhraseMultiplePhrase, $pipeline);
+ }
+
+ public function testPhraseSlop(): void
+ {
+ $pipeline = new Pipeline(
+ Stage::search(
+ Search::phrase(
+ path: 'title',
+ query: 'men women',
+ slop: 5,
+ ),
+ ),
+ Stage::project(
+ _id: 0,
+ title: 1,
+ score: ['$meta' => 'searchScore'],
+ ),
+ );
+
+ $this->assertSamePipeline(Pipelines::PhrasePhraseSlop, $pipeline);
+ }
+
+ public function testPhraseSynonyms(): void
+ {
+ $pipeline = new Pipeline(
+ Stage::search(
+ Search::phrase(
+ path: 'plot',
+ query: 'automobile race',
+ slop: 5,
+ synonyms: 'my_synonyms',
+ ),
+ ),
+ Stage::limit(5),
+ Stage::project(
+ _id: 0,
+ plot: 1,
+ title: 1,
+ score: ['$meta' => 'searchScore'],
+ ),
+ );
+
+ $this->assertSamePipeline(Pipelines::PhrasePhraseSynonyms, $pipeline);
+ }
+
+ public function testSinglePhrase(): void
+ {
+ $pipeline = new Pipeline(
+ Stage::search(
+ Search::phrase(
+ path: 'title',
+ query: 'new york',
+ ),
+ ),
+ Stage::limit(10),
+ Stage::project(
+ _id: 0,
+ title: 1,
+ score: ['$meta' => 'searchScore'],
+ ),
+ );
+
+ $this->assertSamePipeline(Pipelines::PhraseSinglePhrase, $pipeline);
+ }
+}
diff --git a/tests/Builder/Search/Pipelines.php b/tests/Builder/Search/Pipelines.php
new file mode 100644
index 000000000..fa94f8c9a
--- /dev/null
+++ b/tests/Builder/Search/Pipelines.php
@@ -0,0 +1,2814 @@
+assertSamePipeline(Pipelines::QueryStringBooleanOperatorQueries, $pipeline);
+ }
+}
diff --git a/tests/Builder/Search/RangeOperatorTest.php b/tests/Builder/Search/RangeOperatorTest.php
new file mode 100644
index 000000000..9606014ed
--- /dev/null
+++ b/tests/Builder/Search/RangeOperatorTest.php
@@ -0,0 +1,122 @@
+assertSamePipeline(Pipelines::RangeDate, $pipeline);
+ }
+
+ public function testNumberGteLte(): void
+ {
+ $pipeline = new Pipeline(
+ Stage::search(
+ Search::range(
+ path: 'runtime',
+ gte: 2,
+ lte: 3,
+ ),
+ ),
+ Stage::limit(5),
+ Stage::project(
+ _id: 0,
+ title: 1,
+ runtime: 1,
+ ),
+ );
+
+ $this->assertSamePipeline(Pipelines::RangeNumberGteLte, $pipeline);
+ }
+
+ public function testNumberLte(): void
+ {
+ $pipeline = new Pipeline(
+ Stage::search(
+ Search::range(
+ path: 'runtime',
+ lte: 2,
+ ),
+ ),
+ Stage::limit(5),
+ Stage::project(
+ _id: 0,
+ title: 1,
+ runtime: 1,
+ score: ['$meta' => 'searchScore'],
+ ),
+ );
+
+ $this->assertSamePipeline(Pipelines::RangeNumberLte, $pipeline);
+ }
+
+ public function testObjectId(): void
+ {
+ $pipeline = new Pipeline(
+ Stage::search(
+ Search::range(
+ path: '_id',
+ gte: new ObjectId('573a1396f29313caabce4a9a'),
+ lte: new ObjectId('573a1396f29313caabce4ae7'),
+ ),
+ ),
+ Stage::project(
+ _id: 1,
+ title: 1,
+ released: 1,
+ ),
+ );
+
+ $this->assertSamePipeline(Pipelines::RangeObjectId, $pipeline);
+ }
+
+ public function testString(): void
+ {
+ $pipeline = new Pipeline(
+ Stage::search(
+ Search::range(
+ path: 'title',
+ gt: 'city',
+ lt: 'country',
+ ),
+ ),
+ Stage::limit(5),
+ Stage::project(
+ _id: 0,
+ title: 1,
+ ),
+ );
+
+ $this->assertSamePipeline(Pipelines::RangeString, $pipeline);
+ }
+}
diff --git a/tests/Builder/Search/RegexOperatorTest.php b/tests/Builder/Search/RegexOperatorTest.php
new file mode 100644
index 000000000..b95f518a0
--- /dev/null
+++ b/tests/Builder/Search/RegexOperatorTest.php
@@ -0,0 +1,34 @@
+assertSamePipeline(Pipelines::RegexRegex, $pipeline);
+ }
+}
diff --git a/tests/Builder/Search/TextOperatorTest.php b/tests/Builder/Search/TextOperatorTest.php
new file mode 100644
index 000000000..12709740e
--- /dev/null
+++ b/tests/Builder/Search/TextOperatorTest.php
@@ -0,0 +1,194 @@
+ 'searchScore'],
+ ),
+ );
+
+ $this->assertSamePipeline(Pipelines::TextBasic, $pipeline);
+ }
+
+ public function testFuzzyDefault(): void
+ {
+ $pipeline = new Pipeline(
+ Stage::search(
+ Search::text(
+ path: 'title',
+ query: 'naw yark',
+ fuzzy: object(),
+ ),
+ ),
+ Stage::limit(10),
+ Stage::project(
+ _id: 0,
+ title: 1,
+ score: ['$meta' => 'searchScore'],
+ ),
+ );
+
+ $this->assertSamePipeline(Pipelines::TextFuzzyDefault, $pipeline);
+ }
+
+ public function testFuzzyMaxExpansions(): void
+ {
+ $pipeline = new Pipeline(
+ Stage::search(
+ Search::text(
+ path: 'title',
+ query: 'naw yark',
+ fuzzy: object(
+ maxEdits: 1,
+ maxExpansions: 100,
+ ),
+ ),
+ ),
+ Stage::limit(10),
+ Stage::project(
+ _id: 0,
+ title: 1,
+ score: ['$meta' => 'searchScore'],
+ ),
+ );
+
+ $this->assertSamePipeline(Pipelines::TextFuzzyMaxExpansions, $pipeline);
+ }
+
+ public function testFuzzyPrefixLength(): void
+ {
+ $pipeline = new Pipeline(
+ Stage::search(
+ Search::text(
+ path: 'title',
+ query: 'naw yark',
+ fuzzy: object(
+ maxEdits: 1,
+ prefixLength: 2,
+ ),
+ ),
+ ),
+ Stage::limit(8),
+ Stage::project(
+ _id: 1,
+ title: 1,
+ score: ['$meta' => 'searchScore'],
+ ),
+ );
+
+ $this->assertSamePipeline(Pipelines::TextFuzzyPrefixLength, $pipeline);
+ }
+
+ public function testMatchAllUsingSynonyms(): void
+ {
+ $pipeline = new Pipeline(
+ Stage::search(
+ Search::text(
+ path: 'plot',
+ query: 'automobile race',
+ matchCriteria: 'all',
+ synonyms: 'my_synonyms',
+ ),
+ ),
+ Stage::limit(20),
+ Stage::project(
+ _id: 0,
+ plot: 1,
+ title: 1,
+ score: ['$meta' => 'searchScore'],
+ ),
+ );
+
+ $this->assertSamePipeline(Pipelines::TextMatchAllUsingSynonyms, $pipeline);
+ }
+
+ public function testMatchAnyUsingEquivalentMapping(): void
+ {
+ $pipeline = new Pipeline(
+ Stage::search(
+ Search::text(
+ path: 'plot',
+ query: 'attire',
+ synonyms: 'my_synonyms',
+ matchCriteria: 'any',
+ ),
+ ),
+ Stage::limit(5),
+ Stage::project(
+ _id: 0,
+ plot: 1,
+ title: 1,
+ score: ['$meta' => 'searchScore'],
+ ),
+ );
+
+ $this->assertSamePipeline(Pipelines::TextMatchAnyUsingEquivalentMapping, $pipeline);
+ }
+
+ public function testMatchAnyUsingExplicitMapping(): void
+ {
+ $pipeline = new Pipeline(
+ Stage::search(
+ Search::text(
+ path: 'plot',
+ query: 'boat race',
+ synonyms: 'my_synonyms',
+ matchCriteria: 'any',
+ ),
+ ),
+ Stage::limit(10),
+ Stage::project(
+ _id: 0,
+ plot: 1,
+ title: 1,
+ score: ['$meta' => 'searchScore'],
+ ),
+ );
+
+ $this->assertSamePipeline(Pipelines::TextMatchAnyUsingExplicitMapping, $pipeline);
+ }
+
+ public function testWildcardPath(): void
+ {
+ $pipeline = new Pipeline(
+ Stage::search(
+ Search::text(
+ path: ['wildcard' => '*'],
+ query: 'surfer',
+ ),
+ ),
+ Stage::project(
+ _id: 0,
+ title: 1,
+ score: ['$meta' => 'searchScore'],
+ ),
+ );
+
+ $this->assertSamePipeline(Pipelines::TextWildcardPath, $pipeline);
+ }
+}
diff --git a/tests/Builder/Search/WildcardOperatorTest.php b/tests/Builder/Search/WildcardOperatorTest.php
new file mode 100644
index 000000000..18103b75d
--- /dev/null
+++ b/tests/Builder/Search/WildcardOperatorTest.php
@@ -0,0 +1,54 @@
+assertSamePipeline(Pipelines::WildcardEscapeCharacterExample, $pipeline);
+ }
+
+ public function testWildcardPath(): void
+ {
+ $pipeline = new Pipeline(
+ Stage::search(
+ Search::wildcard(
+ query: 'Wom?n *',
+ path: ['wildcard' => '*'],
+ ),
+ ),
+ Stage::limit(5),
+ Stage::project(
+ _id: 0,
+ title: 1,
+ ),
+ );
+
+ $this->assertSamePipeline(Pipelines::WildcardWildcardPath, $pipeline);
+ }
+}
diff --git a/tests/Builder/Stage/Pipelines.php b/tests/Builder/Stage/Pipelines.php
index 8b76342ba..850013c3e 100644
--- a/tests/Builder/Stage/Pipelines.php
+++ b/tests/Builder/Stage/Pipelines.php
@@ -2638,6 +2638,197 @@ enum Pipelines: string
]
JSON;
+ /**
+ * Year Facet
+ *
+ * @see https://www.mongodb.com/docs/atlas/atlas-search/facet/#example-1
+ */
+ case SearchMetaYearFacet = <<<'JSON'
+ [
+ {
+ "$searchMeta": {
+ "facet": {
+ "operator": {
+ "range": {
+ "path": "year",
+ "gte": {
+ "$numberInt": "1980"
+ },
+ "lte": {
+ "$numberInt": "2000"
+ }
+ }
+ },
+ "facets": {
+ "yearFacet": {
+ "type": "number",
+ "path": "year",
+ "boundaries": [
+ {
+ "$numberInt": "1980"
+ },
+ {
+ "$numberInt": "1990"
+ },
+ {
+ "$numberInt": "2000"
+ }
+ ],
+ "default": "other"
+ }
+ }
+ }
+ }
+ }
+ ]
+ JSON;
+
+ /**
+ * Date Facet
+ *
+ * @see https://www.mongodb.com/docs/atlas/atlas-search/facet/#example-2
+ */
+ case SearchMetaDateFacet = <<<'JSON'
+ [
+ {
+ "$searchMeta": {
+ "facet": {
+ "operator": {
+ "range": {
+ "path": "released",
+ "gte": {
+ "$date": {
+ "$numberLong": "946684800000"
+ }
+ },
+ "lte": {
+ "$date": {
+ "$numberLong": "1422662400000"
+ }
+ }
+ }
+ },
+ "facets": {
+ "yearFacet": {
+ "type": "date",
+ "path": "released",
+ "boundaries": [
+ {
+ "$date": {
+ "$numberLong": "946684800000"
+ }
+ },
+ {
+ "$date": {
+ "$numberLong": "1104537600000"
+ }
+ },
+ {
+ "$date": {
+ "$numberLong": "1262304000000"
+ }
+ },
+ {
+ "$date": {
+ "$numberLong": "1420070400000"
+ }
+ }
+ ],
+ "default": "other"
+ }
+ }
+ }
+ }
+ }
+ ]
+ JSON;
+
+ /**
+ * Metadata Results
+ *
+ * @see https://www.mongodb.com/docs/atlas/atlas-search/facet/#examples
+ */
+ case SearchMetaMetadataResults = <<<'JSON'
+ [
+ {
+ "$searchMeta": {
+ "facet": {
+ "operator": {
+ "range": {
+ "path": "released",
+ "gte": {
+ "$date": {
+ "$numberLong": "946684800000"
+ }
+ },
+ "lte": {
+ "$date": {
+ "$numberLong": "1422662400000"
+ }
+ }
+ }
+ },
+ "facets": {
+ "directorsFacet": {
+ "type": "string",
+ "path": "directors",
+ "numBuckets": {
+ "$numberInt": "7"
+ }
+ },
+ "yearFacet": {
+ "type": "number",
+ "path": "year",
+ "boundaries": [
+ {
+ "$numberInt": "2000"
+ },
+ {
+ "$numberInt": "2005"
+ },
+ {
+ "$numberInt": "2010"
+ },
+ {
+ "$numberInt": "2015"
+ }
+ ]
+ }
+ }
+ }
+ }
+ }
+ ]
+ JSON;
+
+ /**
+ * Autocomplete Bucket Results through Facet Queries
+ *
+ * @see https://www.mongodb.com/docs/atlas/atlas-search/autocomplete/#bucket-results-through-facet-queries
+ */
+ case SearchMetaAutocompleteBucketResultsThroughFacetQueries = <<<'JSON'
+ [
+ {
+ "$searchMeta": {
+ "facet": {
+ "operator": {
+ "autocomplete": {
+ "path": "title",
+ "query": "Gravity"
+ }
+ },
+ "facets": {
+ "titleFacet": {
+ "type": "string",
+ "path": "title"
+ }
+ }
+ }
+ }
+ }
+ ]
+ JSON;
+
/**
* Using Two $set Stages
*
@@ -3362,4 +3553,163 @@ enum Pipelines: string
}
]
JSON;
+
+ /**
+ * ANN Basic
+ *
+ * @see https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-stage/#ann-examples
+ */
+ case VectorSearchANNBasic = <<<'JSON'
+ [
+ {
+ "$vectorSearch": {
+ "index": "vector_index",
+ "path": "plot_embedding",
+ "queryVector": [
+ {
+ "$numberDouble": "-0.0016261311999999999121"
+ },
+ {
+ "$numberDouble": "-0.028070756999999998266"
+ },
+ {
+ "$numberDouble": "-0.011342932000000000015"
+ }
+ ],
+ "numCandidates": {
+ "$numberInt": "150"
+ },
+ "limit": {
+ "$numberInt": "10"
+ }
+ }
+ },
+ {
+ "$project": {
+ "_id": {
+ "$numberInt": "0"
+ },
+ "plot": {
+ "$numberInt": "1"
+ },
+ "title": {
+ "$numberInt": "1"
+ },
+ "score": {
+ "$meta": "vectorSearchScore"
+ }
+ }
+ }
+ ]
+ JSON;
+
+ /**
+ * ANN Filter
+ *
+ * @see https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-stage/#ann-examples
+ */
+ case VectorSearchANNFilter = <<<'JSON'
+ [
+ {
+ "$vectorSearch": {
+ "index": "vector_index",
+ "path": "plot_embedding",
+ "filter": {
+ "$and": [
+ {
+ "year": {
+ "$lt": {
+ "$numberInt": "1975"
+ }
+ }
+ }
+ ]
+ },
+ "queryVector": [
+ {
+ "$numberDouble": "0.024210530000000000939"
+ },
+ {
+ "$numberDouble": "-0.022372592000000000173"
+ },
+ {
+ "$numberDouble": "-0.0062311370000000003075"
+ }
+ ],
+ "numCandidates": {
+ "$numberInt": "150"
+ },
+ "limit": {
+ "$numberInt": "10"
+ }
+ }
+ },
+ {
+ "$project": {
+ "_id": {
+ "$numberInt": "0"
+ },
+ "title": {
+ "$numberInt": "1"
+ },
+ "plot": {
+ "$numberInt": "1"
+ },
+ "year": {
+ "$numberInt": "1"
+ },
+ "score": {
+ "$meta": "vectorSearchScore"
+ }
+ }
+ }
+ ]
+ JSON;
+
+ /**
+ * ENN
+ *
+ * @see https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-stage/#enn-examples
+ */
+ case VectorSearchENN = <<<'JSON'
+ [
+ {
+ "$vectorSearch": {
+ "index": "vector_index",
+ "path": "plot_embedding",
+ "queryVector": [
+ {
+ "$numberDouble": "-0.0069540970000000002296"
+ },
+ {
+ "$numberDouble": "-0.009932498999999999148"
+ },
+ {
+ "$numberDouble": "-0.0013114739999999999731"
+ }
+ ],
+ "exact": true,
+ "limit": {
+ "$numberInt": "10"
+ }
+ }
+ },
+ {
+ "$project": {
+ "_id": {
+ "$numberInt": "0"
+ },
+ "plot": {
+ "$numberInt": "1"
+ },
+ "title": {
+ "$numberInt": "1"
+ },
+ "score": {
+ "$meta": "vectorSearchScore"
+ }
+ }
+ }
+ ]
+ JSON;
}
diff --git a/tests/Builder/Stage/SearchMetaStageTest.php b/tests/Builder/Stage/SearchMetaStageTest.php
index 3b8283424..6ded31935 100644
--- a/tests/Builder/Stage/SearchMetaStageTest.php
+++ b/tests/Builder/Stage/SearchMetaStageTest.php
@@ -4,7 +4,10 @@
namespace MongoDB\Tests\Builder\Stage;
+use DateTimeImmutable;
+use MongoDB\BSON\UTCDateTime;
use MongoDB\Builder\Pipeline;
+use MongoDB\Builder\Search;
use MongoDB\Builder\Stage;
use MongoDB\Tests\Builder\PipelineTestCase;
@@ -15,19 +18,134 @@
*/
class SearchMetaStageTest extends PipelineTestCase
{
+ public function testAutocompleteBucketResultsThroughFacetQueries(): void
+ {
+ $pipeline = new Pipeline(
+ Stage::searchMeta(
+ Search::facet(
+ facets: object(
+ titleFacet: object(
+ type: 'string',
+ path: 'title',
+ ),
+ ),
+ operator: Search::autocomplete(
+ path: 'title',
+ query: 'Gravity',
+ ),
+ ),
+ ),
+ );
+
+ $this->assertSamePipeline(Pipelines::SearchMetaAutocompleteBucketResultsThroughFacetQueries, $pipeline);
+ }
+
+ public function testDateFacet(): void
+ {
+ $pipeline = new Pipeline(
+ Stage::searchMeta(
+ Search::facet(
+ operator: Search::range(
+ path: 'released',
+ gte: new UTCDateTime(new DateTimeImmutable('2000-01-01')),
+ lte: new UTCDateTime(new DateTimeImmutable('2015-01-31')),
+ ),
+ facets: object(
+ yearFacet: object(
+ type: 'date',
+ path: 'released',
+ boundaries: [
+ new UTCDateTime(new DateTimeImmutable('2000-01-01')),
+ new UTCDateTime(new DateTimeImmutable('2005-01-01')),
+ new UTCDateTime(new DateTimeImmutable('2010-01-01')),
+ new UTCDateTime(new DateTimeImmutable('2015-01-01')),
+ ],
+ default: 'other',
+ ),
+ ),
+ ),
+ ),
+ );
+
+ $this->assertSamePipeline(Pipelines::SearchMetaDateFacet, $pipeline);
+ }
+
public function testExample(): void
{
$pipeline = new Pipeline(
- Stage::searchMeta(object(
- range: object(
+ Stage::searchMeta(
+ Search::range(
path: 'year',
gte: 1998,
lt: 1999,
),
count: object(type: 'total'),
- )),
+ ),
);
$this->assertSamePipeline(Pipelines::SearchMetaExample, $pipeline);
}
+
+ public function testMetadataResults(): void
+ {
+ $pipeline = new Pipeline(
+ Stage::searchMeta(
+ Search::facet(
+ operator: Search::range(
+ path: 'released',
+ gte: new UTCDateTime(new DateTimeImmutable('2000-01-01')),
+ lte: new UTCDateTime(new DateTimeImmutable('2015-01-31')),
+ ),
+ facets: object(
+ directorsFacet: object(
+ type: 'string',
+ path: 'directors',
+ numBuckets: 7,
+ ),
+ yearFacet: object(
+ type: 'number',
+ path: 'year',
+ boundaries: [
+ 2000,
+ 2005,
+ 2010,
+ 2015,
+ ],
+ ),
+ ),
+ ),
+ ),
+ );
+
+ $this->assertSamePipeline(Pipelines::SearchMetaMetadataResults, $pipeline);
+ }
+
+ public function testYearFacet(): void
+ {
+ $pipeline = new Pipeline(
+ Stage::searchMeta(
+ Search::facet(
+ operator: Search::range(
+ path: 'year',
+ gte: 1980,
+ lte: 2000,
+ ),
+ facets: object(
+ yearFacet: object(
+ type: 'number',
+ path: 'year',
+ boundaries: [
+ 1980,
+ 1990,
+ 2000,
+ ],
+ default: 'other',
+ ),
+ ),
+ ),
+ ),
+ );
+
+ $this->assertSamePipeline(Pipelines::SearchMetaYearFacet, $pipeline);
+ }
}
diff --git a/tests/Builder/Stage/SearchStageTest.php b/tests/Builder/Stage/SearchStageTest.php
index 656b9b9ee..faae2ab11 100644
--- a/tests/Builder/Stage/SearchStageTest.php
+++ b/tests/Builder/Stage/SearchStageTest.php
@@ -8,11 +8,10 @@
use MongoDB\BSON\UTCDateTime;
use MongoDB\Builder\Expression;
use MongoDB\Builder\Pipeline;
+use MongoDB\Builder\Search;
use MongoDB\Builder\Stage;
use MongoDB\Tests\Builder\PipelineTestCase;
-use function MongoDB\object;
-
/**
* Test $search stage
*/
@@ -21,13 +20,13 @@ class SearchStageTest extends PipelineTestCase
public function testExample(): void
{
$pipeline = new Pipeline(
- Stage::search(object(
- near: object(
+ Stage::search(
+ Search::near(
path: 'released',
origin: new UTCDateTime(new DateTime('2011-09-01T00:00:00.000+00:00')),
pivot: 7776000000,
),
- )),
+ ),
Stage::project(_id: 0, title: 1, released: 1),
Stage::limit(5),
Stage::facet(
diff --git a/tests/Builder/Stage/VectorSearchStageTest.php b/tests/Builder/Stage/VectorSearchStageTest.php
new file mode 100644
index 000000000..f6259510a
--- /dev/null
+++ b/tests/Builder/Stage/VectorSearchStageTest.php
@@ -0,0 +1,85 @@
+ 'vectorSearchScore'],
+ ),
+ );
+
+ $this->assertSamePipeline(Pipelines::VectorSearchANNBasic, $pipeline);
+ }
+
+ public function testANNFilter(): void
+ {
+ $pipeline = new Pipeline(
+ Stage::vectorSearch(
+ index: 'vector_index',
+ limit: 10,
+ path: 'plot_embedding',
+ queryVector: [0.02421053, -0.022372592, -0.006231137],
+ filter: Query::and(
+ Query::query(
+ year: Query::lt(1975),
+ ),
+ ),
+ numCandidates: 150,
+ ),
+ Stage::project(
+ _id: 0,
+ title: 1,
+ plot: 1,
+ year: 1,
+ score: ['$meta' => 'vectorSearchScore'],
+ ),
+ );
+
+ $this->assertSamePipeline(Pipelines::VectorSearchANNFilter, $pipeline);
+ }
+
+ public function testENN(): void
+ {
+ $pipeline = new Pipeline(
+ Stage::vectorSearch(
+ index: 'vector_index',
+ limit: 10,
+ path: 'plot_embedding',
+ queryVector: [-0.006954097, -0.009932499, -0.001311474],
+ exact: true,
+ ),
+ Stage::project(
+ _id: 0,
+ title: 1,
+ plot: 1,
+ score: ['$meta' => 'vectorSearchScore'],
+ ),
+ );
+
+ $this->assertSamePipeline(Pipelines::VectorSearchENN, $pipeline);
+ }
+}