For AI agents: a documentation index is available at https://www.mongodb.com/pt-br/docs/llms.txt — markdown versions of all pages are available by appending .md to any URL path.
Make the MongoDB docs better! We value your opinion. Share your feedback for a chance to win $100.
MongoDB Branding Shape
Click here >
Docs Menu

MongoDB\Model\CollectionInfo::getCappedSize()

Deprecated since version 1.9. :

MongoDB\Model\CollectionInfo::getCappedSize()

Return the size limit for the capped collection in bytes. This correlates with the size option for MongoDB\Database::createCollection().

function getCappedSize(): integer|null

The size limit for the capped collection in bytes. If the collection is not capped, null will be returned.

This method is deprecated in favor of using MongoDB\Model\CollectionInfo::getOptions() and accessing the size key.

<?php
$db = (new MongoDB\Client)->test;
// Creates a capped collection with a size of 1048576
$db->createCollection(
'myCappedCollection',
['capped' => true, 'size' => 1048576]
);
// Retrieves the size limit for the capped collection
foreach ($db->listCollections(['filter' => ['name' => 'myCappedCollection']]) as $info) {
var_dump($info->getCappedSize());
}

The output would then resemble:

int(1048576)