-
Notifications
You must be signed in to change notification settings - Fork 263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PHPLIB-1254 Create Yaml for all operators and stages #1180
Changes from 19 commits
6fe9809
204e88f
b3c6279
59f360c
64ee28e
05c5ee5
83aa77a
9a36d17
c0de34d
70f8671
38c7750
5733833
6faa7f8
27c9f21
502ed6b
3f175e7
d89d024
2129f88
06c5294
a5840c0
99e2266
636aa4a
5bc3cd8
bdfbcc5
c7bc14c
35dbd63
00b3cd3
dd28e4a
58fd4d0
13d29a8
e51b16f
c0790e0
960eaa4
120f530
57555b9
fee0df6
ad48be4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,8 +14,10 @@ | |
use MongoDB\Builder\Stage; | ||
use MongoDB\Client; | ||
|
||
use function array_is_list; | ||
use function assert; | ||
use function getenv; | ||
use function is_array; | ||
use function is_object; | ||
use function MongoDB\BSON\fromPHP; | ||
use function MongoDB\BSON\toRelaxedExtendedJSON; | ||
|
@@ -48,15 +50,15 @@ function toJSON(object $document): string | |
totalCount: Aggregation::sum(1), | ||
evenCount: Aggregation::sum( | ||
Aggregation::mod( | ||
Expression::fieldPath('randomValue'), | ||
Expression::numberFieldPath('randomValue'), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is Looking at this now, I can see how these might be annoying if users must use type in the query builder. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a request from @alcaeus in the Technical Design doc.
|
||
2, | ||
), | ||
), | ||
oddCount: Aggregation::sum( | ||
Aggregation::subtract( | ||
1, | ||
Aggregation::mod( | ||
Expression::fieldPath('randomValue'), | ||
Expression::numberFieldPath('randomValue'), | ||
2, | ||
), | ||
), | ||
|
@@ -74,6 +76,8 @@ function toJSON(object $document): string | |
$encoder = new BuilderEncoder(); | ||
$pipeline = $encoder->encode($pipeline); | ||
|
||
assert(is_array($pipeline) && array_is_list($pipeline)); | ||
|
||
$cursor = $collection->aggregate($pipeline); | ||
|
||
foreach ($cursor as $document) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,9 @@ | |
"mongodb/mongodb": "@dev", | ||
"nette/php-generator": "^4", | ||
"symfony/console": "^6.3", | ||
"symfony/css-selector": "^6.3", | ||
"symfony/dom-crawler": "^6.3", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove when the scrape command is removed. |
||
"symfony/finder": "^6.3", | ||
"symfony/yaml": "^6.3" | ||
}, | ||
"license": "Apache-2.0", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# $schema: ../schema.json | ||
name: $abs | ||
category: | ||
- 'Arithmetic Expression' | ||
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/abs/' | ||
type: | ||
- resolvesToNumber | ||
encode: single | ||
description: | | ||
Returns the absolute value of a number. | ||
arguments: | ||
- | ||
name: value | ||
type: | ||
- resolvesToNumber |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# $schema: ../schema.json | ||
name: $accumulator | ||
category: | ||
- Accumulators | ||
- 'Custom Aggregation Expression Operator' | ||
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/accumulator/' | ||
type: | ||
- accumulator | ||
encode: object | ||
description: | | ||
Defines a custom accumulator function. | ||
New in version 4.4. | ||
arguments: | ||
- | ||
name: init | ||
type: | ||
- string | ||
description: | | ||
Function used to initialize the state. The init function receives its arguments from the initArgs array expression. You can specify the function definition as either BSON type Code or String. | ||
- | ||
name: initArgs | ||
type: | ||
- resolvesToArray | ||
optional: true | ||
description: | | ||
Arguments passed to the init function. | ||
- | ||
name: accumulate | ||
type: | ||
- string | ||
description: | | ||
Function used to accumulate documents. The accumulate function receives its arguments from the current state and accumulateArgs array expression. The result of the accumulate function becomes the new state. You can specify the function definition as either BSON type Code or String. | ||
- | ||
name: accumulateArgs | ||
type: | ||
- resolvesToArray | ||
description: | | ||
Arguments passed to the accumulate function. You can use accumulateArgs to specify what field value(s) to pass to the accumulate function. | ||
- | ||
name: merge | ||
type: | ||
- string | ||
description: | | ||
Function used to merge two internal states. merge must be either a String or Code BSON type. merge returns the combined result of the two merged states. For information on when the merge function is called, see Merge Two States with $merge. | ||
- | ||
name: finalize | ||
type: | ||
- string | ||
optional: true | ||
description: | | ||
Function used to update the result of the accumulation. | ||
- | ||
name: lang | ||
type: | ||
- string | ||
description: | | ||
The language used in the $accumulator code. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# $schema: ../schema.json | ||
name: $acos | ||
category: | ||
- 'Trigonometry Expression Operator' | ||
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/acos/' | ||
type: | ||
- resolvesToDouble | ||
- resolvesToDecimal | ||
encode: single | ||
description: | | ||
Returns the inverse cosine (arc cosine) of a value in radians. | ||
arguments: | ||
- | ||
name: expression | ||
type: | ||
- resolvesToNumber | ||
description: | | ||
$acos takes any valid expression that resolves to a number between -1 and 1, e.g. -1 <= value <= 1. | ||
$acos returns values in radians. Use $radiansToDegrees operator to convert the output value from radians to degrees. | ||
By default $acos returns values as a double. $acos can also return values as a 128-bit decimal as long as the expression resolves to a 128-bit decimal value. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# $schema: ../schema.json | ||
name: $acosh | ||
category: | ||
- 'Trigonometry Expression Operator' | ||
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/acosh/' | ||
type: | ||
- resolvesToDouble | ||
- resolvesToDecimal | ||
encode: single | ||
description: | | ||
Returns the inverse hyperbolic cosine (hyperbolic arc cosine) of a value in radians. | ||
arguments: | ||
- | ||
name: expression | ||
type: | ||
- resolvesToNumber | ||
description: | | ||
$acosh takes any valid expression that resolves to a number between 1 and +Infinity, e.g. 1 <= value <= +Infinity. | ||
$acosh returns values in radians. Use $radiansToDegrees operator to convert the output value from radians to degrees. | ||
By default $acosh returns values as a double. $acosh can also return values as a 128-bit decimal as long as the expression resolves to a 128-bit decimal value. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# $schema: ../schema.json | ||
name: $add | ||
category: | ||
- 'Arithmetic Expression Operator' | ||
- 'Date Expression Operator' | ||
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/add/' | ||
type: | ||
- resolvesToNumber | ||
- resolvesToDate | ||
encode: array | ||
description: | | ||
Adds numbers to return the sum, or adds numbers and a date to return a new date. If adding numbers and a date, treats the numbers as milliseconds. Accepts any number of argument expressions, but at most, one expression can resolve to a date. | ||
arguments: | ||
- | ||
name: expression | ||
type: | ||
- resolvesToNumber | ||
- resolvesToDate | ||
variadic: array | ||
description: | | ||
The arguments can be any valid expression as long as they resolve to either all numbers or to numbers and a date. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# $schema: ../schema.json | ||
name: $addToSet | ||
category: | ||
- Accumulators | ||
- 'Window Operator' | ||
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/addToSet/' | ||
type: | ||
- accumulator | ||
encode: single | ||
description: | | ||
Returns an array of unique expression values for each group. Order of the array elements is undefined. | ||
Changed in version 5.0: Available in the $setWindowFields stage. | ||
arguments: | ||
- | ||
name: expression | ||
type: | ||
- expression | ||
- fieldPath |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# $schema: ../schema.json | ||
name: $allElementsTrue | ||
category: | ||
- 'Set Expression Operator' | ||
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/allElementsTrue/' | ||
type: | ||
- resolvesToBool | ||
encode: array | ||
description: | | ||
Returns true if no element of a set evaluates to false, otherwise, returns false. Accepts a single argument expression. | ||
arguments: | ||
- | ||
name: expression | ||
type: | ||
- resolvesToArray | ||
variadic: array |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# $schema: ../schema.json | ||
name: $and | ||
category: | ||
- 'Boolean Expression Operator' | ||
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/and/' | ||
type: | ||
- resolvesToBool | ||
encode: single | ||
description: | | ||
Returns true only when all its expressions evaluate to true. Accepts any number of argument expressions. | ||
arguments: | ||
- | ||
name: expression | ||
type: | ||
- expression | ||
- resolvesToBool | ||
- resolvesToNumber | ||
- resolvesToString | ||
- resolvesToNull | ||
variadic: array |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# $schema: ../schema.json | ||
name: $anyElementTrue | ||
category: | ||
- 'Set Expression Operator' | ||
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/anyElementTrue/' | ||
type: | ||
- resolvesToBool | ||
encode: array | ||
description: | | ||
Returns true if any elements of a set evaluate to true; otherwise, returns false. Accepts a single argument expression. | ||
arguments: | ||
- | ||
name: expression | ||
type: | ||
- resolvesToArray |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# $schema: ../schema.json | ||
name: $arrayElemAt | ||
category: | ||
- 'Array Expression Operator' | ||
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/arrayElemAt/' | ||
type: | ||
- resolvesToAny | ||
encode: array | ||
description: | | ||
Returns the element at the specified array index. | ||
arguments: | ||
- | ||
name: array | ||
type: | ||
- resolvesToArray | ||
- | ||
name: idx | ||
type: | ||
- resolvesToInt |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# $schema: ../schema.json | ||
name: $arrayToObject | ||
category: | ||
- 'Array Expression Operator' | ||
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/arrayToObject/' | ||
type: | ||
- resolvesToObject | ||
encode: array | ||
description: | | ||
Converts an array of key value pairs to a document. | ||
arguments: | ||
- | ||
name: array | ||
type: | ||
- resolvesToArray |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be reverted by PHPLIB-1268
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you come to a solution to still run PHPLIB against 7.4+ but limit the aggregation builder code to 8.1+?