Skip to content

Instantly share code, notes, and snippets.

@sar-joshi
Created January 21, 2025 06:49
Show Gist options
  • Save sar-joshi/c8fc70ea94ba19414ebba2e691763594 to your computer and use it in GitHub Desktop.
Save sar-joshi/c8fc70ea94ba19414ebba2e691763594 to your computer and use it in GitHub Desktop.
// Create an object to store all index information
var clusterIndexes = {};
db.getMongo().getDBs().databases.forEach(function(database) {
if (database.name !== 'admin' && database.name !== 'local' && database.name !== 'config') {
clusterIndexes[database.name] = {};
var dbs = db.getSiblingDB(database.name);
dbs.getCollectionNames().forEach(function(collName) {
clusterIndexes[database.name][collName] = db.getCollection(collName).getIndexes();
});
}
});
// Print the final structured output
printjson(clusterIndexes);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment