我有一个具有以下字段的地方的集合:
{
"name":"AAAAA",
.
.
"location" : {
"loc" : {
"type" : "Point",
"coordinates" : [
25.381911,
37.109551
]
}
.
.
}
}
我想将聚合与geoNear结合使用,但找不到找到设置位置字段的方法。用这样的查询:
db.places.aggregate([
{
$geoNear: {
near: { type: "Point", coordinates: [ -73.99279 , 40.719296 ] },
distanceField: "dist",
maxDistance: 2,
query: {
"categories.categoryList":"Cocktail Bar"
},
includeLocs: "location.loc",
num: 5,
spherical: true
}
}]);
我收到此错误:
"errmsg" : "exception: geoNear command failed: { ok: 0.0, errmsg: \"no geo indices for geoNear\" }"
我认为问题在于位置文档中嵌入了“ loc”字段,我无法“告诉” mongo在“ location.loc”附近进行搜索。
最终的解决方案是在嵌入式位置文档中不包括GeoJsonPoint。我只是以与name相同的方式使用了“ loc”,而MongoDB则“理解”了文档中存在坐标的方式。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句