summaryrefslogtreecommitdiff
path: root/src/mongo/s/commands/cluster_list_databases_cmd.cpp
diff options
context:
space:
mode:
authorGeert Bosch <geert@mongodb.com>2017-02-16 12:49:36 -0500
committerGeert Bosch <geert@mongodb.com>2017-03-03 12:46:02 -0500
commit1349ae75590dee95475c5098ec6babce415ebfff (patch)
tree9e6f87db38b4e1312fbdc3636d6bb1863d9ec780 /src/mongo/s/commands/cluster_list_databases_cmd.cpp
parent114b2b05936e6e88e986baea38c3bd21cdffaefa (diff)
downloadmongo-1349ae75590dee95475c5098ec6babce415ebfff.tar.gz
SERVER-3181 Add nameOnly option to listDatabases
(cherry picked from commit fff6d490ce43a6d3952cf2352f81c524b20e6f49)
Diffstat (limited to 'src/mongo/s/commands/cluster_list_databases_cmd.cpp')
-rw-r--r--src/mongo/s/commands/cluster_list_databases_cmd.cpp13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/mongo/s/commands/cluster_list_databases_cmd.cpp b/src/mongo/s/commands/cluster_list_databases_cmd.cpp
index 2ae555e8593..82d519b52bb 100644
--- a/src/mongo/s/commands/cluster_list_databases_cmd.cpp
+++ b/src/mongo/s/commands/cluster_list_databases_cmd.cpp
@@ -89,6 +89,8 @@ public:
int options,
std::string& errmsg,
BSONObjBuilder& result) {
+ const bool nameOnly = cmdObj["nameOnly"].trueValue();
+
map<string, long long> sizes;
map<string, unique_ptr<BSONObjBuilder>> dbShardInfo;
@@ -154,9 +156,11 @@ public:
BSONObjBuilder temp;
temp.append("name", name);
- temp.appendNumber("sizeOnDisk", size);
- temp.appendBool("empty", size == 1);
- temp.append("shards", dbShardInfo[name]->obj());
+ if (!nameOnly) {
+ temp.appendNumber("sizeOnDisk", size);
+ temp.appendBool("empty", size == 1);
+ temp.append("shards", dbShardInfo[name]->obj());
+ }
dbListBuilder.append(temp.obj());
}
@@ -171,6 +175,9 @@ public:
dbListBuilder.done();
+ if (nameOnly)
+ return true;
+
// Compute the combined total size based on the response we've built so far.
long long totalSize = 0;
for (auto&& dbElt : result.asTempObj()["databases"].Obj()) {