summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mongo/db/commands.cpp9
-rw-r--r--src/mongo/db/commands.h9
2 files changed, 16 insertions, 2 deletions
diff --git a/src/mongo/db/commands.cpp b/src/mongo/db/commands.cpp
index 1dd98be1b33..c84ff1f729f 100644
--- a/src/mongo/db/commands.cpp
+++ b/src/mongo/db/commands.cpp
@@ -319,10 +319,15 @@ NamespaceStringOrUUID CommandHelpers::parseNsOrUUID(StringData dbname, const BSO
}
std::string CommandHelpers::parseNsFromCommand(StringData dbname, const BSONObj& cmdObj) {
+ return parseNsFromCommand({boost::none, dbname}, cmdObj).ns();
+}
+
+NamespaceString CommandHelpers::parseNsFromCommand(const DatabaseName& dbName,
+ const BSONObj& cmdObj) {
BSONElement first = cmdObj.firstElement();
if (first.type() != mongo::String)
- return dbname.toString();
- return str::stream() << dbname << '.' << cmdObj.firstElement().valueStringData();
+ return NamespaceString(dbName);
+ return NamespaceString(dbName, cmdObj.firstElement().valueStringData());
}
ResourcePattern CommandHelpers::resourcePatternForNamespace(const std::string& ns) {
diff --git a/src/mongo/db/commands.h b/src/mongo/db/commands.h
index b08163fb248..83c44496d3c 100644
--- a/src/mongo/db/commands.h
+++ b/src/mongo/db/commands.h
@@ -147,9 +147,18 @@ struct CommandHelpers {
* appended to 'dbname' after a '.' character. If the first field is not of type
* mongo::String, then 'dbname' is returned unmodified.
*/
+ // TODO SERVER-68423: Remove this method once all call sites have been updated to pass
+ // DatabaseName.
static std::string parseNsFromCommand(StringData dbname, const BSONObj& cmdObj);
/**
+ * Return the namespace for the command. If the first field in 'cmdObj' is of type
+ * mongo::String, then that field is interpreted as the collection name.
+ * If the first field is not of type mongo::String, then the namespace only has database name.
+ */
+ static NamespaceString parseNsFromCommand(const DatabaseName& dbName, const BSONObj& cmdObj);
+
+ /**
* Utility that returns a ResourcePattern for the namespace returned from
* BasicCommand::parseNs(dbname, cmdObj). This will be either an exact namespace resource
* pattern or a database resource pattern, depending on whether parseNs returns a fully qualifed