$shardedDataDistribution (aggregation)
項目一覧
定義
$shardedDataDistribution
バージョン 6.0.3 で追加。
Returns information on the distribution of data in sharded collections.
注意
This aggregation stage is only available on
mongos
.This aggregation stage must be run on the
admin
database. The user must have theshardedDataDistribution
privilege action.
構文
shardedDataDistribution
ステージの構文は次のとおりです。
db.aggregate( [ { $shardedDataDistribution: { } } ] )
出力フィールド
The $shardedDataDistribution
stage outputs an array of documents
for each sharded collection in the database. These documents contain the
following fields:
フィールド名 | データ型 | 説明 |
---|---|---|
| string | Namespace of the sharded collection. |
| 配列 | Shards in the collection with the data distribution information for each shard. |
| integer | Number of orphaned documents in the shard. |
| integer | Number of documents owned by the shard. |
| integer | Size in bytes of documents owned by the shard when uncompressed. |
| integer | Size in bytes of orphaned documents in the shard when uncompressed. |
Starting in MongoDB 8.0, $shardedDataDistribution
only returns
output for a collection's プライマリシャード if the primary shard
has chunks or orphaned documents.
動作
Wired Tigerストレージエンジンを使用してmongod
を不正にシャットダウンした後、$shardedDataDistribution
によって報告されるサイズとカウントの統計が不正確になる可能性があります。
ドリフトの量は、チェックポイントからクリーン シャットダウンまでの間に実行された挿入、アップデート、または削除操作の数によって異なります。チェックポイントは通常、60 秒ごとに発現します。ただし、デフォルト以外の --syncdelay
設定で実行されている mongod
インスタンスでは、チェックポイントの頻度が増減する可能性があります。
不正なシャットダウン後に統計を復元するには、mongod
の各コレクションに対して validate
を実行します。
不正なシャットダウン後:
例
Return All Sharded Data Distibution Metrics
To return all sharded data distribution metrics, run the following:
db.aggregate([ { $shardedDataDistribution: { } } ])
出力例:
[ { "ns": "test.names", "shards": [ { "shardName": "shard-1", "numOrphanedDocs": 0, "numOwnedDocuments": 6, "ownedSizeBytes": 366, "orphanedSizeBytes": 0 }, { "shardName": "shard-2", "numOrphanedDocs": 0, "numOwnedDocuments": 6, "ownedSizeBytes": 366, "orphanedSizeBytes": 0 } ] } ]
Return Metrics for a Specific Shard
To return sharded data distribution metrics for a specific shard, run the following:
db.aggregate([ { $shardedDataDistribution: { } }, { $match: { "shards.shardName": "<name of the shard>" } } ])
Return Metrics for a Namespace
To return sharded data distribution data for a namespace, run the following:
db.aggregate([ { $shardedDataDistribution: { } }, { $match: { "ns": "<database>.<collection>" } } ])
Confirm No Orphaned Documents Remain
Starting in MongoDB 6.0.3, you can run an aggregation using the
$shardedDataDistribution
stage to confirm no orphaned
documents remain:
db.aggregate([ { $shardedDataDistribution: { } }, { $match: { "ns": "<database>.<collection>" } } ])
$shardedDataDistribution
has output similar to the following:
[ { "ns": "test.names", "shards": [ { "shardName": "shard-1", "numOrphanedDocs": 0, "numOwnedDocuments": 6, "ownedSizeBytes": 366, "orphanedSizeBytes": 0 }, { "shardName": "shard-2", "numOrphanedDocs": 0, "numOwnedDocuments": 6, "ownedSizeBytes": 366, "orphanedSizeBytes": 0 } ] } ]
Ensure that "numOrphanedDocs"
is 0
for each shard in the
cluster.