@@ -602,36 +602,52 @@ if (typeof (DBPointer) != "undefined") {
602602// DBRef
603603if ( typeof ( DBRef ) != "undefined" ) {
604604 DBRef . prototype . fetch = function ( ) {
605- assert ( this . $ref , "need a ns" ) ;
606- assert ( this . $id , "need an id" ) ;
607- var coll = this . $ db ? db . getSiblingDB ( this . $ db) . getCollection ( this . $ref ) : db [ this . $ref ] ;
608- return coll . findOne ( { _id : this . $id } ) ;
605+ assert ( this . collection , "need a ns" ) ;
606+ assert ( this . oid , "need an id" ) ;
607+ var coll = this . db ? db . getSiblingDB ( this . db ) . getCollection ( this . collection ) : db [ this . collection ] ;
608+ return coll . findOne ( { _id : this . oid } ) ;
609609 } ;
610610
611611 DBRef . prototype . tojson = function ( indent ) {
612612 return this . toString ( ) ;
613613 } ;
614614
615615 DBRef . prototype . getDb = function ( ) {
616- return this . $ db || undefined ;
616+ return this . db || undefined ;
617617 } ;
618618
619619 DBRef . prototype . getCollection = function ( ) {
620- return this . $ref ;
620+ return this . collection ;
621621 } ;
622622
623623 DBRef . prototype . getRef = function ( ) {
624- return this . $ref ;
624+ return this . collection ;
625625 } ;
626626
627627 DBRef . prototype . getId = function ( ) {
628- return this . $id ;
628+ return this . oid ;
629629 } ;
630630
631631 DBRef . prototype . toString = function ( ) {
632- return " DBRef(" + tojson ( this . $ref ) + ", " + tojson ( this . $id ) +
633- ( this . $ db ? " , " + tojson ( this . $db ) : "" ) + ")" ;
632+ return ` DBRef("${ this . collection } ", ${ this . oid . tojson ( ) } ` +
633+ ( this . db ? ` , "${ this . db } "` : "" ) + ")" ;
634634 } ;
635+
636+ Object . defineProperty ( DBRef . prototype , "$ref" , {
637+ get : function ( ) {
638+ return this . collection ;
639+ } ,
640+ } ) ;
641+ Object . defineProperty ( DBRef . prototype , "$id" , {
642+ get : function ( ) {
643+ return this . oid ;
644+ } ,
645+ } ) ;
646+ Object . defineProperty ( DBRef . prototype , "$db" , {
647+ get : function ( ) {
648+ return this . db ;
649+ } ,
650+ } ) ;
635651} else {
636652 print ( "warning: no DBRef" ) ;
637653}
0 commit comments