Skip to content
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

Open
wants to merge 19 commits into
base: master
Choose a base branch
from

Conversation

mayaraman19
Copy link
Collaborator

@mayaraman19 mayaraman19 commented Nov 11, 2024

Pull Request Info

PR Reviewing Guidelines

JIRA - DOCSP-41769
Staging:

Self-Review Checklist

  • Is this free of any warnings or errors in the RST?
  • Did you run a spell-check?
  • Did you run a grammar-check?
  • Are all the links working?
  • Are the facets and meta keywords accurate?

Copy link

netlify bot commented Nov 11, 2024

Deploy Preview for docs-java ready!

Name Link
🔨 Latest commit 1cfd451
🔍 Latest deploy log https://app.netlify.com/sites/docs-java/deploys/675b4fc8cb494100079fdaaf
😎 Deploy Preview https://deploy-preview-590--docs-java.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@mayaraman19 mayaraman19 changed the title initial checkpoint DOCSP-41769: Improved bulk write API Nov 11, 2024
Copy link
Contributor

@rustagir rustagir left a 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

source/fundamentals/crud/write-operations/bulk.txt Outdated Show resolved Hide resolved
source/fundamentals/crud/write-operations/bulk.txt Outdated Show resolved Hide resolved
source/fundamentals/crud/write-operations/bulk.txt Outdated Show resolved Hide resolved
source/fundamentals/crud/write-operations/bulk.txt Outdated Show resolved Hide resolved
source/fundamentals/crud/write-operations/bulk.txt Outdated Show resolved Hide resolved
source/fundamentals/crud/write-operations/bulk.txt Outdated Show resolved Hide resolved
source/fundamentals/crud/write-operations/bulk.txt Outdated Show resolved Hide resolved
source/whats-new.txt Outdated Show resolved Hide resolved
source/whats-new.txt Outdated Show resolved Hide resolved
Copy link
Contributor

@rustagir rustagir left a 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

source/fundamentals/crud/write-operations/bulk.txt Outdated Show resolved Hide resolved
source/fundamentals/crud/write-operations/bulk.txt Outdated Show resolved Hide resolved
source/fundamentals/crud/write-operations/bulk.txt Outdated Show resolved Hide resolved
source/fundamentals/crud/write-operations/bulk.txt Outdated Show resolved Hide resolved
source/fundamentals/crud/write-operations/bulk.txt Outdated Show resolved Hide resolved
source/fundamentals/crud/write-operations/bulk.txt Outdated Show resolved Hide resolved
source/fundamentals/crud/write-operations/bulk.txt Outdated Show resolved Hide resolved
source/fundamentals/crud/write-operations/bulk.txt Outdated Show resolved Hide resolved
source/fundamentals/crud/write-operations/bulk.txt Outdated Show resolved Hide resolved
source/whats-new.txt Outdated Show resolved Hide resolved
Copy link
Contributor

@rustagir rustagir left a 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!

source/fundamentals/crud/write-operations/bulk.txt Outdated Show resolved Hide resolved
source/fundamentals/crud/write-operations/bulk.txt Outdated Show resolved Hide resolved
source/fundamentals/crud/write-operations/bulk.txt Outdated Show resolved Hide resolved
source/fundamentals/crud/write-operations/bulk.txt Outdated Show resolved Hide resolved
source/fundamentals/crud/write-operations/bulk.txt Outdated Show resolved Hide resolved
source/fundamentals/crud/write-operations/bulk.txt Outdated Show resolved Hide resolved
source/fundamentals/crud/write-operations/bulk.txt Outdated Show resolved Hide resolved
source/fundamentals/crud/write-operations/bulk.txt Outdated Show resolved Hide resolved
source/fundamentals/crud/write-operations/bulk.txt Outdated Show resolved Hide resolved
source/fundamentals/crud/write-operations/bulk.txt Outdated Show resolved Hide resolved
@mayaraman19 mayaraman19 requested review from a team and katcharov and removed request for a team November 14, 2024 21:36
@stIncMale stIncMale requested review from stIncMale and removed request for katcharov November 15, 2024 21:04
source/fundamentals/crud/write-operations/bulk.txt Outdated Show resolved Hide resolved
source/fundamentals/crud/write-operations/bulk.txt Outdated Show resolved Hide resolved
source/fundamentals/crud/write-operations/bulk.txt Outdated Show resolved Hide resolved
source/fundamentals/crud/write-operations/bulk.txt Outdated Show resolved Hide resolved
source/fundamentals/crud/write-operations/bulk.txt Outdated Show resolved Hide resolved
source/fundamentals/crud/write-operations/bulk.txt Outdated Show resolved Hide resolved
source/fundamentals/crud/write-operations/bulk.txt Outdated Show resolved Hide resolved
@stIncMale
Copy link
Member

Note that I have neither compiled nor run the examples.

@mayaraman19 mayaraman19 requested a review from stIncMale December 4, 2024 02:11
@stIncMale
Copy link
Member

@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.

@mayaraman19
Copy link
Collaborator Author

@stIncMale Thanks for the feedback. I have unresolved comments that I initially resolved, if you want to take another look at those.

@stIncMale
Copy link
Member

I have unresolved comments that I initially resolved, if you want to take another look at those.

:trollface: 😭 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.

Comment on lines +22 to +40
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.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review here

Comment on lines +47 to +57
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.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review here

Comment on lines +324 to +366
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.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants