Skip to content

[Java] v5.0 Tech Review #507

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions source/includes/fundamentals/code-snippets/mcs.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ private static void createSocketSettings() {
MongoClient mongoClient = MongoClients.create(
MongoClientSettings.builder().applyConnectionString(new ConnectionString("<your connection string>"))
.applyToSocketSettings(builder ->
builder.connectTimeout(10L, SECONDS)
.readTimeout(15L, SECONDS))
builder.connectTimeout(10, SECONDS)
.readTimeout(15, SECONDS))
.build());
//end SocketSettings
mongoClient.listDatabaseNames().forEach(n -> System.out.println(n));
Expand Down
52 changes: 44 additions & 8 deletions source/upgrade.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ Version 5.0 Breaking Changes
``long`` instead of type ``int``. Because this change breaks both binary and source
compatibility, update any source code that uses these methods and rebuild your binary.

- This driver version removes the following record annotations:
- The following record annotations from the
``org.bson.codecs.record.annotations`` package are replaced with
annotations of the same name from the ``org.bson.codecs.pojo.annotations`` package:

- ``BsonId``
- ``BsonProperty``
Expand All @@ -90,32 +92,66 @@ Version 5.0 Breaking Changes
- ``readTimeout()``

In earlier versions, this parameter is of type ``int`` for both methods. To view an example
that shows how to instantiate a ``SocketSettings`` instance by using
these methods, see the :ref:`SocketSettings Example
that shows how to call ``SocketSettings`` methods, see the :ref:`SocketSettings Example
<java-socketsettings-example>` in the Specify MongoClient Settings
guide.

- This driver version removes the ``Filters.eqFull()`` method, which allowed you
This change breaks binary compatibility (requires recompiling) but does not
require code changes.

- This driver version removes the ``Filters.eqFull()`` method, released
exclusively in ``Beta``, which allowed you
to construct an equality filter when performing a vector search.
You can use the ``Filters.eq()`` method when instantiating a
``VectorSearchOptions`` type, as shown in the following code:

.. code-block:: java
VectorSearchOptions opts = vectorSearchOptions().filter(eq("x", 8));

VectorSearchOptions opts = vectorSearchOptions().filter(eq("x", 8));

.. _java-breaking-changes-v5.0-observables:

- This driver version removes the
``org.mongodb.scala.ObservableImplicits.ToSingleObservableVoid`` implicit
class. This means the ``org.reactivestreams.Publisher[Void]`` type no longer
converts automatically to ``org.mongodb.scala.SingleObservable[Void]``. The also
API exposes ``org.mongodb.scala.Observable[Unit]`` instead of
converts automatically to ``org.mongodb.scala.SingleObservable[Void]``. The
API also exposes ``org.mongodb.scala.Observable[Unit]`` instead of
``org.mongodb.scala.Observable[Void]``.

.. After the 5.0 Scala API docs are released, this line will be uncommented.
For more information, see the `Observable trait documentation <https://mongodb.github.io/mongo-java-driver/5.0/apidocs/mongo-scala-driver/org/mongodb/scala/Observable.html>`__.

- This driver changes how ``ClusterSettings`` computes
``ClusterConnectionMode``, making it more consistent by using the specified
replica set name, regardless of how it is configured. Previously, replica set
name was only considered if it was set by the connection string.

For example, the following two code samples both return the value
``ClusterConnectionMode.MULTIPLE``, while previously the second one returned
``ClusterConnectionMode.SINGLE``.

.. code-block:: java

ClusterSettings.builder()
.applyConnectionString(new ConnectionString("mongodb://127.0.0.1:27017/?replicaSet=replset"))
.build()
.getMode()

.. code-block:: java

ClusterSettings.builder()
.hosts(Collections.singletonList(
new ServerAddress("127.0.0.1", 27017)
))
.requiredReplicaSetName("replset")
.build()
.getMode()

- This driver changes how ``BsonDecimal128`` values respond to method calls, by
responding in the same way as ``Decimal128`` values. In particular,
``BsonDecimal128.isNumber()`` now returns ``true``, and
``BsonDecimal128.asNumber()`` returns the equivalent ``BsonNumber``.

.. _java-breaking-changes-v4.8:

Version 4.8 Breaking Changes
Expand Down
17 changes: 3 additions & 14 deletions source/whats-new.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,12 @@ What's New in 5.0

.. warning:: Breaking Changes in v5.0

This driver version introduces breaking changes. For a list of these changes, see
the :ref:`Version 5.0 Breaking Changes section <java-breaking-changes-v5.0>` in the
Upgrade guide.
This driver version introduces breaking changes. For a list of these changes, see
the :ref:`Version 5.0 Breaking Changes section <java-breaking-changes-v5.0>` in the
Upgrade guide.

The 5.0 driver release introduces the following features:

- Consistent computation of the ``ClusterConnectionMode`` type after
instantiating a ``ClusterSettings``. The connection mode defaults to
``SINGLE`` if you specify one host and do not specify a replica set
name, or it defaults to ``MULTIPLE`` if you specify more than one
host.

- ``BsonDecimal128`` values respond to method calls in the same way as Java
``Decimal128`` values. In particular, the error responses for the
``isNumber()`` and ``asNumber()`` methods match the Java responses for
equivalent ``Decimal128`` values.

- The ``getElapsedTime()`` method on ``com.mongodb.event.ConnectionReadyEvent``
includes the time taken to deliver the ``ConnectionCreatedEvent``. That is,
the time returned includes the duration of the
Expand Down