$ geoWithin查询表单mongodb到mongoose语句

时间:2014-05-18 10:32:38

标签: node.js mongodb mongoose

从mongodb获得此查询:

 db.location.find(
 {loc: { $geoWithin: { $centerSphere: [ [ 9, 9], 
 radius ] } }, action:1 })
 .limit(10)
 .skip(1, function(err,   result) {
    console.dir(result);
 });

如何使用geoWithin将其翻译为mongoose语句?

1 个答案:

答案 0 :(得分:1)

有些事情是这样的:

 LocationModel.where('loc').within({ center: [ your_lat, your_lng], radius: your_radius, unique: true, spherical: true }).where('action').equals(your_action).skip(your_skip).limit(10).exec(
    function(err, result) {
    console.dir(result);
});

当然需要创建LocationModel和LocationSchema, 我希望它可以提供帮助。