1
votes

Im trying to self join,merge parent field and get results as separate documents data:

[
{_key="1",name":"a",mf:"xyz"},
{_key="2","name":"b", "parent":"1"},
{_key="3","name":"c", "parent":"1"},
{_key="4",name":"d",mf:"xyzw"},
{_key="5","name":"e", "parent":"4"},
]

query:

for i in data
let o=i.parent>0 ? (for d in data filter i._key==d.parent return merge(d,{mf:i.mf}) : i
return o

expected result:

[
{_key="1",name":"a",mf:"xyz"},
{_key="2","name":"b", "parent":"1",mf:"xyz"},
{_key="3","name":"c", "parent":"1",mf:"xyz"},
{_key="4",name":"d",mf:"xyzw"},
{_key="5","name":"e", "parent":"4",mf:"xyzw"},
}

is this possible to do in arangodb ?

1

1 Answers

0
votes

here you can find examples on how to join collections (and self joins further down the page).

In your particular case the query could look something like this:

for i in data
return i.parent == null ? i : MERGE(i, {
    mf: (for j in data filter j._key == i.parent return j.mf)[0]
})