Skip to content

Commit

Permalink
fix(mongo): db.totalSize can be undefined, fix #568 (#592)
Browse files Browse the repository at this point in the history
  • Loading branch information
MaikoTan authored Apr 5, 2022
1 parent b4dd6e6 commit 1fad834
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion plugins/database/mongo/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,14 @@ class MongoDatabase extends Database {

async stats() {
// https://docs.mongodb.com/manual/reference/command/dbStats/#std-label-dbstats-output
const [{ totalSize }, tables] = await Promise.all([
const [stats, tables] = await Promise.all([
this.db.stats(),
this._collStats(),
])
// While MongoDB's document above says that the `stats.totalSize` is the sum of
// `stats.dataSize` and `stats.storageSize`, it's actually `undefined` in some cases.
// So we have to calculate it manually.
const totalSize = stats.indexSize + stats.storageSize
return { size: totalSize, tables }
}

Expand Down

0 comments on commit 1fad834

Please sign in to comment.