Database Manual / Sharding

Sharding Reference分片参考

Sharding Methods in mongoshmongosh中的分片方法

Name名称Description描述
convertShardKeyToHashed()Returns the hashed value for the input.返回输入的哈希值。
db.checkMetadataConsistency()

Checks the cluster or database for inconsistent sharding metadata.检查群集或数据库是否存在不一致的分片元数据。

New in version 7.0.在版本7.0中新增。

db.collection.checkMetadataConsistency()

Checks the collection for inconsistent sharding metadata.检查集合中是否存在不一致的分片元数据。

New in version 7.0.在版本7.0中新增。

sh.abortMoveCollection()

Stops an in-progress moveCollection operation.停止正在进行的moveCollection操作。

New in version 8.0.在版本8.0中新增。

sh.abortReshardCollection()

Aborts a resharding operation.中止重新分片操作

New in version 5.0.在版本5.0中新增。

sh.addShard()Adds a shard to a sharded cluster.分片添加到分片集群。
sh.addShardTag()This method aliases to sh.addShardToZone().此方法别名为sh.addShardToZone()
sh.addShardToZone()Associates a shard to a zone. Supports configuring zones in sharded clusters.将一个分片与一个区域相关联。支持在分片集群中配置区域
sh.addTagRange()This method aliases to sh.updateZoneKeyRange().此方法别名为sh.updateZoneKeyRange()
sh.balancerCollectionStatus()Returns information on whether the chunks of a sharded collection are balanced.返回有关分片集合的块是否平衡的信息。
sh.checkMetadataConsistency()

Checks the cluster for inconsistent sharding metadata.检查集群中是否存在不一致的分片元数据。

New in version 7.0.在版本7.0中新增。

sh.commitReshardCollection()

Forces a resharding operation to block writes and complete.强制执行重新分片操作以阻止写入并完成。

New in version 5.0.在版本5.0中新增。

sh.disableAutoMerger()

Disables automatic chunk merges for a namespace.禁用命名空间的自动合并。

New in version 7.0.在版本7.0中新增。

sh.disableAutoSplit()

Disables auto-splitting for the sharded cluster.禁用分片群集的自动拆分。

Starting in MongoDB 6.0.3, automatic chunk splitting is not performed. This is because of balancing policy improvements. Auto-splitting commands still exist, but do not perform an operation.从MongoDB 6.0.3开始,不执行自动块分割。这是因为平衡了政策的改进。自动拆分命令仍然存在,但不执行操作。

sh.disableBalancing()Disable balancing on a single collection in a sharded database. Does not affect balancing of other collections in a sharded cluster.禁用分片数据库中单个集合的平衡。不会影响分片集群中其他集合的平衡。
sh.enableAutoMerger()

Enables automatic chunk merges for a namespace.启用命名空间的自动合并。

New in version 7.0.在版本7.0中新增。

sh.enableAutoSplit()

Enables auto-splitting for the sharded cluster.启用分片群集的自动拆分。

Starting in MongoDB 6.0.3, automatic chunk splitting is not performed. This is because of balancing policy improvements. Auto-splitting commands still exist, but do not perform an operation.从MongoDB 6.0.3开始,不执行自动块分割。这是因为平衡了政策的改进。自动拆分命令仍然存在,但不执行操作。

sh.enableBalancing()Activates the sharded collection balancer process if previously disabled using sh.disableBalancing().如果之前使用sh.disableBalancing()禁用了分片集合平衡器进程,则激活该进程。
sh.enableSharding()Creates a database.创建数据库。
sh.getBalancerState()Returns a boolean to report if the balancer is currently enabled.返回一个布尔值,用于报告平衡器当前是否已启用。
sh.getShardedDataDistribution()Returns data distribution information for sharded collections. 返回分片集合的数据分布信息。sh.getShardedDataDistribution() is a shell helper method for the $shardedDataDistribution aggregation pipeline stage.sh.getShardedDataDistribution()$shardedDataDistribution聚合管道阶段的shell辅助方法。
sh.help()Returns help text for the sh methods.返回sh方法的帮助文本。
sh.isBalancerRunning()Returns a document describing the status of the balancer.返回一个描述平衡器状态的文档。
sh.isConfigShardEnabled()Returns whether a cluster has a config shard. 返回集群是否有配置分片If it does, sh.isConfigShardEnabled() also returns host and tag information.如果是这样,sh.isConfigShardEnabled()也会返回主机和标签信息。
sh.listShards()Returns an array of documents describing the shards in a sharded cluster.返回描述分片集群中分片的文档数组。
sh.moveChunk()Migrates a chunk in a sharded cluster.迁移分片集群中的
sh.moveCollection()Moves a single unsharded collection to a different shard.将单个未分片集合移动到其他分片。
sh.moveRange()Move ranges between shards.在分片之间移动范围。
sh.removeRangeFromZone()Removes an association between a range of shard keys and a zone. Supports configuring zones in sharded clusters.删除一系列分片键和区域之间的关联。支持在分片集群中配置区域
sh.removeShardTag()This method aliases to sh.removeShardFromZone().此方法别名为sh.removeShardFromZone()
sh.removeShardFromZone()Removes the association between a shard and a zone. Use to manage zone sharding.删除分片和区域之间的关联。用于管理区域分片
sh.removeTagRange()This method aliases to sh.removeRangeFromZone().此方法别名为sh.removeRangeFromZone()
sh.reshardCollection()

Initiates a resharding operation to change the shard key for a collection, changing the distribution of your data.启动重新分片操作以更改集合的分片键,从而更改数据的分布。

New in version 5.0.在版本5.0中新增。

sh.setBalancerState()Enables or disables the balancer which migrates chunks between shards.启用或禁用在分片之间迁移平衡器
sh.shardAndDistributeCollection()

Shards a collection and immediately redistributes the data using the provided shard key.对集合进行分片,并立即使用提供的分片键重新分发数据。

New in version 8.0.在版本8.0中新增。

sh.shardCollection()Enables sharding for a collection.为集合启用分片。
sh.splitAt()Divides an existing chunk into two chunks using a specific value of the shard key as the dividing point.使用分片键的特定值作为分割点,将现有分为两个块。
sh.splitFind()Divides an existing chunk that contains a document matching a query into two approximately equal chunks.将包含与查询匹配的文档的现有块划分为两个大致相等的
sh.startAutoMerger()

Enables the AutoMerger.启用自动合并

New in version 7.0.在版本7.0中新增。

sh.startBalancer()Enables the balancer and waits for balancing to start.启用平衡器并等待平衡开始。
sh.status()Reports on the status of a sharded cluster, as db.printShardingStatus().报告分片集群的状态,如db.printShardingStatus()
sh.stopAutoMerger()

Disables the AutoMerger.禁用自动合并

New in version 7.0.在版本7.0中新增。

sh.stopBalancer()Disables the balancer and waits for any in progress balancing rounds to complete.禁用平衡器并等待任何正在进行的平衡轮完成。
sh.unshardCollection()

Unshards an existing sharded collection and moves the collection data onto a single shard. When you unshard a collection, the collection cannot be partitioned across multiple shards and the shard key is removed.解开现有的分片集合,并将集合数据移动到单个分片上。当您取消对集合的分区时,该集合不能跨多个分片进行分区,并且分片键将被删除。

New in version 8.0.在版本8.0中新增。

sh.updateZoneKeyRange()Associates a range of shard keys to a zone. Supports configuring zones in sharded clusters.将一系列分片键与一个区域相关联。支持在分片集群中配置区域
sh.waitForBalancer()Internal. Waits for the balancer state to change.内部。等待平衡器状态更改。
sh.waitForBalancerOff()Internal. Waits until the balancer stops running.内部。等待平衡器停止运行。
sh.waitForPingChange()Internal. Waits for a change in ping state from one of the mongos in the sharded cluster.内部。等待分片集群中某个mongoping状态发生变化。

Sharding Database Commands分片数据库命令

The following database commands support sharded clusters.以下数据库命令支持分片集群

Name名称Description描述
abortMoveCollection

Stops an in-progress moveCollection operation.停止正在进行的moveCollection操作。

New in version 8.0.在版本8.0中新增。

abortReshardCollection

Aborts a resharding operation.中止重新分片操作

New in version 5.0.在版本5.0中新增。

addShardAdds a shard to a sharded cluster.分片添加到分片集群
addShardToZoneAssociates a shard with a zone. Supports configuring zones in sharded clusters.将分片与区域关联。支持在分片集群中配置区域
balancerCollectionStatusReturns information on whether the chunks of a sharded collection are balanced.返回有关分片集合的块是否平衡的信息。
balancerStartStarts a balancer thread.启动平衡器线程。
balancerStatusReturns information on the balancer status.返回有关平衡器状态的信息。
balancerStopStops the balancer thread.停止平衡器线程。
clearJumboFlagClears the jumbo flag for a chunk.清除大块的jumbo标志。
cleanupReshardCollection

Cleans up a failed resharding operation.清理失败的重新分片操作

New in version 5.0.在版本5.0中新增。

commitReshardCollection

Forces a resharding operation to block writes and complete.强制执行重新分片操作以阻止写入并完成。

New in version 5.0.在版本5.0中新增。

enableShardingEnables sharding on a specific database.在特定数据库上启用分片。
flushRouterConfigForces a mongod / mongos instance to update its cached routing metadata.强制mongod/mongos实例更新其缓存的路由元数据。
getShardMapInternal command that reports on the state of a sharded cluster.报告分片集群状态的内部命令。
isdbgridVerifies that a process is a mongos.验证进程是否为mongos
listShardsReturns a list of configured shards.返回已配置分片的列表。
moveChunkInternal command that migrates chunks between shards.在分片之间迁移块的内部命令。
moveCollectionMoves a single unsharded collection to a different shard.将单个未分片集合移动到其他分片。
movePrimaryReassigns the primary shard when removing a shard from a sharded cluster.从分片集群中删除分片时,重新分配主分片
moveRangeCommand that migrates ranges between shards.在分片之间迁移范围的命令。
mergeChunksProvides the ability to combine chunks on a single shard.提供在单个分片上组合块的能力。
removeShardStarts the process of removing a shard from a sharded cluster.开始从分片集群中删除分片的过程。
removeShardFromZoneRemoves the association between a shard and a zone. Supports configuring zones in sharded clusters.删除分片和区域之间的关联。支持在分片集群中配置区域
reshardCollection

Initiates a resharding operation to change the shard key for a collection, changing the distribution of your data.启动重新分片操作以更改集合的分片键,从而更改数据的分布。

New in version 5.0.在版本5.0中新增。

shardCollectionEnables the sharding functionality for a collection, allowing the collection to be sharded.为集合启用分片功能,允许对集合进行分片。
shardingStateReports whether the mongod is a member of a sharded cluster.报告mongod是否是分片集群的成员。
splitCreates a new chunk.创建新
unsetShardingRemoved in MongoDB 5.0.在MongoDB 5.0中删除。 Internal command that affects connections between instances in a MongoDB deployment.影响MongoDB部署中实例之间连接的内部命令。
updateZoneKeyRangeAdds or removes the association between a range of sharded data and a zone. 添加或删除分片数据范围与区域之间的关联。Supports configuring zones in sharded clusters.支持在分片集群中配置区域

Reference Documentation参考文档

Operational Restrictions操作限制
Requirement for deploying a sharded cluster部署分片集群的要求
Troubleshoot Sharded Clusters分片群集故障排除
Common strategies for troubleshooting sharded cluster deployments.分片集群部署故障排除的常见策略。
Config Database配置数据库
Complete documentation of the content of the local database that MongoDB uses to store sharded cluster metadata.MongoDB用于存储分片集群元数据的local数据库内容的完整文档。