简体   繁体   English

PHP MongoDB 集合大小

[英]PHP MongoDB Collection Size

I am using the PHP MongoDB Library v1.6 and I want to be able to get the size of a specific collection.我正在使用 PHP MongoDB Library v1.6,我希望能够获得特定集合的大小。 I have looked at the documentation of the library and didn't see anything that would return the size.我查看了的文档,没有看到任何会返回大小的东西。 Is this possible with this library?这个库有可能吗? If so could someone provide some insight on how to achieve this.如果是这样,有人可以就如何实现这一目标提供一些见解。

This is how I would do it from the mongo shell:这就是我从 mongo shell 做的事情:

db.collection.dataSize()

Using aggregations with the $collStats stage you can get the collection size.使用$collStats阶段的聚合,您可以获得集合大小。

Example:例子:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM