Docs Menu

dataSize

dataSize

The dataSize command returns the size in bytes for the specified data.

このコマンドは、次の環境でホストされている配置で使用できます。

  • MongoDB Atlas はクラウドでの MongoDB 配置のためのフルマネージド サービスです

重要

このコマンドは、M0、M2、M5、および Flex クラスターではサポートされていません。詳細については、「 サポートされていないコマンド 」を参照してください。

  • MongoDB Enterprise: サブスクリプションベースの自己管理型 MongoDB バージョン

  • MongoDB Community: ソースが利用可能で、無料で使用できる自己管理型の MongoDB のバージョン

このコマンドの構文は、次のとおりです。

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

このコマンドは、次のフィールドを使用します。

フィールド
タイプ
説明

dataSize

string

ターゲット コレクションの名前。

keyPattern

ドキュメント

Optional. The collection's key pattern to examine.

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

min

ドキュメント

Optional. The lower bound of the key range to be examined.

max

ドキュメント

Optional. The upper bound of the key range to be examined.

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.

Defaults to 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 } })

This returns a document with the size in bytes for all matching documents. Replace database.collection with the database and collection from your deployment.

The amount of time required to return dataSize depends on the amount of data in the collection.