Articles → MONGODB → Introduction To Geospatial Queries In Mongodb
Introduction To Geospatial Queries In Mongodb
What Is Geospatial?
What Are Geospatial Queries?
Shapes In Geospatial Queries
| Shapes | Description |
|---|
| Point | A single position. |
| LineString | A set of points linked by straight lines. |
| Polygon | An area enclosed by multiple points. |
| MultiPoint, MultiLineString, and MultiPolygon | Collections of points, line strings, and polygons, respectively. |
| GeometryCollection | A collection of different geometric types. |
Location Document Collection
Creating An Index
db.locations.createIndex({ location: "2dsphere" });
Geospatial Query
db.locations.find({
location: {
$near: {
$geometry: {
type: "Point",
coordinates: [73.8567, 18.5204]
},
$maxDistance: 500 // Distance in meters
}
}
});
Output
| Posted By - | Karan Gupta |
| |
| Posted On - | Monday, May 20, 2024 |