Create a Hashed Index

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.

Was this page helpful?

Yes No

Thank you for your feedback!

We're sorry! You can Report a Problem to help us improve this page.