summaryrefslogtreecommitdiff
path: root/src/mongo/s/commands/cluster_collection_mod_cmd.cpp
diff options
context:
space:
mode:
authorMoustafa Maher <m.maher@10gen.com>2021-01-27 00:11:02 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-02-04 22:34:30 +0000
commit14bf2ee40260afb8657b0c101931025e940384ab (patch)
tree82b6e0996de17c4658b8844f207f0e7134706fcc /src/mongo/s/commands/cluster_collection_mod_cmd.cpp
parent887ac8a4345814e25e34aca5f393f4a02d38cd4c (diff)
downloadmongo-14bf2ee40260afb8657b0c101931025e940384ab.tar.gz
SERVER-53156 Convert collMod command implementation to inherit from IDL-generated base class
Diffstat (limited to 'src/mongo/s/commands/cluster_collection_mod_cmd.cpp')
-rw-r--r--src/mongo/s/commands/cluster_collection_mod_cmd.cpp60
1 files changed, 47 insertions, 13 deletions
diff --git a/src/mongo/s/commands/cluster_collection_mod_cmd.cpp b/src/mongo/s/commands/cluster_collection_mod_cmd.cpp
index c421dc5ba72..f57881178f6 100644
--- a/src/mongo/s/commands/cluster_collection_mod_cmd.cpp
+++ b/src/mongo/s/commands/cluster_collection_mod_cmd.cpp
@@ -33,6 +33,7 @@
#include "mongo/db/auth/authorization_session.h"
#include "mongo/db/coll_mod_gen.h"
+#include "mongo/db/coll_mod_reply_validation.h"
#include "mongo/db/commands.h"
#include "mongo/logv2/log.h"
#include "mongo/s/cluster_commands_helpers.h"
@@ -41,9 +42,16 @@
namespace mongo {
namespace {
-class CollectionModCmd : public ErrmsgCommandDeprecated {
+constexpr auto kRawFieldName = "raw"_sd;
+constexpr auto kWriteConcernErrorFieldName = "writeConcernError"_sd;
+constexpr auto kTopologyVersionFieldName = "topologyVersion"_sd;
+
+class CollectionModCmd : public BasicCommandWithRequestParser<CollectionModCmd> {
public:
- CollectionModCmd() : ErrmsgCommandDeprecated("collMod") {}
+ using Request = CollMod;
+ using Reply = CollModReply;
+
+ CollectionModCmd() : BasicCommandWithRequestParser() {}
const std::set<std::string>& apiVersions() const {
return kApiVersions1;
@@ -68,16 +76,12 @@ public:
return true;
}
- bool errmsgRun(OperationContext* opCtx,
- const std::string& dbName,
- const BSONObj& cmdObj,
- std::string& errmsg,
- BSONObjBuilder& output) override {
- auto cmd = CollMod::parse(
- IDLParserErrorContext(CollMod::kCommandName,
- APIParameters::get(opCtx).getAPIStrict().value_or(false)),
- cmdObj);
-
+ bool runWithRequestParser(OperationContext* opCtx,
+ const std::string& db,
+ const BSONObj& cmdObj,
+ const RequestParser& requestParser,
+ BSONObjBuilder& result) final {
+ auto cmd = requestParser.request();
auto nss = cmd.getNamespace();
LOGV2_DEBUG(22748,
1,
@@ -101,7 +105,37 @@ public:
Shard::RetryPolicy::kNoRetry,
BSONObj() /* query */,
BSONObj() /* collation */);
- return appendRawResponses(opCtx, &errmsg, &output, std::move(shardResponses)).responseOK;
+ std::string errmsg;
+ auto ok = appendRawResponses(opCtx, &errmsg, &result, std::move(shardResponses)).responseOK;
+ if (!errmsg.empty()) {
+ CommandHelpers::appendSimpleCommandStatus(result, ok, errmsg);
+ }
+
+ return ok;
+ }
+
+ void validateResult(const BSONObj& resultObj) final {
+ auto ctx = IDLParserErrorContext("CollModReply");
+ StringDataSet ignorableFields(
+ {kWriteConcernErrorFieldName, ErrorReply::kOkFieldName, kTopologyVersionFieldName});
+ if (!checkIsErrorStatus(resultObj, ctx)) {
+ if (resultObj.hasField(kRawFieldName)) {
+ const auto& rawData = resultObj[kRawFieldName];
+ if (ctx.checkAndAssertType(rawData, Object)) {
+ for (const auto& element : rawData.Obj()) {
+ const auto& shardReply = element.Obj();
+ if (!checkIsErrorStatus(shardReply, ctx)) {
+ auto reply =
+ Reply::parse(ctx, shardReply.removeFields(ignorableFields));
+ coll_mod_reply_validation::validateReply(reply);
+ }
+ }
+ }
+ } else {
+ auto reply = Reply::parse(ctx, resultObj.removeFields(ignorableFields));
+ coll_mod_reply_validation::validateReply(reply);
+ }
+ }
}
} collectionModCmd;