summaryrefslogtreecommitdiff
path: root/src/mongo/db/pipeline/document_source_replace_root.cpp
diff options
context:
space:
mode:
authorJames Wahlin <james.wahlin@10gen.com>2017-04-05 09:59:54 -0400
committerJames Wahlin <james.wahlin@10gen.com>2017-04-29 09:21:00 -0400
commit5273c2bad7df58c44afdd677609b8656f399a906 (patch)
tree0257684f5555293d72e07179c6b058081c247019 /src/mongo/db/pipeline/document_source_replace_root.cpp
parent2e8e60bfef83ac9c7bf494b0f80977686cb1b772 (diff)
downloadmongo-5273c2bad7df58c44afdd677609b8656f399a906.tar.gz
SERVER-28651 Move agg var ownership to ExpressionContext
Diffstat (limited to 'src/mongo/db/pipeline/document_source_replace_root.cpp')
-rw-r--r--src/mongo/db/pipeline/document_source_replace_root.cpp15
1 files changed, 7 insertions, 8 deletions
diff --git a/src/mongo/db/pipeline/document_source_replace_root.cpp b/src/mongo/db/pipeline/document_source_replace_root.cpp
index 8f6782dc47e..d089e67d097 100644
--- a/src/mongo/db/pipeline/document_source_replace_root.cpp
+++ b/src/mongo/db/pipeline/document_source_replace_root.cpp
@@ -49,12 +49,13 @@ class ReplaceRootTransformation final
: public DocumentSourceSingleDocumentTransformation::TransformerInterface {
public:
- ReplaceRootTransformation() {}
+ ReplaceRootTransformation(const boost::intrusive_ptr<ExpressionContext>& expCtx)
+ : _expCtx(expCtx) {}
Document applyTransformation(Document input) final {
// Extract subdocument in the form of a Value.
- _variables->setRoot(input);
- Value newRoot = _newRoot->evaluate(_variables.get());
+ _expCtx->variables.setRoot(input);
+ Value newRoot = _newRoot->evaluate();
// The newRoot expression, if it exists, must evaluate to an object.
uassert(40228,
@@ -104,7 +105,7 @@ public:
// Create the pointer, parse the stage, and return.
std::unique_ptr<ReplaceRootTransformation> parsedReplaceRoot =
- stdx::make_unique<ReplaceRootTransformation>();
+ stdx::make_unique<ReplaceRootTransformation>(expCtx);
parsedReplaceRoot->parse(expCtx, spec);
return parsedReplaceRoot;
}
@@ -112,8 +113,7 @@ public:
// Check for valid replaceRoot options, and populate internal state variables.
void parse(const boost::intrusive_ptr<ExpressionContext>& expCtx, const BSONElement& spec) {
// We need a VariablesParseState in order to parse the 'newRoot' expression.
- VariablesIdGenerator idGenerator;
- VariablesParseState vps(&idGenerator);
+ VariablesParseState vps = expCtx->variablesParseState;
// Get the options from this stage. Currently the only option is newRoot.
for (auto&& argument : spec.Obj()) {
@@ -131,12 +131,11 @@ public:
// Check that there was a new root specified.
uassert(40231, "no newRoot specified for the $replaceRoot stage", _newRoot);
- _variables = stdx::make_unique<Variables>(idGenerator.getIdCount());
}
private:
- std::unique_ptr<Variables> _variables;
boost::intrusive_ptr<Expression> _newRoot;
+ const boost::intrusive_ptr<ExpressionContext> _expCtx;
};
REGISTER_DOCUMENT_SOURCE(replaceRoot,