mongodb 导出索引(表结构)

导出索引的脚本

兼容了唯一索引,和超时配置

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(
    "try{ db.getCollection(\""+collection+"\").ensureIndex("+JSON.stringify(next.key)+",{background:1, unique:" + (next.unique || false) + "" + (next.expireAfterSeconds > 0 ? ", expireAfterSeconds :" + next.expireAfterSeconds  : "") + " })}catch(e){print(e)}")}}


好用就给我点个赞吧

感谢

发布了17 篇原创文章 · 获赞 24 · 访问量 28万+

猜你喜欢

转载自blog.csdn.net/qq_22956867/article/details/102917841