@@ -51,31 +51,26 @@ The ``WriteError`` type contains the following fields:
51
51
Write Exception Types
52
52
---------------------
53
53
54
- The driver creates write exceptions when a ``WriteError`` object is created.
54
+ The driver creates write exceptions when a ``WriteError`` object is created. The
55
+ driver raises a `MongoWriteException <{+core-api+}/MongoWriteException.html>`__
56
+ for any write errors that occur when performing single write operations. If an
57
+ error is detected during a bulk write operation, a `MongoBulkWriteException
58
+ <{+core-api+}/MongoBulkWriteException.html>`__ is thrown.
55
59
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.
60
+ A ``MongoWriteException`` object contains an ``error`` field containing the
61
+ ``WriteError`` object that caused it. A ``MongoBulkWriteException`` contains a
62
+ ``writeErrors`` field containing a list of one or more ``WriteError`` objects
63
+ associated with the same bulk write operation.
64
64
65
65
Write Exception
66
66
~~~~~~~~~~~~~~~
67
67
68
- The driver raises a `MongoWriteException <{+core-api+}/MongoWriteException.html>`__ for
69
- any errors that it encounters when performing single write operations that are
70
- not related to satisfying the write concern. The ``MongoWriteException`` type
71
- contains the ``WriteError`` object.
72
-
73
- For example, the driver raises a ``MongoWriteException`` if you attempt to
74
- insert a document into a collection that violates the collection's
75
- schema validation rules. Suppose the collection has a rule where the
76
- value of the ``quantity`` field must be an ``int`` type. If you
77
- attempt to insert a document where the value of ``quantity`` is
78
- ``"three"``, the driver prints the following error message:
68
+ For example, the driver raises a ``MongoWriteException`` if you
69
+ attempt to insert a document into a collection that violates the collection's
70
+ schema validation rules. Suppose the collection has a rule where the value of
71
+ the ``quantity`` field must be an ``int`` type. If you attempt to insert a
72
+ document where the value of ``quantity`` is ``"three"``, the driver prints the
73
+ following error message:
79
74
80
75
.. code-block:: none
81
76
:copyable: false
@@ -90,21 +85,18 @@ attempt to insert a document where the value of ``quantity`` is
90
85
offendingDocument: {"name":"Apple","quantity":"three"} } } at
91
86
com.mongodb.internal.connection.WriteResultHelper.createWriteException(WriteResultHelper.java:50)
92
87
93
- In the preceding error message, the ``MongoWriteException`` object describes the
94
- reason for the error, and the ``Caused by `` field provides details from the
95
- ``WriteError`` object about the failing operation. To address this error, you must
96
- either revise the document to adhere to the schema validation rules or bypass
97
- validation.
88
+ In the preceding error message, the ``MongoWriteException`` object provides a
89
+ high-level description of the error. The ``WriteError `` object provides details
90
+ on the failed operation, such as the schema rules and the offending document. To
91
+ address this error, you must either revise the document to adhere to the schema
92
+ validation rules or bypass validation .
98
93
99
94
Bulk Write Exception
100
95
~~~~~~~~~~~~~~~~~~~~
101
96
102
- If the same example were run as a bulk write operation, a
103
- `MongoBulkWriteException <{+core-api+}/MongoBulkWriteException.html>`__ would be
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:
97
+ Using the previous example, if you now attempt to insert two documents that
98
+ violate the collection's schema, one with a ``quantity`` of ``three`` and another
99
+ with a ``quantity`` of ``ten``, the driver prints the following error message:
108
100
109
101
.. code-block:: none
110
102
:copyable: false
@@ -130,3 +122,9 @@ schema, the driver prints the following error message:
130
122
at
131
123
com.mongodb.internal.connection.ProtocolHelper.getBulkWriteException(ProtocolHelper.java:254)
132
124
... 19 more
125
+
126
+ This exception message contains a list of the two ``WriteError`` objects. The
127
+ description in the ``MongoBulkWriteException`` object is vague as
128
+ documents associated with the same bulk operation could produce different error
129
+ types. Refer to the individual ``WriteError`` objects' ``message`` fields to
130
+ determine the cause of each error.
0 commit comments