Book Image

MongoDB High Availability

By : Afshin Mehrabani
Book Image

MongoDB High Availability

By: Afshin Mehrabani

Overview of this book

Table of Contents (17 chapters)
MongoDB High Availability
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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:

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 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...