Created
August 23, 2024 17:00
-
-
Save Kuzmenko-Pavel/7f1043346d1f8d6c45d3e4bc2c2f4875 to your computer and use it in GitHub Desktop.
mongo add collection size
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
| db.getMongo().getDBNames().forEach(function(dbName) { | |
| if ("local" != dbName && "admin" != dbName && "system" != dbName) { | |
| var subject = db.getSiblingDB(dbName); | |
| subject.getCollectionNames().forEach(function (collectionName) { | |
| var stats = subject.runCommand({ collStats: collectionName, scale: 1024 * 1024 }); | |
| print('Database: ' + dbName + ' - Collection: ' + collectionName + | |
| ' - Storage Size: ' + stats.storageSize + ' MB' + | |
| ' - Free Storage Size: ' + stats.freeStorageSize + ' MB' + | |
| ' - Total Index Size: ' + stats.totalIndexSize + ' MB' + | |
| ' - Document Count: ' + stats.count + | |
| ' - Avg Object Size: ' + stats.avgObjSize + ' bytes'); | |
| }); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment