重要
mongosh 方法
This page documents a mongosh method. This is not the documentation for database commands or language-specific drivers, such as Node.js.
对于数据库命令,请参阅 collStats 命令返回的字段。
如需了解 MongoDB API 驱动程序,请参阅特定语言的 MongoDB 驱动程序文档。
定义
db.collection.totalSize()返回: 集合中数据的总大小(以字节为单位)加上集合上每个索引的大小。
如果集合数据经过压缩(即
default for WiredTiger),返回的大小将反映集合数据的压缩大小。如果索引使用前缀压缩(即
default for WiredTiger),返回的大小将反映压缩后的索引大小。返回的值是
db.collection.storageSize()和db.collection.totalIndexSize()的总和(以字节为单位)。要在副本集成员上运行,
collStats操作需要成员处于PRIMARY或SECONDARY状态。如果节点处于其他状态,如STARTUP2,则操作错误。
兼容性
此方法可用于以下环境中托管的部署:
- MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud
注意
This command is supported in all MongoDB Atlas clusters. For information on Atlas support for all commands, see Unsupported Commands.
MongoDB Enterprise:基于订阅、自我管理的 MongoDB 版本
MongoDB Community:源代码可用、免费使用且可自行管理的 MongoDB 版本