[英]Find 10 nearest points
我想知道如何搜索距我的位置最近的10个点。 目前我有这样的事情:
const query50 = Event.where('location').near({
center: {
type: 'Point',
coordinates: [data.lng, data.lat]
},
maxDistance: 50000,
spherical: true
});
但这使我可以显示半径50公里以内的所有事件。 现在,我希望获取最接近我的10个,但不设置maxDistance 。 有什么有效的方法吗?
简短的答案是没有。 但是您可以根据到您所在位置的距离对结果进行分类,速度相当快。
使用.limit(n)
方法进行限制
db.places
.find({
location:
{
$near: {
$geometry: { type: "Point", coordinates: [-73.9667, 40.78] }
}
}
})
.limit(10)
.exec(function(err, result) { /*...*/ });
$maxDistance
和$minDistance
是可选的
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.