如何在Mongoose中使用geoSearch获得距离

时间:2014-11-04 08:27:12

标签: node.js mongodb mongoose

我成功地使用geoNear()让所有商店都有距离;

我成功地使用geoSearch()来获取特殊类型的商店而不显示我的距离。

如何列出特殊类型的商店以及向我显示距离?

Model.geoNear({
"type": "Point",
"coordinates": opts.coordinates
}, {
lean: true,
spherical: true,
includeLocs: true,
maxDistance: opts.radius / EARTH_RADIUS,
distanceMultiplier: EARTH_RADIUS
}, function(err, shops, stats) {
var results = exports.trimedDistance(shops);
deferred.resolve(results);
});

-

 Model.geoSearch({
_category: mongoose.Types.ObjectId(opts.categoryId)
}, {
near: opts.coordinates,
lean: true,
limit: 10,
maxDistance: opts.radius / EARTH_RADIUS
}, function(err, shops) {
var results = exports.trimedDistance(shops);
deferred.resolve(results);
});

1 个答案:

答案 0 :(得分:0)