Skip to content

Add polygonContain to Query #3942

Closed
Closed

Description

@dplewis

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?

Activity

  1. flovilmart commented on Jun 21, 2017

    @flovilmart
    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!

  2. dplewis commented on Jun 21, 2017

    @dplewis
    MemberAuthor

    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

  3. flovilmart commented on Jun 21, 2017

    @flovilmart
    Contributor

    Yeah if using polygons obviously :)

  4. dplewis commented on Jun 21, 2017

    @dplewis
    MemberAuthor

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

  5. flovilmart commented on Jun 21, 2017

    @flovilmart
    Contributor

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

  6. dplewis commented on Jun 21, 2017

    @dplewis
    MemberAuthor

    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

  7. flovilmart commented on Jun 21, 2017

    @flovilmart
    Contributor

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

  8. dplewis commented on Jun 21, 2017

    @dplewis
    MemberAuthor

    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

  9. dplewis commented on Jul 14, 2017

    @dplewis
    MemberAuthor

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

  10. madsb commented on Jul 25, 2017

    @madsb
    Contributor

    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?

  11. flovilmart commented on Jul 25, 2017

    @flovilmart
    Contributor

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

  12. madsb commented on Jul 25, 2017

    @madsb
    Contributor

    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/

  13. dplewis commented on Jul 28, 2017

    @dplewis
    MemberAuthor

    @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?

  14. madsb commented on Jul 29, 2017

    @madsb
    Contributor

    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 😄

  15. madsb commented on Jul 30, 2017

    @madsb
    Contributor

    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

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