javascript - How to find by 2 geopoints from mongodb using mongoose?
问题描述
I'm researching in one project with NodeJS(mongoose driver) back with MongoDB as database and Angular 6 on front. We need realise on back some feature to search some data by 2 geoPoints. Actually i can't find any information how can i store 2 points and find by this points in mongo.
I find some info on mongoose documentation about GeoJSON querying with $near but it search only by one point.
解决方案
非常感谢!看起来我应该更深入地查找文档)下面的代码是帮助我解决问题的方法:
Way.aggregate(
[{
$match: {
'origin.coordinates': {
$geoWithin: { $centerSphere: [ [ origin.lat, origin.lng ], 0.2/6378.1 ] }
},
'destination.coordinates': {
$geoWithin: { $centerSphere: [ [ destination.lat, destination.lng ], 0.2/6378.1 ] }
}
}
}], function(error, results){
Way.populate(results, {path: 'user'}, function(err, ready){
});
}
)
推荐阅读
- r - 在R语言中,如果rhandsontable的行名很长,会在屏幕上只显示一部分
- wordpress - 在没有 Ciomand Line 访问和提供商支持的情况下在 Wordpress 上安装 SSL
- python - 如何在三个维度上比较 3D 矢量与平面的方向
- c# - 数据源配置向导:无法检索表或视图的架构信息
- javascript - 为什么这个mysql错误会导致nodejs崩溃而不是去catch函数?
- overlay - AgGrid“serverSide”rowModel 无法识别自定义覆盖组件(加载和 noRows)
- python - 将两个 dfs 与一列分组并连接所有行值
- c# - 如何在应用程序和条码阅读器之间建立连接?
- mysql - mysql 无法使用本地加载数据导入以 \r\n\r\n 结尾的 csv 行
- database - DCount/检查 Access DB 字段中是否存在值