MongDB 索引备份

2022-11-30  本文已影响0人  嗚嗚雲
var collectionList = db.getCollectionNames();
for (var index in collectionList) {
    var collection = collectionList[index];
    var cur = db.getCollection(collection).getIndexes();
    if (cur.length == 1) {
        continue;
    }
    for (var index1 in cur) {
        var next = cur[index1];
        if (next["key"]["_id"] == '1') {
            continue;
        }
print(" db.getCollection(\"" + collection + "\").ensureIndex(" + JSON.stringify(next.key) + ",{background:1, unique:" + (next.unique || false) + "" + (next.expireAfterSeconds > 0 ? ", expireAfterSeconds :" + next.expireAfterSeconds: "") + " })"
        )
    }
};
上一篇下一篇

猜你喜欢

热点阅读