@@ -21,40 +21,45 @@ MongoDB Java Driver.
2121
2222To perform a single create, replace, update, or delete operation, you can use
2323the corresponding method. For example, to insert one document and replace one
24- document, you can use the ``insertOne()`` and ``replaceOne()`` methods. In this
25- case , the ``MongoClient`` makes a call to the database for each operation.
24+ document, you can use the ``insertOne()`` and ``replaceOne()`` methods. When you
25+ use these methods , the ``MongoClient`` makes one call to the database for each operation.
2626
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:
27+ By using a bulk write operation, you can perform multiple write operations in
28+ fewer database calls . You can perform bulk write operations at the following levels:
2929
30- - :ref:`Collection Level <java-sync-coll-bulk-write>`: You can use the
30+ - :ref:`Collection <java-sync-coll-bulk-write>`: You can use the
3131 ``MongoCollection.bulkWrite()`` method to perform bulk write operations on a
3232 single collection. This method groups write operations together by the kind
3333 of operation. For example, ``MongoCollection.bulkWrite()`` puts multiple update
34- operations in the same call, but makes two calls to the database for an insert
34+ operations in one call, but makes two separate calls to the database for an insert
3535 operation and a replace operation.
3636
37- - :ref:`Client Level <java-sync-client-bulk-write>`: When running {+mdb-server+}
38- version 8.0 or later, you can use the ``MongoClient.bulkWrite()`` method to perform
39- bulk write operations on multiple collections and databases in the same cluster.
40- This method groups multiple kinds of write operations into one call.
37+ - :ref:`Client <java-sync-client-bulk-write>`: If your application connects to
38+ {+mdb-server+} version 8.0 or later, you can use the ``MongoClient.bulkWrite()``
39+ method to perform bulk write operations on multiple collections and databases
40+ in the same cluster. This method performs all write operations
41+ in one database call.
4142
4243.. _java-sync-coll-bulk-write:
4344
4445Collection Bulk Write
4546---------------------
4647
47- Bulk operations consist of many write operations. To perform a bulk operation
48- at the collection level, pass a ``List`` of ``WriteModel`` documents to the
49- ``MongoCollection.bulkWrite()`` method. A ``WriteModel`` is a model that
50- represents any of the write operations .
48+ Bulk write operations contain one or more write operations. To perform a bulk
49+ write operation at the collection level, pass a ``List`` of ``WriteModel``
50+ documents to the ``MongoCollection.bulkWrite()`` method. A ``WriteModel`` is a
51+ model that represents a write operation .
5152
52- The ``MongoCollection.bulkWrite()`` method splits operations of different kinds into
53- different batches. For example, when you pass ``DeleteOneModel``,
54- ``DeleteManyModel``, and ``ReplaceOneModel`` operations to the method, the method
55- splits the delete operations into one batch and the replace operation
56- into another. During this process, the client might reorder operations for
57- efficiency if the bulk operation is not ordered.
53+ The ``MongoCollection.bulkWrite()`` method performs each kind of write
54+ operations in a separate call. For example, when you pass ``DeleteOneModel``,
55+ ``DeleteManyModel``, and ``ReplaceOneModel`` objects to the method, it creates
56+ two calls: one for the delete operations and one for the replace operation.
57+
58+ .. note::
59+
60+ When the client splits operations into calls, it might reorder operations for
61+ efficiency if the bulk write operation is not ordered. To learn more about
62+ operation execution order, see the :ref:`orderOfExecution` section.
5863
5964The following sections show how to create and use each ``WriteModel``
6065document. The examples in each section use the following documents in the
@@ -324,43 +329,91 @@ Client Bulk Write
324329When connecting to a deployment running {+mdb-server+} 8.0 or later,
325330you can use the ``MongoClient.bulkWrite()`` method to write
326331to multiple databases and collections in the same cluster. The ``MongoClient.bulkWrite()``
327- method does not split different kinds of operations into different batches .
332+ method performs all write operations in a single call .
328333
329- In the examples in preceding sections of this page, the ``MongoCollection.bulkWrite()`` method
330- takes a list of ``WriteModel`` instances in which the specified subclass of
331- ``WriteModel`` represents the corresponding write operation. For example, an
332- instance of ``InsertOneModel`` represents an operation to insert one document.
333-
334- Similarly, the ``MongoClient.bulkWrite()`` method takes a
334+ The ``MongoClient.bulkWrite()`` method takes a
335335list of ``ClientNamespacedWriteModel`` instances to represent different write operations.
336336For example, an instance of ``ClientNamespacedInsertOneModel`` represents an
337337operation to insert one document.
338338
339- You can construct instances of ``ClientNamespacedWriteModel`` using the following
340- methods:
339+ You can construct instances of the ``ClientNamespacedWriteModel`` interface by using
340+ instance methods described in the table below. These methods take a
341+ ``MongoNamespace`` object that defines which database and collection to write to.
342+
343+ .. list-table::
344+ :header-rows: 1
345+
346+ * - Instance Method
347+ - Class Constructed
348+ - Parameters
349+ - Operation Description
350+
351+ * - ``insertOne()``
352+ - ``ClientNamespacedInsertOneModel``
353+ - ``namespace``: defines which database and collection to write to
354+
355+ ``document``: defines the document to insert
356+ - Creates a model to insert a document into the ``namespace``.
357+
358+ * - ``updateOne()``
359+ - ``ClientNamespacedInsertOneModel``
360+ - ``namespace``: defines which database and collection to write to
361+
362+ ``filter``: defines filter that selects which document to update
363+
364+ ``update``: defines update to apply to matching document
365+
366+ ``updatePipeline``: defines update pipeline to apply to matching document
367+
368+ ``options``: (optional) defines options to apply when updating document
369+
370+ One of ``update`` or ``updatePipeline`` must be specified.
371+ - Creates a model to update at most one document in the ``namespace``
372+ that matches ``filter``.
373+
374+ * - ``updateMany()``
375+ - ``ClientNamespacedUpdateManyModel``
376+ - ``namespace``: defines which database and collection to write to
377+
378+ ``filter``: defines filter that selects which documents to update
379+
380+ ``update``: defines update to apply to matching documents
381+
382+ ``updatePipeline``: defines update pipeline to apply to matching documents
383+
384+ ``options``: (optional) defines options to apply when updating documents
385+
386+ One of ``update`` or ``updatePipeline`` must be specified.
387+ - Updates all documents in the ``namespace`` that match ``filter``.
388+
389+ * - ``replaceOne()``
390+ - ``ClientNamespacedReplaceOneModel``
391+ - ``namespace``: defines which database and collection to write to
392+
393+ ``filter``: defines filter that selects which document to replace
341394
342- - ``insertOne()``
395+ ``replacement``: defines replacement document
343396
344- - ``updateOne()``
397+ ``options``: (optional) defines options to apply when replacing documents
398+ - Replaces at most one document in the ``namespace`` that matches ``filter``.
345399
346- - ``updateMany()``
400+ * - ``deleteOne()``
401+ - ``ClientNamespacedDeleteOneModel``
402+ - ``namespace``: defines which database and collection to write to
347403
348- - ``replaceOne()``
404+ ``filter``: defines filter that selects which document to delete
349405
350- - ``deleteOne()``
406+ ``option``: (optional) defines options to apply when deleting document
407+ - Deletes at most one document in the ``namespace`` that matches ``filter``.
351408
352- - ``deleteMany()``
409+ * - ``deleteMany()``
410+ - ``ClientNamespacedDeleteManyModel``
411+ - ``namespace``: defines which database and collection to write to
353412
354- These methods are used to construct corresponding write models.
355- For example, ``ClientNamespacedWriteModel.updateOne()`` is used to
356- construct a ``ClientNamespacedUpdateOneModel`` instance, which represents an
357- update operation.
413+ ``filter``: defines filter that selects which documents to delete
358414
359- These methods take a ``MongoNamespace`` object that defines which
360- database and collection to write to. Some, such as ``insertOne()``, can take a
361- ``Document`` instance that defines information about the write operation.
362- Some other methods, such as ``updateOne()`` and ``replaceOne()``, take a filter
363- object that defines the subset of documents to be updated or replaced.
415+ ``option``: (optional) defines options to apply when deleting documents
416+ - Deletes all documents in the ``namespace`` that match ``filter``.
364417
365418The following sections provide examples of how to use the client ``bulkWrite()``
366419method.
0 commit comments