var collectionList = db.getCollectionNames();for(var index in collectionList){var collection = collectionList[index];//兼容唯一索引情况,修改 2020年8月7日 16:50:32var cur = db.getCollection(collection).getIndexes();if(cur.length ==1){continue;}for(var index1 in cur){var next = cur[index1];//兼容唯一索引情况,修改 2020年8月7日 16:50:32if(next["key"]["_id"]=='1'){continue;}print("try{ db.getCollection(\""+collection+"\").ensureIndex("+JSON.stringify(next.key)+",{background:1, unique:"+(next.unique ||false)+" })}catch(e){print(e)}");}}
导出mongo索引碰到索引不一致的情况,想从A库中导出索引在B库执行得到执行语句后再在B库执行碰到索引不一致的情况,想从A库中导出索引在B库执行var collectionList = db.getCollectionNames();for(var index in collectionList){ var collection = collectionList[index]; ...