Filter array value in ArangoDB

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 am trying to find which clients have addrs where the state is in "OH". My aql request:

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

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

+6
source share
2 answers

You can do it:

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

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

+5
source

first you need to select a document in this collection using the following filter:

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

this will return an addrs object in which state == "OH". if you want a complete document, just replace RETURN d with RETURN doc .

0
source

Source: https://habr.com/ru/post/971172/


All Articles