Skip to content

Commit f40fae8

Browse files
authored
Merge pull request #12 from rustagir/DOCSP-37799-writes
DOCSP-37799: writes
2 parents 2bd57ce + 65671cb commit f40fae8

File tree

4 files changed

+472
-1
lines changed

4 files changed

+472
-1
lines changed

snooty.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ intersphinx = [ "https://www.mongodb.com/docs/manual/objects.inv",
55
"https://www.mongodb.com/docs/atlas/objects.inv"
66
]
77

8-
# toc_landing_pages = ["/paths/to/pages/that/have/nested/content"]
8+
toc_landing_pages = [
9+
"/tutorials/connect/",
10+
"/tutorials/write-ops/",
11+
]
912

1013
[constants]
1114
driver-short = "Java RS driver"

source/tutorials.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ Tutorials
99
/tutorials/connect/
1010
/tutorials/db-coll/
1111
/tutorials/indexes/
12+
/tutorials/write-ops/
1213
/tutorials/aggregation/
1314

source/tutorials/bulk-writes.txt

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
.. _javars-bulk-writes:
2+
3+
=====================
4+
Bulk Write Operations
5+
=====================
6+
7+
Starting in v2.6, MongoDB supports bulk write commands
8+
for insert, update, and delete operations in a way that allows the
9+
driver to implement the correct semantics for ``BulkWriteResult`` and
10+
``BulkWriteException``.
11+
12+
There are two types of bulk operations, ordered and unordered bulk
13+
operations:
14+
15+
1. Ordered bulk operations execute all the operations in order and
16+
error out on the first write error.
17+
#. Unordered bulk operations execute all the operations and report any
18+
the errors. Unordered bulk operations do not guarantee an order of
19+
execution.
20+
21+
.. important::
22+
23+
This guide uses the ``Subscriber`` implementations, which are
24+
described in the :ref:`Quick Start Primer <javars-primer>`.
25+
26+
The following code provides examples using ordered and unordered
27+
operations:
28+
29+
.. code-block:: java
30+
31+
// Ordered bulk operation - order is guaranteed
32+
collection.bulkWrite(
33+
Arrays.asList(new InsertOneModel<>(new Document("_id", 4)),
34+
new InsertOneModel<>(new Document("_id", 5)),
35+
new InsertOneModel<>(new Document("_id", 6)),
36+
new UpdateOneModel<>(new Document("_id", 1),
37+
new Document("$set", new Document("x", 2))),
38+
new DeleteOneModel<>(new Document("_id", 2)),
39+
new ReplaceOneModel<>(new Document("_id", 3),
40+
new Document("_id", 3).append("x", 4))))
41+
.subscribe(new ObservableSubscriber<BulkWriteResult>());
42+
43+
// Unordered bulk operation - no guarantee of order of operation
44+
collection.bulkWrite(
45+
Arrays.asList(new InsertOneModel<>(new Document("_id", 4)),
46+
new InsertOneModel<>(new Document("_id", 5)),
47+
new InsertOneModel<>(new Document("_id", 6)),
48+
new UpdateOneModel<>(new Document("_id", 1),
49+
new Document("$set", new Document("x", 2))),
50+
new DeleteOneModel<>(new Document("_id", 2)),
51+
new ReplaceOneModel<>(new Document("_id", 3),
52+
new Document("_id", 3).append("x", 4))),
53+
new BulkWriteOptions().ordered(false))
54+
.subscribe(new ObservableSubscriber<BulkWriteResult>());

0 commit comments

Comments
 (0)