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允许您更改分片键:
You can reshard a collection by changing a collection's shard key.您可以通过更改集合的分片键来重新分片集合。You can refine a shard key by adding a suffix field or fields to the existing 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.如果集群不符合重新分级的标准,你应该优化分片键。
For more information on common performance and scaling issues and advice on how to fix them, read Troubleshoot Shard Keys.有关常见性能和扩展问题的更多信息以及如何解决这些问题的建议,请阅读分片键疑难解答。