@@ -37,7 +37,7 @@ appropriate actions to either handle them or correct the error-causing code.
37
37
Write Error Types
38
38
-----------------
39
39
40
- If the driver encounters an error while performing an write operation, it
40
+ If the driver encounters an error while performing a write operation, it
41
41
returns an error of the `WriteError <{+core-api+}/WriteError.html>`__ type.
42
42
43
43
The ``WriteError`` type contains the following methods:
@@ -61,6 +61,8 @@ methods, ``WriteConcernError`` has the ``getCodeName`` method, which returns the
61
61
name associated with the error code. This type does not have the ``getCategory``
62
62
method.
63
63
64
+ .. _java_error_write_errors:
65
+
64
66
Write Error
65
67
~~~~~~~~~~~
66
68
@@ -70,15 +72,15 @@ satisfying the write concern.
70
72
71
73
For example, the driver raises a ``WriteError`` error if you attempt to insert a
72
74
document into a collection with an ObjectId value that already exists in the
73
- collection. Suppose the collection has an existing document with an ``ObjectId`` of `1`. If you attempt to insert a document
75
+ collection. Suppose the collection has an existing document with an ``ObjectId`` of `1`. If you attempt to insert another document
74
76
where the value of ``ObjectId`` is ``1``, the driver prints the following
75
77
error message:
76
78
77
79
.. code-block:: none
78
80
:copyable: false
79
81
80
82
WriteError: { code: 11000, message: "E11000 duplicate key error collection:
81
- testDB.testCollection index: _id_ dup key: { _id: 1 }", details: { } }
83
+ testDB.testCollection index: _id_ dup key: { _id: 1 }", details: Document{{}} } }
82
84
83
85
In the preceding error message, the ``message`` field describes the reason for
84
86
the error, and the ``details`` field provides specific details about the failing
@@ -88,17 +90,18 @@ operation. To address this error, you must revise the document to have a unique
88
90
Bulk Write Error
89
91
----------------
90
92
91
- If this same example was run in during bulk write operation, an additional field
92
- would be added to the error detailing the index of the item with the duplicate
93
- ``ObjectId``
93
+ If the same example were run as a bulk write operation, the `index` field
94
+ containing the index of the item with the duplicate ``ObjectId`` would be added
95
+ to the message. For example, if the index of the item that produced the error is
96
+ `2`, the driver would print the following error message:
94
97
95
98
.. code-block:: none
96
99
:copyable: false
97
100
:emphasize-lines: 1
98
101
99
- BulkWriteError{index= 2, code= 11000, message= 'E11000 duplicate key error
102
+ BulkWriteError{ index: 2, code: 11000, message: 'E11000 duplicate key error
100
103
collection: testDB.testCollection index: _id_ dup key: { _id: 1 }',
101
- details= Document{{}}}
104
+ details: Document{{}} }
102
105
103
106
Write Concern Error
104
107
~~~~~~~~~~~~~~~~~~~
0 commit comments