...
1data:
2 - {_id: 1, x: 11}
3 - {_id: 2, x: 22}
4 - {_id: 3, x: 33}
5
6tests:
7 -
8 description: "FindOneAndUpdate when many documents match returning the document before modification"
9 operation:
10 name: findOneAndUpdate
11 arguments:
12 filter:
13 _id: {$gt: 1}
14 update:
15 $inc: {x: 1}
16 projection: {x: 1, _id: 0}
17 sort: {x: 1}
18
19 outcome:
20 result: {x: 22}
21 collection:
22 data:
23 - {_id: 1, x: 11}
24 - {_id: 2, x: 23}
25 - {_id: 3, x: 33}
26 -
27 description: "FindOneAndUpdate when many documents match returning the document after modification"
28 operation:
29 name: findOneAndUpdate
30 arguments:
31 filter:
32 _id: {$gt: 1}
33 update:
34 $inc: {x: 1}
35 projection: {x: 1, _id: 0}
36 returnDocument: After
37 sort: {x: 1}
38
39 outcome:
40 result: {x: 23}
41 collection:
42 data:
43 - {_id: 1, x: 11}
44 - {_id: 2, x: 23}
45 - {_id: 3, x: 33}
46 -
47 description: "FindOneAndUpdate when one document matches returning the document before modification"
48 operation:
49 name: findOneAndUpdate
50 arguments:
51 filter: {_id: 2}
52 update:
53 $inc: {x: 1}
54 projection: {x: 1, _id: 0}
55 sort: {x: 1}
56
57 outcome:
58 result: {x: 22}
59 collection:
60 data:
61 - {_id: 1, x: 11}
62 - {_id: 2, x: 23}
63 - {_id: 3, x: 33}
64 -
65 description: "FindOneAndUpdate when one document matches returning the document after modification"
66 operation:
67 name: findOneAndUpdate
68 arguments:
69 filter: {_id: 2}
70 update:
71 $inc: {x: 1}
72 projection: {x: 1, _id: 0}
73 returnDocument: After
74 sort: {x: 1}
75
76 outcome:
77 result: {x: 23}
78 collection:
79 data:
80 - {_id: 1, x: 11}
81 - {_id: 2, x: 23}
82 - {_id: 3, x: 33}
83 -
84 description: "FindOneAndUpdate when no documents match returning the document before modification"
85 operation:
86 name: findOneAndUpdate
87 arguments:
88 filter: {_id: 4}
89 update:
90 $inc: {x: 1}
91 projection: {x: 1, _id: 0}
92 sort: {x: 1}
93
94 outcome:
95 result: null
96 collection:
97 data:
98 - {_id: 1, x: 11}
99 - {_id: 2, x: 22}
100 - {_id: 3, x: 33}
101 -
102 description: "FindOneAndUpdate when no documents match with upsert returning the document before modification"
103 operation:
104 name: findOneAndUpdate
105 arguments:
106 filter: {_id: 4}
107 update:
108 $inc: {x: 1}
109 projection: {x: 1, _id: 0}
110 # Omit the sort option as it has no effect when no documents
111 # match and would only cause an inconsistent return value on
112 # pre-3.0 servers when combined with returnDocument "before"
113 # (see: SERVER-17650).
114 upsert: true
115
116 outcome:
117 result: null
118 collection:
119 data:
120 - {_id: 1, x: 11}
121 - {_id: 2, x: 22}
122 - {_id: 3, x: 33}
123 - {_id: 4, x: 1}
124 -
125 description: "FindOneAndUpdate when no documents match returning the document after modification"
126 operation:
127 name: findOneAndUpdate
128 arguments:
129 filter: {_id: 4}
130 update:
131 $inc: {x: 1}
132 projection: {x: 1, _id: 0}
133 returnDocument: After
134 sort: {x: 1}
135
136 outcome:
137 result: null
138 collection:
139 data:
140 - {_id: 1, x: 11}
141 - {_id: 2, x: 22}
142 - {_id: 3, x: 33}
143 -
144 description: "FindOneAndUpdate when no documents match with upsert returning the document after modification"
145 operation:
146 name: findOneAndUpdate
147 arguments:
148 filter: {_id: 4}
149 update:
150 $inc: {x: 1}
151 projection: {x: 1, _id: 0}
152 returnDocument: After
153 sort: {x: 1}
154 upsert: true
155
156 outcome:
157 result: {x: 1}
158 collection:
159 data:
160 - {_id: 1, x: 11}
161 - {_id: 2, x: 22}
162 - {_id: 3, x: 33}
163 - {_id: 4, x: 1}
View as plain text