MongoDB Documentation, Release 3.0.4 3. Enable sharding for a collection by issuing the sh.shardCollection() method in the mongo shell. The method uses the following syntax: (a) The people collection in the records database using the shard key { "zipcode": 1, "name": 1 } . (b) The addresses collection in the people database using the shard key { "state": 1, "_id": 1 } . (c) The chairs collection in the assets database using the shard key { "type": 1, "_id": 1 } . (d) The alerts collection in the events database using the shard key { "_id": "hashed" } . 1. Compute a more ideal shard key in your application layer, and store this in all of your documents, potentially in the _id field. 2. Use a compound shard key that uses two or three values from all documents that provide the right mix of cardinality with scalable write operations and query isolation. 3. Determine that the impact of using a less than ideal shard key is insignificant in your use case, given: Considerations for Selecting Shard Keys Choosing a Shard Key For many collections there may be no single, naturally occurring key that possesses all the qualities of a good shard key. The following strategies may help construct a useful shard key from existing data: New in version 2.4. This shard key distributes documents by a hash of the value of the _id field. MongoDB computes the hash of the _id field for the hashed index (page 521), which should provide an even distribution of documents across a cluster. This shard key distributes documents by the value of the type field. If a number of documents have the same value for this field, then that chunk will be splittable (page 696) by the values of the _id field. This shard key distributes documents by the value of the state field. If a number of documents have the same value for this field, then that chunk will be splittable (page 696) by the values of the _id field. This shard key distributes documents by the value of the zipcode field. If a number of documents have the same value for this field, then that chunk will be splittable (page 696) by the values of the name field. In order, these operations shard: The following sequence of commands shards four collections: Replace the <database>.<collection> string with the full namespace of your database, which consists of the name of your database, a dot (e.g. . ), and the full name of the collection. The shard-key-pattern represents your shard key, which you specify in the same form as you would an index key pattern. sh.shardCollection("<database>.<collection>", shard-key-pattern) Example sh.shardCollection("records.people", { "zipcode": 1, "name": 1 } ) sh.shardCollection("people.addresses", { "state": 1, "_id": 1 } ) sh.shardCollection("assets.chairs", { "type": 1, "_id": 1 } ) sh.shardCollection("events.alerts", { "_id": "hashed" } ) Chapter 10. Sharding 694