function to return all indexes on all databases

This commit is contained in:
Rick van Lieshout 2021-09-08 10:44:53 +02:00
parent 2c7822fb0e
commit 512549b267

View File

@ -0,0 +1,14 @@
db = db.getSiblingDB("admin");
dbs = db.runCommand({ listDatabases: 1 }).databases;
var indexList = {};
dbs.forEach(function (database) {
db = db.getSiblingDB(database.name);
db.getCollectionNames().forEach(function (collection) {
indexes = db[collection].getIndexes();
indexList[`${database.name}/${collection}`] = indexes;
});
});
printjson(indexList);