Articles → MONGODB → $Geowithin Operator In Mongodb

$Geowithin Operator In Mongodb






Purpose





Creating The 2Dsphere Index




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



Example




Picture showing the sample mongodb collection




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


Picture showing the output of $geowithin operator in mongodb



Posted By  -  Karan Gupta
 
Posted On  -  Saturday, May 25, 2024

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250