Docs Menu

Docs HomeDevelop ApplicationsMongoDB Manual

Change a Shard Key

The ideal shard key allows MongoDB to distribute documents evenly throughout the cluster while facilitating common query patterns. A suboptimal shard key can lead to uneven data distribution and the following problems:

To address these issues, MongoDB allows you to change your shard key:

Data distribution fixes are most effective when you reshard a collection. If you want to improve data distribution and your cluster meets the criteria to reshard, you should reshard the collection instead of refining the shard key. If your cluster doesn't meet the criteria to reshard, you should refine the shard key.

In MongoDB 4.2 and earlier, a document's shard key is immutable.

For more information on common performance and scaling issues and advice on how to fix them, read Troubleshoot Shard Keys.

← Choose a Shard Key