Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-3821

Improve nullish check before using toBSON override function

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • bson-4.6.1
    • Affects Version/s: None
    • Component/s: BSON
    • Labels:
    • 1
    • Not Needed

      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) }
      

            Assignee:
            neal.beeken@mongodb.com Neal Beeken
            Reporter:
            neal.beeken@mongodb.com Neal Beeken
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: