-
-
Save chenyg0911/1c4626fbaaccbb3083fd7cc81418c401 to your computer and use it in GitHub Desktop.
List mongodb collections in descending order of size. Helpful for finding largest collections. First number is "size," second is "storageSize."
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 collectionNames = db.getCollectionNames(), | |
| stats = []; | |
| collectionNames.forEach(function (n) { | |
| stats.push(db[n].stats()); | |
| }); | |
| stats = stats.sort(function(a, b) { | |
| return b['size'] - a['size']; | |
| }); | |
| for (var c in stats) { | |
| print(stats[c]['ns'] + ": " + stats[c]['size'] + " (" + stats[c]['storageSize'] + ")"); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
With these functions you can get stats for the current (use) DB with a simple getStatsFor(db) call, or get stats for a named DB with getStatsFor(mgo.getDB('db_name'))