npm bson 7.0.0
v7.0.0

one day ago

7.0.0 (2025-11-05)

The MongoDB Node.js team is pleased to announce version 7.0.0 of the bson package!

Release Notes

⚠ Breaking Changes

Minimum supported Node.js version now 20.19.0

The minimum supported Node.js version is now v20.19.0. We strive to keep our minimum supported Node.js version in sync with the runtime's release cadence to keep up with the latest security updates and modern language features. Our TypeScript target has also been updated to ES2023.

BSON now requires BigInt literal support

BSON now uses Javascript BigInt syntax and requires a JS engine with support for BigInt literal syntax.

All BSON bundles now use globalThis.crypto for random byte generation

Until BSON@7.x, BSON has supported Node.js v16. Node.js v16 does not include crypto in the global object, which necessitated importing crypto from node:crypto. This require has caused many headaches for bundlers. We improved the situation in NODE-6074, but this release updates our Node.js bundle to rely on the global object instead and removes all requires from the bundle.

BSON no longer vendors atob, btoa, and TextEncoder for react native builds

The React Native JS engine (Hermes) now supports atob, btoa, and TextEncoder natively and polyfills are no longer needed. BSON no longer includes these polyfills for react native builds.

ObjectId constructor no longer accepts a number

If you wish to create an ObjectId from a numeric timestamp, use ObjectId.createFromTime() instead.

BSON Binary subtype 2 constant deprecated

BSON Binary subtype 2 was previously deprecated in the BSON specification, but the corresponding subtype constant remained available in the BSON library. This constant has now been deprecated to align with the specification.

Non-breaking Features

New bsonType symbol property as an alias for _bsontype

JS classes representing BSON values now have a bsonType symbol property as an alias for the existing _bsontype property. This makes it easier to distinguish between values of a specific BSON type and documents with arbitrary keys after deserializing:

import { bsonType, deserialize } from 'bson';

const doc = deserialize(...);
// will be set when doc.value is a BSON wrapper class **or** a sub-document { _bsontype: '...' } 
console.log(doc.value._bsontype); 
// will be set if and only if doc.value is a BSON wrapper class
console.log(doc.value[bsonType]);

It is safe to replace all uses of value._bsontype with value[bsonType].

All Changes

Documentation

We invite you to try the bson library immediately, and report any issues to the NODE project.

Don't miss a new bson release

NewReleases is sending notifications on new releases.