summaryrefslogtreecommitdiff
path: root/src/mongo/s/query/cluster_aggregate.cpp
diff options
context:
space:
mode:
authorRishab Joshi <rishab.joshi@mongodb.com>2021-02-19 06:20:44 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-02-19 09:32:47 +0000
commitb785ca3a3d785814ac7201d5a7d52e718df7e689 (patch)
treeca0f6c2aa5a3ccd142ca8894fda6939f240c398d /src/mongo/s/query/cluster_aggregate.cpp
parenta40e23d8613ad123e26112a61e26963909f1fa07 (diff)
downloadmongo-b785ca3a3d785814ac7201d5a7d52e718df7e689.tar.gz
SERVER-54072 Added internal-client checks for aggregation command.
Diffstat (limited to 'src/mongo/s/query/cluster_aggregate.cpp')
-rw-r--r--src/mongo/s/query/cluster_aggregate.cpp25
1 files changed, 17 insertions, 8 deletions
diff --git a/src/mongo/s/query/cluster_aggregate.cpp b/src/mongo/s/query/cluster_aggregate.cpp
index fa0d714d31c..1a2cdb8467f 100644
--- a/src/mongo/s/query/cluster_aggregate.cpp
+++ b/src/mongo/s/query/cluster_aggregate.cpp
@@ -188,6 +188,21 @@ void updateHostsTargetedMetrics(OperationContext* opCtx,
}
}
+/**
+ * Performs validations related to API versioning before running the aggregation command.
+ * Throws uassert if any of the validations fails
+ * - validation on each stage on the pipeline
+ * - validation on 'AggregateCommand' request
+ */
+void performAPIVersionChecks(const OperationContext* opCtx,
+ const AggregateCommand& request,
+ const LiteParsedPipeline& liteParsedPipeline) {
+ invariant(opCtx);
+
+ liteParsedPipeline.validatePipelineStagesforAPIVersion(opCtx);
+ aggregation_request_helper::validateRequestForAPIVersion(opCtx, request);
+}
+
} // namespace
Status ClusterAggregate::runAggregate(OperationContext* opCtx,
@@ -204,14 +219,8 @@ Status ClusterAggregate::runAggregate(OperationContext* opCtx,
const LiteParsedPipeline& liteParsedPipeline,
const PrivilegeVector& privileges,
BSONObjBuilder* result) {
- // If 'apiStrict: true', validates that the pipeline does not contain stages which are not in
- // this API version.
- auto apiParameters = APIParameters::get(opCtx);
- if (apiParameters.getAPIStrict().value_or(false)) {
- auto apiVersion = apiParameters.getAPIVersion().value_or("");
- if (!apiVersion.empty())
- liteParsedPipeline.validatePipelineStagesIfAPIStrict(apiVersion);
- }
+ // Perform API versioning validation checks.
+ performAPIVersionChecks(opCtx, request, liteParsedPipeline);
uassert(51028, "Cannot specify exchange option to a mongos", !request.getExchange());
uassert(51143,