On this page本页内容
sh.addTagRange(namespace, minimum, maximum, tag)
Changed in version 3.4.在版本3.4中更改。
sh.updateZoneKeyRange()
in MongoDB 3.4. sh.updateZoneKeyRange()
。Attaches a range of shard key values to a shard tag created using the 将一系列分片键值附加到使用sh.addShardTag()
method.sh.addShardTag()
方法创建的分片标记。
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.addTagRange()
takes the following arguments:采用以下参数:
namespace | string | |
minimum | document | <fieldname>:<value> . <fieldname>:<value> 的形式指定最小值。 |
maximum | document | <fieldname>:<value> . <fieldname>:<value> 的形式指定最大值。 |
tag | string | minimum and maximum arguments to. minimum 和maximum 参数指定的范围的标记的名称。 |
Use 使用sh.addShardTag()
to ensure that the balancer migrates documents that exist within the specified range to a specific shard or set of shards.sh.addShardTag()
确保平衡器将存在于指定范围内的文档迁移到特定分片或分片集。
Only issue 仅在连接到sh.addTagRange()
when connected to a mongos
instance.mongos
实例时发出sh.addTagRange()
。
Zone ranges are always inclusive of the lower boundary and exclusive of the upper boundary.区域范围始终包括下边界,不包括上边界。
If you are considering performing zone sharding on an empty or non-existent collection, use 如果您正在考虑对空集合或不存在的集合执行区域分片,请在分片集合之前使用sh.addTagRange()
to create the zones and zone ranges before sharding the collection. sh.addTagRange()
创建区域和区域范围。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:如果哈希字段不是分片键的前缀(即分片键有一个或多个非哈希前导字段),那么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.有关为复合散列分片键上的初始区块分发定义区域和区域范围的更完整示例,请参阅为空集合或不存在集合预定义区域和区域区域范围。
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不会删除已删除集合的标记关联,如果稍后创建同名的新集合,则旧的标记关联将应用于新集合。
Given a shard key of 给定{state: 1, zip: 1}
, the following operation creates a tag range covering zip codes in New York State:{state: 1, zip: 1}
的分片键,以下操作将创建一个包含纽约州邮政编码的标记范围:
sh.addTagRange( "exampledb.collection", { state: "NY", zip: MinKey }, { state: "NY", zip: MaxKey }, "NY" )