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:云中MongoDB部署的完全托管服务
Note
This task is not available on the MongoDB Atlas Free or Flex Tiers.
- MongoDB Enterprise
: The subscription-based, self-managed version of MongoDB:MongoDB的基于订阅的自我管理版本 - MongoDB Community
: The source-available, free-to-use, and self-managed version of MongoDB:MongoDB的源代码可用、免费使用和自我管理版本
Restrictions限制
abortUnshardCollectioncan only be run on sharded clusters.abortUnshardCollectioncan only operate on sharded collections.abortUnshardCollectioncan 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
abortUnshardCollectioncompletes. You cannot run the following operations on the collection that is being unsharded while
abortUnshardCollectionis in progress:You cannot run the following operations on the cluster while
unshardCollectionis in progress:Index builds that occur while
abortUnshardCollectionis in progress might silently fail.- Do not create indexes while
abortUnshardCollectionis in progress. - Do not call
abortUnshardCollectionif there are ongoing index builds.
- Do not create indexes while
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 }) }
],
... }
... }
Learn More了解更多