I can calculate distances in MongoDB from Point to Point, using 2dsphere index.
However, now I need the calculate the distance from a given point to a Polygon.
I'm using the following code :
Document commandNoIntersect = new Document("geoNear", "Location")
.append("near", new com.mongodb.client.model.geojson.Point(new Position(Longitude, Latitude)))
.append("spherical", true)
.append("query", new Document(new Document("location", locationId)))
.append("distanceMultiplier", 0.001);
database.runCommand(commandNoIntersect);
My 2dsphere index is the coordinates of the Polygon. The results are not consistent as in Point to Point distances.
I appreciate your feedback,