Skip to content
This repository was archived by the owner on Feb 28, 2025. It is now read-only.

Commit a1b956d

Browse files
committed
PHPLIB-1374 Add tests on all stages
1 parent ff4fc79 commit a1b956d

File tree

93 files changed

+7669
-86
lines changed

Some content is hidden

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

93 files changed

+7669
-86
lines changed

generator/config/expression/sum.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ arguments:
1212
name: expression
1313
type:
1414
- resolvesToNumber
15+
- resolvesToArray
1516
variadic: array
1617
tests:
1718
-

generator/config/stage/addFields.yaml

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@ tests:
2222
-
2323
$addFields:
2424
totalHomework:
25-
$sum: '$homework'
25+
# The example renders a single value, but the builder generates an array for consistency
26+
# $sum: '$homework'
27+
$sum: ['$homework']
2628
totalQuiz:
27-
$sum: '$quiz'
29+
# $sum: '$quiz'
30+
$sum: ['$quiz']
2831
-
2932
$addFields:
3033
totalScore:
@@ -39,3 +42,23 @@ tests:
3942
-
4043
$addFields:
4144
specs.fuel_type: 'unleaded'
45+
-
46+
name: 'Overwriting an existing field'
47+
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/addFields/#overwriting-an-existing-field'
48+
pipeline:
49+
-
50+
$addFields:
51+
cats: 20
52+
-
53+
name: 'Add Element to an Array'
54+
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/addFields/#add-element-to-an-array'
55+
pipeline:
56+
-
57+
$match:
58+
_id: 1
59+
-
60+
$addFields:
61+
homework:
62+
$concatArrays:
63+
- '$homework'
64+
- [7]

generator/config/stage/bucket.yaml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,62 @@ arguments:
4040
A document that specifies the fields to include in the output documents in addition to the _id field. To specify the field to include, you must use accumulator expressions.
4141
If you do not specify an output document, the operation returns a count field containing the number of documents in each bucket.
4242
If you specify an output document, only the fields specified in the document are returned; i.e. the count field is not returned unless it is explicitly included in the output document.
43+
tests:
44+
-
45+
name: 'Bucket by Year and Filter by Bucket Results'
46+
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/bucket/#bucket-by-year-and-filter-by-bucket-results'
47+
pipeline:
48+
-
49+
$bucket:
50+
groupBy: '$year_born'
51+
boundaries: [1840, 1850, 1860, 1870, 1880]
52+
default: 'Other'
53+
output:
54+
count:
55+
$sum: 1
56+
artists:
57+
$push:
58+
name:
59+
$concat:
60+
- '$first_name'
61+
- ' '
62+
- '$last_name'
63+
year_born: '$year_born'
64+
-
65+
$match:
66+
count:
67+
$gt: 3
68+
-
69+
name: 'Use $bucket with $facet to Bucket by Multiple Fields'
70+
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/bucket/#use--bucket-with--facet-to-bucket-by-multiple-fields'
71+
pipeline:
72+
-
73+
$facet:
74+
price:
75+
-
76+
$bucket:
77+
groupBy: '$price'
78+
boundaries: [0, 200, 400]
79+
default: 'Other'
80+
output:
81+
count:
82+
$sum: 1
83+
artwork:
84+
$push:
85+
title: '$title'
86+
price: '$price'
87+
averagePrice:
88+
$avg: '$price'
89+
year:
90+
-
91+
$bucket:
92+
groupBy: '$year'
93+
boundaries: [1890, 1910, 1920, 1940]
94+
default: 'Unknown'
95+
output:
96+
count:
97+
$sum: 1
98+
artwork:
99+
$push:
100+
title: '$title'
101+
year: '$year'

generator/config/stage/bucketAuto.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,12 @@ arguments:
3535
description: |
3636
A string that specifies the preferred number series to use to ensure that the calculated boundary edges end on preferred round numbers or their powers of 10.
3737
Available only if the all groupBy values are numeric and none of them are NaN.
38+
tests:
39+
-
40+
name: 'Single Facet Aggregation'
41+
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/bucketAuto/#single-facet-aggregation'
42+
pipeline:
43+
-
44+
$bucketAuto:
45+
groupBy: '$price'
46+
buckets: 4

generator/config/stage/changeStream.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,10 @@ arguments:
5757
optional: true
5858
description: |
5959
Specifies a time as the logical starting point for the change stream. Cannot be used with resumeAfter or startAfter fields.
60+
tests:
61+
-
62+
name: 'Example'
63+
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/changeStream/#examples'
64+
pipeline:
65+
-
66+
$changeStream: {}

generator/config/stage/changeStreamSplitLargeEvent.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,10 @@ encode: object
77
description: |
88
Splits large change stream events that exceed 16 MB into smaller fragments returned in a change stream cursor.
99
You can only use $changeStreamSplitLargeEvent in a $changeStream pipeline and it must be the final stage in the pipeline.
10+
tests:
11+
-
12+
name: 'Example'
13+
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/changeStreamSplitLargeEvent/#example'
14+
pipeline:
15+
-
16+
$changeStreamSplitLargeEvent: {}

generator/config/stage/collStats.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,33 @@ arguments:
1111
name: config
1212
type:
1313
- object
14+
tests:
15+
-
16+
name: 'latencyStats Document'
17+
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/collStats/#latencystats-document'
18+
pipeline:
19+
-
20+
$collStats:
21+
latencyStats:
22+
histograms: true
23+
-
24+
name: 'storageStats Document'
25+
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/collStats/#storagestats-document'
26+
pipeline:
27+
-
28+
$collStats:
29+
storageStats: {}
30+
-
31+
name: 'count Field'
32+
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/collStats/#count-field'
33+
pipeline:
34+
-
35+
$collStats:
36+
count: {}
37+
-
38+
name: 'queryExecStats Document'
39+
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/collStats/#queryexecstats-document'
40+
pipeline:
41+
-
42+
$collStats:
43+
queryExecStats: {}

generator/config/stage/count.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,14 @@ arguments:
1414
- string
1515
description: |
1616
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.
17+
tests:
18+
-
19+
name: 'Example'
20+
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/count/#example'
21+
pipeline:
22+
-
23+
$match:
24+
score:
25+
$gt: 80
26+
-
27+
$count: 'passing_scores'

generator/config/stage/currentOp.yaml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,54 @@ type:
66
encode: object
77
description: |
88
Returns information on active and/or dormant operations for the MongoDB deployment. To run, use the db.aggregate() method.
9+
arguments:
10+
-
11+
name: allUsers
12+
type:
13+
- bool
14+
optional: true
15+
-
16+
name: idleConnections
17+
type:
18+
- bool
19+
optional: true
20+
-
21+
name: idleCursors
22+
type:
23+
- bool
24+
optional: true
25+
-
26+
name: idleSessions
27+
type:
28+
- bool
29+
optional: true
30+
-
31+
name: localOps
32+
type:
33+
- bool
34+
optional: true
35+
tests:
36+
-
37+
name: 'Inactive Sessions'
38+
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/currentOp/#inactive-sessions'
39+
pipeline:
40+
-
41+
$currentOp:
42+
allUsers: true
43+
idleSessions: true
44+
-
45+
$match:
46+
active: false
47+
transaction:
48+
$exists: true
49+
-
50+
name: 'Sampled Queries'
51+
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/currentOp/#sampled-queries'
52+
pipeline:
53+
-
54+
$currentOp:
55+
allUsers: true
56+
localOps: true
57+
-
58+
$match:
59+
desc: 'query analyzer'

generator/config/stage/densify.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,29 @@ arguments:
2828
- object # Range
2929
description: |
3030
Specification for range based densification.
31+
tests:
32+
-
33+
name: 'Densify Time Series Data'
34+
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/densify/#densify-time-series-data'
35+
pipeline:
36+
-
37+
$densify:
38+
field: 'timestamp'
39+
range:
40+
step: 1
41+
unit: 'hour'
42+
bounds:
43+
- !bson_utcdatetime '2021-05-18T00:00:00.000Z'
44+
- !bson_utcdatetime '2021-05-18T08:00:00.000Z'
45+
-
46+
name: 'Densifiction with Partitions'
47+
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/densify/#densifiction-with-partitions'
48+
pipeline:
49+
-
50+
$densify:
51+
field: 'altitude'
52+
partitionByFields:
53+
- 'variety'
54+
range:
55+
bounds: 'full'
56+
step: 200

generator/config/stage/documents.yaml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,37 @@ arguments:
1717
- $let expressions
1818
- variables in scope from $lookup expressions
1919
Expressions that do not resolve to a current document, like $myField or $$ROOT, will result in an error.
20+
tests:
21+
-
22+
name: 'Test a Pipeline Stage'
23+
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/documents/#test-a-pipeline-stage'
24+
pipeline:
25+
-
26+
$documents:
27+
- { x: 10 }
28+
- { x: 2 }
29+
- { x: 5 }
30+
-
31+
$bucketAuto:
32+
groupBy: '$x'
33+
buckets: 4
34+
-
35+
name: 'Use a $documents Stage in a $lookup Stage'
36+
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/documents/#use-a--documents-stage-in-a--lookup-stage'
37+
pipeline:
38+
-
39+
$match: {}
40+
-
41+
$lookup:
42+
localField: 'zip'
43+
foreignField: 'zip_id'
44+
as: 'city_state'
45+
pipeline:
46+
-
47+
$documents:
48+
-
49+
zip_id: 94301
50+
name: 'Palo Alto, CA'
51+
-
52+
zip_id: 10019
53+
name: 'New York, NY'

generator/config/stage/facet.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,39 @@ arguments:
1212
type:
1313
- pipeline
1414
variadic: object
15+
tests:
16+
-
17+
name: 'Example'
18+
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/facet/#example'
19+
pipeline:
20+
-
21+
$facet:
22+
categorizedByTags:
23+
-
24+
# $unwind: '$tags'
25+
$unwind:
26+
path: '$tags'
27+
-
28+
$sortByCount: '$tags'
29+
categorizedByPrice:
30+
-
31+
$match:
32+
price:
33+
# The example uses an int, but the builder requires a bool
34+
# $exists: 1
35+
$exists: true
36+
-
37+
$bucket:
38+
groupBy: '$price'
39+
boundaries: [0, 150, 200, 300, 400]
40+
default: 'Other'
41+
output:
42+
count:
43+
$sum: 1
44+
titles:
45+
$push: '$title'
46+
categorizedByYears(Auto):
47+
-
48+
$bucketAuto:
49+
groupBy: '$year'
50+
buckets: 4

0 commit comments

Comments
 (0)