ANNOUNCEMENT: Voyage AI joins MongoDB to power more accurate and trustworthy AI applications on Atlas.
Learn more
Docs Menu

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>"
}
)

注意

Starting in version 6.2, MongoDB removes the maxSize field from the addShard command. As a result:

  • Running addShard with the maxSize field returns an InvalidOptions error.

  • shards コレクション内の新しいドキュメントには、maxSize フィールドは含まれなくなりました。

  • 既存の maxSize フィールド エントリはすべて無視されます。

このコマンドには次のフィールドが含まれています。

フィールド
タイプ
説明

addShard

string

シャードのレプリカセットの少なくとも 1 つのノードのレプリカセット名、ホスト名、ポート。 追加のレプリカセット ノードのホスト名は、カンマで区切る必要があります。 例:

<replica_set>/<hostname><:port>,<hostname><:port>, ...

name

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.

The shard that you add to your sharded cluster must be empty.

シャーディングされたクラスターにシャードを追加すると、既存のすべてのシャーディングされたコレクションのクラスターのシャード間のチャンクのバランスに影響します。 バランサーはチャンクの移行を開始し、クラスターがバランスをとります。 詳細については、「バランサーの内部」を参照してください。

重要

に提供されるシードリストにaddShard 非表示メンバー を含めることはできません。

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.