【发布时间】:2019-06-21 07:26:35
【问题描述】:
在 Mongodb + Nodejs 中进行这个精确的 sql 查询的正确方法是什么?
select *,
acos(cos(centerLat * (PI()/180)) *
cos(centerLon * (PI()/180)) *
cos(lat * (PI()/180)) *
cos(lon * (PI()/180))
+
cos(centerLat * (PI()/180)) *
sin(centerLon * (PI()/180)) *
cos(lat * (PI()/180)) *
sin(lon * (PI()/180))
+
sin(centerLat * (PI()/180)) *
sin(lat * (PI()/180))
) * 3959 as Dist
from TABLE_NAME
having Dist < radius
order by Dist
取自此答案的代码: https://stackoverflow.com/a/12235184/8025329
这是我的猫鼬模式:
const spotSchema = new Schema({
latitude: { type: String, required: true },
longitude: { type: String, required: true },
spotDate: { type: Date, required: true }
});
我希望检索显示用户位置附近地图中点的记录。我认为这部分与公式+ sql查询有关。我的问题是如何将其转换为 Mongodb + NodeJs。
谢谢大家。
【问题讨论】:
标签: node.js mongodb-query