Skip to content

Geo query within kilometers without sorting #4824

Closed
@mtrezza

Description

@mtrezza

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions