diff options
Diffstat (limited to 'src/mongo/db/pipeline/expression_context.h')
-rw-r--r-- | src/mongo/db/pipeline/expression_context.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/mongo/db/pipeline/expression_context.h b/src/mongo/db/pipeline/expression_context.h index 4d8ca0052dd..d5f051bc6eb 100644 --- a/src/mongo/db/pipeline/expression_context.h +++ b/src/mongo/db/pipeline/expression_context.h @@ -197,6 +197,19 @@ public: auto getRuntimeConstants() const { return variables.getRuntimeConstants(); } + + /** + * Retrieves the Javascript Scope for the current thread or creates a new one if it has not been + * created yet. Initializes the Scope with the 'jsScope' variables from the runtimeConstants. + * + * Returns a JsExec and a boolean indicating whether the Scope was created as part of this call. + */ + auto getJsExecWithScope() const { + RuntimeConstants runtimeConstants = getRuntimeConstants(); + const boost::optional<mongo::BSONObj>& scope = runtimeConstants.getJsScope(); + return mongoProcessInterface->getJsExec(scope.get_value_or(BSONObj())); + } + // The explain verbosity requested by the user, or boost::none if no explain was requested. boost::optional<ExplainOptions::Verbosity> explain; |