@@ -15,7 +15,7 @@ Insert Operations
15
15
.. contents:: On this page
16
16
:local:
17
17
:backlinks: none
18
- :depth: 1
18
+ :depth: 2
19
19
:class: singlecol
20
20
21
21
Overview
@@ -194,27 +194,15 @@ operation and an insert many operation:
194
194
Troubleshooting
195
195
---------------
196
196
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.
198
201
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"``.
218
206
219
207
.. code-block:: none
220
208
:copyable: false
@@ -229,13 +217,9 @@ following error message:
229
217
offendingDocument: {"name":"Apple","quantity":"three"} } } at
230
218
com.mongodb.internal.connection.WriteResultHelper.createWriteException(WriteResultHelper.java:50)
231
219
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.
239
223
240
224
Additional Information
241
225
----------------------
@@ -250,8 +234,14 @@ For more information about the methods and classes used to insert documents, see
250
234
- `insertMany() <{+driver-api+}/MongoCollection.html#insertMany(java.util.List)>`__
251
235
- `InsertManyResult <{+core-api+}/client/result/InsertManyResult.html>`__
252
236
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
+
253
242
Server Manual Entries
254
243
~~~~~~~~~~~~~~~~~~~~~
255
244
256
245
- :manual:`db.collection.insertOne() </reference/method/db.collection.insertOne/>`
257
246
- :manual:`db.collection.insertMany() </reference/method/db.collection.insertMany/>`
247
+ - :manual:`Schema Validation </core/schema-validation/>`
0 commit comments