Skip to content

2025

0.25.0 • BsonContext/BsonFactory split, serialization annotation support, experimental BsonPath and eager multiplatform BSON

BsonContext and BsonFactory

Breaking change

Impacted modules: :bson, :dsl

See: #95, !157

Since the start of the project, the configuration of BSON documents is stored by the BsonContext interface. However, it was starting to become too big. Initially, BsonContext was used for BSON object creation. In 0.19.0, it obtained the capability of creating ObjectId instances. In this version, it would also have obtained the configuration for serializing paths.

In this release, it is changed as follows:

  • The BsonContext is removed from :bson.
  • The new BsonFactory interface becomes responsible from creating BSON documents.
  • The capability of creating new ObjectId instances remains in ObjectIdGenerator.
  • A new BsonContext interface is created in :dsl, which aggregates the capabilities required by the DSL.

If you created custom operators, you will need to switch the imports from the old BsonContext to the new one.

Otherwise, end-users should not be impacted.

PropertyNameStrategy

Impacted modules: :dsl, :driver-sync-kmongo, :driver-coroutines-kmongo

See: #89, !151, !157

The new interface PropertyNameStrategy was added to configure how the Foo::user / User::name syntax is converted into MongoDB paths. Users can override the default implementation when initializing the KtMongo library. For example, this can be used to look up annotations on the fields to change their name.

When using one of the KMongo compatibility modules, the strategy used understands @BsonId and KotlinX.Serialization's @SerialName, as recommended by the KMongo documentation for the KotlinX.Serialization library.

If you use Jackson or want to use KotlinX.Serialization annotations with the regular driver modules (without using the KMongo compatibility modules) you can override the PropertyNameStrategy used by the driver.

We do not plan to add support for serialization annotations in the default implementation.

As a consequence, some methods have been moved from Field to FieldDsl.

BsonPath

Experimental

Impacted modules: :bson

See: #2, #93, #146

Added the experimental BsonPath interface to represent JSONPath-like accessors to BSON documents.

BsonPath is a great alternative to deserialization when we are only interested in a few fields, as it avoids the need for creating complex DTOs, especially when they are deeply nested.

val path = BsonPath.parse("$.users.1.name")

val name: String = myDocument at path

BSON

  • Removed @ExperimentalStdlibApi on the ObjectId constructor as it has been stabilized in the standard library (b9ccf073)
  • ObjectId.Serializer has been changed from a class to an object (88f6947e)
  • Timestamp.Serializer has been changed from a class to an object (88f6947e)

BSON (multiplatform)

  • Instances of .reader() are now reused. This will make access to fields faster (60397c9d)
  • Added Bson.eager() and BsonArray.eager() to eagerly initialize the readers, which makes them thread-safe. Improved the documentation on thread-safety (!167)
  • Improved the documentation of Bson and BsonArray (!167)

Dependencies

  • Kotlin 2.2.21

0.23.0 • Multiplatform KotlinX.Serialization, Field.unsafe expansion, replace and KMongo utilities

BSON (Multiplatform)

  • Multiplatform KotlinX.Serialization support (#50, !117, thanks @UnknownJoe796)

DSL

  • Added Field.unsafe() overloads to allow more use-cases (!132)
  • $concat now allows nullability, and has been moved from ArithmeticValueOperators to StringValueOperators (!134)

Drivers

  • Added replaceOne() and repsertOne() (!133)
  • Added :driver-sync-kmongo and :driver-coroutines-kmongo with a utility function to convert KMongo objects to KtMongo objects (!132)

Documentation

0.21.0 • $group and string aggregation operators

DSL

  • Projections are now represented with booleans instead of integers, for smaller request payloads (#81, !121)

Aggregation stages:

  • Added $group (!120)

Accumulation operators:

Aggregation operators:

  • Added $multiply, $divide and $subtract (!122)
  • Added $trim, $ltrim and $rtrim (!123)
  • Added $toLower and $toUpper (!123)
  • Added $substrCP, $substrBytes, $strLenCP and $strLenBytes (!123)
  • Added $split (!123)
  • Added $replaceOne and $replaceAll (!123)

Dependencies

  • KotlinX.Serialization 1.9.0
  • KotlinX.Coroutines 1.10.2
  • KotlinX.IO 0.8.0
  • MongoDB Java driver 5.5.1

0.19.0 • Pure Kotlin ObjectId and Timestamp, $switch, type aggregation operators, bitwise filter operators, writeConcern and readPreference

BSON

  • Moved ObjectId to opensavvy.ktmongo.bson.types (6e455683, !80)
  • Added ObjectIdGenerator with multiple implementations (!80)
  • Added ObjectId.MIN and ObjectId.MAX (!80)
  • Added BsonContext.newId (!80)
  • Added BsonReader.readInstant and BsonWriter.writeInstant (244237ed, !88)
  • Added opensavvy.ktmongo.bson.types.Timestamp (!89)
  • Changed timestamp APIs from Long to the new Timestamp type (!89)

BSON (official)

  • Deleted the old expect class opensavvy.ktmongo.bson.official.types.ObjectId (!80)
  • Added a codec for the new ObjectId (!80)

BSON (multiplatform)

  • Decreased data copying when reading data (417128b5, !84)
  • Removed autoboxing in the implementation of the reader (17cab93a, !84)
  • Added no-copy piping of BSON from a reader to a writer (!86)
  • Added support for reading and writing BsonType.DateTime as kotlin.time.Instant (e15001f4, !88)
  • Added support for reading and writing BsonType.RegExp (2bb5e544, !88)
  • Added support for reading and writing BsonType.Timestamp (aa3c9a9e, !89)

Official driver

  • JvmMongoCollection.find now returns a JvmMongoIterable instead of a MongoIterable (!85)

DSL

  • Added the aggregation operator $switch (!90)
  • Added the aggregation operators $type, $isArray, $isNumber, $toBoolean, $toDate, $toDouble, $toInt, $toLong, $toObjectId, $toString and $toUUID (!91)
  • Added the filter operators $bitAllClear, $bitsAllSet, $bitsAnyClear and $bitsAnySet (!92)
  • Added the option writeConcern (!93)
  • Added the option readPreference (!94)
  • Created the Command interface and reorganized all commands to emit their BSON representation (!95)

Documentation

  • Added a section on aggregation support to the KMongo migration page (#87, !103)

Dependencies

  • Kotlin 2.2.0

0.18.0 • ObjectId, range operators, $min and $max, read concern and Java usage

BSON

  • Pure Kotlin ObjectId implementation (!72)
  • Added utilities for comparing ObjectId and Instant (!72)

DSL

  • Added the isIn operator to query on ranges (!75)
  • Added the $size filter operator (659dae51, !82)
  • Added the $nor filter operator (20378994, !82)
  • Added the $min and $max update operators (b298039f, !82)
  • Added the readConcern option (0b9520aa, !83)

Synchronous driver

  • Added a new experimental module, :driver-sync-java, with utilities for using KtMongo from Java (!69)
  • Java: Added JavaField.of(Customer::name) syntax (!69)
  • Java: Added KtMongo.from() helper (!69)
  • Java: Added options(s -> s.) syntax (!69)

Dependencies