Mongodb导出索引

分类: Mongodb
  1. var collectionList = db.getCollectionNames();
  2. for(var index in collectionList){
  3. var collection = collectionList[index];
  4. var cur = db.getCollection(collection).getIndexes();
  5. if(cur.length == 1){
  6. continue;
  7. }
  8. for(var index1 in cur){
  9. var next = cur[index1];
  10. if(next["key"]["_id"] == '1'){
  11. continue;
  12. }
  13. print(
  14. "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)}")}}
标签: NetCore

上一篇: Mongo查询用户的操作记录,去重后,仅在重复数据中取最新的一条

下一篇: 没有了

by 2023-08-07 23:49:06
篇笔记

学习笔记