On this page本页内容
sh.updateZoneKeyRange(namespace, minimum, maximum, zone)
Associates a range of shard key values with a zone.将一系列分片键值与区域相关联。
Starting in MongoDB 4.0.2, you can run 从MongoDB 4.0.2开始,您可以对未存储的集合或不存在的集合运行updateZoneKeyRange
database command and its helpers sh.updateZoneKeyRange()
and sh.addTagRange()
on an unsharded collection or a non-existing collection.updateZoneKeyRange
数据库命令及其助手sh.updateZoneKeyRange()
和sh.addTagRange()
。
sh.updateZoneKeyRange()
takes the following arguments:采用以下参数:
namespace | string |
|
minimum | document |
|
maximum | document |
|
zone | string | minimum and maximum . minimum 和maximum 限定的分片键值范围关联的区域的名称。 |
Only issue 仅在连接到sh.updateZoneKeyRange()
when connected to a mongos
instance.mongos
实例时发出sh.updateZoneKeyRange()
。
You cannot create a range of shard key values whose lower and upper boundaries overlap with an existing range for the sharded collection. 不能创建其上下边界与分片集合的现有范围重叠的分片键值范围。For example, given an existing range of 例如,如果现有范围为1
to 10
, you cannot create a new range of 5
to 20
, as the new range would overlap with the existing range.1
到10
,则无法创建5
到20
的新范围,因为新范围将与现有范围重叠。
A zone can have multiple ranges of data associated with it, but a range can at most be associated with a single zone.一个区域可以有多个关联的数据范围,但一个范围最多只能与一个区域关联。
See the zone manual page for more information on zones in sharded clusters.有关分片集群中分区的详细信息,请参阅分区手册页面。
If you are considering performing zone sharding on an empty or non-existent collection, use 如果您正在考虑对空集合或不存在的集合执行区域分片,请在分片集合之前使用sh.updateZoneKeyRange()
to create the zones and zone ranges before sharding the collection (since 4.0.2). sh.updateZoneKeyRange()
创建区域和区域范围(自4.0.2起)。Starting in version 4.0.3, creating zones and zone ranges on empty or non-existing collections allows MongoDB to optimize the initial chunk creation and distribution process when sharding the collection. 从版本4.0.3开始,在空集合或不存在的集合上创建区域和区域范围,允许MongoDB在对集合进行分片时优化初始区块创建和分发过程。This optimized process supports faster setup of zoned sharding with less balancer overhead than creating zones after sharding. 此优化过程支持分区分片的更快设置,与分片后创建分区相比,平衡器开销更少。The balancer performs all chunk management after the optimized initial chunk creation and distribution.在优化初始区块创建和分发之后,平衡器执行所有区块管理。
For an example of defining zones and zone ranges for initial chunk distribution, see Pre-Define Zones and Zone Ranges for an Empty or Non-Existing Collection.有关为初始区块分布定义分区和分区范围的示例,请参阅为空集合或不存在集合预先定义分区和区域范围。
Starting in version 4.4, MongoDB supports sharding collections on compound hashed indexes. 从4.4版开始,MongoDB支持对复合哈希索引进行分片集合。MongoDB can perform optimized initial chunk creation and distribution when sharding the empty or non-existing collection on a compound hashed shard key.当在复合散列分片键上对空集合或不存在的集合进行分片时,MongoDB可以执行优化的初始区块创建和分发。
If the hashed field is the prefix of the shard key (i.e. the first field in the shard key), all of the following must be true for MongoDB to perform initial chunk creation and distribution:如果散列字段是分片键的前缀(即分片键中的第一个字段),MongoDB必须满足以下所有条件才能执行初始块创建和分发:
The collection has a single zone range with 集合有一个单一区域范围,所有下限字段使用MinKey
for all lower-bound fields and MaxKey
for all upper-bound fields.MinKey
,所有上限字段使用MaxKey
。
sh.shardCollection()
specifies the presplitHashedZones: true option.指定presplitHashedZones:true
选项。
If the hashed field is not the prefix of the shard key (i.e. the shard key has one or more non-hashed leading fields), all of the following must be true for MongoDB to perform initial chunk creation and distribution:如果hashed字段不是分片键的前缀(即分片键有一个或多个非hashed前导字段),那么MongoDB必须满足以下所有条件才能执行初始区块创建和分发:
The collection has one zone range for each combination of distinct prefix field values (i.e. all fields preceding the hashed field).对于不同前缀字段值的每个组合(即散列字段之前的所有字段),集合都有一个区域范围。
For the lower-bound of each zone range, specify 对于每个区域范围的下限,为散列字段和所有后续字段指定MinKey
for the hashed field and all subsequent fields.MinKey
。
For each zone range, at least one upper-bound prefix field must differ from its lower-bound counterpart.对于每个区域范围,至少有一个上限前缀字段必须与其下限对应字段不同。
sh.shardCollection()
specifies the presplitHashedZones: true option.指定presplitHashedZones: true
选项。
For a more complete example of defining zones and zone ranges for initial chunk distribution on a compound hashed shard key, see Pre-Define Zones and Zone Ranges for an Empty or Non-Existing Collection.有关为复合散列分片键上的初始区块分发定义区域和区域范围的更完整示例,请参阅为空集合或不存在集合预定义区域和区域区域范围。
After associating a range to a zone, the balancer must first run in order to migrate any chunks whose ranges are covered by the zone to shards inside of that zone. 将范围与区域关联后,必须首先运行平衡器,以便将其范围被区域覆盖的任何块迁移到该区域内的分片。Until balancing completes, some chunks may reside on the wrong shard given the configured zones for the sharded cluster. 在平衡完成之前,如果为分片集群配置了分区,则某些块可能驻留在错误的分片上。See Balancer for more information.有关详细信息,请参阅平衡器。
See the sharded cluster balancer manual page for more information on how migrations work in a sharded cluster.有关迁移如何在分片集群中工作的更多信息,请参阅分片集群平衡器手册页。
Zone ranges are always inclusive of the lower boundary and exclusive of the upper boundary.区域范围始终包括下边界,不包括上边界。
Starting in MongoDB 4.0.2, dropping a collection deletes its associated zone/tag ranges.从MongoDB 4.0.2开始,删除集合会删除其关联的区域/标记范围。
In earlier versions, MongoDB does not remove the tag associations for a dropped collection, and if you later create a new collection with the same name, the old tag associations will apply to the new collection.在早期版本中,MongoDB不会删除已删除集合的标记关联,如果稍后创建同名的新集合,则旧的标记关联将应用于新集合。
For sharded clusters running with authentication, you must authenticate as either:对于使用authentication
运行的分片群集,必须使用以下身份验证:
a user whose privileges include the specified actions on various collections in the 其权限包括对config
database:config
数据库中的各个集合执行指定操作的用户:
find
config.shards
collectionconfig.shards
集合上的查找find
and update
on the config.tags
collection;config.tags
集合上的查找和更新;or, alternatively,或者,作为替代,
enableSharding
on the cluster resource (available starting in version 4.2.2, 4.0.14, 3.6.16).enableSharding
的用户(从版本4.2.2、4.0.14、3.6.16开始可用)。The clusterAdmin
or clusterManager
built-in roles have the appropriate permissions for issuing sh.updateZoneKeyRange()
. clusterAdmin
或clusterManager
内置角色具有发出sh.updateZoneKeyRange()
的适当权限。See the documentation page for Role-Based Access Control for more information.有关详细信息,请参阅基于角色的访问控制的文档页面。
Given a sharded collection 给定一个分片集合exampledb.collection
with a shard key of { a : 1 }
, the following operation creates a range with a lower bound of 1
and an upper bound of 10
on the alpha
zone:exampledb.collection
,其分片键为{a:1}
,以下操作在alpha区域创建一个下限为1
、上限为10
的范围:
sh.updateZoneKeyRange( "exampledb.collection", { a : 1 }, { a : 10 }, "alpha" )
The following operation removes the previously created range by passing 以下操作通过向区域字段传递null
to the zone
field.null
来删除先前创建的范围。
sh.updateZoneKeyRange( "exampledb.collection", { a : 1 }, { a : 10 }, null )
The min
and max
must match exactly the bounds of the target range. min
和max
必须精确匹配目标范围的边界。The following operation attempts to remove the previously created range, but specifies 以下操作尝试删除以前创建的范围,但将{ a : 0 }
as the min
bound:{a:0}
指定为最小界限:
sh.updateZoneKeyRange( "exampledb.collection", { a : 0 }, { a : 10 }, null )
While the range of 虽然{ a : 0 }
and { a : 10 }
encompasses the existing range, it is not an exact match and therefore updateZoneKeyRange
does not remove anything.{a:0}
和{a:10}
的范围包含现有范围,但它并不完全匹配,因此updateZoneKeyRange不会删除任何内容。
Given a sharded collection 给定一个分片集合exampledb.collection
with a shard key of { a : 1, b : 1 }
, the following operation creates a range covering the lower bound of { a: 1, b : 1 }
and an upper bound of { a : 10, b : 10}
and associates it with the alpha
zone:exampledb.collection
,其分片键为{a:1, b:1}
,以下操作将创建一个范围,覆盖{a:1,b:1}
的下限和{a:10, b:10}
的上限,并将其与alpha
区域相关联:
sh.updateZoneKeyRange( "exampledb.collection", { a : 1, b : 1 }, { a : 10, b : 10 }, "alpha" )
Starting in version 4.2, creating zones and zone ranges on empty or non-existing collections allows MongoDB to optimize the initial chunk creation and distribution process when sharding the collection. 从4.2版开始,在空集合或不存在的集合上创建区域和区域范围,允许MongoDB在对集合进行分片时优化初始区块创建和分发过程。This optimized process supports faster setup of zoned sharding with less balancer overhead than creating zones after sharding. 此优化过程支持分区分片的更快设置,与分片后创建分区相比,平衡器开销更少。The balancer performs all chunk management after the optimized initial chunk creation and distribution. 在优化初始区块创建和分发之后,平衡器执行所有区块管理。See Initial Chunk Distribution with Compound Hashed Shard Keys for more information.有关详细信息,请参阅使用复合散列分片键的初始区块分布。
The sections below contain examples for three different shard key types.下面的部分包含三种不同的分片键类型的示例。
Consider the following examples, which explore pre-defining zones or zone ranges for three different shard key types:考虑以下示例,这些示例探索了为三种不同的分片键类型预定义分区或分区范围:
This example only applies to single-field or compound shard keys without a hashed field.此示例仅适用于没有散列字段的单个字段或复合分片键。
For example, 例如,{ "zip" : 1 }
or { "zip" : 1, "account" : 1}
{ "zip" : 1 }
或{ "zip" : 1, "account" : 1}
Use 使用sh.addShardToZone()
to create the zones:sh.addShardToZone()
创建分区:
sh.addShardToZone("shardA", "DC1") sh.addShardToZone("shardB", "DC2")
Use 使用sh.updateZoneKeyRange()
to create the ranges for the empty contacts
collection in the exampledb
database:sh.updateZoneKeyRange()
为exampledb
数据库中的空contacts
集合创建范围:
sh.updateZoneKeyRange( "exampledb.contacts", { zip: 10001 }, { zip: 10090 }, "DC1" ); sh.updateZoneKeyRange( "exampledb.contacts", { zip: 90001 }, { zip: 96054 }, "DC2" );
Skip this step if you already enabled sharding on the database.如果已经在数据库上启用了分片,请跳过此步骤。
Use 使用sh.enableSharding()
to enable sharding for the database:sh.enableSharding()
为数据库启用分片:
sh.enableSharding("exampledb")
If the collection does not exist, the sharding operation creates the collection.如果集合不存在,分片操作将创建集合。
If the collection is empty and no index exists to support the shard key, the sharding operation creates the index.如果集合为空,并且不存在支持分片键的索引,则分片操作将创建索引。
Use 使用sh.shardCollection()
to shard the collection contacts
:sh.shardCollection()
共享集合contacts
:
sh.shardCollection("exampledb.contacts", { zip: 1 } );
To see the created chunks and distribution, run the 要查看创建的块和分布,请运行sh.status()
operation:sh.status()
操作:
sh.status()
The method returns:该方法返回:
--- Sharding Status --- sharding version: { "_id" : 1, "minCompatibleVersion" : 5, "currentVersion" : 6, "clusterId" : ObjectId("5b80c06d35a961fd0ae1986d") } shards: { "_id" : "shardA", "host" : "shardA/mongodb0.example.net:27018,mongodb1.example.net:27018,mongodb2.example.net:27018", "state" : 1, "tags" : [ "DC1" ] } { "_id" : "shardB", "host" : "shardB/mongodb3.example.net:27018,mongodb4.example.net:27018,mongodb5.example.net:27018", "state" : 1, "tags" : [ "DC2" ] } active mongoses: "4.2.0" : 2 autosplit: Currently enabled: yes balancer: Currently enabled: yes Currently running: no Failed balancer rounds in last 5 attempts: 0 Migration Results for the last 24 hours: No recent migrations databases: { "_id" : "config", "primary" : "config", "partitioned" : true } { "_id" : "exampledb", "primary" : "shardA", "partitioned" : true, "version" : { "uuid" : UUID("6c351bcf-acd2-4fd9-82d8-9f6bd7321558"), "lastMod" : 1 } } exampledb.contacts shard key: { "zip" : 1 } unique: false balancing: true chunks: shardA 3 shardB 2 { "zip" : { "$minKey" : 1 } } -->> { "zip" : 10001 } on : shardA Timestamp(1, 0) { "zip" : 10001 } -->> { "zip" : 10090 } on : shardA Timestamp(1, 1) { "zip" : 10090 } -->> { "zip" : 90001 } on : shardB Timestamp(1, 2) { "zip" : 90001 } -->> { "zip" : 96054 } on : shardB Timestamp(1, 3) { "zip" : 96054 } -->> { "zip" : { "$maxKey" : 1 } } on : shardA Timestamp(1, 4) tag: DC1 { "zip" : 10001 } -->> { "zip" : 10090 } tag: DC2 { "zip" : 90001 } -->> { "zip" : 96054 }
For the collection, sharding operation created 5 chunks (two chunks that correspond to the zone ranges and the other three to cover all other values) across shardA and shardB.对于集合,分片操作在shardA和shardB中创建了5个块(两个块对应于区域范围,另外三个块覆盖所有其他值)。
This example only applies to compound hashed shard keys where the hashed field is the prefix of the shard key (i.e. the first field in the shard key is hashed).此示例仅适用于复合散列分片键,其中散列字段是分片键的前缀(即分片键中的第一个字段是散列的)。
For example, 例如{ "_id" : "hashed", "facility" : 1 }
Starting in version 4.4, MongoDB supports sharding collections on compound hashed indexes. 从4.4版开始,MongoDB支持对复合哈希索引进行分片集合。When sharding on a compound hashed shard key, MongoDB can perform optimized initial chunk creation and distribution on the empty or non-existing collection only if the defined zone ranges meet additional requirements.在对复合散列分片键进行分片时,只有在定义的区域范围满足其他要求的情况下,MongoDB才能对空集合或不存在的集合执行优化的初始区块创建和分发。
Consider an empty collection 考虑一个空的集合examples.metrics
which will store analytics from one of two manufacturing facilities. examples.metrics
,它将存储来自两个生产设施之一的分析。The planned shard key is 计划的分片键是{ "_id" : "hashed", "facility" : 1}
, where the hashed field is the shard key prefix.{ "_id" : "hashed", "facility" : 1}
,其中哈希字段是分片键前缀。
The planned shard key is 计划的分片键是{ "_id" : "hashed", "facility" : 1 }
. { "_id" : "hashed", "facility" : 1 }
。Since the hashed field is the prefix (i.e. the first field in the shard key), create a single zone using 由于散列字段是前缀(即分片键中的第一个字段),因此使用sh.addShardToZone()
:sh.addShardToZone()
创建单个区域:
sh.addShardToZone("shardA", "FacilityAlpha") sh.addShardToZone("shardB", "FacilityAlpha")
Initial chunk distribution on a compound hashed shard key with a hashed prefix requires a single zone range with 具有哈希前缀的复合哈希分片键上的初始区块分布需要一个单一区域范围,所有下限字段使用MinKey
for all lower-bound fields and MaxKey
for all upper-bound fields.MinKey
,所有上限字段使用MaxKey
。
Use 使用sh.updateZoneKeyRange()
to create a single range:sh.updateZoneKeyRange()
创建单个范围:
sh.updateZoneKeyRange( "examples.metrics", { "_id" : MinKey, "facility" : MinKey }, { "_id" : MaxKey, "facility" : MaxKey }, "FacilityAlpha" );
Skip this step if you already enabled sharding on the database.如果已经在数据库上启用了分片,请跳过此步骤。
Use 使用sh.enableSharding()
to enable sharding for the database:sh.enableSharding()
为数据库启用分片:
sh.enableSharding("examples")
If the collection does not exist, the sharding operation creates the collection.如果集合不存在,分片操作将创建集合。
If the collection is empty and no index exists to support the shard key, the sharding operation creates the index.如果集合为空,并且不存在支持分片键的索引,则分片操作将创建索引。
Use 使用sh.shardCollection()
with presplitHashedZones: true to shard the collection and perform initial chunk creation and distribution:sh.shardCollection()
和presplitHashedZones: true
对集合进行分片,并执行初始区块创建和分发:
sh.shardCollection( "examples.metrics", { "_id" : "hashed", "facility" : 1 }, false, { presplitHashedZones: true } )
To see the created chunks and distribution, run the 要查看创建的块和分布,请运行sh.status()
operation:sh.status()
操作:
sh.status()
The output resembles the following (content omitted for readability):输出类似于以下内容(为便于阅读,省略了内容):
--- Sharding Status --- databases: { "_id" : "config", "primary" : "config", "partitioned" : true } { "_id" : "examples", "primary" : "shardA", "partitioned" : true, "version" : { "uuid" : UUID("245f8abf-a363-48b0-8208-2a5b577bbb4e"), "lastMod" : 1 } } examples.metrics shard key: { "_id" : "hashed", "facility" : 1 } unique: false balancing: true chunks: shardA 2 shardB 2 { "_id" : { "$minKey" : 1 }, "facility" : { "$minKey" : 1 } } -->> { "_id" : NumberLong("-4611686018427387902"), "facility" : { "$minKey" : 1 } } on : shardA Timestamp(1, 0) { "_id" : NumberLong("-4611686018427387902"), "facility" : { "$minKey" : 1 } } -->> { "_id" : NumberLong(0), "facility" : { "$minKey" : 1 } } on : shardA Timestamp(1, 1) { "_id" : NumberLong(0), "facility" : { "$minKey" : 1 } } -->> { "_id" : NumberLong("4611686018427387902"), "facility" : { "$minKey" : 1 } } on : shardB Timestamp(1, 2) { "_id" : NumberLong("4611686018427387902"), "facility" : { "$minKey" : 1 } } -->> { "_id" : { "$maxKey" : 1 }, "facility" : { "$maxKey" : 1 } } on : shardB Timestamp(1, 3) tag: FacilityAlpha { "_id" : { "$minKey" : 1 }, "facility" : { "$minKey" : 1 } } -->> { "_id" : { "$maxKey" : 1 }, "facility" : { "$maxKey" : 1 } }
The sharding operation produced 4 chunks in total. Two chunks correspond to the absolute lower and upper bounds. 分片操作总共产生了4个块。两个块对应于绝对上下限。One zone was created on 在与shardA
and shardB
corresponding to FacilityAlpha
. FacilityAlpha
对应的shardA
和shardB
上创建了一个区域。The zone was subdivided into 2 chunks using the hashed field.使用哈希字段将区域细分为2个块。
This example only applies to compound hashed shard keys where the hashed field is not the prefix of the shard key (i.e. the first field in the shard key is not hashed).此示例仅适用于复合散列分片键,其中散列字段不是分片键的前缀(即分片键中的第一个字段没有散列)。
For example, { "facility" : 1, "_id" : "hashed" }
Starting in version 4.4, MongoDB supports sharding collections on compound hashed indexes. 从4.4版开始,MongoDB支持对复合哈希索引进行分片集合。When sharding on a compound hashed shard key, MongoDB can perform optimized initial chunk creation and distribution on the empty or non-existing collection only if the defined zone ranges meet additional requirements.在对复合散列分片键进行分片时,只有在定义的区域范围满足其他要求的情况下,MongoDB才能对空集合或不存在的集合执行优化的初始区块创建和分发。
Consider an empty collection 考虑一个空的集合examples.metrics
which will store analytics from one of two manufacturing facilities. examples.metrics
,它将存储来自两个生产设施之一的分析。The planned shard key is 计划的分片键是{ "facility" : 1, "_id" : "hashed" }
, where the hashed field is not the shard key prefix.{ "facility" : 1, "_id" : "hashed" }
,其中哈希字段不是分片键前缀。
facility
field stores the name of the facility: "FacilityAlpha"
or "FacilityBaker"
. facility
字段存储设施的名称:"FacilityAlpha"
或"FacilityBaker"
。facility
to help isolate data for each facility to specific shards.facility
上的区域范围,以帮助将每个设施的数据隔离到特定分片。_id
field compensates for the low-cardinality of the facility
field. _id
字段补偿了facility
字段的低基数。_id
field._id
字段单调递增的特性。Use the 使用sh.addShardToZone()
command to create the zones.sh.addShardToZone()
命令创建分区。
sh.addShardToZone("shardA", "FacilityAlpha") sh.addShardToZone("shardB", "FacilityBaker")
The planned shard key is 计划的分片键是{"facility" : 1, "_id" : "hashed"}
. {"facility" : 1, "_id" : "hashed"}
。The 设施字段有两个可能的值:facility
field has two possible values: FacilityAlpha
and FacilityBaker
.FacilityAlpha
和FacilityBaker
。
Initial chunk distribution on a compound hashed shard key where the hashed field is not the prefix requires one zone range for each combination of distinct prefix field values (i.e. all fields preceding the hashed field). 哈希字段不是前缀的复合哈希分片键上的初始区块分布要求不同前缀字段值的每个组合都有一个区域范围(即哈希字段之前的所有字段)。Since 由于facility
has two distinct prefix values, the collection requires exactly two zone ranges that cover those values.facility
有两个不同的前缀值,因此集合需要正好两个区域范围来覆盖这些值。
MinKey
for all non-prefix fields.MinKey
。Use 使用sh.updateZoneKeyRange()
to create the range for "facility": "FacilityAlpha"
:sh.updateZoneKeyRange()
创建"facility": "FacilityAlpha"
的范围:
sh.updateZoneKeyRange( "examples.metrics", { "facility": "FacilityAlpha", "_id" : MinKey }, { "facility": "FacilityBaker", "_id" : MinKey }, "FacilityAlpha" );
"facilty" : "FacilityAlpha"
and all possible values of _id
."facilty" : "FacilityAlpha"
和所有可能值_id
的文档。Use 使用sh.updateZoneKeyRange()
to create the range for "facility": "FacilityBaker"
:sh.updateZoneKeyRange()
创建"facility": "FacilityBaker"
的范围:
sh.updateZoneKeyRange( "examples.metrics", { "facility": "FacilityBaker", "_id" : MinKey }, { "facility": MaxKey, "_id" : MinKey }, "FacilityBaker" );
facility
, the initial chunk distribution logic relies on the assumption that no other distinct values for facility
exist. facility
的其他值,但初始区块分布逻辑依赖于设施不存在其他不同值的假设。facility
is FacilityAlpha
or FacilityBaker
, this range only covers documents with the distinct shard key prefix value "facility" : "FacilityBaker"
and all possible values of _id
.facility
为FacilityAlpha
或FacilityBaker
的文档,因此此范围仅涵盖具有不同的分片键前缀值"facility" : "FacilityBaker"
和所有可能值_id
的文档。Skip this step if you already enabled sharding on the database.如果已经在数据库上启用了分片,请跳过此步骤。
Use 使用sh.enableSharding()
to enable sharding for the database:sh.enableSharding()
为数据库启用分片:
sh.enableSharding("examples")
If the collection does not exist, the sharding operation creates the collection.如果集合不存在,分片操作将创建集合。
If the collection is empty and no index exists to support the shard key, the sharding operation creates the index.如果集合为空,并且不存在支持分片键的索引,则分片操作将创建索引。
Use 使用sh.shardCollection()
with presplitHashedZones: true to shard the collection and perform initial chunk creation and distribution:sh.shardCollection()
配合presplitHashedZones: true
对集合进行分片,并执行初始区块创建和分发:
sh.shardCollection( "examples.metrics", { "facility" : 1, "_id" : "hashed"}, false, { presplitHashedZones: true } )
To see the created chunks and distribution, run the 要查看创建的块和分布,请运行sh.status()
operation:sh.status()
操作:
sh.status()
The output resembles the following (content omitted for readability):输出类似于以下内容(为便于阅读,省略了内容):
--- Sharding Status --- databases: { "_id" : "config", "primary" : "config", "partitioned" : true } { "_id" : "examples", "primary" : "shardA", "partitioned" : true, "version" : { "uuid" : UUID("6c351bcf-acd2-4fd9-82d8-9f6bd7321558"), "lastMod" : 1 } } examples.metrics shard key: { "facility" : 1, "_id" : "hashed" } unique: false balancing: true chunks: shardA 3 shardB 3 { "facility" : { "$minKey" : 1 }, "_id" : { "$minKey" : 1 } } -->> { "facility" : "FacilityAlpha", "_id" : { "$minKey" : 1 } } on : shard1 Timestamp(1, 0) { "facility" : "FacilityAlpha", "_id" : { "$minKey" : 1 } } -->> { "facility" : "FacilityAlpha", "_id" : NumberLong(0) } on : shard1 Timestamp(1, 1) { "facility" : "FacilityAlpha", "_id" : NumberLong(0) } -->> { "facility" : "FacilityBaker", "_id" : { "$minKey" : 1 } } on : shard1 Timestamp(1, 2) { "facility" : "FacilityBaker", "_id" : { "$minKey" : 1 } } -->> { "facility" : "FacilityBaker", "_id" : NumberLong(0) } on : shard2 Timestamp(1, 3) { "facility" : "FacilityBaker", "_id" : NumberLong(0) } -->> { "facility" : { "$maxKey" : 1 }, "_id" : { "$minKey" : 1 } } on : shard2 Timestamp(1, 4) { "facility" : { "$maxKey" : 1 }, "_id" : { "$minKey" : 1 } } -->> { "facility" : { "$maxKey" : 1 }, "_id" : { "$maxKey" : 1 } } on : shard2 Timestamp(1, 5) tag: FacilityAlpha { "facility" : "FacilityAlpha", "_id" : { "$minKey" : 1 } } -->> { "facility" : "FacilityBaker", "_id" : { "$minKey" : 1 } } tag: FacilityBaker { "facility" : "FacilityBaker", "_id" : { "$minKey" : 1 } } -->> { "facility" : { "$maxKey" : 1 }, "_id" : { "$minKey" : 1 } }
The sharding operation produced 6 chunks in total. 分片操作总共产生了6个块。Two chunks correspond to the absolute lower and upper bounds. 两个块对应于绝对上下限。Two zones were created, one on 创建了两个区域,一个在shardA
and one on shardB
, corresponding to FacilityAlpha
and FacilityBaker
. shardA
上,另一个在shardB
上,对应于FacilityAlpha
和FacilityBaker
。Each of these zones has been further subdivided into 2 chunks using the hashed field.使用散列字段将每个区域进一步细分为2个块。