@@ -388,6 +388,30 @@ var deserializeObject = function(buffer, index, options, isArray) {
388
388
} else {
389
389
object [ name ] = new Code ( functionString , scopeObject ) ;
390
390
}
391
+ } else if ( elementType == BSON_DATA_DBPOINTER ) {
392
+ // Get the code string size
393
+ var stringSize = buffer [ index ++ ] | buffer [ index ++ ] << 8 | buffer [ index ++ ] << 16 | buffer [ index ++ ] << 24 ;
394
+ // Check if we have a valid string
395
+ if ( stringSize <= 0 || stringSize > ( buffer . length - index ) || buffer [ index + stringSize - 1 ] != 0 ) throw new Error ( "bad string length in bson" ) ;
396
+ // Namespace
397
+ var namespace = buffer . toString ( 'utf8' , index , index + stringSize - 1 ) ;
398
+ // Update parse index position
399
+ index = index + stringSize ;
400
+
401
+ // Read the oid
402
+ var oidBuffer = new Buffer ( 12 ) ;
403
+ buffer . copy ( oidBuffer , 0 , index , index + 12 ) ;
404
+ var oid = new ObjectID ( oidBuffer ) ;
405
+
406
+ // Update the index
407
+ index = index + 12 ;
408
+
409
+ // Split the namespace
410
+ var parts = namespace . split ( '.' ) ;
411
+ var db = parts . shift ( ) ;
412
+ var collection = parts . join ( '.' ) ;
413
+ // Upgrade to DBRef type
414
+ object [ name ] = new DBRef ( collection , oid , db ) ;
391
415
} else {
392
416
throw new Error ( "Detected unknown BSON type " + elementType . toString ( 16 ) + " for fieldname \"" + name + "\", are you using the latest BSON parser" ) ;
393
417
}
@@ -513,6 +537,12 @@ BSON.BSON_DATA_NULL = 10;
513
537
* @classconstant BSON_DATA_REGEXP
514
538
**/
515
539
BSON . BSON_DATA_REGEXP = 11 ;
540
+ /**
541
+ * Code BSON Type
542
+ *
543
+ * @classconstant BSON_DATA_DBPOINTER
544
+ **/
545
+ BSON . BSON_DATA_DBPOINTER = 12 ;
516
546
/**
517
547
* Code BSON Type
518
548
*
0 commit comments