ArangoDB AQL 深度数组扫描
ArangoDB AQL deep array scan
我收集了客户及其访问过的地点,整理如下:
{
"customer_id": 151,
"first_name": "Nakia",
"last_name": "Boyle",
"visited_places": [
{
"country": "Liberia",
"cities": [
"Mullerside",
"East Graham"
]
},
{
"country": "Rwanda",
"cities": [
"West Kristofer",
"Effertzbury",
"Stokeston",
"South Darionfort",
"Lewisport"
]
}
]
}
我正在尝试查找访问过特定国家/地区特定城市的所有客户。我让它像这样工作:
FOR target IN usertable
FILTER [] != target.visited_places[* FILTER CURRENT.country == @country AND CONTAINS(CURRENT.cities, @city)]
LIMIT @limit
RETURN target
这个查询看起来很麻烦,我不确定它是否有效。
在可读性和性能方面是否有更好的方法来做到这一点?
您可以按国家/地区过滤并在 visited_places[*].country
上为其创建持久数组索引,但您仍然需要次要条件以确保您查找的国家/地区和城市出现在同一数组元素中:
FOR doc IN usertable
FILTER @country IN doc.visited_places[*].country
FILTER LENGTH(doc.visited_places[* FILTER CURRENT.country == @country AND @city IN CURRENT.cities])
RETURN doc
我收集了客户及其访问过的地点,整理如下:
{
"customer_id": 151,
"first_name": "Nakia",
"last_name": "Boyle",
"visited_places": [
{
"country": "Liberia",
"cities": [
"Mullerside",
"East Graham"
]
},
{
"country": "Rwanda",
"cities": [
"West Kristofer",
"Effertzbury",
"Stokeston",
"South Darionfort",
"Lewisport"
]
}
]
}
我正在尝试查找访问过特定国家/地区特定城市的所有客户。我让它像这样工作:
FOR target IN usertable
FILTER [] != target.visited_places[* FILTER CURRENT.country == @country AND CONTAINS(CURRENT.cities, @city)]
LIMIT @limit
RETURN target
这个查询看起来很麻烦,我不确定它是否有效。
在可读性和性能方面是否有更好的方法来做到这一点?
您可以按国家/地区过滤并在 visited_places[*].country
上为其创建持久数组索引,但您仍然需要次要条件以确保您查找的国家/地区和城市出现在同一数组元素中:
FOR doc IN usertable
FILTER @country IN doc.visited_places[*].country
FILTER LENGTH(doc.visited_places[* FILTER CURRENT.country == @country AND @city IN CURRENT.cities])
RETURN doc