@@ -24,18 +24,11 @@ Unique Indexes
2424 :class: singlecol
2525
2626A unique index ensures that the indexed fields do not store duplicate
27- values; i.e. enforces uniqueness for the indexed fields. By default,
28- MongoDB creates a unique index on the :ref:`_id <document-id-field>`
29- field during the creation of a collection.
30-
31- .. note:: New Internal Format
32-
33-
34- Starting in MongoDB 4.2, for :ref:`featureCompatibilityVersion
35- <view-fcv>` (fCV) of 4.2 (or greater), MongoDB uses a new internal
36- format for unique indexes that is incompatible with earlier MongoDB
37- versions. The new format applies to both existing unique indexes as
38- well as newly created/rebuilt unique indexes.
27+ values. A unique index on a single field ensures that a value appears
28+ at most once for a given field. A unique compound index ensures that
29+ any given *combination* of the index key values only appears at most
30+ once. By default, MongoDB creates a unique index on the :ref:`_id
31+ <document-id-field>` field during the creation of a collection.
3932
4033.. |page-topic| replace:: :atlas:`create and manage unique indexes in the UI </atlas-ui/indexes>`
4134
@@ -77,9 +70,9 @@ Unique Compound Index
7770~~~~~~~~~~~~~~~~~~~~~
7871
7972You can also enforce a unique constraint on :ref:`compound indexes
80- <index-type-compound>`. If you use the unique constraint on a
81- :ref:`compound index <index-type-compound>`, then MongoDB will enforce
82- uniqueness on the *combination* of the index key values.
73+ <index-type-compound>`. A unique :ref:`compound index
74+ <index-type-compound>` enforces uniqueness on the *combination* of the
75+ index key values.
8376
8477For example, to create a unique index on ``groupNumber``, ``lastname``,
8578and ``firstname`` fields of the ``members`` collection, use the
@@ -139,18 +132,17 @@ index <index-type-hashed>`.
139132Building Unique Index on Replica Sets and Sharded Clusters
140133~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
141134
142- For replica sets and sharded clusters, using a :doc :`rolling procedure
143- </tutorial/build-indexes -on-replica-sets>` to create a unique index
135+ For replica sets and sharded clusters, using a :ref :`rolling procedure
136+ <index-build -on-replica-sets>` to create a unique index
144137requires that you stop all writes to the collection during the
145138procedure. If you cannot stop all writes to the collection during the
146- procedure, do not use the rolling procedure. Instead, build your unique index
147- on the collection by:
148-
149- - issuing :method:`db.collection.createIndex()` on the primary for a
150- replica set, or
139+ procedure, do not use the rolling procedure. Instead, to build your
140+ unique index on the collection you must either:
151141
152- - issuing :method:`db.collection.createIndex()` on the
153- :binary:`~bin.mongos` for a sharded cluster.
142+ - Run ``db.collection.createIndex()`` on the primary for a
143+ replica set
144+ - Run ``db.collection.createIndex()`` on the :binary:`~bin.mongos`
145+ for a sharded cluster
154146
155147.. _unique-separate-documents:
156148
0 commit comments