summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mongo/db/pipeline/document_path_support.cpp4
-rw-r--r--src/mongo/db/pipeline/document_path_support.h2
-rw-r--r--src/mongo/db/pipeline/document_source_graph_lookup.cpp3
-rw-r--r--src/mongo/db/pipeline/document_source_graph_lookup.h2
-rw-r--r--src/mongo/db/pipeline/document_source_group.cpp9
-rw-r--r--src/mongo/db/pipeline/document_source_group.h2
-rw-r--r--src/mongo/db/pipeline/document_source_redact.cpp4
-rw-r--r--src/mongo/db/pipeline/document_source_redact.h4
-rw-r--r--src/mongo/db/pipeline/document_source_replace_root.cpp2
-rw-r--r--src/mongo/db/pipeline/document_source_single_document_transformation.h2
-rw-r--r--src/mongo/db/pipeline/expression.cpp140
-rw-r--r--src/mongo/db/pipeline/expression.h144
-rw-r--r--src/mongo/db/pipeline/expression_test.cpp2
-rw-r--r--src/mongo/db/pipeline/parsed_add_fields.cpp2
-rw-r--r--src/mongo/db/pipeline/parsed_add_fields.h2
-rw-r--r--src/mongo/db/pipeline/parsed_aggregation_projection.h4
-rw-r--r--src/mongo/db/pipeline/parsed_exclusion_projection.cpp4
-rw-r--r--src/mongo/db/pipeline/parsed_exclusion_projection.h4
-rw-r--r--src/mongo/db/pipeline/parsed_inclusion_projection.cpp8
-rw-r--r--src/mongo/db/pipeline/parsed_inclusion_projection.h8
-rw-r--r--src/mongo/db/pipeline/variables.cpp4
-rw-r--r--src/mongo/db/pipeline/variables.h4
22 files changed, 182 insertions, 178 deletions
diff --git a/src/mongo/db/pipeline/document_path_support.cpp b/src/mongo/db/pipeline/document_path_support.cpp
index 261b7bdf91d..914763e696b 100644
--- a/src/mongo/db/pipeline/document_path_support.cpp
+++ b/src/mongo/db/pipeline/document_path_support.cpp
@@ -132,10 +132,10 @@ void visitAllValuesAtPathHelper(Document doc,
} // namespace
-void visitAllValuesAtPath(Document doc,
+void visitAllValuesAtPath(const Document& doc,
const FieldPath& path,
stdx::function<void(const Value&)> callback) {
- visitAllValuesAtPathHelper(std::move(doc), path, 0, callback);
+ visitAllValuesAtPathHelper(doc, path, 0, callback);
}
} // namespace document_path_support
diff --git a/src/mongo/db/pipeline/document_path_support.h b/src/mongo/db/pipeline/document_path_support.h
index 60020873947..94e22f604c7 100644
--- a/src/mongo/db/pipeline/document_path_support.h
+++ b/src/mongo/db/pipeline/document_path_support.h
@@ -47,7 +47,7 @@ namespace document_path_support {
* For example, 'callback' will be invoked on the values 1, 1, {a: 1}, 2 and 3 are on the path "x.y"
* in the document {x: [{y: 1}, {y: 1}, {y: {a: 1}}, {y: [2, 3]}, 3, 4]}.
*/
-void visitAllValuesAtPath(Document doc,
+void visitAllValuesAtPath(const Document& doc,
const FieldPath& path,
stdx::function<void(const Value&)> callback);
diff --git a/src/mongo/db/pipeline/document_source_graph_lookup.cpp b/src/mongo/db/pipeline/document_source_graph_lookup.cpp
index 88b5c4efc46..d1902978b19 100644
--- a/src/mongo/db/pipeline/document_source_graph_lookup.cpp
+++ b/src/mongo/db/pipeline/document_source_graph_lookup.cpp
@@ -258,7 +258,8 @@ bool DocumentSourceGraphLookUp::addToVisitedAndFrontier(Document result, long lo
return true;
}
-void DocumentSourceGraphLookUp::addToCache(Document result, const ValueUnorderedSet& queried) {
+void DocumentSourceGraphLookUp::addToCache(const Document& result,
+ const ValueUnorderedSet& queried) {
document_path_support::visitAllValuesAtPath(
result, _connectToField, [this, &queried, &result](const Value& connectToValue) {
// It is possible that 'connectToValue' is a single value, but was not queried for. For
diff --git a/src/mongo/db/pipeline/document_source_graph_lookup.h b/src/mongo/db/pipeline/document_source_graph_lookup.h
index 86b27c191cc..0c714be441c 100644
--- a/src/mongo/db/pipeline/document_source_graph_lookup.h
+++ b/src/mongo/db/pipeline/document_source_graph_lookup.h
@@ -149,7 +149,7 @@ private:
* Updates '_cache' with 'result' appropriately, given that 'result' was retrieved when querying
* for 'queried'.
*/
- void addToCache(Document result, const ValueUnorderedSet& queried);
+ void addToCache(const Document& result, const ValueUnorderedSet& queried);
/**
* Assert that '_visited' and '_frontier' have not exceeded the maximum meory usage, and then
diff --git a/src/mongo/db/pipeline/document_source_group.cpp b/src/mongo/db/pipeline/document_source_group.cpp
index 6ac4ad2bbd2..6e8d827e76c 100644
--- a/src/mongo/db/pipeline/document_source_group.cpp
+++ b/src/mongo/db/pipeline/document_source_group.cpp
@@ -490,7 +490,10 @@ DocumentSource::GetNextResult DocumentSourceGroup::initialize() {
_memoryUsageBytes = 0;
}
- Value id = computeId(input.getDocument());
+ // We release the result document here so that it does not outlive the end of this loop
+ // iteration. Not releasing could lead to an array copy when this group follows an unwind.
+ auto rootDocument = input.releaseDocument();
+ Value id = computeId(rootDocument);
// Look for the _id value in the map. If it's not there, add a new entry with a blank
// accumulator. This is done in a somewhat odd way in order to avoid hashing 'id' and
@@ -518,7 +521,7 @@ DocumentSource::GetNextResult DocumentSourceGroup::initialize() {
dassert(numAccumulators == group.size());
for (size_t i = 0; i < numAccumulators; i++) {
- group[i]->process(_accumulatedFields[i].expression->evaluate(input.getDocument()),
+ group[i]->process(_accumulatedFields[i].expression->evaluate(rootDocument),
_doingMerge);
_memoryUsageBytes += group[i]->memUsageForSorter();
@@ -767,7 +770,7 @@ BSONObjSet DocumentSourceGroup::getOutputSorts() {
}
-Value DocumentSourceGroup::computeId(Document root) {
+Value DocumentSourceGroup::computeId(const Document& root) {
// If only one expression, return result directly
if (_idExpressions.size() == 1) {
Value retValue = _idExpressions[0]->evaluate(root);
diff --git a/src/mongo/db/pipeline/document_source_group.h b/src/mongo/db/pipeline/document_source_group.h
index d1c0f079234..8b8094c94ee 100644
--- a/src/mongo/db/pipeline/document_source_group.h
+++ b/src/mongo/db/pipeline/document_source_group.h
@@ -140,7 +140,7 @@ private:
/**
* Computes the internal representation of the group key.
*/
- Value computeId(Document root);
+ Value computeId(const Document& root);
/**
* Converts the internal representation of the group key to the _id shape specified by the
diff --git a/src/mongo/db/pipeline/document_source_redact.cpp b/src/mongo/db/pipeline/document_source_redact.cpp
index 30561034aa0..a1f211b6bd5 100644
--- a/src/mongo/db/pipeline/document_source_redact.cpp
+++ b/src/mongo/db/pipeline/document_source_redact.cpp
@@ -96,7 +96,7 @@ Pipeline::SourceContainer::iterator DocumentSourceRedact::doOptimizeAt(
return std::next(itr);
}
-Value DocumentSourceRedact::redactValue(const Value& in, Document root) {
+Value DocumentSourceRedact::redactValue(const Value& in, const Document& root) {
const BSONType valueType = in.getType();
if (valueType == Object) {
pExpCtx->variables.setValue(_currentId, in);
@@ -126,7 +126,7 @@ Value DocumentSourceRedact::redactValue(const Value& in, Document root) {
}
}
-boost::optional<Document> DocumentSourceRedact::redactObject(Document root) {
+boost::optional<Document> DocumentSourceRedact::redactObject(const Document& root) {
auto& variables = pExpCtx->variables;
const Value expressionResult = _expression->evaluate(root);
diff --git a/src/mongo/db/pipeline/document_source_redact.h b/src/mongo/db/pipeline/document_source_redact.h
index 82d8666ebaf..a76ca9c7940 100644
--- a/src/mongo/db/pipeline/document_source_redact.h
+++ b/src/mongo/db/pipeline/document_source_redact.h
@@ -57,8 +57,8 @@ private:
const boost::intrusive_ptr<Expression>& previsit);
// These both work over pExpCtx->variables.
- boost::optional<Document> redactObject(Document root); // redacts CURRENT
- Value redactValue(const Value& in, Document root);
+ boost::optional<Document> redactObject(const Document& root); // redacts CURRENT
+ Value redactValue(const Value& in, const Document& root);
Variables::Id _currentId;
boost::intrusive_ptr<Expression> _expression;
diff --git a/src/mongo/db/pipeline/document_source_replace_root.cpp b/src/mongo/db/pipeline/document_source_replace_root.cpp
index 5e2c15792c0..7524ea84572 100644
--- a/src/mongo/db/pipeline/document_source_replace_root.cpp
+++ b/src/mongo/db/pipeline/document_source_replace_root.cpp
@@ -52,7 +52,7 @@ public:
ReplaceRootTransformation(const boost::intrusive_ptr<ExpressionContext>& expCtx)
: _expCtx(expCtx) {}
- Document applyTransformation(Document input) final {
+ Document applyTransformation(const Document& input) final {
// Extract subdocument in the form of a Value.
Value newRoot = _newRoot->evaluate(input);
diff --git a/src/mongo/db/pipeline/document_source_single_document_transformation.h b/src/mongo/db/pipeline/document_source_single_document_transformation.h
index 5e09b34e639..3b91a979046 100644
--- a/src/mongo/db/pipeline/document_source_single_document_transformation.h
+++ b/src/mongo/db/pipeline/document_source_single_document_transformation.h
@@ -53,7 +53,7 @@ public:
class TransformerInterface {
public:
virtual ~TransformerInterface() = default;
- virtual Document applyTransformation(Document input) = 0;
+ virtual Document applyTransformation(const Document& input) = 0;
virtual void optimize() = 0;
virtual Document serialize(boost::optional<ExplainOptions::Verbosity> explain) const = 0;
virtual DocumentSource::GetDepsReturn addDependencies(DepsTracker* deps) const = 0;
diff --git a/src/mongo/db/pipeline/expression.cpp b/src/mongo/db/pipeline/expression.cpp
index 3f6667e217c..9db31bba0d4 100644
--- a/src/mongo/db/pipeline/expression.cpp
+++ b/src/mongo/db/pipeline/expression.cpp
@@ -231,7 +231,7 @@ const char* ExpressionAbs::getOpName() const {
/* ------------------------- ExpressionAdd ----------------------------- */
-Value ExpressionAdd::evaluate(Document root) const {
+Value ExpressionAdd::evaluate(const Document& root) const {
// We'll try to return the narrowest possible result value while avoiding overflow, loss
// of precision due to intermediate rounding or implicit use of decimal types. To do that,
// compute a compensated sum for non-decimal values and a separate decimal sum for decimal
@@ -313,7 +313,7 @@ const char* ExpressionAdd::getOpName() const {
/* ------------------------- ExpressionAllElementsTrue -------------------------- */
-Value ExpressionAllElementsTrue::evaluate(Document root) const {
+Value ExpressionAllElementsTrue::evaluate(const Document& root) const {
const Value arr = vpOperand[0]->evaluate(root);
uassert(17040,
str::stream() << getOpName() << "'s argument must be an array, but is "
@@ -391,7 +391,7 @@ intrusive_ptr<Expression> ExpressionAnd::optimize() {
return pE;
}
-Value ExpressionAnd::evaluate(Document root) const {
+Value ExpressionAnd::evaluate(const Document& root) const {
const size_t n = vpOperand.size();
for (size_t i = 0; i < n; ++i) {
Value pValue(vpOperand[i]->evaluate(root));
@@ -409,7 +409,7 @@ const char* ExpressionAnd::getOpName() const {
/* ------------------------- ExpressionAnyElementTrue -------------------------- */
-Value ExpressionAnyElementTrue::evaluate(Document root) const {
+Value ExpressionAnyElementTrue::evaluate(const Document& root) const {
const Value arr = vpOperand[0]->evaluate(root);
uassert(17041,
str::stream() << getOpName() << "'s argument must be an array, but is "
@@ -431,7 +431,7 @@ const char* ExpressionAnyElementTrue::getOpName() const {
/* ---------------------- ExpressionArray --------------------------- */
-Value ExpressionArray::evaluate(Document root) const {
+Value ExpressionArray::evaluate(const Document& root) const {
vector<Value> values;
values.reserve(vpOperand.size());
for (auto&& expr : vpOperand) {
@@ -457,7 +457,7 @@ const char* ExpressionArray::getOpName() const {
/* ------------------------- ExpressionArrayElemAt -------------------------- */
-Value ExpressionArrayElemAt::evaluate(Document root) const {
+Value ExpressionArrayElemAt::evaluate(const Document& root) const {
const Value array = vpOperand[0]->evaluate(root);
const Value indexArg = vpOperand[1]->evaluate(root);
@@ -499,7 +499,7 @@ const char* ExpressionArrayElemAt::getOpName() const {
/* ------------------------- ExpressionObjectToArray -------------------------- */
-Value ExpressionObjectToArray::evaluate(Document root) const {
+Value ExpressionObjectToArray::evaluate(const Document& root) const {
const Value targetVal = vpOperand[0]->evaluate(root);
if (targetVal.nullish()) {
@@ -531,7 +531,7 @@ const char* ExpressionObjectToArray::getOpName() const {
}
/* ------------------------- ExpressionArrayToObject -------------------------- */
-Value ExpressionArrayToObject::evaluate(Document root) const {
+Value ExpressionArrayToObject::evaluate(const Document& root) const {
const Value input = vpOperand[0]->evaluate(root);
if (input.nullish()) {
return Value(BSONNULL);
@@ -680,7 +680,7 @@ void ExpressionCoerceToBool::addDependencies(DepsTracker* deps) const {
pExpression->addDependencies(deps);
}
-Value ExpressionCoerceToBool::evaluate(Document root) const {
+Value ExpressionCoerceToBool::evaluate(const Document& root) const {
Value pResult(pExpression->evaluate(root));
bool b = pResult.coerceToBool();
if (b)
@@ -782,7 +782,7 @@ static const CmpLookup cmpLookup[7] = {
};
}
-Value ExpressionCompare::evaluate(Document root) const {
+Value ExpressionCompare::evaluate(const Document& root) const {
Value pLeft(vpOperand[0]->evaluate(root));
Value pRight(vpOperand[1]->evaluate(root));
@@ -810,7 +810,7 @@ const char* ExpressionCompare::getOpName() const {
/* ------------------------- ExpressionConcat ----------------------------- */
-Value ExpressionConcat::evaluate(Document root) const {
+Value ExpressionConcat::evaluate(const Document& root) const {
const size_t n = vpOperand.size();
StringBuilder result;
@@ -836,7 +836,7 @@ const char* ExpressionConcat::getOpName() const {
/* ------------------------- ExpressionConcatArrays ----------------------------- */
-Value ExpressionConcatArrays::evaluate(Document root) const {
+Value ExpressionConcatArrays::evaluate(const Document& root) const {
const size_t n = vpOperand.size();
vector<Value> values;
@@ -864,7 +864,7 @@ const char* ExpressionConcatArrays::getOpName() const {
/* ----------------------- ExpressionCond ------------------------------ */
-Value ExpressionCond::evaluate(Document root) const {
+Value ExpressionCond::evaluate(const Document& root) const {
Value pCond(vpOperand[0]->evaluate(root));
int idx = pCond.coerceToBool() ? 1 : 2;
return vpOperand[idx]->evaluate(root);
@@ -938,7 +938,7 @@ void ExpressionConstant::addDependencies(DepsTracker* deps) const {
/* nothing to do */
}
-Value ExpressionConstant::evaluate(Document root) const {
+Value ExpressionConstant::evaluate(const Document& root) const {
return pValue;
}
@@ -1008,7 +1008,7 @@ Value ExpressionDateToString::serialize(bool explain) const {
DOC("$dateToString" << DOC("format" << _format << "date" << _date->serialize(explain))));
}
-Value ExpressionDateToString::evaluate(Document root) const {
+Value ExpressionDateToString::evaluate(const Document& root) const {
const Value date = _date->evaluate(root);
if (date.nullish()) {
@@ -1158,7 +1158,7 @@ void ExpressionDateToString::addDependencies(DepsTracker* deps) const {
/* ---------------------- ExpressionDayOfMonth ------------------------- */
-Value ExpressionDayOfMonth::evaluate(Document root) const {
+Value ExpressionDayOfMonth::evaluate(const Document& root) const {
Value pDate(vpOperand[0]->evaluate(root));
return Value(extract(pDate.coerceToTm()));
}
@@ -1170,7 +1170,7 @@ const char* ExpressionDayOfMonth::getOpName() const {
/* ------------------------- ExpressionDayOfWeek ----------------------------- */
-Value ExpressionDayOfWeek::evaluate(Document root) const {
+Value ExpressionDayOfWeek::evaluate(const Document& root) const {
Value pDate(vpOperand[0]->evaluate(root));
return Value(extract(pDate.coerceToTm()));
}
@@ -1182,7 +1182,7 @@ const char* ExpressionDayOfWeek::getOpName() const {
/* ------------------------- ExpressionDayOfYear ----------------------------- */
-Value ExpressionDayOfYear::evaluate(Document root) const {
+Value ExpressionDayOfYear::evaluate(const Document& root) const {
Value pDate(vpOperand[0]->evaluate(root));
return Value(extract(pDate.coerceToTm()));
}
@@ -1194,7 +1194,7 @@ const char* ExpressionDayOfYear::getOpName() const {
/* ----------------------- ExpressionDivide ---------------------------- */
-Value ExpressionDivide::evaluate(Document root) const {
+Value ExpressionDivide::evaluate(const Document& root) const {
Value lhs = vpOperand[0]->evaluate(root);
Value rhs = vpOperand[1]->evaluate(root);
@@ -1295,7 +1295,7 @@ void ExpressionObject::addDependencies(DepsTracker* deps) const {
}
}
-Value ExpressionObject::evaluate(Document root) const {
+Value ExpressionObject::evaluate(const Document& root) const {
MutableDocument outputDoc;
for (auto&& pair : _expressions) {
outputDoc.addField(pair.first, pair.second->evaluate(root));
@@ -1408,7 +1408,7 @@ Value ExpressionFieldPath::evaluatePath(size_t index, const Document& input) con
}
}
-Value ExpressionFieldPath::evaluate(Document root) const {
+Value ExpressionFieldPath::evaluate(const Document& root) const {
auto& vars = getExpressionContext()->variables;
if (_fieldPath.getPathLength() == 1) // get the whole variable
return vars.getValue(_variable, root);
@@ -1512,7 +1512,7 @@ Value ExpressionFilter::serialize(bool explain) const {
<< _filter->serialize(explain))));
}
-Value ExpressionFilter::evaluate(Document root) const {
+Value ExpressionFilter::evaluate(const Document& root) const {
// We are guaranteed at parse time that this isn't using our _varId.
const Value inputVal = _input->evaluate(root);
if (inputVal.nullish())
@@ -1646,7 +1646,7 @@ Value ExpressionLet::serialize(bool explain) const {
DOC("$let" << DOC("vars" << vars.freeze() << "in" << _subExpression->serialize(explain))));
}
-Value ExpressionLet::evaluate(Document root) const {
+Value ExpressionLet::evaluate(const Document& root) const {
for (const auto& item : _variables) {
// It is guaranteed at parse-time that these expressions don't use the variable ids we
// are setting
@@ -1739,7 +1739,7 @@ Value ExpressionMap::serialize(bool explain) const {
<< _each->serialize(explain))));
}
-Value ExpressionMap::evaluate(Document root) const {
+Value ExpressionMap::evaluate(const Document& root) const {
// guaranteed at parse time that this isn't using our _varId
const Value inputVal = _input->evaluate(root);
if (inputVal.nullish())
@@ -1807,7 +1807,7 @@ Value ExpressionMeta::serialize(bool explain) const {
MONGO_UNREACHABLE;
}
-Value ExpressionMeta::evaluate(Document root) const {
+Value ExpressionMeta::evaluate(const Document& root) const {
switch (_metaType) {
case MetaType::TEXT_SCORE:
return root.hasTextScore() ? Value(root.getTextScore()) : Value();
@@ -1825,7 +1825,7 @@ void ExpressionMeta::addDependencies(DepsTracker* deps) const {
/* ------------------------- ExpressionMillisecond ----------------------------- */
-Value ExpressionMillisecond::evaluate(Document root) const {
+Value ExpressionMillisecond::evaluate(const Document& root) const {
Value date(vpOperand[0]->evaluate(root));
return Value(extract(date.coerceToDate()));
}
@@ -1843,7 +1843,7 @@ const char* ExpressionMillisecond::getOpName() const {
/* ------------------------- ExpressionMinute -------------------------- */
-Value ExpressionMinute::evaluate(Document root) const {
+Value ExpressionMinute::evaluate(const Document& root) const {
Value pDate(vpOperand[0]->evaluate(root));
return Value(extract(pDate.coerceToTm()));
}
@@ -1855,7 +1855,7 @@ const char* ExpressionMinute::getOpName() const {
/* ----------------------- ExpressionMod ---------------------------- */
-Value ExpressionMod::evaluate(Document root) const {
+Value ExpressionMod::evaluate(const Document& root) const {
Value lhs = vpOperand[0]->evaluate(root);
Value rhs = vpOperand[1]->evaluate(root);
@@ -1912,7 +1912,7 @@ const char* ExpressionMod::getOpName() const {
/* ------------------------ ExpressionMonth ----------------------------- */
-Value ExpressionMonth::evaluate(Document root) const {
+Value ExpressionMonth::evaluate(const Document& root) const {
Value pDate(vpOperand[0]->evaluate(root));
return Value(extract(pDate.coerceToTm()));
}
@@ -1924,7 +1924,7 @@ const char* ExpressionMonth::getOpName() const {
/* ------------------------- ExpressionMultiply ----------------------------- */
-Value ExpressionMultiply::evaluate(Document root) const {
+Value ExpressionMultiply::evaluate(const Document& root) const {
/*
We'll try to return the narrowest possible result value. To do that
without creating intermediate Values, do the arithmetic for double
@@ -1987,7 +1987,7 @@ const char* ExpressionMultiply::getOpName() const {
/* ------------------------- ExpressionHour ----------------------------- */
-Value ExpressionHour::evaluate(Document root) const {
+Value ExpressionHour::evaluate(const Document& root) const {
Value pDate(vpOperand[0]->evaluate(root));
return Value(extract(pDate.coerceToTm()));
}
@@ -1999,7 +1999,7 @@ const char* ExpressionHour::getOpName() const {
/* ----------------------- ExpressionIfNull ---------------------------- */
-Value ExpressionIfNull::evaluate(Document root) const {
+Value ExpressionIfNull::evaluate(const Document& root) const {
Value pLeft(vpOperand[0]->evaluate(root));
if (!pLeft.nullish())
return pLeft;
@@ -2015,7 +2015,7 @@ const char* ExpressionIfNull::getOpName() const {
/* ----------------------- ExpressionIn ---------------------------- */
-Value ExpressionIn::evaluate(Document root) const {
+Value ExpressionIn::evaluate(const Document& root) const {
Value argument(vpOperand[0]->evaluate(root));
Value arrayOfValues(vpOperand[1]->evaluate(root));
@@ -2059,7 +2059,7 @@ void uassertIfNotIntegralAndNonNegative(Value val,
} // namespace
-Value ExpressionIndexOfArray::evaluate(Document root) const {
+Value ExpressionIndexOfArray::evaluate(const Document& root) const {
Value arrayArg = vpOperand[0]->evaluate(root);
if (arrayArg.nullish()) {
@@ -2117,7 +2117,7 @@ bool stringHasTokenAtIndex(size_t index, const std::string& input, const std::st
} // namespace
-Value ExpressionIndexOfBytes::evaluate(Document root) const {
+Value ExpressionIndexOfBytes::evaluate(const Document& root) const {
Value stringArg = vpOperand[0]->evaluate(root);
if (stringArg.nullish()) {
@@ -2171,7 +2171,7 @@ const char* ExpressionIndexOfBytes::getOpName() const {
/* ----------------------- ExpressionIndexOfCP --------------------- */
-Value ExpressionIndexOfCP::evaluate(Document root) const {
+Value ExpressionIndexOfCP::evaluate(const Document& root) const {
Value stringArg = vpOperand[0]->evaluate(root);
if (stringArg.nullish()) {
@@ -2272,7 +2272,7 @@ const char* ExpressionLn::getOpName() const {
/* ----------------------- ExpressionLog ---------------------------- */
-Value ExpressionLog::evaluate(Document root) const {
+Value ExpressionLog::evaluate(const Document& root) const {
Value argVal = vpOperand[0]->evaluate(root);
Value baseVal = vpOperand[1]->evaluate(root);
if (argVal.nullish() || baseVal.nullish())
@@ -2459,7 +2459,7 @@ Value ExpressionNary::serialize(bool explain) const {
/* ------------------------- ExpressionNot ----------------------------- */
-Value ExpressionNot::evaluate(Document root) const {
+Value ExpressionNot::evaluate(const Document& root) const {
Value pOp(vpOperand[0]->evaluate(root));
bool b = pOp.coerceToBool();
@@ -2473,7 +2473,7 @@ const char* ExpressionNot::getOpName() const {
/* -------------------------- ExpressionOr ----------------------------- */
-Value ExpressionOr::evaluate(Document root) const {
+Value ExpressionOr::evaluate(const Document& root) const {
const size_t n = vpOperand.size();
for (size_t i = 0; i < n; ++i) {
Value pValue(vpOperand[i]->evaluate(root));
@@ -2553,7 +2553,7 @@ intrusive_ptr<Expression> ExpressionPow::create(
return expr;
}
-Value ExpressionPow::evaluate(Document root) const {
+Value ExpressionPow::evaluate(const Document& root) const {
Value baseVal = vpOperand[0]->evaluate(root);
Value expVal = vpOperand[1]->evaluate(root);
if (baseVal.nullish() || expVal.nullish())
@@ -2713,7 +2713,7 @@ const char* ExpressionPow::getOpName() const {
/* ------------------------- ExpressionRange ------------------------------ */
-Value ExpressionRange::evaluate(Document root) const {
+Value ExpressionRange::evaluate(const Document& root) const {
Value startVal(vpOperand[0]->evaluate(root));
Value endVal(vpOperand[1]->evaluate(root));
@@ -2813,7 +2813,7 @@ intrusive_ptr<Expression> ExpressionReduce::parse(
return reduce;
}
-Value ExpressionReduce::evaluate(Document root) const {
+Value ExpressionReduce::evaluate(const Document& root) const {
Value inputVal = _input->evaluate(root);
if (inputVal.nullish()) {
@@ -2860,7 +2860,7 @@ Value ExpressionReduce::serialize(bool explain) const {
/* ------------------------ ExpressionReverseArray ------------------------ */
-Value ExpressionReverseArray::evaluate(Document root) const {
+Value ExpressionReverseArray::evaluate(const Document& root) const {
Value input(vpOperand[0]->evaluate(root));
if (input.nullish()) {
@@ -2888,7 +2888,7 @@ const char* ExpressionReverseArray::getOpName() const {
/* ------------------------- ExpressionSecond ----------------------------- */
-Value ExpressionSecond::evaluate(Document root) const {
+Value ExpressionSecond::evaluate(const Document& root) const {
Value pDate(vpOperand[0]->evaluate(root));
return Value(extract(pDate.coerceToTm()));
}
@@ -2909,7 +2909,7 @@ ValueSet arrayToSet(const Value& val, const ValueComparator& valueComparator) {
/* ----------------------- ExpressionSetDifference ---------------------------- */
-Value ExpressionSetDifference::evaluate(Document root) const {
+Value ExpressionSetDifference::evaluate(const Document& root) const {
const Value lhs = vpOperand[0]->evaluate(root);
const Value rhs = vpOperand[1]->evaluate(root);
@@ -2955,7 +2955,7 @@ void ExpressionSetEquals::validateArguments(const ExpressionVector& args) const
args.size() >= 2);
}
-Value ExpressionSetEquals::evaluate(Document root) const {
+Value ExpressionSetEquals::evaluate(const Document& root) const {
const size_t n = vpOperand.size();
const auto& valueComparator = getExpressionContext()->getValueComparator();
ValueSet lhs = valueComparator.makeOrderedValueSet();
@@ -2992,7 +2992,7 @@ const char* ExpressionSetEquals::getOpName() const {
/* ----------------------- ExpressionSetIntersection ---------------------------- */
-Value ExpressionSetIntersection::evaluate(Document root) const {
+Value ExpressionSetIntersection::evaluate(const Document& root) const {
const size_t n = vpOperand.size();
const auto& valueComparator = getExpressionContext()->getValueComparator();
ValueSet currentIntersection = valueComparator.makeOrderedValueSet();
@@ -3053,7 +3053,7 @@ Value setIsSubsetHelper(const vector<Value>& lhs, const ValueSet& rhs) {
}
}
-Value ExpressionSetIsSubset::evaluate(Document root) const {
+Value ExpressionSetIsSubset::evaluate(const Document& root) const {
const Value lhs = vpOperand[0]->evaluate(root);
const Value rhs = vpOperand[1]->evaluate(root);
@@ -3088,7 +3088,7 @@ public:
vpOperand = operands;
}
- virtual Value evaluate(Document root) const {
+ virtual Value evaluate(const Document& root) const {
const Value lhs = vpOperand[0]->evaluate(root);
uassert(17310,
@@ -3136,7 +3136,7 @@ const char* ExpressionSetIsSubset::getOpName() const {
/* ----------------------- ExpressionSetUnion ---------------------------- */
-Value ExpressionSetUnion::evaluate(Document root) const {
+Value ExpressionSetUnion::evaluate(const Document& root) const {
ValueSet unionedSet = getExpressionContext()->getValueComparator().makeOrderedValueSet();
const size_t n = vpOperand.size();
for (size_t i = 0; i < n; i++) {
@@ -3162,7 +3162,7 @@ const char* ExpressionSetUnion::getOpName() const {
/* ----------------------- ExpressionIsArray ---------------------------- */
-Value ExpressionIsArray::evaluate(Document root) const {
+Value ExpressionIsArray::evaluate(const Document& root) const {
Value argument = vpOperand[0]->evaluate(root);
return Value(argument.isArray());
}
@@ -3174,7 +3174,7 @@ const char* ExpressionIsArray::getOpName() const {
/* ----------------------- ExpressionSlice ---------------------------- */
-Value ExpressionSlice::evaluate(Document root) const {
+Value ExpressionSlice::evaluate(const Document& root) const {
const size_t n = vpOperand.size();
Value arrayVal = vpOperand[0]->evaluate(root);
@@ -3265,7 +3265,7 @@ const char* ExpressionSlice::getOpName() const {
/* ----------------------- ExpressionSize ---------------------------- */
-Value ExpressionSize::evaluate(Document root) const {
+Value ExpressionSize::evaluate(const Document& root) const {
Value array = vpOperand[0]->evaluate(root);
uassert(17124,
@@ -3282,7 +3282,7 @@ const char* ExpressionSize::getOpName() const {
/* ----------------------- ExpressionSplit --------------------------- */
-Value ExpressionSplit::evaluate(Document root) const {
+Value ExpressionSplit::evaluate(const Document& root) const {
Value inputArg = vpOperand[0]->evaluate(root);
Value separatorArg = vpOperand[1]->evaluate(root);
@@ -3360,7 +3360,7 @@ const char* ExpressionSqrt::getOpName() const {
/* ----------------------- ExpressionStrcasecmp ---------------------------- */
-Value ExpressionStrcasecmp::evaluate(Document root) const {
+Value ExpressionStrcasecmp::evaluate(const Document& root) const {
Value pString1(vpOperand[0]->evaluate(root));
Value pString2(vpOperand[1]->evaluate(root));
@@ -3384,7 +3384,7 @@ const char* ExpressionStrcasecmp::getOpName() const {
/* ----------------------- ExpressionSubstrBytes ---------------------------- */
-Value ExpressionSubstrBytes::evaluate(Document root) const {
+Value ExpressionSubstrBytes::evaluate(const Document& root) const {
Value pString(vpOperand[0]->evaluate(root));
Value pLower(vpOperand[1]->evaluate(root));
Value pLength(vpOperand[2]->evaluate(root));
@@ -3437,7 +3437,7 @@ const char* ExpressionSubstrBytes::getOpName() const {
/* ----------------------- ExpressionSubstrCP ---------------------------- */
-Value ExpressionSubstrCP::evaluate(Document root) const {
+Value ExpressionSubstrCP::evaluate(const Document& root) const {
Value inputVal(vpOperand[0]->evaluate(root));
Value lowerVal(vpOperand[1]->evaluate(root));
Value lengthVal(vpOperand[2]->evaluate(root));
@@ -3512,7 +3512,7 @@ const char* ExpressionSubstrCP::getOpName() const {
/* ----------------------- ExpressionStrLenBytes ------------------------- */
-Value ExpressionStrLenBytes::evaluate(Document root) const {
+Value ExpressionStrLenBytes::evaluate(const Document& root) const {
Value str(vpOperand[0]->evaluate(root));
uassert(34473,
@@ -3535,7 +3535,7 @@ const char* ExpressionStrLenBytes::getOpName() const {
/* ----------------------- ExpressionStrLenCP ------------------------- */
-Value ExpressionStrLenCP::evaluate(Document root) const {
+Value ExpressionStrLenCP::evaluate(const Document& root) const {
Value val(vpOperand[0]->evaluate(root));
uassert(34471,
@@ -3564,7 +3564,7 @@ const char* ExpressionStrLenCP::getOpName() const {
/* ----------------------- ExpressionSubtract ---------------------------- */
-Value ExpressionSubtract::evaluate(Document root) const {
+Value ExpressionSubtract::evaluate(const Document& root) const {
Value lhs = vpOperand[0]->evaluate(root);
Value rhs = vpOperand[1]->evaluate(root);
@@ -3616,7 +3616,7 @@ const char* ExpressionSubtract::getOpName() const {
REGISTER_EXPRESSION(switch, ExpressionSwitch::parse);
-Value ExpressionSwitch::evaluate(Document root) const {
+Value ExpressionSwitch::evaluate(const Document& root) const {
for (auto&& branch : _branches) {
Value caseExpression(branch.first->evaluate(root));
@@ -3743,7 +3743,7 @@ Value ExpressionSwitch::serialize(bool explain) const {
/* ------------------------- ExpressionToLower ----------------------------- */
-Value ExpressionToLower::evaluate(Document root) const {
+Value ExpressionToLower::evaluate(const Document& root) const {
Value pString(vpOperand[0]->evaluate(root));
string str = pString.coerceToString();
boost::to_lower(str);
@@ -3757,7 +3757,7 @@ const char* ExpressionToLower::getOpName() const {
/* ------------------------- ExpressionToUpper -------------------------- */
-Value ExpressionToUpper::evaluate(Document root) const {
+Value ExpressionToUpper::evaluate(const Document& root) const {
Value pString(vpOperand[0]->evaluate(root));
string str(pString.coerceToString());
boost::to_upper(str);
@@ -3791,7 +3791,7 @@ const char* ExpressionTrunc::getOpName() const {
/* ------------------------- ExpressionType ----------------------------- */
-Value ExpressionType::evaluate(Document root) const {
+Value ExpressionType::evaluate(const Document& root) const {
Value val(vpOperand[0]->evaluate(root));
return Value(StringData(typeName(val.getType())));
}
@@ -3803,7 +3803,7 @@ const char* ExpressionType::getOpName() const {
/* ------------------------- ExpressionWeek ----------------------------- */
-Value ExpressionWeek::evaluate(Document root) const {
+Value ExpressionWeek::evaluate(const Document& root) const {
Value pDate(vpOperand[0]->evaluate(root));
return Value(extract(pDate.coerceToTm()));
}
@@ -3835,7 +3835,7 @@ const char* ExpressionWeek::getOpName() const {
/* ------------------------- ExpressionIsoDayOfWeek --------------------- */
-Value ExpressionIsoDayOfWeek::evaluate(Document root) const {
+Value ExpressionIsoDayOfWeek::evaluate(const Document& root) const {
Value date(vpOperand[0]->evaluate(root));
return Value(extract(date.coerceToTm()));
}
@@ -3852,7 +3852,7 @@ const char* ExpressionIsoDayOfWeek::getOpName() const {
/* ------------------------- ExpressionIsoWeekYear ---------------------- */
-Value ExpressionIsoWeekYear::evaluate(Document root) const {
+Value ExpressionIsoWeekYear::evaluate(const Document& root) const {
Value date(vpOperand[0]->evaluate(root));
return Value(extract(date.coerceToTm()));
}
@@ -3938,7 +3938,7 @@ int lastWeek(int year) {
}
}
-Value ExpressionIsoWeek::evaluate(Document root) const {
+Value ExpressionIsoWeek::evaluate(const Document& root) const {
Value date(vpOperand[0]->evaluate(root));
return Value(extract(date.coerceToTm()));
}
@@ -3987,7 +3987,7 @@ const char* ExpressionIsoWeek::getOpName() const {
/* ------------------------- ExpressionYear ----------------------------- */
-Value ExpressionYear::evaluate(Document root) const {
+Value ExpressionYear::evaluate(const Document& root) const {
Value pDate(vpOperand[0]->evaluate(root));
return Value(extract(pDate.coerceToTm()));
}
@@ -4052,7 +4052,7 @@ intrusive_ptr<Expression> ExpressionZip::parse(
return std::move(newZip);
}
-Value ExpressionZip::evaluate(Document root) const {
+Value ExpressionZip::evaluate(const Document& root) const {
// Evaluate input values.
vector<vector<Value>> inputValues;
inputValues.reserve(_inputs.size());
diff --git a/src/mongo/db/pipeline/expression.h b/src/mongo/db/pipeline/expression.h
index d698fd127f7..124e4916c1d 100644
--- a/src/mongo/db/pipeline/expression.h
+++ b/src/mongo/db/pipeline/expression.h
@@ -105,7 +105,7 @@ public:
/**
* Evaluate expression with respect to the Document given by 'root', and return the result.
*/
- virtual Value evaluate(Document root) const = 0;
+ virtual Value evaluate(const Document& root) const = 0;
/**
* Parses a BSON Object that could represent an object literal or a functional expression like
@@ -300,7 +300,7 @@ public:
explicit ExpressionFromAccumulator(const boost::intrusive_ptr<ExpressionContext>& expCtx)
: ExpressionVariadic<ExpressionFromAccumulator<Accumulator>>(expCtx) {}
- Value evaluate(Document root) const final {
+ Value evaluate(const Document& root) const final {
Accumulator accum(this->getExpressionContext());
const size_t n = this->vpOperand.size();
// If a single array arg is given, loop through it passing each member to the accumulator.
@@ -352,7 +352,7 @@ public:
virtual ~ExpressionSingleNumericArg() {}
- Value evaluate(Document root) const final {
+ Value evaluate(const Document& root) const final {
Value arg = this->vpOperand[0]->evaluate(root);
if (arg.nullish())
return Value(BSONNULL);
@@ -384,7 +384,7 @@ public:
explicit ExpressionAdd(const boost::intrusive_ptr<ExpressionContext>& expCtx)
: ExpressionVariadic<ExpressionAdd>(expCtx) {}
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
const char* getOpName() const final;
bool isAssociative() const final {
@@ -402,7 +402,7 @@ public:
explicit ExpressionAllElementsTrue(const boost::intrusive_ptr<ExpressionContext>& expCtx)
: ExpressionFixedArity<ExpressionAllElementsTrue, 1>(expCtx) {}
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
const char* getOpName() const final;
};
@@ -413,7 +413,7 @@ public:
: ExpressionVariadic<ExpressionAnd>(expCtx) {}
boost::intrusive_ptr<Expression> optimize() final;
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
const char* getOpName() const final;
bool isAssociative() const final {
@@ -431,7 +431,7 @@ public:
explicit ExpressionAnyElementTrue(const boost::intrusive_ptr<ExpressionContext>& expCtx)
: ExpressionFixedArity<ExpressionAnyElementTrue, 1>(expCtx) {}
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
const char* getOpName() const final;
};
@@ -441,7 +441,7 @@ public:
explicit ExpressionArray(const boost::intrusive_ptr<ExpressionContext>& expCtx)
: ExpressionVariadic<ExpressionArray>(expCtx) {}
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
Value serialize(bool explain) const final;
const char* getOpName() const final;
};
@@ -452,7 +452,7 @@ public:
explicit ExpressionArrayElemAt(const boost::intrusive_ptr<ExpressionContext>& expCtx)
: ExpressionFixedArity<ExpressionArrayElemAt, 2>(expCtx) {}
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
const char* getOpName() const final;
};
@@ -461,7 +461,7 @@ public:
explicit ExpressionObjectToArray(const boost::intrusive_ptr<ExpressionContext>& expCtx)
: ExpressionFixedArity<ExpressionObjectToArray, 1>(expCtx) {}
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
const char* getOpName() const final;
};
@@ -470,7 +470,7 @@ public:
explicit ExpressionArrayToObject(const boost::intrusive_ptr<ExpressionContext>& expCtx)
: ExpressionFixedArity<ExpressionArrayToObject, 1>(expCtx) {}
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
const char* getOpName() const final;
};
@@ -488,7 +488,7 @@ class ExpressionCoerceToBool final : public Expression {
public:
boost::intrusive_ptr<Expression> optimize() final;
void addDependencies(DepsTracker* deps) const final;
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
Value serialize(bool explain) const final;
static boost::intrusive_ptr<ExpressionCoerceToBool> create(
@@ -522,7 +522,7 @@ public:
ExpressionCompare(const boost::intrusive_ptr<ExpressionContext>& expCtx, CmpOp cmpOp)
: ExpressionFixedArity<ExpressionCompare, 2>(expCtx), cmpOp(cmpOp) {}
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
const char* getOpName() const final;
static boost::intrusive_ptr<Expression> parse(
@@ -547,7 +547,7 @@ public:
explicit ExpressionConcat(const boost::intrusive_ptr<ExpressionContext>& expCtx)
: ExpressionVariadic<ExpressionConcat>(expCtx) {}
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
const char* getOpName() const final;
bool isAssociative() const final {
@@ -561,7 +561,7 @@ public:
explicit ExpressionConcatArrays(const boost::intrusive_ptr<ExpressionContext>& expCtx)
: ExpressionVariadic<ExpressionConcatArrays>(expCtx) {}
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
const char* getOpName() const final;
bool isAssociative() const final {
@@ -574,7 +574,7 @@ class ExpressionCond final : public ExpressionFixedArity<ExpressionCond, 3> {
public:
explicit ExpressionCond(const boost::intrusive_ptr<ExpressionContext>& expCtx) : Base(expCtx) {}
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
const char* getOpName() const final;
static boost::intrusive_ptr<Expression> parse(
@@ -591,7 +591,7 @@ class ExpressionConstant final : public Expression {
public:
boost::intrusive_ptr<Expression> optimize() final;
void addDependencies(DepsTracker* deps) const final;
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
Value serialize(bool explain) const final;
const char* getOpName() const;
@@ -623,7 +623,7 @@ class ExpressionDateToString final : public Expression {
public:
boost::intrusive_ptr<Expression> optimize() final;
Value serialize(bool explain) const final;
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
void addDependencies(DepsTracker* deps) const final;
static boost::intrusive_ptr<Expression> parse(
@@ -654,7 +654,7 @@ public:
explicit ExpressionDayOfMonth(const boost::intrusive_ptr<ExpressionContext>& expCtx)
: ExpressionFixedArity<ExpressionDayOfMonth, 1>(expCtx) {}
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
const char* getOpName() const final;
static inline int extract(const tm& tm) {
@@ -668,7 +668,7 @@ public:
explicit ExpressionDayOfWeek(const boost::intrusive_ptr<ExpressionContext>& expCtx)
: ExpressionFixedArity<ExpressionDayOfWeek, 1>(expCtx) {}
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
const char* getOpName() const final;
// MySQL uses 1-7, tm uses 0-6
@@ -683,7 +683,7 @@ public:
explicit ExpressionDayOfYear(const boost::intrusive_ptr<ExpressionContext>& expCtx)
: ExpressionFixedArity<ExpressionDayOfYear, 1>(expCtx) {}
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
const char* getOpName() const final;
// MySQL uses 1-366, tm uses 0-365
@@ -698,7 +698,7 @@ public:
explicit ExpressionDivide(const boost::intrusive_ptr<ExpressionContext>& expCtx)
: ExpressionFixedArity<ExpressionDivide, 2>(expCtx) {}
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
const char* getOpName() const final;
};
@@ -717,7 +717,7 @@ class ExpressionFieldPath final : public Expression {
public:
boost::intrusive_ptr<Expression> optimize() final;
void addDependencies(DepsTracker* deps) const final;
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
Value serialize(bool explain) const final;
/*
@@ -782,7 +782,7 @@ class ExpressionFilter final : public Expression {
public:
boost::intrusive_ptr<Expression> optimize() final;
Value serialize(bool explain) const final;
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
void addDependencies(DepsTracker* deps) const final;
static boost::intrusive_ptr<Expression> parse(
@@ -823,7 +823,7 @@ public:
explicit ExpressionHour(const boost::intrusive_ptr<ExpressionContext>& expCtx)
: ExpressionFixedArity<ExpressionHour, 1>(expCtx) {}
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
const char* getOpName() const final;
static inline int extract(const tm& tm) {
@@ -837,7 +837,7 @@ public:
explicit ExpressionIfNull(const boost::intrusive_ptr<ExpressionContext>& expCtx)
: ExpressionFixedArity<ExpressionIfNull, 2>(expCtx) {}
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
const char* getOpName() const final;
};
@@ -847,7 +847,7 @@ public:
explicit ExpressionIn(const boost::intrusive_ptr<ExpressionContext>& expCtx)
: ExpressionFixedArity<ExpressionIn, 2>(expCtx) {}
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
const char* getOpName() const final;
};
@@ -857,7 +857,7 @@ public:
explicit ExpressionIndexOfArray(const boost::intrusive_ptr<ExpressionContext>& expCtx)
: ExpressionRangedArity<ExpressionIndexOfArray, 2, 4>(expCtx) {}
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
const char* getOpName() const final;
};
@@ -867,7 +867,7 @@ public:
explicit ExpressionIndexOfBytes(const boost::intrusive_ptr<ExpressionContext>& expCtx)
: ExpressionRangedArity<ExpressionIndexOfBytes, 2, 4>(expCtx) {}
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
const char* getOpName() const final;
};
@@ -880,7 +880,7 @@ public:
explicit ExpressionIndexOfCP(const boost::intrusive_ptr<ExpressionContext>& expCtx)
: ExpressionRangedArity<ExpressionIndexOfCP, 2, 4>(expCtx) {}
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
const char* getOpName() const final;
};
@@ -889,7 +889,7 @@ class ExpressionLet final : public Expression {
public:
boost::intrusive_ptr<Expression> optimize() final;
Value serialize(bool explain) const final;
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
void addDependencies(DepsTracker* deps) const final;
static boost::intrusive_ptr<Expression> parse(
@@ -931,7 +931,7 @@ public:
explicit ExpressionLog(const boost::intrusive_ptr<ExpressionContext>& expCtx)
: ExpressionFixedArity<ExpressionLog, 2>(expCtx) {}
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
const char* getOpName() const final;
};
@@ -948,7 +948,7 @@ class ExpressionMap final : public Expression {
public:
boost::intrusive_ptr<Expression> optimize() final;
Value serialize(bool explain) const final;
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
void addDependencies(DepsTracker* deps) const final;
static boost::intrusive_ptr<Expression> parse(
@@ -973,7 +973,7 @@ private:
class ExpressionMeta final : public Expression {
public:
Value serialize(bool explain) const final;
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
void addDependencies(DepsTracker* deps) const final;
static boost::intrusive_ptr<Expression> parse(
@@ -997,7 +997,7 @@ public:
explicit ExpressionMillisecond(const boost::intrusive_ptr<ExpressionContext>& expCtx)
: ExpressionFixedArity<ExpressionMillisecond, 1>(expCtx) {}
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
const char* getOpName() const final;
static int extract(const long long date);
@@ -1009,7 +1009,7 @@ public:
explicit ExpressionMinute(const boost::intrusive_ptr<ExpressionContext>& expCtx)
: ExpressionFixedArity<ExpressionMinute, 1>(expCtx) {}
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
const char* getOpName() const final;
static int extract(const tm& tm) {
@@ -1023,7 +1023,7 @@ public:
explicit ExpressionMod(const boost::intrusive_ptr<ExpressionContext>& expCtx)
: ExpressionFixedArity<ExpressionMod, 2>(expCtx) {}
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
const char* getOpName() const final;
};
@@ -1033,7 +1033,7 @@ public:
explicit ExpressionMultiply(const boost::intrusive_ptr<ExpressionContext>& expCtx)
: ExpressionVariadic<ExpressionMultiply>(expCtx) {}
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
const char* getOpName() const final;
bool isAssociative() const final {
@@ -1051,7 +1051,7 @@ public:
explicit ExpressionMonth(const boost::intrusive_ptr<ExpressionContext>& expCtx)
: ExpressionFixedArity<ExpressionMonth, 1>(expCtx) {}
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
const char* getOpName() const final;
// MySQL uses 1-12, tm uses 0-11
@@ -1066,7 +1066,7 @@ public:
explicit ExpressionNot(const boost::intrusive_ptr<ExpressionContext>& expCtx)
: ExpressionFixedArity<ExpressionNot, 1>(expCtx) {}
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
const char* getOpName() const final;
};
@@ -1083,7 +1083,7 @@ class ExpressionObject final : public Expression {
public:
boost::intrusive_ptr<Expression> optimize() final;
void addDependencies(DepsTracker* deps) const final;
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
Value serialize(bool explain) const final;
static boost::intrusive_ptr<ExpressionObject> create(
@@ -1123,7 +1123,7 @@ public:
: ExpressionVariadic<ExpressionOr>(expCtx) {}
boost::intrusive_ptr<Expression> optimize() final;
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
const char* getOpName() const final;
bool isAssociative() const final {
@@ -1144,7 +1144,7 @@ public:
const boost::intrusive_ptr<ExpressionContext>& expCtx, Value base, Value exp);
private:
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
const char* getOpName() const final;
};
@@ -1154,7 +1154,7 @@ public:
explicit ExpressionRange(const boost::intrusive_ptr<ExpressionContext>& expCtx)
: ExpressionRangedArity<ExpressionRange, 2, 3>(expCtx) {}
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
const char* getOpName() const final;
};
@@ -1165,7 +1165,7 @@ public:
: Expression(expCtx) {}
void addDependencies(DepsTracker* deps) const final;
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
boost::intrusive_ptr<Expression> optimize() final;
static boost::intrusive_ptr<Expression> parse(
const boost::intrusive_ptr<ExpressionContext>& expCtx,
@@ -1188,7 +1188,7 @@ public:
explicit ExpressionSecond(const boost::intrusive_ptr<ExpressionContext>& expCtx)
: ExpressionFixedArity<ExpressionSecond, 1>(expCtx) {}
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
const char* getOpName() const final;
static inline int extract(const tm& tm) {
@@ -1202,7 +1202,7 @@ public:
explicit ExpressionSetDifference(const boost::intrusive_ptr<ExpressionContext>& expCtx)
: ExpressionFixedArity<ExpressionSetDifference, 2>(expCtx) {}
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
const char* getOpName() const final;
};
@@ -1212,7 +1212,7 @@ public:
explicit ExpressionSetEquals(const boost::intrusive_ptr<ExpressionContext>& expCtx)
: ExpressionVariadic<ExpressionSetEquals>(expCtx) {}
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
const char* getOpName() const final;
void validateArguments(const ExpressionVector& args) const final;
};
@@ -1223,7 +1223,7 @@ public:
explicit ExpressionSetIntersection(const boost::intrusive_ptr<ExpressionContext>& expCtx)
: ExpressionVariadic<ExpressionSetIntersection>(expCtx) {}
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
const char* getOpName() const final;
bool isAssociative() const final {
@@ -1243,7 +1243,7 @@ public:
: ExpressionFixedArity<ExpressionSetIsSubset, 2>(expCtx) {}
boost::intrusive_ptr<Expression> optimize() override;
- Value evaluate(Document root) const override;
+ Value evaluate(const Document& root) const override;
const char* getOpName() const final;
private:
@@ -1256,7 +1256,7 @@ public:
explicit ExpressionSetUnion(const boost::intrusive_ptr<ExpressionContext>& expCtx)
: ExpressionVariadic<ExpressionSetUnion>(expCtx) {}
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
const char* getOpName() const final;
bool isAssociative() const final {
@@ -1274,7 +1274,7 @@ public:
explicit ExpressionSize(const boost::intrusive_ptr<ExpressionContext>& expCtx)
: ExpressionFixedArity<ExpressionSize, 1>(expCtx) {}
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
const char* getOpName() const final;
};
@@ -1284,7 +1284,7 @@ public:
explicit ExpressionReverseArray(const boost::intrusive_ptr<ExpressionContext>& expCtx)
: ExpressionFixedArity<ExpressionReverseArray, 1>(expCtx) {}
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
const char* getOpName() const final;
};
@@ -1294,7 +1294,7 @@ public:
explicit ExpressionSlice(const boost::intrusive_ptr<ExpressionContext>& expCtx)
: ExpressionRangedArity<ExpressionSlice, 2, 3>(expCtx) {}
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
const char* getOpName() const final;
};
@@ -1304,7 +1304,7 @@ public:
explicit ExpressionIsArray(const boost::intrusive_ptr<ExpressionContext>& expCtx)
: ExpressionFixedArity<ExpressionIsArray, 1>(expCtx) {}
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
const char* getOpName() const final;
};
@@ -1314,7 +1314,7 @@ public:
explicit ExpressionSplit(const boost::intrusive_ptr<ExpressionContext>& expCtx)
: ExpressionFixedArity<ExpressionSplit, 2>(expCtx) {}
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
const char* getOpName() const final;
};
@@ -1334,7 +1334,7 @@ public:
explicit ExpressionStrcasecmp(const boost::intrusive_ptr<ExpressionContext>& expCtx)
: ExpressionFixedArity<ExpressionStrcasecmp, 2>(expCtx) {}
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
const char* getOpName() const final;
};
@@ -1344,7 +1344,7 @@ public:
explicit ExpressionSubstrBytes(const boost::intrusive_ptr<ExpressionContext>& expCtx)
: ExpressionFixedArity<ExpressionSubstrBytes, 3>(expCtx) {}
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
const char* getOpName() const;
};
@@ -1354,7 +1354,7 @@ public:
explicit ExpressionSubstrCP(const boost::intrusive_ptr<ExpressionContext>& expCtx)
: ExpressionFixedArity<ExpressionSubstrCP, 3>(expCtx) {}
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
const char* getOpName() const final;
};
@@ -1364,7 +1364,7 @@ public:
explicit ExpressionStrLenBytes(const boost::intrusive_ptr<ExpressionContext>& expCtx)
: ExpressionFixedArity<ExpressionStrLenBytes, 1>(expCtx) {}
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
const char* getOpName() const final;
};
@@ -1374,7 +1374,7 @@ public:
explicit ExpressionStrLenCP(const boost::intrusive_ptr<ExpressionContext>& expCtx)
: ExpressionFixedArity<ExpressionStrLenCP, 1>(expCtx) {}
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
const char* getOpName() const final;
};
@@ -1384,7 +1384,7 @@ public:
explicit ExpressionSubtract(const boost::intrusive_ptr<ExpressionContext>& expCtx)
: ExpressionFixedArity<ExpressionSubtract, 2>(expCtx) {}
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
const char* getOpName() const final;
};
@@ -1395,7 +1395,7 @@ public:
: Expression(expCtx) {}
void addDependencies(DepsTracker* deps) const final;
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
boost::intrusive_ptr<Expression> optimize() final;
static boost::intrusive_ptr<Expression> parse(
const boost::intrusive_ptr<ExpressionContext>& expCtx,
@@ -1417,7 +1417,7 @@ public:
explicit ExpressionToLower(const boost::intrusive_ptr<ExpressionContext>& expCtx)
: ExpressionFixedArity<ExpressionToLower, 1>(expCtx) {}
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
const char* getOpName() const final;
};
@@ -1427,7 +1427,7 @@ public:
explicit ExpressionToUpper(const boost::intrusive_ptr<ExpressionContext>& expCtx)
: ExpressionFixedArity<ExpressionToUpper, 1>(expCtx) {}
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
const char* getOpName() const final;
};
@@ -1447,7 +1447,7 @@ public:
explicit ExpressionType(const boost::intrusive_ptr<ExpressionContext>& expCtx)
: ExpressionFixedArity<ExpressionType, 1>(expCtx) {}
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
const char* getOpName() const final;
};
@@ -1457,7 +1457,7 @@ public:
explicit ExpressionWeek(const boost::intrusive_ptr<ExpressionContext>& expCtx)
: ExpressionFixedArity<ExpressionWeek, 1>(expCtx) {}
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
const char* getOpName() const final;
static int extract(const tm& tm);
@@ -1469,7 +1469,7 @@ public:
explicit ExpressionIsoWeekYear(const boost::intrusive_ptr<ExpressionContext>& expCtx)
: ExpressionFixedArity<ExpressionIsoWeekYear, 1>(expCtx) {}
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
const char* getOpName() const final;
static int extract(const tm& tm);
@@ -1481,7 +1481,7 @@ public:
explicit ExpressionIsoDayOfWeek(const boost::intrusive_ptr<ExpressionContext>& expCtx)
: ExpressionFixedArity<ExpressionIsoDayOfWeek, 1>(expCtx) {}
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
const char* getOpName() const final;
static int extract(const tm& tm);
@@ -1493,7 +1493,7 @@ public:
explicit ExpressionIsoWeek(const boost::intrusive_ptr<ExpressionContext>& expCtx)
: ExpressionFixedArity<ExpressionIsoWeek, 1>(expCtx) {}
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
const char* getOpName() const final;
static int extract(const tm& tm);
@@ -1505,7 +1505,7 @@ public:
explicit ExpressionYear(const boost::intrusive_ptr<ExpressionContext>& expCtx)
: ExpressionFixedArity<ExpressionYear, 1>(expCtx) {}
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
const char* getOpName() const final;
// tm_year is years since 1990
@@ -1521,7 +1521,7 @@ public:
: Expression(expCtx) {}
void addDependencies(DepsTracker* deps) const final;
- Value evaluate(Document root) const final;
+ Value evaluate(const Document& root) const final;
boost::intrusive_ptr<Expression> optimize() final;
static boost::intrusive_ptr<Expression> parse(
const boost::intrusive_ptr<ExpressionContext>& expCtx,
diff --git a/src/mongo/db/pipeline/expression_test.cpp b/src/mongo/db/pipeline/expression_test.cpp
index 15e7f0421b2..45b00c69fa1 100644
--- a/src/mongo/db/pipeline/expression_test.cpp
+++ b/src/mongo/db/pipeline/expression_test.cpp
@@ -172,7 +172,7 @@ public:
/** A dummy child of ExpressionNary used for testing. */
class Testable : public ExpressionNary {
public:
- virtual Value evaluate(Document root) const {
+ virtual Value evaluate(const Document& root) const {
// Just put all the values in a list.
// By default, this is not associative/commutative so the results will change if
// instantiated as commutative or associative and operations are reordered.
diff --git a/src/mongo/db/pipeline/parsed_add_fields.cpp b/src/mongo/db/pipeline/parsed_add_fields.cpp
index ac605bb9a96..0cbe513a720 100644
--- a/src/mongo/db/pipeline/parsed_add_fields.cpp
+++ b/src/mongo/db/pipeline/parsed_add_fields.cpp
@@ -84,7 +84,7 @@ void ParsedAddFields::parse(const BSONObj& spec) {
}
}
-Document ParsedAddFields::applyProjection(Document inputDoc) const {
+Document ParsedAddFields::applyProjection(const Document& inputDoc) const {
// The output doc is the same as the input doc, with the added fields.
MutableDocument output(inputDoc);
_root->addComputedFields(&output, inputDoc);
diff --git a/src/mongo/db/pipeline/parsed_add_fields.h b/src/mongo/db/pipeline/parsed_add_fields.h
index 83af2f20018..7afa29d6801 100644
--- a/src/mongo/db/pipeline/parsed_add_fields.h
+++ b/src/mongo/db/pipeline/parsed_add_fields.h
@@ -110,7 +110,7 @@ public:
* in the array "a". If there is an element in "a" that is not an object, it will be replaced
* with {"0": "hello"}. See SERVER-25200 for more details.
*/
- Document applyProjection(Document inputDoc) const final;
+ Document applyProjection(const Document& inputDoc) const final;
private:
/**
diff --git a/src/mongo/db/pipeline/parsed_aggregation_projection.h b/src/mongo/db/pipeline/parsed_aggregation_projection.h
index 227663a1342..dfda0f66756 100644
--- a/src/mongo/db/pipeline/parsed_aggregation_projection.h
+++ b/src/mongo/db/pipeline/parsed_aggregation_projection.h
@@ -150,7 +150,7 @@ public:
/**
* Apply the projection transformation.
*/
- Document applyTransformation(Document input) {
+ Document applyTransformation(const Document& input) {
return applyProjection(input);
}
@@ -161,7 +161,7 @@ protected:
/**
* Apply the projection to 'input'.
*/
- virtual Document applyProjection(Document input) const = 0;
+ virtual Document applyProjection(const Document& input) const = 0;
boost::intrusive_ptr<ExpressionContext> _expCtx;
};
diff --git a/src/mongo/db/pipeline/parsed_exclusion_projection.cpp b/src/mongo/db/pipeline/parsed_exclusion_projection.cpp
index 51809826dfe..b4d52ef77ed 100644
--- a/src/mongo/db/pipeline/parsed_exclusion_projection.cpp
+++ b/src/mongo/db/pipeline/parsed_exclusion_projection.cpp
@@ -65,7 +65,7 @@ void ExclusionNode::excludePath(FieldPath path) {
addOrGetChild(path.getFieldName(0))->excludePath(path.tail());
}
-Document ExclusionNode::applyProjection(Document input) const {
+Document ExclusionNode::applyProjection(const Document& input) const {
MutableDocument output(input);
for (auto&& field : _excludedFields) {
output.remove(field);
@@ -140,7 +140,7 @@ Document ParsedExclusionProjection::serialize(
return _root->serialize();
}
-Document ParsedExclusionProjection::applyProjection(Document inputDoc) const {
+Document ParsedExclusionProjection::applyProjection(const Document& inputDoc) const {
return _root->applyProjection(inputDoc);
}
diff --git a/src/mongo/db/pipeline/parsed_exclusion_projection.h b/src/mongo/db/pipeline/parsed_exclusion_projection.h
index feb868f08ca..d9c495a9cfb 100644
--- a/src/mongo/db/pipeline/parsed_exclusion_projection.h
+++ b/src/mongo/db/pipeline/parsed_exclusion_projection.h
@@ -64,7 +64,7 @@ public:
/**
* Applies this tree of exclusions to the input document.
*/
- Document applyProjection(Document input) const;
+ Document applyProjection(const Document& input) const;
/**
* Creates the child if it doesn't already exist. 'field' is not allowed to be dotted.
@@ -116,7 +116,7 @@ public:
/**
* Exclude the fields specified.
*/
- Document applyProjection(Document inputDoc) const final;
+ Document applyProjection(const Document& inputDoc) const final;
DocumentSource::GetDepsReturn addDependencies(DepsTracker* deps) const final {
return DocumentSource::SEE_NEXT;
diff --git a/src/mongo/db/pipeline/parsed_inclusion_projection.cpp b/src/mongo/db/pipeline/parsed_inclusion_projection.cpp
index fb486543621..300623b632b 100644
--- a/src/mongo/db/pipeline/parsed_inclusion_projection.cpp
+++ b/src/mongo/db/pipeline/parsed_inclusion_projection.cpp
@@ -103,7 +103,7 @@ void InclusionNode::addDependencies(DepsTracker* deps) const {
}
}
-void InclusionNode::applyInclusions(Document inputDoc, MutableDocument* outputDoc) const {
+void InclusionNode::applyInclusions(const Document& inputDoc, MutableDocument* outputDoc) const {
auto it = inputDoc.fieldIterator();
while (it.more()) {
auto fieldPair = it.next();
@@ -141,7 +141,7 @@ Value InclusionNode::applyInclusionsToValue(Value inputValue) const {
}
}
-void InclusionNode::addComputedFields(MutableDocument* outputDoc, Document root) const {
+void InclusionNode::addComputedFields(MutableDocument* outputDoc, const Document& root) const {
for (auto&& field : _orderToProcessAdditionsAndChildren) {
auto childIt = _children.find(field);
if (childIt != _children.end()) {
@@ -155,7 +155,7 @@ void InclusionNode::addComputedFields(MutableDocument* outputDoc, Document root)
}
}
-Value InclusionNode::addComputedFields(Value inputValue, Document root) const {
+Value InclusionNode::addComputedFields(Value inputValue, const Document& root) const {
if (inputValue.getType() == BSONType::Object) {
MutableDocument outputDoc(inputValue.getDocument());
addComputedFields(&outputDoc, root);
@@ -349,7 +349,7 @@ void ParsedInclusionProjection::parse(const BSONObj& spec) {
atLeastOneFieldInOutput);
}
-Document ParsedInclusionProjection::applyProjection(Document inputDoc) const {
+Document ParsedInclusionProjection::applyProjection(const Document& inputDoc) const {
// All expressions will be evaluated in the context of the input document, before any
// transformations have been applied.
MutableDocument output;
diff --git a/src/mongo/db/pipeline/parsed_inclusion_projection.h b/src/mongo/db/pipeline/parsed_inclusion_projection.h
index 3077f3f4b37..e27ed5763aa 100644
--- a/src/mongo/db/pipeline/parsed_inclusion_projection.h
+++ b/src/mongo/db/pipeline/parsed_inclusion_projection.h
@@ -83,12 +83,12 @@ public:
* and an empty 'outputDoc' will leave 'outputDoc' representing the document
* {a: [{b: 1}, {b: 2}], d: [{}, {}]}.
*/
- void applyInclusions(Document inputDoc, MutableDocument* outputDoc) const;
+ void applyInclusions(const Document& inputDoc, MutableDocument* outputDoc) const;
/**
* Add computed fields to 'outputDoc'.
*/
- void addComputedFields(MutableDocument* outputDoc, Document root) const;
+ void addComputedFields(MutableDocument* outputDoc, const Document& root) const;
/**
* Creates the child if it doesn't already exist. 'field' is not allowed to be dotted.
@@ -139,7 +139,7 @@ private:
// Helpers for the Document versions above. These will apply the transformation recursively to
// each element of any arrays, and ensure non-documents are handled appropriately.
Value applyInclusionsToValue(Value inputVal) const;
- Value addComputedFields(Value inputVal, Document root) const;
+ Value addComputedFields(Value inputVal, const Document& root) const;
/**
* Returns nullptr if no such child exists.
@@ -242,7 +242,7 @@ public:
* Arrays will be traversed, with any dotted/nested exclusions or computed fields applied to
* each element in the array.
*/
- Document applyProjection(Document inputDoc) const final;
+ Document applyProjection(const Document& inputDoc) const final;
private:
/**
diff --git a/src/mongo/db/pipeline/variables.cpp b/src/mongo/db/pipeline/variables.cpp
index 53156f92e4b..39b9130ed6e 100644
--- a/src/mongo/db/pipeline/variables.cpp
+++ b/src/mongo/db/pipeline/variables.cpp
@@ -109,7 +109,7 @@ void Variables::setValue(Id id, const Value& value) {
_valueList[id] = value;
}
-Value Variables::getValue(Id id, Document root) const {
+Value Variables::getValue(Id id, const Document& root) const {
if (id < 0) {
// This is a reserved id for a builtin variable.
switch (id) {
@@ -128,7 +128,7 @@ Value Variables::getValue(Id id, Document root) const {
return _valueList[id];
}
-Document Variables::getDocument(Id id, Document root) const {
+Document Variables::getDocument(Id id, const Document& root) const {
if (id == Variables::kRootId) {
// For the common case of ROOT, avoid round-tripping through Value.
return root;
diff --git a/src/mongo/db/pipeline/variables.h b/src/mongo/db/pipeline/variables.h
index 98ffd2fe595..444686551fb 100644
--- a/src/mongo/db/pipeline/variables.h
+++ b/src/mongo/db/pipeline/variables.h
@@ -81,13 +81,13 @@ public:
* Gets the value of a user-defined or system variable. If the 'id' provided represents the
* special ROOT variable, then we return 'root' in Value form.
*/
- Value getValue(Variables::Id id, Document root) const;
+ Value getValue(Variables::Id id, const Document& root) const;
/**
* Returns Document() for non-document values, but otherwise identical to getValue(). If the
* 'id' provided represents the special ROOT variable, then we return 'root'.
*/
- Document getDocument(Variables::Id id, Document root) const;
+ Document getDocument(Variables::Id id, const Document& root) const;
IdGenerator* useIdGenerator() {
return &_idGenerator;