Skip to content

Instantly share code, notes, and snippets.

@shankara-n
Created January 17, 2020 07:08
Show Gist options
  • Save shankara-n/e8a7de84aee661d1e24f523db323fec9 to your computer and use it in GitHub Desktop.
Save shankara-n/e8a7de84aee661d1e24f523db323fec9 to your computer and use it in GitHub Desktop.
Mongo Collections Sizes. Just Edit the DB Name. For RPI, pip install pymongo==2.4.0
from pymongo import MongoClient
client = MongoClient()
db = client.voyagerDB
COL_WIDTH = 30
SMALL_COL_WIDTH = 13
totalStorageSize = 0
print("\nCOLLECTION".ljust(COL_WIDTH) + "\tSTORAGE_SIZE".ljust(SMALL_COL_WIDTH) + "\tCAPPED\n")
for coll in db.collection_names():
stats = db.command("collstats", coll)
totalStorageSize+=stats['storageSize']
if 'capped' in list(stats):
cap = True
else:
cap = False
print(coll.ljust(COL_WIDTH) + "\t" + str(stats['storageSize']).ljust(SMALL_COL_WIDTH) + "\t" + str(cap))
print("\nTOTAL STORAGE_SIZE : "+str(totalStorageSize))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment