Created
June 29, 2012 19:39
-
-
Save mpobrien/3020173 to your computer and use it in GitHub Desktop.
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
db.getSiblingDB("admin"); | |
var databases = null; | |
databases = db.runCommand("listDatabases"); | |
if(databases){ | |
for(var i=0;i<databases.databases.length;i++){ | |
//TODO skip if it's the admin database | |
var dbname = databases.databases[i].name; | |
var the_db = db.getSiblingDB(dbname) | |
databases.databases[i].stats = the_db.stats(); | |
databases.databases[i].collections = {} | |
var collections = the_db.getCollectionNames(); | |
for(var j=0;j<collections.length;j++){ | |
var collectionname = collections[j] | |
var collectioninfo = {} | |
var collection = the_db.getCollection(collectionname); | |
collectioninfo['stats'] = collection.stats() | |
collectioninfo['indexes'] = collection.getIndexes() | |
databases.databases[i].collections[collectionname] = collectioninfo | |
} | |
} | |
} | |
printjson(databases) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment