- Reference >
- Database Commands >
- Sharding Commands >
- cleanupOrphaned
cleanupOrphaned¶
On this page
Definition¶
-
cleanupOrphaned¶ Changed in version 4.4.
Starting in MongoDB 4.4, chunk migrations and orphaned document cleanup are more resilient to failover. The cleanup process automatically resumes in the event of a failover. You no longer need to run the
cleanupOrphanedcommand to clean up orphaned documents. Instead, use this command to wait for orphaned documents in a chunk range from a shard key’s minKey to its maxKey for a specified namespace to be cleaned up from a majority of a shard’s members.In MongoDB 4.2 and earlier,
cleanupOrphanedinitiated the cleanup process for orphaned documents in a specified namespace and shard key range.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.Note
Do not run
cleanupOrphanedon amongosinstance.cleanupOrphanedhas the following syntax:cleanupOrphanedhas 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. startingFromKeydocument Deprecated. Starting in MongoDB 4.4, the value of this field is not used to determine the bounds of the cleanup range. The
cleanupOrphanedcommand waits until all orphaned documents in all ranges are cleaned up from the shard before completing, regardless of the presence of or the value ofstartingFromKey.Note
The
mongodcontinues to validate that thestartingFromKeyvalue matches the shard key pattern, even though it is not used to determine the bounds of the cleanup range.secondaryThrottleboolean Deprecated. Starting in MongoDB 4.4, this field has no effect. writeConcerndocument Deprecated. Starting in MongoDB 4.4, this field has no effect. Orphaned documents are always cleaned up from a majority of a shard’s members ( { writeConcern: { w: "majority" } }) before thecleanupOrphanedcommand returns a response.
Behavior¶
Determine Range¶
Starting in MongoDB 4.4, 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.
Required Access¶
On systems running with authorization, you must have
clusterAdmin privileges to run cleanupOrphaned.
Output¶
Return Document¶
Each cleanupOrphaned command returns a document containing
a subset of the following fields:
-
cleanupOrphaned.ok¶ Equal to
1on success.A value of
1indicates that either:- No orphaned documents remain in the
cleanupOrphanednamespace on the shard, or - The collection referenced in the
cleanupOrphanednamespace is not sharded.
A value of
0indicates that an error has occurred.- No orphaned documents remain in the