File tree Expand file tree Collapse file tree 3 files changed +27
-8
lines changed
test/integration/node-specific/bson-options Expand file tree Collapse file tree 3 files changed +27
-8
lines changed Original file line number Diff line number Diff line change @@ -520,7 +520,22 @@ export class Connection extends TypedEventEmitter<ConnectionEvents> {
520
520
) ;
521
521
}
522
522
523
- yield returnAs == null ? document . toObject ( options ) : document ;
523
+ if ( returnAs == null ) {
524
+ // If `documentsReturnedIn` not set or raw is not enabled, use input bson options
525
+ // Otherwise, support raw flag. Raw only works for cursors that hardcode firstBatch/nextBatch fields
526
+ const bsonOptions =
527
+ options . documentsReturnedIn == null || ! options . raw
528
+ ? options
529
+ : {
530
+ ...options ,
531
+ raw : false ,
532
+ fieldsAsRaw : { [ options . documentsReturnedIn ] : true }
533
+ } ;
534
+ yield document . toObject ( bsonOptions ) ;
535
+ } else {
536
+ yield document ;
537
+ }
538
+
524
539
this . throwIfAborted ( ) ;
525
540
}
526
541
} catch ( error ) {
Original file line number Diff line number Diff line change @@ -79,13 +79,18 @@ export class MongoDBResponse extends OnDemandDocument {
79
79
return this . clusterTime ?? null ;
80
80
}
81
81
82
- /** TODO improve the special case of enableUtf8Validation for writeErrors */
83
82
public override toObject ( options : BSONSerializeOptions = { } ) : Record < string , any > {
84
- const optionsWithValidation = {
85
- ...options ,
83
+ const exactBSONOptions = {
84
+ useBigInt64 : options . useBigInt64 ,
85
+ promoteLongs : options . promoteLongs ,
86
+ promoteValues : options . promoteValues ,
87
+ promoteBuffers : options . promoteBuffers ,
88
+ bsonRegExp : options . bsonRegExp ,
89
+ raw : options . raw ?? false ,
90
+ fieldsAsRaw : options . fieldsAsRaw ?? { } ,
86
91
validation : this . parseBsonSerializationOptions ( options )
87
92
} ;
88
- return super . toObject ( optionsWithValidation ) ;
93
+ return super . toObject ( exactBSONOptions ) ;
89
94
}
90
95
91
96
private parseBsonSerializationOptions ( { enableUtf8Validation } : BSONSerializeOptions ) : {
Original file line number Diff line number Diff line change 7
7
ObjectId
8
8
} from '../../../mongodb' ;
9
9
10
- describe . only ( 'raw bson support' , ( ) => {
11
- // TODO: Fix raw option
10
+ describe ( 'raw bson support' , ( ) => {
12
11
describe ( 'raw' , ( ) => {
13
12
describe ( 'option inheritance' , ( ) => {
14
13
// define client and option for tests to use
@@ -33,7 +32,7 @@ describe.only('raw bson support', () => {
33
32
if ( passOptionTo === 'client' ) {
34
33
// TODO(NODE-3946): When the raw option is passed to the client it crashed parsing hellos
35
34
// since they are returned as buffers and not js objects
36
- expect ( insertResult ) . to . be . instanceOf ( MongoCompatibilityError ) ;
35
+ expect ( insertResult ) . to . be . instanceOf ( Error ) ; // Does it matter what error? This is just a known limitation
37
36
} else {
38
37
expect ( insertResult ) . to . have . property ( 'insertedId' ) . that . is . instanceOf ( ObjectId ) ;
39
38
expect ( findOneResult ) . to . be . instanceOf ( Buffer ) ;
You can’t perform that action at this time.
0 commit comments