Skip to content

Commit 56a801b

Browse files
committed
add tests schema
1 parent 39224b6 commit 56a801b

File tree

288 files changed

+6092
-3302
lines changed

Some content is hidden

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

288 files changed

+6092
-3302
lines changed

generator/config/accumulator/accumulator.yaml

Lines changed: 51 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# $schema: ../schema.json
22
name: $accumulator
3-
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/accumulator/'
3+
link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/accumulator/
44
type:
55
- accumulator
66
encode: object
@@ -52,15 +52,14 @@ arguments:
5252
- string
5353
description: |
5454
The language used in the $accumulator code.
55-
5655
tests:
5756
-
58-
name: 'Use $accumulator to Implement the $avg Operator'
59-
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/accumulator/#use--accumulator-to-implement-the--avg-operator'
57+
name: Use $accumulator to Implement the $avg Operator
58+
link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/accumulator/#use--accumulator-to-implement-the--avg-operator
6059
pipeline:
6160
-
6261
$group:
63-
_id: '$author'
62+
_id: $author
6463
avgCopies:
6564
$accumulator:
6665
init:
@@ -73,7 +72,8 @@ tests:
7372
function(state, numCopies) {
7473
return { count: state.count + 1, sum: state.sum + numCopies }
7574
}
76-
accumulateArgs: [ "$copies" ]
75+
accumulateArgs:
76+
- $copies
7777
merge:
7878
$code: |-
7979
function(state1, state2) {
@@ -87,16 +87,33 @@ tests:
8787
function(state) {
8888
return (state.sum / state.count)
8989
}
90-
lang: 'js'
91-
90+
lang: js
91+
schema:
92+
books:
93+
_id:
94+
types:
95+
-
96+
bsonType: Number
97+
title:
98+
types:
99+
-
100+
bsonType: String
101+
author:
102+
types:
103+
-
104+
bsonType: String
105+
copies:
106+
types:
107+
-
108+
bsonType: Number
92109
-
93-
name: 'Use initArgs to Vary the Initial State by Group'
94-
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/accumulator/#use-initargs-to-vary-the-initial-state-by-group'
110+
name: Use initArgs to Vary the Initial State by Group
111+
link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/accumulator/#use-initargs-to-vary-the-initial-state-by-group
95112
pipeline:
96113
-
97114
$group:
98115
_id:
99-
city: '$city'
116+
city: $city
100117
restaurants:
101118
$accumulator:
102119
init:
@@ -105,8 +122,8 @@ tests:
105122
return { max: city === userProfileCity ? 3 : 1, restaurants: [] }
106123
}
107124
initArgs:
108-
- '$city'
109-
- 'Bettles'
125+
- $city
126+
- Bettles
110127
accumulate:
111128
$code: |-
112129
function(state, restaurantName) {
@@ -115,7 +132,8 @@ tests:
115132
}
116133
return state;
117134
}
118-
accumulateArgs: ['$name']
135+
accumulateArgs:
136+
- $name
119137
merge:
120138
$code: |-
121139
function(state1, state2) {
@@ -129,4 +147,22 @@ tests:
129147
function(state) {
130148
return state.restaurants
131149
}
132-
lang: 'js'
150+
lang: js
151+
schema:
152+
restaurants:
153+
_id:
154+
types:
155+
-
156+
bsonType: Number
157+
name:
158+
types:
159+
-
160+
bsonType: String
161+
city:
162+
types:
163+
-
164+
bsonType: String
165+
cuisine:
166+
types:
167+
-
168+
bsonType: String
Lines changed: 67 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# $schema: ../schema.json
22
name: $addToSet
3-
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/addToSet/'
3+
link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/addToSet/
44
type:
55
- accumulator
66
- window
@@ -13,35 +13,83 @@ arguments:
1313
name: expression
1414
type:
1515
- expression
16-
1716
tests:
1817
-
19-
name: 'Use in $group Stage'
20-
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/addToSet/#use-in--group-stage'
18+
name: Use in $group Stage
19+
link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/addToSet/#use-in--group-stage
2120
pipeline:
22-
- $group:
21+
-
22+
$group:
23+
_id:
24+
day:
25+
$dayOfYear:
26+
date: $date
27+
year:
28+
$year:
29+
date: $date
30+
itemsSold:
31+
$addToSet: $item
32+
schema:
33+
sales:
2334
_id:
24-
day:
25-
$dayOfYear:
26-
date: '$date'
27-
year:
28-
$year:
29-
date: '$date'
30-
itemsSold:
31-
$addToSet: '$item'
35+
types:
36+
-
37+
bsonType: Number
38+
item:
39+
types:
40+
-
41+
bsonType: String
42+
price:
43+
types:
44+
-
45+
bsonType: Number
46+
quantity:
47+
types:
48+
-
49+
bsonType: Number
50+
date:
51+
types:
52+
-
53+
bsonType: Date
3254
-
33-
name: 'Use in $setWindowFields Stage'
34-
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/addToSet/#use-in--setwindowfields-stage'
55+
name: Use in $setWindowFields Stage
56+
link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/addToSet/#use-in--setwindowfields-stage
3557
pipeline:
3658
-
3759
$setWindowFields:
38-
partitionBy: '$state'
60+
partitionBy: $state
3961
sortBy:
4062
orderDate: 1
4163
output:
4264
cakeTypesForState:
43-
$addToSet: '$type'
65+
$addToSet: $type
4466
window:
4567
documents:
46-
- 'unbounded'
47-
- 'current'
68+
- unbounded
69+
- current
70+
schema:
71+
cakeSales:
72+
_id:
73+
types:
74+
-
75+
bsonType: Number
76+
type:
77+
types:
78+
-
79+
bsonType: String
80+
orderDate:
81+
types:
82+
-
83+
bsonType: Date
84+
state:
85+
types:
86+
-
87+
bsonType: String
88+
price:
89+
types:
90+
-
91+
bsonType: Number
92+
quantity:
93+
types:
94+
-
95+
bsonType: Number

generator/config/accumulator/avg.yaml

Lines changed: 63 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# $schema: ../schema.json
22
name: $avg
3-
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/avg/'
3+
link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/avg/
44
type:
55
- accumulator
66
- window
@@ -15,31 +15,80 @@ arguments:
1515
- resolvesToNumber
1616
tests:
1717
-
18-
name: 'Use in $group Stage'
19-
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/avg/#use-in--group-stage'
18+
name: Use in $group Stage
19+
link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/avg/#use-in--group-stage
2020
pipeline:
21-
- $group:
22-
_id: '$item'
21+
-
22+
$group:
23+
_id: $item
2324
avgAmount:
2425
$avg:
2526
$multiply:
26-
- '$price'
27-
- '$quantity'
27+
- $price
28+
- $quantity
2829
avgQuantity:
29-
$avg: '$quantity'
30+
$avg: $quantity
31+
schema:
32+
sales:
33+
_id:
34+
types:
35+
-
36+
bsonType: Number
37+
item:
38+
types:
39+
-
40+
bsonType: String
41+
price:
42+
types:
43+
-
44+
bsonType: Number
45+
quantity:
46+
types:
47+
-
48+
bsonType: Number
49+
date:
50+
types:
51+
-
52+
bsonType: Date
3053
-
31-
name: 'Use in $setWindowFields Stage'
32-
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/avg/#use-in--setwindowfields-stage'
54+
name: Use in $setWindowFields Stage
55+
link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/avg/#use-in--setwindowfields-stage
3356
pipeline:
3457
-
3558
$setWindowFields:
36-
partitionBy: '$state'
59+
partitionBy: $state
3760
sortBy:
3861
orderDate: 1
3962
output:
4063
averageQuantityForState:
41-
$avg: '$quantity'
64+
$avg: $quantity
4265
window:
4366
documents:
44-
- 'unbounded'
45-
- 'current'
67+
- unbounded
68+
- current
69+
schema:
70+
cakeSales:
71+
_id:
72+
types:
73+
-
74+
bsonType: Number
75+
type:
76+
types:
77+
-
78+
bsonType: String
79+
orderDate:
80+
types:
81+
-
82+
bsonType: Date
83+
state:
84+
types:
85+
-
86+
bsonType: String
87+
price:
88+
types:
89+
-
90+
bsonType: Number
91+
quantity:
92+
types:
93+
-
94+
bsonType: Number

0 commit comments

Comments
 (0)