mirror of
https://github.com/Mastermindzh/examples.git
synced 2024-11-23 12:02:05 +01:00
function to return all indexes on all databases
This commit is contained in:
parent
2c7822fb0e
commit
512549b267
14
mongo/get-indexes-on-all-databases.js
Normal file
14
mongo/get-indexes-on-all-databases.js
Normal 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);
|
Loading…
Reference in New Issue
Block a user