对集合分片
MongoDB分片命令
sh.shardCollection("shop.customer", { customerId: "hashed" })作用
按给定的分片键对指定集合分片。
适用场景
希望把不断增长的集合分布到多个分片上时。
注意
在 5.0+ 中可用 reshardCollection 更改分片键(在 4.4+ 中可用 refineCollectionShardKey 扩展),但由于要重新分布全部数据,开销很大;分片键选择不当会导致分布不均。
sh.shardCollection("shop.customer", { customerId: "hashed" })按给定的分片键对指定集合分片。
希望把不断增长的集合分布到多个分片上时。
在 5.0+ 中可用 reshardCollection 更改分片键(在 4.4+ 中可用 refineCollectionShardKey 扩展),但由于要重新分布全部数据,开销很大;分片键选择不当会导致分布不均。