Navigation
This version of the documentation is archived and no longer supported.

Index Creation Tutorials

Instructions for creating and configuring indexes in MongoDB and building indexes on replica sets and sharded clusters.

Create an Index
Build an index for any field on a collection.
Create a Compound Index
Build an index of multiple fields on a collection.
Create a Unique Index
Build an index that enforces unique values for the indexed field or fields.
Create a Sparse Index
Build an index that omits references to documents that do not include the indexed field. This saves space when indexing fields that are present in only some documents.
Create a Hashed Index
Compute a hash of the value of a field in a collection and index the hashed value. These indexes permit equality queries and may be suitable shard keys for some collections.
Build Indexes on Replica Sets
To build indexes on a replica set, you build the indexes separately on the primary and the secondaries, as described here.
Build Indexes in the Background
Background index construction allows read and write operations to continue while building the index, but take longer to complete and result in a larger index.
Build Old Style Indexes
A {v : 0} index is necessary if you need to roll back from MongoDB version 2.0 (or later) to MongoDB version 1.8.