Database Reference
In-Depth Information
Enable sharding
In order to enable sharding for a collection of data, we should enable sharding for a data-
base first.
We should use the same mongo command-line environment to enable, deactivate, or modi-
fy database sharding. To enable sharding for a database, you can use following command:
sh.enableSharding(database)
We enable sharding for the database newdb . This is shown in the following screenshot:
If the enabling process is successful, you get the preceding message from the shell. Other-
wise, you will get an error. Now that we enabled sharding for the database, the next step is
to enable sharding for database collections.
The following screenshot shows the status of sharding after enabling sharding for the
newdb database:
As you can see in the preceding screenshot, the partitioned field is true for the database
newdb , but it's false for other databases.
Before jumping into enabling sharding for a collection of databases, you should consider
one or more shard keys. MongoDB will distribute the whole dataset using these keys in dif-
Search WWH ::




Custom Search