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

Commit 4ca7e63

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

File tree

83 files changed

+6131
-1
lines changed

Some content is hidden

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

83 files changed

+6131
-1
lines changed

generator/config/stage/addFields.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,23 @@ tests:
3939
-
4040
$addFields:
4141
specs.fuel_type: 'unleaded'
42+
-
43+
name: 'Overwriting an existing field'
44+
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/addFields/#overwriting-an-existing-field'
45+
pipeline:
46+
-
47+
$addFields:
48+
cats: 20
49+
-
50+
name: 'Add Element to an Array'
51+
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/addFields/#add-element-to-an-array'
52+
pipeline:
53+
-
54+
$match:
55+
_id: 1
56+
-
57+
$addFields:
58+
homework:
59+
$concatArrays:
60+
- '$homework'
61+
- [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: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,28 @@ 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+
tests:
10+
-
11+
name: 'Inactive Sessions'
12+
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/currentOp/#inactive-sessions'
13+
pipeline:
14+
-
15+
$currentOp:
16+
allUsers: true
17+
idleSessions: true
18+
-
19+
$match:
20+
active: false
21+
transaction:
22+
$exists: true
23+
-
24+
name: 'Sampled Queries'
25+
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/currentOp/#sampled-queries'
26+
pipeline:
27+
-
28+
$currentOp:
29+
allUsers: true
30+
localOps: true
31+
-
32+
$match:
33+
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: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,35 @@ 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+
-
26+
$sortByCount: '$tags'
27+
categorizedByPrice:
28+
-
29+
$match:
30+
price:
31+
$exists: 1
32+
-
33+
$bucket:
34+
groupBy: '$price'
35+
boundaries: [0, 150, 200, 300, 400]
36+
default: 'Other'
37+
output:
38+
count:
39+
$sum: 1
40+
titles:
41+
$push: '$title'
42+
categorizedByYears(Auto):
43+
-
44+
$bucketAuto:
45+
groupBy: '$year'
46+
buckets: 4

generator/config/stage/fill.yaml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,71 @@ arguments:
4040
description: |
4141
Specifies an object containing each field for which to fill missing values. You can specify multiple fields in the output object.
4242
The object name is the name of the field to fill. The object value specifies how the field is filled.
43+
tests:
44+
-
45+
name: 'Fill Missing Field Values with a Constant Value'
46+
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/fill/#fill-missing-field-values-with-a-constant-value'
47+
pipeline:
48+
-
49+
$fill:
50+
output:
51+
bootsSold:
52+
value: 0
53+
sandalsSold:
54+
value: 0
55+
sneakersSold:
56+
value: 0
57+
-
58+
name: 'Fill Missing Field Values with Linear Interpolation'
59+
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/fill/#fill-missing-field-values-with-linear-interpolation'
60+
pipeline:
61+
-
62+
$fill:
63+
sortBy:
64+
time: 1
65+
output:
66+
price:
67+
method: 'linear'
68+
-
69+
name: 'Fill Missing Field Values Based on the Last Observed Value'
70+
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/fill/#fill-missing-field-values-based-on-the-last-observed-value'
71+
pipeline:
72+
-
73+
$fill:
74+
sortBy:
75+
date: 1
76+
output:
77+
score:
78+
method: 'locf'
79+
-
80+
name: 'Fill Data for Distinct Partitions'
81+
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/fill/#fill-data-for-distinct-partitions'
82+
pipeline:
83+
-
84+
$fill:
85+
sortBy:
86+
date: 1
87+
partitionBy:
88+
restaurant: '$restaurant'
89+
output:
90+
score:
91+
method: 'locf'
92+
-
93+
name: 'Indicate if a Field was Populated Using $fill'
94+
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/fill/#indicate-if-a-field-was-populated-using--fill'
95+
pipeline:
96+
-
97+
$set:
98+
valueExisted:
99+
$ifNull:
100+
-
101+
$toBool:
102+
$toString: '$score'
103+
- false
104+
-
105+
$fill:
106+
sortBy:
107+
date: 1
108+
output:
109+
score:
110+
method: 'locf'

0 commit comments

Comments
 (0)