我正在编写一个端点,它响应半径内最近的目的地以及给定坐标的距离。我使用 mongodb v2.4 作为数据存储的节点。所有位置数据都以GeoJson格式存储,并且在集合上创建了2dsphere索引。
db.dest.geoNear(lon,lat,
{num: 30, maxDistance: 20000, query: {someQuery for filtering}
, spherical: true, distanceMultiplier: 6378.1}
, function(err, results){})
maxDistance以米为单位,如docs中所述,distanceMultiplier为地球半径。但不知何故,maxDistance被忽略了。以下是示例输出
{ results:
[ { dis: 4.755328392420995, obj: [Object] },
{ dis: 4.807060479634336, obj: [Object] },
{ dis: 5.492899524461121, obj: [Object] },
{ dis: 5.511199055273086, obj: [Object] },
{ dis: 5.511199055273086, obj: [Object] },
{ dis: 5.660463080160375, obj: [Object] },
{ dis: 5.682780578954481, obj: [Object] },
{ dis: 5.803407121966422, obj: [Object] },
{ dis: 5.89496185238861, obj: [Object] },
{ dis: 5.912218148470887, obj: [Object] },
{ dis: 6.043122792876154, obj: [Object] },
{ dis: 6.138052836083365, obj: [Object] },
{ dis: 6.152973556017727, obj: [Object] },
{ dis: 6.895647639041904, obj: [Object] },
{ dis: 7.487292026198752, obj: [Object] },
{ dis: 7.487292026198752, obj: [Object] },
{ dis: 8.18958659411917, obj: [Object] },
{ dis: 8.18958659411917, obj: [Object] },
{ dis: 8.18958659411917, obj: [Object] },
{ dis: 116.1262295642328, obj: [Object] },
{ dis: 197.59476541200738, obj: [Object] },
{ dis: 281.1553130990714, obj: [Object] },
{ dis: 293.0284376976589, obj: [Object] },
{ dis: 293.0961663596255, obj: [Object] },
{ dis: 293.10437722899286, obj: [Object] },
{ dis: 293.3819790311049, obj: [Object] },
{ dis: 293.5152536606294, obj: [Object] },
{ dis: 293.5332617516882, obj: [Object] },
{ dis: 293.5546344697255, obj: [Object] },
{ dis: 294.7790206142557, obj: [Object] } ],
stats:
{ nscanned: 470,
objectsLoaded: 470,
avgDistance: 102.08913656122567,
maxDistance: 294.7790206142557,
time: 37 },
ok: 1 }
如您所见,尾随条目超出20公里半径。我做错了什么?