定義
addShardToZoneシャードをゾーンに関連付けます。 MongoDB はこのシャードを指定されたゾーンに関連付けます。 ゾーンによってカバーされる チャンク は、そのゾーンに関連付けられているシャードに割り当てられます。
Tip
In
mongosh, this command can also be run through thesh.addShardToZone()helper method.Helper methods are convenient for
mongoshusers, but they may not return the same level of information as database commands. In cases where the convenience is not needed or the additional return fields are required, use the database command.
You can only run addShardToZone on the admin database from a mongos instance.
互換性
このコマンドは、次の環境でホストされている配置で使用できます。
- MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud
MongoDB Enterprise: サブスクリプションベースの自己管理型 MongoDB バージョン
MongoDB Community: ソースが利用可能で、無料で使用できる自己管理型の MongoDB のバージョン
構文
このコマンドの構文は、次のとおりです。
db.adminCommand( { addShardToZone: <string>, zone: <string> } )
コマンドフィールド
このコマンドは、次のフィールドを使用します。
フィールド | タイプ | 説明 |
|---|---|---|
string | The name of the shard to associate with the zone. | |
string | The name of the zone to associate with the shard. |
mongosh provides the helper method sh.addShardToZone().
動作
ゾーンを複数のシャードに関連付けることができ、シャードは複数のゾーンに関連付けらることができます。
シャーディングされたクラスター内のゾーンの詳細については、ゾーンのマニュアル ページを参照してください。
Ranges
MongoDB は、関連付けられているシャードキー値が少なくとも 1 つの範囲ではないゾーンを実質的に無視します。
シャードキー値の範囲をゾーンに関連付けるには、 updateZoneKeyRangeデータベースコマンドまたはsh.updateZoneKeyRange() shellヘルパーを使用します。
updateZoneKeyRangeデータベースコマンドとそのヘルパーsh.updateZoneKeyRange()およびsh.addTagRange()は、シャーディングされていないコレクションまたは存在しないコレクションで実行できます。
Tip
空のコレクションまたは存在しないコレクションをシャーディングする前にゾーンとゾーン範囲を定義することで、シャード コレクション操作は定義されたゾーン範囲のチャンクと、シャードキー値の全範囲をカバーする追加のチャンクを作成し、初期化を実行しますゾーン範囲に基づく チャンク分散 。 このように初期チャンクを作成して分散することで、ゾーン シャーディングの設定を迅速に行うことができます。 初期分散後、バランサーは今後のチャンク分散を管理します。
例については、「 空または存在しないコレクションのゾーンとゾーン範囲の事前定義」を参照してください。
セキュリティ
アクセス制御を強制するシャーディングされたクラスターの場合は、次のいずれかの特権を持つユーザーとして認証する必要があります。
データベース内の
updateshardsコレクションにある { または、あるいは、configenableShardingクラスター リソースの
The clusterAdmin or clusterManager built-in roles have the appropriate permissions for issuing addShardToZone. See the documentation page for Role-Based Access Control for more information.
例
次の例えでは、 shard0000とゾーンJFKを関連付けます。
db.adminCommand( { addShardToZone : "shard0000" , zone : "JFK" } )
シャードは複数のゾーンに関連付けることができます。 次の例えでは、 LGAをshard0000に関連付けます。
db.adminCommand( { addShardToZone : "shard0000" , zone : "LGA" } )
shard0000 は、 LGAゾーンとJFKゾーンの両方に関連付けられています。 MongoDB はバランスの取れたクラスター内で、いずれのゾーンでカバーされる読み取りと書込みをshard0000にルーティングします。