0
To get a Mongodb database use the following code:
router.get('/multibancos', function(req, res, next){
MB.aggregate().near({
near: { type: "Point", coordinates: [parseFloat(req.query.lng) , parseFloat(req.query.lat)] },
distanceField: "dist.calculated",
maxDistance: 100000,
spherical: true
}).then(function(mb){
res.send(mb);
}).catch(next);
});
and call with the following link:
localhost:4000/api/multibancos/?lng=80&lat=-20
Turns out it gives me my mistake back:
{
"error": "geoNear command failed: { ok: 0.0, errmsg: \"no geo indices for geoNear\" }"
}
try to execute this command in the:
db.ensureIndex({ loc: '2dsphere' });
and then run the query again– BrTkCa
run before "router.get('...')" ?
– SaPires
In the same shell Mongo @Sapires
– BrTkCa