@@ -19,11 +19,11 @@ MongoDB Java Driver.
1919To perform a single create, replace, update, or delete operation, you can use
2020the corresponding method. For example, to insert one document and replace one
2121document, you can use the ``insertOne()`` and ``replaceOne()`` methods. In this
22- case, the ``MongoClient`` makes a call to the database for each operation.
23- You can reduce the number of calls to one by using bulk write operations .
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.
2424
2525You can perform bulk write operations by using the bulk write API in the
26- {+driver-short+} to perform multiple data changes in one call. You can
26+ {+driver-short+} to define multiple data changes in one method call. You can
2727perform bulk operations at the following levels:
2828
2929- :ref:`Collection Level <java-sync-coll-bulk-write>`: You can use the
@@ -320,19 +320,25 @@ instance of ``InsertOneModel`` represents an operation to insert one document.
320320
321321Similarly, the ``MongoClient.bulkWrite()`` method takes a
322322list of ``ClientNamespacedWriteModel`` instances to represent different write operations.
323- Instead of selecting a specific subclass for each write operation, the
324- ``ClientNamespacedWriteModel`` object contains different methods to represent
325- write operations. ``ClientNamespacedWriteModel`` contains the methods
326- ``insertOne()``, ``updateOne()``, ``updateMany()``, ``replaceOne()``,
327- ``deleteOne()``, and ``deleteMany()``.
323+ For example, an instance of ``ClientNamespacedInsertOneModel`` represents an
324+ operation to insert one document.
325+
326+ You can construct these ``ClientNamespacedWriteModel`` instances using different
327+ methods to represent write operations. ``ClientNamespacedWriteModel`` contains
328+ the methods ``insertOne()``, ``updateOne()``, ``updateMany()``, ``replaceOne()``,
329+ ``deleteOne()``, and ``deleteMany()``. These methods are used to construct corresponding
330+ write models. For example, ``ClientNamespacedWriteModel.updateOne()`` is used to
331+ construct a ``ClientNamespacedUpdateOneModel`` instance, which represents an
332+ update operation.
328333
329334These methods take a ``MongoNamespace`` object that defines which
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 subset of
333- documents to be updated or replaced.
335+ database and collection to write to. Some, such as ``insertOne()``, can take a
336+ ``Document`` instance that defines information about the write operation.
337+ Some other methods, such as ``updateOne ()`` and ``replaceOne()``, take a filter
338+ object that defines the subset of documents to be updated or replaced.
334339
335- The following sections describe how to use the client ``bulkWrite()`` method.
340+ The following sections provide examples of how to use the client ``bulkWrite()``
341+ method.
336342
337343Insert Example
338344~~~~~~~~~~~~~~
@@ -350,19 +356,20 @@ each write operation applies to.
350356
351357 List<ClientNamespacedWriteModel> bulkOperations = new ArrayList<>();
352358
353- bulkOperations.add(
354- ClientNamespacedWriteModel .insertOne(
359+ ClientNamespacedInsertOneModel insertDocument1 = new ClientNamespacedWriteModel
360+ .insertOne(
355361 peopleNamespace,
356362 new Document("name", "Julia Smith")
357- )
358- );
363+ );
359364
360- bulkOperations.add(
361- ClientNamespacedWriteModel .insertOne(
365+ ClientNamespacedInsertOneModel insertDocument2 = new ClientNamespacedWriteModel
366+ .insertOne(
362367 thingsNamespace,
363368 new Document("object", "washing machine")
364- )
365- );
369+ );
370+
371+ bulkOperations.add(insertDocument1);
372+ bulkOperations.add(insertDocument2);
366373
367374 ClientBulkWriteResult result = mongoClient.bulkWrite(bulkOperations);
368375
@@ -413,12 +420,13 @@ method to specify options when running the bulk write operations.
413420Order of Execution Example
414421``````````````````````````
415422
416- By default, the driver performs write operations in the order that you specify them until
417- an error occurs, or until they execute successfully. However, you can pass
418- ``false`` to the ``ordered()`` method on the ``ClientBulkWriteOptions``
419- interface to perform write operations in an unordered way. When using the unordered
420- option, an error-producing operation does not block execution of other write
421- operations in the call to the ``bulkWrite()`` method.
423+ By default, the individual operations in a bulk operation are executed in the
424+ order that you specify them until an error occurs, or until they execute
425+ successfully. However, you can pass ``false`` to the ``ordered()`` method on
426+ the ``ClientBulkWriteOptions`` interface to perform write operations in an
427+ unordered way. When using the unordered option, an error-producing operation
428+ does not prevent execution of other write operations in the call to the
429+ ``bulkWrite()`` method.
422430
423431The following code sets the ``ordered()`` method on an
424432instance of ``ClientBulkWriteOptions`` and performs a bulk write operation to
@@ -469,9 +477,9 @@ Summary
469477~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
470478
471479To perform a bulk operation, you create and pass a list of
472- ``WriteModel`` documents to the ``bulkWrite()`` method.
480+ ``WriteModel`` instances to the ``bulkWrite()`` method.
473481
474- There are 6 different ``WriteModel`` documents : ``InsertOneModel``,
482+ There are 6 different ``WriteModel`` subtypes : ``InsertOneModel``,
475483``ReplaceOneModel``, ``UpdateOneModel``, ``UpdateManyModel``,
476484``DeleteOneModel`` and ``DeleteManyModel``.
477485
@@ -488,12 +496,20 @@ When connecting to a deployment running {+mdb-server+} version 8.0 or later, you
488496can use the ``MongoClient.bulkWrite()`` method to perform bulk operations on multiple
489497databases and collections at once.
490498
491- This method uses the ``ClientNamespacedWriteModel`` and its methods
492- ``insertOne()``, ``updateOne()``, ``updateMany()``, ``replaceOne()``,
493- ``deleteOne()``, and ``deleteMany()``.
499+ To perform a client bulk operation, you create an pass a list of
500+ ``ClientNamespacedWriteModel`` instances to this method.
501+
502+ There are six subtypes of ``ClientNamespacedWriteModel``: ``ClientNamespacedInsertOneModel``,
503+ ``ClientNamespacedUpdateOneModel``, ``ClientNamespacedUpdateManyModel``,
504+ ``ClientNamespacedReplaceOneModel``, ``ClientNamespacedDeleteOneModel``, and
505+ ``ClientNamespacedDeleteManyModel``. To construct these write models, you can
506+ use the ``ClientNamespacedWriteModel`` methods ``insertOne()``, ``updateOne()``,
507+ ``updateMany()``, ``replaceOne()``, ``deleteOne()``, and ``deleteMany()``. These
508+ methods take a ``MongoNamespace`` object that defines which
509+ database and collection to write to.
494510
495- The method can also take a ``ClientBulkWriteOptions`` object to specify different
496- options for how the command is executed.
511+ The ``MongoClient.bulkWrite()`` method can also take a ``ClientBulkWriteOptions``
512+ object to specify different options for how the command is executed.
497513
498514To learn more about the client ``bulkWrite`` command, see the
499515:manual:`bulkWrite() <reference/command/bulkWrite/>` method reference in the {+mdb-server+}
0 commit comments