Docs Menu
Docs Home
/
Database Manual
/ / /

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.

The following scenarios benefit from moving unsharded collections across shards.

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.

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.

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.

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
  • Unshard a Collection

Back

Distribute Collection Data

On this page