问题
I want to writing 'friends of friend' traversal using AQL
I have a Collection with Name:User and a edge Collection with name Conatct.
my Conatct documents:
I also read this article that implement friends of friend in ArangoDb, but that's post Uses functions of lower version of ArangoDB that used GRAPH_NEIGHBORS() function.
in ArnagoDB 3.0(latest version), GRAPH_NEIGHBORS() function have been removed!
now, how can I implement fof using Aql in ArnagoDB 3.0 ?
thanks a lot
回答1:
The graph functions have been removed, because there is the more powerful, flexible and performant native AQL traversal, which was introduced with 2.8, and extended and optimized for version 3.0.
To retrieve friends of friends, a traversal starting at the user in question with a traversal depth = 2 is needed:
LET user = DOCUMENT("User/@9302796301")
LET foaf = (
FOR v IN 2..2 ANY user Contact
RETURN v // you might wanna return the name only here
)
RETURN MERGE(user, { foaf } )
The document for the user with _key
= @9302796301
is loaded and assigned to a variable user
. It is used as start vertex for a traversal with min and max depth = 2, using the edges of the collection Contact
and ignoring their direction (ANY
; can also be INBOUND
or OUTBOUND
). The friends of friends documents are fully returned in this example (v
) and merged with the user
document, using the attribute key "foaf"
and the value of the variable foaf
.
This is just one simple example how to traverse graphs and how to construct result sets. There are many more options of course.
来源:https://stackoverflow.com/questions/38614564/friends-of-friend-query-in-arangodb-3-0