Skip to content

Commit 2076d6b

Browse files
committed
DOCSP-30350 fixing up minor issues with page, final check
1 parent d60da9e commit 2076d6b

File tree

1 file changed

+30
-29
lines changed

1 file changed

+30
-29
lines changed

source/crud/operation-error-handling.txt

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
.. _java-operation-errors:
22

3-
==============================
4-
Write Operation Error Handling
5-
==============================
3+
=============================
4+
Troubleshooting Write Errors
5+
=============================
66

77
.. meta::
88
:description: Understand how to handle operation errors in the MongoDB Java Sync Driver, including error types like WriteErrror and ConnectionPoolCleared.
@@ -54,12 +54,11 @@ The `BulkWriteError <{+core-api+}/bulk/BulkWriteError.html>`__ type extends
5454
operations and includes an ``index`` field that identifies the item in the bulk
5555
operation that caused the error.
5656

57-
The `WriteConcernError <{+core-api+}/bulk/WriteConcernError.html>`__ is not
58-
related to the ``WriteError`` type and details errors relating to the :ref:`write
59-
concern </reference/write-concern/>`. In addition to the ``getCode``, ``getMessage``, and ``getDetails``
60-
methods, ``WriteConcernError`` has the ``getCodeName`` method, which returns the
61-
name associated with the error code. This type does not have the ``getCategory``
62-
method.
57+
The `WriteConcernError <{+core-api+}/bulk/WriteConcernError.html>`__ details
58+
errors related to the :manual:`write concern </reference/write-concern/>`. It
59+
does not extend the ``WriteError`` type, but has the same methods, except for
60+
`getCategory`. In addition, ``WriteConcernError`` has the ``getCodeName``
61+
method, which returns the name associated with the error code.
6362

6463
.. _java_error_write_errors:
6564

@@ -70,42 +69,44 @@ The driver raises a ``WriteError`` error for any errors that it
7069
encounters when performing single write operations that are not related to
7170
satisfying the write concern.
7271

73-
For example, the driver raises a ``WriteError`` error if you attempt to insert a
74-
document into a collection with an ObjectId value that already exists in the
75-
collection. Suppose the collection has an existing document with an ``ObjectId`` of `1`. If you attempt to insert another document
76-
where the value of ``ObjectId`` is ``1``, the driver prints the following
77-
error message:
72+
For example, the driver raises a ``WriteError`` error if you attempt to
73+
insert a document into a collection that violates the collection's
74+
schema validation rules. Suppose the collection has a rule where the
75+
value of the ``quantity`` field must be an ``int`` type. If you
76+
attempt to insert a document where the value of ``quantity`` is
77+
``"three"``, the driver prints the following error message:
7878

7979
.. code-block:: none
8080
:copyable: false
8181

82-
WriteError{code=11000, message='E11000 duplicate key error
83-
collection: testDB.testCollection index: _id_ dup key: { _id: 1 }',
84-
details=Document{{}}}
82+
WriteError{ code=121, message='Document failed validation',
83+
details=Document{{operator=$jsonSchema, schema={type=object,
84+
required=["name", "age"], properties={name={type=string}, age={type=int,
85+
minimum=18}}}} }
86+
}
8587

8688
In the preceding error message, the ``message`` field describes the reason for
8789
the error, and the ``details`` field provides specific details about the failing
88-
operation. To address this error, you must revise the document to have a unique
89-
``ObjectId``.
90-
91-
If you run the ``getCategory`` method on this ``WriteError`` object, it would
92-
return an ``ErrorCategory`` of ``DUPLICATE_KEY``.
90+
operation, in this case it provides the schema rules. To address this error, you
91+
must either revise the document to adhere to the schema validation rules or
92+
bypass validation.
9393

9494
Bulk Write Error
9595
----------------
9696

97-
If the same example were run as a bulk write operation, the `index` field
98-
containing the index of the item with the duplicate ``ObjectId`` would be added
99-
to the message. For example, if the index of the item that produced the error is
100-
`2`, the driver would print the following error message:
97+
If the same example were run as a bulk write operation, the ``index`` field
98+
containing the index of the erring item would be added to the message. For
99+
example, if the ``index`` of the item that violated the schema is ``2``, the driver
100+
would print the following error message:
101101

102102
.. code-block:: none
103103
:copyable: false
104104
:emphasize-lines: 1
105105

106-
BulkWriteError{index=2, code=11000, message='E11000 duplicate key error
107-
collection: testDB.testCollection index: _id_ dup key: { _id: 1 }',
108-
details=Document{{}}}
106+
BulkWriteError{ index=2, code=121, message='Document failed validation',
107+
details=Document{{operator=$jsonSchema, schema={type=object,
108+
required=["name", "age"], properties={name={type=string}, age={type=int,
109+
minimum=18}}}} }
109110

110111
Write Concern Error
111112
~~~~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)