Created
December 16, 2016 09:05
-
-
Save dungmanh88/36bbe47aa7b444fec34ab2176bea7d0a to your computer and use it in GitHub Desktop.
Count collection in MongoDB
This file contains 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
vi mongodb_collection_size.js | |
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]['count'] + ":" + stats[c]['size'] + "(" + stats[c]['storageSize'] + ")"); } | |
mongo --port 27017 -u myUserAdmin -p abc123 --authenticationDatabase admin <DB> mongodb_collection_size.js |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment