PHP MongoDB Collection Size

one text

Solution:

Using aggregations with the $collStats stage you can get the collection size.

Example:

$pipeline = [
    [
        '$collStats' => [
            'storageStats' =>
                ['scale' => 1024]
        ]
    ]
];
$storageStats = $collection->aggregate($pipeline)->toArray();
var_dump($storageStats);

Source