Skip to content

Instantly share code, notes, and snippets.

@anujsinghwd
Forked from vkarpov15/geo.js
Created November 10, 2021 12:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anujsinghwd/fd9ced2521e779644afc8ef964e97fdc to your computer and use it in GitHub Desktop.
Save anujsinghwd/fd9ced2521e779644afc8ef964e97fdc to your computer and use it in GitHub Desktop.
Example of querying a GeoJSON feature collection in MongoDB
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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment