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)}")}}


好用就給點個讚唄! 白嫖不是好同志啊~

感謝

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章