From 8585d684d3c33a49f7648b0b3e6f0753199de0f7 Mon Sep 17 00:00:00 2001 From: Hugh Tong Date: Thu, 13 Apr 2023 20:00:19 +0000 Subject: SERVER-74897 Change IDL defined commands to call NamespaceStringUtil --- src/mongo/idl/idl_parser.cpp | 23 ++++++++--------------- src/mongo/idl/idl_parser.h | 16 ++++++++-------- 2 files changed, 16 insertions(+), 23 deletions(-) (limited to 'src/mongo/idl') diff --git a/src/mongo/idl/idl_parser.cpp b/src/mongo/idl/idl_parser.cpp index 81a6ca19f4b..e7e7e7bca13 100644 --- a/src/mongo/idl/idl_parser.cpp +++ b/src/mongo/idl/idl_parser.cpp @@ -240,9 +240,8 @@ void IDLParserContext::throwAPIStrictErrorIfApplicable(StringData fieldName) con !_apiStrict); } -NamespaceString IDLParserContext::parseNSCollectionRequired(const DatabaseName& dbName, - const BSONElement& element, - bool allowGlobalCollectionName) { +StringData IDLParserContext::checkAndAssertCollectionName(const BSONElement& element, + bool allowGlobalCollectionName) { const bool isUUID = (element.canonicalType() == canonicalizeBSONType(mongo::BinData) && element.binDataType() == BinDataType::newUUID); uassert(ErrorCodes::BadValue, @@ -255,29 +254,23 @@ NamespaceString IDLParserContext::parseNSCollectionRequired(const DatabaseName& str::stream() << "Invalid command format: the '" << element.fieldNameStringData() << "' field must specify a collection name or 1", element.number() == 1); - return NamespaceString(dbName, collectionlessAggregateCursorCol); + return collectionlessAggregateCursorCol; } uassert(ErrorCodes::BadValue, str::stream() << "collection name has invalid type " << typeName(element.type()), element.canonicalType() == canonicalizeBSONType(mongo::String)); - const NamespaceString nss(dbName, element.valueStringData()); - - uassert(ErrorCodes::InvalidNamespace, - str::stream() << "Invalid namespace specified '" << nss.toStringForErrorMsg() << "'", - nss.isValid()); - - return nss; + return element.valueStringData(); } -NamespaceStringOrUUID IDLParserContext::parseNsOrUUID(const DatabaseName& dbName, - const BSONElement& element) { +stdx::variant IDLParserContext::checkAndAssertCollectionNameOrUUID( + const BSONElement& element) { if (element.type() == BinData && element.binDataType() == BinDataType::newUUID) { - return {dbName, uassertStatusOK(UUID::parse(element))}; + return uassertStatusOK(UUID::parse(element)); } else { // Ensure collection identifier is not a Command - return {parseNSCollectionRequired(dbName, element, false)}; + return checkAndAssertCollectionName(element, false); } } diff --git a/src/mongo/idl/idl_parser.h b/src/mongo/idl/idl_parser.h index f568fbf05ae..725f5ab9269 100644 --- a/src/mongo/idl/idl_parser.h +++ b/src/mongo/idl/idl_parser.h @@ -362,18 +362,18 @@ public: void throwAPIStrictErrorIfApplicable(BSONElement fieldName) const; /** - * Equivalent to CommandHelpers::parseNsCollectionRequired. - * 'allowGlobalCollectionName' allows use of global collection name, e.g. {aggregate: 1}. + * Check that the collection name in 'element' is valid. Throws an exception if not valid. + * Returns the collection name otherwise. */ - static NamespaceString parseNSCollectionRequired(const DatabaseName& dbname, - const BSONElement& element, - bool allowGlobalCollectionName); + static StringData checkAndAssertCollectionName(const BSONElement& element, + bool allowGlobalCollectionName); /** - * Equivalent to CommandHelpers::parseNsOrUUID + * Check that the collection name or UUID in 'element' is valid. Throws an exception if not + * valid. Returns either the collection name or UUID otherwise. */ - static NamespaceStringOrUUID parseNsOrUUID(const DatabaseName& dbname, - const BSONElement& element); + static stdx::variant checkAndAssertCollectionNameOrUUID( + const BSONElement& element); /** * Take all the well known command generic arguments from commandPassthroughFields, but ignore -- cgit v1.2.1