Skip to content

Instantly share code, notes, and snippets.

@vkarpov15
Created July 18, 2018 13:49
Show Gist options
  • Select an option

  • Save vkarpov15/b4d6c924883b8b2e62e4a6285bf8eded to your computer and use it in GitHub Desktop.

Select an option

Save vkarpov15/b4d6c924883b8b2e62e4a6285bf8eded to your computer and use it in GitHub Desktop.

Revisions

  1. vkarpov15 created this gist Jul 18, 2018.
    41 changes: 41 additions & 0 deletions geo.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    db.test.drop();
    db.test.insertOne({
    name: 'Denver',
    location: {
    "type": "FeatureCollection",
    "features": [
    {
    "type": "Feature",
    "properties": {},
    "geometry": {
    "type": "Point",
    "coordinates": [
    -104.9903,
    39.7392
    ]
    }
    }
    ]
    }
    });

    db.test.createIndex( { "location.features.geometry": "2dsphere" } )

    const doc = db.test.findOne({
    'location.features.geometry': {
    $geoIntersects: {
    $geometry: {
    "type": "Polygon",
    "coordinates": [[
    [-109, 41],
    [-102, 41],
    [-102, 37],
    [-109, 37],
    [-109, 41]
    ]]
    }
    }
    }
    });

    print(doc.name);