Debian Codegraph @

testdata/crud/v1/write/updateOne-arrayFilters.yml

raw
1 data:
2 - {_id: 1, y: [{b: 3}, {b: 1}]}
3 - {_id: 2, y: [{b: 0}, {b: 1}]}
4 - {_id: 3, y: [{b: 5, c: [{d: 2}, {d: 1}] }]}
5 minServerVersion: '3.5.6'
6
7 tests:
8 -
9 description: "UpdateOne when no document matches arrayFilters"
10 operation:
11 name: "updateOne"
12 arguments:
13 filter: {}
14 update:
15 $set: {"y.$[i].b": 2}
16 arrayFilters:
17 - {i.b: 4}
18
19 outcome:
20 result:
21 matchedCount: 1
22 modifiedCount: 0
23 upsertedCount: 0
24 collection:
25 data:
26 - {_id: 1, y: [{b: 3}, {b: 1}]}
27 - {_id: 2, y: [{b: 0}, {b: 1}]}
28 - {_id: 3, y: [{b: 5, c: [{d: 2}, {d: 1}] }]}
29 -
30 description: "UpdateOne when one document matches arrayFilters"
31 operation:
32 name: "updateOne"
33 arguments:
34 filter: {}
35 update:
36 $set: {"y.$[i].b": 2}
37 arrayFilters:
38 - {i.b: 3}
39
40 outcome:
41 result:
42 matchedCount: 1
43 modifiedCount: 1
44 upsertedCount: 0
45 collection:
46 data:
47 - {_id: 1, y: [{b: 2}, {b: 1}]}
48 - {_id: 2, y: [{b: 0}, {b: 1}]}
49 - {_id: 3, y: [{b: 5, c: [{d: 2}, {d: 1}] }]}
50 -
51 description: "UpdateOne when multiple documents match arrayFilters"
52 operation:
53 name: "updateOne"
54 arguments:
55 filter: {}
56 update:
57 $set: {"y.$[i].b": 2}
58 arrayFilters:
59 - {i.b: 1}
60
61 outcome:
62 result:
63 matchedCount: 1
64 modifiedCount: 1
65 upsertedCount: 0
66 collection:
67 data:
68 - {_id: 1, y: [{b: 3}, {b: 2}]}
69 - {_id: 2, y: [{b: 0}, {b: 1}]}
70 - {_id: 3, y: [{b: 5, c: [{d: 2}, {d: 1}] }]}
71 -
72 description: "UpdateOne when no documents match multiple arrayFilters"
73 operation:
74 name: "updateOne"
75 arguments:
76 filter: {_id: 3}
77 update:
78 $set: {"y.$[i].c.$[j].d": 0}
79 arrayFilters:
80 - {i.b: 5}
81 - {j.d: 3}
82
83 outcome:
84 result:
85 matchedCount: 1
86 modifiedCount: 0
87 upsertedCount: 0
88 collection:
89 data:
90 - {_id: 1, y: [{b: 3}, {b: 1}]}
91 - {_id: 2, y: [{b: 0}, {b: 1}]}
92 - {_id: 3, y: [{b: 5, c: [{d: 2}, {d: 1}] }]}
93 -
94 description: "UpdateOne when one document matches multiple arrayFilters"
95 operation:
96 name: "updateOne"
97 arguments:
98 filter: {_id: 3}
99 update:
100 $set: {"y.$[i].c.$[j].d": 0}
101 arrayFilters:
102 - {i.b: 5}
103 - {j.d: 1}
104
105 outcome:
106 result:
107 matchedCount: 1
108 modifiedCount: 1
109 upsertedCount: 0
110 collection:
111 data:
112 - {_id: 1, y: [{b: 3}, {b: 1}]}
113 - {_id: 2, y: [{b: 0}, {b: 1}]}
114 - {_id: 3, y: [{b: 5, c: [{d: 2}, {d: 0}] }]}