@@ -4,10 +4,57 @@ Perform Bulk Operations
4
4
5
5
.. default-domain:: mongodb
6
6
7
+ You can perform bulk write operations on a collection using the
8
+ ``BulkWrite()`` method.
7
9
8
- The ``bulkWrite()`` method performs batch write operations against a
9
- *single* collection. This method reduces the number of network round trips from
10
- your application to the server which therefore increases the potential
11
- throughput and performance. Since you only receive the success status after
12
- all the operations return, we recommend you use this if that meets the
13
- requirements of your use case.
10
+ The following example specifies a slice of ``WriteModels`` and an option
11
+ to the ``BulkWrite()`` method, which performs the following in order:
12
+
13
+ - Match a document where the ``title`` is "Record of a Shriveled Datum" and replace it with a new document
14
+ - Match a document where the ``title`` is "Dodging Greys" and update that field to "Dodge The Greys"
15
+
16
+ .. include:: /includes/usage-examples/run-example-tip.rst
17
+
18
+ .. literalinclude:: /includes/usage-examples/code-snippets/bulk.go
19
+ :start-after: begin bulk
20
+ :end-before: end bulk
21
+ :emphasize-lines: 10
22
+ :language: go
23
+ :dedent:
24
+
25
+ Click `here <{+example+}/bulk.go>`__ to see a fully runnable example.
26
+
27
+ Expected Result
28
+ ---------------
29
+
30
+ After you run the preceding code snippet, you should be able to find the
31
+ document in the ``haikus`` collection:
32
+
33
+ .. code-block:: json
34
+ :copyable: false
35
+
36
+ {
37
+ "_id" : ObjectId("..."),
38
+ "title" : "Dodge The Greys",
39
+ "text" : "When there're no matches, no longer need to panic. You can use upsert."
40
+ }
41
+
42
+ For an example on how to find a document, see our :doc:`Find
43
+ One Usage Example </usage-examples/findOne>`.
44
+
45
+ Additional Information
46
+ ----------------------
47
+
48
+ For more information on performing bulk write operations on a collection
49
+ and handling potential errors, see our guide on <TODO: Bulk Write
50
+ Fundamentals>.
51
+
52
+ For more information, see our :manual:`Bulk Write Operations
53
+ </core/bulk-write-operations/>` page.
54
+
55
+ API Documentation
56
+ ~~~~~~~~~~~~~~~~~
57
+
58
+ - `BulkWrite() <{+godocs+}/mongo#Collection.BulkWrite>`__
59
+ - `NewUpdateOneModel() <{+godocs+}/mongo#NewUpdateOneModel>`__
60
+ - `NewReplaceOneModel() <{+godocs+}/mongo#NewReplaceOneModel>`__
0 commit comments