AI エージェント向け: ドキュメントインデックスは https://www.mongodb.com/ja-jp/docs/llms.txt で利用できます。すべてのページの markdown バージョンは、いずれかの URL パスに .md を追加することで利用できます。
Docs Menu

sh.enableSharding()(mongoshメソッド)

sh.enableSharding(database, primaryShard)

注意

バージョン6.0で変更。

MongoDB 6.0 以降では、コレクションを シャード するためにこのメソッドは必須ではあり ません 。

Explicitly creates a database. Use the mongosh method sh.shardCollection() to shard collections on the database. The mongosh method sh.enableSharding() wraps the enableSharding command.

重要

mongosh メソッド

This page documents a mongosh method. This is not the documentation for database commands or language-specific drivers, such as Node.js.

データベースコマンドについては、enableSharding コマンドを参照してください。

MongoDB API ドライバーについては、各言語の「MongoDB ドライバーのドキュメント」を参照してください。

このメソッドは、次の環境でホストされている配置で使用できます。

  • MongoDB Atlas はクラウドでの MongoDB 配置のための完全管理サービスです

重要

このコマンドは、M0 および Flex クラスターではサポートされていません。詳細については、サポートされていないコマンド を参照してください。

  • MongoDB Enterprise: サブスクリプションベースの自己管理型 MongoDB バージョン

  • MongoDB Community: ソースが利用可能で、無料で使用できる自己管理型の MongoDB のバージョン

The sh.enableSharding() has the following form:

sh.enableSharding(
<database>,
<primary shard> // Optional.
)

The sh.enableSharding() method takes the following parameter:

Parameter
タイプ
説明

文字列

作成するデータベースの名前。

文字列

任意。 データベースのプライマリシャード。 これは、データベース内のすべてのシャーディングされていないコレクションのデフォルトのシャードです。

警告:一般に、プライマリシャードは指定しないでください。 クラスターで代わりにプライマリシャードを選択できるようにします。

mongos uses "majority" for the enableSharding command and its helper sh.enableSharding().

一般に、コマンドでプライマリシャードを指定する必要はありません。 代わりに、バランサーでプライマリシャードを選択できるようにします。

However, if you do specify the primary shard for a database and the database is already enabled for sharding with a different primary shard, the operation returns an error and the primary shard for the database remains as before. To change the primary shard for a database, use the movePrimary command instead.

次の例では、 mongosから実行すると、 shardTestデータベースが明示的に作成されます。

sh.enableSharding("shardTest")

確認するには、 sh.status()を実行します。

このページを評価