Skip to content

Instantly share code, notes, and snippets.

@locvfx
Forked from ixti/show-indexes.js
Created January 30, 2021 09:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save locvfx/7f8d36a3a07f5c5f5f8221ff4369c7c7 to your computer and use it in GitHub Desktop.
Save locvfx/7f8d36a3a07f5c5f5f8221ff4369c7c7 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) + ")");
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment