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

Create a Hashed Index

On this page

New in version 2.4.

Hashed indexes 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.


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


Hashed Shard Keys for more information about hashed indexes in sharded clusters, as well as Index Concepts and Indexing Tutorials for more information about indexes.


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


Specify a hashed index on _id

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


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.