getting-MEAN
getting-MEAN copied to clipboard
Chapter 07- geoNear library doesn't work properly
Hello i changed the locationsListByDistance function in app_api\controllers\location.js Delete the old Loc.geoNear function and added Loc.aggregate function. In this method you don't need buildLocationList func. anymore because aggregate calculates the distance by itself. ... Loc .aggregate([{ $geoNear: { near: point, maxDistance: theEarth.getRadsFromDistance(maxDistance), includeLocs: "dist.location", distanceField: "dist.calculated", spherical: true, num: 10 } }]) .limit(20) .exec((err, results) => { if (err) { res .status(400) .json(err) } else { res .status(200) .json(results); } }); ...