From 76e1e97f064016a86e56561a098d6dab8f5c7d21 Mon Sep 17 00:00:00 2001 From: Nick Zolnierz Date: Tue, 25 Feb 2020 13:12:34 -0500 Subject: SERVER-46264 Change the rename command so it is passed through IDL rather than manually constructed BSON --- src/mongo/db/commands/rename_collection_cmd.cpp | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) (limited to 'src/mongo/db/commands/rename_collection_cmd.cpp') diff --git a/src/mongo/db/commands/rename_collection_cmd.cpp b/src/mongo/db/commands/rename_collection_cmd.cpp index 4778255072e..3226d38c550 100644 --- a/src/mongo/db/commands/rename_collection_cmd.cpp +++ b/src/mongo/db/commands/rename_collection_cmd.cpp @@ -37,6 +37,7 @@ #include "mongo/db/client.h" #include "mongo/db/commands.h" #include "mongo/db/commands/rename_collection.h" +#include "mongo/db/commands/rename_collection_gen.h" #include "mongo/db/db_raii.h" #include "mongo/db/index/index_descriptor.h" #include "mongo/db/namespace_string.h" @@ -84,21 +85,13 @@ public: const BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result) { - const auto sourceNsElt = cmdObj[getName()]; - const auto targetNsElt = cmdObj["to"]; - - uassert(ErrorCodes::TypeMismatch, - "'renameCollection' must be of type String", - sourceNsElt.type() == BSONType::String); - uassert(ErrorCodes::TypeMismatch, - "'to' must be of type String", - targetNsElt.type() == BSONType::String); - - const NamespaceString source(sourceNsElt.valueStringData()); - const NamespaceString target(targetNsElt.valueStringData()); - bool dropTarget = cmdObj["dropTarget"].trueValue(); - bool stayTemp = cmdObj["stayTemp"].trueValue(); - validateAndRunRenameCollection(opCtx, source, target, dropTarget, stayTemp); + auto renameRequest = + RenameCollectionCommand::parse(IDLParserErrorContext("renameCollection"), cmdObj); + validateAndRunRenameCollection(opCtx, + renameRequest.getCommandParameter(), + renameRequest.getTo(), + renameRequest.getDropTarget(), + renameRequest.getStayTemp()); return true; } -- cgit v1.2.1