Skip to content

Instantly share code, notes, and snippets.

@manjeshpv
Created March 23, 2021 12:45
Show Gist options
  • Save manjeshpv/c421c16b00e40169c799765edc131822 to your computer and use it in GitHub Desktop.
Save manjeshpv/c421c16b00e40169c799765edc131822 to your computer and use it in GitHub Desktop.
var cur = db.getCollection('students').getIndexes();
for(var index1 in cur){
var next = cur[index1];
if(next["name"] == '_id_') {
continue;
}
var unique = next["unique"] ? true : false;
print("try{ db.getCollection(\"students\").createIndex("+JSON.stringify(next["key"])+",{unique:"+unique+"},{background:1})}catch(e){print(e)}");
}
@manjeshpv
Copy link
Author

https://stackoverflow.com/questions/26458457/mongodb-how-to-mongodump-only-indexes-to-another-mongodb-instance

mongo --quiet mongodb://localhost:27017/mydatabase dump-mongodb-index.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment