@@ -35,7 +35,7 @@ appropriate actions to either handle them or correct the error-causing code.
35
35
discussions, or general technical support
36
36
37
37
Write Error
38
- ~~~~~~~~~~~
38
+ -----------
39
39
40
40
If the driver encounters an error while performing a write operation, it
41
41
creates an error of the `WriteError <{+core-api+}/WriteError.html>`__ type.
@@ -48,8 +48,22 @@ The ``WriteError`` type contains the following fields:
48
48
49
49
.. _java_error_write_exceptions:
50
50
51
+ Write Exception Types
52
+ ---------------------
53
+
54
+ The driver creates write exceptions when a ``WriteError`` object is created.
55
+
56
+ The write exception object contains the following fields:
57
+
58
+ - ``error``: the ``WriteError`` object that triggered the exception
59
+ - ``serverAddress``: the address of the server where the exception occurred
60
+ - ``errorLabels``: the server error labels, such as ``RetryableWriteError`` and ``TransientTransactionError``
61
+
62
+ Details on the different types of write exceptions and the error messages that
63
+ are thrown when one is created can be found below.
64
+
51
65
Write Exception
52
- ---------------
66
+ ~~~~~~~~~~~~~~~
53
67
54
68
The driver raises a `MongoWriteException <{+core-api+}/MongoWriteException.html>`__ for
55
69
any errors that it encounters when performing single write operations that are
@@ -83,14 +97,14 @@ either revise the document to adhere to the schema validation rules or bypass
83
97
validation.
84
98
85
99
Bulk Write Exception
86
- --------------------
100
+ ~~~~~~~~~~~~~~~~~~~~
87
101
88
102
If the same example were run as a bulk write operation, a
89
103
`MongoBulkWriteException <{+core-api+}/MongoBulkWriteException.html>`__ would be
90
- thrown. A ``MongoBulkWriteException`` can contain a list of errors associated
91
- with the same bulk write operation. For example, if you attempt to insert two
92
- documents that violate the collection's schema, the error message would appear
93
- as follows :
104
+ thrown. A ``MongoBulkWriteException`` contains a list of errors associated with
105
+ the same bulk write operation if more than one item caused an error. For
106
+ example, if you attempt to insert two documents that violate the collection's
107
+ schema, the driver prints the following error message :
94
108
95
109
.. code-block:: none
96
110
:copyable: false
@@ -106,9 +120,9 @@ as follows:
106
120
schemaRules: { bsonType: "int", description: "must be an integer" },
107
121
offendingDocument: {"name":"Apple","quantity":"three"} }} at
108
122
com.mongodb.internal.connection.WriteResultHelper.createWriteException(WriteResultHelper.java:50)
109
- at
110
- com.mongodb.internal.connection.ProtocolHelper.getBulkWriteException(ProtocolHelper.java:254)
111
- ... 19 more Caused by: com.mongodb.MongoWriteException: WriteError{code=121,
123
+ at com.mongodb.internal.connection.ProtocolHelper.getBulkWriteException(ProtocolHelper.java:254)
124
+ ... 19 more
125
+ Caused by: com.mongodb.MongoWriteException: WriteError{code=121,
112
126
message='Document failed validation', details={ operator: "$jsonSchema",
113
127
schemaRules: { bsonType: "int", description: "must be an integer" },
114
128
offendingDocument: {"name":"Banana","quantity":"ten"} }} at
0 commit comments