summaryrefslogtreecommitdiff
path: root/src/mongo/s/commands/cluster_list_databases_cmd.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/s/commands/cluster_list_databases_cmd.cpp')
-rw-r--r--src/mongo/s/commands/cluster_list_databases_cmd.cpp58
1 files changed, 28 insertions, 30 deletions
diff --git a/src/mongo/s/commands/cluster_list_databases_cmd.cpp b/src/mongo/s/commands/cluster_list_databases_cmd.cpp
index 5dea5e17120..a95dc29c972 100644
--- a/src/mongo/s/commands/cluster_list_databases_cmd.cpp
+++ b/src/mongo/s/commands/cluster_list_databases_cmd.cpp
@@ -95,7 +95,7 @@ public:
CommandHelpers::handleMarkKillOnClientDisconnect(opCtx);
IDLParserErrorContext ctx("listDatabases");
- auto cmd = ListDatabasesCommand::parse(ctx, cmdObj);
+ auto cmd = ListDatabases::parse(ctx, cmdObj);
auto* as = AuthorizationSession::get(opCtx->getClient());
// { nameOnly: bool } - Default false.
@@ -178,52 +178,50 @@ public:
bb.reset(new BSONObjBuilder());
}
- bb->appendNumber(s->getId().toString(), size);
+ bb->append(s->getId().toString(), size);
}
}
// Now that we have aggregated results for all the shards, convert to a response,
// and compute total sizes.
long long totalSize = 0;
+ std::vector<ListDatabasesReplyItem> items;
+ for (const auto& sizeEntry : sizes) {
+ const auto& name = sizeEntry.first;
+ const long long size = sizeEntry.second;
- {
- BSONArrayBuilder dbListBuilder(result.subarrayStart("databases"));
- for (const auto& sizeEntry : sizes) {
- const auto& name = sizeEntry.first;
- const long long size = sizeEntry.second;
-
- // Skip the local database, since all shards have their own independent local
- if (name == NamespaceString::kLocalDb)
- continue;
-
- if (authorizedDatabases && !as->isAuthorizedForAnyActionOnAnyResourceInDB(name)) {
- // We don't have listDatabases on the cluser or find on this database.
- continue;
- }
+ // Skip the local database, since all shards have their own independent local
+ if (name == NamespaceString::kLocalDb)
+ continue;
- BSONObjBuilder temp;
- temp.append("name", name);
- if (!nameOnly) {
- temp.appendNumber("sizeOnDisk", size);
- temp.appendBool("empty", size == 1);
- temp.append("shards", dbShardInfo[name]->obj());
+ if (authorizedDatabases && !as->isAuthorizedForAnyActionOnAnyResourceInDB(name)) {
+ // We don't have listDatabases on the cluser or find on this database.
+ continue;
+ }
- uassert(ErrorCodes::BadValue,
- str::stream() << "Found negative 'sizeOnDisk' in: " << name,
- size >= 0);
+ ListDatabasesReplyItem item(name);
+ if (!nameOnly) {
+ item.setSizeOnDisk(size);
+ item.setEmpty(size == 1);
+ item.setShards(dbShardInfo[name]->obj());
- totalSize += size;
- }
+ uassert(ErrorCodes::BadValue,
+ str::stream() << "Found negative 'sizeOnDisk' in: " << name,
+ size >= 0);
- dbListBuilder.append(temp.obj());
+ totalSize += size;
}
+
+ items.push_back(std::move(item));
}
+ ListDatabasesReply reply(items);
if (!nameOnly) {
- result.appendNumber("totalSize", totalSize);
- result.appendNumber("totalSizeMb", totalSize / (1024 * 1024));
+ reply.setTotalSize(totalSize);
+ reply.setTotalSizeMb(totalSize / (1024 * 1024));
}
+ reply.serialize(&result);
return true;
}