11.. _index-feature-case-insensitive:
22
33========================
4- Case Insensitive Indexes
4+ Case- Insensitive Indexes
55========================
66
77.. default-domain:: mongodb
@@ -12,42 +12,59 @@ Case Insensitive Indexes
1212 :depth: 2
1313 :class: singlecol
1414
15- Case insensitive indexes support queries that perform string
16- comparisons without regard for case.
15+ Case-insensitive indexes support queries that perform string comparisons
16+ without regard for case. Case insensitivity is derived from
17+ :ref:`collation <collation>`.
1718
18- You can create a case insensitive index with
19- :method:`db.collection.createIndex()` by specifying the ``collation``
20- parameter as an option. For example:
19+ .. important::
2120
22- .. code-block :: javascript
21+ .. include :: /includes/indexes/case-insensitive-regex-queries.rst
2322
24- db.collection.createIndex( { "key" : 1 },
25- { collation: {
26- locale : <locale>,
27- strength : <strength>
28- }
29- } )
23+ Command Syntax
24+ --------------
3025
31- 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:
3229
33- - ``locale``: specifies language rules. See
34- :ref:`Collation Locales<collation-languages-locales>` for a list of
35- available locales.
30+ .. code-block:: javascript
3631
37- - ``strength``: determines comparison rules. A value of
38- ``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.
3961
4062For additional collation fields, see
4163:ref:`Collation<collation-document-fields>`.
4264
4365Behavior
4466--------
4567
46- Using a case insensitive index does not affect
47- the results of a query, but it can increase performance; see
48- :ref:`Indexes <indexes>` for a detailed discussion of the costs and
49- benefits of indexes.
50-
5168To use an index that specifies a collation, query and sort operations
5269must specify the same collation as the index. If a collection has
5370defined a collation, all queries and indexes inherit that collation
@@ -58,26 +75,28 @@ Examples
5875
5976.. _no-default-collation-example:
6077
61- Create a Case Insensitive Index
78+ Create a Case- Insensitive Index
6279~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6380
64- 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
6582collation, create an index with a collation and set the ``strength``
6683parameter to ``1`` or ``2`` (see
6784:ref:`Collation<collation-document-fields>` for a detailed
6885description of the ``strength`` parameter). You must specify the same
6986collation at the query level in order to use the index-level collation.
7087
7188The following example creates a collection with no default collation,
72- 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
7390collation.
7491
7592.. code-block:: javascript
7693
7794 db.createCollection("fruit")
7895
79- db.fruit.createIndex( { type: 1},
80- { collation: { locale: 'en', strength: 2 } } )
96+ db.fruit.createIndex(
97+ { type: 1 },
98+ { collation: { locale: 'en', strength: 2 } }
99+ )
81100
82101To use the index, queries must specify the same collation.
83102
@@ -99,7 +118,7 @@ To use the index, queries must specify the same collation.
99118
100119.. _default-collation-example:
101120
102- Case Insensitive Indexes on Collections with a Default Collation
121+ Case- Insensitive Indexes on Collections with a Default Collation
103122~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
104123
105124When you create a collection with a default collation, all the indexes
0 commit comments