Skip to content

Commit 4407172

Browse files
committed
PHPLIB-1564: Increase batchSize for find when it's equal to limit
1 parent 8946e5d commit 4407172

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/Operation/Find.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
use MongoDB\Exception\UnsupportedException;
3131
use MongoDB\Model\CodecCursor;
3232

33+
use function assert;
3334
use function is_array;
3435
use function is_bool;
3536
use function is_integer;
@@ -418,6 +419,12 @@ private function createQueryOptions(): array
418419
$options['modifiers'] = is_object($modifiers) ? document_to_array($modifiers) : $modifiers;
419420
}
420421

422+
// Ensure no cursor is left behind when limit == batchSize by increasing batchSize
423+
if (isset($options['limit'], $options['batchSize']) && $options['limit'] === $options['batchSize']) {
424+
assert(is_integer($options['batchSize']));
425+
$options['batchSize']++;
426+
}
427+
421428
return $options;
422429
}
423430
}

0 commit comments

Comments
 (0)