Home > Net >  $geoWithin for a point returns empty
$geoWithin for a point returns empty

Time:10-04

I have stored locations in my documents according to the Postman

lat and lon are the variables that hold co-ordinates of my current location.

CodePudding user response:

This playground example seems to demonstrate the query with the given sample data and predicate values correctly returning the results. The predicate values (lat: 73.05302350472694, lon: 33.69672730400787, distance: 10) come from this comment, with the distance having the radian conversion from the code applied (10 / 3963.2).

I'm not an expert, but I'm curious if the lon and lat parameters have been inadvertently swapped. From the screenshot, the GET request hits:

{{LOCAL}}/api/items/{{lon}}/{{lat}}/10

But in the handler code I see:

// @route     GET /api/items/:lat/:lon/:distance
// @access    Private
exports.getItems = asyncHandler( async (req, res, next) => {
  const { lat, lon, distance } = req.params;

Does ordering matter when these variables are being processed? I'm assuming so, which means that the Postman request has the two variables in the wrong order. That would certainly explain why the query is failing to return results.

  • Related