From bf4504d9fd632f65a1ee165d201565793ef288e6 Mon Sep 17 00:00:00 2001 From: Mike Woofter <108414937+mongoKart@users.noreply.github.com> Date: Fri, 11 Oct 2024 22:04:50 -0500 Subject: [PATCH 01/17] wip --- .../crud/write-operations/bulk-write.txt | 308 ++++++++++++++++++ .../fundamentals/code-examples/BulkWrite.cs | 0 2 files changed, 308 insertions(+) create mode 100644 source/fundamentals/crud/write-operations/bulk-write.txt create mode 100644 source/includes/fundamentals/code-examples/BulkWrite.cs diff --git a/source/fundamentals/crud/write-operations/bulk-write.txt b/source/fundamentals/crud/write-operations/bulk-write.txt new file mode 100644 index 00000000..247dec08 --- /dev/null +++ b/source/fundamentals/crud/write-operations/bulk-write.txt @@ -0,0 +1,308 @@ +.. _csharp-bulk-write: + +===================== +Bulk Write Operations +===================== + +.. contents:: On this page + :local: + :backlinks: none + :depth: 2 + :class: singlecol + +.. facet:: + :name: genre + :values: reference + +.. meta:: + :keywords: insert, update, replace, code example + +Overview +-------- + +Consider a scenario in which you want to insert a document into a collection, +update multiple other documents, then delete a document. If you use +individual methods, each operation requires its own database call. This guide +shows you how to use bulk write operations to perform multiple write operations +in a single database call. + +Sample Data +~~~~~~~~~~~ + +The examples in this guide use the ``sample_restaurants.restaurants`` collection +from the :atlas:`Atlas sample datasets `. To learn how to create a +free MongoDB Atlas cluster and load the sample datasets, see the +:ref:`` tutorial. + +Define the Write Operations +--------------------------- + +For each write operation you want to perform, create an instance of one of +the following operation classes: + +- ``BulkWriteInsertOneModel`` +- ``BulkWriteUpdateOneModel`` +- ``BulkWriteUpdateManyModel`` +- ``BulkWriteReplaceOneModel`` +- ``BulkWriteDeleteOneModel`` +- ``BulkWriteDeleteManyModel`` + +Then, pass an ``IReadOnlyList`` of these instances to the ``MongoClient.BulkWrite()`` or +``MongoClient.BulkWriteAsync()`` method. + +The following sections show how to create and use instances of the preceding classes. + +Insert Operations +~~~~~~~~~~~~~~~~~ + +To perform an insert operation, create an instance of the ``BulkWriteInsertOneModel`` +and specify the document you want to insert. + +The following example creates an instance of the ``BulkWriteInsertOneModel``: + +.. literalinclude:: /includes/write/bulk-write.py + :start-after: start-bulk-insert-one + :end-before: end-bulk-insert-one + :language: csharp + :copyable: + +To insert multiple documents, create an instance of ``InsertOne`` for each document. + +Update Operations +~~~~~~~~~~~~~~~~~ + +To update a document, create an instance of ``UpdateOne`` and pass in +the following arguments: + +- A **query filter** that specifies the criteria used to match documents in your collection +- The update operation you want to perform. For more information about update + operations, see the :manual:`Field Update Operators + ` guide in the {+mdb-server+} manual. + +``UpdateOne`` updates *the first* document that matches your query filter. + +The following example creates an instance of ``UpdateOne``: + +.. literalinclude:: /includes/write/bulk-write.py + :start-after: start-bulk-update-one + :end-before: end-bulk-update-one + :language: python + :copyable: + +To update multiple documents, create an instance of ``UpdateMany`` and pass in +the same arguments. ``UpdateMany`` updates *all* documents that match your query +filter. + +The following example creates an instance of ``UpdateMany``: + +.. literalinclude:: /includes/write/bulk-write.py + :start-after: start-bulk-update-many + :end-before: end-bulk-update-many + :language: python + :copyable: + +Replace Operations +~~~~~~~~~~~~~~~~~~ + +A replace operation removes all fields and values of a specified document and +replaces them with new ones. To perform a replace operation, create an instance +of ``ReplaceOne`` and pass it a query filter and the fields and values you want +to store in the matching document. + +The following example creates an instance of ``ReplaceOne``: + +.. literalinclude:: /includes/write/bulk-write.py + :start-after: start-bulk-replace-one + :end-before: end-bulk-replace-one + :language: python + :copyable: + +To replace multiple documents, you must create an instance of ``ReplaceOne`` for each document. + +Delete Operations +~~~~~~~~~~~~~~~~~ + +To delete a document, create an instance of ``DeleteOne`` and pass in a +query filter specifying the document you want to delete. ``DeleteOne`` removes +only *the first* document that matches your query filter. + +The following example creates an instance of ``DeleteOne``: + +.. literalinclude:: /includes/write/bulk-write.py + :start-after: start-bulk-delete-one + :end-before: end-bulk-delete-one + :language: python + :copyable: + +To delete multiple documents, create an instance of ``DeleteMany`` and pass in a +query filter specifying the document you want to delete. ``DeleteMany`` removes +*all* documents that match your query filter. + +The following example creates an instance of ``DeleteMany``: + +.. literalinclude:: /includes/write/bulk-write.py + :start-after: start-bulk-delete-many + :end-before: end-bulk-delete-many + :language: python + :copyable: + +Call the ``bulk_write()`` Method +-------------------------------- + +After you define a class instance for each operation you want to perform, +pass a list of these instances to the ``bulk_write()`` method. +By default, the method runs the operations in the order +they're defined in the list. + +The following example performs multiple write operations by using the +``bulk_write()`` method: + +.. io-code-block:: + + .. input:: /includes/write/bulk-write.py + :start-after: start-bulk-write-mixed + :end-before: end-bulk-write-mixed + :language: python + + .. output:: + + BulkWriteResult({'writeErrors': [], 'writeConcernErrors': [], 'nInserted': 2, 'nUpserted': 0, 'nMatched': 2, 'nModified': 2, 'nRemoved': 1, 'upserted': []}, acknowledged=True) + +If any of the write operations fail, {+driver-short+} raises a +``BulkWriteError`` and does not perform any further operations. +``BulkWriteError`` provides a ``details`` attribute that includes the operation +that failed, and details about the exception. + +.. note:: + + When {+driver-short+} runs a bulk operation, it uses the ``write_concern`` of the + collection in which the operation is running. The driver reports all write + concern errors after attempting all operations, regardless of execution order. + +Customize Bulk Write Operations +------------------------------- + +The ``bulk_write()`` method optionally accepts additional +parameters, which represent options you can use to configure the bulk write +operation. If you don't specify any additional options, the driver does not customize +the bulk write operation. + +.. list-table:: + :widths: 30 70 + :header-rows: 1 + + * - Property + - Description + + * - ``ordered`` + - | If ``True``, the driver performs the write operations in the order + provided. If an error occurs, the remaining operations are not + attempted. + | + | If ``False``, the driver performs the operations in an + arbitrary order and attempts to perform all operations. + | Defaults to ``True``. + + * - ``bypass_document_validation`` + - | Specifies whether the operation bypasses document-level validation. For more + information, see :manual:`Schema + Validation ` in the MongoDB + Server manual. + | Defaults to ``False``. + + * - ``session`` + - | An instance of ``ClientSession``. For more information, see the `API + documentation <{+api-root+}pymongo/client_session.html#pymongo.client_session.ClientSession>`__. + + * - ``comment`` + - | A comment to attach to the operation. For more information, see the :manual:`delete command + fields ` guide in the + {+mdb-server+} manual. + + * - ``let`` + - | A map of parameter names and values. Values must be constant or closed + expressions that don't reference document fields. For more information, + see the :manual:`let statement + ` in the + {+mdb-server+} manual. + +The following example calls the ``bulk_write()`` method from the preceding example, with the ``ordered`` option set +to ``False``: + +.. literalinclude:: /includes/write/bulk-write.py + :start-after: start-bulk-write-unordered + :end-before: end-bulk-write-unordered + :language: python + :copyable: + +If any of the write operations in an unordered bulk write fail, {+driver-short+} +reports the errors only after attempting all operations. + +.. note:: + + Unordered bulk operations do not guarantee order of execution. The order can + differ from the way you list them to optimize the runtime. + +Return Value +------------ + +The ``bulk_write()`` method returns a ``BulkWriteResult`` object. The +``BulkWriteResult`` object contains the following properties: + +.. list-table:: + :widths: 30 70 + :header-rows: 1 + + * - Property + - Description + + * - ``acknowledged`` + - | Indicates if the server acknowledged the write operation. + + * - ``bulk_api_result`` + - | The raw bulk API result returned by the server. + + * - ``deleted_count`` + - | The number of documents deleted, if any. + + * - ``inserted_count`` + - | The number of documents inserted, if any. + + * - ``matched_count`` + - | The number of documents matched for an update, if applicable. + + * - ``modified_count`` + - | The number of documents modified, if any. + + * - ``upserted_count`` + - | The number of documents upserted, if any. + + * - ``upserted_ids`` + - | A map of the operation's index to the ``_id`` of the upserted documents, if + applicable. + +Additional Information +---------------------- + +To learn how to perform individual write operations, see the following guides: + +- :ref:`pymongo-write-insert` +- :ref:`pymongo-write-update` +- :ref:`pymongo-write-replace` +- :ref:`pymongo-write-delete` + +API Documentation +~~~~~~~~~~~~~~~~~ + +To learn more about any of the methods or types discussed in this +guide, see the following API Documentation: + +- `bulk_write() <{+api-root+}pymongo/collection.html#pymongo.collection.Collection.bulk_write>`__ +- `InsertOne <{+api-root+}pymongo/operations.html#pymongo.operations.InsertOne>`__ +- `UpdateOne <{+api-root+}pymongo/operations.html#pymongo.operations.UpdateOne>`__ +- `UpdateMany <{+api-root+}pymongo/operations.html#pymongo.operations.UpdateMany>`__ +- `ReplaceOne <{+api-root+}pymongo/operations.html#pymongo.operations.ReplaceOne>`__ +- `DeleteOne <{+api-root+}pymongo/operations.html#pymongo.operations.DeleteOne>`__ +- `DeleteMany <{+api-root+}pymongo/operations.html#pymongo.operations.DeleteMany>`__ +- `BulkWriteResult <{+api-root+}pymongo/results.html#pymongo.results.BulkWriteResult>`__ +- `BulkWriteError <{+api-root+}pymongo/errors.html#pymongo.errors.BulkWriteError>`__ diff --git a/source/includes/fundamentals/code-examples/BulkWrite.cs b/source/includes/fundamentals/code-examples/BulkWrite.cs new file mode 100644 index 00000000..e69de29b From 37aabe0fb4e7090e9ea93582cda7463fcc7d9676 Mon Sep 17 00:00:00 2001 From: Mike Woofter <108414937+mongoKart@users.noreply.github.com> Date: Sat, 12 Oct 2024 21:39:10 -0500 Subject: [PATCH 02/17] wip --- .../crud/write-operations/bulk-write.txt | 58 ++++++---- .../fundamentals/code-examples/BulkWrite.cs | 103 ++++++++++++++++++ 2 files changed, 141 insertions(+), 20 deletions(-) diff --git a/source/fundamentals/crud/write-operations/bulk-write.txt b/source/fundamentals/crud/write-operations/bulk-write.txt index 247dec08..d369ce37 100644 --- a/source/fundamentals/crud/write-operations/bulk-write.txt +++ b/source/fundamentals/crud/write-operations/bulk-write.txt @@ -47,59 +47,77 @@ the following operation classes: - ``BulkWriteDeleteOneModel`` - ``BulkWriteDeleteManyModel`` -Then, pass an ``IReadOnlyList`` of these instances to the ``MongoClient.BulkWrite()`` or -``MongoClient.BulkWriteAsync()`` method. +Then, pass an ``IReadOnlyList`` of the instances you created to the +``MongoClient.BulkWrite()`` or ``MongoClient.BulkWriteAsync()`` method. The following sections show how to create and use instances of the preceding classes. Insert Operations ~~~~~~~~~~~~~~~~~ -To perform an insert operation, create an instance of the ``BulkWriteInsertOneModel`` -and specify the document you want to insert. +To perform an insert operation, create an instance of the ``BulkWriteInsertOneModel`` class +and pass the following arguments: -The following example creates an instance of the ``BulkWriteInsertOneModel``: +- The names of the database and collection to insert the BSON document into, in the format + "database.collection" +- The BSON document to insert into the collection, as a ``BsonDocument`` object -.. literalinclude:: /includes/write/bulk-write.py +The following example creates an instance of the ``BulkWriteInsertOneModel`` class. The +``BsonDocument`` object represents a new restaurant named "Mongo's Deli" to be inserted +into the ``sample_restaurants.restaurants`` collection. + +.. literalinclude:: /includes/fundamentals/code-examples/BulkWrite.cs :start-after: start-bulk-insert-one :end-before: end-bulk-insert-one :language: csharp :copyable: + :dedent: 8 -To insert multiple documents, create an instance of ``InsertOne`` for each document. +To insert multiple documents, create an instance of ``BulkWriteInsertOneModel`` for +each document. Update Operations ~~~~~~~~~~~~~~~~~ -To update a document, create an instance of ``UpdateOne`` and pass in +To update a document, create an instance of the ``BulkWriteUpdateOneModel`` class and pass the following arguments: -- A **query filter** that specifies the criteria used to match documents in your collection +- The names of the database and collection to insert the BSON document into, in the format + "database.collection". +- A **query filter** that specifies the criteria used to match documents in your collection. + The ``BulkWriteUpdateOneModel`` operation updates *only the first document* that matches your + query filter. - The update operation you want to perform. For more information about update operations, see the :manual:`Field Update Operators ` guide in the {+mdb-server+} manual. -``UpdateOne`` updates *the first* document that matches your query filter. - -The following example creates an instance of ``UpdateOne``: +The following example creates an instance of the ``BulkWriteUpdateOneModel`` class. The +filter matches the first document in the ``sample_restaurants.restaurants`` collection +where the ``name`` field is ``"Mongo's Deli"``. The update operation sets the ``cuisine`` +field to ``"Sandwiches and Salads"``. -.. literalinclude:: /includes/write/bulk-write.py +.. literalinclude:: /includes/fundamentals/code-examples/BulkWrite.cs :start-after: start-bulk-update-one :end-before: end-bulk-update-one - :language: python + :language: csharp :copyable: + :dedent: 8 -To update multiple documents, create an instance of ``UpdateMany`` and pass in -the same arguments. ``UpdateMany`` updates *all* documents that match your query -filter. +To update multiple documents, create an instance of the ``BulkWriteUpdateManyModel`` class +and pass in the same arguments described previously. The ``BulkWriteUpdateManyModel`` +operation updates *all documents* that match your query filter. -The following example creates an instance of ``UpdateMany``: +The following example creates an instance of the ``BulkWriteUpdateManyModel`` class. The +filter matches all documents in the ``sample_restaurants.restaurants`` collection +where the ``name`` field is ``"Mongo's Deli"``. The update operation sets the ``cuisine`` +field to ``"Sandwiches and Salads"``. -.. literalinclude:: /includes/write/bulk-write.py +.. literalinclude:: /includes/fundamentals/code-examples/BulkWrite.cs :start-after: start-bulk-update-many :end-before: end-bulk-update-many - :language: python + :language: csharp :copyable: + :dedent: 8 Replace Operations ~~~~~~~~~~~~~~~~~~ diff --git a/source/includes/fundamentals/code-examples/BulkWrite.cs b/source/includes/fundamentals/code-examples/BulkWrite.cs index e69de29b..4a98cfd7 100644 --- a/source/includes/fundamentals/code-examples/BulkWrite.cs +++ b/source/includes/fundamentals/code-examples/BulkWrite.cs @@ -0,0 +1,103 @@ +using System; + +class BulkWrite +{ + static void Main(string[] args) + { + Console.WriteLine("Hello, World!"); + BulkWrite + } + + static void InsertOne() + { + // start-bulk-insert-one + var insertOneModel = new BulkWriteInsertOneModel( + "sample_restaurants.restaurants", + new BsonDocument{ + { "name", "Mongo's Deli" }, + { "cuisine", "Sandwiches" }, + { "borough", "Manhattan" }, + { "restaurant_id", "1234" } + } + ); + // end-bulk-insert-one + } + + static void UpdateOne() + { + // start-bulk-update-one + var updateOneModel = new BulkWriteUpdateOneModel( + "sample_restaurants.restaurants", + Builders.Filter.Eq("name", "Mongo's Deli"), + Builders.Update.Set("cuisine", "Sandwiches and Salads") + ); + // end-bulk-update-one + } + + static void UpdateMany() + { + // start-bulk-update-many + var updateManyModel = new BulkWriteUpdateManyModel( + "sample_restaurants.restaurants", + Builders.Filter.Eq("name", "Mongo's Deli"), + Builders.Update.Set("cuisine", "Sandwiches and Salads") + ); + // end-bulk-update-many + } + + +# start-bulk-replace-one + operation = pymongo.ReplaceOne( + { "restaurant_id": "1234" }, + { + "name": "Mongo's Pizza", + "cuisine": "Pizza", + "borough": "Brooklyn", + "restaurant_id": "5678" + } +) +# end-bulk-replace-one + +# start-bulk-delete-one +operation = pymongo.DeleteOne({ "restaurant_id": "5678" }) +# end-bulk-delete-one + +# start-bulk-delete-many +operation = pymongo.DeleteMany({ "name": "Mongo's Deli" }) +# end-bulk-delete-many + +# start-bulk-write-mixed +operations = [ + pymongo.InsertOne( + { + "name": "Mongo's Deli", + "cuisine": "Sandwiches", + "borough": "Manhattan", + "restaurant_id": "1234" + } + ), + pymongo.InsertOne( + { + "name": "Mongo's Deli", + "cuisine": "Sandwiches", + "borough": "Brooklyn", + "restaurant_id": "5678" + } + ), + pymongo.UpdateMany( + { "name": "Mongo's Deli" }, + { "$set": { "cuisine": "Sandwiches and Salads" } }, + ), + pymongo.DeleteOne( + { "restaurant_id": "1234" } + ) +] + +results = restaurants.bulk_write(operations) + +print(results) +# end-bulk-write-mixed + +# start-bulk-write-unordered +results = restaurants.bulk_write(operations, ordered = False) +# end-bulk-write-unordered \ No newline at end of file From 6690f808b46dd95fb1d9c8010ba9a5754b66443b Mon Sep 17 00:00:00 2001 From: Mike Woofter <108414937+mongoKart@users.noreply.github.com> Date: Sat, 12 Oct 2024 22:08:49 -0500 Subject: [PATCH 03/17] wip --- source/fundamentals/crud/write-operations/bulk-write.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/fundamentals/crud/write-operations/bulk-write.txt b/source/fundamentals/crud/write-operations/bulk-write.txt index d369ce37..f44ddc39 100644 --- a/source/fundamentals/crud/write-operations/bulk-write.txt +++ b/source/fundamentals/crud/write-operations/bulk-write.txt @@ -122,9 +122,9 @@ field to ``"Sandwiches and Salads"``. Replace Operations ~~~~~~~~~~~~~~~~~~ -A replace operation removes all fields and values of a specified document and +A replace operation removes all fields and values in a specified document and replaces them with new ones. To perform a replace operation, create an instance -of ``ReplaceOne`` and pass it a query filter and the fields and values you want +of the ``BulkWriteReplaceOneModel`` class and pass it a query filter and the fields and values you want to store in the matching document. The following example creates an instance of ``ReplaceOne``: From cb693cf09e9e056dad9fd69191469665b2c2b9c5 Mon Sep 17 00:00:00 2001 From: Mike Woofter <108414937+mongoKart@users.noreply.github.com> Date: Mon, 14 Oct 2024 16:02:45 -0500 Subject: [PATCH 04/17] wip --- .../crud/write-operations/bulk-write.txt | 278 ++++++++++++++---- .../fundamentals/code-examples/BulkWrite.cs | 111 ++++--- 2 files changed, 280 insertions(+), 109 deletions(-) diff --git a/source/fundamentals/crud/write-operations/bulk-write.txt b/source/fundamentals/crud/write-operations/bulk-write.txt index f44ddc39..bd3bdeae 100644 --- a/source/fundamentals/crud/write-operations/bulk-write.txt +++ b/source/fundamentals/crud/write-operations/bulk-write.txt @@ -40,29 +40,54 @@ Define the Write Operations For each write operation you want to perform, create an instance of one of the following operation classes: -- ``BulkWriteInsertOneModel`` -- ``BulkWriteUpdateOneModel`` -- ``BulkWriteUpdateManyModel`` -- ``BulkWriteReplaceOneModel`` -- ``BulkWriteDeleteOneModel`` -- ``BulkWriteDeleteManyModel`` +- ``BulkWriteInsertOneModel`` +- ``BulkWriteUpdateOneModel`` +- ``BulkWriteUpdateManyModel`` +- ``BulkWriteReplaceOneModel`` +- ``BulkWriteDeleteOneModel`` +- ``BulkWriteDeleteManyModel`` Then, pass an ``IReadOnlyList`` of the instances you created to the ``MongoClient.BulkWrite()`` or ``MongoClient.BulkWriteAsync()`` method. The following sections show how to create and use instances of the preceding classes. +.. tip:: Bulk Write Operations with POCOs + + The examples in this guide use ``BsonDocument`` as the type for ``TDocument``. + You can also use a Plain Old CLR Objects (POCO) as the type for ``TDocument``. + + To use a POCO, define a class that represents the documents in your collection. + The class must have properties that match the fields in your documents. + For more information, see :ref:``. + Insert Operations ~~~~~~~~~~~~~~~~~ -To perform an insert operation, create an instance of the ``BulkWriteInsertOneModel`` class -and pass the following arguments: +To perform an insert operation, create an instance of the +``BulkWriteInsertOneModel`` class. +The ``BulkWriteInsertOneModel`` constructor accepts the following parameters: + +.. list-table:: + :header-rows: 1 + :stub-columns: 1 + :widths: 10 10 20 (Optional) + + * - Parameter + - Description + + * - ``collectionNamespace`` + - | The database and collection to insert the BSON document into. + | + | **Data Type:** {+string-data-type+} or `CollectionNamespace <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.CollectionNamespace.html>`__ -- The names of the database and collection to insert the BSON document into, in the format - "database.collection" -- The BSON document to insert into the collection, as a ``BsonDocument`` object + * - ``document`` + - | The document to insert into the collection. + | + | **Data Type:** ``TDocument`` -The following example creates an instance of the ``BulkWriteInsertOneModel`` class. The +The following example creates an instance of the ``BulkWriteInsertOneModel`` +class. The ``BsonDocument`` object represents a new restaurant named "Mongo's Deli" to be inserted into the ``sample_restaurants.restaurants`` collection. @@ -73,28 +98,83 @@ into the ``sample_restaurants.restaurants`` collection. :copyable: :dedent: 8 -To insert multiple documents, create an instance of ``BulkWriteInsertOneModel`` for -each document. +.. tip:: Insert Multiple Documents + + To insert multiple documents, create an instance of the + ``BulkWriteInsertOneModel`` class for each document you want to insert. Update Operations ~~~~~~~~~~~~~~~~~ -To update a document, create an instance of the ``BulkWriteUpdateOneModel`` class and pass -the following arguments: +To update a document, create an instance of the ``BulkWriteUpdateOneModel`` +class. The ``BulkWriteUpdateOneModel`` constructor accepts the following +parameters: -- The names of the database and collection to insert the BSON document into, in the format - "database.collection". -- A **query filter** that specifies the criteria used to match documents in your collection. - The ``BulkWriteUpdateOneModel`` operation updates *only the first document* that matches your - query filter. -- The update operation you want to perform. For more information about update - operations, see the :manual:`Field Update Operators - ` guide in the {+mdb-server+} manual. +.. list-table:: + :header-rows: 1 + :stub-columns: 1 + + * - Parameter + - Description + + * - ``collectionNamespace`` + - | The database and collection to insert the BSON document into. + | + | **Data Type:** {+string-data-type+} or `CollectionNamespace <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.CollectionNamespace.html>`__ -The following example creates an instance of the ``BulkWriteUpdateOneModel`` class. The + * - ``filter`` + - | The **query filter** that specifies the criteria used to match documents in your collection. + | The ``UpdateOne`` operation updates *only the first document* that matches the + | query filter. + | + | **Data Type:** `FilterDefinition <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.FilterDefinition-1.html>`__ + + * - ``update`` + - | The update operation you want to perform. For more information about update + | operations, see + | :manual:`Field Update Operators ` in the + | {+mdb-server+} manual. + | + | **Data Type:** `UpdateDefinition <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.UpdateDefinition-1.html>`__ + + * - ``collation`` + - | *Optional.* The language collation to use when sorting results. See + | :manual:`the delete statements` + for more information. + | + | **Data Type:** `Collation <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.Collation.html>`__ + | **Default:** ``null`` + + * - ``hint`` + - | *Optional.* The index to use to scan for documents. + See :manual:`the MongoDB server manual` + for more information. + | + | **Data Type:** `BsonValue <{+new-api-root+}/MongoDB.Bson/MongoDB.Bson.BsonValue.html>`__ + | **Default:** ``null`` + + * - ``isUpsert`` + - | *Optional.* Specifies whether the update operation performs an upsert operation if no + | documents match the query filter. + | See :manual:`the MongoDB server manual ` + | for more information. + | + | **Data Type:** {+bool-data-type+} + | **Default:** ``false`` + + * - ``arrayFilters`` + - | Specifies which array elements to modify for an update operation on an array field. + | See :manual:`the MongoDB server manual` + | for more information. + | + | **Data Type:** `IEnumerable `__ + | **Default:** ``null`` + +The following example creates an instance of the ``BulkWriteUpdateOneModel`` +class, and uses ``BsonDocument`` as the type for ``TDocument``. The filter matches the first document in the ``sample_restaurants.restaurants`` collection -where the ``name`` field is ``"Mongo's Deli"``. The update operation sets the ``cuisine`` -field to ``"Sandwiches and Salads"``. +where the value of the ``name`` field is ``"Mongo's Deli"``. The update operation sets +the value of the ``cuisine`` field to ``"Sandwiches and Salads"``. .. literalinclude:: /includes/fundamentals/code-examples/BulkWrite.cs :start-after: start-bulk-update-one @@ -103,14 +183,17 @@ field to ``"Sandwiches and Salads"``. :copyable: :dedent: 8 -To update multiple documents, create an instance of the ``BulkWriteUpdateManyModel`` class -and pass in the same arguments described previously. The ``BulkWriteUpdateManyModel`` +To update multiple documents, create an instance of the +``BulkWriteUpdateManyModel`` class. The constructor for this class +accepts the same parameters as the ``BulkWriteUpdateOneModel`` constructor. +The ``BulkWriteUpdateManyModel`` operation updates *all documents* that match your query filter. -The following example creates an instance of the ``BulkWriteUpdateManyModel`` class. The +The following example creates an instance of the ``BulkWriteUpdateManyModel`` +class, and uses ``BsonDocument`` as the type for ``TDocument``. The filter matches all documents in the ``sample_restaurants.restaurants`` collection -where the ``name`` field is ``"Mongo's Deli"``. The update operation sets the ``cuisine`` -field to ``"Sandwiches and Salads"``. +where the value of the ``name`` field is ``"Mongo's Deli"``. The update operation sets +the value of the ``cuisine`` field to ``"Sandwiches and Salads"``. .. literalinclude:: /includes/fundamentals/code-examples/BulkWrite.cs :start-after: start-bulk-update-many @@ -122,79 +205,144 @@ field to ``"Sandwiches and Salads"``. Replace Operations ~~~~~~~~~~~~~~~~~~ -A replace operation removes all fields and values in a specified document and -replaces them with new ones. To perform a replace operation, create an instance -of the ``BulkWriteReplaceOneModel`` class and pass it a query filter and the fields and values you want -to store in the matching document. +To replace the fields in a document, create an instance of the +``BulkWriteReplaceOneModel`` class. The ``BulkWriteReplaceOneModel`` +constructor accepts the following parameters: -The following example creates an instance of ``ReplaceOne``: +.. list-table:: + :header-rows: 1 + :stub-columns: 1 -.. literalinclude:: /includes/write/bulk-write.py + * - Parameter + - Description + + * - ``collectionNamespace`` + - | The database and collection to insert the BSON document into. + | + | **Data Type:** {+string-data-type+} or `CollectionNamespace <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.CollectionNamespace.html>`__ + + * - ``filter`` + - | The **query filter** that specifies the criteria used to match documents in your collection. + | The ``UpdateOne`` operation updates *only the first document* that matches the + | query filter. + | + | **Data Type:** `FilterDefinition <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.FilterDefinition-1.html>`__ + + * - ``replacement`` + - | The replacement document, which specifies the fields and values to insert in the + | target document. + | + | **Data Type:** ``TDocument`` + + * - ``collation`` + - | *Optional.* The language collation to use when sorting results. See + | :manual:`the delete statements` + for more information. + | + | **Data Type:** `Collation <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.Collation.html>`__ + | **Default:** ``null`` + + * - ``hint`` + - | *Optional.* The index to use to scan for documents. + See :manual:`the MongoDB server manual` + for more information. + | + | **Data Type:** `BsonValue <{+new-api-root+}/MongoDB.Bson/MongoDB.Bson.BsonValue.html>`__ + | **Default:** ``null`` + + * - ``isUpsert`` + - | *Optional.* Specifies whether the update operation performs an upsert operation if no + | documents match the query filter. + | See :manual:`the MongoDB server manual ` + | for more information. + | + | **Data Type:** {+bool-data-type+} + | **Default:** ``false`` + +The following example creates an instance of the ``BulkWriteReplaceOneyModel`` +class, and uses ``BsonDocument`` as the type for ``TDocument``. The +filter matches the document in the ``sample_restaurants.restaurants`` collection +where the value of the ``restaurant_id`` field is ``"1234"``. The replace operation +removes all fields from this document and sets new values in the ``name``, ``cuisine``, +``borough``, and ``restaurant_id`` fields. + +.. literalinclude:: /includes/fundamentals/code-examples/BulkWrite.cs :start-after: start-bulk-replace-one :end-before: end-bulk-replace-one - :language: python + :language: csharp :copyable: + :dedent: 8 -To replace multiple documents, you must create an instance of ``ReplaceOne`` for each document. +.. tip:: Replace Multiple Documents + + To replace multiple documents, you must create an instance of the + ``BulkWriteReplaceOneModel`` class for each document you want to replace. Delete Operations ~~~~~~~~~~~~~~~~~ -To delete a document, create an instance of ``DeleteOne`` and pass in a -query filter specifying the document you want to delete. ``DeleteOne`` removes -only *the first* document that matches your query filter. +To delete a document, create an instance of the ``BulkWriteDeleteOneModel`` and pass in +a query filter that specifies the document that you want to delete. The +``BulkWriteDeleteOneModel`` operation removes +only the *first document* that matches your query filter. -The following example creates an instance of ``DeleteOne``: +The following example creates an instance of the ``BulkWriteDeleteOneModel`` class: -.. literalinclude:: /includes/write/bulk-write.py +.. literalinclude:: /includes/fundamentals/code-examples/BulkWrite.cs :start-after: start-bulk-delete-one :end-before: end-bulk-delete-one - :language: python + :language: csharp :copyable: + :dedent: 8 -To delete multiple documents, create an instance of ``DeleteMany`` and pass in a -query filter specifying the document you want to delete. ``DeleteMany`` removes -*all* documents that match your query filter. +To delete multiple documents, create an instance of the ``BulkWriteDeleteManyModel`` +class and pass a query filter that specifies the document that you want to delete. +The ``BulkWriteDeleteManyModel`` operation removes *all* documents that match your +query filter. -The following example creates an instance of ``DeleteMany``: +The following example creates an instance of the ``BulkWriteDeleteManyModel`` class: -.. literalinclude:: /includes/write/bulk-write.py +.. literalinclude:: /includes/fundamentals/code-examples/BulkWrite.cs :start-after: start-bulk-delete-many :end-before: end-bulk-delete-many - :language: python + :language: csharp :copyable: + :dedent: 8 -Call the ``bulk_write()`` Method +Call the ``BulkWrite()`` Method -------------------------------- -After you define a class instance for each operation you want to perform, -pass a list of these instances to the ``bulk_write()`` method. -By default, the method runs the operations in the order +After you define a ``BulkWriteModel`` instance for each operation that you want to perform, +pass an ``IList`` of these instances to the ``BulkWrite()`` or ``BulkWriteAsync()`` method. +By default, these methods run the operations in the order they're defined in the list. -The following example performs multiple write operations by using the -``bulk_write()`` method: +The following code examples show how to use the asynchronous +``BulkWriteAsync()`` method and the synchronous ``BulkWrite()`` method to +perform multiple write operations. .. io-code-block:: - .. input:: /includes/write/bulk-write.py + .. input:: /includes/fundamentals/code-examples/BulkWrite.cs :start-after: start-bulk-write-mixed :end-before: end-bulk-write-mixed - :language: python + :language: csharp + :dedent: 8 .. output:: BulkWriteResult({'writeErrors': [], 'writeConcernErrors': [], 'nInserted': 2, 'nUpserted': 0, 'nMatched': 2, 'nModified': 2, 'nRemoved': 1, 'upserted': []}, acknowledged=True) -If any of the write operations fail, {+driver-short+} raises a -``BulkWriteError`` and does not perform any further operations. -``BulkWriteError`` provides a ``details`` attribute that includes the operation +If any of the write operations fail, the {+driver-short+} raises a +``BulkWriteException`` and does not perform any further operations. +``BulkWriteException`` provides a ``details`` attribute that includes the operation that failed, and details about the exception. .. note:: - When {+driver-short+} runs a bulk operation, it uses the ``write_concern`` of the - collection in which the operation is running. The driver reports all write + When the {+driver-short+} executes a bulk write operation, it uses the + ``WriteConcern`` of the + collection on which the operation is running. The driver reports all write concern errors after attempting all operations, regardless of execution order. Customize Bulk Write Operations diff --git a/source/includes/fundamentals/code-examples/BulkWrite.cs b/source/includes/fundamentals/code-examples/BulkWrite.cs index 4a98cfd7..d3cb3c30 100644 --- a/source/includes/fundamentals/code-examples/BulkWrite.cs +++ b/source/includes/fundamentals/code-examples/BulkWrite.cs @@ -45,58 +45,81 @@ static void UpdateMany() // end-bulk-update-many } - -# start-bulk-replace-one - operation = pymongo.ReplaceOne( - { "restaurant_id": "1234" }, + static void ReplaceOne() { - "name": "Mongo's Pizza", - "cuisine": "Pizza", - "borough": "Brooklyn", - "restaurant_id": "5678" + // start-bulk-replace-one + var replaceOneModel = new BulkWriteReplaceOneModel( + "sample_restaurants.restaurants", + Builders.Filter.Eq("restaurant_id", "1234"), + new BsonDocument{ + { "name", "Mongo's Pizza" }, + { "cuisine", "Pizza" }, + { "borough", "Brooklyn" }, + { "restaurant_id", "5678" } + } + ); + // end-bulk-replace-one } -) -# end-bulk-replace-one -# start-bulk-delete-one -operation = pymongo.DeleteOne({ "restaurant_id": "5678" }) -# end-bulk-delete-one + static void DeleteOne() + { + // start-bulk-delete-one + var deleteOneModel = new BulkWriteDeleteOneModel( + "sample_restaurants.restaurants", + Builders.Filter.Eq("restaurant_id", "5678") + ); + // end-bulk-delete-one + } -# start-bulk-delete-many -operation = pymongo.DeleteMany({ "name": "Mongo's Deli" }) -# end-bulk-delete-many + static void DeleteMany() + { + // start-bulk-delete-many + var deleteManyModel = new BulkWriteDeleteManyModel( + "sample_restaurants.restaurants", + Builders.Filter.Eq("name", "Mongo's Deli") + ); + // end-bulk-delete-many + } -# start-bulk-write-mixed -operations = [ - pymongo.InsertOne( - { - "name": "Mongo's Deli", - "cuisine": "Sandwiches", - "borough": "Manhattan", - "restaurant_id": "1234" - } - ), - pymongo.InsertOne( + static void BulkWrite() + { + // start-bulk-write-mixed + var bulkWriteModels = new WriteModel[] { - "name": "Mongo's Deli", - "cuisine": "Sandwiches", - "borough": "Brooklyn", - "restaurant_id": "5678" - } - ), - pymongo.UpdateMany( - { "name": "Mongo's Deli" }, - { "$set": { "cuisine": "Sandwiches and Salads" } }, - ), - pymongo.DeleteOne( - { "restaurant_id": "1234" } - ) -] + new BulkWriteInsertOneModel( + new BsonDocument{ + { "name", "Mongo's Deli" }, + { "cuisine", "Sandwiches" }, + { "borough", "Manhattan" }, + { "restaurant_id", "1234" } + } + ), + new BulkWriteInsertOneModel( + new BsonDocument{ + { "name", "Mongo's Deli" }, + { "cuisine", "Sandwiches" }, + { "borough", "Brooklyn" }, + { "restaurant_id", "5678" } + } + ), + new BulkWriteUpdateManyModel( + Builders.Filter.Eq("name", "Mongo's Deli"), + Builders.Update.Set("cuisine", "Sandwiches and Salads") + ), + new BulkWriteDeleteOneModel( + Builders.Filter.Eq("restaurant_id", "1234") + ) + // end-bulk-write-mixed + }; + + //results = restaurants.bulk_write(operations) + Console.WriteLine("Bulk write results: " + results); + } + +} + -results = restaurants.bulk_write(operations) -print(results) -# end-bulk-write-mixed # start-bulk-write-unordered results = restaurants.bulk_write(operations, ordered = False) From 84a3a8aec0687b926f84b067b983c016e3bfe4ea Mon Sep 17 00:00:00 2001 From: Mike Woofter <108414937+mongoKart@users.noreply.github.com> Date: Wed, 16 Oct 2024 10:20:48 -0500 Subject: [PATCH 05/17] first draft --- .../crud/write-operations/bulk-write.txt | 280 +++++++++++------- .../fundamentals/code-examples/BulkWrite.cs | 103 ++++++- 2 files changed, 270 insertions(+), 113 deletions(-) diff --git a/source/fundamentals/crud/write-operations/bulk-write.txt b/source/fundamentals/crud/write-operations/bulk-write.txt index bd3bdeae..cd79f47c 100644 --- a/source/fundamentals/crud/write-operations/bulk-write.txt +++ b/source/fundamentals/crud/write-operations/bulk-write.txt @@ -259,7 +259,7 @@ constructor accepts the following parameters: | **Data Type:** {+bool-data-type+} | **Default:** ``false`` -The following example creates an instance of the ``BulkWriteReplaceOneyModel`` +The following example creates an instance of the ``BulkWriteReplaceOneModel`` class, and uses ``BsonDocument`` as the type for ``TDocument``. The filter matches the document in the ``sample_restaurants.restaurants`` collection where the value of the ``restaurant_id`` field is ``"1234"``. The replace operation @@ -281,12 +281,49 @@ removes all fields from this document and sets new values in the ``name``, ``cui Delete Operations ~~~~~~~~~~~~~~~~~ -To delete a document, create an instance of the ``BulkWriteDeleteOneModel`` and pass in -a query filter that specifies the document that you want to delete. The -``BulkWriteDeleteOneModel`` operation removes -only the *first document* that matches your query filter. +To delete a document, create an instance of the ``BulkWriteDeleteOneModel`` +class. The ``BulkWriteDeleteOneModel`` constructor accepts the following +parameters: + +.. list-table:: + :header-rows: 1 + :stub-columns: 1 + + * - Parameter + - Description + + * - ``collectionNamespace`` + - | The database and collection to insert the BSON document into. + | + | **Data Type:** {+string-data-type+} or `CollectionNamespace <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.CollectionNamespace.html>`__ + + * - ``filter`` + - | The **query filter** that specifies the criteria used to match documents in your collection. + | The ``DeleteOne`` operation deletes *only the first document* that matches the + | query filter. + | + | **Data Type:** `FilterDefinition <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.FilterDefinition-1.html>`__ -The following example creates an instance of the ``BulkWriteDeleteOneModel`` class: + * - ``collation`` + - | *Optional.* The language collation to use when sorting results. See + | :manual:`the delete statements` + for more information. + | + | **Data Type:** `Collation <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.Collation.html>`__ + | **Default:** ``null`` + + * - ``hint`` + - | *Optional.* The index to use to scan for documents. + See :manual:`the MongoDB server manual` + for more information. + | + | **Data Type:** `BsonValue <{+new-api-root+}/MongoDB.Bson/MongoDB.Bson.BsonValue.html>`__ + | **Default:** ``null`` + +The following example creates an instance of the ``BulkWriteDeleteOneModel`` +class, and uses ``BsonDocument`` as the type for ``TDocument``. The +filter matches the document in the ``sample_restaurants.restaurants`` collection +where the value of the ``restaurant_id`` field is ``"5678"``. .. literalinclude:: /includes/fundamentals/code-examples/BulkWrite.cs :start-after: start-bulk-delete-one @@ -295,12 +332,15 @@ The following example creates an instance of the ``BulkWriteDeleteOneModel`` cla :copyable: :dedent: 8 -To delete multiple documents, create an instance of the ``BulkWriteDeleteManyModel`` +To delete multiple documents, create an instance of the ``BulkWriteDeleteManyModel`` class and pass a query filter that specifies the document that you want to delete. -The ``BulkWriteDeleteManyModel`` operation removes *all* documents that match your +The ``DeleteMany`` operation removes *all documents* that match your query filter. -The following example creates an instance of the ``BulkWriteDeleteManyModel`` class: +The following example creates an instance of the ``BulkWriteDeleteManyModel`` +class, and uses ``BsonDocument`` as the type for ``TDocument``. The +filter matches the document in the ``sample_restaurants.restaurants`` collection +where the value of the ``name`` field is ``"Mongo's Deli"``. .. literalinclude:: /includes/fundamentals/code-examples/BulkWrite.cs :start-after: start-bulk-delete-many @@ -313,45 +353,58 @@ Call the ``BulkWrite()`` Method -------------------------------- After you define a ``BulkWriteModel`` instance for each operation that you want to perform, -pass an ``IList`` of these instances to the ``BulkWrite()`` or ``BulkWriteAsync()`` method. -By default, these methods run the operations in the order -they're defined in the list. +pass an ``IReadOnlyList`` collection of these instances to the ``BulkWrite()`` or +``BulkWriteAsync()`` method. By default, these methods run the operations in the order +they're defined in the collection. + +.. tip:: IReadOnlyList + + ``Array`` and ``List`` are two common classes that implement the ``IReadOnlyList`` + interface. The following code examples show how to use the asynchronous ``BulkWriteAsync()`` method and the synchronous ``BulkWrite()`` method to perform multiple write operations. -.. io-code-block:: +.. tabs:: - .. input:: /includes/fundamentals/code-examples/BulkWrite.cs - :start-after: start-bulk-write-mixed - :end-before: end-bulk-write-mixed - :language: csharp - :dedent: 8 + .. tab:: Asynchronous + :tabid: bulk-write-async - .. output:: - - BulkWriteResult({'writeErrors': [], 'writeConcernErrors': [], 'nInserted': 2, 'nUpserted': 0, 'nMatched': 2, 'nModified': 2, 'nRemoved': 1, 'upserted': []}, acknowledged=True) + .. literalinclude:: /includes/fundamentals/code-examples/BulkWrite.cs + :start-after: start-bulk-write-async + :end-before: end-bulk-write-async + :language: csharp + :copyable: + :dedent: 8 -If any of the write operations fail, the {+driver-short+} raises a -``BulkWriteException`` and does not perform any further operations. -``BulkWriteException`` provides a ``details`` attribute that includes the operation -that failed, and details about the exception. + .. tab:: Synchronous + :tabid: bulk-write-sync + + .. literalinclude:: /includes/fundamentals/code-examples/BulkWrite.cs + :start-after: start-bulk-write-async + :end-before: end-bulk-write-async + :language: csharp + :copyable: + :dedent: 8 -.. note:: +The preceding code examples produce the following output: + +.. code-block:: shell + + BulkWriteResult({'writeErrors': [], 'writeConcernErrors': [], 'nInserted': 2, 'nUpserted': 0, 'nMatched': 2, 'nModified': 2, 'nRemoved': 1, 'upserted': []}, acknowledged=True) - When the {+driver-short+} executes a bulk write operation, it uses the - ``WriteConcern`` of the - collection on which the operation is running. The driver reports all write - concern errors after attempting all operations, regardless of execution order. +If any of the write operations fail, the {+driver-short+} raises a +``BulkWriteException`` and does not perform any further operations. You can examine +the properties of the exception to determine which operation failed. Customize Bulk Write Operations ------------------------------- -The ``bulk_write()`` method optionally accepts additional -parameters, which represent options you can use to configure the bulk write -operation. If you don't specify any additional options, the driver does not customize -the bulk write operation. +When you call the ``BulkWrite()`` or ``BulkWriteAsync()`` method, you can pass an +instance of the ``ClientBulkWriteOptions`` class. The ``ClientBulkWriteOptions`` class +contains the following properties, which represent options you can use to configure the +bulk write operation: .. list-table:: :widths: 30 70 @@ -360,60 +413,84 @@ the bulk write operation. * - Property - Description - * - ``ordered`` - - | If ``True``, the driver performs the write operations in the order - provided. If an error occurs, the remaining operations are not - attempted. - | - | If ``False``, the driver performs the operations in an - arbitrary order and attempts to perform all operations. - | Defaults to ``True``. - - * - ``bypass_document_validation`` + * - ``BypassDocumentValidation`` - | Specifies whether the operation bypasses document-level validation. For more information, see :manual:`Schema - Validation ` in the MongoDB - Server manual. - | Defaults to ``False``. + Validation ` in the {+mdb-server+} + manual. + | Defaults to ``false``. - * - ``session`` - - | An instance of ``ClientSession``. For more information, see the `API - documentation <{+api-root+}pymongo/client_session.html#pymongo.client_session.ClientSession>`__. - - * - ``comment`` - - | A comment to attach to the operation. For more information, see the :manual:`delete command + * - ``Comment`` + - | A comment to attach to the operation, in the form of a ``BsonValue``. For + more information, see the :manual:`delete command fields ` guide in the {+mdb-server+} manual. - * - ``let`` - - | A map of parameter names and values. Values must be constant or closed + * - ``IsOrdered`` + - | If ``true``, the driver performs the write operations in the order + provided. If an error occurs, the remaining operations are not + attempted. + | + | If ``false``, the driver performs the operations in an + arbitrary order and attempts to perform all operations. + | Defaults to ``True``. + + * - ``Let`` + - | A map of parameter names and values, in the form of a ``BsonDocument``. Values + must be constant or closed expressions that don't reference document fields. For more information, see the :manual:`let statement ` in the {+mdb-server+} manual. + + * - ``VerboseResult`` + - | Specifies whether the ``ClientBulkWriteResult`` object returned by the operation + includes detailed results for each successful write operation. + | Defaults to ``false``. -The following example calls the ``bulk_write()`` method from the preceding example, with the ``ordered`` option set -to ``False``: + * - ``WriteConcern`` + - | The write concern to use for the write operation, as a value from the ``WriteConcern`` + enum. + | Defaults to the write concern of the collection on which the operation is running. -.. literalinclude:: /includes/write/bulk-write.py - :start-after: start-bulk-write-unordered - :end-before: end-bulk-write-unordered - :language: python - :copyable: +The following code examples use a ``ClientBulkWriteOptions`` object to customize +a delete operation: + +.. tabs:: + + .. tab:: Asynchronous + :tabid: bulk-write-options-async -If any of the write operations in an unordered bulk write fail, {+driver-short+} -reports the errors only after attempting all operations. + .. literalinclude:: /includes/fundamentals/code-examples/BulkWrite.cs + :start-after: start-bulk-write-options-async + :end-before: end-bulk-write-options-async + :language: csharp + :copyable: + :dedent: 8 -.. note:: + .. tab:: Synchronous + :tabid: bulk-write-options-sync + + .. literalinclude:: /includes/fundamentals/code-examples/BulkWrite.cs + :start-after: start-bulk-write-options-async + :end-before: end-bulk-write-options-async + :language: csharp + :copyable: + :dedent: 8 + +.. note:: Unordered Bulk Write Operations Unordered bulk operations do not guarantee order of execution. The order can differ from the way you list them to optimize the runtime. + + If any of the write operations in an unordered bulk write fail, the {+driver-short+} + reports the errors only after attempting all operations. Return Value ------------ -The ``bulk_write()`` method returns a ``BulkWriteResult`` object. The -``BulkWriteResult`` object contains the following properties: +The ``BulkWrite()`` and ``BulkWriteAsync()`` methods return a ``ClientBulkWriteResult`` +object that contains the following properties: .. list-table:: :widths: 30 70 @@ -422,53 +499,58 @@ The ``bulk_write()`` method returns a ``BulkWriteResult`` object. The * - Property - Description - * - ``acknowledged`` - - | Indicates if the server acknowledged the write operation. + * - ``Acknowledged`` + - | Indicates whether the server acknowledged the bulk write operation. - * - ``bulk_api_result`` - - | The raw bulk API result returned by the server. - - * - ``deleted_count`` + * - ``DeleteResults`` + - | An ``IReadOnlyDictionary`` object containing the + results of each successful delete operation, if any. + + * - ``DeletedCount`` - | The number of documents deleted, if any. - * - ``inserted_count`` + * - ``InsertResults`` + - | An ``IReadOnlyDictionary`` object containing the + results of each successful insert operation, if any. + + * - ``InsertedCount`` - | The number of documents inserted, if any. - * - ``matched_count`` + * - ``MatchedCount`` - | The number of documents matched for an update, if applicable. - * - ``modified_count`` + * - ``ModifiedCount`` - | The number of documents modified, if any. - * - ``upserted_count`` + * - ``UpsertResults`` + - | An ``IReadOnlyDictionary`` object containing the + results of each successful update operation, if any. + + * - ``UpsertedCount`` - | The number of documents upserted, if any. - * - ``upserted_ids`` - - | A map of the operation's index to the ``_id`` of the upserted documents, if - applicable. - Additional Information ---------------------- To learn how to perform individual write operations, see the following guides: -- :ref:`pymongo-write-insert` -- :ref:`pymongo-write-update` -- :ref:`pymongo-write-replace` -- :ref:`pymongo-write-delete` - -API Documentation -~~~~~~~~~~~~~~~~~ +- :ref:`csharp-change-guide` +- :ref:`csharp-insert-guide` +- :ref:`csharp-delete-guide` To learn more about any of the methods or types discussed in this -guide, see the following API Documentation: - -- `bulk_write() <{+api-root+}pymongo/collection.html#pymongo.collection.Collection.bulk_write>`__ -- `InsertOne <{+api-root+}pymongo/operations.html#pymongo.operations.InsertOne>`__ -- `UpdateOne <{+api-root+}pymongo/operations.html#pymongo.operations.UpdateOne>`__ -- `UpdateMany <{+api-root+}pymongo/operations.html#pymongo.operations.UpdateMany>`__ -- `ReplaceOne <{+api-root+}pymongo/operations.html#pymongo.operations.ReplaceOne>`__ -- `DeleteOne <{+api-root+}pymongo/operations.html#pymongo.operations.DeleteOne>`__ -- `DeleteMany <{+api-root+}pymongo/operations.html#pymongo.operations.DeleteMany>`__ -- `BulkWriteResult <{+api-root+}pymongo/results.html#pymongo.results.BulkWriteResult>`__ -- `BulkWriteError <{+api-root+}pymongo/errors.html#pymongo.errors.BulkWriteError>`__ +guide, see the following API documentation: + +- `BulkWrite() <{+new-api-root+}/MongoDB.Driver/MongoClient.BulkWrite.html>`__ +- `BulkWriteAsync() <{+new-api-root+}/MongoDB.Driver/MongoClient.BulkWriteAsync.html>`__ +- `ClientBulkWriteOptions <{+new-api-root+}/MongoDB.Driver/MongoClient.ClientBulkWriteOptions.html>`__ +- `ClientBulkWriteResult <{+new-api-root+}/MongoDB.Driver/MongoClient.ClientBulkWriteResult.html>`__ +- `BulkWriteInsertOneModel <{+new-api-root+}/MongoDB.Driver/MongoClient.BulkWriteInsertOneModel-1.html>`__ +- `BulkWriteUpdateOneModel <{+new-api-root+}/MongoDB.Driver/MongoClient.BulkWriteUpdateOneModel-1.html>`__ +- `BulkWriteUpdateManyModel <{+new-api-root+}/MongoDB.Driver/MongoClient.BulkWriteUpdateManyModel-1.html>`__ +- `BulkWriteReplaceOneModel <{+new-api-root+}/MongoDB.Driver/MongoClient.BulkWriteReplaceOneModel-1.html>`__ +- `BulkWriteDeleteOneModel <{+new-api-root+}/MongoDB.Driver/MongoClient.BulkWriteDeleteOneModel-1.html>`__ +- `BulkWriteDeleteManyModel <{+new-api-root+}/MongoDB.Driver/MongoClient.BulkWriteDeleteManyModel-1.html>`__ +- `BulkWriteInsertOneResult <{+new-api-root+}/MongoDB.Driver/MongoClient.BulkWriteInsertOneResult.html>`__ +- `BulkWriteUpdateResult <{+new-api-root+}/MongoDB.Driver/MongoClient.BulkWriteUpdateResult.html>`__ +- `BulkWriteDeleteResult <{+new-api-root+}/MongoDB.Driver/MongoClient.BulkWriteDeleteResult.html>`__ diff --git a/source/includes/fundamentals/code-examples/BulkWrite.cs b/source/includes/fundamentals/code-examples/BulkWrite.cs index d3cb3c30..ab042de1 100644 --- a/source/includes/fundamentals/code-examples/BulkWrite.cs +++ b/source/includes/fundamentals/code-examples/BulkWrite.cs @@ -2,12 +2,6 @@ class BulkWrite { - static void Main(string[] args) - { - Console.WriteLine("Hello, World!"); - BulkWrite - } - static void InsertOne() { // start-bulk-insert-one @@ -81,12 +75,16 @@ static void DeleteMany() // end-bulk-delete-many } - static void BulkWrite() + static void BulkWriteSync() { - // start-bulk-write-mixed + // start-bulk-write-sync + var client = new MongoClient("mongodb://localhost:27017"); + var collection = "sample_restaurants.restaurants"; + var bulkWriteModels = new WriteModel[] { new BulkWriteInsertOneModel( + collection, new BsonDocument{ { "name", "Mongo's Deli" }, { "cuisine", "Sandwiches" }, @@ -95,6 +93,7 @@ static void BulkWrite() } ), new BulkWriteInsertOneModel( + collection, new BsonDocument{ { "name", "Mongo's Deli" }, { "cuisine", "Sandwiches" }, @@ -103,24 +102,100 @@ static void BulkWrite() } ), new BulkWriteUpdateManyModel( + ,collection Builders.Filter.Eq("name", "Mongo's Deli"), Builders.Update.Set("cuisine", "Sandwiches and Salads") ), new BulkWriteDeleteOneModel( + collection, Builders.Filter.Eq("restaurant_id", "1234") ) - // end-bulk-write-mixed }; - //results = restaurants.bulk_write(operations) + var results = client.BulkWriteSync(bulkWriteModels); Console.WriteLine("Bulk write results: " + results); + // start-bulk-write-sync } + static async void BulkWriteAsync() + { + // start-bulk-write-async + var client = new MongoClient("mongodb://localhost:27017"); + var collection = "sample_restaurants.restaurants"; -} + var bulkWriteModels = new WriteModel[] + { + new BulkWriteInsertOneModel( + collection, + new BsonDocument{ + { "name", "Mongo's Deli" }, + { "cuisine", "Sandwiches" }, + { "borough", "Manhattan" }, + { "restaurant_id", "1234" } + } + ), + new BulkWriteInsertOneModel( + collection, + new BsonDocument{ + { "name", "Mongo's Deli" }, + { "cuisine", "Sandwiches" }, + { "borough", "Brooklyn" }, + { "restaurant_id", "5678" } + } + ), + new BulkWriteUpdateManyModel( + ,collection + Builders.Filter.Eq("name", "Mongo's Deli"), + Builders.Update.Set("cuisine", "Sandwiches and Salads") + ), + new BulkWriteDeleteOneModel( + collection, + Builders.Filter.Eq("restaurant_id", "1234") + ) + }; + + var results = await client.BulkWriteAsync(bulkWriteModels); + Console.WriteLine("Bulk write results: " + results); + // end-bulk-write-async + } + + static void BulkWriteOptionsSync() + { + // start-bulk-write-options-sync + var client = new MongoClient("mongodb://localhost:27017"); + + var deleteOneModel = new BulkWriteDeleteOneModel( + "sample_restaurants.restaurants", + Builders.Filter.Eq("restaurant_id", "5678") + ); + var clientBulkWriteOptions = new ClientBulkWriteOptions + { + IsOrdered = false, + WriteConcern = WriteConcern.Unacknowledged, + VerboseResult = true + }; + var results = client.BulkWriteSync(deleteOneModel, clientBulkWriteOptions); + // end-bulk-write-options-sync + } + static async void BulkWriteOptionsAsync() + { + // start-bulk-write-options-async + var client = new MongoClient("mongodb://localhost:27017"); + var deleteOneModel = new BulkWriteDeleteOneModel( + "sample_restaurants.restaurants", + Builders.Filter.Eq("restaurant_id", "5678") + ); + + var clientBulkWriteOptions = new ClientBulkWriteOptions + { + IsOrdered = false, + WriteConcern = WriteConcern.Unacknowledged, + VerboseResult = true + }; -# start-bulk-write-unordered -results = restaurants.bulk_write(operations, ordered = False) -# end-bulk-write-unordered \ No newline at end of file + var results = await client.BulkWriteAsync(deleteOneModel, clientBulkWriteOptions); + // end-bulk-write-options-async + } +} \ No newline at end of file From b3d5494385ec4b67e8ea3b0d06eaa54fa9732d6c Mon Sep 17 00:00:00 2001 From: Mike Woofter <108414937+mongoKart@users.noreply.github.com> Date: Wed, 16 Oct 2024 10:49:41 -0500 Subject: [PATCH 06/17] build fixes --- source/fundamentals/crud/write-operations.txt | 4 +++- source/fundamentals/crud/write-operations/bulk-write.txt | 3 +-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/source/fundamentals/crud/write-operations.txt b/source/fundamentals/crud/write-operations.txt index 67fdd956..ec132498 100644 --- a/source/fundamentals/crud/write-operations.txt +++ b/source/fundamentals/crud/write-operations.txt @@ -13,7 +13,9 @@ Write Operations /fundamentals/crud/write-operations/insert /fundamentals/crud/write-operations/modify /fundamentals/crud/write-operations/delete + /fundamentals/crud/write-operations/bulk-write +- :ref:`csharp-insert-guide` - :ref:`csharp-change-guide` - :ref:`csharp-delete-guide` -- :ref:`csharp-insert-guide` +- :ref:`csharp-bulk-write` diff --git a/source/fundamentals/crud/write-operations/bulk-write.txt b/source/fundamentals/crud/write-operations/bulk-write.txt index cd79f47c..4c83781f 100644 --- a/source/fundamentals/crud/write-operations/bulk-write.txt +++ b/source/fundamentals/crud/write-operations/bulk-write.txt @@ -32,7 +32,7 @@ Sample Data The examples in this guide use the ``sample_restaurants.restaurants`` collection from the :atlas:`Atlas sample datasets `. To learn how to create a free MongoDB Atlas cluster and load the sample datasets, see the -:ref:`` tutorial. +:ref:`` tutorial. Define the Write Operations --------------------------- @@ -71,7 +71,6 @@ The ``BulkWriteInsertOneModel`` constructor accepts the following par .. list-table:: :header-rows: 1 :stub-columns: 1 - :widths: 10 10 20 (Optional) * - Parameter - Description From 2a8b99b2d04b003f2531b41adcb7511321a7a847 Mon Sep 17 00:00:00 2001 From: Mike Woofter <108414937+mongoKart@users.noreply.github.com> Date: Wed, 16 Oct 2024 11:12:22 -0500 Subject: [PATCH 07/17] fixes --- .../crud/write-operations/bulk-write.txt | 79 +++++++++---------- 1 file changed, 38 insertions(+), 41 deletions(-) diff --git a/source/fundamentals/crud/write-operations/bulk-write.txt b/source/fundamentals/crud/write-operations/bulk-write.txt index 4c83781f..d8fd3bd4 100644 --- a/source/fundamentals/crud/write-operations/bulk-write.txt +++ b/source/fundamentals/crud/write-operations/bulk-write.txt @@ -38,7 +38,7 @@ Define the Write Operations --------------------------- For each write operation you want to perform, create an instance of one of -the following operation classes: +the following ``BulkWriteModel`` classes: - ``BulkWriteInsertOneModel`` - ``BulkWriteUpdateOneModel`` @@ -47,15 +47,12 @@ the following operation classes: - ``BulkWriteDeleteOneModel`` - ``BulkWriteDeleteManyModel`` -Then, pass an ``IReadOnlyList`` of the instances you created to the -``MongoClient.BulkWrite()`` or ``MongoClient.BulkWriteAsync()`` method. - The following sections show how to create and use instances of the preceding classes. .. tip:: Bulk Write Operations with POCOs The examples in this guide use ``BsonDocument`` as the type for ``TDocument``. - You can also use a Plain Old CLR Objects (POCO) as the type for ``TDocument``. + You can also use a Plain Old CLR Object (POCO) as the type for ``TDocument``. To use a POCO, define a class that represents the documents in your collection. The class must have properties that match the fields in your documents. @@ -123,22 +120,21 @@ parameters: * - ``filter`` - | The **query filter** that specifies the criteria used to match documents in your collection. - | The ``UpdateOne`` operation updates *only the first document* that matches the - | query filter. + The ``UpdateOne`` operation updates *only the first document* that matches the + query filter. | | **Data Type:** `FilterDefinition <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.FilterDefinition-1.html>`__ * - ``update`` - | The update operation you want to perform. For more information about update - | operations, see - | :manual:`Field Update Operators ` in the - | {+mdb-server+} manual. + operations, see :manual:`Field Update Operators ` + in the {+mdb-server+} manual. | | **Data Type:** `UpdateDefinition <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.UpdateDefinition-1.html>`__ * - ``collation`` - - | *Optional.* The language collation to use when sorting results. See - | :manual:`the delete statements` + - | *Optional.* The language collation to use when sorting results. See the + :manual:`{+mdb+server+} manual` for more information. | | **Data Type:** `Collation <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.Collation.html>`__ @@ -146,7 +142,7 @@ parameters: * - ``hint`` - | *Optional.* The index to use to scan for documents. - See :manual:`the MongoDB server manual` + See the :manual:`{+mdb-server+} manual` for more information. | | **Data Type:** `BsonValue <{+new-api-root+}/MongoDB.Bson/MongoDB.Bson.BsonValue.html>`__ @@ -154,17 +150,16 @@ parameters: * - ``isUpsert`` - | *Optional.* Specifies whether the update operation performs an upsert operation if no - | documents match the query filter. - | See :manual:`the MongoDB server manual ` - | for more information. + documents match the query filter. See the :manual:`{+mdb-server+} manual` + for more information. | | **Data Type:** {+bool-data-type+} | **Default:** ``false`` * - ``arrayFilters`` - | Specifies which array elements to modify for an update operation on an array field. - | See :manual:`the MongoDB server manual` - | for more information. + See the :manual:`{+mdb-server+} manual` + for more information. | | **Data Type:** `IEnumerable `__ | **Default:** ``null`` @@ -222,20 +217,20 @@ constructor accepts the following parameters: * - ``filter`` - | The **query filter** that specifies the criteria used to match documents in your collection. - | The ``UpdateOne`` operation updates *only the first document* that matches the - | query filter. + The ``UpdateOne`` operation updates *only the first document* that matches the + query filter. | | **Data Type:** `FilterDefinition <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.FilterDefinition-1.html>`__ * - ``replacement`` - | The replacement document, which specifies the fields and values to insert in the - | target document. + target document. | | **Data Type:** ``TDocument`` * - ``collation`` - | *Optional.* The language collation to use when sorting results. See - | :manual:`the delete statements` + the :manual:`{+mdb-server+} manual` for more information. | | **Data Type:** `Collation <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.Collation.html>`__ @@ -243,7 +238,7 @@ constructor accepts the following parameters: * - ``hint`` - | *Optional.* The index to use to scan for documents. - See :manual:`the MongoDB server manual` + See the :manual:`{+mdb-server+} manual` for more information. | | **Data Type:** `BsonValue <{+new-api-root+}/MongoDB.Bson/MongoDB.Bson.BsonValue.html>`__ @@ -251,9 +246,9 @@ constructor accepts the following parameters: * - ``isUpsert`` - | *Optional.* Specifies whether the update operation performs an upsert operation if no - | documents match the query filter. - | See :manual:`the MongoDB server manual ` - | for more information. + documents match the query filter. + See the :manual:`{+mdb-server+} manual` + for more information. | | **Data Type:** {+bool-data-type+} | **Default:** ``false`` @@ -274,7 +269,7 @@ removes all fields from this document and sets new values in the ``name``, ``cui .. tip:: Replace Multiple Documents - To replace multiple documents, you must create an instance of the + To replace multiple documents, create an instance of the ``BulkWriteReplaceOneModel`` class for each document you want to replace. Delete Operations @@ -298,14 +293,14 @@ parameters: * - ``filter`` - | The **query filter** that specifies the criteria used to match documents in your collection. - | The ``DeleteOne`` operation deletes *only the first document* that matches the - | query filter. + The ``DeleteOne`` operation deletes *only the first document* that matches the + query filter. | | **Data Type:** `FilterDefinition <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.FilterDefinition-1.html>`__ * - ``collation`` - | *Optional.* The language collation to use when sorting results. See - | :manual:`the delete statements` + the :manual:`{+mdb-server+} manual` for more information. | | **Data Type:** `Collation <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.Collation.html>`__ @@ -313,7 +308,7 @@ parameters: * - ``hint`` - | *Optional.* The index to use to scan for documents. - See :manual:`the MongoDB server manual` + See the :manual:`{+mdb-server+} manual` for more information. | | **Data Type:** `BsonValue <{+new-api-root+}/MongoDB.Bson/MongoDB.Bson.BsonValue.html>`__ @@ -348,8 +343,8 @@ where the value of the ``name`` field is ``"Mongo's Deli"``. :copyable: :dedent: 8 -Call the ``BulkWrite()`` Method --------------------------------- +Run the Write Operations +------------------------ After you define a ``BulkWriteModel`` instance for each operation that you want to perform, pass an ``IReadOnlyList`` collection of these instances to the ``BulkWrite()`` or @@ -381,8 +376,8 @@ perform multiple write operations. :tabid: bulk-write-sync .. literalinclude:: /includes/fundamentals/code-examples/BulkWrite.cs - :start-after: start-bulk-write-async - :end-before: end-bulk-write-async + :start-after: start-bulk-write-sync + :end-before: end-bulk-write-sync :language: csharp :copyable: :dedent: 8 @@ -393,9 +388,11 @@ The preceding code examples produce the following output: BulkWriteResult({'writeErrors': [], 'writeConcernErrors': [], 'nInserted': 2, 'nUpserted': 0, 'nMatched': 2, 'nModified': 2, 'nRemoved': 1, 'upserted': []}, acknowledged=True) -If any of the write operations fail, the {+driver-short+} raises a -``BulkWriteException`` and does not perform any further operations. You can examine -the properties of the exception to determine which operation failed. +.. tip:: Troubleshooting Bulk Write Operations + + If any of the write operations fail, the {+driver-short+} raises a + ``BulkWriteException`` and does not perform any further operations. You can examine + the properties of the exception to determine which operation failed. Customize Bulk Write Operations ------------------------------- @@ -471,8 +468,8 @@ a delete operation: :tabid: bulk-write-options-sync .. literalinclude:: /includes/fundamentals/code-examples/BulkWrite.cs - :start-after: start-bulk-write-options-async - :end-before: end-bulk-write-options-async + :start-after: start-bulk-write-options-sync + :end-before: end-bulk-write-options-sync :language: csharp :copyable: :dedent: 8 @@ -482,7 +479,7 @@ a delete operation: Unordered bulk operations do not guarantee order of execution. The order can differ from the way you list them to optimize the runtime. - If any of the write operations in an unordered bulk write fail, the {+driver-short+} + If any of the write operations in an unordered bulk write fail, the driver reports the errors only after attempting all operations. Return Value From a335ac22ccb521cd08840bece1f51c104eef35b8 Mon Sep 17 00:00:00 2001 From: Mike Woofter <108414937+mongoKart@users.noreply.github.com> Date: Wed, 16 Oct 2024 11:17:00 -0500 Subject: [PATCH 08/17] fix includes --- source/includes/fundamentals/code-examples/BulkWrite.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/includes/fundamentals/code-examples/BulkWrite.cs b/source/includes/fundamentals/code-examples/BulkWrite.cs index ab042de1..8e552ba7 100644 --- a/source/includes/fundamentals/code-examples/BulkWrite.cs +++ b/source/includes/fundamentals/code-examples/BulkWrite.cs @@ -114,7 +114,7 @@ static void BulkWriteSync() var results = client.BulkWriteSync(bulkWriteModels); Console.WriteLine("Bulk write results: " + results); - // start-bulk-write-sync + // end-bulk-write-sync } static async void BulkWriteAsync() { From 7a1729b6b9aecb4b5fa56f932785dc03f9ed3da8 Mon Sep 17 00:00:00 2001 From: Mike Woofter <108414937+mongoKart@users.noreply.github.com> Date: Wed, 16 Oct 2024 15:57:00 -0500 Subject: [PATCH 09/17] update what's new --- source/whats-new.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source/whats-new.txt b/source/whats-new.txt index a4c51e9d..83963981 100644 --- a/source/whats-new.txt +++ b/source/whats-new.txt @@ -152,6 +152,9 @@ The 3.0 driver release includes the following new features: To learn more about using the aggregation pipeline with the {+driver-short+}, see :ref:`csharp-aggregation`. +- Adds an API for bulk write operations. To learn more about bulk write operations, see + :ref:`csharp-bulk-write`. + For more information about this release, see the :github:`v3.0 release notes `. From 3013cab098d5b6de38931730785fbc6830cc7b3a Mon Sep 17 00:00:00 2001 From: Mike Woofter <108414937+mongoKart@users.noreply.github.com> Date: Fri, 18 Oct 2024 08:06:41 -0500 Subject: [PATCH 10/17] merge --- .../crud/write-operations/bulk-write.txt | 37 ++++++++++--------- .../fundamentals/code-examples/BulkWrite.cs | 4 +- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/source/fundamentals/crud/write-operations/bulk-write.txt b/source/fundamentals/crud/write-operations/bulk-write.txt index d8fd3bd4..5512914b 100644 --- a/source/fundamentals/crud/write-operations/bulk-write.txt +++ b/source/fundamentals/crud/write-operations/bulk-write.txt @@ -20,11 +20,14 @@ Bulk Write Operations Overview -------- +This guide shows you how to use the {+driver-short+} to perform **bulk write operations** +that include multiple write operations in a single database call. + Consider a scenario in which you want to insert a document into a collection, update multiple other documents, then delete a document. If you use -individual methods, each operation requires its own database call. This guide -shows you how to use bulk write operations to perform multiple write operations -in a single database call. +individual methods, each operation requires its own database call. If you use +a bulk write operation, you can improve efficiency by performing multiple write +operations in a single database call. Sample Data ~~~~~~~~~~~ @@ -51,11 +54,10 @@ The following sections show how to create and use instances of the preceding cla .. tip:: Bulk Write Operations with POCOs - The examples in this guide use ``BsonDocument`` as the type for ``TDocument``. - You can also use a Plain Old CLR Object (POCO) as the type for ``TDocument``. - - To use a POCO, define a class that represents the documents in your collection. - The class must have properties that match the fields in your documents. + The examples in this guide use the ``BsonDocument`` type for the ``TDocument`` type + in all generic classes. You can also use a Plain Old CLR Object (POCO) for these + classes. To do so, you must define a class that represents the documents in your + collection. The class must have properties that match the fields in your documents. For more information, see :ref:``. Insert Operations @@ -164,11 +166,11 @@ parameters: | **Data Type:** `IEnumerable `__ | **Default:** ``null`` -The following example creates an instance of the ``BulkWriteUpdateOneModel`` -class, and uses ``BsonDocument`` as the type for ``TDocument``. The -filter matches the first document in the ``sample_restaurants.restaurants`` collection -where the value of the ``name`` field is ``"Mongo's Deli"``. The update operation sets -the value of the ``cuisine`` field to ``"Sandwiches and Salads"``. +In the following code example, the ``BulkWriteUpdateOneModel`` object +represents an update operation on the ``sample_restaurants.restaurants`` collection. +The operation matches the first document in the collection where the value of the ``name`` +field is ``"Mongo's Deli"``. It then updates the value of the ``cuisine`` field in the +matched document to ``"Sandwiches and Salads"``. .. literalinclude:: /includes/fundamentals/code-examples/BulkWrite.cs :start-after: start-bulk-update-one @@ -347,9 +349,10 @@ Run the Write Operations ------------------------ After you define a ``BulkWriteModel`` instance for each operation that you want to perform, -pass an ``IReadOnlyList`` collection of these instances to the ``BulkWrite()`` or -``BulkWriteAsync()`` method. By default, these methods run the operations in the order -they're defined in the collection. +create an instance of a class that implements the ``IReadOnlyList`` interface. Add your +``BulkWriteModel`` objects to this ``IReadOnlyList``, then pass the ``IReadOnlyList`` +to the ``BulkWrite()`` or ``BulkWriteAsync()`` method. By default, these methods run +the operations in the order they're defined in the collection. .. tip:: IReadOnlyList @@ -388,7 +391,7 @@ The preceding code examples produce the following output: BulkWriteResult({'writeErrors': [], 'writeConcernErrors': [], 'nInserted': 2, 'nUpserted': 0, 'nMatched': 2, 'nModified': 2, 'nRemoved': 1, 'upserted': []}, acknowledged=True) -.. tip:: Troubleshooting Bulk Write Operations +.. tip:: If any of the write operations fail, the {+driver-short+} raises a ``BulkWriteException`` and does not perform any further operations. You can examine diff --git a/source/includes/fundamentals/code-examples/BulkWrite.cs b/source/includes/fundamentals/code-examples/BulkWrite.cs index 8e552ba7..6a8ba3e0 100644 --- a/source/includes/fundamentals/code-examples/BulkWrite.cs +++ b/source/includes/fundamentals/code-examples/BulkWrite.cs @@ -81,7 +81,7 @@ static void BulkWriteSync() var client = new MongoClient("mongodb://localhost:27017"); var collection = "sample_restaurants.restaurants"; - var bulkWriteModels = new WriteModel[] + var bulkWriteModels = new[] { new BulkWriteInsertOneModel( collection, @@ -122,7 +122,7 @@ static async void BulkWriteAsync() var client = new MongoClient("mongodb://localhost:27017"); var collection = "sample_restaurants.restaurants"; - var bulkWriteModels = new WriteModel[] + var bulkWriteModels = new[] { new BulkWriteInsertOneModel( collection, From 8afa5b82ca59b1b2ac7d0c7339a57b83fe557b29 Mon Sep 17 00:00:00 2001 From: Mike Woofter <108414937+mongoKart@users.noreply.github.com> Date: Fri, 18 Oct 2024 08:19:53 -0500 Subject: [PATCH 11/17] feedback --- .../crud/write-operations/bulk-write.txt | 12 +++--------- .../includes/fundamentals/code-examples/BulkWrite.cs | 4 ++-- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/source/fundamentals/crud/write-operations/bulk-write.txt b/source/fundamentals/crud/write-operations/bulk-write.txt index 5512914b..96d60f47 100644 --- a/source/fundamentals/crud/write-operations/bulk-write.txt +++ b/source/fundamentals/crud/write-operations/bulk-write.txt @@ -431,7 +431,9 @@ bulk write operation: attempted. | | If ``false``, the driver performs the operations in an - arbitrary order and attempts to perform all operations. + arbitrary order and attempts to perform all operations. If any of the write + operations in an unordered bulk write fail, the driver + reports the errors only after attempting all operations. | Defaults to ``True``. * - ``Let`` @@ -477,14 +479,6 @@ a delete operation: :copyable: :dedent: 8 -.. note:: Unordered Bulk Write Operations - - Unordered bulk operations do not guarantee order of execution. The order can - differ from the way you list them to optimize the runtime. - - If any of the write operations in an unordered bulk write fail, the driver - reports the errors only after attempting all operations. - Return Value ------------ diff --git a/source/includes/fundamentals/code-examples/BulkWrite.cs b/source/includes/fundamentals/code-examples/BulkWrite.cs index 6a8ba3e0..b71d0c45 100644 --- a/source/includes/fundamentals/code-examples/BulkWrite.cs +++ b/source/includes/fundamentals/code-examples/BulkWrite.cs @@ -102,7 +102,7 @@ static void BulkWriteSync() } ), new BulkWriteUpdateManyModel( - ,collection + collection, Builders.Filter.Eq("name", "Mongo's Deli"), Builders.Update.Set("cuisine", "Sandwiches and Salads") ), @@ -143,7 +143,7 @@ static async void BulkWriteAsync() } ), new BulkWriteUpdateManyModel( - ,collection + collection, Builders.Filter.Eq("name", "Mongo's Deli"), Builders.Update.Set("cuisine", "Sandwiches and Salads") ), From 4ee975f4eec66a5365ec403278d1025dbdd346c7 Mon Sep 17 00:00:00 2001 From: Mike Woofter <108414937+mongoKart@users.noreply.github.com> Date: Fri, 18 Oct 2024 13:11:31 -0500 Subject: [PATCH 12/17] Apply suggestions from code review Co-authored-by: Rea Rustagi <85902999+rustagir@users.noreply.github.com> --- source/fundamentals/crud/write-operations/bulk-write.txt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/source/fundamentals/crud/write-operations/bulk-write.txt b/source/fundamentals/crud/write-operations/bulk-write.txt index 96d60f47..98888eb1 100644 --- a/source/fundamentals/crud/write-operations/bulk-write.txt +++ b/source/fundamentals/crud/write-operations/bulk-write.txt @@ -50,7 +50,8 @@ the following ``BulkWriteModel`` classes: - ``BulkWriteDeleteOneModel`` - ``BulkWriteDeleteManyModel`` -The following sections show how to create and use instances of the preceding classes. +The following sections show how to create and use instances of the preceding classes +to perform the corresponding write operation in a bulk write. .. tip:: Bulk Write Operations with POCOs @@ -104,7 +105,7 @@ into the ``sample_restaurants.restaurants`` collection. Update Operations ~~~~~~~~~~~~~~~~~ -To update a document, create an instance of the ``BulkWriteUpdateOneModel`` +To update a single document, create an instance of the ``BulkWriteUpdateOneModel`` class. The ``BulkWriteUpdateOneModel`` constructor accepts the following parameters: @@ -359,9 +360,9 @@ the operations in the order they're defined in the collection. ``Array`` and ``List`` are two common classes that implement the ``IReadOnlyList`` interface. -The following code examples show how to use the asynchronous +Select from the following tabs to view how to use the asynchronous ``BulkWriteAsync()`` method and the synchronous ``BulkWrite()`` method to -perform multiple write operations. +perform a bulk write operation. .. tabs:: From 9c4f7bfa03d7f627388f0a1ae649bd1c7da23856 Mon Sep 17 00:00:00 2001 From: Mike Woofter <108414937+mongoKart@users.noreply.github.com> Date: Tue, 22 Oct 2024 09:57:31 -0500 Subject: [PATCH 13/17] rr feedback --- .../crud/write-operations/bulk-write.txt | 42 ++++++++++--------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/source/fundamentals/crud/write-operations/bulk-write.txt b/source/fundamentals/crud/write-operations/bulk-write.txt index 98888eb1..9d5440ec 100644 --- a/source/fundamentals/crud/write-operations/bulk-write.txt +++ b/source/fundamentals/crud/write-operations/bulk-write.txt @@ -86,9 +86,8 @@ The ``BulkWriteInsertOneModel`` constructor accepts the following par | **Data Type:** ``TDocument`` The following example creates an instance of the ``BulkWriteInsertOneModel`` -class. The -``BsonDocument`` object represents a new restaurant named "Mongo's Deli" to be inserted -into the ``sample_restaurants.restaurants`` collection. +class. This instance directs the driver to insert a document in which the ``"name"`` field +is ``"Mongo's Deli"`` into the ``sample_restaurants.restaurants`` collection. .. literalinclude:: /includes/fundamentals/code-examples/BulkWrite.cs :start-after: start-bulk-insert-one @@ -186,10 +185,10 @@ accepts the same parameters as the ``BulkWriteUpdateOneModel`` constr The ``BulkWriteUpdateManyModel`` operation updates *all documents* that match your query filter. -The following example creates an instance of the ``BulkWriteUpdateManyModel`` -class, and uses ``BsonDocument`` as the type for ``TDocument``. The -filter matches all documents in the ``sample_restaurants.restaurants`` collection -where the value of the ``name`` field is ``"Mongo's Deli"``. The update operation sets +In the following code example, the ``BulkWriteUpdateManyModel`` object +represents an update operation on the ``sample_restaurants.restaurants`` collection. +The operation matches all documents in the collection where +the value of the ``name`` field is ``"Mongo's Deli"``. It then updates the value of the ``cuisine`` field to ``"Sandwiches and Salads"``. .. literalinclude:: /includes/fundamentals/code-examples/BulkWrite.cs @@ -256,12 +255,12 @@ constructor accepts the following parameters: | **Data Type:** {+bool-data-type+} | **Default:** ``false`` -The following example creates an instance of the ``BulkWriteReplaceOneModel`` -class, and uses ``BsonDocument`` as the type for ``TDocument``. The -filter matches the document in the ``sample_restaurants.restaurants`` collection -where the value of the ``restaurant_id`` field is ``"1234"``. The replace operation -removes all fields from this document and sets new values in the ``name``, ``cuisine``, -``borough``, and ``restaurant_id`` fields. +In the following example, the ``BulkWriteReplaceOneModel`` object +represents a replace operation on the ``sample_restaurants.restaurants`` collection. +The operation matches the document in the collection +where the value of the ``restaurant_id`` field is ``"1234"``. It then +removes all fields other than ``_id`` from this document, and sets new values in the +``name``, ``cuisine``, ``borough``, and ``restaurant_id`` fields. .. literalinclude:: /includes/fundamentals/code-examples/BulkWrite.cs :start-after: start-bulk-replace-one @@ -317,9 +316,9 @@ parameters: | **Data Type:** `BsonValue <{+new-api-root+}/MongoDB.Bson/MongoDB.Bson.BsonValue.html>`__ | **Default:** ``null`` -The following example creates an instance of the ``BulkWriteDeleteOneModel`` -class, and uses ``BsonDocument`` as the type for ``TDocument``. The -filter matches the document in the ``sample_restaurants.restaurants`` collection +In the following code example, the ``BulkWriteDeleteOneModel`` object +represents a delete operation on the ``sample_restaurants.restaurants`` collection. +The operation matches and deletes the first document where the value of the ``restaurant_id`` field is ``"5678"``. .. literalinclude:: /includes/fundamentals/code-examples/BulkWrite.cs @@ -334,9 +333,14 @@ class and pass a query filter that specifies the document that you want to delet The ``DeleteMany`` operation removes *all documents* that match your query filter. -The following example creates an instance of the ``BulkWriteDeleteManyModel`` -class, and uses ``BsonDocument`` as the type for ``TDocument``. The -filter matches the document in the ``sample_restaurants.restaurants`` collection +In the following code example, the ``BulkWriteDeleteOneModel`` object +represents a delete operation on the ``sample_restaurants.restaurants`` collection. +The operation matches and deletes the first document +where the value of the ``restaurant_id`` field is ``"5678"``. + +In the following code example, the ``BulkWriteDeleteManyModel`` object +represents a delete operation on the ``sample_restaurants.restaurants`` collection. +The operation matches and deletes all documents where the value of the ``name`` field is ``"Mongo's Deli"``. .. literalinclude:: /includes/fundamentals/code-examples/BulkWrite.cs From 127e288cd78ede7d2dcb0750d6ed92d17fa5bddf Mon Sep 17 00:00:00 2001 From: Mike Woofter <108414937+mongoKart@users.noreply.github.com> Date: Tue, 22 Oct 2024 09:57:35 -0500 Subject: [PATCH 14/17] feedback --- source/fundamentals/crud/write-operations/bulk-write.txt | 5 ----- 1 file changed, 5 deletions(-) diff --git a/source/fundamentals/crud/write-operations/bulk-write.txt b/source/fundamentals/crud/write-operations/bulk-write.txt index 9d5440ec..6e9e6eb8 100644 --- a/source/fundamentals/crud/write-operations/bulk-write.txt +++ b/source/fundamentals/crud/write-operations/bulk-write.txt @@ -333,11 +333,6 @@ class and pass a query filter that specifies the document that you want to delet The ``DeleteMany`` operation removes *all documents* that match your query filter. -In the following code example, the ``BulkWriteDeleteOneModel`` object -represents a delete operation on the ``sample_restaurants.restaurants`` collection. -The operation matches and deletes the first document -where the value of the ``restaurant_id`` field is ``"5678"``. - In the following code example, the ``BulkWriteDeleteManyModel`` object represents a delete operation on the ``sample_restaurants.restaurants`` collection. The operation matches and deletes all documents From 9911dd0412a14a6e3529a98bba287dacbdd5f60c Mon Sep 17 00:00:00 2001 From: Mike Woofter <108414937+mongoKart@users.noreply.github.com> Date: Tue, 22 Oct 2024 10:07:25 -0500 Subject: [PATCH 15/17] feedback --- .../fundamentals/crud/write-operations/bulk-write.txt | 11 ++++------- source/whats-new.txt | 4 ++-- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/source/fundamentals/crud/write-operations/bulk-write.txt b/source/fundamentals/crud/write-operations/bulk-write.txt index 6e9e6eb8..6a474e2d 100644 --- a/source/fundamentals/crud/write-operations/bulk-write.txt +++ b/source/fundamentals/crud/write-operations/bulk-write.txt @@ -21,13 +21,10 @@ Overview -------- This guide shows you how to use the {+driver-short+} to perform **bulk write operations** -that include multiple write operations in a single database call. - -Consider a scenario in which you want to insert a document into a collection, -update multiple other documents, then delete a document. If you use -individual methods, each operation requires its own database call. If you use -a bulk write operation, you can improve efficiency by performing multiple write -operations in a single database call. +from your ``MongoClient`` instance. A bulk write operation is a single database call +that performs multiple write operations on one or more MongoDB collections. This is more +efficient than performing multiple individual write operations because it reduces the +number of round trips between your application and the database. Sample Data ~~~~~~~~~~~ diff --git a/source/whats-new.txt b/source/whats-new.txt index 83963981..6fff4b91 100644 --- a/source/whats-new.txt +++ b/source/whats-new.txt @@ -152,8 +152,8 @@ The 3.0 driver release includes the following new features: To learn more about using the aggregation pipeline with the {+driver-short+}, see :ref:`csharp-aggregation`. -- Adds an API for bulk write operations. To learn more about bulk write operations, see - :ref:`csharp-bulk-write`. +- Adds a ``MongoClient`` API for bulk write operations. To learn more about bulk write + operations, see :ref:`csharp-bulk-write`. For more information about this release, see the :github:`v3.0 release notes `. From 95d479cb2889e6b07447dc03adb4ccbf3f1b3f28 Mon Sep 17 00:00:00 2001 From: Mike Woofter <108414937+mongoKart@users.noreply.github.com> Date: Tue, 29 Oct 2024 15:54:47 -0500 Subject: [PATCH 16/17] feedback --- .../crud/write-operations/bulk-write.txt | 50 ++++++++++++++++--- .../fundamentals/code-examples/BulkWrite.cs | 8 +-- 2 files changed, 47 insertions(+), 11 deletions(-) diff --git a/source/fundamentals/crud/write-operations/bulk-write.txt b/source/fundamentals/crud/write-operations/bulk-write.txt index 6a474e2d..55834b12 100644 --- a/source/fundamentals/crud/write-operations/bulk-write.txt +++ b/source/fundamentals/crud/write-operations/bulk-write.txt @@ -388,12 +388,6 @@ The preceding code examples produce the following output: BulkWriteResult({'writeErrors': [], 'writeConcernErrors': [], 'nInserted': 2, 'nUpserted': 0, 'nMatched': 2, 'nModified': 2, 'nRemoved': 1, 'upserted': []}, acknowledged=True) -.. tip:: - - If any of the write operations fail, the {+driver-short+} raises a - ``BulkWriteException`` and does not perform any further operations. You can examine - the properties of the exception to determine which operation failed. - Customize Bulk Write Operations ------------------------------- @@ -490,7 +484,9 @@ object that contains the following properties: - Description * - ``Acknowledged`` - - | Indicates whether the server acknowledged the bulk write operation. + - | Indicates whether the server acknowledged the bulk write operation. If the + value of this property is ``false`` and you try to access any other property + of the ``ClientBulkWriteResult`` object, the driver throws an exception. * - ``DeleteResults`` - | An ``IReadOnlyDictionary`` object containing the @@ -519,6 +515,45 @@ object that contains the following properties: * - ``UpsertedCount`` - | The number of documents upserted, if any. +Handling Exceptions +------------------- + +If any of the operations in a bulk write operation fail, the {+driver-short+} throws a +``ClientBulkWriteException`` and does not perform any further operations. + +A ``ClientBulkWriteException`` object contains the following properties: + +.. list-table:: + :header-rows: 1 + :stub-columns: 1 + + * - Property + - Description + * - ``connectionId`` + - | The connection identifier. + | + | **Data Type:** `ConnectionId <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.Core.Connections.ConnectionId.html>`__ + * - ``message`` + - | The error message. + | + | **Data Type:** {+string-data-type+} + * - ``writeErrors`` + - | A dictionary of errors that occurred during the bulk write operation. + | + | **Data Type:** IReadOnlyDictionary`__> + * - ``partialResult`` + - | The results of any successful operations performed before the exception was thrown. + | + | **Data Type:** `ClientBulkWriteResult <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.ClientBulkWriteResult.html>`__ + * - ``writeConcernErrors`` + - | Write concern errors that occurred during execution of the bulk write operation. + | + | **Data Type:** IReadOnlyList<`MongoWriteConcernException <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.MongoWriteConcernException.html>`__> + * - ``innerException`` + - | The inner exception. + | + | **Data Type:** `Exception `__ + Additional Information ---------------------- @@ -544,3 +579,4 @@ guide, see the following API documentation: - `BulkWriteInsertOneResult <{+new-api-root+}/MongoDB.Driver/MongoClient.BulkWriteInsertOneResult.html>`__ - `BulkWriteUpdateResult <{+new-api-root+}/MongoDB.Driver/MongoClient.BulkWriteUpdateResult.html>`__ - `BulkWriteDeleteResult <{+new-api-root+}/MongoDB.Driver/MongoClient.BulkWriteDeleteResult.html>`__ +- `ClientBulkWriteException <{+new-api-root+}/MongoDB.Driver/MongoClient.ClientBulkWriteException.html>`__ diff --git a/source/includes/fundamentals/code-examples/BulkWrite.cs b/source/includes/fundamentals/code-examples/BulkWrite.cs index b71d0c45..4ee5e0c6 100644 --- a/source/includes/fundamentals/code-examples/BulkWrite.cs +++ b/source/includes/fundamentals/code-examples/BulkWrite.cs @@ -112,11 +112,11 @@ static void BulkWriteSync() ) }; - var results = client.BulkWriteSync(bulkWriteModels); + var results = client.BulkWrite(bulkWriteModels); Console.WriteLine("Bulk write results: " + results); // end-bulk-write-sync } - static async void BulkWriteAsync() + static async Task BulkWriteAsync() { // start-bulk-write-async var client = new MongoClient("mongodb://localhost:27017"); @@ -175,10 +175,10 @@ static void BulkWriteOptionsSync() VerboseResult = true }; - var results = client.BulkWriteSync(deleteOneModel, clientBulkWriteOptions); + var results = client.BulkWrite(deleteOneModel, clientBulkWriteOptions); // end-bulk-write-options-sync } - static async void BulkWriteOptionsAsync() + static async Task BulkWriteOptionsAsync() { // start-bulk-write-options-async var client = new MongoClient("mongodb://localhost:27017"); From d1bc7dece6d5e3a1e802c7b41b997b57e007f0e6 Mon Sep 17 00:00:00 2001 From: Mike Woofter <108414937+mongoKart@users.noreply.github.com> Date: Tue, 29 Oct 2024 16:03:41 -0500 Subject: [PATCH 17/17] fixes --- .../crud/write-operations/bulk-write.txt | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/source/fundamentals/crud/write-operations/bulk-write.txt b/source/fundamentals/crud/write-operations/bulk-write.txt index 55834b12..8da9b794 100644 --- a/source/fundamentals/crud/write-operations/bulk-write.txt +++ b/source/fundamentals/crud/write-operations/bulk-write.txt @@ -536,7 +536,7 @@ A ``ClientBulkWriteException`` object contains the following properties: * - ``message`` - | The error message. | - | **Data Type:** {+string-data-type+} + | **Data Type:** string * - ``writeErrors`` - | A dictionary of errors that occurred during the bulk write operation. | @@ -566,17 +566,17 @@ To learn how to perform individual write operations, see the following guides: To learn more about any of the methods or types discussed in this guide, see the following API documentation: -- `BulkWrite() <{+new-api-root+}/MongoDB.Driver/MongoClient.BulkWrite.html>`__ -- `BulkWriteAsync() <{+new-api-root+}/MongoDB.Driver/MongoClient.BulkWriteAsync.html>`__ -- `ClientBulkWriteOptions <{+new-api-root+}/MongoDB.Driver/MongoClient.ClientBulkWriteOptions.html>`__ -- `ClientBulkWriteResult <{+new-api-root+}/MongoDB.Driver/MongoClient.ClientBulkWriteResult.html>`__ -- `BulkWriteInsertOneModel <{+new-api-root+}/MongoDB.Driver/MongoClient.BulkWriteInsertOneModel-1.html>`__ -- `BulkWriteUpdateOneModel <{+new-api-root+}/MongoDB.Driver/MongoClient.BulkWriteUpdateOneModel-1.html>`__ -- `BulkWriteUpdateManyModel <{+new-api-root+}/MongoDB.Driver/MongoClient.BulkWriteUpdateManyModel-1.html>`__ -- `BulkWriteReplaceOneModel <{+new-api-root+}/MongoDB.Driver/MongoClient.BulkWriteReplaceOneModel-1.html>`__ -- `BulkWriteDeleteOneModel <{+new-api-root+}/MongoDB.Driver/MongoClient.BulkWriteDeleteOneModel-1.html>`__ -- `BulkWriteDeleteManyModel <{+new-api-root+}/MongoDB.Driver/MongoClient.BulkWriteDeleteManyModel-1.html>`__ -- `BulkWriteInsertOneResult <{+new-api-root+}/MongoDB.Driver/MongoClient.BulkWriteInsertOneResult.html>`__ -- `BulkWriteUpdateResult <{+new-api-root+}/MongoDB.Driver/MongoClient.BulkWriteUpdateResult.html>`__ -- `BulkWriteDeleteResult <{+new-api-root+}/MongoDB.Driver/MongoClient.BulkWriteDeleteResult.html>`__ -- `ClientBulkWriteException <{+new-api-root+}/MongoDB.Driver/MongoClient.ClientBulkWriteException.html>`__ +- `BulkWrite() <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.IMongoClient.BulkWrite.html>`__ +- `BulkWriteAsync() <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.IMongoClient.BulkWriteAsync.html>`__ +- `ClientBulkWriteOptions <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.ClientBulkWriteOptions.html>`__ +- `ClientBulkWriteResult <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.ClientBulkWriteResult.html>`__ +- `BulkWriteInsertOneModel <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.BulkWriteInsertOneModel-1.html>`__ +- `BulkWriteUpdateOneModel <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.BulkWriteUpdateOneModel-1.html>`__ +- `BulkWriteUpdateManyModel <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.BulkWriteUpdateManyModel-1.html>`__ +- `BulkWriteReplaceOneModel <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.BulkWriteReplaceOneModel-1.html>`__ +- `BulkWriteDeleteOneModel <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.BulkWriteDeleteOneModel-1.html>`__ +- `BulkWriteDeleteManyModel <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.BulkWriteDeleteManyModel-1.html>`__ +- `BulkWriteInsertOneResult <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.BulkWriteInsertOneResult.html>`__ +- `BulkWriteUpdateResult <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.BulkWriteUpdateResult.html>`__ +- `BulkWriteDeleteResult <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.BulkWriteDeleteResult.html>`__ +- `ClientBulkWriteException <{+new-api-root+}/MongoDB.Driver/MongoDB.Driver.ClientBulkWriteException.html>`__