@@ -275,13 +275,9 @@ const BSON_TYPE_MAPPINGS = {
275275 ) ,
276276 MaxKey : ( ) => new MaxKey ( ) ,
277277 MinKey : ( ) => new MinKey ( ) ,
278- ObjectID : ( o : ObjectId ) => new ObjectId ( o ) ,
279- // The _bsontype for ObjectId is spelled with a capital "D", to the mapping above will be used (most of the time)
280- // specifically BSON versions 4.0.0 and 4.0.1 the _bsontype was changed to "ObjectId" so we keep this mapping to support
281- // those version of BSON
282278 ObjectId : ( o : ObjectId ) => new ObjectId ( o ) ,
283279 BSONRegExp : ( o : BSONRegExp ) => new BSONRegExp ( o . pattern , o . options ) ,
284- Symbol : ( o : BSONSymbol ) => new BSONSymbol ( o . value ) ,
280+ BSONSymbol : ( o : BSONSymbol ) => new BSONSymbol ( o . value ) ,
285281 Timestamp : ( o : Timestamp ) => Timestamp . fromBits ( o . low , o . high )
286282} as const ;
287283
@@ -312,6 +308,13 @@ function serializeDocument(doc: any, options: EJSONSerializeOptions) {
312308 }
313309 }
314310 return _doc ;
311+ } else if (
312+ doc != null &&
313+ typeof doc === 'object' &&
314+ typeof doc . _bsontype === 'string' &&
315+ doc [ Symbol . for ( '@@mdb.bson.version' ) ] == null
316+ ) {
317+ throw new BSONError ( 'Unsupported BSON version, bson types must be from bson 5.0 or later' ) ;
315318 } else if ( isBSONType ( doc ) ) {
316319 // the "document" is really just a BSON type object
317320 // eslint-disable-next-line @typescript-eslint/no-explicit-any
0 commit comments