summaryrefslogtreecommitdiff
path: root/src/mongo/db/pipeline/expression_context.cpp
diff options
context:
space:
mode:
authorMilitsa Sotirova <militsa.sotirova@mongodb.com>2023-04-20 15:01:01 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2023-04-20 16:55:18 +0000
commit504791ab80450817064977dcb11c524e977ebd18 (patch)
tree893a93a97d9e7bb6ea7b3fbafc445352180d74da /src/mongo/db/pipeline/expression_context.cpp
parent6b1dcfe922d995648083b032f7c75bf03035879f (diff)
downloadmongo-504791ab80450817064977dcb11c524e977ebd18.tar.gz
SERVER-76126 Set user roles system variable only if referenced in query
Diffstat (limited to 'src/mongo/db/pipeline/expression_context.cpp')
-rw-r--r--src/mongo/db/pipeline/expression_context.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/mongo/db/pipeline/expression_context.cpp b/src/mongo/db/pipeline/expression_context.cpp
index 18254dedec9..41eee309189 100644
--- a/src/mongo/db/pipeline/expression_context.cpp
+++ b/src/mongo/db/pipeline/expression_context.cpp
@@ -279,12 +279,14 @@ void ExpressionContext::stopExpressionCounters() {
}
void ExpressionContext::setUserRoles() {
+ // Only set the value of $$USER_ROLES if it is referenced in the query.
// We need to check the FCV here because the $$USER_ROLES variable will always appear in the
// serialized command when one shard is sending a sub-query to another shard. The query will
// fail in the case where the shards are running different binVersions and one of them does not
// have a notion of this variable. This FCV check prevents this from happening, as the value of
// the variable is not set (and therefore not serialized) if the FCV is too old.
- if (serverGlobalParams.featureCompatibility.isVersionInitialized() &&
+ if (isSystemVarReferencedInQuery(Variables::kUserRolesId) &&
+ serverGlobalParams.featureCompatibility.isVersionInitialized() &&
feature_flags::gFeatureFlagUserRoles.isEnabled(serverGlobalParams.featureCompatibility) &&
enableAccessToUserRoles.load()) {
variables.defineUserRoles(opCtx);