Browse Source

Add MongoDB Compact All Commands

Not a fully running script but useful for compacting MongoDB databases.
master
Nate Bohman 3 years ago
parent
commit
a02b62c60b
Signed by: Nate Bohman <natrinicle@gmail.com> GPG Key ID: C10546A54ABA1CE5
1 changed files with 15 additions and 0 deletions
  1. +15
    -0
      mongo_compact_all

+ 15
- 0
mongo_compact_all View File

https://gist.github.com/BlakeGardner/8548102

mongo "mongodb://admin:$(salt-call pillar.get mongodb:server:admin:password --out=newline_values_only)@localhost/?authSource=admin&ssl=false"


rs.secondaryOk();
db.getMongo().getDBNames().forEach(function(dbName) {
if (!(["local", "admin", "system"].includes(dbName))) {
var subject = db.getSiblingDB(dbName);
subject.getCollectionNames().forEach(function (collectionName) {
print('Compacting: ' +dbName + " - " + collectionName);
subject.runCommand({ compact: collectionName, force: true });
});
}
});

Loading…
Cancel
Save