Database Manual / Reference / mongosh Methods / Collections

db.collection.totalSize() (mongosh method方法)

db.collection.totalSize()

Important

mongosh Method方法

This page documents a mongosh method. This is not the documentation for database commands or language-specific drivers, such as Node.js.本页记录了一种mongosh方法。这不是数据库命令或特定语言驱动程序(如Node.js)的文档。

For the database command, see the totalSize field returned by the collStats command.对于数据库命令,请参阅collStats命令返回的totalSize字段。

For MongoDB API drivers, refer to the language-specific MongoDB driver documentation.有关MongoDB API驱动程序,请参阅特定语言的MongoDB驱动程序文档

Returns:返回The total size in bytes of the data in the collection plus the size of every index on the collection.集合中数据的总大小(以字节为单位)加上集合上每个索引的大小。

If collection data is compressed (which is the default for WiredTiger), the returned size reflects the compressed size of the collection data.如果集合数据被压缩(这是WiredTiger的默认值),则返回的大小反映了集合数据的压缩大小。

If an index uses prefix compression (which is the default for WiredTiger), the returned size reflects the compressed size of the index.如果索引使用前缀压缩(这是WiredTiger的默认值),则返回的大小反映了索引的压缩大小。

The value returned is the sum of db.collection.storageSize() and db.collection.totalIndexSize() in bytes.返回的值是db.collection.storageSize()db.collection.totalIndexSize()的总和,单位为字节。

To run on a replica set member, collStats operations require the member to be in PRIMARY or SECONDARY state. 要在副本集成员上运行,collStats操作要求该成员处于PRIMARYSECONDARY状态。If the member is in another state, such as STARTUP2, the operation errors.如果成员处于另一种状态,如STARTUP2,则操作错误。

Compatibility兼容性

This method is available in deployments hosted in the following environments:此方法在以下环境中托管的部署中可用:

  • MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud:云中MongoDB部署的完全托管服务

Note

This command is supported in all MongoDB Atlas clusters. 所有MongoDB Atlas集群都支持此命令。For information on Atlas support for all commands, see Unsupported Commands.有关Atlas支持所有命令的信息,请参阅不支持的命令

  • MongoDB Enterprise: The subscription-based, self-managed version of MongoDB:MongoDB的基于订阅的自我管理版本
  • MongoDB Community: The source-available, free-to-use, and self-managed version of MongoDB:MongoDB的源代码可用、免费使用和自我管理版本