Skip to content

Commit 10cbc15

Browse files
committed
JAVA-2566: Include empty cursor document in AggregateToCollectionOperation when connected to a 3.6 MongoDB server
1 parent 45a7f58 commit 10cbc15

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

driver-core/src/main/com/mongodb/operation/AggregateToCollectionOperation.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import static com.mongodb.operation.OperationHelper.AsyncCallableWithConnection;
4343
import static com.mongodb.operation.OperationHelper.CallableWithConnection;
4444
import static com.mongodb.operation.OperationHelper.LOGGER;
45+
import static com.mongodb.operation.OperationHelper.serverIsAtLeastVersionThreeDotSix;
4546
import static com.mongodb.operation.OperationHelper.validateCollation;
4647
import static com.mongodb.operation.OperationHelper.releasingCallback;
4748
import static com.mongodb.operation.OperationHelper.serverIsAtLeastVersionThreeDotTwo;
@@ -270,6 +271,11 @@ private BsonDocument getCommand(final ConnectionDescription description) {
270271
if (bypassDocumentValidation != null && serverIsAtLeastVersionThreeDotTwo(description)) {
271272
commandDocument.put("bypassDocumentValidation", BsonBoolean.valueOf(bypassDocumentValidation));
272273
}
274+
275+
if (serverIsAtLeastVersionThreeDotSix(description)) {
276+
commandDocument.put("cursor", new BsonDocument());
277+
}
278+
273279
appendWriteConcernToCommand(writeConcern, commandDocument, description);
274280
if (collation != null) {
275281
commandDocument.put("collation", collation.asDocument());

driver-core/src/main/com/mongodb/operation/OperationHelper.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,10 @@ static boolean serverIsAtLeastVersionThreeDotFour(final ConnectionDescription de
385385
return serverIsAtLeastVersion(description, new ServerVersion(3, 4));
386386
}
387387

388+
static boolean serverIsAtLeastVersionThreeDotSix(final ConnectionDescription description) {
389+
return serverIsAtLeastVersion(description, new ServerVersion(3, 5));
390+
}
391+
388392
static boolean serverIsAtLeastVersion(final ConnectionDescription description, final ServerVersion serverVersion) {
389393
return description.getServerVersion().compareTo(serverVersion) >= 0;
390394
}

driver-core/src/test/functional/com/mongodb/operation/AggregateToCollectionOperationSpecification.groovy

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -233,18 +233,23 @@ class AggregateToCollectionOperationSpecification extends OperationFunctionalSpe
233233
operation.collation(defaultCollation)
234234
expectedCommand.append('collation', defaultCollation.asDocument())
235235
}
236+
if (useCursor) {
237+
expectedCommand.append('cursor', new BsonDocument())
238+
}
236239

237240
then:
238241
testOperation(operation, serverVersion, expectedCommand, false, BsonDocument.parse('{ok: 1}'))
239242

240243
where:
241-
serverVersion | includeBypassValidation | includeWriteConcern | includeCollation | async
242-
[3, 4, 0] | true | true | true | true
243-
[3, 4, 0] | true | true | true | false
244-
[3, 2, 0] | true | false | false | true
245-
[3, 2, 0] | true | false | false | false
246-
[3, 0, 0] | false | false | false | true
247-
[3, 0, 0] | false | false | false | false
244+
serverVersion | includeBypassValidation | includeWriteConcern | includeCollation | async | useCursor
245+
[3, 6, 0] | true | true | true | true | true
246+
[3, 6, 0] | true | true | true | false | true
247+
[3, 4, 0] | true | true | true | true | false
248+
[3, 4, 0] | true | true | true | false | false
249+
[3, 2, 0] | true | false | false | true | false
250+
[3, 2, 0] | true | false | false | false | false
251+
[3, 0, 0] | false | false | false | true | false
252+
[3, 0, 0] | false | false | false | false | false
248253

249254
}
250255

0 commit comments

Comments
 (0)