Mongodb error - geoNear "in geo indices"

Asked

Viewed 83 times

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

  • run before "router.get('...')" ?

  • In the same shell Mongo @Sapires

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.