Skip to content

Commit

Permalink
Merge pull request #96 from alcaeus/fix-count-cursor-closed
Browse files Browse the repository at this point in the history
Fix error when counting a closed cursor
  • Loading branch information
alcaeus committed Apr 12, 2016
2 parents 8ff73f3 + 124a4a7 commit 83f69d3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG-1.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 0 additions & 4 deletions lib/Mongo/MongoCursor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down
12 changes: 12 additions & 0 deletions tests/Alcaeus/MongoDbAdapter/Mongo/MongoCursorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 83f69d3

Please sign in to comment.