Docs HomeMongoDB Manual

$shardedDataDistribution (aggregation)

Definition定义

$shardedDataDistribution

New in version 6.0.3. 6.0.3版新增。

Returns information on the distribution of data in sharded collections.返回有关分片集合中数据分布的信息。

Note

This aggregation stage is only available on mongos.此聚合阶段仅在mongos上可用。

This aggregation stage must be run on the admin database. 此聚合阶段必须在admin数据库上运行。The user must have the shardedDataDistribution privilege action.用户必须具有shardedDataDistribution权限操作。

Syntax语法

The shardedDataDistribution stage has the following syntax:shardedDataDistribution阶段具有以下语法:

db.aggregate( [
{ $shardedDataDistribution: { } }
] )

Output Fields输出字段

The $shardedDataDistribution stage outputs an array of documents for each sharded collection in the database. shardedDataDistribution阶段为数据库中的每个分片集合输出一个文档数组。These documents contain the following fields:这些文档包含以下字段:

Field Name字段名称Data Type数据类型Description描述
nsstringThe namespace of the sharded collection.分片集合的命名空间。
shardsarrayLists the shards in the collection with data distribution information on each shard.列出集合中的分片以及每个分片的数据分布信息。
shards.numOrphanedDocsintegerNumber of orphaned documents in the shard.分片中孤立文档的数量。
shards.numOwnedDocumentsintegerNumber of documents owned by the shard.分片拥有的文档数。
shards.orphanedSizeBytesintegerAmount of storage in bytes used by orphaned documents in the shard.分片中孤立文档使用的存储量(以字节为单位)。
shards.ownedSizeBytesintegerAmount of storage in bytes used by owned documents in the shard.分片中拥有的文档使用的存储量(以字节为单位)。

Examples实例

db.aggregate( [
{ $shardedDataDistribution: { } }
] )

Example output:输出示例:

[
{
"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
}
]
}
]