addShard
定義
addShard
Adds a shard replica set to a シャーディングされたクラスター.
Tip
mongosh
では、このコマンドはsh.addShard()
ヘルパー メソッドを通じて実行することもできます。ヘルパー メソッドは
mongosh
ユーザーには便利ですが、データベースコマンドと同じレベルの情報は返されない可能性があります。 便宜上必要ない場合、または追加の戻りフィールドが必要な場合は、 データベースコマンドを使用します。
互換性
このコマンドは、次の環境でホストされている配置で使用できます。
MongoDB Enterprise: サブスクリプションベースの自己管理型 MongoDB バージョン
MongoDB Community: ソースが利用可能で、無料で使用できる自己管理型の MongoDB のバージョン
注意
このコマンドはMongoDB Atlasではサポートされていません。Atlas クラスターからシャードを追加または削除するには、「 Atlasシャードクラスタの変更 」を参照してください。
構文
このコマンドの構文は、次のとおりです。
db.adminCommand( { addShard: "<replica_set>/<hostname><:port>", name: "<shard_name>" } )
コマンドフィールド
注意
このコマンドには次のフィールドが含まれています。
フィールド | タイプ | 説明 | |
---|---|---|---|
| string | シャードのレプリカセットの少なくとも 1 つのノードのレプリカセット名、ホスト名、ポート。 追加のレプリカセット ノードのホスト名は、カンマで区切る必要があります。 例:
| |
| string | Optional. A name for the shard. If this is not specified, MongoDB automatically provides a unique name. |
The addShard
command stores shard configuration
information in the config database. Always run
addShard
when using the admin
database.
Considerations
ストレージ
The shard that you add to your sharded cluster must be empty.
バランシング
シャーディングされたクラスターにシャードを追加すると、既存のすべてのシャーディングされたコレクションのクラスターのシャード間のチャンクのバランスに影響します。 バランサーはチャンクの移行を開始し、クラスターがバランスをとります。 詳細については、「バランサーの内部」を参照してください。
非表示メンバー
DDL 操作
If you add a shard while your cluster executes a DDL operation
(operation that modifies a collection such as
reshardCollection
), addShard
only executes after the
concurrent DDL operation finishes.
例
The following command adds a replica set as a shard:
use admin db.runCommand( { addShard: "repl0/mongodb3.example.net:27327"} )
警告
Do not use localhost
for the hostname unless your
config server is also running on
localhost
.