[英]How to add filter condition while getting data from edge collection in arangodb
I'm trying to get data from edge collection based on a condition我正在尝试根据条件从边缘集合中获取数据
In my edge collection, I have data like below在我的边缘集合中,我有如下数据
{
_from: "rooms/1"
_to: "users/1"
type: "admin"
},{
_from: "rooms/1"
_to: "users/2"
type: "member"
},{
_from: "rooms/1"
_to: "users/3"
type: "member"
}
Now I want to get user info of admin only.现在我只想获取管理员的用户信息。 I try with the below query but it is returning null values
我尝试使用以下查询,但它返回空值
FOR r IN rooms
FILTER r._key == 1
let admins = (
FOR u IN ANY r rooms_users
FILTER rooms_users.type == "admin"
RETURN u
)
RETURN MERGE([r, {admin: admins [0]}])
thanks in advance提前致谢
I see three minor issues...我看到三个小问题...
First, the _key
attribute is always a string, so you need to quote the 1
in the first filter.首先,
_key
属性始终是一个字符串,因此您需要在第一个过滤器中引用1
。
Second, in the "admins" subquery, you can't filter on "rooms_users" because that's the name of the edge collection, not the identification of the edge document(s).其次,在“admins”子查询中,您不能过滤“rooms_users”,因为这是边缘集合的名称,而不是边缘文档的标识。 To filter on an attribute of an edge, you need to add a variable to the
FOR
statement to identify the edge ( e
in this case) -docs .要过滤边的属性,您需要在
FOR
语句中添加一个变量来标识边(在本例中为e
) -docs 。
Last, for performance reasons, I changed the graph query from ANY
to INBOUND
and gave it a limit of 1
.最后,出于性能原因,我将图形查询从
ANY
更改为INBOUND
并将其限制为1
。 This means we will only find: (a) admins of THIS room, and won't traverse long directions up and down the graph trying to find any and all documents (it actually wound in a loop for me and timed out).这意味着我们只会找到:(a) 这个房间的管理员,并且不会在图表上下长距离试图找到任何和所有文档(它实际上对我来说是一个循环并超时)。
FOR r IN rooms
FILTER r._key == '1'
LET admins = (
FOR u,e IN 1 INBOUND r rooms_users
FILTER e.type == 'admin'
RETURN u
)
RETURN MERGE([r, { admin: admins[0] }])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.