unstale

npm / bson

bson

What changed in bson 2 to 7, from its official release notes, upgrade guides and advisories. Sources checked 2026-12-05.

34 breaking3 security3 deprecations10 new APIs and options1 performance4 behavior and defaults3 tooling23 fixes and other

See which of these apply to your code, ranked, in your agent:

npx @unstale/cli init

@unstale/cli 0.3.1 on npm

bson 731 changes

Breaking changes 8

  • On malformed input containing a string element with a declared length of zero, the experimental on-demand parser now throws a BSONOffsetError instead of hanging.

    7.3.4release notes

  • Throws an exception when a circular reference is detected instead of hanging indefinitely.

    7.3.3release notes

  • A Code with Scope scope containing $ref, $id, and $db is returned as a plain object instead of being promoted to a DBRef instance.

    7.3.0release notes

  • ByteUtils and NumberUtils are no longer available from the onDemand namespace; they have moved to the top-level package export.

    7.1.0release notes

  • BSON now uses JavaScript BigInt syntax and requires a JavaScript engine that supports BigInt literal syntax.

    7.0.0release notes

  • The minimum supported Node.js version is now 20.19.0; Node.js 16 and 18 are no longer supported.

    7.0.0release notes

  • The ObjectId constructor no longer accepts a number; use ObjectId.createFromTime() to create an ObjectId from a numeric timestamp.

    7.0.0release notes

  • BSON no longer includes atob, btoa, and TextEncoder polyfills for React Native builds because Hermes supports them natively.

    7.0.0release notes

Security 2

  • Counts negative zero as an 8-byte double, matching serialize() and preventing undersized buffers and out-of-bounds errors.

    7.3.4release notes

  • Counts a Code value with an empty scope as code with scope, matching serialize() and preventing undersized buffers and out-of-bounds errors.

    7.3.4release notes

Deprecations 2

  • Long methods and operations that are inapplicable to Timestamp are now marked deprecated; use the .t and .i accessors for its timestamp components.

    7.3.0release notes

  • The BSON Binary subtype 2 constant is now deprecated to align with the BSON specification.

    7.0.0release notes

New APIs and options 5

  • ByteUtils now provides a copy() method that behaves identically to Node.js Buffer.copy().

    7.2.0release notes

  • EJSON.stringify and EJSON.serialize accept ignoreUndefined to skip keys whose values are undefined; it defaults to false.

    7.2.0release notes

  • ByteUtils is now a public top-level export providing platform-agnostic tools to manipulate binary data; it is experimental and may change.

    7.1.0release notes

  • NumberUtils is now exported from the BSON package for reading to and from buffers of bytes; it is experimental and may change.

    7.1.0release notes

  • BSON value classes now expose a bsonType symbol property as an alias for _bsontype, distinguishing wrapper instances from documents with arbitrary keys.

    7.0.0release notes

Performance 1

  • Stores its 12 bytes as four inline integers instead of a Uint8Array, cutting per-ObjectId memory by about 63% with no serialization slowdown.

    7.3.2release notes

Behavior and default changes 1

  • All BSON bundles now use globalThis.crypto for random byte generation; the Node.js bundle no longer requires crypto.

    7.0.0release notes

Tooling 2

Fixes and other changes 10

  • Guards against optional APIs implemented with throwing stubs, preventing import-time throws in Next.js Edge and Bun runtimes.

    7.3.4release notes

  • Returns accurate byte counts for Int32 and BSONSymbol values, correcting a previous 12-byte overcount per value.

    7.3.2release notes

  • Properly accounts for ES Map objects when calculating size; serialization was not affected.

    7.3.2release notes

  • Avoids crypto calls during module initialization, which are forbidden by Cloudflare Workers and other environments.

    7.3.2release notes

  • Uses the first instant of year 10000 as the relaxed EJSON date bound instead of a date five hours after the maximum limit.

    7.3.2release notes

  • ObjectId startup snapshot API calls now use optional chaining, preventing a TypeError in environments with a stubbed or partial process global.

    7.3.1release notes

  • The constructor coerces subtype inputs to match BSON serialization, keeping the subtype property consistent with the serialized value.

    7.3.0release notes

  • Serialization, deserialization, and object-size calculation use iterative algorithms, so sufficiently nested documents no longer exhaust the call stack.

    7.3.0release notes

  • The space parameter is no longer discarded when stringify is called with value, options, and space, enabling formatted output for that signature.

    7.3.0release notes

  • Reverts a breaking change to the onDemand namespace, restoring compatibility with v7.0.0 of the MongoDB Node.js Driver.

    7.1.1release notes

bson 69 changes

Breaking changes 7

  • The constructor and write() no longer accept strings as binary sequences; string-format interpretation is expected outside the Binary class.

    6.0.0release notes

  • value() now returns only a properly sized Uint8Array or Buffer containing the data relevant to the Binary value.

    6.0.0release notes

  • The major version is now 6; only BSON objects with the same major version can be serialized, and mismatches throw BSONVersionError.

    6.0.0release notes

  • The constructor and fromString now throw a BSONError when conversion would lose precision instead of silently rounding.

    6.0.0release notes

  • The minimum supported Node.js version is now v16.20.1.

    6.0.0release notes

  • The constructor no longer interprets strings of length 12 as UTF8 bytes that can be converted to an ObjectId.

    6.0.0release notes

  • The deprecated, unused property was removed.

    6.0.0release notes

Fixes and other changes 2

  • Inspection now accounts for quotes when inspecting Code and BSONSymbol.

    6.0.0release notes

  • The method now accepts undefined and null parameters for equality checks.

    6.0.0release notes

bson 527 changes

Breaking changes 12

  • BSON errors when given BSON types that are not from this version.

    5.0.0release notes

  • All thrown errors are now BSONErrors.

    5.0.0release notes

  • A BSONType enum is added, while internal constants are removed from the export.

    5.0.0release notes

  • The Decimal128 toObject transformer is removed.

    5.0.0release notes

  • Extended JSON double values no longer include a .0 suffix.

    5.0.0release notes

  • The evalFunctions option is removed.

    5.0.0release notes

  • The minimum Node.js requirement is now v14.20.1 or later; older EOL Node.js versions are no longer supported.

    5.0.0release notes

  • Deprecated ObjectId methods are removed.

    5.0.0release notes

  • The capital-D ObjectID export is removed.

    5.0.0release notes

  • Enumeration now includes only own properties.

    5.0.0release notes

  • The serializer now validates its root input.

    5.0.0release notes

  • The Timestamp constructor now validates its argument.

    5.0.0release notes

New APIs and options 5

  • Set useBigInt64 to true to return BSON int64 values as BigInt; this is not enabled by default.

    5.0.0release notes

  • EJSON.parse now supports parsing $numberLong values to BigInt when useBigInt64 is enabled.

    5.0.0release notes

  • Set useBigInt64 to true to parse int64 values as BigInt; this is not enabled by default.

    5.0.0release notes

  • BSON now offers a native ESM bundle that works in Node.js and the browser alongside the existing CommonJS format.

    5.0.0release notes

  • Package exports are added for React Native.

    5.0.0release notes

Behavior and default changes 3

  • BSON.serialize now converts BigInt values into BSON Long values.

    5.0.0release notes

  • EJSON.stringify now converts BigInt values to EJSON's $numberLong format.

    5.0.0release notes

  • BSON's cross-platform byte handling uses Uint8Array on the web and Buffer in Node.js, allowing its ES module build to run without shims or polyfills.

    5.0.0release notes

Tooling 1

  • The TypeScript target version is raised to es2020.

    5.0.0release notes

Fixes and other changes 6

  • Canonical EJSON double precision accuracy is fixed.

    5.0.0release notes

  • EJSON parsing supports the $numberDouble: -0.0 representation of negative zero.

    5.0.0release notes

  • EJSON stringification preserves negative zero using the $numberDouble: -0.0 representation.

    5.0.0release notes

  • Serialization now checks for a toBSON method on values in Map entries.

    5.0.0release notes

  • Negative zero is serialized as a BSON double.

    5.0.0release notes

  • serializeFunctions no longer breaks function names outside basic Latin.

    5.0.0release notes

bson 48 changes

Breaking changes 7

  • BSON is no longer an instantiable type; use the exported namespace to call methods such as BSON.serialize.

    4.0.0upgrade guide

  • Types no longer maintain circular references; BSON.Timestamp.Timestamp is no longer available.

    4.0.0upgrade guide

  • The Symbol type is renamed BSONSymbol to avoid conflicts with the ES6 Symbol.

    4.0.0upgrade guide

  • The _bsontype property of all known types is now non-enumerable.

    4.0.0upgrade guide

  • Extended JSON is merged into bson and is accessible through the EJSON export, including stringify and parse.

    4.0.0upgrade guide

  • Doubles are deserialized as Number when relaxed mode is enabled.

    4.0.0upgrade guide

  • Node.js v6 or above is now required because the module uses ES2015 features in non-transpiled code.

    4.0.0upgrade guide

Deprecations 1

  • Strict mode is deprecated in favor of relaxed mode, in line with the Extended JSON specification.

    4.0.0upgrade guide

bson 26 changes

Security 1

  • Added a basic guard against REDOS attacks in Decimal128 handling.

    2.0.0release notes

Fixes and other changes 5

  • Fixed the browser property in package.json, affecting how browser-aware tooling resolves the package.

    2.0.0release notes

  • Only objects with allowed $keys are upgraded to DBRefs.

    2.0.0release notes

  • toString and fromString now correctly handle cases with too many significant digits.

    2.0.0release notes

  • When pid is 1, ObjectId generation uses a random value.

    2.0.0release notes

  • Documents are now written to the start of the intermediate buffer.

    2.0.0release notes