Important
Starting in MongoDB 6.0.3, run an aggregation using the 从MongoDB 6.0.3开始,使用$shardedDataDistribution stage to confirm no orphaned documents remain. $shardedDataDistribution阶段运行聚合,以确认没有孤立文档残留。For details, see Confirm No Orphaned Documents Remain.有关详细信息,请参阅确认无遗留孤立文档。
Definition定义
cleanupOrphanedDeprecated since version 8.0.自8.0版本起已弃用。Use this command to wait for orphaned documents in a chunk range from a shard key's使用此命令等待从分片键的MinKeyto itsMaxKeyfor 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要运行,请直接在作为分片的主要副本集成员的cleanupOrphanedin theadmindatabase directly on themongodinstance that is the primary replica set member of the shard. You do not need to disable the balancer before runningcleanupOrphaned.mongod实例上的管理数据库中发出cleaneupOrphaned。在运行cleanupOrphaned之前,您不需要禁用平衡器。Note
Do not run不要在cleanupOrphanedon amongosinstance.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:具有以下字段:
cleanupOrphaned |
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.okEqual to成功等于1on success.1。A value of值1indicates that either:1表示:No orphaned documents remain in the分片上的cleanupOrphanednamespace on the shard, orcleaneupOrphaned命名空间中没有孤立的文档,或者The collection referenced in thecleanupOrphanednamespace is not sharded.cleaneupOrphaned命名空间中引用的集合没有分片。
A value of值为0indicates that an error has occurred.0表示发生了错误。