Articles → MONGODB → $Geowithin Operator In Mongodb
$Geowithin Operator In Mongodb
Purpose
Creating The 2Dsphere Index
db.locations.createIndex({ location: "2dsphere" });
Example
db.locations.find({
location: {
$geoWithin: {
$geometry: {
type: "Polygon",
coordinates: [[
[73.865, 18.522], // Bottom-left corner
[73.865, 18.530], // Top-left corner
[73.872, 18.530], // Top-right corner
[73.872, 18.522], // Bottom-right corner
[73.865, 18.522] // Closing the polygon
]]
}
}
}
})