summaryrefslogtreecommitdiff
path: root/src/mongo/db/commands/dbcommands.cpp
diff options
context:
space:
mode:
authorYu Jin Kang Park <yujin.kang@mongodb.com>2022-03-16 10:34:26 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-03-16 11:28:15 +0000
commit539165defa601981015f0e89eba9a0d957c3b031 (patch)
treeb8f0129bc044b9829d6ef767ef3234d2c5ee672a /src/mongo/db/commands/dbcommands.cpp
parent6184015b89d61a890d11f682d172c8473b60b513 (diff)
downloadmongo-539165defa601981015f0e89eba9a0d957c3b031.tar.gz
SERVER-63255 Fix dbStats output for non-existing database to match existing database output fields
Diffstat (limited to 'src/mongo/db/commands/dbcommands.cpp')
-rw-r--r--src/mongo/db/commands/dbcommands.cpp26
1 files changed, 17 insertions, 9 deletions
diff --git a/src/mongo/db/commands/dbcommands.cpp b/src/mongo/db/commands/dbcommands.cpp
index 4a2caafb16d..2267c619692 100644
--- a/src/mongo/db/commands/dbcommands.cpp
+++ b/src/mongo/db/commands/dbcommands.cpp
@@ -663,22 +663,30 @@ public:
Database* db = autoDb.getDb();
if (!db) {
- // TODO: This preserves old behaviour where we used to create an empty database
- // metadata even when the database is accessed for read. Without this several
- // unit-tests will fail, which are fairly easy to fix. If backwards compatibility
- // is not needed for the missing DB case, we can just do the same that's done in
- // CollectionStats.
+ // This preserves old behavior where we used to create an empty database even when the
+ // database was accessed for a read. Changing this behavior would impact users that have
+ // learned to depend on it, so we continue to support it. Ensure that these fields match
+ // exactly the fields in `DatabaseImpl::getStats`.
+
result.appendNumber("collections", 0);
result.appendNumber("views", 0);
result.appendNumber("objects", 0);
result.append("avgObjSize", 0);
result.appendNumber("dataSize", 0);
result.appendNumber("storageSize", 0);
- result.appendNumber("totalSize", 0);
- result.appendNumber("indexes", 0);
- result.appendNumber("indexSize", 0);
+ if (includeFreeStorage) {
+ result.appendNumber("freeStorageSize", 0);
+ result.appendNumber("indexes", 0);
+ result.appendNumber("indexSize", 0);
+ result.appendNumber("indexFreeStorageSize", 0);
+ result.appendNumber("totalSize", 0);
+ result.appendNumber("totalFreeStorageSize", 0);
+ } else {
+ result.appendNumber("indexes", 0);
+ result.appendNumber("indexSize", 0);
+ result.appendNumber("totalSize", 0);
+ }
result.appendNumber("scaleFactor", scale);
- result.appendNumber("fileSize", 0);
if (!getGlobalServiceContext()->getStorageEngine()->isEphemeral()) {
result.appendNumber("fsUsedSize", 0);
result.appendNumber("fsTotalSize", 0);