浏览代码

Add MongoDB Compact All Commands

Not a fully running script but useful for compacting MongoDB databases.
master
Nate Bohman 3 年前
父节点
当前提交
a02b62c60b
签署人:: Nate Bohman <natrinicle@gmail.com> GPG 密钥 ID: C10546A54ABA1CE5
共有 1 个文件被更改,包括 15 次插入0 次删除
  1. +15
    -0
      mongo_compact_all

+ 15
- 0
mongo_compact_all 查看文件

@@ -0,0 +1,15 @@
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 });
});
}
});

正在加载...
取消
保存