From 1074e23e23dc395238de55f2b952626128a277f2 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 22 Nov 2024 11:25:44 -0500 Subject: [PATCH] PHPLIB-1563 and PHPLIB-1564: batchSize and singleBatch fixes for find operations * PHPLIB-1564: Increase batchSize for find when it's equal to limit * PHPLIB-1563: set singleBatch option for findOne * Bump tests/specifications from `a32d445` to `11022ca` Bumps [tests/specifications](https://github.com/mongodb/specifications) from `a32d445` to `11022ca`. - [Release notes](https://github.com/mongodb/specifications/releases) - [Commits](https://github.com/mongodb/specifications/compare/a32d4453a7abcf7cd5cf3ddde99b60a31fba07b3...11022ca4f21377f00827918ebbdf5ea3dbdb7d4a) --- updated-dependencies: - dependency-name: tests/specifications dependency-type: direct:production ... Signed-off-by: dependabot[bot] --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Andreas Braun --- src/Operation/Find.php | 11 +++++++++++ tests/specifications | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Operation/Find.php b/src/Operation/Find.php index 52c43c525..6516d52c9 100644 --- a/src/Operation/Find.php +++ b/src/Operation/Find.php @@ -30,6 +30,7 @@ use MongoDB\Exception\UnsupportedException; use MongoDB\Model\CodecCursor; +use function assert; use function is_array; use function is_bool; use function is_integer; @@ -418,6 +419,16 @@ private function createQueryOptions(): array $options['modifiers'] = is_object($modifiers) ? document_to_array($modifiers) : $modifiers; } + // Ensure no cursor is left behind when limit == batchSize by increasing batchSize + if (isset($options['limit'], $options['batchSize']) && $options['limit'] === $options['batchSize']) { + assert(is_integer($options['batchSize'])); + $options['batchSize']++; + } + + if (isset($options['limit']) && $options['limit'] === 1) { + $options['singleBatch'] = true; + } + return $options; } } diff --git a/tests/specifications b/tests/specifications index a32d4453a..11022ca4f 160000 --- a/tests/specifications +++ b/tests/specifications @@ -1 +1 @@ -Subproject commit a32d4453a7abcf7cd5cf3ddde99b60a31fba07b3 +Subproject commit 11022ca4f21377f00827918ebbdf5ea3dbdb7d4a