8

I have a document like this:

{   "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"   ] }

I'm trying to find which clients have an addrs where the state is in "OH". My aql query is:

for client in clients.addrs
filter client.state == "OH"
return client

But I keep getting [1563] list expected. Is there some other way to work with arrays?

erakitin
  • 10,743
  • 5
  • 40
  • 46
Lerato
  • 271
  • 3
  • 5

2 Answers2

10

you can do this:

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

this should return all clients which have at least one element in the "addrs" attribute with "state" == "OH"

fceller
  • 2,666
  • 11
  • 18
1

first you have to select a doc in that collection by using filter like this:

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

this will return the addrs object in which state == "OH". if you want to get complete doc, just replace RETURN d with RETURN doc .

  • 4
    I request you to please add some more context around your answer. Code-only or link-only answers are difficult to understand. It will help the asker and future readers both if you can add more information in your post. – RBT Jan 04 '17 at 08:14
  • Thank you! for your suggestion. – Vinit Singh Jan 04 '17 at 12:13