Docs Menu
Docs Home
/
MongoDB Manual
/ /

Stop Unsharding a Collection

On this page

  • About this Task
  • Access Control
  • Steps
  • Learn More

You can stop unsharding a sharded collection with the abortUnshardCollection command.

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.

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.

  • 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.

  • abortUnshardCollection has a 5 minute minimum duration.

  • You must rebuild Atlas Search indexes after abortUnshardCollection runs.

  • 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.

If your deployment has access control enabled, the enableSharding role grants you access to run the abortUnshardCollection command.

1

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",
} )
2

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 }) }
],
... }
... }

Back

Unshard a Collection