我有这样的文件:
{ "baths": 2, "beds": 3, "id": "3225C", "addrs": [
{
"line2": "",
"line3": "",
"state": "OH",
"zip": "67845",
"line1": "3225 ABC AVE",
"city": "CLEVELAND"
},
{
"line2": "",
"line3": "",
"state": "FL",
"zip": "32818",
"line1": "2438 DEF AVE",
"city": "ORLANDO"
} ], "homeAddress": {
"line2": "",
"line3": "",
"state": "FL",
"zip": "32818",
"line1": "1234 CHICOTA AVE",
"city": "ORLANDO" }, "rentingAddresses": {
"ownsObjects": true,
"count": 0,
"arrayManager": {},
"items": [] }, "mailAddress": [
"4561 RAYCO AVE",
"",
"",
"ORLANDO",
"FL",
"32818" ] }
我试图找到哪个客户有一个addrs
,其中州是" OH"。我的aql查询是:
for client in clients.addrs
filter client.state == "OH"
return client
但我一直在[1563] list expected
。有没有其他方法可以使用数组?
答案 0 :(得分:6)
你可以这样做:
FOR client IN clients
FILTER 'OH' IN client.addrs[*].state
RETURN client
这应该返回所有至少有一个元素的客户端 " addrs的"属性为" state" ==" OH"
答案 1 :(得分:0)
首先,您必须使用以下过滤器选择该集合中的文档:
FOR doc IN clients
FILTER doc.id == "3225C"
FOR d IN doc.addrs
FILTER d.state == "OH"
RETURN d
这将返回状态==“OH”的addrs
对象。如果您想获得完整的文档,只需将RETURN d
替换为RETURN doc
。