0.30.0 • BSON refactor, type-aware operators and Multiplatform progress
This is KtMongo's greatest release yet. It contains multiple breaking changes, though they should not impact users in major ways.
The BSON refactor
With the growth of the library, we have noticed that the design of the BSON classes was suboptimal.
Bsonhas been renamed toBsonDocumentBsonValuehas been createdBsonDocumentReaderhas been removed (its functionality is now included directly inBsonDocument)BsonArrayReaderhas been removed (its functionality is now included directly inBsonArray)BsonValueReaderhas been removed (its functionality is now included directly inBsonValue)- All reading methods have been renamed to
encodevariants - The API to access data from
BsonDocument,BsonArrayandBsonValuehas been rewritten, with conversion functions toMap,List,IterableandSequence - All implementations now throw the same
BsonDecodingExceptionon failure - We now test KtMongo against both the official's reflection-based and KotlinX.Serialization-based libraries
BsonDocument,BsonArrayandBsonValuehas afactoryproperty to access the factory which created them (0fb55a77)- The types
BsonDocument,BsonArrayandBsonValuecan now be serialized and deserialized, which is convenient for handling dynamic or untyped data (!238)
Related changes in the official BSON implementation:
BsonFactoryis changed from aninterfaceto anexpect class- Kotlin primitive types can now be serialized and deserialized without additional configuration (60a016ae)
For more information, see #112 and !223.
The operators refactor
The KtMongo DSL now has a templating engine, which allows generating convenience overloads for most operators. In most situations, aggregation queries don't need the of() operator anymore.
Before:
After:
All operators now have an additional overload that accepts KType as a last parameter.
These overloads are not meant to be called directly by users, you should almost always call the overload that doesn't have a KType parameter.
Operators are now inline reified, which allows the serialization library to know about type parameters (which were previously stripped during compilation).
This information is not yet used in all situations.
Additionally:
- The syntax of the
switchconditional aggregation operator has changed: the value is now defined withtheninstead ofto - The
addToSetoverload that accepts a list has been renamed toaddEachToSet - Added
Field.unsafeCast<T>()(7a5170bd) - Added the
$pushupdate operator with its different options (!236)
Route to Multiplatform
- The entire DSL can now compile and run on KotlinJS in addition to the JVM (!239). More platforms are coming in the future.
- The repository now contains a prototype Multiplatform driver (!240).
GeoJSON
- Added the seven GeoJSON data types under the
Geointerface (#76, !241) - For now, no operators use them. However, they are serializable.
Deployment
- Apple x64 targets have been removed, because they are deprecated
Documentation
- The tutorial pages now link directly to the API reference (624fb8c4)
- Reworked the Getting Started page to mention the different KtMongo flavors (806fc7ed)
- Added detailed pages on KotlinX.Serialization, Reflection and custom serialization strategies.
- Java driver: fixed missing pages and incorrect examples (abfb3301, 6317e9ef)