Last active
March 6, 2019 07:27
-
-
Save mvasilenko/c6551a66a5a99cae860400e1e583893c to your computer and use it in GitHub Desktop.
mongodb list all indexes for all databases
This file contains hidden or 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
// 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