summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMoustafa Maher Khalil <m.maher@mongodb.com>2022-02-02 17:19:31 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-02-02 18:34:55 +0000
commitb6ec92b3b7d0be5b7dd53c3e915b4d93b7b576ed (patch)
tree66b34825ea76b7054dcf6bef810fafc7b474bc0e /src
parent7c3c590d5996089b5cf20263e3660ae0a0bec999 (diff)
downloadmongo-b6ec92b3b7d0be5b7dd53c3e915b4d93b7b576ed.tar.gz
SERVER-62562 Use CollectionUUIDMismatch error code for collectionUUID parameter of aggregate command
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/catalog/collection_uuid_mismatch.cpp8
-rw-r--r--src/mongo/db/catalog/collection_uuid_mismatch.h3
-rw-r--r--src/mongo/db/commands/run_aggregate.cpp22
3 files changed, 18 insertions, 15 deletions
diff --git a/src/mongo/db/catalog/collection_uuid_mismatch.cpp b/src/mongo/db/catalog/collection_uuid_mismatch.cpp
index 7639f7570ca..e4ca0f9c83d 100644
--- a/src/mongo/db/catalog/collection_uuid_mismatch.cpp
+++ b/src/mongo/db/catalog/collection_uuid_mismatch.cpp
@@ -36,15 +36,17 @@
namespace mongo {
void checkCollectionUUIDMismatch(OperationContext* opCtx,
const CollectionPtr& coll,
- const boost::optional<UUID>& uuid) {
+ const boost::optional<UUID>& uuid,
+ bool checkFeatureFlag) {
if (!uuid) {
return;
}
uassert(ErrorCodes::InvalidOptions,
"The collectionUUID parameter is not enabled",
- feature_flags::gCommandsAcceptCollectionUUID.isEnabled(
- serverGlobalParams.featureCompatibility));
+ !checkFeatureFlag ||
+ feature_flags::gCommandsAcceptCollectionUUID.isEnabled(
+ serverGlobalParams.featureCompatibility));
uassert((CollectionUUIDMismatchInfo{*uuid,
CollectionCatalog::get(opCtx)
diff --git a/src/mongo/db/catalog/collection_uuid_mismatch.h b/src/mongo/db/catalog/collection_uuid_mismatch.h
index 3c0fd3ed3a7..2bd6b8a9e16 100644
--- a/src/mongo/db/catalog/collection_uuid_mismatch.h
+++ b/src/mongo/db/catalog/collection_uuid_mismatch.h
@@ -34,5 +34,6 @@
namespace mongo {
void checkCollectionUUIDMismatch(OperationContext* opCtx,
const CollectionPtr& coll,
- const boost::optional<UUID>& uuid);
+ const boost::optional<UUID>& uuid,
+ bool checkFeatureFlag = true);
} // namespace mongo
diff --git a/src/mongo/db/commands/run_aggregate.cpp b/src/mongo/db/commands/run_aggregate.cpp
index b1b80cc7827..e7634306797 100644
--- a/src/mongo/db/commands/run_aggregate.cpp
+++ b/src/mongo/db/commands/run_aggregate.cpp
@@ -39,6 +39,7 @@
#include "mongo/db/api_parameters.h"
#include "mongo/db/auth/authorization_session.h"
+#include "mongo/db/catalog/collection_uuid_mismatch.h"
#include "mongo/db/catalog/database.h"
#include "mongo/db/catalog/database_holder.h"
#include "mongo/db/commands/cqf/cqf_aggregate.h"
@@ -770,10 +771,11 @@ Status runAggregate(OperationContext* opCtx,
if (ctx && ctx->getView() && !liteParsedPipeline.startsWithCollStats()) {
invariant(nss != NamespaceString::kRsOplogNamespace);
invariant(!nss.isCollectionlessAggregateNS());
- uassert(ErrorCodes::OptionNotSupportedOnView,
- str::stream() << AggregateCommandRequest::kCollectionUUIDFieldName
- << " is not supported against a view",
- !request.getCollectionUUID());
+
+ checkCollectionUUIDMismatch(opCtx,
+ collections.getMainCollection(),
+ request.getCollectionUUID(),
+ false /* checkFeatureFlag */);
uassert(ErrorCodes::CommandNotSupportedOnView,
"mapReduce on a view is not supported",
@@ -851,13 +853,11 @@ Status runAggregate(OperationContext* opCtx,
return status;
}
- if (request.getCollectionUUID()) {
- // If the namespace is not a view and collectionUUID was provided, verify the collection
- // exists and has the expected UUID.
- uassert(ErrorCodes::NamespaceNotFound,
- "No collection found with the given namespace and UUID",
- uuid && uuid == *request.getCollectionUUID());
- }
+ // If collectionUUID was provided, verify the collection exists and has the expected UUID.
+ checkCollectionUUIDMismatch(opCtx,
+ collections.getMainCollection(),
+ request.getCollectionUUID(),
+ false /* checkFeatureFlag */);
invariant(collatorToUse);
expCtx = makeExpressionContext(