Stop Unsharding a Collection
On this page
You can stop unsharding a sharded collection with the
abortUnshardCollection
command.
About this Task
To stop an in-progress unshardCollection
operation, run the
abortUnshardCollection
command.
Note
Unsharding is a write-intensive process which can generate increased rates of oplog. You may wish to:
set a fixed oplog size to prevent unbounded oplog growth.
increase the oplog size to minimize the chance that one or more secondary nodes becomes stale.
See the Replica Set Oplog documentation for more details.
Compatibility
You can perform this task on deployments hosted in the following environments:
MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud
Note
This task is not available on the Atlas Shared Tier or on Atlas Serverless.
MongoDB Enterprise: The subscription-based, self-managed version of MongoDB
MongoDB Community: The source-available, free-to-use, and self-managed version of MongoDB
Restrictions
abortUnshardCollection
can only be run on sharded clusters.abortUnshardCollection
can only operate on sharded collections.abortUnshardCollection
can only operate on a single collection at a time.You cannot make topology changes, such as adding or removing shards or transitioning between embedded and dedicated config servers, until
abortUnshardCollection
completes.You cannot run the following operations on the collection that is being unsharded while
abortUnshardCollection
is in progress:You cannot run the following operations on the cluster while
unshardCollection
is in progress:Index builds that occur while
abortUnshardCollection
is in progress might silently fail.Do not create indexes while
abortUnshardCollection
is in progress.Do not call
abortUnshardCollection
if there are ongoing index builds.
Access Control
If your deployment has access control enabled,
the enableSharding
role grants you access to run the
abortUnshardCollection
command.
Steps
Stop unsharding the collection
To stop unshard a collection, run the abortUnshardCollection
command.
The following example stops unshardCollection
operations on the us_accounts
in the sales
database:
db.adminCommand( { abortUnshardCollection: "sales.us_accounts", } )
Confirm the unsharding operation has been stopped
To confirm the unshardCollection
operation has been stopped,
use the sh.status()
method:
sh.status()
This sample output shows the collection as sharded with its original shard key:
collections: { 'sales.us_accounts': { shardKey: { account_number: 1 }, unique: false, balancing: true, chunkMetadata: [ { shard: 'shard-0', nChunks: 1 }, { shard: 'shard-1', nChunks: 1 } ], chunks: [ { min: { _id: MinKey() }, max: { _id: Long('0') }, 'on shard': 'shard-0', 'last modified': Timestamp({ t: 1, i: 0 }) }, { min: { _id: Long('0') }, max: { _id: MaxKey() }, 'on shard': 'shard-1', 'last modified': Timestamp({ t: 1, i: 1 }) } ], ... } ... }