-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathBulk.txt
157 lines (96 loc) · 4.1 KB
/
Bulk.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
======
Bulk()
======
.. default-domain:: mongodb
.. contents:: On this page
:local:
:backlinks: none
:depth: 1
:class: singlecol
.. include:: /includes/fact-bulkwrite.rst
Description
-----------
.. method:: Bulk()
Bulk operations builder used to construct a list of write operations
to perform in bulk for a single collection. To instantiate the
builder, use either the
:method:`db.collection.initializeOrderedBulkOp()` or the
:method:`db.collection.initializeUnorderedBulkOp()` method.
Compatibility
-------------
This command is available in deployments hosted in the following
environments:
.. include:: /includes/fact-environments-atlas-only.rst
.. include:: /includes/fact-environments-atlas-support-all.rst
Ordered and Unordered Bulk Operations
-------------------------------------
The builder can construct the list of operations as *ordered* or
*unordered*.
Ordered Operations
~~~~~~~~~~~~~~~~~~
With an *ordered* operations list, MongoDB executes the write
operations in the list serially. If an error occurs during the
processing of one of the write operations, MongoDB will return without
processing any remaining write operations in the list.
Use :method:`db.collection.initializeOrderedBulkOp()` to create a
builder for an ordered list of write commands.
.. include:: /includes/fact-bulk-operation-ordered-list.rst
.. include:: /includes/fact-bulk-operation-batches.rst
.. include:: /includes/fact-bulk-operation-sharded-cluster.rst
Unordered Operations
~~~~~~~~~~~~~~~~~~~~
With an *unordered* operations list, MongoDB can execute in parallel,
as well as in a nondeterministic order, the write operations in the
list. If an error occurs during the processing of one of the write
operations, MongoDB will continue to process remaining write operations
in the list.
Use :method:`db.collection.initializeUnorderedBulkOp()` to create a
builder for an unordered list of write commands.
.. include:: /includes/fact-bulk-operation-unordered-list.rst
.. include:: /includes/fact-bulk-operation-batches.rst
Transactions
~~~~~~~~~~~~
.. include:: /includes/extracts/transactions-supported-operation.rst
For :method:`Bulk.insert()` operations, the collection must already exist.
For :method:`Bulk.find.upsert()`, if the operation results in an
upsert, the collection must already exist.
.. include:: /includes/extracts/transactions-operations-write-concern.rst
.. include:: /includes/extracts/transactions-usage.rst
.. |operation| replace:: :method:`Bulk()`
.. _bulk-methods:
Methods
-------
The :method:`Bulk()` builder has the following methods:
.. list-table::
:widths: 30,70
:header-rows: 1
* - Name
- Description
* - :method:`Bulk.insert()`
- Adds an insert operation to a list of operations.
* - :method:`Bulk.find()`
- Specifies the query condition for an update or a remove operation.
* - :method:`Bulk.find.delete()`
- Adds a multiple document delete operation to a list of operations.
* - :method:`Bulk.find.deleteOne()`
- Adds a single document delete operation to a list of operations.
* - :method:`Bulk.find.remove()`
- An alias for ``Bulk.find.delete()``.
* - :method:`Bulk.find.removeOne()`
- An alias for ``Bulk.find.deleteOne()``.
* - :method:`Bulk.find.replaceOne()`
- Adds a single document replacement operation to a list of operations.
* - :method:`Bulk.find.updateOne()`
- Adds a single document update operation to a list of operations.
* - :method:`Bulk.find.update()`
- Adds a ``multi`` update operation to a list of operations.
* - :method:`Bulk.find.upsert()`
- Specifies ``upsert: true`` for an update operation.
* - :method:`Bulk.execute()`
- Executes a list of operations in bulk.
* - :method:`Bulk.getOperations()`
- Returns an array of write operations executed in the :method:`Bulk()` operations object.
* - :method:`Bulk.toJSON()`
- Returns a JSON document that contains the number of operations and batches in the :method:`Bulk()` operations object.
* - :method:`Bulk.toString()`
- Returns the :method:`Bulk.toJSON()` results as a string.