Skip to content

Instantly share code, notes, and snippets.

@jbutko
Last active March 7, 2019 08:09
Show Gist options
  • Save jbutko/184aefb30b5ae0b240994da89e19a4db to your computer and use it in GitHub Desktop.
Save jbutko/184aefb30b5ae0b240994da89e19a4db to your computer and use it in GitHub Desktop.
MongoDB: Check size of indexes in collection

list collection stats and check indexSizes

mongo
use collectionName
db.collectionName.stats()

copy indexSizes and assign it to variable (in devtools)

get sizes and total sizes:

function getCollectionTotalIndexSize(indexSizes) {
  const total = 0;
  Object.keys(indexSizes).forEach(key => console.log(key, indexSizes[key]/(1024*1024), total += indexSizes[key]/(1024*1024)));
  console.log('Total index size', total) // in MB
  return total;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment