Skip to content

Commit 99b1889

Browse files
Merge v1.x into v2.x (#1550)
2 parents 213648f + c386f6d commit 99b1889

File tree

375 files changed

+10727
-1956
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

375 files changed

+10727
-1956
lines changed

.gitattributes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ rector.php export-ignore
2222
/src/Builder/Accumulator/*.php linguist-generated=true
2323
/src/Builder/Expression/*.php linguist-generated=true
2424
/src/Builder/Query/*.php linguist-generated=true
25-
/src/Builder/Projection/*.php linguist-generated=true
25+
/src/Builder/Search/*.php linguist-generated=true
2626
/src/Builder/Stage/*.php linguist-generated=true
2727
/tests/Builder/*/Pipelines.php linguist-generated=true

generator/README.md

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,40 @@ Updating the generated code can be done only by modifying the code generator, or
1010
To run the generator, you need to have PHP 8.1+ installed and Composer.
1111

1212
1. Move to the `generator` directory: `cd generator`
13-
1. Install dependencies: `composer install`
14-
1. Run the generator: `./generate`
13+
2. Install dependencies: `composer install`
14+
3. Run the generator: `./generate`
1515

1616
## Configuration
1717

1818
The `generator/config/*.yaml` files contains the list of operators and stages that are supported by the library.
1919

20+
### Arguments
21+
22+
| Field | Type | Description |
23+
|---------------|---------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
24+
| `name` | `string` | The name of the argument. If it starts with `$`, the dollar is trimmed from the class property name |
25+
| `type` | list of `string` | The list of accepted types |
26+
| `description` | `string` | The description of the argument from MongoDB's documentation |
27+
| `optional` | `boolean` | Whether the argument is optional or not |
28+
| `valueMin` | `number` | The minimum value for a numeric argument |
29+
| `valueMax` | `number` | The maximum value for a numeric argument |
30+
| `variadic` | `string` | If sent, the argument is variadic. Defines the format `array` for a list or `object` for a map |
31+
| `variadicMin` | `integer` | The minimum number of arguments for a variadic parameter |
32+
| `default` | `scalar` or `array` | The default value for the argument |
33+
| `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 |
34+
2035
### Test pipelines
2136

22-
Each operator can contain a `tests` section with a list if pipelines. To represent specific BSON objects,
23-
it is necessary to use Yaml tags:
37+
Each operator can contain a `tests` section with a list if pipelines. To represent specific BSON objects, it is necessary to use Yaml tags:
2438

2539
| BSON Type | Example |
2640
|-------------|--------------------------------------------------------|
2741
| Regex | `!bson_regex '^abc'` <br/> `!bson_regex ['^abc', 'i']` |
2842
| Int64 | `!bson_int64 '123456789'` |
2943
| Decimal128 | `!bson_decimal128 '0.9'` |
3044
| UTCDateTime | `!bson_utcdatetime 0` |
45+
| ObjectId | `!bson_ObjectId '5a9427648b0beebeb69589a1` |
3146
| Binary | `!bson_binary 'IA=='` |
47+
| Binary UUID | `!bson_uuid 'fac32260-b511-4c69-8485-a2be5b7dda9e'` |
3248

33-
To add new test cases to operators, you can get inspiration from the official MongoDB documentation and use
34-
the `generator/js2yaml.html` web page to manually convert a pipeline array from JS to Yaml.
49+
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.

generator/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"repositories": [
55
{
66
"type": "path",
7-
"url": "../",
7+
"url": "..",
88
"symlink": true
99
}
1010
],

generator/config/definitions.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,16 @@
5858
OperatorTestGenerator::class,
5959
],
6060
],
61+
62+
// Search Operators
63+
[
64+
'configFiles' => __DIR__ . '/search',
65+
'namespace' => 'MongoDB\\Builder\\Search',
66+
'classNameSuffix' => 'Operator',
67+
'generators' => [
68+
OperatorClassGenerator::class,
69+
OperatorFactoryGenerator::class,
70+
OperatorTestGenerator::class,
71+
],
72+
],
6173
];

generator/config/expression/case.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ name: $case
33
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/switch/'
44
type:
55
- switchBranch
6-
encode: flat_object
6+
encode: object
7+
wrapObject: false
78
description: |
89
Represents a single case in a $switch expression
910
arguments:

generator/config/expressions.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@
109109
'implements' => [ResolvesToAny::class],
110110
'acceptedTypes' => ['string'],
111111
],
112+
'searchOperator' => [
113+
'returnType' => Type\SearchOperatorInterface::class,
114+
'acceptedTypes' => [Type\SearchOperatorInterface::class, ...$bsonTypes['object']],
115+
],
112116
'geometry' => [
113117
'returnType' => Type\GeometryInterface::class,
114118
'acceptedTypes' => [Type\GeometryInterface::class, ...$bsonTypes['object']],
@@ -168,4 +172,12 @@
168172
'GeoPoint' => [
169173
'acceptedTypes' => [...$bsonTypes['object']],
170174
],
175+
176+
// Search
177+
'searchPath' => [
178+
'acceptedTypes' => ['string', 'array'],
179+
],
180+
'searchScore' => [
181+
'acceptedTypes' => [...$bsonTypes['object']],
182+
],
171183
];

generator/config/query/geoIntersects.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ name: $geoIntersects
33
link: 'https://www.mongodb.com/docs/manual/reference/operator/query/geoIntersects/'
44
type:
55
- fieldQuery
6-
encode: single
6+
encode: object
77
description: |
88
Selects geometries that intersect with a GeoJSON geometry. The 2dsphere index supports $geoIntersects.
99
arguments:
1010
-
1111
name: geometry
12+
mergeObject: true
1213
type:
1314
- geometry
1415
tests:

generator/config/query/geoWithin.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ name: $geoWithin
33
link: 'https://www.mongodb.com/docs/manual/reference/operator/query/geoWithin/'
44
type:
55
- fieldQuery
6-
encode: single
6+
encode: object
77
description: |
88
Selects geometries within a bounding GeoJSON geometry. The 2dsphere and 2d indexes support $geoWithin.
99
arguments:
1010
-
1111
name: geometry
12+
mergeObject: true
1213
type:
1314
- geometry
1415
tests:

generator/config/query/near.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,24 @@ name: $near
33
link: 'https://www.mongodb.com/docs/manual/reference/operator/query/near/'
44
type:
55
- fieldQuery
6-
encode: dollar_object
6+
encode: object
77
description: |
88
Returns geospatial objects in proximity to a point. Requires a geospatial index. The 2dsphere and 2d indexes support $near.
99
arguments:
1010
-
1111
name: geometry
12+
mergeObject: true
1213
type:
1314
- geometry
1415
-
15-
name: maxDistance
16+
name: $maxDistance
1617
type:
1718
- number
1819
optional: true
1920
description: |
2021
Distance in meters. Limits the results to those documents that are at most the specified distance from the center point.
2122
-
22-
name: minDistance
23+
name: $minDistance
2324
type:
2425
- number
2526
optional: true

generator/config/query/nearSphere.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,24 @@ name: $nearSphere
33
link: 'https://www.mongodb.com/docs/manual/reference/operator/query/nearSphere/'
44
type:
55
- fieldQuery
6-
encode: dollar_object
6+
encode: object
77
description: |
88
Returns geospatial objects in proximity to a point on a sphere. Requires a geospatial index. The 2dsphere and 2d indexes support $nearSphere.
99
arguments:
1010
-
1111
name: geometry
12+
mergeObject: true
1213
type:
1314
- geometry
1415
-
15-
name: maxDistance
16+
name: $maxDistance
1617
type:
1718
- number
1819
optional: true
1920
description: |
2021
Distance in meters.
2122
-
22-
name: minDistance
23+
name: $minDistance
2324
type:
2425
- number
2526
optional: true

0 commit comments

Comments
 (0)