定义
dataSizeThe
dataSizecommand returns the size in bytes for the specified data.
兼容性
此命令可用于以下环境中托管的部署:
- MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud
重要
This command is not supported in M0 and Flex clusters. For more information, see Unsupported Commands.
MongoDB Enterprise:基于订阅、自我管理的 MongoDB 版本
MongoDB Community:源代码可用、免费使用且可自行管理的 MongoDB 版本
语法
该命令具有以下语法:
db.runCommand( { dataSize: <string>, keyPattern: <document>, min: <document>, max: <document>, estimate: <boolean> } )
命令字段
该命令接受以下字段:
字段 | 类型 | 说明 |
|---|---|---|
| 字符串 | 目标集合的名称。 |
| 文档 | 可选。要检查的集合键模式。 The collection must have an index with the corresponding pattern. Otherwise |
| 文档 | 可选。要检查的键范围的下限。 |
| 文档 | 可选。要检查的键范围的上限。 |
| 布尔 |
例子
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}.
db.runCommand({ dataSize: "database.collection", keyPattern: { field: 1 }, min: { field: 10 }, max: { field: 100 } })
这将返回一个文档,其中包含所有匹配文档的大小(以字节为单位)。将 database.collection 替换为部署中的数据库和集合。
The amount of time required to return dataSize depends on the amount of data in the collection.