@@ -91,15 +91,35 @@ recreating an index on just the shard key.
91
91
Unique Indexes
92
92
~~~~~~~~~~~~~~
93
93
94
- For a sharded collection, only the ``_id`` field index and the index on
95
- the shard key or a :term:`compound index` where the shard key is a
96
- :ref:`prefix <compound-index-prefix>` can be :doc:`unique
97
- </core/index-unique>`:
94
+ For a ranged sharded collection, only the following indexes can be
95
+ :doc:`unique </core/index-unique>`:
98
96
99
- - You cannot shard a collection that has unique indexes on other fields.
97
+ - the index on the shard key
100
98
101
- - You cannot create unique indexes on other fields for a sharded
102
- collection.
99
+ - a :term:`compound index` where the shard key is a :ref:`prefix
100
+ <compound-index-prefix>`
101
+
102
+ - the default ``_id`` index
103
+
104
+ .. note::
105
+
106
+ If the ``_id`` field is not part of the shard key, ``_id`` index
107
+ only enforces the uniqueness constraint per shard and **not**
108
+ across shards.
109
+
110
+ For example, consider a sharded collection (with shard key ``{x:
111
+ 1}``) that spans two shards A and B. Because the ``_id`` key is
112
+ not part of the shard key, the collection could have a document
113
+ with ``_id`` value ``1`` in shard A and another document with
114
+ ``_id`` value ``1`` in shard B.
115
+
116
+ The unique index constraints mean that:
117
+
118
+ - For a to-be-sharded collection, you cannot shard the collection if
119
+ the collection has other unique indexes.
120
+
121
+ - For an already-sharded collection, you cannot create unique indexes
122
+ on other fields.
103
123
104
124
Through the use of the unique index on the shard key, MongoDB *can*
105
125
enforce uniqueness on the shard key values. MongoDB enforces uniqueness
0 commit comments