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.

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