Orphan Record Check On MongoDB

Run the command below after switch database.

use test;

db.collname.find( { }, { _id: 1, _id: 0 } ).hint( { _id: 1 } ).explain(true)

“chunkSkips” : 0, check the chunkskips row. If its greater than 0 that means there are some orphan records on mongodb.

—— Clear Orphan

var dbName: db.getName();

db.getCollectionNames().forEach(function(cName) {

    var nameSpace = dbName.concat(“.”+cName);

    result = db.runCommand({

      cleanupOrphaned: nameSpace

    });

    if (result.ok != 1)
      print(nameSpace + “:Unable to complete at this time: failure or timeout.”)

  });

Related Post

Leave a Reply

Your email address will not be published. Required fields are marked *