Skip to content

Commit 02b1720

Browse files
committed
feedback
1 parent d9a33d9 commit 02b1720

File tree

1 file changed

+26
-13
lines changed
  • source/fundamentals/crud/write-operations

1 file changed

+26
-13
lines changed

source/fundamentals/crud/write-operations/bulk.txt

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ Bulk Operations
1010
:depth: 2
1111
:class: singlecol
1212

13+
.. meta::
14+
:keywords: insert, update, replace, code example, efficiency
15+
1316
Overview
1417
--------
1518

@@ -19,28 +22,37 @@ MongoDB Java Driver.
1922
To perform a single create, replace, update, or delete operation, you can use
2023
the corresponding method. For example, to insert one document and replace one
2124
document, you can use the ``insertOne()`` and ``replaceOne()`` methods. In this
22-
case, the ``MongoClient`` makes a call to the database for each operation. However,
23-
by using bulk write operations, you can reduce the number of calls.
25+
case, the ``MongoClient`` makes a call to the database for each operation.
2426

25-
You can perform bulk write operations by using the bulk write API in the
26-
{+driver-short+} to define multiple data changes in one method call. You can
27-
perform bulk operations at the following levels:
27+
Generally, you can reduce the number of calls to the database by using bulk write
28+
operations. You can perform bulk write operations at the following levels:
2829

2930
- :ref:`Collection Level <java-sync-coll-bulk-write>`: You can use the
3031
``MongoCollection.bulkWrite()`` method to perform bulk write operations on a
31-
single collection.
32+
single collection. This method groups write operations together by the kind
33+
of operation. For example, ``MongoCollection.bulkWrite()`` puts multiple insert
34+
operations, including ``insertOne()`` and ``insertMany()``, in the same call,
35+
but will make two calls to the database for an insert operation and a replace
36+
operation.
3237

3338
- :ref:`Client Level <java-sync-client-bulk-write>`: When running {+mdb-server+}
3439
version 8.0 or later, you can use the ``MongoClient.bulkWrite()`` method to perform
3540
bulk write operations on multiple collections and databases in the same cluster.
41+
This method groups multiple kinds of write operations into one call.
3642

3743
.. _java-sync-coll-bulk-write:
3844

3945
Collection Bulk Write
4046
---------------------
4147

42-
Bulk operations consist of a large number of write operations. To perform
43-
a bulk operation at the collection level, pass a ``List`` of ``WriteModel``
48+
Bulk operations consist of a large number of write operations. The
49+
``MongoCollection.bulkWrite()`` method splits operations of different kinds into
50+
different batches. For example, when the method is passed an ``insertOne()``,
51+
``insertMany()``, and ``replaceOne()`` operation, it will split the insert operations
52+
into one batch and the replace operation into another. During this process,
53+
the client may reorder operations for efficiency.
54+
55+
To perform a bulk operation at the collection level, pass a ``List`` of ``WriteModel``
4456
documents to the ``MongoCollection.bulkWrite()`` method. A ``WriteModel`` is a model that
4557
represents any of the write operations.
4658

@@ -221,14 +233,14 @@ see the following API documentation:
221233
.. _orderOfExecution:
222234

223235
Order of Execution
224-
------------------
236+
~~~~~~~~~~~~~~~~~~
225237

226238
The ``bulkWrite()`` method accepts an optional ``BulkWriteOptions`` as a
227239
second parameter to specify whether the execution of the bulk operations is
228-
ordered or unordered.
240+
ordered or unordered.
229241

230242
Ordered Execution
231-
~~~~~~~~~~~~~~~~~
243+
+++++++++++++++++
232244

233245
By default, the ``bulkWrite()`` method executes bulk operations in
234246
order. This means that the bulk operations execute in the order you
@@ -264,7 +276,7 @@ document:
264276
{ "_id": 6, "name": "Zaynab Hassan", "age": 37 }
265277

266278
Unordered Execution
267-
~~~~~~~~~~~~~~~~~~~
279+
+++++++++++++++++++
268280

269281
You can also execute bulk operations in any order by specifying "false"
270282
to the ``order()`` method on ``BulkWriteOptions``. This means that
@@ -311,7 +323,8 @@ Client Bulk Write
311323

312324
When connecting to a deployment running {+mdb-server+} 8.0 or later,
313325
you can use the ``MongoClient.bulkWrite()`` method to write
314-
to multiple databases and collections in the same cluster.
326+
to multiple databases and collections in the same cluster. The ``MongoClient.bulkWrite()``
327+
method does not split different kinds of operations into different batches.
315328

316329
In the examples in preceding sections of this page, the ``MongoCollection.bulkWrite()`` method
317330
takes a list of ``WriteModel`` instances in which the specified subclass of

0 commit comments

Comments
 (0)