The ideal shard key allows MongoDB to distribute documents evenly throughout the cluster while facilitating common query patterns. 理想的分片键允许MongoDB在整个集群中均匀分布文档,同时促进常见的查询模式。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:为了解决这些问题,MongoDB允许您更改分片键:
In MongoDB 4.2 and earlier, a document's shard key is immutable.在MongoDB 4.2及更早版本中,文档的shard键是不可变的。
For more information on common performance and scaling issues and advice on how to fix them, read Troubleshoot Shard Keys.有关常见性能和扩展问题的更多信息以及如何解决这些问题的建议,请阅读分片键疑难解答。