Skip to content

Commit d6a3431

Browse files
committed
DOCS-2933 ensureIndex options
1 parent d6235a5 commit d6a3431

13 files changed

+334
-87
lines changed

source/core/2d.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,17 @@ map ordering.
7171

7272
For all points, if you use longitude and latitude,
7373
store coordinates in **longitude, latitude** order.
74+
75+
``sparse`` Property
76+
-------------------
77+
78+
``2d`` indexes are :doc:`sparse </core/index-sparse>` by default and
79+
ignores the :doc:`sparse: true </core/index-sparse>` option. If a
80+
document lacks a ``2d`` index field (or the field is ``null`` or an
81+
empty array), MongoDB does not add an entry for the document to the
82+
``2d`` index. For inserts, MongoDB inserts the document but does not
83+
add to the ``2d`` index.
84+
85+
For a compound index that includes a ``2d`` index key along with keys
86+
of other types, only the ``2d`` index field determines whether the
87+
index references a document.

source/core/2dsphere.txt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ To create a ``2dsphere`` index as a version 1, include the option ``{
3939
Additional GeoJSON Objects
4040
~~~~~~~~~~~~~~~~~~~~~~~~~~
4141

42+
.. versionchanged:: 2.6
43+
4244
Version 2 adds support for additional GeoJSON object:
4345
:ref:`geojson-multipoint`, :ref:`geojson-multilinestring`,
4446
:ref:`geojson-multipolygon`, and
@@ -47,15 +49,22 @@ Version 2 adds support for additional GeoJSON object:
4749
``sparse`` Property
4850
~~~~~~~~~~~~~~~~~~~
4951

52+
.. versionchanged:: 2.6
53+
5054
Version 2 ``2dsphere`` indexes are :doc:`sparse </core/index-sparse>`
5155
by default and ignores the :doc:`sparse: true </core/index-sparse>`
5256
option. If a document lacks a ``2dsphere`` index field (or the field is
53-
a ``null`` or an empty array), MongoDB does not add an entry for the
57+
``null`` or an empty array), MongoDB does not add an entry for the
5458
document to the ``2dsphere`` index. For inserts, MongoDB inserts the
5559
document but does not add to the ``2dsphere`` index.
5660

57-
Version 1 ``2dsphere`` indexes are not sparse by default and will
58-
reject documents with ``null`` location fields.
61+
For a compound index that includes a ``2dsphere`` index key along with
62+
keys of other types, only the ``2dsphere`` index field determines
63+
whether the index references a document.
64+
65+
Earlier versions of MongoDB only support Version 1 ``2dsphere``
66+
indexes. Version 1 ``2dsphere`` indexes are *not* sparse by default and
67+
will reject documents with ``null`` location fields.
5968

6069
Considerations
6170
--------------

source/core/geohaystack.txt

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,49 @@
11
.. _index-geohaystack-index:
22

3-
================
4-
Haystack Indexes
5-
================
3+
=======================
4+
``geoHaystack`` Indexes
5+
=======================
66

77
.. default-domain:: mongodb
88

9-
A haystack index is a special index that is optimized to return results
10-
over small areas. Haystack indexes improve performance on queries that
11-
use flat geometry.
9+
A ``geoHaystack`` index is a special index that is optimized to return
10+
results over small areas. ``geoHaystack`` indexes improve performance
11+
on queries that use flat geometry.
1212

1313
For queries that use spherical geometry, a **2dsphere index is a better
1414
option** than a haystack index. :doc:`2dsphere indexes
15-
</core/2dsphere>` allow field reordering; haystack indexes require the
16-
first field to be the location field. Also, haystack indexes are only
17-
usable via commands and so always return all results at once.
15+
</core/2dsphere>` allow field reordering; ``geoHaystack`` indexes
16+
require the first field to be the location field. Also, ``geoHaystack``
17+
indexes are only usable via commands and so always return all results
18+
at once.
1819

19-
Haystack indexes create "buckets" of documents from the same geographic
20-
area in order to improve performance for queries limited to that area.
21-
Each bucket in a haystack index contains all the documents within a
22-
specified proximity to a given longitude and latitude.
20+
Behavior
21+
--------
2322

24-
To create a geohaystacks index, see
23+
``geoHaystack`` indexes create "buckets" of documents from the same
24+
geographic area in order to improve performance for queries limited to
25+
that area. Each bucket in a ``geoHaystack`` index contains all the
26+
documents within a specified proximity to a given longitude and
27+
latitude.
28+
29+
``sparse`` Property
30+
-------------------
31+
32+
``geoHaystack`` indexes are :doc:`sparse </core/index-sparse>` by
33+
default and ignores the :doc:`sparse: true </core/index-sparse>`
34+
option. If a document lacks a ``geoHaystack`` index field (or the field
35+
is ``null`` or an empty array), MongoDB does not add an entry for the
36+
document to the ``geoHaystack`` index. For inserts, MongoDB inserts the
37+
document but does not add to the ``geoHaystack`` index.
38+
39+
For a compound index that includes a ``geoHaystack`` index key along
40+
with a key of a different type, only the ``geoHaystack`` index field
41+
determines whether the index references a document.
42+
43+
Create ``geoHaystack`` Index
44+
----------------------------
45+
46+
To create a ``geoHaystack`` index, see
2547
:doc:`/tutorial/build-a-geohaystack-index`. For information and example
2648
on querying a haystack index, see
2749
:doc:`/tutorial/query-a-geohaystack-index`.

source/core/index-text.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,21 @@ for non-diacritics; i.e. case insensitive for ``[A-z]``.
5656
To specify a language for the ``text`` index, see
5757
:doc:`/tutorial/specify-language-for-text-index`
5858

59+
``sparse`` Property
60+
-------------------
61+
62+
``text`` indexes are :doc:`sparse </core/index-sparse>` by default and
63+
ignores the :doc:`sparse: true </core/index-sparse>` option. If a
64+
document lacks a ``text`` index field (or the field is ``null`` or an
65+
empty array), MongoDB does not add an entry for the document to the
66+
``text`` index. For inserts, MongoDB inserts the document but does not
67+
add to the ``text`` index.
68+
69+
For a compound index that includes a ``text`` index key along with keys
70+
of other types, only the ``text`` index field determine whether the
71+
index references a document. The other keys do not determine whether
72+
the index references the documents or not.
73+
5974
Restrictions
6075
------------
6176

source/reference/command/createIndexes-indexes-field.yaml

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,39 @@ file: /reference/method/db.collection.ensureIndex-options-param.yaml
6464
name: v
6565
position: 9
6666
---
67-
file: /reference/method/db.collection.ensureIndex-options-param.yaml
67+
file: /reference/method/db.collection.ensureIndex-options-text.yaml
6868
name: weights
6969
position: 10
7070
---
71-
file: /reference/method/db.collection.ensureIndex-options-param.yaml
71+
file: /reference/method/db.collection.ensureIndex-options-text.yaml
7272
name: default_language
7373
position: 11
7474
---
75-
file: /reference/method/db.collection.ensureIndex-options-param.yaml
75+
file: /reference/method/db.collection.ensureIndex-options-text.yaml
7676
name: language_override
7777
position: 12
78+
---
79+
file: /reference/method/db.collection.ensureIndex-options-text.yaml
80+
name: textIndexVersion
81+
position: 13
82+
---
83+
file: /reference/method/db.collection.ensureIndex-options-2dsphere.yaml
84+
name: 2dsphereIndexVersion
85+
position: 14
86+
---
87+
file: /reference/method/db.collection.ensureIndex-options-2d.yaml
88+
name: bits
89+
position: 15
90+
---
91+
file: /reference/method/db.collection.ensureIndex-options-2d.yaml
92+
name: min
93+
position: 16
94+
---
95+
file: /reference/method/db.collection.ensureIndex-options-2d.yaml
96+
name: max
97+
position: 17
98+
---
99+
file: /reference/method/db.collection.ensureIndex-options-geohaystack.yaml
100+
name: bucketSize
101+
position: 18
78102
...
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
object:
2+
name: db.collection.ensureIndex()
3+
type: method
4+
field:
5+
optional: true
6+
type: param
7+
name: bits
8+
type: integer
9+
position: 1
10+
description: |
11+
For :doc:`2d </core/2d>` indexes, the number of precision of the
12+
stored :term:`geohash` value of the location data.
13+
14+
The ``bits`` value ranges from 1 to 32 inclusive. The default value
15+
is ``26``.
16+
---
17+
object:
18+
name: db.collection.ensureIndex()
19+
type: method
20+
field:
21+
optional: true
22+
type: param
23+
name: min
24+
type: number
25+
position: 2
26+
description: |
27+
For :doc:`2d </core/2d>` indexes, the lower inclusive boundary for
28+
the longitude and latitude values. The default value is ``-180.0``.
29+
---
30+
object:
31+
name: db.collection.ensureIndex()
32+
type: method
33+
field:
34+
optional: true
35+
type: param
36+
name: max
37+
type: number
38+
position: 3
39+
description: |
40+
For :doc:`2d </core/2d>` indexes, the upper inclusive boundary for
41+
the longitude and latitude values. The default value is ``180.0``.
42+
...
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
object:
2+
name: db.collection.ensureIndex()
3+
type: method
4+
field:
5+
optional: true
6+
type: param
7+
name: 2dsphereIndexVersion
8+
type: integer
9+
position: 1
10+
description: |
11+
For :doc:`2dsphere </core/2dsphere>` indexes, the ``2dsphere``
12+
index version number. Version can be either ``1`` or ``2``.
13+
14+
In MongoDB 2.6, the default version is ``2``. MongoDB 2.4 can only
15+
support version ``1``.
16+
17+
.. versionadded:: 2.6
18+
19+
...
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
object:
2+
name: db.collection.ensureIndex()
3+
type: method
4+
field:
5+
optional: false
6+
type: param
7+
name: bucketSize
8+
type: number
9+
position: 1
10+
description: |
11+
For :doc:`geoHaystack </core/geohaystack>` indexes, specify the
12+
number of units within which to group the location values; i.e. group
13+
in the same bucket those location values that are within the
14+
specified number of units to each other.
15+
16+
The value must be greater than 0.
17+
...

source/reference/method/db.collection.ensureIndex-options-param.yaml

Lines changed: 25 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ description: |
2525
Creates a unique index so that the collection will not accept
2626
insertion of documents where the index key or keys match an existing
2727
value in the index. Specify ``true`` to create a unique index. The
28-
default value is ``false``. This option applies only to ascending/descending
28+
default value is ``false``.
29+
30+
The option is *unavailable* for :doc:`hashed </core/index-hashed>`
2931
indexes.
3032
---
3133
object:
@@ -40,6 +42,10 @@ position: 3
4042
description: |
4143
The name of the index. If unspecified, MongoDB generates an index name
4244
by concatenating the names of the indexed fields and the sort order.
45+
46+
Whether user specified or MongoDB generated, index names including
47+
their full namespace (i.e. ``database.collection``) cannot be longer
48+
than the :limit:`Index Name Limit`.
4349
---
4450
object:
4551
name: db.collection.ensureIndex()
@@ -55,7 +61,10 @@ description: |
5561
indexes only the first occurrence of a key and **removes** all
5662
documents from the collection that contain subsequent occurrences of
5763
that key. Specify ``true`` to create unique index. The default value
58-
is ``false``. This option applies only to scalar indexes.
64+
is ``false``.
65+
66+
The option is *unavailable* for :doc:`hashed </core/index-hashed>`
67+
indexes.
5968
6069
.. deprecated:: 2.6
6170
@@ -75,8 +84,20 @@ position: 5
7584
description: |
7685
If ``true``, the index only references documents with the specified
7786
field. These indexes use less space but behave differently in some
78-
situations (particularly sorts). The default value is ``false``. This
79-
applies only to ascending/descending indexes.
87+
situations (particularly sorts). The default value is ``false``.
88+
See :doc:`/core/index-sparse` for more information.
89+
90+
.. versionchanged:: 2.6
91+
92+
:doc:`2dsphere </core/2dsphere>` indexes are sparse by default and
93+
ignore this option. For a compound index that includes
94+
``2dsphere`` index key(s) along with keys of other types, only the
95+
``2dsphere`` index fields determine whether the index references a
96+
document.
97+
98+
:doc:`2d </core/2d>`, :doc:`geoHaystack </core/geohaystack>`, and
99+
:doc:`text </core/index-text>` indexes behave similarly to the
100+
:doc:`2dsphere </core/2dsphere>` indexes.
80101
---
81102
object:
82103
name: db.collection.ensureIndex()
@@ -108,54 +129,4 @@ description: |
108129
version 2.0, the this value was 0; versions 2.0 and later use version
109130
1, which provides a smaller and faster index format. Specify a
110131
different index version *only* in unusual situations.
111-
---
112-
object:
113-
name: db.collection.ensureIndex()
114-
type: method
115-
field:
116-
optional: true
117-
type: param
118-
name: weights
119-
type: document
120-
position: 8
121-
description: |
122-
For ``text`` indexes, the significance of the field relative to the
123-
other indexed fields. The document contains field and weight pairs.
124-
The weight is a number ranging from 1 to 99,999 and denotes the
125-
significance of the field relative to the other indexed fields in
126-
terms of the score. You can specify weights for some or all the
127-
indexed fields. See :doc:`/tutorial/control-results-of-text-search` to
128-
adjust the scores. The default value is ``1``. This applies to
129-
``text`` indexes only.
130-
---
131-
object:
132-
name: db.collection.ensureIndex()
133-
type: method
134-
field:
135-
optional: true
136-
type: param
137-
name: default_language
138-
type: string
139-
position: 9
140-
description: |
141-
For a ``text`` index, the language that determines the list of stop
142-
words and the rules for the stemmer and tokenizer. See
143-
:ref:`text-search-languages` for the available languages and
144-
:doc:`/tutorial/specify-language-for-text-index` for more information
145-
and examples. The default value is ``english``. This applies to
146-
``text`` indexes only.
147-
---
148-
object:
149-
name: db.collection.ensureIndex()
150-
type: method
151-
field:
152-
optional: true
153-
type: param
154-
name: language_override
155-
type: string
156-
position: 10
157-
description: |
158-
For a ``text`` index, specify the name of the field in the document
159-
that contains, for that document, the language to override the default
160-
language. The default value is ``language``.
161132
...

0 commit comments

Comments
 (0)