Skip to content

Commit 75edbe2

Browse files
committed
CXX-1390 Support arrayFilters
1 parent 1cb66e2 commit 75edbe2

Some content is hidden

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

54 files changed

+1613
-67
lines changed

data/crud/README.rst

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,6 @@ define and setup. Therefore, these YAML tests are in no way a replacement for
1212
more thorough testing. However, they can provide an initial verification of your
1313
implementation.
1414

15-
Converting to JSON
16-
==================
17-
18-
The tests are written in YAML because it is easier for humans to write and read,
19-
and because YAML includes a standard comment format. A JSONified version of each
20-
YAML file is included in this repository. Whenever a YAML file is modified, the
21-
corresponding JSON file should be regenerated. One method to convert to JSON is
22-
using `yamljs <https://www.npmjs.com/package/yamljs>`_::
23-
24-
npm install -g yamljs
25-
yaml2json -s -p -r .
26-
2715
Version
2816
=======
2917

@@ -44,13 +32,14 @@ Each YAML file has the following keys:
4432
- ``data``: The data that should exist in the collection under test before each
4533
test run.
4634

47-
- ``minServerVersion`` (optional): The minimum server version required to
48-
successfully run the test. If this field is not present, it should be assumed
49-
that there is no lower bound on the server version required.
35+
- ``minServerVersion`` (optional): The minimum server version (inclusive)
36+
required to successfully run the test. If this field is not present, it should
37+
be assumed that there is no lower bound on the required server version.
5038

51-
- ``maxServerVersion`` (optional): The max server version against which this
52-
test can run successfully. If this field is not present, it should be assumed
53-
that there is no upper bound on the server version required.
39+
- ``maxServerVersion`` (optional): The maximum server version (exclusive)
40+
against which this test can run successfully. If this field is not present,
41+
it should be assumed that there is no upper bound on the required server
42+
version.
5443

5544
- ``tests``: An array of tests that are to be run independently of each other.
5645
Each test will have some or all of the following fields:
@@ -68,7 +57,11 @@ Each YAML file has the following keys:
6857
the collection after the operation is executed. This will have some or all
6958
of the following fields:
7059

71-
- ``result``: The return value from the operation.
60+
- ``result``: The return value from the operation. Note that some tests
61+
specify an ``upsertedCount`` field when the server does not provide
62+
one in the result document. In these cases, an ``upsertedCount`` field
63+
with a value of 0 should be manually added to the document received
64+
from the server to facilitate comparison.
7265

7366
- ``collection``:
7467

@@ -83,6 +76,5 @@ Use as integration tests
8376

8477
Running these as integration tests will require a running mongod server. Each of
8578
these tests is valid against a standalone mongod, a replica set, and a sharded
86-
system for server version 3.0.0. Many of them will run against 2.4 and 2.6, but
87-
some will require conditional code. For instance, ``$out`` is not supported in
88-
an aggregation pipeline in server 2.4, so that test must be skipped.
79+
system for server version 3.0 and later. Many of them will run against 2.6, but
80+
some will require conditional code.

data/crud/read/aggregate-collation.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@
3535
}
3636
}
3737
]
38-
}
38+
}

data/crud/read/aggregate-out.json

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,57 @@
6565
]
6666
}
6767
}
68+
},
69+
{
70+
"description": "Aggregate with $out and batch size of 0",
71+
"operation": {
72+
"name": "aggregate",
73+
"arguments": {
74+
"pipeline": [
75+
{
76+
"$sort": {
77+
"x": 1
78+
}
79+
},
80+
{
81+
"$match": {
82+
"_id": {
83+
"$gt": 1
84+
}
85+
}
86+
},
87+
{
88+
"$out": "other_test_collection"
89+
}
90+
],
91+
"batchSize": 0
92+
}
93+
},
94+
"outcome": {
95+
"result": [
96+
{
97+
"_id": 2,
98+
"x": 22
99+
},
100+
{
101+
"_id": 3,
102+
"x": 33
103+
}
104+
],
105+
"collection": {
106+
"name": "other_test_collection",
107+
"data": [
108+
{
109+
"_id": 2,
110+
"x": 22
111+
},
112+
{
113+
"_id": 3,
114+
"x": 33
115+
}
116+
]
117+
}
118+
}
68119
}
69120
]
70-
}
121+
}

data/crud/read/aggregate-out.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,24 @@ tests:
2626
data:
2727
- {_id: 2, x: 22}
2828
- {_id: 3, x: 33}
29+
-
30+
description: "Aggregate with $out and batch size of 0"
31+
operation:
32+
name: aggregate
33+
arguments:
34+
pipeline:
35+
- $sort: {x: 1}
36+
- $match:
37+
_id: {$gt: 1}
38+
- $out: "other_test_collection"
39+
batchSize: 0
40+
41+
outcome:
42+
result:
43+
- {_id: 2, x: 22}
44+
- {_id: 3, x: 33}
45+
collection:
46+
name: "other_test_collection"
47+
data:
48+
- {_id: 2, x: 22}
49+
- {_id: 3, x: 33}

data/crud/read/aggregate.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,4 @@
5050
}
5151
}
5252
]
53-
}
53+
}

data/crud/read/count-collation.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@
2626
}
2727
}
2828
]
29-
}
29+
}

data/crud/read/count.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,4 @@
5757
}
5858
}
5959
]
60-
}
60+
}

data/crud/read/distinct-collation.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@
3030
}
3131
}
3232
]
33-
}
33+
}

data/crud/read/distinct.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,4 @@
5252
}
5353
}
5454
]
55-
}
55+
}

data/crud/read/find-collation.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@
3131
}
3232
}
3333
]
34-
}
34+
}

data/crud/read/find.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,4 @@
102102
}
103103
}
104104
]
105-
}
105+
}

data/crud/test_files.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
./read/distinct.json
88
./read/find-collation.json
99
./read/find.json
10+
./write/bulkWrite-arrayFilters.json
1011
./write/deleteMany-collation.json
1112
./write/deleteMany.json
1213
./write/deleteOne-collation.json
@@ -17,16 +18,19 @@
1718
./write/findOneAndReplace-upsert.json
1819
./write/findOneAndReplace-upsert_pre_2.6.json
1920
./write/findOneAndReplace.json
21+
./write/findOneAndUpdate-arrayFilters.json
2022
./write/findOneAndUpdate-collation.json
2123
./write/findOneAndUpdate.json
2224
./write/insertMany.json
2325
./write/insertOne.json
2426
./write/replaceOne-collation.json
2527
./write/replaceOne-pre_2.6.json
2628
./write/replaceOne.json
29+
./write/updateMany-arrayFilters.json
2730
./write/updateMany-collation.json
2831
./write/updateMany-pre_2.6.json
2932
./write/updateMany.json
33+
./write/updateOne-arrayFilters.json
3034
./write/updateOne-collation.json
3135
./write/updateOne-pre_2.6.json
3236
./write/updateOne.json
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
{
2+
"data": [
3+
{
4+
"_id": 1,
5+
"y": [
6+
{
7+
"b": 3
8+
},
9+
{
10+
"b": 1
11+
}
12+
]
13+
},
14+
{
15+
"_id": 2,
16+
"y": [
17+
{
18+
"b": 0
19+
},
20+
{
21+
"b": 1
22+
}
23+
]
24+
}
25+
],
26+
"minServerVersion": "3.5.6",
27+
"tests": [
28+
{
29+
"description": "BulkWrite with arrayFilters",
30+
"operation": {
31+
"arguments": {
32+
"options": {
33+
"ordered": true
34+
},
35+
"requests": [
36+
{
37+
"arguments": {
38+
"arrayFilters": [
39+
{
40+
"i.b": 3
41+
}
42+
],
43+
"filter": {},
44+
"update": {
45+
"$set": {
46+
"y.$[i].b": 2
47+
}
48+
}
49+
},
50+
"name": "updateOne"
51+
},
52+
{
53+
"arguments": {
54+
"arrayFilters": [
55+
{
56+
"i.b": 1
57+
}
58+
],
59+
"filter": {},
60+
"update": {
61+
"$set": {
62+
"y.$[i].b": 2
63+
}
64+
}
65+
},
66+
"name": "updateMany"
67+
}
68+
]
69+
},
70+
"name": "bulkWrite"
71+
},
72+
"outcome": {
73+
"collection": {
74+
"data": [
75+
{
76+
"_id": 1,
77+
"y": [
78+
{
79+
"b": 2
80+
},
81+
{
82+
"b": 2
83+
}
84+
]
85+
},
86+
{
87+
"_id": 2,
88+
"y": [
89+
{
90+
"b": 0
91+
},
92+
{
93+
"b": 2
94+
}
95+
]
96+
}
97+
]
98+
},
99+
"result": {
100+
"deletedCount": 0,
101+
"insertedIds": {},
102+
"matchedCount": 3,
103+
"modifiedCount": 3,
104+
"upsertedCount": 0,
105+
"upsertedIds": {}
106+
}
107+
}
108+
}
109+
]
110+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
data:
2+
- {_id: 1, y: [{b: 3}, {b: 1}]}
3+
- {_id: 2, y: [{b: 0}, {b: 1}]}
4+
5+
minServerVersion: '3.5.6'
6+
7+
tests:
8+
-
9+
description: "BulkWrite with arrayFilters"
10+
operation:
11+
name: "bulkWrite"
12+
arguments:
13+
requests:
14+
-
15+
# UpdateOne when one document matches arrayFilters
16+
name: "updateOne"
17+
arguments:
18+
filter: {}
19+
update:
20+
$set: {"y.$[i].b": 2}
21+
arrayFilters:
22+
- {i.b: 3}
23+
-
24+
# UpdateMany when multiple documents match arrayFilters
25+
name: "updateMany"
26+
arguments:
27+
filter: {}
28+
update:
29+
$set: {"y.$[i].b": 2}
30+
arrayFilters:
31+
- {i.b: 1}
32+
options: { ordered: true }
33+
outcome:
34+
result:
35+
deletedCount: 0
36+
insertedIds: {}
37+
matchedCount: 3
38+
modifiedCount: 3
39+
upsertedCount: 0
40+
upsertedIds: {}
41+
collection:
42+
data:
43+
- {_id: 1, y: [{b: 2}, {b: 2}]}
44+
- {_id: 2, y: [{b: 0}, {b: 2}]}

data/crud/write/deleteMany-collation.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@
4444
}
4545
}
4646
]
47-
}
47+
}

0 commit comments

Comments
 (0)