美文网首页
MongDB 索引备份

MongDB 索引备份

作者: 嗚嗚雲 | 来源:发表于2022-11-30 14:37 被阅读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: "") + " })"
        )
    }
};

相关文章

网友评论

      本文标题:MongDB 索引备份

      本文链接:https://www.haomeiwen.com/subject/goqsfdtx.html