Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Geo query within kilometers without sorting #4824

Closed
mtrezza opened this issue Jun 11, 2018 · 0 comments
Closed

Geo query within kilometers without sorting #4824

mtrezza opened this issue Jun 11, 2018 · 0 comments

Comments

@mtrezza
Copy link
Member

mtrezza commented Jun 11, 2018

I tried to add a $geoWithin constraint to a Parse.Query like so:

var query = new Parse.Query("MyCollection");
var jsonQuery = query.toJSON();

jsonQuery.where.location = {
    "$geoWithin": {
        "$centerSphere": [
            [geoPoint.longitude, geoPoint.latitude],
            10 / 6371.0
        ]
    }
};

query.withJSON(jsonQuery);

It throws the error:

bad $geoWithin value; $polygon should contain at least 3 GeoPoints.

The reason is apparently that Parse Server's Mongo Transformer only accepts a polygon parameter with $geoWithin.

The advantage of a $geoWithin.$centerSphere constraint vs. the existing withinKilometers constraint is that is is not using $near to sort the results by distance and therefore executed faster.

How can I add a query constraint that limits the results to documents with a location field within a certain radius in km of a geo coordinate?

If not I'll do to a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants