定義
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: The fully managed service for MongoDB deployments in the cloud
重要
This command is not supported in M0 and Flex clusters. For more information, see Unsupported Commands.
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().
プライマリシャード
In general, you should not need to specify the primaryShard in the command. Instead, allow the balancer to select the primary shard.
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()を実行します。