Database Manual / Sharding / Administration / Scaling Strategies

Consolidate Collection Data

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.

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.

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.

db.adminCommand({unshardCollection:"taxi.riders", toShard: "shard1"})
Diagram of a sharded collection distributed across two shards that is unsharded to contain the collection to a single shard.
click to enlarge

Learn More