summaryrefslogtreecommitdiff
path: root/src/mongo/idl
diff options
context:
space:
mode:
authorHugh Tong <hugh.tong@mongodb.com>2023-04-13 20:00:19 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2023-04-19 22:42:19 +0000
commit8585d684d3c33a49f7648b0b3e6f0753199de0f7 (patch)
treeb201ce0853c788d8c194b46fb40afb5dd12a9f43 /src/mongo/idl
parent99433d9de31ba908ad8199aab74dfb2b21d5964c (diff)
downloadmongo-8585d684d3c33a49f7648b0b3e6f0753199de0f7.tar.gz
SERVER-74897 Change IDL defined commands to call NamespaceStringUtil
Diffstat (limited to 'src/mongo/idl')
-rw-r--r--src/mongo/idl/idl_parser.cpp23
-rw-r--r--src/mongo/idl/idl_parser.h16
2 files changed, 16 insertions, 23 deletions
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<UUID, StringData> 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<UUID, StringData> checkAndAssertCollectionNameOrUUID(
+ const BSONElement& element);
/**
* Take all the well known command generic arguments from commandPassthroughFields, but ignore