...
1description: "CRUD Api Version 1 (strict)"
2
3schemaVersion: "1.4"
4
5runOnRequirements:
6 - minServerVersion: "4.9"
7
8createEntities:
9 - client:
10 id: &client client
11 observeEvents:
12 - commandStartedEvent
13 serverApi:
14 version: "1"
15 strict: true
16 - database:
17 id: &database database
18 client: *client
19 databaseName: &databaseName versioned-api-tests
20 - database:
21 id: &adminDatabase adminDatabase
22 client: *client
23 databaseName: &adminDatabaseName admin
24 - collection:
25 id: &collection collection
26 database: *database
27 collectionName: &collectionName test
28
29_yamlAnchors:
30 versions:
31 - &expectedApiVersion
32 apiVersion: "1"
33 apiStrict: true
34 apiDeprecationErrors: { $$unsetOrMatches: false }
35
36initialData:
37 - collectionName: *collectionName
38 databaseName: *databaseName
39 documents:
40 - { _id: 1, x: 11 }
41 - { _id: 2, x: 22 }
42 - { _id: 3, x: 33 }
43 - { _id: 4, x: 44 }
44 - { _id: 5, x: 55 }
45
46tests:
47 - description: "aggregate on collection appends declared API version"
48 operations:
49 - name: aggregate
50 object: *collection
51 arguments:
52 pipeline: &pipeline
53 - $sort: { x : 1 }
54 - $match: { _id: { $gt: 1 } }
55 expectEvents:
56 - client: *client
57 events:
58 - commandStartedEvent:
59 command:
60 aggregate: *collectionName
61 pipeline: *pipeline
62 <<: *expectedApiVersion
63
64 - description: "aggregate on database appends declared API version"
65 runOnRequirements:
66 # serverless does not support either of the current database-level aggregation stages ($listLocalSessions and
67 # $currentOp)
68 - serverless: "forbid"
69 operations:
70 - name: aggregate
71 object: *adminDatabase
72 arguments:
73 pipeline: &pipeline
74 - $listLocalSessions: {}
75 - $limit: 1
76 expectError:
77 errorCodeName: "APIStrictError"
78 expectEvents:
79 - client: *client
80 events:
81 - commandStartedEvent:
82 command:
83 aggregate: 1
84 pipeline: *pipeline
85 <<: *expectedApiVersion
86
87 - description: "bulkWrite appends declared API version"
88 operations:
89 - name: bulkWrite
90 object: *collection
91 arguments:
92 requests:
93 - insertOne:
94 document: { _id: 6, x: 66 }
95 - updateOne:
96 filter: { _id: 2 }
97 update: { $inc: { x: 1 } }
98 - deleteMany:
99 filter: { x: { $nin: [ 24, 34 ] } }
100 - updateMany:
101 filter: { _id: { $gt: 1 } }
102 update: { $inc: { x: 1 } }
103 - deleteOne:
104 filter: { _id: 7 }
105 - replaceOne:
106 filter: { _id: 4 }
107 replacement: { _id: 4, x: 44 }
108 upsert: true
109 ordered: true
110 expectEvents:
111 - client: *client
112 events:
113 - commandStartedEvent:
114 command:
115 insert: *collectionName
116 documents:
117 - { _id: 6, x: 66 }
118 <<: *expectedApiVersion
119 - commandStartedEvent:
120 command:
121 update: *collectionName
122 updates:
123 - q: { _id: 2 }
124 u: { $inc: { x: 1 } }
125 multi: { $$unsetOrMatches: false }
126 upsert: { $$unsetOrMatches: false }
127 <<: *expectedApiVersion
128 - commandStartedEvent:
129 command:
130 delete: *collectionName
131 deletes:
132 - { q: { x: { $nin: [ 24, 34 ] } }, limit: 0 }
133 <<: *expectedApiVersion
134 - commandStartedEvent:
135 command:
136 update: *collectionName
137 updates:
138 - q: { _id: { $gt: 1 } }
139 u: { $inc: { x: 1 } }
140 multi: true
141 upsert: { $$unsetOrMatches: false }
142 <<: *expectedApiVersion
143 - commandStartedEvent:
144 command:
145 delete: *collectionName
146 deletes:
147 - { q: { _id: 7 }, limit: 1 }
148 <<: *expectedApiVersion
149 - commandStartedEvent:
150 command:
151 update: *collectionName
152 updates:
153 - q: { _id: 4 }
154 u: { _id: 4, x: 44 }
155 multi: { $$unsetOrMatches: false }
156 upsert: true
157 <<: *expectedApiVersion
158
159 - description: "countDocuments appends declared API version"
160 operations:
161 - name: countDocuments
162 object: *collection
163 arguments:
164 filter: &filter
165 x : { $gt: 11 }
166 expectEvents:
167 - client: *client
168 events:
169 - commandStartedEvent:
170 command:
171 aggregate: *collectionName
172 pipeline:
173 - { $match: *filter }
174 - { $group: { _id: 1, n: { $sum: 1 } } }
175 <<: *expectedApiVersion
176
177 - description: "deleteMany appends declared API version"
178 operations:
179 - name: deleteMany
180 object: *collection
181 arguments:
182 filter: { x: { $nin: [ 24, 34 ] } }
183 expectEvents:
184 - client: *client
185 events:
186 - commandStartedEvent:
187 command:
188 delete: *collectionName
189 deletes:
190 - { q: { x: { $nin: [ 24, 34 ] } }, limit: 0 }
191 <<: *expectedApiVersion
192
193 - description: "deleteOne appends declared API version"
194 operations:
195 - name: deleteOne
196 object: *collection
197 arguments:
198 filter: { _id: 7 }
199 expectEvents:
200 - client: *client
201 events:
202 - commandStartedEvent:
203 command:
204 delete: *collectionName
205 deletes:
206 - { q: { _id: 7 }, limit: 1 }
207 <<: *expectedApiVersion
208
209 # distinct will fail until drivers replace it with an alternative
210 # implementation
211 - description: "distinct appends declared API version"
212 operations:
213 - name: distinct
214 object: *collection
215 arguments:
216 fieldName: x
217 filter: {}
218 expectError:
219 isError: true
220 errorContains: "command distinct is not in API Version 1"
221 errorCodeName: "APIStrictError"
222 expectEvents:
223 - client: *client
224 events:
225 - commandStartedEvent:
226 command:
227 distinct: *collectionName
228 key: x
229 <<: *expectedApiVersion
230
231 - description: "estimatedDocumentCount appends declared API version"
232 # See: https://jira.mongodb.org/browse/SERVER-63850
233 runOnRequirements:
234 - minServerVersion: "5.0.9"
235 maxServerVersion: "5.0.99"
236 - minServerVersion: "5.3.2"
237 operations:
238 - name: estimatedDocumentCount
239 object: *collection
240 arguments: {}
241 expectEvents:
242 - client: *client
243 events:
244 - commandStartedEvent:
245 command:
246 count: *collectionName
247 <<: *expectedApiVersion
248
249 - description: "find and getMore append API version"
250 operations:
251 - name: find
252 object: *collection
253 arguments:
254 filter: {}
255 sort: { _id: 1 }
256 batchSize: 3
257 expectResult:
258 - { _id: 1, x: 11 }
259 - { _id: 2, x: 22 }
260 - { _id: 3, x: 33 }
261 - { _id: 4, x: 44 }
262 - { _id: 5, x: 55 }
263 expectEvents:
264 - client: *client
265 events:
266 - commandStartedEvent:
267 command:
268 find: *collectionName
269 <<: *expectedApiVersion
270 - commandStartedEvent:
271 command:
272 getMore: { $$type: [ int, long ] }
273 <<: *expectedApiVersion
274
275 - description: "findOneAndDelete appends declared API version"
276 operations:
277 - name: findOneAndDelete
278 object: *collection
279 arguments:
280 filter: &filter { _id: 1 }
281 expectEvents:
282 - client: *client
283 events:
284 - commandStartedEvent:
285 command:
286 findAndModify: *collectionName
287 query: *filter
288 remove: true
289 <<: *expectedApiVersion
290
291 - description: "findOneAndReplace appends declared API version"
292 operations:
293 - name: findOneAndReplace
294 object: *collection
295 arguments:
296 filter: &filter { _id: 1 }
297 replacement: &replacement { x: 33 }
298 expectEvents:
299 - client: *client
300 events:
301 - commandStartedEvent:
302 command:
303 findAndModify: *collectionName
304 query: *filter
305 update: *replacement
306 <<: *expectedApiVersion
307
308 - description: "findOneAndUpdate appends declared API version"
309 operations:
310 - name: findOneAndUpdate
311 object: collection
312 arguments:
313 filter: &filter { _id: 1 }
314 update: &update { $inc: { x: 1 } }
315 expectEvents:
316 - client: *client
317 events:
318 - commandStartedEvent:
319 command:
320 findAndModify: *collectionName
321 query: *filter
322 update: *update
323 <<: *expectedApiVersion
324
325 - description: "insertMany appends declared API version"
326 operations:
327 - name: insertMany
328 object: *collection
329 arguments:
330 documents:
331 - { _id: 6, x: 66 }
332 - { _id: 7, x: 77 }
333 expectEvents:
334 - client: *client
335 events:
336 - commandStartedEvent:
337 command:
338 insert: *collectionName
339 documents:
340 - { _id: 6, x: 66 }
341 - { _id: 7, x: 77 }
342 <<: *expectedApiVersion
343
344 - description: "insertOne appends declared API version"
345 operations:
346 - name: insertOne
347 object: *collection
348 arguments:
349 document: { _id: 6, x: 66 }
350 expectEvents:
351 - client: *client
352 events:
353 - commandStartedEvent:
354 command:
355 insert: *collectionName
356 documents:
357 - { _id: 6, x: 66 }
358 <<: *expectedApiVersion
359
360 - description: "replaceOne appends declared API version"
361 operations:
362 - name: replaceOne
363 object: *collection
364 arguments:
365 filter: { _id: 4 }
366 replacement: { _id: 4, x: 44 }
367 upsert: true
368 expectEvents:
369 - client: *client
370 events:
371 - commandStartedEvent:
372 command:
373 update: *collectionName
374 updates:
375 - q: { _id: 4 }
376 u: { _id: 4, x: 44 }
377 multi: { $$unsetOrMatches: false }
378 upsert: true
379 <<: *expectedApiVersion
380
381 - description: "updateMany appends declared API version"
382 operations:
383 - name: updateMany
384 object: *collection
385 arguments:
386 filter: { _id: { $gt: 1 } }
387 update: { $inc: { x: 1 } }
388 expectEvents:
389 - client: *client
390 events:
391 - commandStartedEvent:
392 command:
393 update: *collectionName
394 updates:
395 - q: { _id: { $gt: 1 } }
396 u: { $inc: { x: 1 } }
397 multi: true
398 upsert: { $$unsetOrMatches: false }
399 <<: *expectedApiVersion
400
401 - description: "updateOne appends declared API version"
402 operations:
403 - name: updateOne
404 object: *collection
405 arguments:
406 filter: { _id: 2 }
407 update: { $inc: { x: 1 } }
408 expectEvents:
409 - client: *client
410 events:
411 - commandStartedEvent:
412 command:
413 update: *collectionName
414 updates:
415 - q: { _id: 2 }
416 u: { $inc: { x: 1 } }
417 multi: { $$unsetOrMatches: false }
418 upsert: { $$unsetOrMatches: false }
419 <<: *expectedApiVersion
View as plain text