Created
August 23, 2024 16:42
-
-
Save Kuzmenko-Pavel/865790a30ba0e9db145c68629de07a67 to your computer and use it in GitHub Desktop.
mongo compact all db and collection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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