geoHaystack
Indexes索引
Removed in MongoDB 5.0在MongoDB 5.0中删除
MongoDB 5.0 removes the deprecated geoHaystack index and MongoDB 5.0删除了不推荐使用的geoHaystack索引和geoSearch
command. geoSearch
命令。Use a 2d index with 请改用带有$geoNear
or one of the supported geospatial query operators instead.$geoNear
的2d
索引或支持的地理空间查询运算符之一。
Upgrading your MongoDB instance to 5.0 and setting featureCompatibilityVersion to 将MongoDB实例升级到5.0并将5.0
will delete any pre-existing geoHaystack indexes.featureCompatibilityVersion
设置为5.0将删除任何预先存在的geoHaystack
索引。
A geoHaystack
index is a special index that is optimized to return results over small areas. geoHaystack
索引是一种特殊的索引,经过优化可以在小范围内返回结果。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. 对于使用球形几何体的查询,2dsphere
索引比干草堆索引更好。2dsphere indexes 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 sparse by default and ignore the sparse: true
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 collation.
To create a geoHaystack
index on 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 Create a Haystack Index. For information and example on querying a haystack index, see Query a Haystack Index.