Skip to content

Instantly share code, notes, and snippets.

@mvasilenko
Last active March 6, 2019 07:27
Show Gist options
  • Save mvasilenko/c6551a66a5a99cae860400e1e583893c to your computer and use it in GitHub Desktop.
Save mvasilenko/c6551a66a5a99cae860400e1e583893c to your computer and use it in GitHub Desktop.
mongodb list all indexes for all databases
// List all indexes in all databases
db.getMongo().getDBNames().forEach(function(dbName) {
if (dbName != "admin" && dbName != "local" && dbName != "config") {
db.getSiblingDB(dbName).getCollectionNames().forEach(function(coll) {
db.getSiblingDB(dbName)[coll].getIndexes().forEach(function(index) {
if ("id" !== index.name) {
print("db.getSiblingDB('" + dbName + "')." + coll + ".ensureIndex(" + tojson(index.key) + ")");
}
});
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment