-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
create-a-hashed-index.txt
50 lines (34 loc) · 1.33 KB
/
create-a-hashed-index.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
.. index:: index; hashed
.. _index-hashed-index:
=====================
Create a Hashed Index
=====================
.. default-domain:: mongodb
.. contents:: On this page
:local:
:backlinks: none
:depth: 1
:class: singlecol
.. versionadded:: 2.4
:ref:`Hashed indexes <index-type-hashed>` 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.
.. include:: /includes/tip-applications-do-not-need-to-compute-hashes.rst
.. see:: :ref:`sharding-hashed-sharding` for more information about hashed
indexes in sharded clusters, as well as :doc:`/core/indexes` and
:doc:`/administration/indexes` for more information about indexes.
Procedure
---------
To create a :ref:`hashed index <index-type-hashed>`, specify
``hashed`` as the value of the index key, as in the following
example:
.. example:: Specify a hashed index on ``_id``
.. code-block:: javascript
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.