Database Manual / Reference / Database Commands / Sharding

cleanupOrphaned (database command数据库命令)

Important

Starting in MongoDB 6.0.3, run an aggregation using the $shardedDataDistribution stage to confirm no orphaned documents remain. 从MongoDB 6.0.3开始,使用$shardedDataDistribution阶段运行聚合,以确认没有孤立文档残留。For details, see Confirm No Orphaned Documents Remain.有关详细信息,请参阅确认无遗留孤立文档

Definition定义

cleanupOrphaned

Deprecated since version 8.0.自8.0版本起已弃用。

Use this command to wait for orphaned documents in a chunk range from a shard key's MinKey to its MaxKey for MongoDB to clean up a specified namespace from a majority of a shard's members.使用此命令等待从分片键的MinKey到其MaxKey的MongoDB块范围内的孤立文档,以从分片的大多数成员中清理指定的命名空间。

Note

This command does not directly clean up orphaned documents, it awaits the cleanup of orphans in a specified range. For more information on how MongoDB cleans up orphaned documents, see Sharded Cluster Balancer.此命令不直接清理孤立文档,它等待在指定范围内清理孤立文档。有关MongoDB如何清理孤立文档的更多信息,请参阅分片集群平衡器

To run, issue cleanupOrphaned in the admin database directly on the mongod instance that is the primary replica set member of the shard. You do not need to disable the balancer before running cleanupOrphaned.要运行,请直接在作为分片的主要副本集成员的mongod实例上的管理数据库中发出cleaneupOrphaned。在运行cleanupOrphaned之前,您不需要禁用平衡器。

Note

Do not run cleanupOrphaned on a mongos instance.不要在mongos实例上运行cleaneupOrphaned

Compatibility兼容性

This command is available in deployments hosted in the following environments:此命令在以下环境中托管的部署中可用:

  • MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud:云中MongoDB部署的完全托管服务

Important

This command is not supported in M0 and Flex clusters. For more information, see Unsupported Commands.M0和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的源代码可用、免费使用和自我管理版本

Syntax语法

The command has the following syntax:该命令具有以下语法:

db.runCommand(
{
cleanupOrphaned: "<database>.<collection>",
startingFromKey: <minimumShardKeyValue>, // deprecated
secondaryThrottle: <boolean>, // deprecated
writeConcern: <document> // deprecated
}
)

Command Fields命令字段

cleanupOrphaned has the following fields:具有以下字段:

Field字段Type类型Description描述
cleanupOrphanedstring字符串The namespace, i.e. both the database and the collection name, of the sharded collection for which to wait for cleanup of the orphaned data.等待孤立数据清理的分片集合的命名空间,即数据库和集合名称。

Behavior行为

Determine Range确定范围

The value of this field is not used to determine the bounds of the cleanup range. The cleanupOrphaned command waits until all orphaned documents in all ranges in the namespace are cleaned up from the shard before completing, regardless of the presence of or value of startingFromKey.此字段的值不用于确定清理范围的边界。cleaneupOrphaned命令会等待,直到命名空间中所有范围内的所有孤立文档都从分片中清理干净,然后再完成,无论startingFromKey是否存在或值如何。

Required Access所需访问权限

On systems running with authorization, you must have clusterAdmin privileges to run cleanupOrphaned.在使用authorization(授权)运行的系统上,您必须具有clusterAdmin权限才能运行cleaneupOrphaned

Output输出

Return Document返回文档

Each cleanupOrphaned command returns a document containing a subset of the following fields:每个cleaneupOrphaned命令都会返回一个包含以下字段子集的文档:

cleanupOrphaned.ok

Equal to 1 on success.成功等于1

A value of 1 indicates that either:1表示:

  • No orphaned documents remain in the cleanupOrphaned namespace on the shard, or分片上的cleaneupOrphaned命名空间中没有孤立的文档,或者
  • The collection referenced in the cleanupOrphaned namespace is not sharded.cleaneupOrphaned命名空间中引用的集合没有分片。

A value of 0 indicates that an error has occurred.值为0表示发生了错误。