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并将featureCompatibilityVersion设置为5.0将删除任何预先存在的5.0
will delete any pre-existing geoHaystack indexes.geoHaystack
索引。
A haystack index is a special 干草堆索引是一种特殊的2d
geospatial index that is optimized to return results over small areas. 2d
地理空间索引,经过优化后可返回小区域的结果。To create a haystack index see Create a Haystack Index.要创建干草堆索引,请参阅创建干草垛索引。
To query a haystack index, use the 要查询干草堆索引,请使用geoSearch
command. geoSearch
命令。You must specify both the coordinates and the additional field to 您必须为geoSearch
. geoSearch
指定坐标和附加字段。For example, to return all documents with the value 例如,要在示例点附近的restaurant
in the type
field near the example point, the command would resemble:type
字段中返回值为restaurant
的所有文档,命令如下:
db.runCommand( { geoSearch : "places" , search : { type: "restaurant" } , near : [-74, 40.74] , maxDistance : 10 } )
Haystack indexes are not suited to queries for the complete list of documents closest to a particular location. 干草堆索引不适合查询离特定位置最近的完整文档列表。The closest documents could be more distant compared to the bucket size.与桶大小相比,最近的文档可能更远。
Spherical query operations球形查询操作 are not currently supported by haystack indexes.草堆索引当前不支持。
The find()
method cannot access the haystack index.find()
方法无法访问干草堆索引。