-
-
Save paulozullu/2fa3b3ee96aab994db39effce3874e1b to your computer and use it in GitHub Desktop.
Compact all collections inside of a MongoDB database
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
// This script loops though the list of collection names in a MongoDB and runs the compact operation on them | |
// Simply paste this into the Mongo shell | |
use testDbName; | |
db.getCollectionNames().forEach(function (collectionName) { | |
print('Compacting: ' + collectionName); | |
db.runCommand({ compact: collectionName }); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment