Last active
November 21, 2020 05:48
-
-
Save jsjohnst/a6820ad3bdf9282507a4 to your computer and use it in GitHub Desktop.
Calculate total disk usage by MongoDB. storageSize is the actual used space, totalSize is the amount of disk space allocated.
This file contains 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 = db.getSiblingDB("admin"); | |
dbs = db.runCommand({ "listDatabases": 1 }).databases; | |
storageSize = 0; | |
totalSize = 0; | |
dbs.forEach(function(database) { | |
db = db.getSiblingDB(database.name); | |
stats = db.stats(); | |
storageSize += stats.storageSize; | |
totalSize += stats.fileSize; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment