-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DOCSP-41769: Improved bulk write API #590
base: master
Are you sure you want to change the base?
DOCSP-41769: Improved bulk write API #590
Conversation
✅ Deploy Preview for docs-java ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good start! There are a lot of comments, so let me know if you have any questions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
eep sorry for more comments but it is for sure shaping up!! great work
…CSP-41769-improved-bulk-write
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no blocking changes, but pointed out some last issues and suggestions!
Note that I have neither compiled nor run the examples. |
@mayaraman19 could you please not resolve discussions started by a reviewer, as it complicates the review process: the list of unresolved discussions represent the items the reviewer has to re-review, and by resolving them the PR author hides those items from the reviewer. It should be up to the reviewer to decide whether a concern raised by him is resolved. |
@stIncMale Thanks for the feedback. I have unresolved comments that I initially resolved, if you want to take another look at those. |
😭 This resulted in even more confusion, because I have reviewed all of them, including the resolved ones. But now I will have to re-review them again. |
To perform a single create, replace, update, or delete operation, you can use | ||
the corresponding method. For example, to insert one document and replace one | ||
document, you can use the ``insertOne()`` and ``replaceOne()`` methods. In this | ||
case, the ``MongoClient`` makes a call to the database for each operation. | ||
|
||
Generally, you can reduce the number of calls to the database by using bulk write | ||
operations. You can perform bulk write operations at the following levels: | ||
|
||
- :ref:`Collection Level <java-sync-coll-bulk-write>`: You can use the | ||
``MongoCollection.bulkWrite()`` method to perform bulk write operations on a | ||
single collection. This method groups write operations together by the kind | ||
of operation. For example, ``MongoCollection.bulkWrite()`` puts multiple update | ||
operations in the same call, but makes two calls to the database for an insert | ||
operation and a replace operation. | ||
|
||
- :ref:`Client Level <java-sync-client-bulk-write>`: When running {+mdb-server+} | ||
version 8.0 or later, you can use the ``MongoClient.bulkWrite()`` method to perform | ||
bulk write operations on multiple collections and databases in the same cluster. | ||
This method groups multiple kinds of write operations into one call. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re-review here
Bulk operations consist of many write operations. To perform a bulk operation | ||
at the collection level, pass a ``List`` of ``WriteModel`` documents to the | ||
``MongoCollection.bulkWrite()`` method. A ``WriteModel`` is a model that | ||
represents any of the write operations. | ||
|
||
The ``MongoCollection.bulkWrite()`` method splits operations of different kinds into | ||
different batches. For example, when you pass ``DeleteOneModel``, | ||
``DeleteManyModel``, and ``ReplaceOneModel`` operations to the method, the method | ||
splits the delete operations into one batch and the replace operation | ||
into another. During this process, the client might reorder operations for | ||
efficiency if the bulk operation is not ordered. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re-review here
When connecting to a deployment running {+mdb-server+} 8.0 or later, | ||
you can use the ``MongoClient.bulkWrite()`` method to write | ||
to multiple databases and collections in the same cluster. The ``MongoClient.bulkWrite()`` | ||
method does not split different kinds of operations into different batches. | ||
|
||
In the examples in preceding sections of this page, the ``MongoCollection.bulkWrite()`` method | ||
takes a list of ``WriteModel`` instances in which the specified subclass of | ||
``WriteModel`` represents the corresponding write operation. For example, an | ||
instance of ``InsertOneModel`` represents an operation to insert one document. | ||
|
||
Similarly, the ``MongoClient.bulkWrite()`` method takes a | ||
list of ``ClientNamespacedWriteModel`` instances to represent different write operations. | ||
For example, an instance of ``ClientNamespacedInsertOneModel`` represents an | ||
operation to insert one document. | ||
|
||
You can construct instances of ``ClientNamespacedWriteModel`` using the following | ||
methods: | ||
|
||
- ``insertOne()`` | ||
|
||
- ``updateOne()`` | ||
|
||
- ``updateMany()`` | ||
|
||
- ``replaceOne()`` | ||
|
||
- ``deleteOne()`` | ||
|
||
- ``deleteMany()`` | ||
|
||
These methods are used to construct corresponding write models. | ||
For example, ``ClientNamespacedWriteModel.updateOne()`` is used to | ||
construct a ``ClientNamespacedUpdateOneModel`` instance, which represents an | ||
update operation. | ||
|
||
These methods take a ``MongoNamespace`` object that defines which | ||
database and collection to write to. Some, such as ``insertOne()``, can take a | ||
``Document`` instance that defines information about the write operation. | ||
Some other methods, such as ``updateOne()`` and ``replaceOne()``, take a filter | ||
object that defines the subset of documents to be updated or replaced. | ||
|
||
The following sections provide examples of how to use the client ``bulkWrite()`` | ||
method. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re-review here
Pull Request Info
PR Reviewing Guidelines
JIRA - DOCSP-41769
Staging:
Self-Review Checklist