@@ -16,13 +16,15 @@ Overview
1616In this guide, you can learn how to use bulk operations in the
1717MongoDB Java Driver.
1818
19- .. note:: Improved Bulk Write Commands
19+ .. note:: Client Bulk Write Method
2020
21- The first half of this guide focuses on the ``MongoCollection.bulkWrite()``
22- method. In {+mdb-server+} version 8.0 and {+driver-short+} version 5.3 and later,
23- you can use an improved ``MongoClient.bulkWrite()`` method which can write
24- to multiple databases and collections at once. See the :ref:`improved-bulk-write`
25- section below to learn how to use the new method.
21+ This guide primarily focuses on the ``MongoCollection.bulkWrite()``
22+ method, which allows you to perform bulk operations on a collection.
23+ When connecting to a deployment running {+mdb-server+} 8.0 or later,
24+ you can use the ``MongoClient.bulkWrite()`` method to write
25+ to multiple databases and collections in the same call. See the
26+ :ref:`java-sync-client-bulk-write` section below to learn how to use the
27+ ``MongoClient.bulkWrite()`` method.
2628
2729To perform a create, replace, update, or delete operation,
2830use its corresponding method. For example, to insert one document,
@@ -108,7 +110,7 @@ describing people:
108110For more information about the methods and classes mentioned in this section,
109111see the `InsertOneModel
110112<{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/model/InsertOneModel.html>`__
111- API Documentation .
113+ API documentation .
112114
113115Replace Operation
114116~~~~~~~~~~~~~~~~~
@@ -140,7 +142,7 @@ contains an added ``location`` field:
140142For more information about the methods and classes mentioned in this section,
141143see the following resources:
142144
143- - `ReplaceOneModel <{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/model/ReplaceOneModel.html>`__ API Documentation
145+ - `ReplaceOneModel <{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/model/ReplaceOneModel.html>`__ API documentation
144146- :manual:`Unique indexes </core/index-unique/>` Server Manual Explanation
145147
146148Update Operation
@@ -176,8 +178,8 @@ the ``age`` field in a document where the ``_id`` is ``2``:
176178For more information about the methods and classes mentioned in this section,
177179see the following resources:
178180
179- - `UpdateOneModel <{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/model/UpdateOneModel.html>`__ API Documentation
180- - `UpdateManyModel <{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/model/UpdateManyModel.html>`__ API Documentation
181+ - `UpdateOneModel <{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/model/UpdateOneModel.html>`__ API documentation
182+ - `UpdateManyModel <{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/model/UpdateManyModel.html>`__ API documentation
181183- :manual:`unique indexes </core/index-unique/>` Server Manual Explanation
182184
183185Delete Operation
@@ -210,7 +212,7 @@ a document where the ``_id`` is ``1``:
210212 :end-before: end deleteDocumentsExample
211213
212214For more information about the methods and classes mentioned in this section,
213- see the following API Documentation :
215+ see the following API documentation :
214216
215217- `DeleteOneModel <{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/model/DeleteOneModel.html>`__
216218- `DeleteManyModel <{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/model/DeleteManyModel.html>`__
@@ -296,45 +298,48 @@ operations to execute in any order:
296298 { "_id": 6, "name": "Zaynab Omar", "age": 37 }
297299
298300For more information about the methods and classes mentioned in this section,
299- see the following API Documentation :
301+ see the following API documentation :
300302
301303- `BulkWriteOptions <{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/model/BulkWriteOptions.html>`__
302304- `ordered() <{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/model/BulkWriteOptions.html#ordered(boolean)>`__
303305
304- .. _improved -bulk-write:
306+ .. _java-sync-client -bulk-write:
305307
306- Improved Bulk Write Command
307- ---------------------------
308+ Client Bulk Write Method
309+ ------------------------
308310
309- Starting with {+mdb-server+} version 8.0 and {+driver-short+} version 5.3, there
310- is an improved bulk write method, ``MongoClient.bulkWrite()``, that writes to
311- different databases and collections in the same cluster.
311+ When connecting to a deployment running {+mdb-server+} 8.0 or later,
312+ you can use the ``MongoClient.bulkWrite()`` method to write
313+ to multiple databases and collections in the same cluster.
312314
313- In the previous examples on this page, the ``bulkWrite()`` method takes a list
314- of ``WriteModel`` documents in which the specified subclass of ``WriteModel``
315- represents the corresponding write operation. For example, ``InsertOneModel``
316- represents inserting one document.
315+ In the examples in preceding sections of this page, the ``MongoCollection. bulkWrite()`` method
316+ takes a list of ``WriteModel`` documents in which the specified subclass of
317+ ``WriteModel`` represents the corresponding write operation. For example, an
318+ instance of ``InsertOneModel`` represents an operation to insert one document.
317319
318- Similarly, the new ``bulkWrite()`` method takes a
319- list of ``ClientNamespacedWriteModel`` objects to represent the write operation.
320+ .. TODO - not necessarily instances
321+
322+ Similarly, the ``MongoClient.bulkWrite()`` method takes a
323+ list of ``ClientNamespacedWriteModel`` instances to represent different write operations.
320324However, you do not need to specify the subclass that represents the corresponding
321325write operation. Instead, the ``ClientNamespacedWriteModel`` object contains different
322326methods to represent different write operations, such as ``insertOne()`` or
323327``updateOne()``.
324328
325329These methods take a ``MongoNamespace`` object that defines which
326- database and collection to write to, and a ``Document`` object that defines the
327- document information. Some methods, such as ``updateOne()`` and ``replaceOne()``,
328- also take a ``Filters`` object that defines the filter for the operation.
330+ database and collection to write to, and a ``Document`` object that defines
331+ information about the write operation . Some methods, such as ``updateOne()`` and
332+ ``replaceOne()``, also take a ``Filters`` object that defines the filter for the operation.
329333
330- The following sections describe how to use the new ``bulkWrite()`` method.
334+ The following sections describe how to use the client ``bulkWrite()`` method.
331335
332336Insert Example
333337~~~~~~~~~~~~~~
334338
335- The following example shows how to use the new ``bulkWrite()`` method to insert
336- two documents. One document is inserted into the ``people`` collection in our
337- database. The other document is inserted into a collection called ``things``.
339+ This following example shows how to use the ``bulkWrite()`` method to insert
340+ two documents. One document is inserted into the ``people`` collection in a
341+ database named ``db``. The other document is inserted into a collection called ``things``
342+ in the ``db`` database.
338343We use the ``MongoNamespace`` object to define the database and collection we
339344want each write operation to be applied to.
340345
@@ -348,18 +353,13 @@ want each write operation to be applied to.
348353 ClientNamespacedWriteModel.insertOne(thingsNamespace, new Document("object", "washing machine"))
349354 ));
350355
351- After this example is executed, the ``people`` collection holds a
352- ``{ "name": "Julia Smith" }`` document and the ``things`` collection holds
353- a ``{ "object": "washing machine" }`` document.
354-
355356.. TODO: link documentation
356357
357358Replace Example
358359~~~~~~~~~~~~~~~
359360
360- The following example shows how to use the ``bulkWrite()`` method to replace an
361- existing document in the ``people`` collection and an existing document in the
362- ``things`` collection.
361+ The following example shows how to use the ``bulkWrite()`` method to replace
362+ existing documents in the ``people`` and ``things`` collections.
363363
364364.. code-block:: java
365365
@@ -379,28 +379,32 @@ existing document in the ``people`` collection and an existing document in the
379379 )
380380 ));
381381
382- After this example is executed, the document in the ``people`` collection in
383- which the ``_id`` field has the value of ``1`` has been replaced with a new
384- ``{ "name": "Maximus Farquaad" }`` document. Also, the document
385- in the ``things`` collection in which the ``_id`` field has the value of ``1``
386- has been replaced with a ``{ "object": "potato" }`` document.
382+ After this example runs successfully, the document in the ``people`` collection in
383+ which the ``_id`` field has the value of ``1`` is replaced with a new
384+ document. The document in the ``things`` collection in which the
385+ ``_id`` field has the value of ``1`` is replaced with a new document.
386+
387+ .. _java-sync-client-bulk-write-options:
387388
388389Bulk Write Options
389390~~~~~~~~~~~~~~~~~~
390391
391- Similarly to the :ref:`orderOfExecution` section above, you can use the
392- ``ClientBulkWriteOptions`` object to execute the new ``bulkWrite()`` method
393- with options.
392+ .. TODO: reword this
393+
394+ You can use the ``ClientBulkWriteOptions`` object to execute the ``bulkWrite()``
395+ method with options.
394396
395397Order of Execution Example
396398``````````````````````````
399+ By default, the write operations execute in the order that you specify them. However,
400+ you can pass ``false`` to the ``ordered()`` method on the ``ClientBulkWriteOptions``
401+ object to perform write operations in an unordered way. When using the unordered
402+ option, an error-producing operation will not block execution of other bulk
403+ write operations.
397404
398- As described in the previous Order of Execution section, by default the write
399- operations execute in the order they're specified. However, we can pass
400- ``false`` to the ``ordered()`` method on the ``ClientBulkWriteOptions`` object
401- to execute write operations in any order.
405+ .. TODO: the object itself is not necessarily being created
402406
403- The following code shows how to use the ``ordered()`` method on the
407+ The following code shows how to set the ``ordered()`` method on the
404408``ClientBulkWriteOptions`` object.
405409
406410.. code-block:: java
@@ -409,11 +413,13 @@ The following code shows how to use the ``ordered()`` method on the
409413
410414 ClientBulkWriteOptions options = new ClientBulkWriteOptions().ordered(false);
411415
412- ClientBulkWriteResult result = client.bulkWrite(List<>(
413- ClientNamespacedWriteModel.insertOne(namespace, new Document("name", "Donkey Kong")),
414- ClientNamespacedWriteModel.insertOne(namespace, new Document("name", "Mario"))
416+ ClientBulkWriteResult result = client.bulkWrite(
417+ List<>(
418+ ClientNamespacedWriteModel.insertOne(namespace, new Document("name", "Donkey Kong")),
419+ ClientNamespacedWriteModel.insertOne(namespace, new Document("name", "Mario"))
415420 ),
416- options);
421+ options
422+ );
417423
418424.. TODO: link documentation
419425
@@ -455,5 +461,5 @@ options for how the command is executed.
455461.. OPEN QUESTIONS FOR ENGINEERING:
456462 .. Should I include the extraneous types like the Client...Result object?
457463 .. Should I include the different ClientNamespacedInsertModel... etc?
458- .. Is ClientWriteModel being exposed for public use?
459- .. Is MongoCollection.bulkWrite() being deprecated?
464+ .. Is ClientWriteModel being exposed for public use? <no>
465+ .. Is MongoCollection.bulkWrite() being deprecated? <no>
0 commit comments