O'Reilly logo

MongoDB High Availability by Afshin Mehrabani

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Enable sharding

In order to enable sharding for a collection of data, we should enable sharding for a database first.

We should use the same mongo command-line environment to enable, deactivate, or modify 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:

Enable sharding

If the enabling process is successful, you get the preceding message from the shell. Otherwise, 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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required