-
Type: Bug
-
Resolution: Unresolved
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: BSON
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
- is related to
-
NODE-5454 Driver Container and Kubernetes Awareness
- Closed