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限制
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.abortUnhardCollection完成之前,您无法进行拓扑更改,例如添加或删除分片或在嵌入式和专用配置服务器之间转换。You cannot run the following operations on the collection that is being unsharded while当abortUnshardCollectionis in progress:aboutUnhardCollection正在进行时,您无法对未记录的集合运行以下操作:You cannot run the following operations on the cluster while当unshardCollectionis in progress:unshardCollection正在进行时,您无法在群集上运行以下操作:Index builds that occur while在abortUnshardCollectionis in progress might silently fail.abortUnhardCollection进行过程中发生的索引构建可能会悄无声息地失败。Do not create indexes while在abortUnshardCollectionis in progress.abortUnhardCollection正在进行时,不要创建索引。Do not call如果有正在进行的索引构建,请不要调用abortUnshardCollectionif 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步骤
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_accounts的unsardCollection操作:
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: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 }) }
],
... }
... }