-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
geohaystack.txt
73 lines (55 loc) · 2.33 KB
/
geohaystack.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
.. _index-geohaystack-index:
=======================
``geoHaystack`` Indexes
=======================
.. default-domain:: mongodb
.. contents:: On this page
:local:
:backlinks: none
:depth: 1
:class: singlecol
A ``geoHaystack`` index is a special index that is optimized to return
results over small areas. ``geoHaystack`` indexes improve performance
on queries that use flat geometry.
For queries that use spherical geometry, a **2dsphere index is a better
option** than a haystack index. :doc:`2dsphere indexes
</core/2dsphere>` allow field reordering; ``geoHaystack`` indexes
require the first field to be the location field. Also, ``geoHaystack``
indexes are only usable via commands and so always return all results
at once.
Behavior
--------
``geoHaystack`` indexes create "buckets" of documents from the same
geographic area in order to improve performance for queries limited to
that area. Each bucket in a ``geoHaystack`` index contains all the
documents within a specified proximity to a given longitude and
latitude.
``sparse`` Property
-------------------
``geoHaystack`` indexes are :doc:`sparse </core/index-sparse>` by
default and ignore the :doc:`sparse: true </core/index-sparse>`
option. If a document lacks a ``geoHaystack`` index field (or the field
is ``null`` or an empty array), MongoDB does not add an entry for the
document to the ``geoHaystack`` index. For inserts, MongoDB inserts the
document but does not add to the ``geoHaystack`` index.
``geoHaystack`` indexes include one ``geoHaystack`` index key and one
non-geospatial index key; however, only the ``geoHaystack`` index field
determines whether the index references a document.
Collation Option
~~~~~~~~~~~~~~~~
``geoHaystack`` indexes only support simple binary comparison and do not support
the :ref:`collation <collation>`.
To create a ``geoHaystack`` index on a a collection that has a non-simple
collation, you must explicitly specify ``{collation: {locale: "simple"}
}`` when creating the index.
Create ``geoHaystack`` Index
----------------------------
To create a ``geoHaystack`` index, see
:doc:`/tutorial/build-a-geohaystack-index`. For information and example
on querying a haystack index, see
:doc:`/tutorial/query-a-geohaystack-index`.
.. toctree::
:titlesonly:
:hidden:
/tutorial/build-a-geohaystack-index
/tutorial/query-a-geohaystack-index