summaryrefslogtreecommitdiff
path: root/src/mongo/db/commands.h
diff options
context:
space:
mode:
authorA. Jesse Jiryu Davis <jesse@mongodb.com>2021-02-09 15:06:07 -0500
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-02-09 22:47:45 +0000
commitfcb69334e15e32049a45ebdcc7d2988acf441f5e (patch)
tree8211c18a65852f1d6b7c4701b9a4264a365f93b7 /src/mongo/db/commands.h
parent4a732d685ffa7c29e541c5ef6fe41751c9227d18 (diff)
downloadmongo-fcb69334e15e32049a45ebdcc7d2988acf441f5e.tar.gz
SERVER-52542 Convert dropIndexes to IDL
Diffstat (limited to 'src/mongo/db/commands.h')
-rw-r--r--src/mongo/db/commands.h26
1 files changed, 22 insertions, 4 deletions
diff --git a/src/mongo/db/commands.h b/src/mongo/db/commands.h
index 2d3df2eb106..813c5397ab2 100644
--- a/src/mongo/db/commands.h
+++ b/src/mongo/db/commands.h
@@ -930,6 +930,23 @@ public:
}
};
+namespace {
+// Used in BasicCommandWithRequestParser below.
+template <typename T, typename = int>
+struct CommandAlias {
+ // An empty alias is equivalent to no alias, see CommandRegistry::registerCommand.
+ static constexpr StringData kAlias = ""_sd;
+};
+
+template <typename T>
+struct CommandAlias<T, decltype((void)T::kCommandAlias, 0)> {
+ static constexpr StringData kAlias = T::kCommandAlias;
+};
+
+template <typename T>
+constexpr StringData command_alias_v = CommandAlias<T>::kAlias;
+} // namespace
+
/**
* A CRTP base class for BasicCommandWithRequestParser, which simplifies writing commands that
* accept requests generated by IDL to enforce API versioning and to overcome the complexity
@@ -952,7 +969,8 @@ public:
*
* which enables it to be parsed as an IDL command.
*
- * - a 'constexpr StringData kCommandName' member.
+ * - a 'static constexpr StringData kCommandName' member.
+ * - (optional) a 'static constexpr StringData kCommandAlias' member.
*
* - validateResult: that has a custom logic to validate the result BSON object
* to enforce API versioning.
@@ -961,9 +979,9 @@ public:
template <typename Derived>
class BasicCommandWithRequestParser : public BasicCommandWithReplyBuilderInterface {
protected:
- // Commands that only have a single name don't need to define any constructors.
BasicCommandWithRequestParser()
- : BasicCommandWithReplyBuilderInterface(Derived::Request::kCommandName) {}
+ : BasicCommandWithReplyBuilderInterface(Derived::Request::kCommandName,
+ command_alias_v<typename Derived::Request>) {}
bool runWithReplyBuilder(OperationContext* opCtx,
const std::string& db,
@@ -1003,7 +1021,7 @@ protected:
auto wcStatus = getWriteConcernStatusFromCommandResult(resultObj);
if (!wcStatus.isOK()) {
if (wcStatus.code() == ErrorCodes::TypeMismatch) {
- // Result has "writeConcerError" field but it is not valid wce object.
+ // Result has "writeConcernError" field but it is not valid wce object.
uassertStatusOK(wcStatus);
}
}