@@ -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
2121Overview
@@ -194,27 +194,15 @@ operation and an insert many operation:
194194Troubleshooting
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
240224Additional 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+
253242Server 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/>`
0 commit comments