summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mongo/db/commands/SConscript12
-rw-r--r--src/mongo/db/commands/list_databases.cpp24
-rw-r--r--src/mongo/db/commands/list_databases.idl35
-rw-r--r--src/mongo/s/commands/SConscript1
-rw-r--r--src/mongo/s/commands/cluster_list_databases_cmd.cpp6
5 files changed, 64 insertions, 14 deletions
diff --git a/src/mongo/db/commands/SConscript b/src/mongo/db/commands/SConscript
index ec5b2339ae6..52c15bb7802 100644
--- a/src/mongo/db/commands/SConscript
+++ b/src/mongo/db/commands/SConscript
@@ -204,6 +204,17 @@ env.Library(
],
)
+env.Library(
+ target='list_databases_command',
+ source=[
+ env.Idlc('list_databases.idl')[0],
+ ],
+ LIBDEPS_PRIVATE=[
+ '$BUILD_DIR/mongo/base',
+ '$BUILD_DIR/mongo/idl/idl_parser',
+ ],
+)
+
# Commands that are present in both mongod and embedded
env.Library(
target="standalone",
@@ -254,6 +265,7 @@ env.Library(
'fsync_locked',
'kill_common',
'list_collections_filter',
+ 'list_databases_command',
'write_commands_common',
],
)
diff --git a/src/mongo/db/commands/list_databases.cpp b/src/mongo/db/commands/list_databases.cpp
index d736b4b5737..59e29c5f600 100644
--- a/src/mongo/db/commands/list_databases.cpp
+++ b/src/mongo/db/commands/list_databases.cpp
@@ -35,6 +35,7 @@
#include "mongo/db/catalog_raii.h"
#include "mongo/db/client.h"
#include "mongo/db/commands.h"
+#include "mongo/db/commands/list_databases_gen.h"
#include "mongo/db/concurrency/write_conflict_exception.h"
#include "mongo/db/matcher/expression.h"
#include "mongo/db/operation_context.h"
@@ -87,27 +88,24 @@ public:
bool run(OperationContext* opCtx,
const string& dbname,
- const BSONObj& jsobj,
+ const BSONObj& cmdObj,
BSONObjBuilder& result) final {
+ IDLParserErrorContext ctx("listDatabases");
+ auto cmd = ListDatabasesCommand::parse(ctx, cmdObj);
+
+ const bool nameOnly = cmd.getNameOnly();
+
// Parse the filter.
std::unique_ptr<MatchExpression> filter;
- if (auto filterElt = jsobj[kFilterField]) {
- if (filterElt.type() != BSONType::Object) {
- uasserted(ErrorCodes::TypeMismatch,
- str::stream() << "Field '" << kFilterField
- << "' must be of type Object in: "
- << jsobj);
- }
+ if (auto filterObj = cmd.getFilter()) {
// The collator is null because database metadata objects are compared using simple
// binary comparison.
const CollatorInterface* collator = nullptr;
boost::intrusive_ptr<ExpressionContext> expCtx(new ExpressionContext(opCtx, collator));
- auto statusWithMatcher =
- MatchExpressionParser::parse(filterElt.Obj(), std::move(expCtx));
- uassertStatusOK(statusWithMatcher.getStatus());
- filter = std::move(statusWithMatcher.getValue());
+ auto matcher =
+ uassertStatusOK(MatchExpressionParser::parse(filterObj.get(), std::move(expCtx)));
+ filter = std::move(matcher);
}
- bool nameOnly = jsobj[kNameOnlyField].trueValue();
vector<string> dbNames;
StorageEngine* storageEngine = getGlobalServiceContext()->getStorageEngine();
diff --git a/src/mongo/db/commands/list_databases.idl b/src/mongo/db/commands/list_databases.idl
new file mode 100644
index 00000000000..b08cda90cd3
--- /dev/null
+++ b/src/mongo/db/commands/list_databases.idl
@@ -0,0 +1,35 @@
+# Copyright (C) 2018 MongoDB Inc.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License, version 3,
+# as published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+global:
+ cpp_namespace: "mongo"
+
+
+imports:
+ - "mongo/idl/basic_types.idl"
+
+
+commands:
+ listDatabasesCommand:
+ description: "listDatabases Command"
+ namespace: ignored
+ fields:
+ nameOnly:
+ description: "Return just the database name without metadata"
+ type: safeBool
+ default: false
+ filter:
+ description: "Filter description to limit results"
+ type: object
+ optional: true
diff --git a/src/mongo/s/commands/SConscript b/src/mongo/s/commands/SConscript
index b1892e0a43e..9bacfae7fe2 100644
--- a/src/mongo/s/commands/SConscript
+++ b/src/mongo/s/commands/SConscript
@@ -99,6 +99,7 @@ env.Library(
'$BUILD_DIR/mongo/db/commands/current_op_common',
'$BUILD_DIR/mongo/db/commands/feature_compatibility_parsers',
'$BUILD_DIR/mongo/db/commands/kill_common',
+ '$BUILD_DIR/mongo/db/commands/list_databases_command',
'$BUILD_DIR/mongo/db/commands/profile_common',
'$BUILD_DIR/mongo/db/commands/servers',
'$BUILD_DIR/mongo/db/commands/test_commands_enabled',
diff --git a/src/mongo/s/commands/cluster_list_databases_cmd.cpp b/src/mongo/s/commands/cluster_list_databases_cmd.cpp
index 5c2f83d90d8..a22352ab7ce 100644
--- a/src/mongo/s/commands/cluster_list_databases_cmd.cpp
+++ b/src/mongo/s/commands/cluster_list_databases_cmd.cpp
@@ -36,6 +36,7 @@
#include "mongo/client/remote_command_targeter.h"
#include "mongo/db/auth/authorization_session.h"
#include "mongo/db/commands.h"
+#include "mongo/db/commands/list_databases_gen.h"
#include "mongo/s/client/shard.h"
#include "mongo/s/client/shard_registry.h"
#include "mongo/s/commands/strategy.h"
@@ -81,7 +82,10 @@ public:
const std::string& dbname_unused,
const BSONObj& cmdObj,
BSONObjBuilder& result) override {
- const bool nameOnly = cmdObj["nameOnly"].trueValue();
+ IDLParserErrorContext ctx("listDatabases");
+ auto cmd = ListDatabasesCommand::parse(ctx, cmdObj);
+
+ const bool nameOnly = cmd.getNameOnly();
auto const shardRegistry = Grid::get(opCtx)->shardRegistry();