对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。
Docs 菜单

dataSize(数据库命令)

dataSize

The dataSize command 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.

该命令具有以下语法:

db.runCommand(
{
dataSize: <string>,
keyPattern: <document>,
min: <document>,
max: <document>,
estimate: <boolean>
}
)

该命令接受以下字段:

字段
类型
说明

dataSize

字符串

目标集合的名称。

keyPattern

文档

可选。要检查的集合键模式。

The collection must have an index with the corresponding pattern. Otherwise dataSize returns an error message.

min

文档

可选。要检查的键范围的下限。

max

文档

可选。要检查的键范围的上限。

estimate

布尔

Optional. When true, dataSize estimates the data size by assuming that all documents in the specified range are uniformly sized as per the collection's average object size. The collection's average object size is obtained from the avgObjSize field in the output of the collStats command.

默认值为 false。

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.

给本页内容打分