diff options
Diffstat (limited to 'src/mongo/db/matcher/expression_where.cpp')
-rw-r--r-- | src/mongo/db/matcher/expression_where.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/mongo/db/matcher/expression_where.cpp b/src/mongo/db/matcher/expression_where.cpp index c6633bc3802..7d1f261370f 100644 --- a/src/mongo/db/matcher/expression_where.cpp +++ b/src/mongo/db/matcher/expression_where.cpp @@ -43,6 +43,7 @@ #include "mongo/db/namespace_string.h" #include "mongo/scripting/engine.h" #include "mongo/stdx/memory.h" +#include "mongo/util/scopeguard.h" namespace mongo { @@ -67,6 +68,8 @@ WhereMatchExpression::WhereMatchExpression(OperationContext* opCtx, AuthorizationSession::get(Client::getCurrent())->getAuthenticatedUserNamesToken(); _scope = getGlobalScriptEngine()->getPooledScope(_opCtx, _dbName, "where" + userToken); + const auto guard = makeGuard([&] { _scope->unregisterOperation(); }); + _func = _scope->createFunction(getCode().c_str()); uassert(ErrorCodes::BadValue, "$where compile error", _func); @@ -76,6 +79,9 @@ bool WhereMatchExpression::matches(const MatchableDocument* doc, MatchDetails* d uassert(28692, "$where compile error", _func); BSONObj obj = doc->toBSON(); + _scope->registerOperation(Client::getCurrent()->getOperationContext()); + const auto guard = makeGuard([&] { _scope->unregisterOperation(); }); + if (!getScope().isEmpty()) { _scope->init(&getScope()); } |