add new style DBRef to js SERVER-243

This commit is contained in:
Eliot Horowitz
2009-10-02 17:07:07 -04:00
parent eaf0c845bc
commit cc2c5c4911
6 changed files with 86 additions and 0 deletions

View File

@@ -415,6 +415,14 @@ namespace mongo {
}
JSObject * toJSObject( const BSONObj * obj , bool readOnly=false ){
static string ref = "$ref";
if ( ref == obj->firstElement().fieldName() ){
JSObject * o = JS_NewObject( _context , &dbref_class , NULL, NULL);
assert( o );
setProperty( o , "$ref" , toval( obj->firstElement() ) );
setProperty( o , "$id" , toval( (*obj)["$id"] ) );
return o;
}
JSObject * o = JS_NewObject( _context , readOnly ? &bson_ro_class : &bson_class , NULL, NULL);
assert( o );
assert( JS_SetPrivate( _context , o , (void*)(new BSONHolder( obj->getOwned() ) ) ) );