-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathdb.collection.initializeOrderedBulkOp.txt
87 lines (58 loc) · 2.16 KB
/
db.collection.initializeOrderedBulkOp.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
=======================================
db.collection.initializeOrderedBulkOp()
=======================================
.. default-domain:: mongodb
.. contents:: On this page
:local:
:backlinks: none
:depth: 1
:class: singlecol
.. include:: /includes/fact-bulkwrite.rst
Definition
----------
.. method:: db.collection.initializeOrderedBulkOp()
.. include:: /includes/fact-mongosh-shell-method.rst
Initializes and returns a new :method:`Bulk()` operations builder
for a collection. The builder constructs an ordered list of write
operations that MongoDB executes in bulk.
:returns: new :method:`Bulk()` operations builder object.
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
Behavior
--------
Order of Operation
~~~~~~~~~~~~~~~~~~
With an *ordered* operations list, MongoDB executes the write
operations in the list serially.
Execution of Operations
~~~~~~~~~~~~~~~~~~~~~~~
.. include:: /includes/fact-bulk-operation-ordered-list.rst
.. include:: /includes/fact-bulk-operation-batches.rst
.. include:: /includes/fact-bulk-operation-sharded-cluster.rst
Error Handling
~~~~~~~~~~~~~~
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.
Examples
--------
The following initializes a :method:`Bulk()` operations builder on the
``users`` collection, adds a series of write operations, and executes
the operations:
.. code-block:: javascript
var bulk = db.users.initializeOrderedBulkOp();
bulk.insert( { user: "abc123", status: "A", points: 0 } );
bulk.insert( { user: "ijk123", status: "A", points: 0 } );
bulk.insert( { user: "mop123", status: "P", points: 0 } );
bulk.find( { status: "D" } ).delete();
bulk.find( { status: "P" } ).update( { $set: { comment: "Pending" } } );
bulk.execute();
.. seealso::
- :method:`db.collection.initializeUnorderedBulkOp()`
- :method:`Bulk.find()`
- :method:`Bulk.find.removeOne()`
- :method:`Bulk.execute()`