Skip to content

Commit 441d7ad

Browse files
authored
DOCS-14277 v5.2 (#713)
* DOCS-14277 sparse and non sparse updates * update examples * add Unique to header * usage -> creation * remove unlike other indexes from extract * CR1 * CR 1.5 * CR 2 * update collection name * TR Comments 1 * TR 1.5 Adding basic and unique section * add periods to bullets * remove bullet points * patten -> pattern
1 parent 9d9e9e2 commit 441d7ad

File tree

6 files changed

+97
-15
lines changed

6 files changed

+97
-15
lines changed

source/core/index-sparse.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ index keys along with ascending/descending index keys, only the
100100
existence of the ``text`` index field(s) determine whether the index
101101
references a document.
102102

103+
.. _sparse-unique-index:
104+
103105
``sparse`` and ``unique`` Properties
104106
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
105107

@@ -249,3 +251,9 @@ and ``90``:
249251
{ "userid": "BBBBBBB", "score": 90 }
250252
] )
251253

254+
.. _sparse-and-non-sparse_example:
255+
256+
Sparse and Non-Sparse Unique Indexes
257+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
258+
259+
.. include:: /includes/fact-5.0-sparse-unique-index-updates.rst

source/core/index-unique.txt

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,3 +284,45 @@ The unique index constraints mean that:
284284

285285
- For an already-sharded collection, you cannot create unique indexes
286286
on other fields.
287+
288+
Sparse and Non-Sparse Unique Indexes
289+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
290+
291+
.. include:: /includes/fact-5.0-sparse-unique-index-updates.rst
292+
293+
Basic and Unique Indexes With Duplicate Key Patterns
294+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
295+
296+
Starting in MongoDB 5.0, basic and unique indexes can exist with the
297+
same :ref:`key pattern <key_patterns>`.
298+
299+
This duplication in key patterns allows for adding a unique index to
300+
already indexed fields.
301+
302+
In this example:
303+
304+
Create a basic index with the key pattern ``{ score : 1 }`` and insert
305+
three documents.
306+
307+
.. code-block:: javascript
308+
309+
db.scoreHistory.createIndex( { score : 1 }, { name: "basic_index" } )
310+
db.scoreHistory.insert( { score : 1 } )
311+
db.scoreHistory.insert( { score : 2 } )
312+
db.scoreHistory.insert( { score : 3 } )
313+
314+
Create a unique index with the same key pattern ``{ score : 1 }``.
315+
316+
.. code-block:: javascript
317+
318+
db.scoreHistory.createIndex( { score : 1 }, { name: "unique_index", unique: true } )
319+
320+
Try to insert a duplicate ``score`` document that fails because of
321+
the unique index.
322+
323+
.. code-block:: javascript
324+
325+
db.scoreHistory.insert( { score : 3 } )
326+
327+
328+

source/includes/extracts-collation.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,9 @@ content: |
8181
---
8282
ref: collation-index-options
8383
content: |
84-
Unlike other index options, you can create multiple indexes on the same
85-
key(s) with different collations. To create indexes with the same key
86-
pattern but different collations, you must supply unique index names.
84+
You can create multiple indexes on the same key(s) with different
85+
collations. To create indexes with the same key pattern but different
86+
collations, you must supply unique index names.
8787
---
8888
ref: collation-index-collection
8989
content: |-
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Starting in MongoDB 5.0, :ref:`unique sparse <sparse-unique-index>`
2+
and :ref:`unique non-sparse <unique-index>` indexes with the same
3+
:ref:`key pattern<key_patterns>` can exist on a single collection.
4+
5+
Unique and Sparse Index Creation
6+
````````````````````````````````
7+
8+
This example creates multiple indexes with the same key pattern and
9+
different ``sparse`` options:
10+
11+
.. code-block:: javascript
12+
13+
db.scoreHistory.createIndex( { score : 1 }, { name: "unique_index", unique: true } )
14+
db.scoreHistory.createIndex( { score : 1 }, { name: "unique_sparse_index", unique: true, sparse: true } )
15+
16+
Basic and Sparse Index Creation
17+
```````````````````````````````
18+
19+
You can also create basic indexes with the same key pattern with and
20+
without the sparse option:
21+
22+
.. code-block:: javascript
23+
24+
db.scoreHistory.createIndex( { score : 1 }, { name: "sparse_index", sparse: true } )
25+
db.scoreHistory.createIndex( { score : 1 }, { name: "basic_index" } )

source/reference/command/createIndexes.txt

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -630,22 +630,20 @@ Memory Usage Limit
630630
Index Options
631631
~~~~~~~~~~~~~
632632

633-
Non-Collation and Non-Hidden Options
634-
````````````````````````````````````
635-
636-
With the exception of the :ref:`collation option
637-
<createIndexes-collation-option>`, if you create an index with one set
638-
of index options and then try to recreate the same index but with
639-
different index options, MongoDB will not change the options nor
640-
recreate the index.
633+
Non-Hidden Option
634+
`````````````````
641635

642636
The :ref:`hidden <createIndexes-hidden-option>` option can be changed
643637
without dropping and recreating the index. See
644638
:ref:`createIndexes-hidden-option`.
645639

646-
To change the other index options, drop the existing index with
647-
:method:`db.collection.dropIndex()` before running
648-
:dbcommand:`createIndexes` with the new options.
640+
Changing Index Options
641+
``````````````````````
642+
643+
Collation options on an existing index can be updated. To change other
644+
index options, drop the existing index with
645+
:method:`db.collection.dropIndex()` then run :dbcommand:`createIndexes`
646+
with the new options.
649647

650648
.. _createIndexes-collation-option:
651649

source/release-notes/5.0.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,10 +373,19 @@ Indexes
373373
-------
374374

375375
Partial Indexes Behavior Change
376-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
376+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
377377

378378
.. include:: /includes/fact-5.0-multiple-partial-index.rst
379379

380+
Unique Sparse Index Behavior Change
381+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
382+
383+
Starting in MongoDB 5.0, :ref:`unique sparse <sparse-unique-index>`
384+
and :ref:`unique non-sparse <unique-index>` indexes with the same
385+
:ref:`key pattern<key_patterns>` can exist on a single collection.
386+
387+
See :ref:`unique sparse index creation <sparse-and-non-sparse_example>`
388+
380389
Cannot Drop ``Ready`` Indexes During In-Progress Index Builds
381390
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
382391

0 commit comments

Comments
 (0)