Skip to content

Commit ea3710b

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 445c156 commit ea3710b

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
@@ -33,26 +33,146 @@ View Existing Indexes
3333
Remove Indexes
3434
--------------
3535

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

3849
Modify an Index
3950
---------------
4051

4152
.. include:: /includes/driver-examples/driver-example-modify-index-tabs.rst
4253

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

45-
tabs:
46-
- id: compass
47-
content: |
48-
.. seealso::
165+
.. code-block:: javascript
166+
:copyable: false
49167

50-
- :ref:`MongoDB Compass Documentation <compass-index>`
51-
- :compass:`Compass Documentation for Indexes </indexes/>`
168+
[
169+
{ v: 2, key: { _id: 1 }, name: '_id_' },
170+
{ v: 2, key: { url: 1 }, name: 'url_1', unique: true }
171+
]
52172

53173
.. _manage-indexes-find-inconsistent-indexes:
54174

55-
Find Inconsistent Indexes across Shards
175+
Find Inconsistent Indexes Across Shards
56176
---------------------------------------
57177

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

0 commit comments

Comments
 (0)