count() public method

Total count of documents in collection
public count ( ) : integer
return integer
コード例 #1
0
ファイル: DocumentEventTest.php プロジェクト: sokil/php-mongo
 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());
 }
コード例 #2
0
ファイル: CursorTest.php プロジェクト: agolomazov/php-mongo
 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();
 }