Skip to content

Commit f737781

Browse files
refactor code logic from FindOptions to FindOperation
1 parent 84a175b commit f737781

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

driver-core/src/main/com/mongodb/internal/client/model/FindOptions.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,7 @@ public FindOptions maxAwaitTime(final long maxAwaitTime, final TimeUnit timeUnit
215215
* @mongodb.driver.manual reference/method/cursor.batchSize/#cursor.batchSize Batch Size
216216
*/
217217
public int getBatchSize() {
218-
return batchSize > 0 && batchSize == limit
219-
? batchSize + 1 // avoid an open cursor on server side when batchSize and limit are equal
220-
: batchSize;
218+
return batchSize;
221219
}
222220

223221
/**

driver-core/src/main/com/mongodb/internal/operation/FindOperation.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,12 @@ private BsonDocument getCommand(final OperationContext operationContext, final i
390390
if (batchSize < 0 && Math.abs(batchSize) < limit) {
391391
commandDocument.put("limit", new BsonInt32(Math.abs(batchSize)));
392392
} else if (batchSize != 0) {
393-
commandDocument.put("batchSize", new BsonInt32(Math.abs(batchSize)));
393+
int effectiveBatchSize = Math.abs(batchSize);
394+
if (effectiveBatchSize == limit) {
395+
// avoid an open cursor on server side when batchSize and limit are equal
396+
effectiveBatchSize++;
397+
}
398+
commandDocument.put("batchSize", new BsonInt32(effectiveBatchSize));
394399
}
395400
}
396401
if (limit < 0 || batchSize < 0) {

0 commit comments

Comments
 (0)