10

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?

2 Answers 2

14

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"

Sign up to request clarification or add additional context in comments.

Comments

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 .

2 Comments

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.
Thank you! for your suggestion.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.