@@ -12,55 +12,36 @@ Bulk Operations
12
12
13
13
.. _ruby-driver-bulk-ops:
14
14
15
- The bulk write API sends a list of write operations to the server in
16
- one method call. Execution order of the operations is guaranteed if
17
- you pass in the ``ordered`` option.
15
+ The bulk write API sends several write operations to the server in a single
16
+ command. Use the bulk write API to reduce the number of network round-trips
17
+ when performing several writes at a time.
18
+
19
+ If the ``ordered`` option is set to ``true`` (which is the default),
20
+ the operations are applied in order and if any operation fails, subsequent
21
+ operations are not attempted. If the ``ordered`` option is set to ``false``,
22
+ all specified operations are attempted.
18
23
19
24
The ``bulk_write`` method takes three arguments:
20
25
21
- - A list of operations.
22
- - The ``ordered`` option with a boolean. Defaults to ``true``.
23
- - A write concern option. Defaults to the collection's write concern.
26
+ - A list of operations to execute .
27
+ - The ``ordered`` option taking a boolean value . Defaults to ``true``.
28
+ - The write concern option. Defaults to the collection's write concern.
24
29
25
30
Valid bulk write operations are the following:
26
31
32
+
27
33
insert_one
28
34
==========
29
35
30
36
.. code-block:: ruby
31
37
32
38
{ :insert_one => { :x => 1 } }
33
39
34
- insert_many
35
- ===========
36
-
37
- .. code-block:: ruby
38
-
39
- { :insert_many => [ { :x => 1 }, { :x => 2 } ] }
40
-
41
- delete_one
42
- ==========
43
-
44
- .. code-block:: ruby
45
-
46
- { :delete_one => { :filter => { :x => 1 } } }
47
-
48
- delete_many
49
- ===========
50
-
51
- .. code-block:: ruby
52
-
53
- { :delete_many => { :filter => { :x => 1 } } }
54
-
55
- replace_one
56
- ===========
40
+ .. note::
57
41
58
- .. code-block:: ruby
42
+ There is no ``insert_many`` operation. To insert multiple documents,
43
+ specify multiple ``insert_one`` operations.
59
44
60
- { :replace_one => { :filter => { :x => 1 },
61
- :replacement => { :x => 2 },
62
- :upsert => true } # upsert is optional and defaults to false
63
- }
64
45
65
46
update_one
66
47
==========
@@ -72,6 +53,7 @@ update_one
72
53
:upsert => true } # upsert is optional and defaults to false
73
54
}
74
55
56
+
75
57
update_many
76
58
===========
77
59
@@ -100,3 +82,30 @@ to the ``bulk_write`` method.
100
82
}
101
83
],
102
84
:ordered => true)
85
+
86
+
87
+ replace_one
88
+ ===========
89
+
90
+ .. code-block:: ruby
91
+
92
+ { :replace_one => { :filter => { :x => 1 },
93
+ :replacement => { :x => 2 },
94
+ :upsert => true } # upsert is optional and defaults to false
95
+ }
96
+
97
+
98
+ delete_one
99
+ ==========
100
+
101
+ .. code-block:: ruby
102
+
103
+ { :delete_one => { :filter => { :x => 1 } } }
104
+
105
+
106
+ delete_many
107
+ ===========
108
+
109
+ .. code-block:: ruby
110
+
111
+ { :delete_many => { :filter => { :x => 1 } } }
0 commit comments