ArangoDB 3.0中朋友查询的朋友 [英] friends of friend Query in ArangoDB 3.0
问题描述
我想使用 AQL
I want to writing 'friends of friend' traversal using AQL
我有一个名称为:用户的收藏集和一个名称为连接的边缘收藏集.
I have a Collection with Name:User and a edge Collection with name Conatct.
我的联系文档:
我还阅读了这篇文章,在ArangoDb中实现朋友的朋友,但这是使用使用GRAPH_NEIGHBORS()函数的ArangoDB较低版本的函数的帖子.
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.
在ArnagoDB 3.0(最新版本)中, GRAPH_NEIGHBORS()函数已被删除!
in ArnagoDB 3.0(latest version), GRAPH_NEIGHBORS() function have been removed!
现在,如何在ArnagoDB 3.0中使用Aql实现fof?
now, how can I implement fof using Aql in ArnagoDB 3.0 ?
非常感谢
推荐答案
原生AQL遍历,它在2.8中引入,并针对3.0版进行了扩展和优化.
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.
要检索朋友的朋友,需要从有问题的用户处开始遍历,遍历深度为2:
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 } )
已加载_key
= @9302796301
的用户文档,并将其分配给变量user
.它用作最小深度和最大深度= 2的遍历的起始顶点,使用集合Contact
的边缘并忽略其方向(ANY
;也可以是INBOUND
或OUTBOUND
).在此示例中,将完全返回friends文档的friends(v
),并使用属性键"foaf"
和变量foaf
的值将其与user
文档合并.
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.
这篇关于ArangoDB 3.0中朋友查询的朋友的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!