[英]ArangoDB finding connected vertices
I'm very new with arangodb and like it very much but I'm struggling to create query statement.我对 arangodb 很陌生并且非常喜欢它,但我正在努力创建查询语句。 I have two collections (VA, VB) and edge between them (EC) I want find search Va with specific filter (not by _id) and then RETURN documents (VB) connected (via EC) where EC has specific property (ex. active: true)
我有两个集合(VA,VB)和它们之间的边缘(EC)我想找到具有特定过滤器(不是通过 _id)的搜索 Va,然后返回文档(VB)连接(通过 EC)其中 EC 具有特定属性(例如活动: 真的)
In documentation I found only examples when vertex is already known.在文档中,我只找到了顶点已知的例子。 Thank you in advance, Jnl
提前谢谢你,Jnl
Yes, making a graph makes it a bit easier, but you can still query it without using a graph.是的,制作图表会使它更容易一些,但您仍然可以在不使用图表的情况下查询它。
This is an example that will work just using the three collections directly:这是一个直接使用三个集合的示例:
FOR va IN VA
FILTER va.name == 'Bob'
FOR e IN EC
FILTER e._from == va._id && e.active == true
FOR vb IN VB
FILTER e._to == vb._id
RETURN vb
If you want to use a graph, looks like you might have been testing one, then this will work:如果您想使用图表,看起来您可能已经在测试一个图表,那么这将起作用:
LET myOrigin = FIRST(FOR d IN VA FILTER d.name == 'Bob' RETURN d._id)
FOR v, e, p IN 1..1 OUTBOUND myOrigin GRAPH 'GD'
FILTER p.edges[0].active == true
RETURN p.vertices[1]
The thing to note is that myOrigin
needs to be an _id, which means when setting the value you use FIRST(...)
when assigning the value.需要注意的是,
myOrigin
需要是一个 _id,这意味着在设置值时您在分配值时使用FIRST(...)
。 This ensures you get a single value back (the first one) and not an array.这确保您返回单个值(第一个)而不是数组。
Your example also works:您的示例也适用:
FOR m IN VA FILTER m.name == 'Bob'
FOR v, e, p IN 1..1 ANY m GRAPH 'GD'
FILTER p.edges[0].active == true
RETURN v
The thing to note is that this example could match more than one document (as more than one document could have .name == 'Bob'
and it will return all nodes in VB
that match.需要注意的是,此示例可以匹配多个文档(因为多个文档可以具有
.name == 'Bob'
并且它将返回VB
中匹配的所有节点。
If you wanted the results to show which entry in VA was connected with VB, and had the option of having multiple VA values that match, this will help you:如果您希望结果显示 VA 中的哪个条目与 VB 相关联,并且可以选择具有多个匹配的 VA 值,这将对您有所帮助:
FOR m IN VA FILTER m.name == 'Bob'
FOR v, e, p IN 1..1 ANY m GRAPH 'GD'
FILTER p.edges[0].active == true
RETURN {
origin: m,
connected_to: v
}
If you want to clean up the results, you can use UNSET to make the results better:如果要清理结果,可以使用 UNSET 使结果更好:
FOR m IN VA FILTER m.name == 'Bob'
FOR v, e, p IN 1..1 ANY m GRAPH 'GD'
FILTER p.edges[0].active == true
RETURN {
origin: UNSET(m, '_key', '_rev'),
connected_to: UNSET(v, '_key', '_rev')
}
It just removes those keys from the results sent to you in the query.它只是从查询中发送给您的结果中删除这些键。
There are so many ways to retrieve data, just looking at different examples can really help get a feel for AQL.检索数据的方法有很多种,仅查看不同的示例就可以真正帮助您了解 AQL。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.