Database Manual / Sharding / Shard Keys

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:理想的分片键允许MongoDB在整个集群中均匀分布文档,同时促进常见的查询模式。次优分片键可能会导致数据分布不均和以下问题:

To address these issues, MongoDB allows you to change your shard key:为了解决这些问题,MongoDB允许您更改分片键:

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.如果集群不符合重新分级的标准,你应该优化分片键。

For more information on common performance and scaling issues and advice on how to fix them, read Troubleshoot Shard Keys.有关常见性能和扩展问题的更多信息以及如何解决这些问题的建议,请阅读分片键疑难解答