Skip to content

DOCS-219 merged index advice wiki to manual #218

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 10 commits into from
Sep 26, 2012
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
55 changes: 29 additions & 26 deletions source/administration/indexes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,23 @@ Indexing Operations
Synopsis
--------

Indexes allow MongoDB to process and fulfill queries quickly, by
creating an small and efficient representation of the documents in the
collection. Fundamentally, indexes in MongoDB are operationally
similar to indexes in other database systems. Read the
":doc:`/core/indexes`" documentation for more information on the
fundamentals of indexing in MongoDB, and the
":doc:`/applications/indexes`" documentation for practical strategies
and examples for using indexes in your application.

This document provides operational guidelines and procedures related
to indexing data in MongoDB collections.
This document provides operational guidelines and procedures for
indexing data in MongoDB collections. For the fundamentals of MongoDB
indexing, see the :doc:`/core/indexes` document. For strategies and
practical approaches, see the :doc:`/applications/indexes` document.

Indexes allow MongoDB to process and fulfill queries quickly by creating
small and efficient representations of the documents in a collection.

Operations
----------

Creation
~~~~~~~~

Use the :method:`db.collection.ensureIndex()`, or similar :api:`method
for your driver <>`, to create an index. Consider the following
prototype operation:

.. code-block:: javascript

db.collection.ensureIndex( { a: 1 } )
Create an Index
~~~~~~~~~~~~~~~

The following example creates [#ensure]_ an index on the ``phone-number`` field
To create an index, use :method:`db.collection.ensureIndex()` or a similar
:api:`method your driver <>`. For example
the following creates [#ensure]_ an index on the ``phone-number`` field
of the ``people`` collection:

.. code-block:: javascript
Expand Down Expand Up @@ -135,8 +125,21 @@ You can also enforce a unique constraint on :ref:`compound indexes
These indexes enforce uniqueness for the *combination* of index keys
and *not* for either key individually.

Removal
~~~~~~~
List a Collection's Indexes
~~~~~~~~~~~~~~~~~~~~~~~~~~~

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

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

.. code-block:: javascript

db.people.getIndexes()

Remove an Index
~~~~~~~~~~~~~~~

To remove an index, use the :method:`db.collection.dropIndex()` method,
as in the following example:
Expand Down Expand Up @@ -334,8 +337,8 @@ following tools:

Append the :method:`explain() <cursor.explain()>` method to any cursor
(e.g. query) to return a document with statistics about the query
process, including the index used, and the number of documents
scanned.
process, including the index used, the number of documents scanned,
and the time the query takes to process in milliseconds.

- :method:`cursor.hint()`

Expand Down
Loading