-
-
Save locvfx/7f8d36a3a07f5c5f5f8221ff4369c7c7 to your computer and use it in GitHub Desktop.
Small script that extracts all non-default indexes from MongoDB
This file contains 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
rs.slaveOk(); | |
db.getCollectionNames().forEach(function(coll) { | |
db[coll].getIndexes().forEach(function(index) { | |
if ("_id_" !== index.name) { | |
print("db." + coll + ".ensureIndex(" + tojson(index.key) + ")"); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment