You are currently viewing an older version of the Java driver documentation.
For the most recent version of the reference documentation, see our MongoDB Java Driver documentation site.
  • What's New

What’s New in 3.5

Key new features of the 3.5 Java driver release:

Native POJO support

The 3.5 release adds support for POJO serialization at the BSON layer, and can be used by the synchronous and asynchronous drivers. See the POJO Quick start pages for details.

Improved JSON support

The 3.5 release improves support for JSON parsing and generation.

  • Implements the new Extended JSON specification
  • Implements custom JSON converters to give applications full control over JSON generation for each BSON type

See the JSON reference for details.

Connection pool monitoring

The 3.5 release adds support for monitoring connection pool-related events.

SSLContext configuration

The 3.5 release supports overriding the default used for SSL connections to MongoDB.

KeepAlive configuration deprecated

The 3.5 release deprecated socket keep-alive settings, also socket keep-alive checks are now on by default. It is strongly recommended that system keep-alive settings should be configured with shorter timeouts.

See the ‘does TCP keep-alive time affect MongoDB deployments?’ documentation for more information.

What’s New in 3.4

The 3.4 release includes full support for the MongoDB 3.4 server release. Key new features include:

Support for Decimal128 Format

import org.bson.types.Decimal128;

The Decimal128 format supports numbers with up to 34 decimal digits (i.e. significant digits) and an exponent range of −6143 to +6144.

To create a Decimal128 number, you can use

Support for Collation

import com.mongodb.client.model.Collation;

Collation allows users to specify language-specific rules for string comparison. Use the Collation.builder() to create the Collation object. For example, the following example creates a Collation object with Primary level of comparison and locale fr.


You can specify collation at the collection level, at an index level, or at a collation-supported operation level:

Collection Level

To specify collation at the collection level, pass a Collation object as an option to the createCollection() method. To specify options to the createCollection method, use the CreateCollectionOptions class.

database.createCollection("myColl", new CreateCollectionOptions().collation(

Index Level

To specify collation for an index, pass a Collation object as an option to the createIndex() method. To specify index options, use the IndexOptions class.

IndexOptions collationIndexOptions = new IndexOptions().name("collation-fr")

        Indexes.ascending("name"), collationIndexOptions);

Operation Level

The following operations support collation by specifying the Collation object to their respective Iterable object.

  • MongoCollection.aggregate()

  • MongoCollection.distinct()

  • MongoCollection.find()

  • MongoCollection.mapReduce()

For example:

Collation collation = Collation.builder()

collection.find(Filters.eq("category", "cafe")).collation(collation);

               "$category", Accumulators.sum("count", 1))))

The following operations support collation by specifying the Collation object as an option using the corresponding option class for the method:

  • MongoCollection.count()
  • MongoCollection.deleteOne()
  • MongoCollection.deleteMany()
  • MongoCollection.findOneAndDelete()
  • MongoCollection.findOneAndReplace()
  • MongoCollection.findOneAndUpdate()
  • MongoCollection.updateOne()
  • MongoCollection.updateMany()
  • MongoCollection.bulkWrite() for:

    • DeleteManyModel and DeleteOneModel using DeleteOptions to specify the collation
    • ReplaceOneModel, UpdateManyModel, and UpdateOneModel using UpdateOptions to specify the collation.

For example:

Collation collation = Collation.builder()

collection.count(Filters.eq("category", "cafe"), new CountOptions().collation(collation));

collection.updateOne(Filters.eq("category", "cafe"), set("stars", 1), 
                     new UpdateOptions().collation(collation));

                new UpdateOneModel<>(new Document("category", "cafe"),
                                     new Document("$set", new Document("x", 0)), 
                                     new UpdateOptions().collation(collation)),
                new DeleteOneModel<>(new Document("category", "cafe"), 
                                     new DeleteOptions().collation(collation))));

For more information on collation, including the supported locales, refer to the manual.

Other MongoDB 3.4 features

Support for JNDI

The synchronous driver now includes a JNDI ObjectFactory implementation.


See the upgrading guide on how to upgrade to 3.5.