Mongoose aggregation with geonear

后端 未结 2 437
遥遥无期
遥遥无期 2021-01-07 10:32

I\'m trying to implement paging with Mongoose geoNear command. It seem skip is not supported with geoNear, and I understand aggregation would work (with paging with a perfor

2条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-07 11:07

    location.aggregate({"$geoNear": { "near": { "type": "Point", "coordinates": [parseFloat(req.params.lon), parseFloat(req.params.lat)] }, "maxDistance":500, 'distanceField' : 'distance', spherical: true
          }}, 
        function(err, places) {
       if(!err){
               console.log(places);
                res.send('({"records":' + JSON.stringify(places) + '});');
            }
            else{
                console.log(err);
                res.send("error coming")
            }
        });`
    
    Above Query working fine in mongo shell but not working in mongoose 
    

提交回复
热议问题