Articles → MONGODB → $Geointersects Operator In Mongodb
$Geointersects Operator In Mongodb
Purpose
Creating The 2Dsphere Index
db.locations.createIndex({ location: "2dsphere" });
Example
const searchArea = {
"type": "Polygon",
"coordinates": [[
[-73.98, 40.75],
[-73.96, 40.75],
[-73.96, 40.78],
[-73.98, 40.78],
[-73.98, 40.75]
]]
};
db.locations.find({
location: {
$geoIntersects: {
$geometry: searchArea
}
}
});