Skip to content

Instantly share code, notes, and snippets.

@HugoPoi
Created January 30, 2019 16:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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