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

Undefined values in ES Map throw TypeError

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: BSON
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      Issue

      • ES Map throws on undefined values
      • ignoreUndefined has no effect, the error is thrown regardless
      • Objects and arrays have if (value === undefined) handling case, Map is missing the same handling

      Steps to reproduce?

      > BSON.serialize(new Map().set('a', undefined))
      Uncaught TypeError: Cannot read properties of undefined (reading '_bsontype')
          at serializeInto (/Users/neal/code/drivers/js/mongodb/node_modules/bson/lib/bson.cjs:3519:28)
          at Object.serialize (/Users/neal/code/drivers/js/mongodb/node_modules/bson/lib/bson.cjs:3997:32)
      

      User Impact

      • Impacts bson 1.1.6+
      • Anyone using ES Maps for their documents
      • Index API and client metadata notably use ES Map - they're not effected b/c they do not have undefined values

      Dependencies

      • This needs to be fixed in a patch to BSON and pulled into the driver

      Unknowns

      • Should we merge the Array, Object, and Map code paths?
        • Known risks? sparse arrays are special case
        • Unknown risks?

      Acceptance Criteria

      Implementation Requirements

      • Add handling for undefined values from Map
        • Align with object, ignoreUndefined controls whether or not to include the value in the BSON bytes
        • if Undefined is to be included is MUST be serialized as a BSON null
          • BSON undefined is deprecated and no longer produced by our or any BSON library under normal circumstances

      Testing Requirements

      • Test for true, false, and default setting of ignoreUndefined
      • Add tests for other containers (object, array) or reorganize existing ones

      Documentation Requirements

      • N/A

      Follow Up Requirements

      • Follow up with backport considerations

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

              Created:
              Updated: