简体   繁体   English

如何使用mongoose应用geoNear并获得两个坐标之间的距离

[英]How to apply geoNear with mongoose and get distance between two coordinates

I am looking for a solution to retrieve docs from my collection by applying a query in Node. 我正在寻找一种解决方案,通过在Node中应用查询来从我的集合中检索文档。 The Purpose is to retrieve the distance between two coordinates. 目的是检索两个坐标之间的距离。 It can be implemented using Native MongoDb but i want to get results with mongoose. 它可以使用Native MongoDb实现,但我想用mongoose获得结果。 How do i do that ? 我怎么做 ?

The geoNear method from mongoose is used as following: 来自geoNear方法如下:

Model.geoNear([1,3], { maxDistance : 5, spherical : true }, function(err, results, stats) {
   console.log(results);
});

// geoJson
var point = { type : "Point", coordinates : [9,9] };
Model.geoNear(point, { maxDistance : 5, spherical : true }, function(err, results, stats) {
   console.log(results);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM