## Create a Hashed Index 

New in version 2.4. 

Hashed indexes (page 502) 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. 

## Tip 

MongoDB automatically computes the hashes when resolving queries using hashed indexes. Applications do not need to compute hashes. 

## See 

Hashed Shard Keys (page 674) for more information about hashed indexes in sharded clusters, as well as Index Con- cepts (page 486) and Indexing Tutorials (page 517) for more information about indexes. 

## Procedure 

To create a hashed index (page 502), specify hashed as the value of the index key, as in the following example: 

## Example 

Specify a hashed index on _id 

db.collection.createIndex( { _id: "hashed" } ) 

## Considerations 

MongoDB supports hashed indexes of any single field. The hashing function collapses embedded documents and computes the hash for the entire value, but does not support multi-key (i.e. arrays) indexes. 

You may not create compound indexes that have hashed index fields. 

## Build Indexes on Replica Sets 

For replica sets, secondaries will begin building indexes after the primary finishes building the index. In sharded clusters , the mongos will send createIndex() to the primary members of the replica set for each shard, which then replicate to the secondaries after the primary finishes building the index. 

To minimize the impact of building an index on your replica set, use the following procedure to build indexes: 

## See 

Indexing Tutorials (page 517) and Index Concepts (page 486) for more information. 

## Considerations 

• Ensure that your oplog is large enough to permit the indexing or re-indexing operation to complete without falling too far behind to catch up. See the oplog sizing (page 593) documentation for additional information. 

