Skip to content

Instantly share code, notes, and snippets.

@HugoPoi
Created January 30, 2019 16:21
Show Gist options
  • Save HugoPoi/cb6fe298cf65c36218158e1f41f0088e to your computer and use it in GitHub Desktop.
Save HugoPoi/cb6fe298cf65c36218158e1f41f0088e to your computer and use it in GitHub Desktop.
MongoDB Get collections storage sizes in GB sorted
(() => {
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