0

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.

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?

Community
  • 1
  • 1
Loredra L
  • 1,485
  • 2
  • 16
  • 32

1 Answers1

2

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. 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. 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.

CodeManX
  • 11,159
  • 5
  • 49
  • 70
  • Sorry, the way I phase the question is so bad. I just want to get all links from any depth given a node. So the links result if you choose node A,B,C,D is the same if they are connected. But from your answer, I have made a working one using nested to get the nodes then only query out the Inbound links from those nodes. – Loredra L Aug 08 '16 at 12:50
  • I see, so you find all nodes connected to a certain node, then return all nodes that point to these nodes. The nesting approach is the best solution in this case I guess. – CodeManX Aug 08 '16 at 13:52