What's New
On this page
Learn what's new in:
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
getStats()
andisCapped()
instance methods of theDBCollection
class are deprecated. The corresponding server commands are deprecated in MongoDB v6.2 and later. Use the$collStats
aggregation pipeline stage to retrieve the information provided by these methods instead. You can run the aggregation as shown in the following code example:Cursor cursor = collection.aggregate(Arrays.asList( new BasicDBObject("$collStats", new BasicDBObject("storageStats", new BasicDBObject()))), AggregationOptions.builder().build() ); To determine whether a collection is a capped collection, access the value of the
storageStats.capped
field returned byCursor
instance in the preceding example aggregation.To learn more about the
$collStats
aggregation operator, see the $collStats (aggregation) Server manual entry.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. To learn more see Connect to MongoDB by Using a SOCKS5 Proxy.
Fixed an issue related to how domain names are validated when you use proxy functionality, allowing you to use domain names with more than six characters in the top-level domain.
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. To learn more, see Split Large Change Stream Events.Added an aggregation stage builder for
$vectorSearch
. To learn more, see Atlas Vector Search.Added Atlas Search index management helpers. To learn more, see Atlas Search Indexes.
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
New features of the 4.10 driver release include:
Implementation of the
Accumulators.percentile()
andAccumulators.median()
methods for statistical aggregations.Interfaces in the
com.mongodb.client.model.search
package are now marked as@Sealed
instead of@Evolving
. Sealed interfaces must not be extended or implemented by consumers of the library.Resolved an issue where the driver emitted duplicate log messages for retry operations. The driver now correctly emits one log message for each retry operation.
The
org.bson.codecs.Parameterizable
interface is deprecated. Instead of implementing this interface on a customCodec
type, override theCodecProvider.get()
method on the codec'sCodecProvider
if the codec is intended for a parameterized type.Support for custom DNS resolvers.
Support for Queryable Encryption (QE). To learn more about the requirements for using the QE feature, see the Queryable Encryption Driver Compatibility Table.