sh.addTagRange()
定義
sh.addTagRange(namespace, minimum, maximum, tag)
注意
このメソッドは
sh.updateZoneKeyRange()
のエイリアスになります。 MongoDB は、タグ対応シャーディングの継承としてゾーン シャーディングを提供します。Attaches a range of shard key values to a shard tag created using the
sh.addShardTag()
method.You can run
updateZoneKeyRange
database command and its helperssh.updateZoneKeyRange()
andsh.addTagRange()
on an unsharded collection or a non-existing collection.sh.addTagRange()
takes the following arguments:Parameterタイプ説明namespace
string
タグを付けるシャーディングされたコレクションの名前空間。
minimum
ドキュメント
The minimum value of the シャードキー range to include in the tag. The minimum is an inclusive match. Specify the minimum value in the form of
<fieldname>:<value>
. This value must be of the same BSON type or types as the shard key.maximum
ドキュメント
The maximum value of the shard key range to include in the tag. The maximum is an exclusive match. Specify the maximum value in the form of
<fieldname>:<value>
. This value must be of the same BSON type or types as the shard key.tag
string
The name of the tag to attach the range specified by the
minimum
andmaximum
arguments to.使用
sh.addShardTag()
to ensure that the balancer migrates documents that exist within the specified range to a specific shard or set of shards.sh.addTagRange()
インスタンスに接続されている場合にのみmongos
を発行します。
互換性
このメソッドは、次の環境でホストされている配置で使用できます。
MongoDB Atlas はクラウドでの MongoDB 配置のためのフルマネージド サービスです
重要
このコマンドは、M0、M2、M5、および Flex クラスターではサポートされていません。詳細については、「 サポートされていないコマンド 」を参照してください。
MongoDB Enterprise: サブスクリプションベースの自己管理型 MongoDB バージョン
MongoDB Community: ソースが利用可能で、無料で使用できる自己管理型の MongoDB のバージョン
動作
限界
ゾーン範囲は、常に下限を含み、上限を含まない範囲です。
Initial Chunk Distribution for Empty or Non-Existing Collections
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.
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. This optimized process supports faster setup of zoned
sharding with less balancer overhead than creating zones after sharding. The
バランサー 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.
Initial Chunk Distribution with Compound Hashed Shard Keys
MongoDB supports sharding collections on compound hashed indexes. MongoDB can perform optimized initial chunk creation and distribution when sharding the empty or non-existing collection on a compound hashed shard key.
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:
The collection has a single zone range with
MinKey
for all lower-bound fields andMaxKey
for all upper-bound fields.sh.shardCollection()
specifies the presplitHashedZones: true option.
If the hashed field is ではない 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:
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.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.
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.
Dropped Collections
コレクションを削除すると、それに関連付けられたゾーンやタグの範囲も削除されます。
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.
例
Given a shard key of {state: 1, zip: 1}
, the following operation
creates a tag range covering zip codes in New York State:
sh.addTagRange( "exampledb.collection", { state: "NY", zip: MinKey }, { state: "NY", zip: MaxKey }, "NY" )