-
Type:
Improvement
-
Resolution: Fixed
-
Priority:
Minor - P4
-
Affects Version/s: None
-
Component/s: BSON
How are you using Mongo? What version of the server and driver are you using?
While using the BSON library it is desirable to be able to define custom BSON serialization methods on objects passed into the serializer.
What is the feature/improvement you would like?
Currently the serializer relies on a JS truthiness check before checking for the toBSON function to avoid causing an error if the value is null or undefined. We should instead check explicitly for those two cases (null or undefined).
The following types could have toBSON methods defined on them:
- false
- 0 (zero)
- -0 (minus zero)
- 0n (BigInt zero)
- '', "", `` (empty string)
- NaN
But they are falsey, we should test that these specific inputs can have custom serialization methods.
What use case would this feature/improvement enable?
BigInt.prototype.toBSON = function() { return BSON.Long.fromBigInt(this) }