Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on May 17, 2021. It is now read-only.

feat: Add support for $geoIntersects, $near and $nearSphere queries #11

Merged
durran merged 5 commits into master from bug/CHARTS-2172-geo-operators-invalid
Mar 1, 2019

Conversation

@matt-d-rat
Copy link
Contributor

@matt-d-rat matt-d-rat commented Feb 28, 2019
edited
Loading

This PR adds support for the following Geospatial Query operators:

In the case of $near and $nearSphere support has also been added for specifying the optional $minDistance and $maxDistance limits to the query.

In addition, I have made some minor updates to the validation of $geometry that is used by all of the geo-operators to ensure that we check the type and coordinates values are correct. I have also added additional grammar for legacy coordinates, validating that the numbers provided in the array syntax are valid longitude and latitude numbers.

As such the following queries no longer throw a parser error (verified through unit tests and the online PEG.js parser):

$geoIntersects

{
 "address.location": {
 "$geoIntersects": {
 "$geometry": {
 "type": "Polygon" ,
 "coordinates": [
 [
 [ 0, 0 ],
 [ 3, 6 ],
 [ 6, 1 ],
 [ 0, 0 ]
 ]
 ]
 }
 }
 }
}

$near

{
 "address.location": {
 "$near" : {
 "$geometry": {
 "type": "Point",
 "coordinates": [0,0]
 }
 }
 }
}
{
 "address.location": {
 "$near" : [1, 90]
 }
}
{
 "address.location": {
 "$near" : {
 "$geometry": {
 "type": "Point",
 "coordinates": [0,0]
 },
 "$minDistance": 1000,
 "$maxDistance": 5000
 }
 }
}
{
 "address.location": {
 "$near" : [1, 90],
 "$maxDistance": 5000,
 "$minDistance": 1000
 }
}

$nearSphere

{
 "address.location": {
 "$nearSphere" : {
 "$geometry": {
 "type": "Point",
 "coordinates": [0,0]
 }
 }
 }
}
{
 "address.location": {
 "$nearSphere" : [1, 90]
 }
}
{
 "address.location": {
 "$nearSphere" : {
 "$geometry": {
 "type": "Point",
 "coordinates": [0,0]
 },
 "$minDistance": 1000,
 "$maxDistance": 5000
 }
 }
}
{
 "address.location": {
 "$nearSphere" : [1, 90],
 "$maxDistance": 5000,
 "$minDistance": 1000
 }
}

imlucas reacted with hooray emoji
Copy link
Contributor Author

matt-d-rat commented Feb 28, 2019
edited
Loading

@durran Assuming you are happy with the changes, would you be okay with me publishing a minor package update to npm, and updating the mongodb-query-parser to use the new version? Given the timezone differences I can ask someone on the Charts team to approve the change to the downstream repo so I am not blocked waiting for async approvals.

@matt-d-rat matt-d-rat force-pushed the bug/CHARTS-2172-geo-operators-invalid branch 2 times, most recently from f57d096 to 95c7650 Compare February 28, 2019 23:00
...cation. Add array_number, geometry_type and geometry_coordinates operators.
...onal grammar helpers.
- Add number_positive grammar
- Add number_longitude grammar
- Add number_latitude grammar
- Add array_number grammar
- Add legacy_coordinates grammar
- Add $near/$nearSphere operator
- Add $minDistance/$maxDistance operator
- Updated unit test cases
@matt-d-rat matt-d-rat force-pushed the bug/CHARTS-2172-geo-operators-invalid branch from 95c7650 to a5eb59a Compare March 1, 2019 01:07
Copy link

@shaketbaby shaketbaby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Copy link
Member

durran commented Mar 1, 2019

Yes! Ship it. :)

@durran durran merged commit bb13ad9 into master Mar 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

@durran durran Awaiting requested review from durran

@rueckstiess rueckstiess Awaiting requested review from rueckstiess

1 more reviewer

@shaketbaby shaketbaby shaketbaby approved these changes

Reviewers whose approvals may not affect merge requirements

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /