API Reference
BSON
The BSON serialization library for MongoDB, encoding documents to a compact binary format.
Official Documentation ↗CompatibilityThis documentation covers version
v7.3.3. Check the official docs for the latest API surface.Installation
npm
npm install bsonMethods
No methods match this filter.
js-bson encodes and decodes BSON documents and object ids, the wire format used by MongoDB.
Key Features
- Binary encoding of the rich BSON type set
- ObjectId creation and validation
- Order-preserving document fields
Usage Notes
Pin a version and check the official docs for the API surface you depend on before upgrading.
Errors
The following points are quoted verbatim from the official documentation. 来源:https://cdn.jsdelivr.net/gh/mongodb/js-bson@latest/README.md · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:48:35.163Z. Any error type, throw condition or recovery step not stated there is left unspecified; this page does not infer exception classes or return values.
- 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. (https://cdn.jsdelivr.net/gh/mongodb/js-bson@latest/README.md)
- 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. (https://cdn.jsdelivr.net/gh/mongodb/js-bson@latest/README.md)
- This means BSONError.isBSONError() will always be able to accurately capture the errors that our BSON library throws. (https://cdn.jsdelivr.net/gh/mongodb/js-bson@latest/README.md)
FAQ
- What types does BSON support beyond JSON?
- BSON adds Date, binary, ObjectId, long, decimal, and regex, which is why it is used by MongoDB internally.
- Is BSON order-preserving?
- Yes. Documents are an ordered sequence of fields, so field order round-trips exactly, unlike JSON parsed into a plain object.
- Can ObjectId bytes come from a client?
- Yes. new ObjectId(string) validates length and hex characters, so malformed identifiers throw instead of corrupting queries.
Report a problem with this API docOpens a pre-filled issue on GitHub.