diff --git a/CHANGELOG-1.0.md b/CHANGELOG-1.0.md index ca45dd44..68f4f2c3 100644 --- a/CHANGELOG-1.0.md +++ b/CHANGELOG-1.0.md @@ -6,6 +6,18 @@ This changelog references the relevant changes done in minor version updates. 1.0.2 (????-??-??) ------------------ +All issues and pull requests under this release may be found under the +[1.0.3](https://github.com/alcaeus/mongo-php-adapter/issues?q=milestone%3A1.0.3) +milestone. + + * [#96](https://github.com/alcaeus/mongo-php-adapter/pull/96) fixes errors when + calling `count` on a cursor that has been iterated fully. The fix removes a + performance improvement when calling `count` on a cursor that has been opened. + `MongoCursor::count` now always re-issues a `count` command to the server. + +1.0.2 (2016-04-08) +------------------ + All issues and pull requests under this release may be found under the [1.0.2](https://github.com/alcaeus/mongo-php-adapter/issues?q=milestone%3A1.0.2) milestone. diff --git a/lib/Mongo/MongoCursor.php b/lib/Mongo/MongoCursor.php index b5a6da2d..29b816ac 100644 --- a/lib/Mongo/MongoCursor.php +++ b/lib/Mongo/MongoCursor.php @@ -135,10 +135,6 @@ public function awaitData($wait = true) */ public function count($foundOnly = false) { - if ($foundOnly && $this->cursor !== null) { - return iterator_count($this->ensureIterator()); - } - $optionNames = ['hint', 'maxTimeMS']; if ($foundOnly) { $optionNames = array_merge($optionNames, ['limit', 'skip']); diff --git a/tests/Alcaeus/MongoDbAdapter/Mongo/MongoCursorTest.php b/tests/Alcaeus/MongoDbAdapter/Mongo/MongoCursorTest.php index 1bb02068..b4716bd1 100644 --- a/tests/Alcaeus/MongoDbAdapter/Mongo/MongoCursorTest.php +++ b/tests/Alcaeus/MongoDbAdapter/Mongo/MongoCursorTest.php @@ -60,6 +60,18 @@ public function testCountCannotConnect() $cursor->count(); } + public function testCountAfterIteration() + { + $this->prepareData(); + + $collection = $this->getCollection(); + $cursor = $collection->find(['foo' => 'bar']); + + // Ensure the generator is consumed and thus closed + iterator_to_array($cursor); + $this->assertSame(2, $cursor->count(true)); + } + public function testNextStartsWithFirstItem() { $this->prepareData();