Created
January 17, 2020 07:08
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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