Skip to content

Commit a930606

Browse files
(DOCSP-23732): Fix tabs on Manage Indexes page (#1435)
* (DOCSP-23732): Fix tabs on Manage Indexes page * formatting
1 parent b3f61ef commit a930606

File tree

5 files changed

+67
-88
lines changed

5 files changed

+67
-88
lines changed

source/includes/driver-list-collection-indexes-tabs.rst

Lines changed: 0 additions & 18 deletions
This file was deleted.

source/includes/driver-list-database-indexes-tabs.rst

Lines changed: 0 additions & 52 deletions
This file was deleted.

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,7 @@
8080
.. figure:: /images/compass-delete-index.png
8181
:alt: Delete an index in Compass
8282

83+
.. seealso::
84+
85+
- :ref:`MongoDB Compass Documentation <compass-index>`
86+
- :compass:`Compass Documentation for Indexes </indexes/>`

source/includes/driver-view-existing-indexes-tabs.rst

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,71 @@
33
tabs:
44
- id: shell
55
content: |
6+
67
The following sections provide methods for viewing existing indexes
78
on a collection or an entire database.
89

10+
.. _index-list-indexes-for-collection:
11+
12+
List All Indexes on a Collection
13+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
14+
15+
To return a list of all indexes on a collection, use the
16+
:method:`db.collection.getIndexes()` method or a similar :api:`method
17+
for your driver </>`.
18+
19+
For example, to view all indexes on the ``people`` collection, run the
20+
following command:
21+
22+
.. code-block:: javascript
23+
24+
db.people.getIndexes()
25+
26+
.. _index-list-indexes-for-database:
27+
28+
List All Indexes for a Database
29+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
30+
31+
To list all the collection indexes in a database, run the following
32+
command in :binary:`~bin.mongosh`:
33+
34+
.. code-block:: javascript
35+
36+
db.getCollectionNames().forEach(function(collection) {
37+
indexes = db[collection].getIndexes();
38+
print("Indexes for " + collection + ":");
39+
printjson(indexes);
40+
});
41+
42+
.. _list-specific-index-types:
43+
44+
List Specific Type of Indexes
45+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
46+
47+
To list all indexes of a certain type (such as :doc:`hashed
48+
</core/index-hashed>` or :doc:`text </core/index-text>`) for all
49+
collections in all database, run the following command in
50+
:binary:`~bin.mongosh`:
51+
52+
.. code-block:: javascript
53+
54+
// The following finds all hashed indexes
55+
56+
db.adminCommand("listDatabases").databases.forEach(function(d){
57+
let mdb = db.getSiblingDB(d.name);
58+
mdb.getCollectionInfos({ type: "collection" }).forEach(function(c){
59+
let currentCollection = mdb.getCollection(c.name);
60+
currentCollection.getIndexes().forEach(function(idx){
61+
let idxValues = Object.values(Object.assign({}, idx.key));
62+
63+
if (idxValues.includes("hashed")) {
64+
print("Hashed index: " + idx.name + " on " + d.name + "." + c.name);
65+
printjson(idx);
66+
};
67+
});
68+
});
69+
});
70+
971
- id: compass
1072
content: |
1173
To view a list of all indexes on a collection in |compass|,
@@ -17,4 +79,4 @@
1779

1880

1981
For details on the information displayed in this tab, refer to
20-
the :ref:`Compass documentation <indexes-tab>`.
82+
the :ref:`Compass documentation <indexes-tab>`.

source/tutorial/manage-indexes.txt

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,6 @@ View Existing Indexes
2424
.. |things| replace:: collections and indexes
2525
.. |method| replace:: :method:`db.getCollectionNames()` and :method:`db.collection.getIndexes()`
2626

27-
.. _index-list-indexes-for-collection:
28-
29-
.. include:: /includes/driver-list-collection-indexes-tabs.rst
30-
31-
.. _index-list-indexes-for-database:
32-
33-
.. include:: /includes/driver-list-database-indexes-tabs.rst
3427

3528
Remove Indexes
3629
--------------
@@ -42,16 +35,6 @@ Modify an Index
4235

4336
.. include:: /includes/driver-examples/driver-example-modify-index-tabs.rst
4437

45-
.. tabs-drivers::
46-
47-
tabs:
48-
- id: compass
49-
content: |
50-
.. seealso::
51-
52-
- :ref:`MongoDB Compass Documentation <compass-index>`
53-
- :compass:`Compass Documentation for Indexes </indexes/>`
54-
5538
.. _manage-indexes-find-inconsistent-indexes:
5639

5740
Find Inconsistent Indexes across Shards

0 commit comments

Comments
 (0)