Skip to content

Commit 97c54e2

Browse files
Fix getMore with comment specs (#1161)
* DRIVERS-2243 Do not add comment to getMore on <4.4 * DRIVERS-2244 Test getMore comment on all topolgies
1 parent 4a9defd commit 97c54e2

File tree

8 files changed

+482
-26
lines changed

8 files changed

+482
-26
lines changed

source/change-streams/change-streams.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,9 @@ Driver API
418418
* and providing a non-string type will result in a server-side error.
419419
*
420420
* If a comment is provided, drivers MUST attach this comment to all
421-
* subsequent getMore commands run on the same cursor.
421+
* subsequent getMore commands run on the same cursor for server
422+
* versions 4.4 and above. For server versions below 4.4 drivers MUST NOT
423+
* attach a comment to getMore commands.
422424
*
423425
* @see https://docs.mongodb.com/manual/reference/command/aggregate
424426
* @note this is an aggregation command option

source/change-streams/tests/unified/change-streams.json

Lines changed: 95 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,98 @@
254254
{
255255
"minServerVersion": "4.4.0",
256256
"topologies": [
257-
"single",
257+
"replicaset"
258+
]
259+
}
260+
],
261+
"operations": [
262+
{
263+
"name": "createChangeStream",
264+
"object": "collection0",
265+
"arguments": {
266+
"pipeline": [],
267+
"comment": {
268+
"key": "value"
269+
}
270+
},
271+
"saveResultAsEntity": "changeStream0"
272+
},
273+
{
274+
"name": "insertOne",
275+
"object": "collection0",
276+
"arguments": {
277+
"document": {
278+
"_id": 1,
279+
"a": 1
280+
}
281+
}
282+
},
283+
{
284+
"name": "iterateUntilDocumentOrError",
285+
"object": "changeStream0"
286+
}
287+
],
288+
"expectEvents": [
289+
{
290+
"client": "client0",
291+
"events": [
292+
{
293+
"commandStartedEvent": {
294+
"command": {
295+
"aggregate": "collection0",
296+
"pipeline": [
297+
{
298+
"$changeStream": {}
299+
}
300+
],
301+
"comment": {
302+
"key": "value"
303+
}
304+
}
305+
}
306+
},
307+
{
308+
"commandStartedEvent": {
309+
"command": {
310+
"insert": "collection0",
311+
"documents": [
312+
{
313+
"_id": 1,
314+
"a": 1
315+
}
316+
]
317+
}
318+
}
319+
},
320+
{
321+
"commandStartedEvent": {
322+
"command": {
323+
"getMore": {
324+
"$$type": [
325+
"int",
326+
"long"
327+
]
328+
},
329+
"collection": "collection0",
330+
"comment": {
331+
"key": "value"
332+
}
333+
},
334+
"commandName": "getMore",
335+
"databaseName": "database0"
336+
}
337+
}
338+
]
339+
}
340+
]
341+
},
342+
{
343+
"description": "Test that comment is not set on getMore - pre 4.4",
344+
"runOnRequirements": [
345+
{
346+
"minServerVersion": "3.6.0",
347+
"maxServerVersion": "4.3.99",
348+
"topologies": [
258349
"replicaset"
259350
]
260351
}
@@ -324,7 +415,9 @@
324415
]
325416
},
326417
"collection": "collection0",
327-
"comment": "comment"
418+
"comment": {
419+
"$$exists": false
420+
}
328421
},
329422
"commandName": "getMore",
330423
"databaseName": "database0"

source/change-streams/tests/unified/change-streams.yml

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,56 @@ tests:
140140
- description: "Test that comment is set on getMore"
141141
runOnRequirements:
142142
- minServerVersion: "4.4.0"
143-
topologies: [ single, replicaset ]
143+
# Topolgies are limited because of potentially empty getMore responses
144+
# on sharded clusters.
145+
# See https://jira.mongodb.org/browse/DRIVERS-2248 for more details.
146+
topologies: [ replicaset ]
147+
operations:
148+
- name: createChangeStream
149+
object: *collection0
150+
arguments:
151+
pipeline: []
152+
comment: &commentDoc
153+
key: "value"
154+
saveResultAsEntity: &changeStream0 changeStream0
155+
- name: insertOne
156+
object: *collection0
157+
arguments:
158+
document: &new_document
159+
_id: 1
160+
a: 1
161+
- name: iterateUntilDocumentOrError
162+
object: *changeStream0
163+
expectEvents:
164+
- client: *client0
165+
events:
166+
- commandStartedEvent:
167+
command:
168+
aggregate: *collection0
169+
pipeline:
170+
- $changeStream: {}
171+
comment: *commentDoc
172+
- commandStartedEvent:
173+
command:
174+
insert: *collection0
175+
documents:
176+
- *new_document
177+
- commandStartedEvent:
178+
command:
179+
getMore: { $$type: [ int, long ] }
180+
collection: *collection0
181+
comment: *commentDoc
182+
commandName: getMore
183+
databaseName: *database0
184+
185+
- description: "Test that comment is not set on getMore - pre 4.4"
186+
runOnRequirements:
187+
- minServerVersion: "3.6.0"
188+
maxServerVersion: "4.3.99"
189+
# Topolgies are limited because of potentially empty getMore responses
190+
# on sharded clusters.
191+
# See https://jira.mongodb.org/browse/DRIVERS-2248 for more details.
192+
topologies: [ replicaset ]
144193
operations:
145194
- name: createChangeStream
146195
object: *collection0
@@ -174,6 +223,6 @@ tests:
174223
command:
175224
getMore: { $$type: [ int, long ] }
176225
collection: *collection0
177-
comment: "comment"
226+
comment: { $$exists: false }
178227
commandName: getMore
179228
databaseName: *database0

source/crud/crud.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,9 @@ Read
312312
* and providing one will result in a server-side error.
313313
*
314314
* If a comment is provided, drivers MUST attach this comment to all
315-
* subsequent getMore commands run on the same cursor.
315+
* subsequent getMore commands run on the same cursor for server
316+
* versions 4.4 and above. For server versions below 4.4 drivers MUST NOT
317+
* attach a comment to getMore commands.
316318
*/
317319
comment: Optional<any>;
318320
@@ -523,7 +525,9 @@ Read
523525
* and providing a non-string type will result in a server-side error.
524526
*
525527
* If a comment is provided, drivers MUST attach this comment to all
526-
* subsequent getMore commands run on the same cursor.
528+
* subsequent getMore commands run on the same cursor for server
529+
* versions 4.4 and above. For server versions below 4.4 drivers MUST NOT
530+
* attach a comment to getMore commands.
527531
*/
528532
comment: Optional<any>;
529533

source/crud/tests/unified/aggregate.json

Lines changed: 127 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -330,12 +330,129 @@
330330
"description": "aggregate with comment sets comment on getMore",
331331
"runOnRequirements": [
332332
{
333-
"minServerVersion": "4.4.0",
334-
"topologies": [
335-
"single",
336-
"replicaset"
333+
"minServerVersion": "4.4.0"
334+
}
335+
],
336+
"operations": [
337+
{
338+
"name": "aggregate",
339+
"arguments": {
340+
"pipeline": [
341+
{
342+
"$match": {
343+
"_id": {
344+
"$gt": 1
345+
}
346+
}
347+
}
348+
],
349+
"batchSize": 2,
350+
"comment": {
351+
"content": "test"
352+
}
353+
},
354+
"object": "collection0",
355+
"expectResult": [
356+
{
357+
"_id": 2,
358+
"x": 22
359+
},
360+
{
361+
"_id": 3,
362+
"x": 33
363+
},
364+
{
365+
"_id": 4,
366+
"x": 44
367+
},
368+
{
369+
"_id": 5,
370+
"x": 55
371+
},
372+
{
373+
"_id": 6,
374+
"x": 66
375+
}
376+
]
377+
}
378+
],
379+
"expectEvents": [
380+
{
381+
"client": "client0",
382+
"events": [
383+
{
384+
"commandStartedEvent": {
385+
"command": {
386+
"aggregate": "coll0",
387+
"pipeline": [
388+
{
389+
"$match": {
390+
"_id": {
391+
"$gt": 1
392+
}
393+
}
394+
}
395+
],
396+
"cursor": {
397+
"batchSize": 2
398+
},
399+
"comment": {
400+
"content": "test"
401+
}
402+
},
403+
"commandName": "aggregate",
404+
"databaseName": "aggregate-tests"
405+
}
406+
},
407+
{
408+
"commandStartedEvent": {
409+
"command": {
410+
"getMore": {
411+
"$$type": [
412+
"int",
413+
"long"
414+
]
415+
},
416+
"collection": "coll0",
417+
"batchSize": 2,
418+
"comment": {
419+
"content": "test"
420+
}
421+
},
422+
"commandName": "getMore",
423+
"databaseName": "aggregate-tests"
424+
}
425+
},
426+
{
427+
"commandStartedEvent": {
428+
"command": {
429+
"getMore": {
430+
"$$type": [
431+
"int",
432+
"long"
433+
]
434+
},
435+
"collection": "coll0",
436+
"batchSize": 2,
437+
"comment": {
438+
"content": "test"
439+
}
440+
},
441+
"commandName": "getMore",
442+
"databaseName": "aggregate-tests"
443+
}
444+
}
337445
]
338446
}
447+
]
448+
},
449+
{
450+
"description": "aggregate with comment does not set comment on getMore - pre 4.4",
451+
"runOnRequirements": [
452+
{
453+
"minServerVersion": "3.6.0",
454+
"maxServerVersion": "4.3.99"
455+
}
339456
],
340457
"operations": [
341458
{
@@ -415,7 +532,9 @@
415532
},
416533
"collection": "coll0",
417534
"batchSize": 2,
418-
"comment": "comment"
535+
"comment": {
536+
"$$exists": false
537+
}
419538
},
420539
"commandName": "getMore",
421540
"databaseName": "aggregate-tests"
@@ -432,7 +551,9 @@
432551
},
433552
"collection": "coll0",
434553
"batchSize": 2,
435-
"comment": "comment"
554+
"comment": {
555+
"$$exists": false
556+
}
436557
},
437558
"commandName": "getMore",
438559
"databaseName": "aggregate-tests"

0 commit comments

Comments
 (0)