Skip to content

Instantly share code, notes, and snippets.

@jaimemin
Created July 14, 2025 15:29
Show Gist options
  • Select an option

  • Save jaimemin/c30f4d0fa418cdd24de6ff73bfbe1070 to your computer and use it in GitHub Desktop.

Select an option

Save jaimemin/c30f4d0fa418cdd24de6ff73bfbe1070 to your computer and use it in GitHub Desktop.
// 2dsphere 인덱스 생성
db.places.createIndex({ location: "2dsphere" });
// 근처 장소 쿼리하기
db.places.find({
location: {
$near: {
$geometry: { type: "Point", coordinates: [-73.9667, 40.78]},
$maxDistance: 500
}
}
})
// 지정된 다각형 내의 문서 쿼리하기
db.places.find({
location: {
$geoWithin: {
$geometry: {
type: "Polygon",
coordinates: [
[
[0, 0],
[3, 6],
[6, 1],
[0, 0]
]
]
}
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment