Database Manual / Sharding / Administration / Unsharded Collections

Stop Unsharding a Collection停止分片集合

You can stop unsharding a sharded collection with the abortUnshardCollection command.您可以使用abortUnshardCollection命令停止取消对分片集合的设置。

About this Task关于此任务

To stop an in-progress unshardCollection operation, run the abortUnshardCollection command.要停止正在进行的unshardCollection操作,请运行abortUnhardCollection命令。

Note

Unsharding is a write-intensive process which can generate increased rates of oplog. You may wish to:未分片是一个写密集型过程,可以产生更高的oplog速率。您可能希望:

  • set a fixed oplog size to prevent unbounded oplog growth.设置固定的oplog大小以防止oplog无限增长。
  • increase the oplog size to minimize the chance that one or more secondary nodes becomes stale.增加oplog大小,以尽量减少一个或多个辅助节点过时的可能性。

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 Atlas Free或Flex层上不可用。

  • 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限制

  • 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.abortUnhardCollection完成之前,您无法进行拓扑更改,例如添加或删除分片或在嵌入式和专用配置服务器之间转换。
  • You cannot run the following operations on the collection that is being unsharded while abortUnshardCollection is in progress:aboutUnhardCollection正在进行时,您无法对未记录的集合运行以下操作:

  • You cannot run the following operations on the cluster while unshardCollection is in progress:unshardCollection正在进行时,您无法在群集上运行以下操作:

  • Index builds that occur while abortUnshardCollection is in progress might silently fail.abortUnhardCollection进行过程中发生的索引构建可能会悄无声息地失败。

    • Do not create indexes while abortUnshardCollection is in progress.abortUnhardCollection正在进行时,不要创建索引。
    • Do not call abortUnshardCollection if there are ongoing index builds.如果有正在进行的索引构建,请不要调用abortUnhardCollection

Access Control访问控制

If your deployment has access control enabled, the enableSharding role grants you access to run the abortUnshardCollection command.如果部署启用了访问控制,则enableSharding角色将授予您运行abortUnshardCollection命令的权限。

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:要停止对集合的取消分片,请运行abortUnshardCollection命令。以下示例停止了对销售数据库中us_accountsunsardCollection操作:

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:要确认unshardCollection操作已停止,请使用sh.status()方法:

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了解更多