File tree Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -757,7 +757,11 @@ export function serializeInto(
757757
758758 // Get the entry values
759759 const key = entry . value [ 0 ] ;
760- const value = entry . value [ 1 ] ;
760+ let value = entry . value [ 1 ] ;
761+
762+ if ( typeof value ?. toBSON === 'function' ) {
763+ value = value . toBSON ( ) ;
764+ }
761765
762766 // Check the type of the value
763767 const type = typeof value ;
Original file line number Diff line number Diff line change @@ -183,6 +183,15 @@ describe('toBSON', function () {
183183 const sizeNestedToBSON = BSON . calculateObjectSize ( { a : [ 0 ] } ) ;
184184 expect ( sizeNestedToBSON ) . to . equal ( 33 ) ;
185185 } ) ;
186+
187+ it ( 'uses toBSON on values contained in a map' , ( ) => {
188+ const map = new Map ( ) ;
189+ map . set ( 'a' , 100 ) ;
190+
191+ const serializedData = BSON . serialize ( map ) ;
192+ const deserializedData = BSON . deserialize ( serializedData ) ;
193+ expect ( deserializedData ) . to . have . property ( 'a' , 'hello number' ) ;
194+ } ) ;
186195 } ) ;
187196
188197 it ( 'should use toBSON in calculateObjectSize' , ( ) => {
You can’t perform that action at this time.
0 commit comments