Skip to content

Instantly share code, notes, and snippets.

@ebot
Created November 4, 2011 14:31
Show Gist options
  • Save ebot/1339448 to your computer and use it in GitHub Desktop.
Save ebot/1339448 to your computer and use it in GitHub Desktop.
Script that compresses all Mongo DBs except admin and local.
var hospitals = db.getMongo().getDBNames();
for(var h in hospitals){
if (hospitals[h] != "admin" && hospitals[h] != "local") {
var db = db.getMongo().getDB( hospitals[h] );
var size_before = ((db.stats()["dataSize"] / 60) / 60);
print( "Repairing DB " + db.getName() + " - " + size_before );
db.repairDatabase();
var size = ((db.stats()["dataSize"] / 60) / 60);
print( " Complete - " + size + ". Size reduced by " + ( size_before - size ) + " MB." );
}
}
print( "Repair Process Complete" );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment