Articles → MONGODB → $Geointersects Operator In Mongodb

$Geointersects Operator In Mongodb






Purpose





Creating The 2Dsphere Index




db.locations.createIndex({ location: "2dsphere" });



Example




Picture showing the sample db collection




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
    }
  }
});


Picture showing the output of $geointersects operator in mongodb



Posted By  -  Karan Gupta
 
Posted On  -  Wednesday, May 29, 2024

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250