Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

bson

mongodb25.1mApache-2.06.10.1TypeScript support: included

A bson parser for node.js and the browser

mongodb, bson, parser

readme

BSON parser

BSON is short for "Binary JSON," and is the binary-encoded serialization of JSON-like documents. You can learn more about it in the specification.

Table of Contents

Release Integrity

Releases are created automatically and signed using the Node team's GPG key. This applies to the git tag as well as all release packages provided as part of a GitHub release. To verify the provided packages, download the key and import it using gpg:

gpg --import node-driver.asc

The GitHub release contains a detached signature file for the NPM package (named bson-X.Y.Z.tgz.sig).

The following command returns the link npm package.

npm view bson@vX.Y.Z dist.tarball 

Using the result of the above command, a curl command can return the official npm package for the release.

To verify the integrity of the downloaded package, run the following command:

gpg --verify bson-X.Y.Z.tgz.sig bson-X.Y.Z.tgz

[!Note] No verification is done when using npm to install the package. The contents of the Github tarball and npm's tarball are identical.

Bugs / Feature Requests

Think you've found a bug? Want to see a new feature in bson? Please open a case in our issue management tool, JIRA:

  1. Create an account and login: jira.mongodb.org
  2. Navigate to the NODE project: jira.mongodb.org/browse/NODE
  3. Click Create Issue - Please provide as much information as possible about the issue and how to reproduce it.

Bug reports in JIRA for the NODE driver project are public.

Usage

To build a new version perform the following operations:

npm install
npm run build

Node.js or Bundling Usage

When using a bundler or Node.js you can import bson using the package name:

import { BSON, EJSON, ObjectId } from 'bson';
// or:
// const { BSON, EJSON, ObjectId } = require('bson');

const bytes = BSON.serialize({ _id: new ObjectId() });
console.log(bytes);
const doc = BSON.deserialize(bytes);
console.log(EJSON.stringify(doc));
// {"_id":{"$oid":"..."}}

Browser Usage

If you are working directly in the browser without a bundler please use the .mjs bundle like so:

<script type="module">
  import { BSON, EJSON, ObjectId } from './lib/bson.mjs';

  const bytes = BSON.serialize({ _id: new ObjectId() });
  console.log(bytes);
  const doc = BSON.deserialize(bytes);
  console.log(EJSON.stringify(doc));
  // {"_id":{"$oid":"..."}}
</script>

Installation

npm install bson

MongoDB Node.js Driver Version Compatibility

Only the following version combinations with the MongoDB Node.js Driver are considered stable.

| | `bson@1.x|bson@4.x|bson@5.x|bson@6.x| | ------------- | ---------- | ---------- | ---------- | ---------- | |mongodb@6.x| N/A | N/A | N/A | ✓ | |mongodb@5.x| N/A | N/A | ✓ | N/A | |mongodb@4.x| N/A | ✓ | N/A | N/A | |mongodb@3.x` | ✓ | N/A | N/A | N/A |

Documentation

BSON

API documentation

EJSON

EJSON.parse(text, [options])

Param Type Default Description
text string |
[options] object | Optional settings
[options.relaxed] boolean true Attempt to return native JS types where possible, rather than BSON types (if true)

Parse an Extended JSON string, constructing the JavaScript value or object described by that string.

Example

const { EJSON } = require('bson');
const text = '{ "int32": { "$numberInt": "10" } }';

// prints { int32: { [String: '10'] _bsontype: 'Int32', value: '10' } }
console.log(EJSON.parse(text, { relaxed: false }));

// prints { int32: 10 }
console.log(EJSON.parse(text));

EJSON.stringify(value, [replacer], [space], [options])

Param Type Default Description
value object | The value to convert to extended JSON
[replacer] function | array | A function that alters the behavior of the stringification process, or an array of String and Number objects that serve as a whitelist for selecting/filtering the properties of the value object to be included in the JSON string. If this value is null or not provided, all properties of the object are included in the resulting JSON string
[space] string | number | A String or Number object that's used to insert white space into the output JSON string for readability purposes.
[options] object | Optional settings
[options.relaxed] boolean true Enabled Extended JSON's relaxed mode
[options.legacy] boolean true Output in Extended JSON v1

Converts a BSON document to an Extended JSON string, optionally replacing values if a replacer function is specified or optionally including only the specified properties if a replacer array is specified.

Example

const { EJSON } = require('bson');
const Int32 = require('mongodb').Int32;
const doc = { int32: new Int32(10) };

// prints '{"int32":{"$numberInt":"10"}}'
console.log(EJSON.stringify(doc, { relaxed: false }));

// prints '{"int32":10}'
console.log(EJSON.stringify(doc));

EJSON.serialize(bson, [options])

Param Type Description
bson object The object to serialize
[options] object Optional settings passed to the stringify function

Serializes an object to an Extended JSON string, and reparse it as a JavaScript object.

EJSON.deserialize(ejson, [options])

Param Type Description
ejson object The Extended JSON object to deserialize
[options] object Optional settings passed to the parse method

Deserializes an Extended JSON object into a plain JavaScript object with native/BSON types

Error Handling

It is our recommendation to use BSONError.isBSONError() checks on errors and to avoid relying on parsing error.message and error.name strings in your code. We guarantee BSONError.isBSONError() checks will pass according to semver guidelines, but errors may be sub-classed or their messages may change at any time, even patch releases, as we see fit to increase the helpfulness of the errors.

Any new errors we add to the driver will directly extend an existing error class and no existing error will be moved to a different parent class outside of a major release. This means BSONError.isBSONError() will always be able to accurately capture the errors that our BSON library throws.

Hypothetical example: A collection in our Db has an issue with UTF-8 data:

let documentCount = 0;
const cursor = collection.find({}, { utf8Validation: true });
try {
  for await (const doc of cursor) documentCount += 1;
} catch (error) {
  if (BSONError.isBSONError(error)) {
    console.log(`Found the troublemaker UTF-8!: ${documentCount} ${error.message}`);
    return documentCount;
  }
  throw error;
}

React Native

BSON vendors the required polyfills for TextEncoder, TextDecoder, atob, btoa imported from React Native and therefore doesn't expect users to polyfill these. One additional polyfill, crypto.getRandomValues is recommended and can be installed with the following command:

npm install --save react-native-get-random-values

The following snippet should be placed at the top of the entrypoint (by default this is the root index.js file) for React Native projects using the BSON library. These lines must be placed for any code that imports BSON.

// Required Polyfills For ReactNative
import 'react-native-get-random-values';

Finally, import the BSON library like so:

import { BSON, EJSON } from 'bson';

This will cause React Native to import the node_modules/bson/lib/bson.rn.cjs bundle (see the "react-native" setting we have in the "exports" section of our package.json.)

Technical Note about React Native module import

The "exports" definition in our package.json will result in BSON's CommonJS bundle being imported in a React Native project instead of the ES module bundle. Importing the CommonJS bundle is necessary because BSON's ES module bundle of BSON uses top-level await, which is not supported syntax in React Native's runtime hermes.

FAQ

Why does undefined get converted to null?

The undefined BSON type has been deprecated for many years, so this library has dropped support for it. Use the ignoreUndefined option (for example, from the driver ) to instead remove undefined keys.

How do I add custom serialization logic?

This library looks for toBSON() functions on every path, and calls the toBSON() function to get the value to serialize.

const BSON = require('bson');

class CustomSerialize {
  toBSON() {
    return 42;
  }
}

const obj = { answer: new CustomSerialize() };
// "{ answer: 42 }"
console.log(BSON.deserialize(BSON.serialize(obj)));

changelog

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

6.10.1 (2024-11-27)

Bug Fixes

  • NODE-6552: remove cache and use toStringTag in type helpers (#740) (3ede13e)

Performance Improvements

  • NODE-6450: Lazy objectId hex string cache (#722) (7c37580)

6.10.0 (2024-11-18)

Features

  • NODE-6537: add support for binary vectors (#730) (d7bdcec)

Bug Fixes

  • NODE-6536: Binary.read never returns number[] and reads beyond content (#727) (f99fdfd)

6.9.0 (2024-10-15)

Features

Performance Improvements

  • NODE-6344: improve ObjectId.isValid(string) performance (#708) (064ba91)
  • NODE-6356: Improve serialization performance (#709) (61537f5)

6.8.0 (2024-06-27)

Features

  • NODE-6156: add signature to github releases (#692) (f0fbe91)

Performance Improvements

  • NODE-6126: improve Long.fromBigInt performance (#681) (63eafcb)

6.7.0 (2024-05-01)

Features

  • NODE-5648: add Long.fromStringStrict() (#675) (9d5a5df)
  • NODE-6086: add Double.fromString() method (#671) (e943cdb)
  • NODE-6087: add Int32.fromString method (#670) (5a21889)

Bug Fixes

  • NODE-6102: Double.fromString prohibiting '+' character and prohibiting exponential notation (#674) (c58d1e2)
  • NODE-6123: utf8 validation is insufficiently strict (#676) (ae8bac7)
  • NODE-6144: Long.fromString incorrectly coerces valid inputs to Long.ZERO in special cases (#677) (208f7e8)

6.6.0 (2024-04-01)

Features

  • NODE-5958: add BSON iterating API (#656) (269df91)
  • NODE-5959: make byte parsing utils available on onDemand library (#662) (efab49a)

Bug Fixes

  • NODE-6042: Binary.toString output with respect to position (#663) (d7898f9)
  • NODE-6059: clean up experimental APIs (#665) (3289184)

6.5.0 (2024-03-12)

Features

Bug Fixes

  • NODE-6016: flip byte order depending on system endianness (#659) (6a7ef5d)

6.4.0 (2024-02-29)

Features

  • NODE-5909: optimize writing basic latin strings (#645) (ec51256)

Bug Fixes

  • NODE-5873: objectId symbol property not defined on instances from cross cjs and mjs (#643) (4d9884d)

Performance Improvements

  • NODE-5557: move DataView and Set allocation used for double parsing and utf8 validation to nested path (#611) (9a150e1)
  • NODE-5910: optimize small byte copies (#651) (24d035e)
  • NODE-5934: replace DataView uses with bit math (#649) (6d343ab)
  • NODE-5955: use pooled memory when possible (#653) (78c4264)

6.3.0 (2024-01-31)

Features

  • NODE-3034: deprecate number as an input to ObjectId constructor (#640) (44bec19)
  • NODE-5861: optimize parsing basic latin strings (#642) (cdb779b)

6.2.0 (2023-10-16)

Features

  • NODE-5040: add color to BSON inspect (#635) (7802c66)

Bug Fixes

  • NODE-5640: BsonVersionError improve message clarity (#629) (eb98b8c)

6.1.0 (2023-09-12)

Features

  • NODE-5594: add Decimal128.fromStringWithRounding() static method (#617) (6fee2d5)

Bug Fixes

  • NODE-5577: improve ObjectId serialization by around 10% (#614) (81c8fa1)

6.0.0 (2023-08-24)

⚠ BREAKING CHANGES

  • NODE-5504: bump bson major version (#605)
  • NODE-4770: remove 12 length string support from ObjectId constructor (#601)
  • NODE-4769: remove ISO-8859-1 string support from Binary (#602)
  • NODE-5223: remove deprecated cacheHexString (#595)
  • NODE-4787: bump minimum Node.js version to v16.20.1 (#590)

Features

  • NODE-4769: remove ISO-8859-1 string support from Binary (#602) (74f7f8a)
  • NODE-4770: remove 12 length string support from ObjectId constructor (#601) (409c592)
  • NODE-4787: bump minimum Node.js version to v16.20.1 (#590) (1dcca92)
  • NODE-5223: remove deprecated cacheHexString (#595) (76eca2b)
  • NODE-5504: bump bson major version (#605) (9615902)

Bug Fixes

  • NODE-5509: Allow undefined or null params in ObjectId.equals (#607) (e2674c6)
  • NODE-5546: decimal 128 fromString performs inexact rounding (#613) (1384cee)
  • NODE-5559: account for quotes when inspecting Code and BSONSymbol (#612) (0664840)

6.0.0-alpha.0 (2023-08-15)

⚠ BREAKING CHANGES

  • NODE-5504: bump bson major version (#605)
  • NODE-4770: remove 12 length string support from ObjectId constructor (#601)
  • NODE-4769: remove ISO-8859-1 string support from Binary (#602)
  • NODE-5223: remove deprecated cacheHexString (#595)
  • NODE-4787: bump minimum Node.js version to v16.20.1 (#590)

Features

  • NODE-4769: remove ISO-8859-1 string support from Binary (#602) (74f7f8a)
  • NODE-4770: remove 12 length string support from ObjectId constructor (#601) (409c592)
  • NODE-4787: bump minimum Node.js version to v16.20.1 (#590) (1dcca92)
  • NODE-5223: remove deprecated cacheHexString (#595) (76eca2b)
  • NODE-5504: bump bson major version (#605) (9615902)

Bug Fixes

  • NODE-5509: Allow undefined or null params in ObjectId.equals (#607) (e2674c6)

5.4.0 (2023-07-03)

Features

  • NODE-4938: improve react native bundle experience (#578) (7e16636)

Bug Fixes

  • NODE-5363: defer byte slicing to utf8 decoding API in nodejs (#585) (e087042)

5.3.0 (2023-05-10)

Features

  • NODE-5224: deprecate UUID hex string cache control (#573) (70aea75)

Bug Fixes

  • NODE-4960: UUID validation too strict (#572) (d239cd1)

5.2.0 (2023-04-04)

Features

  • NODE-4855: add hex and base64 ctor methods to Binary and ObjectId (#569) (0d49a63)

5.1.0 (2023-03-16)

Features

  • NODE-4789: support Map stringification in EJSON (#567) (c70c82d)

5.0.1 (2023-02-16)

Bug Fixes

  • NODE-5025: no type definitions for es module (#563) (50e90fc)
  • NODE-5048: webpack unable to bundle import with leading 'node:' (#564) (3aed24a)
  • NODE-5056: EJSON.parse date handling when useBigInt64=true (#562) (d5088af)

5.0.0 (2023-01-31)

5.0.0-alpha.3 (2023-01-20)

⚠ BREAKING CHANGES

  • NODE-4892: error on bson types not from this version (#543)
  • NODE-4890: make all thrown errors into BSONErrors (#545)
  • NODE-4713: modernize bundling (#534)
  • NODE-1921: validate serializer root input (#537)
  • NODE-4711: remove evalFunctions option (#539)

Features

  • NODE-1921: validate serializer root input (#537) (95d5edf)
  • NODE-4711: remove evalFunctions option (#539) (0427eb5)
  • NODE-4713: modernize bundling (#534) (28ce4d5)
  • NODE-4870: Support BigInt serialization (#541) (e9e40a2)
  • NODE-4871: Add support for int64 deserialization to BigInt (#542) (9ff60ba)
  • NODE-4873: support EJSON stringify from BigInt to $numberLong (#547) (37e8690)
  • NODE-4874: support EJSON parse for BigInt from $numberLong (#552) (854aa70)
  • NODE-4890: make all thrown errors into BSONErrors (#545) (5b837a9)
  • NODE-4892: error on bson types not from this version (#543) (d9f0eaa)
  • NODE-4927: exports in package.json for react native and document how to polyfill for BSON (#550) (3b4b61e)

Bug Fixes

  • NODE-4771: serializeFunctions breaks function names outside of basic latin (#538) (35a9234)
  • NODE-4887: serializeInto does not check for the presence of a toBSON method for values in Map entries (#555) (ebc1c76)
  • NODE-4905: double precision accuracy in canonical EJSON (#548) (e0dbb17)
  • NODE-4932: remove .0 suffix from double extended json values (#554) (946866d)

4.7.0 (2022-08-18)

Features

  • NODE-4405: support serializing UUID class (#508) (f5dc9ed)
  • NODE-4419: UUID class deserialization (#509) (ff2b975)
  • NODE-4506: Make UUID a subclass of binary (#512) (e9afa9d)
  • NODE-4535: automatically promote UUIDs when deserializing and parsing UUIDs (#513) (1dc7eae)

4.6.5 (2022-07-07)

Bug Fixes

  • NODE-3630: remove float parser and test edge cases for Double (#502) (54ca603)
  • NODE-4211: Do not require crypto in browser builds (#500) (b32ab40)
  • NODE-4302: remove downlevel ts and typesVersions (#501) (651b60e)
  • NODE-4381: handle __proto__ well in EJSON (#506) (4bda57d)

4.6.4 (2022-05-19)

4.6.3 (2022-04-20)

4.6.2 (2022-03-22)

Bug Fixes

  • MONGOSH-1155: update error message in ObjectId class (#493) (67fbc7c)
  • NODE-3015: ObjectId.equals should use Buffer.equals for better performance (#478) (8305bdf)
  • NODE-3962: correct type for ObjectiId._bsontype (#480) (9671773)

4.6.1 (2022-01-06)

Bug Fixes

  • NODE-3760: ObjectId.isValid string and byte length match (#475) (187d1c4)
  • NODE-3815: update Decimal128 constructor validation (#476) (95e8293)
  • NODE-3821: nullish check before using toBSON override function (#477) (1d898b6)

4.6.0 (2021-11-23)

Features

  • NODE-3740: Implement root and top level key utf-8 validation settings for BSON (#472) (07019a0)

Bug Fixes

  • NODE-3724: Fix BSONTypeError and BSONError to correctly handle instanceof checks (#471) (d8f334b)

4.5.4 (2021-11-03)

Bug Fixes

  • NODE-3640: Fix Int32 constructor to coerce its argument to int32 (#466) (d388f1e)
  • NODE-3662: error checking to make sure that ObjectId results in object with correct properties (#467) (5f99b1b)

4.5.3 (2021-10-05)

Bug Fixes

  • NODE-3493: code and symbol tests are partially testing the wrong types (#459) (80d7f03)
  • NODE-3534: add subtype 0x6 and 0x7 constants on Binary class (#461) (52cfe9c)
  • NODE-3629: correct corpus runner and add null checks (#464) (d75102d)

4.5.2 (2021-09-14)

Bug Fixes

  • NODE-3021: fix a long standing bug in Decimal128.fromString() (#458) (824939a)
  • NODE-3582: fix internal marked APIs, add toString methods to Int32 and Double (#457) (b46ab5f)

4.5.1 (2021-08-24)

Bug Fixes

  • NODE-3561: umd bundle fails to require util (#455) (1c15155)

4.5.0 (2021-08-19)

Features

  • NODE-3504: add unambiguous Timestamp() constructor overload (#449) (0298dd8)

Bug Fixes

  • NODE-3451: fix performance regression from v1 (#451) (2330ab1)
  • NODE-3520: global not defined in esm bundles (#452) (cb82a80)

4.4.1 (2021-07-06)

Bug Fixes

  • NODE-3247: DBRef special handling (#443) (f5d984d)
  • NODE-3282: BSONRegExp options not alphabetized (#441) (18c3512)
  • NODE-3376: use standard JS methods for copying Buffers (#444) (804050d)
  • NODE-3390: serialize non-finite doubles correctly in EJSON (#445) (7eb7998)

4.4.0 (2021-05-18)

Features

  • NODE-3264: allow Decimal128(string), Long(string), Long(bigint) (#437) (392c1bc)
  • make circular input errors for EJSON expressive (#433) (7b351cc)

Bug Fixes

  • make Long inspect result evaluable (3a2eff1)
  • NODE-3153: correctly deserialize __proto__ properties (#431) (f34cabc)
  • accept Uint8Array where Buffer is accepted (#432) (4613763)
  • clean up instanceof usage (9b6d52a)
  • improve ArrayBuffer brand check in ensureBuffer (#429) (99722f6)

4.3.0 (2021-04-06)

Features

4.2.3 (2021-03-02)

Bug Fixes

  • allow library to be loaded in web workeds (#423) (023f57e)

  • make inspection result of BSON types evaluable (#416) (616665f)

  • permit BSON types to be created without new (#424) (d2bc284)

4.2.2 (2020-12-01)

Bug Fixes

  • remove tslib usage and fix Long method alias (#415) (2d9a8e6)

4.2.1 (2020-12-01)

Bug Fixes

  • backwards compatibility with older BSON package versions (#411) (5167be2)
  • Downlevel type definitions (#410) (203402f)
  • make inspect method for ObjectId work (#412) (a585a0c)
  • remove stringify overloads (2df6b42)

4.2.0 (2020-10-13)

Features

Bug Fixes

  • adds interfaces for EJSON objects (7f5f1a3)
  • Correct API Extractor config to omit definition file from dist (#407) (ace8647)
  • coverage (992e2e0)
  • deprecate cacheFunctionsCrc32 (ea83bf5)
  • Rework rollup config to output named and default exports (#404) (a48676b)
  • Throw on BigInt type values (#397) (2dd54e5)
  • type issues with SerializeOptions and Long methods accepting Timestamp (c18ba71)

4.1.0 (2020-08-10)

Bug Fixes

  • spelling in deserializer errors (4c6f2e4)
  • object-id: harden the duck-typing (4b800ae)
  • parse value of Int32 in constructor (5cda40f)
  • Reduce floating point precision required of extended json implementations (#369) (5e35d1a)

Features

  • add support for primitives to EJSON.stringify (329857d)

4.0.4 (2020-03-26)

Bug Fixes

  • improve EJSON generation for previously skipped edge cases (30f5a8f)
  • only upgrade symbol to string if promoteValues is true (067a7ba)

4.0.3 (2020-01-09)

Bug Fixes

  • support Number object in Int32 and Double constructors (fe3f0dc)
  • Timestamp: make sure timestamp is always unsigned (36b2d43)

4.0.2 (2019-03-08)

Bug Fixes

  • buffer: don't use deprecated Buffer constructors (7bb9c57)
  • Buffer: import buffer for binary, decimal128, and fnv1a (6be7b8d)
  • ejson: enable serialization of legacy ObjectID (ba98ccb), closes #303
  • ejson: support array for replacer parameter in EJSON.stringify (9f43809), closes #303 #302 #303
  • ejson-serialize: prevent double serialization for nested documents (ab790c9), closes #303
  • object-id: correct serialization of old ObjectID types (8d57a8c)
  • timestamp: getTimestamp support times beyond 2038 (a0820d5)
  • 4.x-1.x interop (incl. ObjectID _bsontype) (f4b16d9)

4.0.1 (2018-12-06)

Bug Fixes

  • object-id: correct serialization of old ObjectID types (8d57a8c)

4.0.0 (2018-11-13)

Migration Guide

Please see the migration guide for detailed discussion of breaking changes in this release.

Bug Fixes

  • buffer: replace deprecated Buffer constructor (5acdebf)
  • dbPointer: fix utf8 bug for dbPointer (018c769)
  • deserialize: fix deserialization of 0xFFFD (c682ae3), closes #277
  • ext-json: deserialize doubles as Number in relaxed mode (a767fa1)
  • ObjectId: will now throw if an invalid character is passed (6f30b4e)
  • ObjectID: ObjectId.isValid should check buffer length (06af813)
  • package: browser section needs to point to correct index (08337e3)
  • random-bytes: fallback to insecure path if require is null (963b12b)
  • random-bytes: wrap crypto require in try/catch for fallback (47fd5f7)
  • serializer: do not use checkKeys for $clusterTime (cbb4724)
  • serializer: map insert expects only string keys (aba3a18)

Code Refactoring

  • symbol: rename Symbol to BSONSymbol (5d5b3d2)

Features

  • BSON: simplify and flatten module exports (f8920c6)
  • bsontype: move all _bsontypes to non-enumerable properties (16f5bf6)
  • ext-json: add extended JSON codecs directly to BSON types (10e5f00)
  • ext-json: add extended JSON support to the bson library (d6b71ab)
  • ext-json: export EJSON at top level of module (c356a5a)
  • karma: test bson in the browser (cd593ca)
  • long: replace long implementatin with long.js (545900d)

BREAKING CHANGES

  • ObjectId: Where code was previously silently erroring, users may now experience TypeErrors
  • symbol: This was conflicting with the ES6 Symbol type

3.0.2 (2018-07-13)

Bug Fixes

  • revert: Reverting v3.0.1 (efb0720)

3.0.0 (2018-06-13)

Features

  • ObjectID: use FNV-1a hash for objectId (4f545b1)
  • rollup: initial commit of rollup-generated bundle (474b8f7)
  • rollup: switch from webpack to rollup for bundling (98068fa)

2.0.8 (2018-06-06)

Bug Fixes

  • readme: clarify documentation about deserialize methods (e311056)
  • serialization: normalize function stringification (21eb0b0)

2.0.7 (2018-05-31)

Bug Fixes

  • binary: add type checking for buffer (cbfb25d)

2.0.6 (2018-04-27)

Bug Fixes

  • deserializeStream: allow multiple documents to be deserialized (6fc5984), closes #244

2.0.5 (2018-04-06)

Bug Fixes

  • regexp: properly construct new BSONRegExp when constructor called without new (#242) (93ae799)

2.0.4 (2018-03-12)

2.0.3 (2018-03-12)

Features

  • serialization: support arbitrary sizes for the internal serialization buffer (a6bd45c)

2.0.2 (2018-03-02)

Bug Fixes

  • make sure all functions are named consistently (6df9022)

2.0.1 (2018-02-28)

Bug Fixes

  • serializer: ensure RegExp options are alphabetically sorted (d60659d)

Features

  • db-ref: support passing a namespace into a DBRef ctor (604831b)

2.0.0 (2018-02-26)

Bug Fixes

  • browser: fixing browser property in package.json (095fba9)
  • dbref: only upgrade objects with allowed $keys to DBRefs (98eb9e2)
  • decimal128: add basic guard against REDOS attacks (511ecc4)
  • Decimal128: update toString and fromString methods to correctly handle the case of too many significant digits (25ed43e)
  • objectid: if pid is 1, use random value (e188ae6)
  • serializeWithBufferAndIndex: write documents to start of intermediate buffer (b4e4ac5)

1.0.4 2016-01-11

  • 204 remove Buffer.from as it's partially broken in early 4.x.x. series of node releases.

1.0.3 2016-01-03

  • Fixed toString for ObjectId so it will work with inspect.

1.0.2 2016-01-02

  • Minor optimizations for ObjectID to use Buffer.from where available.

1.0.1 2016-12-06

  • Reverse behavior for undefined to be serialized as NULL. MongoDB 3.4 does not allow for undefined comparisons.

1.0.0 2016-12-06

  • Introduced new BSON API and documentation.

0.5.7 2016-11-18

  • NODE-848 BSON Regex flags must be alphabetically ordered.

0.5.6 2016-10-19

  • NODE-833, Detects cyclic dependencies in documents and throws error if one is found.
  • Fix(deserializer): corrected the check for (size + index) comparison… (Issue #195, https://github.com/JoelParke).

0.5.5 2016-09-15

  • Added DBPointer up conversion to DBRef

0.5.4 2016-08-23

  • Added promoteValues flag (default to true) allowing user to specify if deserialization should be into wrapper classes only.

0.5.3 2016-07-11

  • Throw error if ObjectId is not a string or a buffer.

0.5.2 2016-07-11

  • All values encoded big-endian style for ObjectId.

0.5.1 2016-07-11

  • Fixed encoding/decoding issue in ObjectId timestamp generation.
  • Removed BinaryParser dependency from the serializer/deserializer.

0.5.0 2016-07-05

  • Added Decimal128 type and extended test suite to include entire bson corpus.

0.4.23 2016-04-08

  • Allow for proper detection of ObjectId or objects that look like ObjectId, improving compatibility across third party libraries.
  • Remove one package from dependency due to having been pulled from NPM.

0.4.22 2016-03-04

  • Fix "TypeError: data.copy is not a function" in Electron (Issue #170, https://github.com/kangas).
  • Fixed issue with undefined type on deserializing.

0.4.21 2016-01-12

  • Minor optimizations to avoid non needed object creation.

0.4.20 2015-10-15

0.4.19 2015-10-15

  • Remove all support for bson-ext.

0.4.18 2015-10-15

  • ObjectID equality check should return boolean instead of throwing exception for invalid oid string #139
  • add option for deserializing binary into Buffer object #116

0.4.17 2015-10-15

  • Validate regexp string for null bytes and throw if there is one.

0.4.16 2015-10-07

  • Fixed issue with return statement in Map.js.

0.4.15 2015-10-06

  • Exposed Map correctly via index.js file.

0.4.14 2015-10-06

  • Exposed Map correctly via bson.js file.

0.4.13 2015-10-06

  • Added ES6 Map type serialization as well as a polyfill for ES5.

0.4.12 2015-09-18

  • Made ignore undefined an optional parameter.

0.4.11 2015-08-06

  • Minor fix for invalid key checking.

0.4.10 2015-08-06

  • NODE-38 Added new BSONRegExp type to allow direct serialization to MongoDB type.
  • Some performance improvements by in lining code.

0.4.9 2015-08-06

  • Undefined fields are omitted from serialization in objects.

0.4.8 2015-07-14

  • Fixed size validation to ensure we can deserialize from dumped files.

0.4.7 2015-06-26

  • Added ability to instruct deserializer to return raw BSON buffers for named array fields.
  • Minor deserialization optimization by moving inlined function out.

0.4.6 2015-06-17

  • Fixed serializeWithBufferAndIndex bug.

0.4.5 2015-06-17

  • Removed any references to the shared buffer to avoid non GC collectible bson instances.

0.4.4 2015-06-17

  • Fixed rethrowing of error when not RangeError.

0.4.3 2015-06-17

  • Start buffer at 64K and double as needed, meaning we keep a low memory profile until needed.

0.4.2 2015-06-16

  • More fixes for corrupt Bson

0.4.1 2015-06-16

  • More fixes for corrupt Bson

0.4.0 2015-06-16

  • New JS serializer serializing into a single buffer then copying out the new buffer. Performance is similar to current C++ parser.
  • Removed bson-ext extension dependency for now.

0.3.2 2015-03-27

  • Removed node-gyp from install script in package.json.

0.3.1 2015-03-27

  • Return pure js version on native() call if failed to initialize.

0.3.0 2015-03-26

  • Pulled out all C++ code into bson-ext and made it an optional dependency.

0.2.21 2015-03-21

  • Updated Nan to 1.7.0 to support io.js and node 0.12.0

0.2.19 2015-02-16

  • Updated Nan to 1.6.2 to support io.js and node 0.12.0

0.2.18 2015-01-20

  • Updated Nan to 1.5.1 to support io.js

0.2.16 2014-12-17

  • Made pid cycle on 0xffff to avoid weird overflows on creation of ObjectID's

0.2.12 2014-08-24

  • Fixes for fortify review of c++ extension
  • toBSON correctly allows returns of non objects

0.2.3 2013-10-01

0.1.4 2012-09-25

  • Added precompiled c++ native extensions for win32 ia32 and x64