diff options
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 6b8e392f06b..b155d8f3b78 100644 --- a/src/mongo/db/commands/generic.cpp +++ b/src/mongo/db/commands/generic.cpp @@ -32,7 +32,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/commands.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") {} @@ -156,22 +153,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("slaveOk", command->secondaryAllowed(opCtx->getServiceContext()) == |