Skip to content

DOCSP-1614 - Adding Compass tab for Manage Indexes page #3201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added source/images/compass-delete-index.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added source/images/compass-index-tab-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions source/includes/driver-example-modify-index-tabs.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.. tabs-drivers::

tabs:
- id: shell
content: |
To modify an existing index, you need to drop and recreate the
index. The exception to this rule is
:doc:`TTL indexes </core/index-ttl/>`, which can be modified
via the :dbcommand:`collMod` command in conjunction with the
:collflag:`index` collection flag.

- id: compass
content: |
To modify an existing index in |compass|, you need to drop and
recreate the index.
19 changes: 19 additions & 0 deletions source/includes/driver-list-collection-indexes-tabs.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.. tabs-drivers::

tabs:
- id: shell
content: |
List all Indexes on a Collection
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

To return a list of all indexes on a collection, use the
:method:`db.collection.getIndexes()` method or a similar
:api:`method for your driver <>`.

For example, to view all indexes on the ``people`` collection,
run the following command:

.. cssclass:: copyable-code
.. code-block:: javascript

db.people.getIndexes()
28 changes: 28 additions & 0 deletions source/includes/driver-list-database-indexes-tabs.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
.. tabs-drivers::

tabs:
- id: shell
content: |
List all Indexes on a Database
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

To list all indexes on all collections in a database, you
can use the following operation in the :program:`mongo` shell:

.. cssclass:: copyable-code

.. code-block:: javascript

db.getCollectionNames().forEach(function(collection) {
indexes = db[collection].getIndexes();
print("Indexes for " + collection + ":");
printjson(indexes);
});

.. versionchanged:: 3.0

MongoDB 3.0 deprecates direct access to the ``system.indexes``
collection, which had previously been used to list all indexes
in a database.

.. include:: /includes/fact-wiredtiger-compatibility-with-old-shells.rst
33 changes: 33 additions & 0 deletions source/includes/driver-rebuild-indexes-tabs.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
.. tabs-drivers::

tabs:
- id: shell
content: |
To rebuild all indexes on a collection in a single operation
use the :method:`db.collection.reIndex()` method. This
operation drops all indexes for a collection, including the
``_id`` index, and then rebuilds all indexes.

.. include:: /includes/note-reindex-impact-on-replica-sets.rst

.. include:: /includes/important-reindex-locking.rst

The following example rebuilds all indexes for the ``accounts``
collection:

.. cssclass:: copyable-code

.. code-block:: javascript

db.accounts.reIndex()

This shell helper provides a wrapper around the :dbcommand:`reIndex`
:term:`database command`. Your :doc:`client library </applications/drivers>`
may have a different or additional interface for this operation.

.. include:: /includes/note-build-indexes-on-replica-sets.rst

- id: compass
content: |
To rebuild indexes for a collection in |compass|, you need to
drop and recreate the target indexes.
75 changes: 75 additions & 0 deletions source/includes/driver-remove-indexes-tabs.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
.. tabs-drivers::

tabs:
- id: shell
content: |
MongoDB provides two methods for removing indexes from a collection:

- :method:`db.collection.dropIndex()` and

- :method:`db.collection.dropIndexes()`

To rebuild indexes, see :ref:`rebuild-indexes` instead.

Remove Specific Index
~~~~~~~~~~~~~~~~~~~~~

To remove an index, use the :method:`db.collection.dropIndex()` method.

For example, the following operation removes an ascending index on the
``tax-id`` field in the ``accounts`` collection:

.. cssclass:: copyable-code

.. code-block:: javascript

db.accounts.dropIndex( { "tax-id": 1 } )

The operation returns a document with the status of the operation:

.. code-block:: javascript

{ "nIndexesWas" : 3, "ok" : 1 }

Where the value of ``nIndexesWas`` reflects the number of indexes
*before* removing this index.

For :doc:`text </core/index-text>` indexes, pass the index name to the
:method:`db.collection.dropIndex()` method. See :ref:`drop-text-index`
for details.

Remove All Indexes
~~~~~~~~~~~~~~~~~~

You can also use the :method:`db.collection.dropIndexes()` to remove
*all* indexes except for the :ref:`_id index <index-type-id>` from a
collection.

For example, the following command removes all indexes from
the ``accounts`` collection:

.. cssclass:: copyable-code
.. code-block:: javascript

db.accounts.dropIndexes()

These shell helpers provide wrappers around the
:dbcommand:`dropIndexes` :term:`database command`. Your :doc:`client
library </applications/drivers>` may have a different or additional
interface for these operations.

- id: compass
content: |
To remove an index from a collection in |compass|:

1. Navigate to the collection on which the target
index exists.

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

3. Click the :guilabel:`trash can` icon in the
:guilabel:`Drop` column for the index you wish to delete.

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

20 changes: 20 additions & 0 deletions source/includes/driver-view-existing-indexes-tabs.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.. tabs-drivers::

tabs:
- id: shell
content: |
The following sections provide methods for viewing existing indexes
on a collection or an entire database.

- id: compass
content: |
To view a list of all indexes on a collection in |compass|,
click on the target collection in the left-hand pane and
select the :guilabel:`Indexes` tab.

.. figure:: /images/compass-index-tab-2.png
:alt: View indexes on a collection in Compass


For details on the information displayed in this tab, refer to
the :ref:`Compass documentation <indexes-tab>`.
122 changes: 21 additions & 101 deletions source/tutorial/manage-indexes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,136 +10,56 @@ Manage Indexes
:depth: 1
:class: singlecol

The following procedures provides some common procedures for managing
existing indexes. For instructions on creating indexes, refer to the
specific index type pages.

View Existing Indexes
---------------------
This page shows how to manage existing indexes. For instructions on
creating indexes, refer to the specific index type pages.

.. index:: index; list indexes
.. _index-list-indexes-for-collection:

List all Indexes on a Collection
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

To return a list of all indexes on a collection, use the
:method:`db.collection.getIndexes()` method or a similar
:api:`method for your driver <>`.

For example, to view all indexes on the ``people`` collection:

.. code-block:: javascript
View Existing Indexes
---------------------

db.people.getIndexes()
.. include:: /includes/driver-view-existing-indexes-tabs.rst

.. index:: index; list indexes
.. _index-list-indexes-for-database:

List all Indexes for a Database
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

To list all indexes on all collections in a database, you
can use the following operation in the :binary:`~bin.mongo` shell:

.. code-block:: javascript

db.getCollectionNames().forEach(function(collection) {
indexes = db[collection].getIndexes();
print("Indexes for " + collection + ":");
printjson(indexes);
});

MongoDB 3.0 deprecates direct access to the ``system.indexes``
collection.

.. |things| replace:: collections and indexes
.. |method| replace:: :method:`db.getCollectionNames()` and :method:`db.collection.getIndexes()`

.. include:: /includes/fact-wiredtiger-compatibility-with-old-shells.rst

Remove Indexes
--------------

To remove an index from a collection, you can use the
:method:`db.collection.dropIndex()` method. To rebuild indexes,
see :ref:`rebuild-indexes` instead.

Remove a Specific Index
~~~~~~~~~~~~~~~~~~~~~~~

To remove an index, use the :method:`db.collection.dropIndex()` method.

For example, the following operation removes an ascending index on the
``tax-id`` field in the ``accounts`` collection:

.. code-block:: javascript

db.accounts.dropIndex( { "tax-id": 1 } )

The operation returns a document with the status of the operation:

.. code-block:: javascript

{ "nIndexesWas" : 3, "ok" : 1 }
.. _index-list-indexes-for-collection:

Where the value of ``nIndexesWas`` reflects the number of indexes
*before* removing this index.
.. include:: /includes/driver-list-collection-indexes-tabs.rst

For :doc:`text </core/index-text>` indexes, pass the index name to the
:method:`db.collection.dropIndex()` method. See :ref:`drop-text-index`
for details.
.. _index-list-indexes-for-database:

Remove All Indexes
~~~~~~~~~~~~~~~~~~
.. include:: /includes/driver-list-database-indexes-tabs.rst

You can also use the :method:`db.collection.dropIndexes()` to remove
*all* indexes, except for the :ref:`_id index <index-type-id>` from a
collection.
Remove Indexes
--------------

These shell helpers provide wrappers around the
:dbcommand:`dropIndexes` :term:`database command`. Your :doc:`client
library </applications/drivers>` may have a different or additional
interface for these operations.
.. include:: /includes/driver-remove-indexes-tabs.rst

Modify an Index
---------------

To modify an existing index, you need to drop and recreate the index
with the exception of TTL indexes.

If you need to rebuild indexes for a collection you can use the
:method:`db.collection.reIndex()` method to rebuild all indexes on a
collection in a single operation. This operation drops all indexes,
including the :ref:`_id index <index-type-id>`, and then rebuilds all
indexes.
.. include:: /includes/driver-example-modify-index-tabs.rst

.. _rebuild-indexes:

Rebuild Indexes
---------------

If you need to rebuild indexes for a collection you can use the
:method:`db.collection.reIndex()` method to rebuild all indexes on a
collection in a single operation. This operation drops all indexes for
a collection, including the ``_id`` index, and then rebuilds all
indexes.

.. |cmd-name| replace:: :method:`db.collection.reIndex()`

.. include:: /includes/note-reindex-impact-on-replica-sets.rst

.. include:: /includes/important-reindex-locking.rst

.. |limit| replace:: :limit:`Maximum Index Key Length <Index Key>`

.. code-block:: javascript

db.accounts.reIndex()
.. include:: /includes/driver-rebuild-indexes-tabs.rst

This shell helper provides a wrapper around the :dbcommand:`reIndex`
:term:`database command`. Your :doc:`client library </applications/drivers>`
may have a different or additional interface for this operation.
.. tabs-drivers::

.. include:: /includes/note-build-indexes-on-replica-sets.rst
tabs:
- id: compass
content: |
.. seealso::

- :ref:`MongoDB Compass Documentation <compass-index>`
- `Compass Documentation for Indexes <https://docs.mongodb.com/compass/master/indexes/>`_