定義
sh.enableSharding(database, primaryShard)Explicitly creates a database. Use the
mongoshmethodsh.shardCollection()to shard collections on the database. Themongoshmethodsh.enableSharding()wraps theenableShardingcommand.重要
mongosh メソッド
This page documents a
mongoshmethod. 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. )
Parameter
The sh.enableSharding() method takes the following parameter:
動作
書込み保証 (write concern)
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()を実行します。