1
1
.. _index-feature-case-insensitive:
2
2
3
3
========================
4
- Case Insensitive Indexes
4
+ Case- Insensitive Indexes
5
5
========================
6
6
7
7
.. default-domain:: mongodb
@@ -12,44 +12,59 @@ Case Insensitive Indexes
12
12
:depth: 2
13
13
:class: singlecol
14
14
15
- .. versionadded:: 3.4
15
+ Case-insensitive indexes support queries that perform string comparisons
16
+ without regard for case. Case insensitivity is derived from
17
+ :ref:`collation <collation>`.
16
18
17
- Case insensitive indexes support queries that perform string
18
- comparisons without regard for case.
19
+ .. important::
19
20
20
- You can create a case insensitive index with
21
- :method:`db.collection.createIndex()` by specifying the ``collation``
22
- parameter as an option. For example:
23
-
24
- .. code-block:: javascript
21
+ .. include:: /includes/indexes/case-insensitive-regex-queries.rst
25
22
26
- db.collection.createIndex( { "key" : 1 },
27
- { collation: {
28
- locale : <locale>,
29
- strength : <strength>
30
- }
31
- } )
23
+ Command Syntax
24
+ --------------
32
25
33
- To specify a collation for a case sensitive index, include:
26
+ You can create a case-insensitive index with
27
+ :method:`db.collection.createIndex()` by specifying the ``collation``
28
+ option:
34
29
35
- - ``locale``: specifies language rules. See
36
- :ref:`Collation Locales<collation-languages-locales>` for a list of
37
- available locales.
30
+ .. code-block:: javascript
38
31
39
- - ``strength``: determines comparison rules. A value of
40
- ``1`` or ``2`` indicates a case insensitive collation.
32
+ db.collection.createIndex(
33
+ {
34
+ <field>: <sortOrder>
35
+ },
36
+ {
37
+ collation:
38
+ {
39
+ locale : <locale>,
40
+ strength : < 1 | 2 >
41
+ }
42
+ }
43
+ )
44
+
45
+ To specify a collation for a case-insensitive index, include the
46
+ following fields in the ``collation`` object:
47
+
48
+ .. list-table::
49
+ :header-rows: 1
50
+ :widths: 10 20
51
+
52
+ * - Field
53
+ - Description
54
+
55
+ * - ``locale``
56
+ - Specifies language rules. For a list of available locales, see
57
+ :ref:`collation-languages-locales`.
58
+ * - ``strength``
59
+ - Determines comparison rules. A ``strength`` value of 1 or 2
60
+ indicates case-insensitive collation.
41
61
42
62
For additional collation fields, see
43
63
:ref:`Collation<collation-document-fields>`.
44
64
45
65
Behavior
46
66
--------
47
67
48
- Using a case insensitive index does not affect
49
- the results of a query, but it can increase performance; see
50
- :doc:`Indexes</indexes>` for a detailed discussion of the costs and
51
- benefits of indexes.
52
-
53
68
To use an index that specifies a collation, query and sort operations
54
69
must specify the same collation as the index. If a collection has
55
70
defined a collation, all queries and indexes inherit that collation
@@ -60,26 +75,28 @@ Examples
60
75
61
76
.. _no-default-collation-example:
62
77
63
- Create a Case Insensitive Index
78
+ Create a Case- Insensitive Index
64
79
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
65
80
66
- To use a case insensitive index on a collection with no default
81
+ To use a case- insensitive index on a collection with no default
67
82
collation, create an index with a collation and set the ``strength``
68
83
parameter to ``1`` or ``2`` (see
69
84
:ref:`Collation<collation-document-fields>` for a detailed
70
85
description of the ``strength`` parameter). You must specify the same
71
86
collation at the query level in order to use the index-level collation.
72
87
73
88
The following example creates a collection with no default collation,
74
- then adds an index on the ``type`` field with a case insensitive
89
+ then adds an index on the ``type`` field with a case- insensitive
75
90
collation.
76
91
77
92
.. code-block:: javascript
78
93
79
94
db.createCollection("fruit")
80
95
81
- db.fruit.createIndex( { type: 1},
82
- { collation: { locale: 'en', strength: 2 } } )
96
+ db.fruit.createIndex(
97
+ { type: 1 },
98
+ { collation: { locale: 'en', strength: 2 } }
99
+ )
83
100
84
101
To use the index, queries must specify the same collation.
85
102
@@ -99,7 +116,7 @@ To use the index, queries must specify the same collation.
99
116
100
117
.. _default-collation-example:
101
118
102
- Case Insensitive Indexes on Collections with a Default Collation
119
+ Case- Insensitive Indexes on Collections with a Default Collation
103
120
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
104
121
105
122
When you create a collection with a default collation, all the indexes
0 commit comments