Skip to content

Instantly share code, notes, and snippets.

@jgraglia
Last active August 29, 2015 14:04
Show Gist options
  • Save jgraglia/186c634bd6a280fe005d to your computer and use it in GitHub Desktop.
Save jgraglia/186c634bd6a280fe005d to your computer and use it in GitHub Desktop.
Mongo : export collections size to csv
// wget .... raw url ...
// mongo colstats_to_csv.js > `date +"%Y-%m-%d"`_stats.csv
rs.slaveOk();
print("db; col; total; storage; index; unused; unused KB; unused MB");
db._adminCommand("listDatabases").databases.forEach(function (d) {mdb = db.getSiblingDB(d.name); mdb.getCollectionNames().forEach(function(c) {idx = mdb[c].totalIndexSize(); s = mdb[c].storageSize(); t = mdb[c].totalSize(); print(d.name+"; "+c+"; "+t+";"+s+"; "+idx+"; "+(t-s-idx)+"; "+((t-s-idx)/1024)+"; "+((t-s-idx)/1024/1024));})})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment