@@ -306,6 +306,8 @@ The following code shows how to delete a search index from a collection:
306
306
:start-after: start drop-search-index
307
307
:end-before: end drop-search-index
308
308
309
+ .. _text-indexes:
310
+
309
311
Text Indexes
310
312
~~~~~~~~~~~~
311
313
@@ -424,28 +426,31 @@ in the {+mdb-server+} manual.
424
426
Unique Indexes
425
427
~~~~~~~~~~~~~~
426
428
429
+ .. _unique-indexes:
430
+
427
431
Unique indexes ensure that the indexed fields do not store duplicate values. By default, MongoDB creates a unique index
428
432
on the ``_id`` field during the creation of a collection. To create a unique index, specify the field or combination of
429
433
fields that you want to prevent duplication on and set the ``unique`` option to ``true``.
430
434
431
435
The following example creates a unique, descending index on the ``theaterId`` field:
432
436
433
- .. literalinclude::
434
- :language: csharp
437
+ .. literalinclude:: /includes/fundamentals/code-snippets/IndexPage.java
438
+ :language: java
435
439
:dedent:
436
440
:start-after: begin unique index
437
441
:end-before: end unique index
438
442
439
- If you attempt to perform a write operation that stores a duplicate value
440
- that violates the unique index, MongoDB will throw an error that resembles
441
- the following:
443
+ .. important::
442
444
443
- .. code-block:: none
444
- :copyable: false
445
+ If you perform a write operation that stores a duplicate value that violates the unique index, the MongoDB
446
+ Java driver raises a ``DuplicateKeyException``, and MongoDB throws an error resembling the following:
447
+
448
+ .. code-block:: none
449
+ :copyable: false
445
450
446
- E11000 duplicate key error index
451
+ E11000 duplicate key error index
447
452
448
- To learn more, see :manual:`Unique Indexes </core/index-unique>`.
453
+ For more information , see the :manual:`Unique Indexes</core/index-unique>` page in the {+mdb-server+} manual .
449
454
450
455
Wildcard Indexes
451
456
~~~~~~~~~~~~~~~~
@@ -590,4 +595,4 @@ For prior versions of MongoDB, pass "*" as a parameter to your call to
590
595
For more information about the methods in this section, see the following API Documentation:
591
596
592
597
- `dropIndex() <{+api+}/apidocs/mongodb-driver-sync/com/mongodb/client/MongoCollection.html#dropIndex(java.lang.String)>`__
593
- - `dropIndexes() <{+api+}/apidocs/mongodb-driver-sync/com/mongodb/client/MongoCollection.html#dropIndexes()>`__
598
+ - `dropIndexes() <{+api+}/apidocs/mongodb-driver-sync/com/mongodb/client/MongoCollection.html#dropIndexes()>`__
0 commit comments