Skip to content

Instantly share code, notes, and snippets.

@Kuzmenko-Pavel
Created August 23, 2024 17:00
Show Gist options
  • Select an option

  • Save Kuzmenko-Pavel/7f1043346d1f8d6c45d3e4bc2c2f4875 to your computer and use it in GitHub Desktop.

Select an option

Save Kuzmenko-Pavel/7f1043346d1f8d6c45d3e4bc2c2f4875 to your computer and use it in GitHub Desktop.
mongo add collection size
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