Skip to content

Commit 64bea27

Browse files
authored
DOCSP-46772: sort option for client bw - updateone & replaceone (#113)
1 parent a6b6dd2 commit 64bea27

File tree

3 files changed

+87
-3
lines changed

3 files changed

+87
-3
lines changed

source/includes/write/client-bulk-write.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,22 @@ public static void main(String[] args) {
3939
);
4040
// end-insert-models
4141

42+
// start-update-models
43+
ClientNamespacedUpdateOneModel personUpdate = ClientNamespacedWriteModel
44+
.updateOne(
45+
new MongoNamespace("db", "people"),
46+
Filters.eq("name", "Freya Polk"),
47+
Updates.inc("age", 1)
48+
);
49+
50+
ClientNamespacedUpdateManyModel thingUpdate = ClientNamespacedWriteModel
51+
.updateMany(
52+
new MongoNamespace("db", "things"),
53+
Filters.eq("category", "electronic"),
54+
Updates.set("manufacturer", "Premium Technologies")
55+
);
56+
// end-update-models
57+
4258
// start-replace-models
4359
ClientNamespacedReplaceOneModel personReplacement = ClientNamespacedWriteModel
4460
.replaceOne(

source/whats-new.txt

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,30 @@ What's New
2020
Learn about new features, improvements, and fixes introduced in the
2121
following versions of the {+driver-long+}:
2222

23+
* :ref:`Version 5.4 <javars-version-5.4>`
2324
* :ref:`Version 5.3 <javars-version-5.3>`
2425
* :ref:`Version 5.2 <javars-version-5.2>`
2526
* :ref:`Version 5.1.3 <javars-version-5.1.3>`
2627
* :ref:`Version 5.1.2 <javars-version-5.1.2>`
2728
* :ref:`Version 5.1.1 <javars-version-5.1.1>`
2829
* :ref:`Version 5.1 <javars-version-5.1>`
2930

31+
.. _javars-version-5.4:
32+
33+
What's New in 5.4
34+
-----------------
35+
36+
The 5.4 driver release includes the following changes, fixes,
37+
and features:
38+
39+
.. sharedinclude:: dbx/jvm/v5.4-wn-items.rst
40+
41+
.. replacement:: sort-option-link
42+
43+
the :ref:`java-rs-client-bulk-write-update` and
44+
:ref:`java-rs-client-bulk-write-replace` sections of the Bulk
45+
Write Operations guide
46+
3047
.. _javars-version-5.3:
3148

3249
What's New in 5.3
@@ -125,4 +142,5 @@ What's New in 5.1
125142
release and will be removed in the v5.2 release of the driver.
126143

127144
To learn about other changes introduced in v5.1, see the :driver:`What's
128-
New </java/sync/current/whats-new/>` guide in the Java Sync Driver documentation.
145+
New </java/sync/current/whats-new/>` guide in the Java Sync Driver
146+
documentation.

source/write/bulk-writes.txt

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ The following example creates an instance of ``UpdateOneModel``:
116116
If multiple documents match the query filter specified in
117117
the ``UpdateOneModel`` instance, the operation updates the first
118118
result. You can specify a sort in an ``UpdateOptions`` instance to apply
119-
an order to matched documents before the driver performs the update
119+
an order to matched documents before the server performs the update
120120
operation, as shown in the following code:
121121

122122
.. code-block:: java
@@ -156,7 +156,7 @@ The following example creates an instance of ``ReplaceOneModel``:
156156
If multiple documents match the query filter specified in
157157
the ``ReplaceOneModel`` instance, the operation replaces the first
158158
result. You can specify a sort in a ``ReplaceOptions`` instance to apply
159-
an order to matched documents before the driver performs the replace
159+
an order to matched documents before the server performs the replace
160160
operation, as shown in the following code:
161161

162162
.. code-block:: java
@@ -428,6 +428,43 @@ each write operation applies to.
428428
:copyable:
429429
:dedent:
430430

431+
.. _java-rs-client-bulk-write-update:
432+
433+
Update Operations
434+
~~~~~~~~~~~~~~~~~
435+
436+
The following example shows how to use the ``bulkWrite()`` method to update
437+
existing documents in the ``db.people`` and
438+
``db.things`` collections:
439+
440+
.. literalinclude:: /includes/write/client-bulk-write.java
441+
:start-after: start-update-models
442+
:end-before: end-update-models
443+
:language: java
444+
:copyable:
445+
:dedent:
446+
447+
This example increments the value of the ``age`` field by ``1`` in the
448+
document that has a ``name`` value of ``"Freya Polk"`` in the ``people``
449+
collection. It also sets the value of the ``manufacturer`` field to
450+
``"Premium Technologies"`` in all documents that have a ``category``
451+
value of ``"electronic"`` in the ``things`` collection.
452+
453+
If multiple documents match the query filter specified in
454+
a ``ClientNamespacedUpdateOneModel`` instance, the operation updates the
455+
first result. You can specify a sort order in a `ClientUpdateOneOptions
456+
<{+core-api+}/client/model/bulk/ClientUpdateOneOptions.html>`__
457+
instance to apply an order to matched documents before the server
458+
performs the update operation, as shown in the following code:
459+
460+
.. code-block:: java
461+
462+
ClientUpdateOneOptions options = ClientUpdateOneOptions
463+
.clientUpdateOneOptions()
464+
.sort(Sorts.ascending("_id"));
465+
466+
.. _java-rs-client-bulk-write-replace:
467+
431468
Replace Operations
432469
~~~~~~~~~~~~~~~~~~
433470

@@ -446,6 +483,19 @@ in the ``people`` collection is replaced with a new document. The document in
446483
the ``things`` collection that has an ``_id`` value of ``1``
447484
is replaced with a new document.
448485

486+
If multiple documents match the query filter specified in
487+
a ``ClientNamespacedReplaceOneModel`` instance, the operation replaces the
488+
first result. You can specify a sort order in a `ClientReplaceOneOptions
489+
<{+core-api+}/client/model/bulk/ClientReplaceOneOptions.html>`__
490+
instance to apply an order to matched documents before the server
491+
performs the replace operation, as shown in the following code:
492+
493+
.. code-block:: java
494+
495+
ClientReplaceOneOptions options = ClientReplaceOneOptions
496+
.clientReplaceOneOptions()
497+
.sort(Sorts.ascending("_id"));
498+
449499
Perform the Bulk Operation
450500
~~~~~~~~~~~~~~~~~~~~~~~~~~
451501

0 commit comments

Comments
 (0)