Created
January 30, 2019 16:21
-
-
Save HugoPoi/cb6fe298cf65c36218158e1f41f0088e to your computer and use it in GitHub Desktop.
MongoDB Get collections storage sizes in GB sorted
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
(() => { | |
let datas = []; | |
db.getCollectionNames().forEach(colName => { | |
let stats = db.getCollection(colName).stats(); | |
datas.push({ | |
colName, | |
size : stats.storageSize, | |
humanSize: (stats.storageSize / (1024*1024*1024)) + ' GB' | |
}); | |
}) | |
return datas.sort((a,b) => { | |
return b.size - a.size; | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment