Skip to content

Instantly share code, notes, and snippets.

@Kuzmenko-Pavel
Created August 23, 2024 16:42
Show Gist options
  • Select an option

  • Save Kuzmenko-Pavel/865790a30ba0e9db145c68629de07a67 to your computer and use it in GitHub Desktop.

Select an option

Save Kuzmenko-Pavel/865790a30ba0e9db145c68629de07a67 to your computer and use it in GitHub Desktop.
mongo compact all db and collection
// rs.slaveOk();
db.getMongo().getDBNames().forEach(function(dbName) {
if ("local" != dbName && "admin" != dbName && "system" != dbName) {
var subject = db.getSiblingDB(dbName);
subject.getCollectionNames().forEach(function (collectionName) {
print('Compacting: ' +dbName + " - " + collectionName);
subject.runCommand({ compact: collectionName });
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment