Last active
August 29, 2015 14:16
-
-
Save mattparlane/a8c39260f034eedec820 to your computer and use it in GitHub Desktop.
MongoDB/WiredTiger - compress all collections in a database.
This file contains 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
colls = db.getCollectionNames(); | |
for (var i = 0; i < colls.length; i++) { | |
var coll = colls[i]; | |
if (coll.match(/^system/)) continue; | |
if (coll.match(/_old$/) || coll.match(/_comp$/)) { | |
db[coll].drop(); | |
continue; | |
} | |
stats = db[coll].stats(); | |
if (stats.wiredTiger.creationString.match(/snappy/)) continue; | |
db.createCollection(coll + "_comp", {storageEngine: {wiredTiger: {configString: 'block_compressor=snappy'}}}); | |
db[coll].find().forEach(function(o) { | |
db[coll + "_comp"].save(o); | |
}); | |
db[coll].renameCollection(coll + "_old"); | |
db[coll + "_comp"].renameCollection(coll); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Make sure you don't already have collections where
name =~ /_old$/ || name =~ /_comp$/
, or they will be deleted.