Skip to content

Commit 763949d

Browse files
committed
DOCSP-30350 adding suggestions and API doc links
1 parent 140c02d commit 763949d

File tree

3 files changed

+30
-89
lines changed

3 files changed

+30
-89
lines changed

source/crud/bulk.txt

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -628,28 +628,16 @@ unordered.
628628
Troubleshooting
629629
---------------
630630

631-
.. include:: /includes/crud/write-error.rst
631+
If the driver encounters an error during a bulk write operation, the driver
632+
throws a `MongoBulkWriteException
633+
<{+core-api+}/MongoBulkWriteException.html>`__. A ``MongoBulkWriteException``
634+
contains a ``writeErrors`` field consisting of a list of one or more
635+
``WriteError`` objects associated with the same bulk write operation.
632636

633-
Bulk Write Exception
634-
~~~~~~~~~~~~~~~~~~~~
635-
636-
The driver creates a write exception when it creates a ``WriteError`` object. If an
637-
error is detected during a bulk write operation, the driver throws a `MongoBulkWriteException
638-
<{+core-api+}/MongoBulkWriteException.html>`__.
639-
640-
A ``MongoBulkWriteException`` contains a ``writeErrors`` field consisting of a
641-
list of one or more ``WriteError`` objects associated with the same bulk write
642-
operation.
643-
644-
Example
645-
```````
646-
647-
For example, the driver throws a ``MongoBulkWriteException`` if your bulk insert
648-
contains two documents that violate the collection's schema
649-
validation rules. Suppose the collection has a rule where the value of the
650-
``quantity`` field must be an ``int`` type. If your bulk insert contains a
651-
document with a ``quantity`` of ``"three"`` and another with a ``quantity`` of
652-
``"ten"``, the driver prints the following error message:
637+
Consider a collection that has a rule where the value of the ``quantity`` field
638+
must be an ``int`` type. In the following example, a ``MongoBulkWriteException``
639+
is thrown when when you attempt to insert a document with a ``quantity`` field
640+
value of ``"three"`` and another with a ``quantity`` field value of ``"ten"``.
653641

654642
.. code-block:: none
655643
:copyable: false
@@ -676,15 +664,8 @@ document with a ``quantity`` of ``"three"`` and another with a ``quantity`` of
676664
com.mongodb.internal.connection.ProtocolHelper.getBulkWriteException(ProtocolHelper.java:254)
677665
... 19 more
678666

679-
680-
In the preceding error message, the ``MongoBulkWriteException`` object provides
681-
a vague description of the error, as documents associated with the same bulk
682-
operation could produce different error types. Instead, refer to the
683-
``WriteError`` objects' ``message`` fields to determine the cause of each error.
684-
Refer to the ``WriteError`` objects' ``details`` field for more specific
685-
information, such as the schema rules and the offending documents. To address
686-
this error, you must either revise the document to adhere to the schema
687-
validation rules or bypass validation.
667+
To learn more about the ``MongoBulkWriteException`` and ``WriteError`` types,
668+
see MongoBulkWriteException and WriteError in the API documentation.
688669

689670
Additional Information
690671
----------------------
@@ -700,6 +681,7 @@ MongoCollection
700681

701682
- `bulkWrite() <{+driver-api+}/MongoCollection.html#bulkWrite(com.mongodb.client.ClientSession,java.util.List)>`__
702683
- `BulkWriteOptions <{+core-api+}/client/model/BulkWriteOptions.html>`__
684+
- `WriteError <{+core-api+}/WriteError.html>`__
703685
- `MongoBulkWriteException <{+core-api+}/MongoBulkWriteException.html>`__
704686

705687
MongoClient

source/crud/insert.txt

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Insert Operations
1515
.. contents:: On this page
1616
:local:
1717
:backlinks: none
18-
:depth: 1
18+
:depth: 2
1919
:class: singlecol
2020

2121
Overview
@@ -194,27 +194,15 @@ operation and an insert many operation:
194194
Troubleshooting
195195
---------------
196196

197-
.. include:: /includes/crud/write-error.rst
197+
The driver throws a `MongoWriteException
198+
<{+core-api+}/MongoWriteException.html>`__ for any write errors that occur when
199+
performing single write operations. A ``MongoWriteException`` object has an
200+
``error`` field containing the ``WriteError`` object that caused it.
198201

199-
Write Exception
200-
~~~~~~~~~~~~~~~
201-
202-
The driver creates a write exception when it creates a ``WriteError`` object. The
203-
driver throws a `MongoWriteException <{+core-api+}/MongoWriteException.html>`__
204-
for any write errors that occur when performing single write operations.
205-
206-
A ``MongoWriteException`` object has an ``error`` field containing the
207-
``WriteError`` object that caused it.
208-
209-
Example
210-
```````
211-
212-
For example, the driver throws a ``MongoWriteException`` if you
213-
attempt to insert a document into a collection that violates the collection's
214-
schema validation rules. Suppose the collection has a rule where the value of
215-
the ``quantity`` field must be an ``int`` type. If you attempt to insert a
216-
document where the value of ``quantity`` is ``"three"``, the driver prints the
217-
following error message:
202+
Consider a collection with a rule where the value of the ``quantity`` field must
203+
be an ``int`` type. In the following example, a ``MongoBulkWriteException`` is
204+
thrown if you attempt to insert a document where the value of ``quantity`` is
205+
``"three"``.
218206

219207
.. code-block:: none
220208
:copyable: false
@@ -229,13 +217,9 @@ following error message:
229217
offendingDocument: {"name":"Apple","quantity":"three"} } } at
230218
com.mongodb.internal.connection.WriteResultHelper.createWriteException(WriteResultHelper.java:50)
231219

232-
In the preceding error message, the ``MongoWriteException`` object provides a
233-
high-level description of the error. The ``WriteError`` object provides details
234-
on the failed operation, such as the schema rules and the offending document. To
235-
address this error, you must either revise the document to adhere to the schema
236-
validation rules or bypass validation.
237-
238-
To learn more about schema validation, see :manual:`Schema Validation </core/schema-validation/>` in the Server Manual.
220+
To learn more about the ``MongoWriteException`` and ``WriteError`` types,
221+
see MongoWriteException and WriteError in the API documentation. To learn
222+
more about schema validation, see Schema Validation in Additional Information.
239223

240224
Additional Information
241225
----------------------
@@ -250,8 +234,14 @@ For more information about the methods and classes used to insert documents, see
250234
- `insertMany() <{+driver-api+}/MongoCollection.html#insertMany(java.util.List)>`__
251235
- `InsertManyResult <{+core-api+}/client/result/InsertManyResult.html>`__
252236

237+
For more information about the error types discussed in the Troubleshooting section, see the following API documentation:
238+
239+
- `WriteError <{+core-api+}/WriteError.html>`__
240+
- `MongoWriteException <{+core-api+}/MongoWriteException.html>`__
241+
253242
Server Manual Entries
254243
~~~~~~~~~~~~~~~~~~~~~
255244

256245
- :manual:`db.collection.insertOne() </reference/method/db.collection.insertOne/>`
257246
- :manual:`db.collection.insertMany() </reference/method/db.collection.insertMany/>`
247+
- :manual:`Schema Validation </core/schema-validation/>`

source/includes/crud/write-error.rst

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

0 commit comments

Comments
 (0)