Skip to content

Add polygonContain to Query #3942

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

Closed
dplewis opened this issue Jun 21, 2017 · 15 comments
Closed

Add polygonContain to Query #3942

dplewis opened this issue Jun 21, 2017 · 15 comments

Comments

@dplewis
Copy link
Member

dplewis commented Jun 21, 2017

Mongo has a $geoIntersects that I want to use to return all polygons that contains a single point. Unfortunately it only supports 2dsphere indexes and parse-server currently doesn't use geoJson.

Maybe we can reopen #524 to support legacy coordinates (2d) as well as geoJSON (2dsphere) indexes.

Adding Type Polygon to Schema?

@flovilmart
Copy link
Contributor

We need to introduce a new type to the schéma, i’m all Open for it as Long as we don’t break legacy points. We’ll also need to define those types in the client SDKs!

@dplewis
Copy link
Member Author

dplewis commented Jun 21, 2017

I've also read the 2dsphere indexes can cover multiple geospatial fields in a document. It might get rid of that MongoDB only supports one GeoPoint field in a class error

@flovilmart
Copy link
Contributor

Yeah if using polygons obviously :)

@dplewis
Copy link
Member Author

dplewis commented Jun 21, 2017

Maybe a tool to convert legacy to 2dsphere would help.

@flovilmart
Copy link
Contributor

Yeah but that imply migrating data in production more likely, which could be problematic at large scale.

@dplewis
Copy link
Member Author

dplewis commented Jun 21, 2017

The main issue I see is $nearSphere. I can test for 2d vs 2dsphere but the rest format are different.

2d

location : { 
    $nearSphere : [ -73.9667, 40.78 ], 
    $maxDistance: 0.10 
}

2dsphere

location: {
    $nearSphere: {
        $geometry: {
              type : "Point",
              coordinates : [ -73.9667, 40.78 ]
        },
        $maxDistance: 0.10
    }
}

For polygonContain I could only use geojson for Type Polygon and keep geopoints 2d for now

@flovilmart
Copy link
Contributor

Also the indexes are different and I’m not sure you can index the same column 2 2D and 2dsphere

@dplewis
Copy link
Member Author

dplewis commented Jun 21, 2017

You can have multiple geospatial indexes per collection. Unless you are using $geoNear which we aren't using. I just created both on the same collection without problems.

https://docs.mongodb.com/manual/core/2dsphere/#geonear-and-geonear-restrictions

@dplewis
Copy link
Member Author

dplewis commented Jul 14, 2017

I'll probably do 2dsphere indexes for legacy GeoPoints at a later date just closing this for now.

@dplewis dplewis closed this as completed Jul 14, 2017
@madsb
Copy link
Contributor

madsb commented Jul 25, 2017

Could the $nearSphere dilemma be solved by adding the equivalent SDK methods for a $geoWithin query? We could have withinCenterSphereRadians and the equivalent withinCenterSphereMiles and withinCenterSphereKilometers convenience methods. Then, for people who wants to use 2dsphere indexes, add in the documentation that the legacy calls to $nearSphere are deprecated? I don't know about adding the indexes… maybe for starters we would have to do that manually?

@flovilmart
Copy link
Contributor

@madsb do you wanna try adding a PR for it? Which version of mongodb do they start using those indexes?

@madsb
Copy link
Contributor

madsb commented Jul 25, 2017

I'll try to take a stab at it. I think $geoWithin queries are supported from version 2.4 and upwards: https://docs.mongodb.com/manual/reference/operator/query/geoWithin/

@dplewis
Copy link
Member Author

dplewis commented Jul 28, 2017

@madsb withinCenterSphere doesn't sort like $nearSphere which a lot of applications have sorting. But not sorting leads to faster queries, we can use this as a option for users who don't care about sorting. To get $nearSphere to work with 2dsphere is just changing the mongo transform, using createIndexIfNeeded and updating to geoJSON

What do you think?

@dplewis dplewis reopened this Jul 28, 2017
@dplewis dplewis closed this as completed Jul 28, 2017
@madsb
Copy link
Contributor

madsb commented Jul 29, 2017

You're right about the sorting, I totally missed that (I'm not using sorting either in my app).

Still a bit novice about the whole index 2d/2dsphere thing. Databases are not my strong suit. Would probably be up to @drew-gross or @flovilmart to decide if now is the time to support GeoJSON. My vote is squarely in the 'yes' camp 😄

@madsb
Copy link
Contributor

madsb commented Jul 30, 2017

I closed #4060. I may re-open it at a later point, but I made another pull request (#4064) that I'd prefer to have merged sooner, that allows for basic coordinate pairs in a $polygon query.

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

3 participants