diff options
author | Ali Mir <ali.mir@mongodb.com> | 2020-09-23 18:18:26 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-09-23 20:41:59 +0000 |
commit | e178007c01565bf59d038f3be1566da036c60397 (patch) | |
tree | f5e348c2a116c0977483dad5cc599a169edc705e /src/mongo/db/commands/generic.cpp | |
parent | 62e89bd2119904531b591b6948f57b00eb52ec79 (diff) | |
download | mongo-e178007c01565bf59d038f3be1566da036c60397.tar.gz |
SERVER-51106 Make the isMaster command a derived class of hello
Diffstat (limited to 'src/mongo/db/commands/generic.cpp')
-rw-r--r-- | src/mongo/db/commands/generic.cpp | 26 |
1 files changed, 10 insertions, 16 deletions
diff --git a/src/mongo/db/commands/generic.cpp b/src/mongo/db/commands/generic.cpp index a27b1aa133d..af73d11052b 100644 --- a/src/mongo/db/commands/generic.cpp +++ b/src/mongo/db/commands/generic.cpp @@ -31,7 +31,6 @@ #include "mongo/platform/basic.h" -#include "mongo/base/string_data.h" #include "mongo/bson/util/bson_extract.h" #include "mongo/bson/util/builder.h" #include "mongo/db/auth/authorization_session.h" @@ -53,8 +52,6 @@ using std::string; using std::stringstream; using std::vector; -constexpr auto kIsMasterString = "isMaster"_sd; - class PingCommand : public BasicCommand { public: PingCommand() : BasicCommand("ping") {} @@ -168,22 +165,19 @@ public: const BSONObj& cmdObj, BSONObjBuilder& result) { // Sort the command names before building the result BSON. - std::vector<std::string> commandNames; - const auto commandRegistry = globalCommandRegistry(); - for (const auto command : commandRegistry->allCommands()) { - // Don't show oldnames unless it's "isMaster". The output of the listCommands command - // must include "isMaster," even though it's an alias for the "hello" command, in order - // to preserve backwards compatibility with Ops Manager 4.4. - if (command.first == command.second->getName() || command.first == kIsMasterString) - commandNames.push_back(command.first); + std::vector<Command*> commands; + for (const auto command : globalCommandRegistry()->allCommands()) { + // Don't show oldnames + if (command.first == command.second->getName()) + commands.push_back(command.second); } - std::sort(commandNames.begin(), commandNames.end()); + std::sort(commands.begin(), commands.end(), [](Command* lhs, Command* rhs) { + return (lhs->getName()) < (rhs->getName()); + }); BSONObjBuilder b(result.subobjStart("commands")); - for (const auto& c : commandNames) { - const auto command = commandRegistry->findCommand(c); - auto name = (c == kIsMasterString) ? kIsMasterString : command->getName(); - BSONObjBuilder temp(b.subobjStart(name)); + for (const auto& command : commands) { + BSONObjBuilder temp(b.subobjStart(command->getName())); temp.append("help", command->help()); temp.append("requiresAuth", command->requiresAuth()); temp.append("slaveOk", |