7.3.4 (2026-11-05)
The MongoDB Node.js team is pleased to announce version 7.3.4 of the bson package!
Release Notes
BSON.onDemand.parseToElements no longer hangs on malformed input
A malformed document containing a string element with a declared length of zero previously caused a non-terminating scan (synchronous CPU hang). The experimental on-demand parser now throws a BSONOffsetError instead.
Thanks to @AbinMadathil07 for providing the fix!
calculateObjectSize() now returns the correct size for negative zero
Previously, calculateObjectSize() counted -0 as a 4-byte int32, but serialize() writes it as an 8-byte double so the sign is kept. This made the result 4 bytes too small for every -0 in a document. Serializing into a buffer sized from that result (for example with serializeWithBufferAndIndex) would throw an out-of-bounds error. Thanks to @spokodev for the fix!
calculateObjectSize() now returns the correct size for a Code with an empty scope
Previously, calculateObjectSize() counted a Code whose scope is an empty object (for example new Code('x', {})) as plain code, but serialize() writes it as code with scope. The result was 9 bytes too small for each such value. Serializing into a buffer sized from that result (for example with serializeWithBufferAndIndex) would throw an out-of-bounds error. The two functions now agree. Thanks to @spokodev for the fix!
ObjectId no longer throws at import-time
Guards against throws at import-time in the Next.js Edge & Bun runtimes, which occur when the static ObjectId initializer calls specific optional APIs: getBuiltinModule and isBuildingSnapshot, which are implemented with a throwing stub.
Bug Fixes
- NODE-7611: bounds check findNull scan in on-demand parser (#924) (12ed533)
- NODE-7652: count negative zero as a double in calculateObjectSize (#908) (58d34bd)
- NODE-7661: count empty-scope Code as code_with_scope in calculateObjectSize (#911) (e0d0bd5)
- NODE-7784: try..catch wrapper around snapshot fn calls in static ObjectID initializer (#936) (5a9d5fc)
Documentation
We invite you to try the bson library immediately, and report any issues to the NODE project.