count() public method

Total count of documents in collection
public count ( ) : integer
return integer
Example #1
0
 public function testCancelOperation_BeforeDelete()
 {
     $document = $this->collection->delete()->createDocument(array('field' => 'value'))->save()->onBeforeDelete(function (\Sokil\Mongo\Event $event, $eventName, $dispatcher) {
         $event->cancel();
     })->delete();
     $this->assertEquals(1, $this->collection->count());
 }
Example #2
0
 public function testMoveToCollection()
 {
     $targetCollectionName = 'targetMoveCollection';
     $targetCollection = $this->collection->getDatabase()->getCollection($targetCollectionName)->delete();
     // fill collection with documents
     for ($i = 0; $i < 200; $i++) {
         $this->collection->createDocument(array('i' => $i))->save();
     }
     $this->collection->find()->whereMod('i', 2, 0)->moveToCollection($targetCollectionName);
     // check source collection
     $this->assertEquals(100, $this->collection->count());
     foreach ($this->collection->find() as $document) {
         $this->assertEquals(1, $document->i % 2);
     }
     // check target collection
     $this->assertEquals(100, $targetCollection->count());
     foreach ($targetCollection->find() as $document) {
         $this->assertEquals(0, $document->i % 2);
     }
     // clear
     $targetCollection->delete();
 }