Skip to content

Commit d4c425f

Browse files
committed
DOCSP-30350 put troubleshooting into main pages, not separate
1 parent ab053b6 commit d4c425f

File tree

5 files changed

+134
-134
lines changed

5 files changed

+134
-134
lines changed

source/crud.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ CRUD Operations
1919
Collations </crud/collations>
2020
Large File Storage with GridFS </crud/gridfs>
2121
Configure Custom CRUD Settings </crud/crud-settings>
22-
Troubleshooting Write Exceptions </crud/operation-error-handling>
2322

2423
- :ref:`Insert Documents <java-fundamentals-insert>`
2524
- :ref:`Query Documents <java-read-operations>`
@@ -33,4 +32,3 @@ CRUD Operations
3332
- :ref:`Collations <java-crud-collations>`
3433
- :ref:`Large File Storage with GridFS <java-crud-gridfs>`
3534
- :ref:`Configure Custom CRUD Settings <java-configure-custom-crud>`
36-
- :ref:`Troubleshooting Write Exceptions <java-operation-errors>`

source/crud/bulk.txt

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,63 @@ Even though the write operation inserting a document with a duplicate key result
623623
in an error, the other operations are executed because the write operation is
624624
unordered.
625625

626+
Troubleshooting
627+
---------------
628+
629+
.. include:: /includes/crud/write-error.rst
630+
631+
Bulk Write Exception
632+
~~~~~~~~~~~~~~~~~~~~
633+
634+
The driver creates write exceptions when a ``WriteError`` object is created. If an
635+
error is detected during a bulk write operation, a `MongoBulkWriteException
636+
<{+core-api+}/MongoBulkWriteException.html>`__ is thrown.
637+
638+
A ``MongoBulkWriteException`` contains a ``writeErrors`` field containing a list
639+
of one or more ``WriteError`` objects associated with the same bulk write
640+
operation.
641+
642+
Example
643+
'''''''
644+
645+
For example, the driver raises a ``MongoBulkWriteException`` if your bulk insert
646+
contains two documents into a collection that violate the collection's schema
647+
validation rules. Suppose the collection has a rule where the value of the
648+
``quantity`` field must be an ``int`` type. If your bulk insert contains a
649+
document with a ``quantity`` of ``"three"`` and another with a ``quantity`` of
650+
``"ten"`, the driver prints the following error message:
651+
652+
.. code-block:: none
653+
:copyable: false
654+
:emphasize-lines: 1-2, 6-9, 13-16
655+
656+
Exception in thread "main" com.mongodb.MongoBulkWriteException: Bulk write
657+
operation result had errors at
658+
com.mongodb.internal.connection.ProtocolHelper.getBulkWriteException(ProtocolHelper.java:258)
659+
... at
660+
BulkWriteMultipleValidationErrorsExample.main(BulkWriteMultipleValidationErrorsExample.java:30)
661+
Caused by: com.mongodb.MongoWriteException: WriteError{code=121,
662+
message='Document failed validation', details={ operator: "$jsonSchema",
663+
schemaRules: { bsonType: "int", description: "must be an integer" },
664+
offendingDocument: {"name":"Apple","quantity":"three"} }} at
665+
com.mongodb.internal.connection.WriteResultHelper.createWriteException(WriteResultHelper.java:50)
666+
at com.mongodb.internal.connection.ProtocolHelper.getBulkWriteException(ProtocolHelper.java:254)
667+
... 19 more
668+
Caused by: com.mongodb.MongoWriteException: WriteError{code=121,
669+
message='Document failed validation', details={ operator: "$jsonSchema",
670+
schemaRules: { bsonType: "int", description: "must be an integer" },
671+
offendingDocument: {"name":"Banana","quantity":"ten"} }} at
672+
com.mongodb.internal.connection.WriteResultHelper.createWriteException(WriteResultHelper.java:50)
673+
at
674+
com.mongodb.internal.connection.ProtocolHelper.getBulkWriteException(ProtocolHelper.java:254)
675+
... 19 more
676+
677+
This exception message contains a list of the two ``WriteError`` objects. The
678+
description in the ``MongoBulkWriteException`` object is vague as
679+
documents associated with the same bulk operation could produce different error
680+
types. Refer to the individual ``WriteError`` objects' ``message`` fields to
681+
determine the cause of each error.
682+
626683
Additional Information
627684
----------------------
628685

source/crud/insert.txt

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,52 @@ operation and an insert many operation:
189189
insertOne() document id: BsonObjectId{value=...}
190190
insertMany() document ids: {0=BsonObjectId{value=...}, 1=BsonObjectId{value=...}}
191191

192+
Troubleshooting
193+
---------------
194+
195+
.. include:: /includes/crud/write-error.rst
196+
197+
Write Exception
198+
~~~~~~~~~~~~~~~
199+
200+
The driver creates write exceptions when a ``WriteError`` object is created. The
201+
driver raises a `MongoWriteException <{+core-api+}/MongoWriteException.html>`__
202+
for any write errors that occur when performing single write operations.
203+
204+
A ``MongoWriteException`` object contains an ``error`` field containing the
205+
``WriteError`` object that caused it.
206+
207+
Example
208+
'''''''
209+
210+
For example, the driver raises a ``MongoWriteException`` if you
211+
attempt to insert a document into a collection that violates the collection's
212+
schema validation rules. Suppose the collection has a rule where the value of
213+
the ``quantity`` field must be an ``int`` type. If you attempt to insert a
214+
document where the value of ``quantity`` is ``"three"``, the driver prints the
215+
following error message:
216+
217+
.. code-block:: none
218+
:copyable: false
219+
:emphasize-lines: 1, 4-7
220+
221+
Exception in thread "main" com.mongodb.MongoWriteException: Document failed validation at
222+
com.mongodb.internal.connection.ProtocolHelper.getWriteException(ProtocolHelper.java:228)
223+
...
224+
Caused by: com.mongodb.MongoWriteException: WriteError{code=121,
225+
message='Document failed validation', details={ operator: "$jsonSchema",
226+
schemaRules: { bsonType: "int", description: "must be an integer" },
227+
offendingDocument: {"name":"Apple","quantity":"three"} } } at
228+
com.mongodb.internal.connection.WriteResultHelper.createWriteException(WriteResultHelper.java:50)
229+
230+
In the preceding error message, the ``MongoWriteException`` object provides a
231+
high-level description of the error. The ``WriteError`` object provides details
232+
on the failed operation, such as the schema rules and the offending document. To
233+
address this error, you must either revise the document to adhere to the schema
234+
validation rules or bypass validation.
235+
236+
To learn more about schema validation, see :manual:`Schema Validation </core/schema-validation/>` in the Server Manual.
237+
192238
Additional Information
193239
----------------------
194240

source/crud/operation-error-handling.txt

Lines changed: 0 additions & 132 deletions
This file was deleted.

source/includes/crud/write-error.rst

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
.. _java_write_error:
2+
3+
This section describes write exceptions you might encounter when
4+
using the {+driver-long+} to perform MongoDB write operations. Once you
5+
understand the types of write exceptions that the driver raises, you can take
6+
appropriate actions to either handle them or correct the error-causing code.
7+
8+
.. note::
9+
10+
This page addresses only write exception handling. If you encounter
11+
any other issues with MongoDB or the driver, visit the following
12+
resources:
13+
14+
- :ref:`java-connection-troubleshooting` for potential solutions to issues
15+
you might encounter when connecting to a MongoDB deployment
16+
- :ref:`java-issues-and-help` page for information about reporting bugs,
17+
contributing to the driver, and finding more resources
18+
- :community-forum:`MongoDB Community Forums </tag/java>` for questions,
19+
discussions, or general technical support
20+
21+
Write Error
22+
~~~~~~~~~~~
23+
24+
If the driver encounters an error while performing a write operation, it
25+
creates an error of the `WriteError <{+core-api+}/WriteError.html>`__ type.
26+
27+
The ``WriteError`` type contains the following fields:
28+
29+
- ``code``: the code associated with the error
30+
- ``message``: a message explaining the error
31+
- ``details``: an optional field containing details associated with the error

0 commit comments

Comments
 (0)