8

我有这样的文件:

{   "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。还有其他方法可以处理数组吗?

4

2 回答 2

10

你可以这样做:

FOR client IN clients
   FILTER 'OH' IN client.addrs[*].state
   RETURN client

这应该返回所有在“addrs”属性中具有至少一个元素且“state”==“OH”的客户端

于 2014-06-22T13:21:36.847 回答
1

首先,您必须使用这样的过滤器在该集合中选择一个文档:

FOR doc IN clients
 FILTER doc.id == "3225C"
   FOR d IN doc.addrs
    FILTER d.state == "OH"
   RETURN d

这将返回addrsstate == "OH" 的对象。如果您想获得完整的文档,只需替换RETURN dRETURN doc.

于 2017-01-04T07:54:41.843 回答