Definition定义
dataSizeThedataSizecommand returns the size in bytes for the specified data.dataSize命令返回指定数据的大小(以字节为单位)。
Compatibility兼容性
This command is available in deployments hosted in the following environments:此命令在以下环境中托管的部署中可用:
- MongoDB Atlas
: The fully managed service for MongoDB deployments in the cloud:云中MongoDB部署的完全托管服务
Important
This command is not supported in M0 and Flex clusters. For more information, see Unsupported Commands.M0和Flex集群不支持此命令。有关详细信息,请参阅不支持的命令。
- 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的源代码可用、免费使用和自我管理版本
Syntax语法
The command has the following syntax:该命令具有以下语法:
db.runCommand(
{
dataSize: <string>,
keyPattern: <document>,
min: <document>,
max: <document>,
estimate: <boolean>
}
)Command Fields命令字段
The command takes the following fields:该命令包含以下字段:
dataSize | ||
keyPattern |
| |
min | ||
max | ||
estimate |
|
Example示例
The following operation runs the 以下操作在dataSize command on the database.collection collection, specifying a key pattern of {field: 1} with the lower bound of the range of keys to be examined being {field: 10} and the upper bound of the key to be examined being {field: 100}.database.collection集合上运行dataSize命令,指定键模式为{field: 1},要检查的键范围的下限为{field: 10},要检测的键的上限为{field: 100}。
db.runCommand({ dataSize: "database.collection", keyPattern: { field: 1 }, min: { field: 10 }, max: { field: 100 } })
This returns a document with the size in bytes for all matching documents. Replace 这将返回一个文档,其中包含所有匹配文档的大小(以字节为单位)。用部署中的数据库和集合替换database.collection with the database and collection from your deployment.database.collection。
The amount of time required to return 返回dataSize depends on the amount of data in the collection.dataSize所需的时间取决于集合中的数据量。