diff options
author | Eliot Horowitz <eliot@10gen.com> | 2009-09-15 14:02:39 -0400 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2009-09-15 14:02:39 -0400 |
commit | 5ee8961f40ed47907e14c613f640036100385346 (patch) | |
tree | 4d1f78c18da9c5bfa61390de145f5d44344994d0 /db | |
parent | 265af2d1f9c438903d23569e250bd5f54d354212 (diff) | |
download | mongo-5ee8961f40ed47907e14c613f640036100385346.tar.gz |
CodeWScope for group SERVER-262
Diffstat (limited to 'db')
-rw-r--r-- | db/dbcommands.cpp | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/db/dbcommands.cpp b/db/dbcommands.cpp index 82ec3c44ad8..b60120d95c5 100644 --- a/db/dbcommands.cpp +++ b/db/dbcommands.cpp @@ -1191,7 +1191,10 @@ namespace mongo { return obj.extractFields( keyPattern , true ); } - bool group( string realdbname , auto_ptr<DBClientCursor> cursor , BSONObj keyPattern , string keyFunction , string reduceCode , BSONObj initial , string& errmsg , BSONObjBuilder& result ){ + bool group( string realdbname , auto_ptr<DBClientCursor> cursor , + BSONObj keyPattern , string keyFunction , string reduceCode , const char * reduceScope , + BSONObj initial , + string& errmsg , BSONObjBuilder& result ){ if ( keyFunction.size() ){ errmsg = "can't only handle real keys right now, not functions"; @@ -1200,6 +1203,9 @@ namespace mongo { auto_ptr<Scope> s = globalScriptEngine->getPooledScope( realdbname ); s->localConnect( realdbname.c_str() ); + + if ( reduceScope ) + s->init( reduceScope ); s->setObject( "$initial" , initial , true ); @@ -1281,7 +1287,12 @@ namespace mongo { // no key specified, will use entire object as key } - return group( realdbname , cursor , key , keyf , p["$reduce"].ascode() , p["initial"].embeddedObjectUserCheck() , errmsg , result ); + BSONElement reduce = p["$reduce"]; + + return group( realdbname , cursor , + key , keyf , reduce.ascode() , reduce.type() != CodeWScope ? 0 : reduce.codeWScopeScopeData() , + p["initial"].embeddedObjectUserCheck() , + errmsg , result ); } } cmdGroup; |