MongoDB For Geospatial Data
Posted By : Arun Kataria | 30-Jan-2018
MongoDB can support the query operations on a geospatial data. Here is some feature of MongoDB’s geospatial:
Geospatial Data: MongoDB store geospatial data in a GeoJson object.
the format of GeoJson object is:
{
type: <GeoJSON type>,
coordinates: <coordinates>
}
Here GeoJson type can be Point, LineString, Polygon, MultiPoint, MultiLineString, and MultiPolygon. And coordinates are in the array.
In case of Point as a GeoJson type then the coordinates would be latitude and longitude coordinates, Here longitude first and then latitude. Valid longitude values are between -180 to 180, both inclusive. And Valid latitude values are between -90 to 90, both inclusive.
Example:
location: {
type: "Point",
coordinates: [-73.322037, 50.548557]
}
Now if you want to get the data by
example:
db.user.find(
{
location:
{ $near :
{
$geometry: { type: "Point", coordinates: [ -72.2627, 42.28 ] },
$minDistance: 2000,
$maxDistance: 6000
}
}
}
);
here $minDistance and $maxDistance distance are in meters.
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Arun Kataria
Arun has good skills in AngularJS, NodeJS, MongoDB and many more. He is highly motivated which allow him to strive for proficiency when accomplishing assigned duties. He is an excellent team operative.