그래서 두 개의 콜렉션이 있습니다. 하나는 속성으로 우편 번호 배열이 있고 다른 하나는 우편 번호와 위도가 & 경도입니다.AQL의 별개의 정렬 된 쿼리
좌표에 가장 가까운 도시를 반환하고 싶습니다. 이것은 지리적 색인으로는 쉽지만, 내가 가지고있는 문제는 동일한 도시가 여러 번 반환되는 것과 몇 번에 걸쳐 다른 도시와 접하는 우편 번호이기 때문에 가장 가까운 도시 일 수 있습니다.
도시 예제 데이터 :
[
{
"_key": "30936019",
"_id": "cities/30936019",
"_rev": "30936019",
"countryCode": "US",
"label": "Colorado Springs, CO",
"name": "Colorado Springs",
"postalCodes": [
"80904",
"80927"
],
"region": "CO"
},
{
"_key": "30983621",
"_id": "cities/30983621",
"_rev": "30983621",
"countryCode": "US",
"label": "Manitou Springs, CO",
"name": "Manitou Springs",
"postalCodes": [
"80829"
],
"region": "CO"
}
]
postalCodes 예 데이터 :
가[
{
"_key": "32132856",
"_id": "postalCodes/32132856",
"_rev": "32132856",
"countryCode": "US",
"location": [
38.9286,
-104.6583
],
"postalCode": "80927"
},
{
"_key": "32147422",
"_id": "postalCodes/32147422",
"_rev": "32147422",
"countryCode": "US",
"location": [
38.8533,
-104.8595
],
"postalCode": "80904"
},
{
"_key": "32172144",
"_id": "postalCodes/32172144",
"_rev": "32172144",
"countryCode": "US",
"location": [
38.855,
-104.9058
],
"postalCode": "80829"
}
]
다음 쿼리는이 작업을 수행하는보다 효율적인 방법이 있는지 궁금 해요 ArangoDB 초보자으로 만 작동합니다
FOR p IN WITHIN(postalCodes, 38.8609, -104.8734, 30000, 'distance')
FOR c IN cities
FILTER p.postalCode IN c.postalCodes AND c.countryCode == p.countryCode
COLLECT close = c._id AGGREGATE distance = MIN(p.distance)
FOR c2 IN cities
FILTER c2._id == close
SORT distance
RETURN c2