Created
March 23, 2021 12:45
-
-
Save manjeshpv/c421c16b00e40169c799765edc131822 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)}"); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://stackoverflow.com/questions/26458457/mongodb-how-to-mongodump-only-indexes-to-another-mongodb-instance