AI エージェント向け: ドキュメントインデックスは https://www.mongodb.com/ja-jp/docs/llms.txt で利用できます。すべてのページの markdown バージョンは、いずれかの URL パスに .md を追加することで利用できます。
Docs Menu

dbStats(データベースコマンド)

dbStats

The dbStats command returns storage statistics for a given database.

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

  • MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud

重要

This command has limited support in M0 and Flex clusters. For more information, see Unsupported Commands.

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

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

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

db.runCommand(
{
dbStats: 1,
scale: <number>,
freeStorage: 0
}
)

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

フィールド
説明

1

任意。 さまざまなサイズ データの増やす ファクター。scaleのデフォルトは 1 で、サイズ データをバイト単位で返します。 バイトではなくキロバイトを表示するには、 scaleの値を1024に指定します。

整数以外のスケール係数を指定した場合、MongoDB は指定された係数の整数部分を使用します。たとえば、スケール係数を 1023.999 に指定すると、MongoDB はスケール係数として 1023 使用します。

バージョン 4.2 以降では、出力にサイズ値を増やすのに使用される scaleFactor が含まれるようになりました。

任意。コレクションに割り当てられた空き領域の詳細を返すには、 freeStorage を「1」に設定します。

If the instance has a large number of collections or indexes, obtaining free space usage data may cause processing delays. To gather dbStats information without free space details, either set freeStorage to 0 or do not include the field.

mongosh では、db.stats() 関数が dbStats のラッパーを提供します。

コマンドの実行に必要な時間は、データベースの合計サイズによって異なります。コマンドはすべてのデータファイルにアクセスする必要があるため、コマンドの実行には数秒かかる場合があります。

After an unclean shutdown of a mongod using the Wired Tiger storage engine, count and size statistics reported by dbStats may be inaccurate.

ドリフトの量は、チェックポイントからクリーン シャットダウンまでの間に実行された挿入、アップデート、または削除操作の数によって異なります。チェックポイントは通常、60 秒ごとに発現します。ただし、デフォルト以外の --syncdelay 設定で実行されている mongod インスタンスでは、チェックポイントの頻度が増減する可能性があります。

不正なシャットダウン後に統計を復元するには、mongod の各コレクションに対して validate を実行します。

不正なシャットダウン後:

To run on a replica set member, dbStats operations require the member to be in PRIMARY or SECONDARY state. If the member is in another state, such as STARTUP2, the operation errors.

dbStats.db

データベースの名前。

dbStats.collections

データベース内のコレクションの数。

dbStats.views

データベース内のビュー数。

dbStats.objects

すべてのコレクションにわたるデータベース内のオブジェクト(具体的には、ドキュメント)の数。

dbStats.avgObjSize

Average size of each document in bytes. This is the dataSize divided by the number of documents. The scale argument does not affect the avgObjSize value.

dbStats.dataSize

Total size of the uncompressed data held in the database. The dataSize decreases when you remove documents.

WiredTiger ストレージ エンジンを使用するデータベースの場合、圧縮が有効になっていると、dataSize が storageSize より大きくなる可能性があります。ドキュメントが縮小すると、 dataSize は減少します。

dbStats.storageSize

ドキュメントストレージ用にデータベース内のすべてのコレクションに割り当てられたディスク領域の合計(空き領域を含む)。

The storageSize does not decrease as you remove or shrink documents. This value may be smaller than dataSize for databases using the WiredTiger storage engine with compression enabled.

storageSize does not include space allocated to indexes. See indexSize for the total index size.

dbStats.freeStorageSize

ドキュメントストレージ用にデータベース内のすべてのコレクションに割り当てられた空き領域の合計。データベース・ストレージの空き領域はコレクションに割り当てられていますが、データは含まれていません。

freeStorageSize does not include free space allocated to indexes. See indexFreeStorageSize for the total free index size.

To include this value in the dbStats output, set freeStorage to 1.

バージョン 5.3.0、5.2.1、および 5.0.6 でアップデート

dbStats.indexes

データベース内のすべてのコレクションにわたるインデックスの合計数。

dbStats.indexSize

インデックスの空き領域を含む、データベース内のすべてのインデックスに割り当てられたディスク容量の合計。

注意

_ìdフィールドのデフォルトインデックスのみ(セカンダリ インデックスなし)のクラスター化されたコレクションでは、コレクションに別のインデックスファイルが必要ないため、インデックスサイズはゼロとして表示されます。

dbStats.indexFreeStorageSize

データベース内のすべてのインデックスに割り当てられたディスクの空き領域の合計。データベース・ストレージの空き領域はインデックスに割り当てられていますが、データは含まれていません。

indexFreeStorageSize does not include free space allocated to document storage. See freeStorageSize for the total free document storage size.

indexFreeStorageSize 進行中のインデックス構築は含まれません。

To include this value in the dbStats output, set freeStorage to 1.

バージョン 7.0、6.3.2、6.0.7、5.3.0、5.2.1、5.0.19、5.0.6 でアップデート

dbStats.totalSize

Sum of the disk space allocated for both documents and indexes in all collections in the database. Includes used and free storage space. This is the sum of storageSize and indexSize.

dbStats.totalFreeStorageSize

Sum of the free storage space allocated for both documents and indexes in all collections in the database. This is the sum of freeStorageSize and indexFreeStorageSize.

To include this value in the dbStats output, set freeStorage to 1.

バージョン 5.3.0、5.2.1、および 5.0.6 でアップデート。

dbStats.scaleFactor

scale 値(コマンドで使用)。

整数以外のスケール係数を指定した場合、MongoDB は指定された係数の整数部分を使用します。たとえば、スケール係数を 1023.999 に指定すると、MongoDB はスケール係数として 1023 使用します。

dbStats.fsUsedSize

MongoDB がデータを保存するファイルシステムで使用中のすべてのディスク領域の合計サイズ。

dbStats.fsTotalSize

MongoDB がデータを保存するファイルシステム上のすべてのディスク容量の合計サイズ。

The following examples demonstrate dbStats usage.

1つのフィールドに返されるデータを制限するには、dbStats コマンドにフィールド名を追加します。この例では、indexSize 値を返します。

db.runCommand( { dbStats: 1 } ).indexSize

To view free storage usage, set freeStorage to 1.

db.runCommand( { dbStats: 1, scale: 1024, freeStorage: 1 } )

出力例:

{
db: 'test',
collections: 2,
views: 0,
objects: 1689,
avgObjSize: 52.56542332741267,
dataSize: 86.7021484375,
storageSize: 100,
freeStorageSize: 32,
indexes: 2,
indexSize: 116,
indexFreeStorageSize: 36,
totalSize: 216,
totalFreeStorageSize: 68,
scaleFactor: 1024,
fsUsedSize: 60155820,
fsTotalSize: 61255492,
ok: 1,
'$clusterTime': {
clusterTime: Timestamp({ t: 1646085664, i: 1 }),
signature: {
hash: Binary(Buffer.from("0000000000000000000000000000000000000000", "hex"), 0),
keyId: Long("0")
}
},
operationTime: Timestamp({ t: 1646085664, i: 1 })
}

freeStorageフィールドを使用すると、強調表示されたメトリクスの収集と表示が可能になります。

スケールフィールドでは、表示される値をキロバイトに設定します。