Search code examples
mongodbgeolocationgeo

mongodb how to find exclude areas, $geoExclusion?


There is a $geoIntersection. But does it exist something similar to $geoExclusion? I would like to find polygons that do not intersect to certain areas.


Solution

  • Try using $not:

    db.places.find({ "loc" : { "$not" : { "$geoIntersects" : { 
        "$geometry" : { 
            "type" : "Polygon", 
            "coordinates" : [[ [ 0, 0 ], [ 3, 6 ], [ 6, 1 ], [ 0, 0 ] ]] 
        } 
    } } } })