summaryrefslogtreecommitdiff
path: root/src/mongo/db/pipeline/expression.cpp
diff options
context:
space:
mode:
authorNaama Bareket <naama.bareket@mongodb.com>2023-01-26 18:40:14 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2023-01-26 19:34:03 +0000
commit20fb7faeb7f3c724440faaca1bd494e3c3c84cc8 (patch)
treee1b39cbe111b2eca431cdb86847ba113873831e0 /src/mongo/db/pipeline/expression.cpp
parent364aa0b1cfb69bc53615ab11b7d62e918025ec79 (diff)
downloadmongo-20fb7faeb7f3c724440faaca1bd494e3c3c84cc8.tar.gz
SERVER-72688 $meta aggregate expression should be marked as unstable for API Version 1
Diffstat (limited to 'src/mongo/db/pipeline/expression.cpp')
-rw-r--r--src/mongo/db/pipeline/expression.cpp19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/mongo/db/pipeline/expression.cpp b/src/mongo/db/pipeline/expression.cpp
index ced1cf0f7fc..69a13f74e9a 100644
--- a/src/mongo/db/pipeline/expression.cpp
+++ b/src/mongo/db/pipeline/expression.cpp
@@ -3017,7 +3017,12 @@ Expression::ComputedPaths ExpressionMap::getComputedPaths(const std::string& exp
/* ------------------------- ExpressionMeta ----------------------------- */
-REGISTER_STABLE_EXPRESSION(meta, ExpressionMeta::parse);
+REGISTER_EXPRESSION_CONDITIONALLY(meta,
+ ExpressionMeta::parse,
+ AllowedWithApiStrict::kConditionally,
+ AllowedWithClientType::kAny,
+ boost::none,
+ true);
namespace {
const std::string textScoreName = "textScore";
@@ -3072,7 +3077,19 @@ intrusive_ptr<Expression> ExpressionMeta::parse(ExpressionContext* const expCtx,
uassert(17307, "$meta only supports string arguments", expr.type() == String);
const auto iter = kMetaNameToMetaType.find(expr.valueStringData());
+
if (iter != kMetaNameToMetaType.end()) {
+ const auto apiStrict =
+ expCtx->opCtx && APIParameters::get(expCtx->opCtx).getAPIStrict().value_or(false);
+
+ auto typeName = iter->first;
+ auto usesUnstableField = (typeName == "searchScore") || (typeName == "indexKey") ||
+ (typeName == "textScore") || (typeName == "searchHighlights");
+
+ if (apiStrict && usesUnstableField) {
+ uasserted(ErrorCodes::APIStrictError,
+ "Provided apiStrict is true with an unstable parameter");
+ }
return new ExpressionMeta(expCtx, iter->second);
} else {
uasserted(17308, "Unsupported argument to $meta: " + expr.String());