@@ -55,7 +55,7 @@ Atlas </getting-started>` guide.
55
55
The documents in these collections are modeled by the following
56
56
{+language+} data classes:
57
57
58
- .. literalinclude:: /includes/write/bulk.kt
58
+ .. literalinclude:: /includes/write/client- bulk-write .kt
59
59
:start-after: start-data-classes
60
60
:end-before: end-data-classes
61
61
:language: kotlin
@@ -138,7 +138,7 @@ The following example creates an instance of ``UpdateOneModel``:
138
138
If multiple documents match the query filter specified in
139
139
the ``UpdateOneModel`` instance, the operation updates the first
140
140
result. You can specify a sort in an ``UpdateOptions`` instance to apply
141
- an order to matched documents before the driver performs the update
141
+ an order to matched documents before the server performs the update
142
142
operation, as shown in the following code:
143
143
144
144
.. code-block:: kotlin
@@ -181,7 +181,7 @@ The following example creates an instance of ``ReplaceOneModel``:
181
181
If multiple documents match the query filter specified in
182
182
the ``ReplaceOneModel`` instance, the operation replaces the first
183
183
result. You can specify a sort in a ``ReplaceOptions`` instance to apply
184
- an order to matched documents before the driver performs the replace
184
+ an order to matched documents before the server performs the replace
185
185
operation, as shown in the following code:
186
186
187
187
.. code-block:: kotlin
@@ -467,8 +467,8 @@ Insert Operations
467
467
~~~~~~~~~~~~~~~~~
468
468
469
469
This example shows how to create models that contain instructions to
470
- insert two documents. One document is inserted into the ``db.people ``
471
- collection, and the other document is inserted into the ``db.things `` collection.
470
+ insert two documents. One document is inserted into the ``sample_restaurants.restaurants ``
471
+ collection, and the other document is inserted into the ``sample_mflix.movies `` collection.
472
472
The ``MongoNamespace`` instance defines the target database and collection that
473
473
each write operation applies to.
474
474
@@ -479,11 +479,49 @@ each write operation applies to.
479
479
:copyable:
480
480
:dedent:
481
481
482
+ .. _kotlin-sync-client-bulk-write-update:
483
+
484
+ Update Operation
485
+ ~~~~~~~~~~~~~~~~
486
+
487
+ The following example shows how to use the ``bulkWrite()`` method to update
488
+ existing documents in the ``sample_restaurants.restaurants`` and
489
+ ``sample_mflix.movies`` collections:
490
+
491
+ .. literalinclude:: /includes/write/client-bulk-write.kt
492
+ :start-after: start-update-models
493
+ :end-before: end-update-models
494
+ :language: kotlin
495
+ :copyable:
496
+ :dedent:
497
+
498
+ This example increments the value of the ``stars`` field by ``1`` in the
499
+ document that has a ``name`` value of ``"Villa Berulia"`` in the
500
+ ``restaurants`` collection. It also sets the value of the ``seen`` field
501
+ to ``true`` in all documents that have a ``title`` value of ``"Carrie"``
502
+ in the ``movies`` collection.
503
+
504
+ If multiple documents match the query filter specified in
505
+ a ``ClientNamespacedUpdateOneModel`` instance, the operation updates the
506
+ first result. You can specify a sort order in a `ClientUpdateOneOptions
507
+ <{+core-api+}/com/mongodb/client/model/bulk/ClientUpdateOneOptions.html>`__
508
+ instance to apply an order to matched documents before the server
509
+ performs the update operation, as shown in the following code:
510
+
511
+ .. code-block:: kotlin
512
+
513
+ val options = ClientUpdateOneOptions
514
+ .clientUpdateOneOptions()
515
+ .sort(Sorts.ascending("_id"))
516
+
517
+ .. _kotlin-sync-client-bulk-write-replace:
518
+
482
519
Replace Operations
483
520
~~~~~~~~~~~~~~~~~~
484
521
485
522
The following example shows how to create models to replace
486
- existing documents in the ``db.people`` and ``db.things`` collections:
523
+ existing documents in the ``sample_restaurants.restaurants`` and
524
+ ``sample_mflix.movies`` collections:
487
525
488
526
.. literalinclude:: /includes/write/client-bulk-write.kt
489
527
:start-after: start-replace-models
@@ -493,9 +531,22 @@ existing documents in the ``db.people`` and ``db.things`` collections:
493
531
:dedent:
494
532
495
533
After this example runs successfully, the document that has an ``_id`` value of ``1``
496
- in the ``people`` collection is replaced with a new document. The document in
497
- the ``things`` collection that has an ``_id`` value of ``1``
498
- is replaced with a new document.
534
+ in the ``restaurants`` collection is replaced with a new document. The document in
535
+ the ``movies`` collection that has an ``_id`` value of ``1``
536
+ is also replaced with a new document.
537
+
538
+ If multiple documents match the query filter specified in
539
+ a ``ClientNamespacedReplaceOneModel`` instance, the operation replaces the
540
+ first result. You can specify a sort order in a `ClientReplaceOneOptions
541
+ <{+core-api+}/com/mongodb/client/model/bulk/ClientReplaceOneOptions.html>`__
542
+ instance to apply an order to matched documents before the driver
543
+ performs the replace operation, as shown in the following code:
544
+
545
+ .. code-block:: kotlin
546
+
547
+ val options = ClientReplaceOneOptions
548
+ .clientReplaceOneOptions()
549
+ .sort(Sorts.ascending("_id"))
499
550
500
551
Perform the Bulk Operation
501
552
~~~~~~~~~~~~~~~~~~~~~~~~~~
0 commit comments