Prior to MongoDB v8.0, sharding a collection was an irreversible action. Starting in v8.0, you can unshard a collection to the shard of your choice.在MongoDB v8.0之前,对集合进行分片是不可逆的操作。从v8.0开始,您可以将集合取消到您选择的分片。
When to Unshard a Collection何时取消集合
The following scenarios benefit from moving unsharded collections across shards.以下场景受益于在分片之间移动未分片的集合。
Correcting unintentional sharding of a collection纠正集合的无意识分片
If you discover that sharding was unnecessary or causing performance issues, you can use the``unshardCollection`` command to rewrite the entire collection as an unsharded collection.如果您发现分片是不必要的或导致性能问题,可以使用“unshadCollection”命令将整个集合重写为未分片集合。
Simplifying zone-based isolation简化基于区域的隔离
If you use zones to keep a sharded collection on a single shard, you can now unshard the collection to reduce the complexity in your cluster.如果你使用区域将分片集合保存在单个分片上,你现在可以取消对集合的分片,以降低集群的复杂性。
Consolidating previously sharded small collections整合以前分片的小型集合
If you sharded small collections to efficiently utilize resources on multiple shards, you can unshard and move the collections to a shard of your choice. Doing so reduces the complexity of a deployment while maintaining appropriate resource allocation.如果你对小集合进行了分片,以有效地利用多个分片上的资源,你可以取消分片并将集合移动到你选择的分片上。这样做可以降低部署的复杂性,同时保持适当的资源分配。
Command Syntax命令语法
sh.unshardCollection("database.collection", "shardName")
The following example unshards the 以下示例取消了riders collection in the taxi database and moves the collection to shard1.taxi(出租车)数据库中riders(乘客)集合的遮挡,并将集合移动到shard1。
db.adminCommand({unshardCollection:"taxi.riders", toShard: "shard1"})