Created
May 27, 2011 14:11
-
-
Save RobinStamer/995319 to your computer and use it in GitHub Desktop.
Mongo shell script to scan database sizes.
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
| var s = {} | |
| var d = db.getMongo() | |
| var dbnames = d.getDBNames() | |
| for (var i = 0; i < dbnames.length; ++i) { | |
| var dbh = d.getDB(dbnames[i]) | |
| var cnames = dbh.getCollectionNames() | |
| s[dbnames[i]] = 0 | |
| //print("Scanning: " + dbnames[i]) | |
| for (var j = 0; j < cnames.length; ++j) { | |
| //print("Scanning: " + dbnames[i] + "." + cnames[j]) | |
| s[dbnames[i]] += dbh.getCollection(cnames[j]).dataSize() | |
| } | |
| } | |
| var total = 0 | |
| for (var k in s) { | |
| total += s[k] | |
| print(k + "\t" + s[k]) | |
| } | |
| print("total\t" + total) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment