Sokil\Mongo\Database::createCappedCollection PHP Method

createCappedCollection() public method

public createCappedCollection ( string $name, integer $maxElements, integer $size ) : Collection
$name string name of collection
$maxElements integer The maximum number of elements to store in the collection.
$size integer Size in bytes.
return Collection
    public function createCappedCollection($name, $maxElements, $size)
    {
        $options = array('capped' => true, 'size' => (int) $size, 'max' => (int) $maxElements);
        if (!$options['size'] && !$options['max']) {
            throw new Exception('Size or number of elements must be defined');
        }
        return $this->createCollection($name, $options);
    }

Usage Example

Example #1
0
 public function testCappedCollectionInsert()
 {
     $this->collection = $this->database->createCappedCollection('capped_collection', 3, 30);
     $this->collection->createDocument(array('param' => 1))->save();
     $this->collection->createDocument(array('param' => 2))->save();
     $this->collection->createDocument(array('param' => 3))->save();
     $this->collection->createDocument(array('param' => 4))->save();
     $this->assertEquals(3, $this->collection->find()->count());
     $documents = $this->collection->find();
     $this->assertEquals(2, $documents->current()->param);
     $documents->next();
     $this->assertEquals(3, $documents->current()->param);
     $documents->next();
     $this->assertEquals(4, $documents->current()->param);
     $this->collection->delete();
 }
All Usage Examples Of Sokil\Mongo\Database::createCappedCollection