bson
Bson library for Dart. BSON is a binary-encoded serialization of JSON-like documents. The package allows also eJson and object serialization/deserialization.
5.0.8
53K downloads/mo
#1436 most downloaded on pub.dev
mongo-dart/bson
What this package is like to depend on
Last release 6 months ago
26 Jan 2026
Release timing varies
gaps range from 8 days to 9 months
Some releases are documented
notes for 20 of 47 stable releases
Nothing withdrawn
no release was ever pulled
13 years old
59 releases · first in 2013
1 release in the last 12 months
see the full history below
Release timeline
59 releases · Apr 2013 to Jan 2026Releases
latest 59-
5.0.826 Jan 2026Release notes
Open source →- Fix ObjectId generation producing duplicate IDs across process restarts. The
setIntExtendedmethod was not advancing the buffer offset after writing, causing the counter bytes to overwrite the random value bytes instead of being written to the correct position.
- Fix ObjectId generation producing duplicate IDs across process restarts. The
-
5.0.703 May 2025 -
5.0.625 Apr 2025 -
5.0.515 Sep 2024 -
5.0.416 Mar 2024Release notes
Open source →- Code clean-up
- LegacyUuid class. It allows to manage Binary Subtype 3 Bson types (Uuid Old). The class holds the value in the storing format, some helpers are available for converting back an forth this value based on the known algorithms: java Legacy, C# legacy and Python.
-
5.0.314 Jan 2024Release notes
Open source →Fixed some inconsistencies with dart2js
double.NaNis stored in a different way in VM and JS, forced the VM way.double.infinityanddouble.negativeInfinityin JS were considered as int, forced to be considered asdouble.- Fixed "Unsupported operation: Int64 accessor not supported by dart2js"
It has not been found a way to let the system detect correctly
doublevariabls when the values has no decimals. JS in this case considers the field as an int. The only way to solve this, is to send thedoublefields wrapped into aBsonDobuleobject. -
5.0.211 Nov 2023 -
5.0.110 Nov 2023 -
5.0.003 Nov 2023Release notes
Open source →This release contains many breaking changes. Here is a list of the most noticeable:
-
BSONhas been deprecated in favor ofBsonCodec -
In general the logic is changed so that the document to be encoded should contain normal "Dart object" and the document returned will do the same. In input the system will continue to accept BsonObjects anyway, the issue can be with the returned Objects. At present the more important exceptions are ``BsonBinary
andDbPointer`. This also measn that the BSON classes are not automatically exported in the package, if needed you should import them from the src/types/ folder -
To address the above logic some new classes have been created:
JsCodeandDbRef. -
The
DbRefvalues were stored as DbPointers. Now they are stored correctly as a particular type of Map (contains $ref and $id elements). Beware that, if you have stored Dbref values, now they will be returnde as DbPointers. Also an optional $db value is accepted and managed from the new DbRef class. -
The
JsCodeclass is used to clearly separate normal Strings from Javascript code. -
The
RegExpclass is used instead of the BsonRegexp one. -
The
DbPointerclass is deprecated (as per Bson specifications). -
dataSize()andbyteLenght()have been deprecated in favor of contentLength and totalByteLength getters. -
the Bson classes now are intended to be used internally, so they are no more exported explicitly in the bson package.
-
BsonBinary.setInExtendednow supports also 5 and 7 bytes aside of the already managed 3 bytes. Corrected the endian logic, nowEndian.littleis the default. -
Class
ObjectId:- Removed the obscure
ClientMode parameter. $oidgetter renamed asoid. It is more practical in string interpolation- updated the random and counter parts logic. Before they were 4+4 bytes. Now, as per specifications, they are 5+3 bytes
- Removed the obscure
-
The logic for the increment part was not correct in the
Timestampclass -
Added
toJsonmethod toDbRef,JsCodeandTimestampclasses
-
-
5.0.0-7.0.beta17 Oct 2023 pre-release -
5.0.0-6.0.beta08 Oct 2023 pre-releaseRelease notes
Open source →- General Clean-up
- Deprecated
ObjectId.toHexString()in favor of theObjectId.oidgetter
-
5.0.0-5.0.beta08 Oct 2023 pre-releaseRelease notes
Open source →- Added
EJson.stringify()method. - Added
EJson.parse()method. - Modified the second parameter of the Map constructor to optional (with bsonSerialization as default)
- Added
-
5.0.0-4.0.dev01 Oct 2023 pre-release -
5.0.0-3.0.dev29 Aug 2023 pre-releaseRelease notes
Open source →- Added tests
- Moved back Date to UTC, it is a BSON requirement.
- dataSize() and byteLength() methods changed into getters
-
5.0.0-2.0.dev21 Aug 2023 pre-releaseRelease notes
Open source →- Reviewed the codecs. Now we have three codecs: Bson, Ejson and Object. There is also a generic one simply called Codec, that can be customized to run serialization and deserialization with specific parameters.
- Object serialization
- Removed old deprecated typeByte consts.
- Reviewed the BsonRegexp class (now returns and accepts RegExp objects).
- Created a JsCode class for BsonCode class. Now the latter accepts and returns JsCode objects.
-
5.0.0-1.0.dev16 Aug 2023 pre-releaseRelease notes
Open source →Completed ejson creation. Still missing tests and docs. Some base classes have been revisited, and there can be some breaking changes, this is the reason of the change in release number.
-
4.0.1-1.1.dev08 Aug 2023 pre-releaseRelease notes
Open source →- Small fixes
- EJson methods made static.
- Created eJson2doc and doc2eJson methods
-
4.0.1-1.0.dev08 Aug 2023 pre-release -
4.0.022 Feb 2023Release notes
Open source →- Breaking Change. The BsonLong class is now backed by an
Int64field.BsonLongobject returned from the server will always be returned as Int64. Int values passed to the server will be passed as int32 if below the int32 limit, otherwise as int64 objects. TheBsonObject.bsonObjectFrom()method now also acceptInt64andInt32Objects. This change was needed to avoid the limits that the int type has on the web apps. - Removed deprecated Bson types
- Removed deprecated unpack methods
- Breaking Change. The BsonLong class is now backed by an
-
3.0.105 Dec 2022Release notes
Open source →- Added
isValidHexId()to ObjectId class - Added
TryParse()to ObjectId class
- Added
-
3.0.024 Sep 2022Release notes
Open source →- Reorganization and adoption of Decimal 2.3.0 that contains potential breaking changes
-
2.0.223 Sep 2022 -
2.0.101 Sep 2022 -
2.0.0-1.0.beta25 Apr 2022 pre-releaseRelease notes
Open source →Moving to the most recent version of the
Rationalclass, a Breaking change had been introduced. We have decided to substitute theRationalclass with theDecimalone, because the latter, that it is a wrapper around the former, contains more user friendly methods. You can always get aRationalinstance, if needed, calling thetoRational()method of theDecimalclass. -
1.0.427 Oct 2021Release notes
Open source →- Switched to Lints from Pedantic
- MaxBits static variable renamed to maxBits
- RandomId static variable renamed randomId
- Fixed a bug in Timestamp class so that, unpacking a buffer, seconds and increment were inverted.
- Decoupled the original
Timestampclass into a newTimestampand a bsonDataBsonTimestamp.
-
1.0.329 Mar 2021Release notes
Open source →- Removed the wrapper class UuidValue. Now we are using the original class from the Uuid package.
-
1.0.227 Mar 2021 -
1.0.122 Mar 2021 -
1.0.022 Mar 2021Release notes
Open source →A Breaking change in relation to Uuid management. As uuid_type package wasn't yet ported to null-safety, I moved to the widely used uuid one. The name of the class is no more Uuid (in uuid package Uuid is the generator class), but UuidValue. I had to make a custom version of UuidValue because it was missing some functionalities, but I hope that the standard package will adopt this changes in a near future. This is why I left the name as UuidValue instead of the more intuitive Uuid.
-
1.0.0-nullsafety.216 Mar 2021 pre-release -
1.0.0-nullsafety15 Nov 2020 pre-releaseRelease notes
Open source →This is a preliminary port to the null-safety feature for the bson package. It is not production ready yet.
Please, report any issue you encounter if you have time to test it.
Moving to null safety has lead to consider a new approach to writing this driver. The idea came from reading the Decimal128 specs, that requires the BsonObject representing the mongoDb type, to be immutable and the language specific class used to manage the value to be different from the Bson Object. This is in contrast with the actual way the driver is written. You can see the unpack method, that changes the value of the class itself or the BsonBinary class where the byteList is continually updated when writing on it as a buffer. Nothing wrong with this, we are simply looking for a better (in terms of readability and maintainence) way of writing the classes. So, considering this, our goal is to make Bson Type classes immutable and distinct from the language type ones. In this release whe have made some changes in order to prepare for a future major change. We have not yet proceeded mainly for two reasons:
- compatibility -> triyng to minify the changes to the packages using these APIs.
- performance -> with respect to BsonBinary, the idea was to, on pack method, not to update the buffer but create and return a new one. This would work greatly, but the question is how this would impact on performances? At present I have not the time to find a better and comparably faster way of changing the buffer, so I decided to delay this development to a future moment.
More in detail, plus or minus all Bson classes have been changed, removing the empty constructor, when possible, and reducing the cases in which they can be updated after creation. The only Bson classes that have a constructor that accepts a null value are those that are capable of creating a default value (like BsonDecimal128, for instance).
I would like to point out the main changes in the following three classes that, on my opinion, could generate some incompatibility issues:
BsonObjectBsonObjecthas been made abstract. I do not expect this to be a big issue, because it was of no use to create a BsonObject directly, anyway, if there is a case that I cannot foresee, this can be a issue to be fixed.- the
bsonObjectFrommethod has been transformed into a factory constructor. - the
bsonObjectFromTypeBytemethod has been transfomed into thefromTypeByteAndBufferfactory constructor, that requires, aside of the type byte, also the buffer. - the method
elementSizehas been moved into the BsonObject class as static method. - constants have been renamed to a more "dartish" style (camelCase), but the old version is still available even if deprecated.
ObjectId- The
ObjectIdclass have benn decoupled, and a new class (BsonObjectId) have been created. - The
ObjectIdclass is no more extending theBsonObjectone. As a result the following methods/getters have been removed:typeByte(getter)value(getter)byteLength()(method)packValue()(method)unpackMethod()(method)
- The
BsonBinary- The logic behind the binary class has changed slightly. The attempt is to have always a field class representation valid and the others generated on request. I choose the byteList field to be the image of the values of this class. This means that, on creation, the byteList field is always created. The hexString and byteArray fields are generated on demand when the respective getter is called. As a result of this, there is no more need to call the
makeHexString()method or themakeByteList()ones. They are called when needed. Theese method are still available (even if deprecated), but do not update theBsonBinaryclass, they only returns the calculated value. - To prevent unmanaged changes to the value representation, the
byteList,hexStringandbyteArraysetters have been removed. - constants have been renamed to a more "dartish" style (camelCase), the old version (when the value could have been used outside the package) is still available even if deprecated.
- The logic behind the binary class has changed slightly. The attempt is to have always a field class representation valid and the others generated on request. I choose the byteList field to be the image of the values of this class. This means that, on creation, the byteList field is always created. The hexString and byteArray fields are generated on demand when the respective getter is called. As a result of this, there is no more need to call the
Aside of the null-safety changes, a new Bson type has been managed: The
UUIDone. Like theDecimal128type, it should be considered experimental. -
0.3.419 Oct 2020Release notes
Open source →- New
Decimal128Bson type. To be considered experimental. As in Dart there is not a corresponding Decimal128 type, we have used the Rational class (pub Rational), that allows to deal with rational numbers with no limits. - The minimum SDK required has been raised to 2.7.0
- New
-
0.3.304 Aug 2020Nothing published for this version
-
0.3.226 Jul 2018Nothing published for this version
-
0.3.113 May 2018Nothing published for this version
-
0.3.023 Jul 2017Nothing published for this version
-
0.2.025 Jul 2015Nothing published for this version
-
0.1.2306 Sep 2014Nothing published for this version
-
0.1.2206 Sep 2014Nothing published for this version
-
0.1.2129 Aug 2014Nothing published for this version
-
0.1.2015 Aug 2014Nothing published for this version
-
0.1.1914 Aug 2014Nothing published for this version
-
0.1.1829 Mar 2014Nothing published for this version
-
0.1.1729 Mar 2014Nothing published for this version
-
0.1.1509 Nov 2013Nothing published for this version
-
0.1.1430 Oct 2013Nothing published for this version
-
0.1.1317 Oct 2013Nothing published for this version
-
0.1.1211 Oct 2013Nothing published for this version
-
0.1.1107 Sep 2013Nothing published for this version
-
0.1.1001 Sep 2013Nothing published for this version
-
0.1.901 Sep 2013Nothing published for this version
-
0.1.801 Sep 2013Nothing published for this version
-
0.1.705 Jul 2013Nothing published for this version
-
0.1.625 Jun 2013Nothing published for this version
-
0.1.506 Jun 2013Nothing published for this version
-
0.1.403 May 2013Nothing published for this version
-
0.1.301 May 2013Nothing published for this version
-
0.1.201 May 2013Nothing published for this version
-
0.1.127 Apr 2013Nothing published for this version