cleanupOrphaned doesn't seem to be doing what I want

MongoDB server version: 3.4.18

In the mongo sh, I am trying to run cleanupOrphaned and don’t really understand the results. All I can tell is it failed. I am not a mongo dba, just doing ops work for my team:

db.adminCommand( { cleanupOrphaned: "dbname.collectionname" } )

        "ok" : 0,
        "errmsg" : "ns: <dbname>.<collectionname>, min: { document_normalized_id: MinKey }, max: { document_normalized_id: \"-sb6Zhn9moNP_wIyvur7uTsWXvG5AtBmKsLgz2bg02o\" } is already being processed for deletion."

Hi @Philip_Izor

The message ... is already being processed for deletion means that the documents you’re trying to delete is already scheduled to be deleted (typically due to a chunk move), but the server haven’t been able to delete them yet for some reason (typically because a query is still holding a cursor on them). It doesn’t necessarily mean that there’s a problem.

Could you elaborate what you are trying to achieve? What was the motivation behind running the cleanupOrphaned command?

In another note, MongoDB 3.4 series was out of support since Jan 2020 (see Support Policy). If possible, I would encourage you to upgrade to a newer, supported MongoDB versions.

Best regards,

Thanks. I found a script that does this for us, too. We’re putting orphan mongo docs in our mongo exports. I found documents in the physical document collection export that are deleted from mongo. Yes, aware of the EOSL. Waiting on architecture and devs to decide if they are upgrading or migrating. Thank you so much!

Hi, can you share the script to perform cleanupOrphaned. TIA

Hi @Dheeraj_G,

The cleanupOrphaned command is an inbuilt server command.

Please consult the documentation for your version of MongoDB server for the relevant details, as there have been some changes between releases.

Quoting from the MongoDB 4.4 manual:

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 cleanupOrphaned command 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, cleanupOrphaned initiated the cleanup process for orphaned documents in a specified namespace and shard key range.