summaryrefslogtreecommitdiff
path: root/db/dbeval.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'db/dbeval.cpp')
-rw-r--r--db/dbeval.cpp23
1 files changed, 13 insertions, 10 deletions
diff --git a/db/dbeval.cpp b/db/dbeval.cpp
index e8a42b2..31d5260 100644
--- a/db/dbeval.cpp
+++ b/db/dbeval.cpp
@@ -37,7 +37,7 @@ namespace mongo {
const int edebug=0;
- bool dbEval(const char *ns, BSONObj& cmd, BSONObjBuilder& result, string& errmsg) {
+ bool dbEval(const string& dbName, BSONObj& cmd, BSONObjBuilder& result, string& errmsg) {
BSONElement e = cmd.firstElement();
uassert( 10046 , "eval needs Code" , e.type() == Code || e.type() == CodeWScope || e.type() == String );
@@ -60,16 +60,16 @@ namespace mongo {
return false;
}
- auto_ptr<Scope> s = globalScriptEngine->getPooledScope( ns );
+ auto_ptr<Scope> s = globalScriptEngine->getPooledScope( dbName );
ScriptingFunction f = s->createFunction(code);
if ( f == 0 ) {
errmsg = (string)"compile failed: " + s->getError();
return false;
}
-
+
if ( e.type() == CodeWScope )
s->init( e.codeWScopeScopeData() );
- s->localConnect( cc().database()->name.c_str() );
+ s->localConnect( dbName.c_str() );
BSONObj args;
{
@@ -89,7 +89,7 @@ namespace mongo {
res = s->invoke(f,args, cmdLine.quota ? 10 * 60 * 1000 : 0 );
int m = t.millis();
if ( m > cmdLine.slowMS ) {
- out() << "dbeval slow, time: " << dec << m << "ms " << ns << endl;
+ out() << "dbeval slow, time: " << dec << m << "ms " << dbName << endl;
if ( m >= 1000 ) log() << code << endl;
else OCCASIONALLY log() << code << endl;
}
@@ -100,7 +100,7 @@ namespace mongo {
errmsg += s->getError();
return false;
}
-
+
s->append( result , "retval" , "return" );
return true;
@@ -122,16 +122,19 @@ namespace mongo {
virtual LockType locktype() const { return NONE; }
CmdEval() : Command("eval", false, "$eval") { }
bool run(const string& dbname , BSONObj& cmdObj, string& errmsg, BSONObjBuilder& result, bool fromRepl) {
-
+
AuthenticationInfo *ai = cc().getAuthenticationInfo();
uassert( 12598 , "$eval reads unauthorized", ai->isAuthorizedReads(dbname.c_str()) );
-
+
+ if ( cmdObj["nolock"].trueValue() ) {
+ return dbEval(dbname, cmdObj, result, errmsg);
+ }
+
// write security will be enforced in DBDirectClient
mongolock lk( ai->isAuthorized( dbname.c_str() ) );
Client::Context ctx( dbname );
-
- return dbEval(dbname.c_str(), cmdObj, result, errmsg);
+ return dbEval(dbname, cmdObj, result, errmsg);
}
} cmdeval;