Skip to content

Instantly share code, notes, and snippets.

@ixti
Last active May 4, 2021 08:37
Show Gist options
  • Save ixti/5359329 to your computer and use it in GitHub Desktop.
Save ixti/5359329 to your computer and use it in GitHub Desktop.
Small script that extracts all non-default indexes from MongoDB
rs.slaveOk();
db.getCollectionNames().forEach(function(coll) {
db[coll].getIndexes().forEach(function(index) {
if ("_id_" !== index.name) {
print("db." + coll + ".ensureIndex(" + tojson(index.key) + ")");
}
});
});
@cn73
Copy link

cn73 commented Nov 8, 2019

@nicothed thxs!

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