add DBRef support to v8 engine (not DBPointer)

This commit is contained in:
metagoto
2009-11-24 10:36:10 +08:00
committed by Eliot
parent 3c71fb2ef9
commit 705ec48cd9
5 changed files with 52 additions and 4 deletions

View File

@@ -30,14 +30,28 @@ namespace mongo {
#define DDD(x)
Local<v8::Object> mongoToV8( const BSONObj& m , bool array ){
// handle DBRef. needs to come first. isn't it? (metagoto)
static string ref = "$ref";
if ( ref == m.firstElement().fieldName() ) {
const BSONElement& id = m["$id"];
if (!id.eoo()) { // there's no check on $id exitence in sm implementation. risky ?
v8::Function* dbRef = getNamedCons( "DBRef" );
v8::Handle<v8::Value> argv[2];
argv[0] = mongoToV8Element(m.firstElement());
argv[1] = mongoToV8Element(m["$id"]);
return dbRef->NewInstance(2, argv);
}
}
Local<v8::Object> o;
if ( array )
o = v8::Array::New();
else
o = v8::Object::New();
mongo::BSONObj sub;
for ( BSONObjIterator i(m); i.more(); ) {
const BSONElement& f = i.next();