@@ -273,13 +273,9 @@ const BSON_TYPE_MAPPINGS = {
273273 ) ,
274274 MaxKey : ( ) => new MaxKey ( ) ,
275275 MinKey : ( ) => new MinKey ( ) ,
276- ObjectID : ( o : ObjectId ) => new ObjectId ( o ) ,
277- // The _bsontype for ObjectId is spelled with a capital "D", to the mapping above will be used (most of the time)
278- // specifically BSON versions 4.0.0 and 4.0.1 the _bsontype was changed to "ObjectId" so we keep this mapping to support
279- // those version of BSON
280276 ObjectId : ( o : ObjectId ) => new ObjectId ( o ) ,
281277 BSONRegExp : ( o : BSONRegExp ) => new BSONRegExp ( o . pattern , o . options ) ,
282- Symbol : ( o : BSONSymbol ) => new BSONSymbol ( o . value ) ,
278+ BSONSymbol : ( o : BSONSymbol ) => new BSONSymbol ( o . value ) ,
283279 Timestamp : ( o : Timestamp ) => Timestamp . fromBits ( o . low , o . high )
284280} as const ;
285281
@@ -310,6 +306,13 @@ function serializeDocument(doc: any, options: EJSONSerializeOptions) {
310306 }
311307 }
312308 return _doc ;
309+ } else if (
310+ doc != null &&
311+ typeof doc === 'object' &&
312+ typeof doc . _bsontype === 'string' &&
313+ doc [ Symbol . for ( '@@mdb.bson.version' ) ] == null
314+ ) {
315+ throw new BSONError ( 'Unsupported BSON version, bson types must be from bson 5.0 or later' ) ;
313316 } else if ( isBSONType ( doc ) ) {
314317 // the "document" is really just a BSON type object
315318 // eslint-disable-next-line @typescript-eslint/no-explicit-any
0 commit comments