summaryrefslogtreecommitdiff
path: root/src/mongo/db/pipeline/expression.cpp
diff options
context:
space:
mode:
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());