Created
October 21, 2020 09:23
-
-
Save karan9/420bb4a8f856f540fe54d980f25b7c9c to your computer and use it in GitHub Desktop.
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
function getStorageDetails() { | |
var db = this.db.getSiblingDB("admin"); | |
var totalIndexSize = 0, | |
totalStorageSize = 0, | |
totalDataSize = 0, | |
formatSize = 1024 * 1024 * 1024; | |
// List the databases | |
var dbs = db.runCommand({ listDatabases: 1 }); | |
// Loop over and get storage stats for each database | |
dbs.forEach(function(database) { | |
db = db.getSiblingDB(database.name); | |
print("\nDB: " + database.name); | |
print("dataSize: " + db.stats(formatSize).dataSize); | |
print("storageSize: " + db.stats(formatSize).storageSize); | |
print("indexSize: " + db.stats(formatSize).indexSize); | |
totalDataSize += db.stats(formatSize).dataSize; | |
totalStorageSize += db.stats(formatSize).storageSize; | |
totalIndexSize += db.stats(formatSize).indexSize; | |
}); | |
// Show total information | |
print("\nTotal:"); | |
print("dataSize: " + totalDataSize); | |
print("storageSize: " + totalStorageSize); | |
print("indexSize: " + totalIndexSize); | |
} | |
getStorageDetails(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment