diff --git a/jstests/noPassthroughWithMongod/find_cmd.js b/jstests/noPassthroughWithMongod/find_cmd.js index 00e4d315791e5..31d3311832ccd 100644 --- a/jstests/noPassthroughWithMongod/find_cmd.js +++ b/jstests/noPassthroughWithMongod/find_cmd.js @@ -47,3 +47,7 @@ assert.commandFailed(coll.runCommand("find", {foo: "bar"})); // Filter doesn't parse. assert.commandFailed(coll.runCommand("find", {projection: {_id: 0}, filter: {$foo: "bar"}})); + +// Special command namespace. +assert.commandFailed(coll.getDB().runCommand({find: "$cmd"})); +assert.commandFailed(coll.getDB().runCommand({find: "$cmd.sys.inprog"})); \ No newline at end of file diff --git a/src/mongo/db/commands/find_cmd.cpp b/src/mongo/db/commands/find_cmd.cpp index 775518e402a48..3b544e78be797 100644 --- a/src/mongo/db/commands/find_cmd.cpp +++ b/src/mongo/db/commands/find_cmd.cpp @@ -181,7 +181,7 @@ class FindCmd : public Command { BSONObjBuilder& result) override { const std::string fullns = parseNs(dbname, cmdObj); const NamespaceString nss(fullns); - if (!nss.isValid()) { + if (!nss.isValid() || nss.isCommand() || nss.isSpecialCommand()) { return appendCommandStatus(result, {ErrorCodes::InvalidNamespace, str::stream() << "Invalid collection name: " << nss.ns()});