fix: correctly detect geo filters to be merged (COMPASS-4968) #2407
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
mergeGeoFilter incorrectly detected geo filter queries by looking at the field name to see if it is "coordinates", but coordinate fields can be called anything.
The geo queries coming from the schema are actually using Geospatial Query Operators, so
newGeoQueryFilter
looks like this for the first query:Where
"coordinates"
is just the field name. It could also be something like"start station location"
or"end station location"
.Then for the second one onwards,
newGeoQueryFilter
looks something like like this:If you draw a polygon rather than a circle, then it still uses
$geoWithin
, but$centerSphere
is just replaced with$geometry
. Here's a nice complicated query with multiple circles and geometry across two different coordinate fields:Changes
['$geoIntersects', '$geoWithin', '$near', '$nearSphere']
. This means it works with any coordinate field names and the exact coordinate format used ( type: "point" vs just two-tuples for longitude and latitude) is irrelevant.{ lon: X, lat: Y}
to specify exact coordinates. Technically that's a correct way to specify coordinates because it is the legacy coordinate pair via an embedded document (where the first one is the field to use for longitude and the second one the field for latitide) but it was incorrect in that the schema analyzer doesn't build queries with exact coordinates - it builds $geoWithin style queries.