Database Manual / Sharding / Administration / Unsharded Collections

Stop Unsharding a Collection

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 MongoDB Atlas Free or Flex Tiers.

Restrictions

Access Control

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

Steps

1

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

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

Learn More