Skip to content

Instantly share code, notes, and snippets.

@vitorpacheco
Forked from ixti/show-indexes.js
Created February 4, 2019 13:57
Show Gist options
  • Save vitorpacheco/e0c5caf10b9bd9dcda42fb780f611faa to your computer and use it in GitHub Desktop.
Save vitorpacheco/e0c5caf10b9bd9dcda42fb780f611faa 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 + ".createIndex(" + tojson(index.key) + ")");
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment