What's New
On this page
Learn what's new in:
What's New in 5.2
Important
Removal of Support for MongoDB server 3.6
Kotlin driver v5.2 removes support for MongoDB server 3.6. To learn more about compatible versions of the server, see Compatibility.
The 5.2 driver release includes the following new features, improvements, and fixes:
Adds the
SearchIndexType
class, which you can pass when constructing aSearchIndexModel
instance. This change allows you to specify the index type when creating an Atlas Search or Vector Search index. To learn more, see Atlas Search and Vector Search Indexes in the Indexes guide.Delegates the implementation of the algorithms that implement the
SCRAM-SHA-1
andSCRAM-SHA-256
authentication mechanisms to the configured JCA provider. This change means that your application can use a configured FIPS-compliant JCA provider to provide a higher level of security.Revises the mongodb-crypt dependency versioning to match the versioning for the JVM drivers. Future versions of
mongodb-crypt
will be released alongside the driver and will share the same version number. You must upgrade yourmongodb-crypt
dependency to v5.2.0 when upgrading your driver for this release. To learn more, see the In-Use Encryption guide.Performance improvements due to implementation of native cryptography on all supported platforms. The following list describes the actions needed to implement this improvement depending on your operating system:
Windows: Upgrade your
mongodb-crypt
version to v5.2.0.Mac: Upgrade your
mongodb-crypt
version to v5.2.0.Linux: Install
libmongocrypt.so
directly on the file system, instead of using the file that is bundled within themongodb-crypt
JAR file. You can find Linux instructions to installlibmongocrypt
in the Server manual. If you use a package manager to installlibmongocrypt
, Java Native Access (JNA) will find it there without further configuration. Alternatively, you can specify the search path by setting theLD_LIBRARY_PATH
environment variable to the file path of thelibmongocrypt
package.We recommend direct installation because the bundled shared library does not link with OpenSSL due to the potential for OpenSSL binary incompatibilities.
The shared library loading is handled by JNA. You can view the rules for library loading search path order in the NativeLibrary class documentation.
Fixes an issue that caused the
InsertOneResult.getInsertedId()
andInsertManyResult.getInsertedIds()
methods to return incorrect document IDs in some situations. This change is backported to Kotlin driver v5.1.4 and v4.11.4.When a sharded cluster operation is unsuccessful, the driver avoids selecting the same
mongos
server for operation retry attempts if othermongos
servers are available.Adds reachability metadata needed when your application uses GraalVM Native Image. This metadata replaces the need for collecting reachability metadata when using the driver libraries. To learn more, see Reachability Metadata in the GraalVM documentation.
This change does not add the
libjnidispatch
andlibmongocrypt
resource entries, because adding entries for all supported platforms (targets) significantly affects the size of native executables built using GraalVM Native Image. View this sample resource-config.json file in the driver GitHub repository to see how to specify these entries explicitly if your application depends on theorg.mongodb:mongodb-crypt
library.Enables exact vector search by extending the
VectorSearchOptions
API to introduce the following specific option subtypes:ExactVectorSearchOptions
: Use this options type to enable precise matching, ensuring that results are the closest vectors to a given query vector.ApproximateVectorSearchOptions
: Use this options type to enable searches that might not return the exact closest vectors. You can pass anumCandidates
parameter when instantiating this type to specify the number of nearest neighbors to consider.
To learn more about using the Atlas Vector Search feature, see Atlas Vector Search in the Aggregates Builders guide.
Adds support for serializers from the
kotlinx-datetime
library that let you map Kotlin date and time types to BSON as the expected types instead of as strings. To learn more, see the Serialize Dates and Times section of the Kotlin Serialization guide.Supports serialization of JsonElement values. To work with the
JsonElement
type, you must add thekotlinx-serialization-json
library as a dependency in your application.
What's New in 5.1.3
The 5.1.3 driver patch release includes the following changes:
Fixes an issue that could cause assertion errors when using
Cursor
types.
What's New in 5.1.2
The 5.1.2 driver patch release includes the following changes:
Support for encoding Kotlin data classes with nullable generic parameter types. For example, you can encode the
Container
class in the following code:data class Box<T>( val boxed: T ) data class Container( val box: Box<String?> )
What's New in 5.1.1
The 5.1.1 driver patch release includes the following changes:
When using the
MONGODB-OIDC
authentication mechanism, you must not include comma characters in theauthMechanismProperties
connection string value. To learn more about this behavior, see the MONGODB-OIDC section of the Enterprise Authentication guide.
What's New in 5.1
Warning
Deprecations in this release
To avoid breaking changes in future major releases of the driver, replace any application code that depends on deprecated program elements.
This section includes the following information:
Deprecations in 5.1
Support for MongoDB server v3.6 is deprecated and will be removed in the next driver version release. To learn how to upgrade your MongoDB server deployment, see Release Notes in the MongoDB server manual.
Improvements in 5.1
Internal testing of GraalVM native image technology. These tests involve building native applications by using the GraalVM native-image tool.
Enhanced support for the
MONGODB-OIDC
authentication mechanism. To learn more about OIDC, see the MONGODB-OIDC section of the Enterprise Authentication Mechanisms guide.Fixes an issue in which operations used the incorrect codec when using a polymorphic
MongoCollection
instance. This ensures that discriminator information is not lost when usingbson-kotlinx
.Fixes an issue in which the class discriminator was the first field when decoding, resulting in field type errors when using a polymorphic
MongoCollection
instance.
New Features in 5.1
Support for polymorphic serialization. To learn more, see the Polymorphic Serialization section of the Kotlin Serialization guide.
Introduces the
serverMonitoringMode
connection URI option. To learn more, see the Connection Options guide.
What's New in 5.0
New features of the 5.0 driver release include:
The
KotlinSerializerCodecProvider
constructor now acceptsserializersModule
andbsonConfiguration
objects:KotlinSerializerCodec.create(clazz.kotlin, serializersModule=serializersModule, bsonConfiguration=bsonConfiguration) This makes it easier to customize your configuration.
Fixes a Kotlin reflection bug that resulted in container type erasure.
What's New in 4.11
This section includes the following information:
Deprecations in 4.11
Warning
Deprecations in this release
To avoid breaking changes in future major releases of the driver, replace any application code that depends on deprecated methods and types.
The 4.11 driver release deprecates the following items:
The following network address-related methods are deprecated and will be removed in v5.0:
The ServerAddress methods
getSocketAddress()
andgetSocketAddresses()
.Instead of
getSocketAddress()
, use thegetByName()
instance method ofjava.net.InetAddress
.Instead of
getSocketAddresses()
, use thegetAllByName()
instance method ofjava.net.InetAddress
.The UnixServerAddress method
getUnixSocketAddress()
.Instead of
getUnixSocketAddress()
, construct an instance ofjnr.unixsocket.UnixSocketAddress
. Pass the full path of the UNIX socket file to the constructor. By default, MongoDB creates a UNIX socket file located at"/tmp/mongodb-27017.sock"
. To learn more about theUnixSocketAddress
, see the UnixSocketAddress API documentation.
The following methods and types related to the StreamFactory interface are deprecated and scheduled for removal in v5.0:
streamFactoryFactory()
method fromMongoClientSettings.Builder
getStreamFactoryFactory()
method fromMongoClientSettings
NettyStreamFactoryFactory
classNettyStreamFactory
classAsynchronousSocketChannelStreamFactory
classAsynchronousSocketChannelStreamFactoryFactory
classBufferProvider
classSocketStreamFactory
classStream
classStreamFactory
classStreamFactoryFactory
classTlsChannelStreamFactoryFactory
class
If you configure Netty by using
MongoClientSettings.Builder.streamFactoryFactory()
, your code might resemble the following:import com.mongodb.connection.netty.NettyStreamFactoryFactory; // ... MongoClientSettings settings = MongoClientSettings.builder() .streamFactoryFactory(NettyStreamFactoryFactory.builder().build()) .build(); Replace this code with the TransportSettings.nettyBuilder() as shown in the following example:
import com.mongodb.connection.TransportSettings; // ... MongoClientSettings settings = MongoClientSettings.builder() .transportSettings(TransportSettings.nettyBuilder().build()) .build();
New Features in 4.11
New features of the 4.11 driver release include:
Support for connecting to MongoDB by using a SOCKS5 proxy.
Added the
getSplitEvent()
method to theChangeStreamDocument
class to identify fragments of a change stream event that exceeds 16MB. You must use the aggregation stage$changeStreamSplitLargeEvent
in your change stream to handle events that exceed 16MB.Added an aggregation stage builder for
$vectorSearch
.Added Atlas Search index management helpers.
Updated Snappy and Zstd compression library dependency versions. To learn more about the current dependency versions, see Network Compression.
Added
getElapsedTime()
methods to the following classes to monitor the duration of connection pool events:Support for Java 21 virtual threads and structured concurrency. The driver internals were updated to avoid unnecessary pinning of virtual threads and to preserve interrupted status of a thread, as the latter matters for structured concurrency where it is used for cancellation.
To learn more about virtual threads, see the Virtual Threads JDK enhancement proposal. To learn more about structured concurrency, see the Structured Concurrency JDK enhancement proposal.
Updated API documentation for the following types:
What's New in 4.10
Important
Starting in version 4.10.1 of the Kotlin driver, you must add
the bson-kotlinx
library as an explicit dependency to use the
kotlinx-serialization
library.
Support for Kotlin server-side usage, both for coroutines and for synchronous applications.
Codec support for Kotlin data classes.
Support for the
kotlinx.serialization
library