summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/pipeline/expression.cpp26
-rw-r--r--src/mongo/db/pipeline/expression.h4
2 files changed, 28 insertions, 2 deletions
diff --git a/src/mongo/db/pipeline/expression.cpp b/src/mongo/db/pipeline/expression.cpp
index 8db17f3152a..2ce8b92cbbb 100644
--- a/src/mongo/db/pipeline/expression.cpp
+++ b/src/mongo/db/pipeline/expression.cpp
@@ -1321,7 +1321,6 @@ void ExpressionObject::addToDocument(MutableDocument& out,
if (dynamic_cast<ExpressionObject*>(it->second.get()) && pValue.getDocument().empty())
continue;
-
out.addField(fieldName, pValue);
}
}
@@ -2407,7 +2406,6 @@ intrusive_ptr<Expression> ExpressionSetIsSubset::optimize() {
return new Optimized(arrayToSet(rhs), vpOperand);
}
-
return optimized;
}
@@ -2470,6 +2468,30 @@ const char* ExpressionSize::getOpName() const {
return "$size";
}
+/* ----------------------- ExpressionSqrt ---------------------------- */
+
+Value ExpressionSqrt::evaluateInternal(Variables* vars) const {
+ Value argVal = vpOperand[0]->evaluateInternal(vars);
+ if (argVal.nullish())
+ return Value(BSONNULL);
+
+ uassert(28715,
+ str::stream() << "$sqrt only supports numeric types, not "
+ << typeName(argVal.getType()),
+ argVal.numeric());
+
+ double argDouble = argVal.coerceToDouble();
+ uassert(28714,
+ "$sqrt's argument must be greater than or equal to 0",
+ argDouble >= 0 || std::isnan(argDouble));
+ return Value(sqrt(argDouble));
+}
+
+REGISTER_EXPRESSION("$sqrt", ExpressionSqrt::parse);
+const char* ExpressionSqrt::getOpName() const {
+ return "$sqrt";
+}
+
/* ----------------------- ExpressionStrcasecmp ---------------------------- */
Value ExpressionStrcasecmp::evaluateInternal(Variables* vars) const {
diff --git a/src/mongo/db/pipeline/expression.h b/src/mongo/db/pipeline/expression.h
index 3650efc6655..330487b4342 100644
--- a/src/mongo/db/pipeline/expression.h
+++ b/src/mongo/db/pipeline/expression.h
@@ -989,6 +989,10 @@ public:
const char* getOpName() const final;
};
+class ExpressionSqrt final : public ExpressionFixedArity<ExpressionSqrt, 1> {
+ Value evaluateInternal(Variables* vars) const final;
+ const char* getOpName() const final;
+};
class ExpressionStrcasecmp final : public ExpressionFixedArity<ExpressionStrcasecmp, 2> {
public: