简体   繁体   English

ArangoDB:从节点数组中获取所有链接

[英]ArangoDB: Get all links out of an array of nodes

Following after this question and an excellent answer from CoDEManX , I would like to ask how to use previous result (An array of returned nodes) to query out all of the links in that collection. 在回答了这个问题和CoDEManX的一个很好的回答之后,我想问一下如何使用以前的结果(返回节点的数组)来查询该集合中的所有链接。

Basically I intended to use the result of 基本上我打算使用的结果

FOR v IN 0..100 ANY "Entity/node_id" 
EntityRelation OPTIONS      
{uniqueVertices: "global"}
RETURN v._key

for query links: 用于查询链接:

"FOR c IN EntityRelation FILTER c._from==" + "\"" + 
node._id + "\"" + " OR c._to==" + "\"" + 
node._id + "\"" + " RETURN c";

How should I approach it? 我应该如何处理?

I'm not sure what you want to achieve exactly, but here are two possible solutions: 我不确定您要确切实现什么,但是这里有两种可能的解决方案:

FOR v IN 0..100 ANY "Entity/node_id" EntityRelation OPTIONS {uniqueVertices: "global"}
  FOR vv, c IN ANY v EntityRelation
    RETURN c

Above query uses a nested for-loop (actually traversal) to perform a traversal for each node returned by the outer traversal, using v as start vertex and ignoring the direction of the edges. 上面的查询使用嵌套的for循环(实际遍历)对外部遍历返回的每个节点执行遍历,使用v作为起始顶点并忽略边的方向。 The entire edge documents of the inner traversal are returned. 返回内部遍历的整个边缘文档。

If you want the edges of the outer traversal, this isn't even necessary: 如果您想要外部遍历的边缘,则甚至没有必要:

FOR v, e IN 0..100 ANY "Entity/node_id" EntityRelation OPTIONS {uniqueVertices: "global"}
  RETURN e

If you want to access the traversal results later in your query, turn it into a subquery and assign the result to a variable: 如果要稍后在查询中访问遍历结果,请将其转换为子查询并将结果分配给变量:

LET nodes = (
  FOR v IN 0..100 ANY "Entity/node_id" EntityRelation OPTIONS {uniqueVertices: "global"}
    RETURN v._id
)
FOR node IN nodes
  FOR vv, c IN ANY node EntityRelation
    RETURN c

Note that the first traversal returns only document IDs. 请注意,第一次遍历仅返回文档ID。 They are sufficient to start another traversal from these nodes, and no other properties of the vertices are used in this query anyway. 它们足以从这些节点开始另一个遍历,并且在此查询中无论如何都不会使用这些顶点的其他属性。 Returning the whole documents would work as well, but is not as efficient. 返回整个文档也可以,但是效率不高。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM