Uploaded image for project: 'PHP Driver: Library'
  1. PHP Driver: Library
  2. PHPLIB-1167

Fix CachingIterator::count() on empty Cursor

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 1.16.1, 1.17.0
    • Affects Version/s: None
    • Component/s: None
    • None

      Reproducer:

       

      <?php
      
      require __DIR__ . '/vendor/autoload.php';
      
      $client = new MongoDB\Client('mongodb://localhost:27070/?replicaSet=rs0');
      $collection = $client->test->foo;
      $collection->drop();
      
      $it = new MongoDB\Model\CachingIterator($collection->find());
      
      var_dump($it);
      var_dump($it->count()); 

       

      Result :

       

      MongoDB\Driver\Exception\RuntimeException : Cannot advance a completed or failed cursor. 
      

      Expected : no error, the var_dump returns 0

       

            Assignee:
            jerome.tamarelle@mongodb.com Jérôme Tamarelle
            Reporter:
            jerome.tamarelle@mongodb.com Jérôme Tamarelle
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: