Skip to content

Commit c4280b3

Browse files
(DOCSP-23728): Clarify manage indexes behavior (#1443) (#1453)
* WIP * (DOCSP-23728): Clarify manage indexes behavior * typo fix * add 'success' step * formatting * edits * move tip * edits * add clarification * add clarity to steps * typo * remove extra word * address review feedback * minor edit * wording * updates per review feedback * wording
1 parent 7dcd642 commit c4280b3

File tree

4 files changed

+141
-20
lines changed

4 files changed

+141
-20
lines changed

source/core/index-hidden.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ The operation returns the following information:
121121

122122
The index option ``hidden`` is only returned if the value is ``true``.
123123

124+
.. _hide-existing-index:
125+
124126
Hide an Existing Index
125127
~~~~~~~~~~~~~~~~~~~~~~
126128

source/includes/driver-examples/driver-example-modify-index-tabs.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
tabs:
44
- id: shell
55
content: |
6-
To modify an existing index, you need to drop and recreate the
7-
index. The exception to this rule is
6+
To modify an existing index in the MongoDB Shell, you need to
7+
drop and recreate the index. The exception to this rule is
88
:doc:`TTL indexes </core/index-ttl/>`, which can be modified
99
via the :dbcommand:`collMod` command in conjunction with the
1010
:collflag:`index` collection flag.
1111

1212
- id: compass
1313
content: |
1414
To modify an existing index in |compass|, you need to drop and
15-
recreate the index.
15+
recreate the index.

source/includes/driver-remove-indexes-tabs.rst

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
tabs:
44
- id: shell
55
content: |
6-
MongoDB provides two methods for removing indexes from a collection:
6+
7+
When removing indexes in the MongoDB Shell, you can either:
78

8-
- :method:`db.collection.dropIndex()` and
9+
- Remove a specific index.
910

10-
- :method:`db.collection.dropIndexes()`
11+
- Remove all indexes from the collection.
1112

12-
1313
Remove Specific Index
1414
~~~~~~~~~~~~~~~~~~~~~
1515

@@ -67,16 +67,15 @@
6767

6868
- id: compass
6969
content: |
70+
7071
To remove an index from a collection in |compass|:
7172

72-
1. Navigate to the collection on which the target
73-
index exists.
73+
1. Navigate to the collection containing the target index.
7474

7575
2. Click the :guilabel:`Indexes` tab.
7676

77-
3. Click the :guilabel:`trash can` icon in the
78-
:guilabel:`Drop` column for the index you wish to delete.
77+
3. In the :guilabel:`Drop` column for the target index, click
78+
the trash icon.
7979

8080
.. figure:: /images/compass-delete-index.png
8181
:alt: Delete an index in Compass
82-

source/tutorial/manage-indexes.txt

Lines changed: 128 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,146 @@ View Existing Indexes
3535
Remove Indexes
3636
--------------
3737

38+
.. tip:: Hide an Index Before Dropping It
39+
40+
If you drop an index that is actively used in production, your
41+
application may incur a performance degradation. Before you drop an
42+
index, you can evaluate the potential impact of the drop by
43+
:ref:`hiding the index <hide-existing-index>`.
44+
45+
Hidden indexes are not used to support queries. If you hide an index
46+
and observe substantial negative performance impact, consider keeping
47+
and unhiding the index so queries can resume using it.
48+
3849
.. include:: /includes/driver-remove-indexes-tabs.rst
3950

4051
Modify an Index
4152
---------------
4253

4354
.. include:: /includes/driver-examples/driver-example-modify-index-tabs.rst
4455

45-
.. tabs-drivers::
56+
Minimize Performance Impact With a Temporary Index
57+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
58+
59+
If you drop an index that is actively used in production, your
60+
application may incur a performance degradation. To ensure queries can
61+
still use an index during modification, you can create a temporary,
62+
redundant index that contains the same fields as the modified index.
63+
64+
Example
65+
```````
66+
67+
This example creates a new index and modifies that index to make it
68+
:ref:`unique <index-type-unique>`.
69+
70+
.. procedure::
71+
:style: normal
72+
73+
.. step:: Create a ``siteAnalytics`` collection with an index on the ``url`` field
74+
75+
Run this command:
76+
77+
.. code-block:: javascript
78+
79+
db.siteAnalytics.createIndex( { "url": 1 } )
80+
81+
The command returns the name of the index:
82+
83+
.. code-block:: javascript
84+
:copyable: false
85+
86+
url_1
87+
88+
.. step:: Create a temporary index that contains the ``url`` field
89+
90+
Run this command:
91+
92+
.. code-block:: javascript
93+
94+
db.siteAnalytics.createIndex( { "url": 1, "dummyField": 1 } )
95+
96+
The command returns the name of the index:
97+
98+
.. code-block:: javascript
99+
:copyable: false
100+
101+
url_1_dummyField_1
102+
103+
This temporary index lets you safely drop the original ``{ "url":
104+
1 }`` index without impacting performance.
105+
106+
.. step:: Drop the original index
107+
108+
Run this command:
109+
110+
.. code-block:: javascript
111+
112+
db.siteAnalytics.dropIndex( { "url": 1 } )
113+
114+
The command returns:
115+
116+
.. code-block:: javascript
117+
:copyable: false
118+
119+
{ nIndexesWas: 3, ok: 1 }
120+
121+
.. step:: Recreate the ``{ "url": 1 }`` index with the ``unique`` property
122+
123+
Run this command:
124+
125+
.. code-block:: javascript
126+
127+
db.siteAnalytics.createIndex( { "url": 1 }, { "unique": true } )
128+
129+
The command returns the name of the index:
130+
131+
.. code-block:: javascript
132+
:copyable: false
133+
134+
url_1
135+
136+
The ``url_1`` index is recreated and you can drop the temporary
137+
index without impacting performance. Queries on the ``url`` field
138+
can use the new unique index.
139+
140+
.. step:: Drop the temporary index
141+
142+
Run this command:
143+
144+
.. code-block:: javascript
145+
146+
db.siteAnalytics.dropIndex( { "url": 1, "dummyField": 1 } )
147+
148+
The command returns:
149+
150+
.. code-block:: javascript
151+
:copyable: false
152+
153+
{ nIndexesWas: 3, ok: 1 }
154+
155+
.. step:: Confirm that the index was updated
156+
157+
To view the indexes on the ``siteAnalytics`` collection, run this
158+
command:
159+
160+
.. code-block:: javascript
161+
162+
db.siteAnalytics.getIndexes()
163+
164+
The command returns these indexes, indicating that the ``url_1``
165+
index is now unique:
46166

47-
tabs:
48-
- id: compass
49-
content: |
50-
.. seealso::
167+
.. code-block:: javascript
168+
:copyable: false
51169

52-
- :ref:`MongoDB Compass Documentation <compass-index>`
53-
- :compass:`Compass Documentation for Indexes </indexes/>`
170+
[
171+
{ v: 2, key: { _id: 1 }, name: '_id_' },
172+
{ v: 2, key: { url: 1 }, name: 'url_1', unique: true }
173+
]
54174

55175
.. _manage-indexes-find-inconsistent-indexes:
56176

57-
Find Inconsistent Indexes across Shards
177+
Find Inconsistent Indexes Across Shards
58178
---------------------------------------
59179

60180
A sharded collection has an inconsistent index if the collection does

0 commit comments

Comments
 (0)