Skip to content

Commit f645c87

Browse files
authored
DOCS-15260 prevent dropping shard key index when alternative index doesn't exist (#1071)
* updates dropIndexes and db.collection.dropIndexes * spacing; * fix include path * updates top-level desc * typo * internal review feedback * external feedback * external round 2
1 parent 85e81db commit f645c87

File tree

4 files changed

+30
-7
lines changed

4 files changed

+30
-7
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Starting in MongoDB 6.0, |drop-index| raises an error if you attempt
2+
to use it to remove the last remaining shard key compatible index.
3+
Passing ``"*"`` to |drop-index| drops all indexes except
4+
the ``_id`` index and the last remaining shard key compatible index,
5+
if one exists.

source/reference/command/dropIndexes.txt

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ dropIndexes
1212

1313
.. dbcommand:: dropIndexes
1414

15+
.. versionchanged:: 6.0
16+
1517
The :dbcommand:`dropIndexes` command drops one or more indexes
16-
(except the index on the ``_id`` field) from the specified
17-
collection.
18-
18+
(except the index on the ``_id`` field and the last remaining shard
19+
key index, if one exists) from the specified collection.
20+
1921
The command has the following form:
2022

2123
.. code-block:: javascript
@@ -42,15 +44,17 @@ dropIndexes
4244

4345
- The index or indexes to drop.
4446

45-
- To drop all but the _id index from the collection,
46-
specify ``"*"``.
47+
- To drop all indexes except the ``_id`` index and the last
48+
remaining shard key index from the collection if one
49+
exists, specify ``"*"``.
4750

4851
- To drop a single index, specify either the index name,
4952
the index specification document (unless the index is a
5053
:doc:`text </core/index-text>` index), or an array of the
5154
index name. To drop a :doc:`text </core/index-text>` index,
5255
specify the index names instead of the index specification
53-
document.
56+
document. If this index is the last remaining shard key
57+
index, ``dropIndexes`` raises an error.
5458

5559
- To drop multiple indexes (Available starting in MongoDB
5660
4.2), specify an array of the index names.
@@ -75,6 +79,8 @@ Behavior
7579

7680
.. |drop-index| replace:: :dbcommand:`dropIndexes`
7781

82+
.. include:: /includes/fact-drop-indexes-6.0.rst
83+
7884
.. include:: /includes/fact-drop-index-5.2.rst
7985

8086
Kill related queries only

source/reference/method/db.collection.dropIndexes.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ Definition
2121

2222

2323
Drops the specified index or indexes (except the index on the
24-
``_id`` field) from a collection.
24+
``_id`` field and the last remaining shard key index) from a
25+
collection.
2526

2627
You can use the method to:
2728

@@ -111,6 +112,8 @@ Behavior
111112

112113
.. |drop-index| replace:: :method:`db.collection.dropIndexes()`
113114

115+
.. include:: /includes/fact-drop-indexes-6.0.rst
116+
114117
.. include:: /includes/fact-drop-index-5.2.rst
115118

116119
Kill related queries only

source/release-notes/6.0-compatibility.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ Change Streams
4141
Indexes
4242
-------
4343

44+
Last Remaining Shard Key Index Cannot be Dropped Inadvertently
45+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
46+
47+
Starting in MongoDB 6.0, passing ``"*"`` to :dbcommand:`dropIndexes` or
48+
:method:`db.collection.dropIndexes()` drops all indexes **except**
49+
for the ``_id`` index and the last remaining shard key index, if one
50+
exists. Attempts to explicitly drop the last remaining shard key index
51+
raise an error.
52+
4453
Existing Indexes Can Be Dropped During an Index Build
4554
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4655

0 commit comments

Comments
 (0)