【发布时间】:2015-12-03 03:10:25
【问题描述】:
我的文档结构如下:
{ agency_key : '',
route_id: '',
direction_id: '',
stops: [
{stop_id:15,
stop_lat: '',
stop_lon: '',
loc: [-83.118972, 42, 121567]
},
{...
}
]
}
我想在集合中的每个文档的给定距离内找到靠近给定 (lat,lon) 对的停靠点。我创建了二维索引。我试过 $unwind,然后 $geoNear 但它说 $geoNear 只能在管道的第一阶段。 我试过这个:
db.tm_stops.aggregate([
... {
... $geoNear: { near: {coordinates: [-82.958841, 42.370114] }, distanceField: "stops.calculated", query: { agency_key: "DDOT"},
... includeLocs: "stops.loc" }
... }
... ])
我尝试了以下方法:
db.tm_stops.find({stops:{$near:[-82.958841, 42.370114], $maxDistance: 1 } } )
它会抛出这个错误:
error: {
"$err" : "Unable to execute query: error processing query: ns=gtfs.tm_stops limit=0 skip=0\nTree: GEONEAR field=stops maxdist=1 isNearSphere=0\nSort: {}\nProj: {}\n planner returned error: unable to find index for $geoNear query",
"code" : 17007
我的 mongo 查询应该是什么?我需要从 Node.js 应用程序执行此操作,但我想先在 Mongo shell 中查看一些结果。提前致谢。
【问题讨论】:
标签: node.js mongodb aggregation-framework pipeline