Cannot project $dist.location after $geoNear query on atlas custom https endpoint

I followed the $geoNear documentation and created a $geoNear query that works correctly:

$geoNear: {
            near: { type: "Point", coordinates: [lon, lat] },
            distanceField: "dist.calculated",
            maxDistance: distance,
            includeLocs: "dist.location",
            spherical: true,
            query: {
              type: type,

this is connected to a function enabled on a custom https endpoint. i get the results without any problem.

the problem is in the next stage where i want to project the location in my results:

          $project: {
            _id: 1,
            type: 1,
            distance: "$dist.calculated", // <- this returns the correct value
            position: "$dist.location", // <- if i add this line i get server error (500)

i also tried “location: 1” and get same error. i need the coordinates in the project stage because i want to use them in my results view.

the solution i found now is to run another query that loops the results and adds the location to each item but i wish to use the location during query stages but any attempt leads to error.

any suggestions about it?


"accept-encoding": "null",

to the headers in the request to the endpoint seems to fix the problem

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.