Michael Scott
Michael Scott

Reputation: 580

Gremlin query cosmosDB to find a connection

I have a graph modeled this way. A --calls('for', 'Item1')--> B --calls('for', 'Item1')--> C --calls('for', 'Item1')--> D. A calls B for Item1(property of the edge). B calls C and C calls D. There can be other chains as well in the graph that would have some vertex call D for Item1. How can i determine all such chains? All the ways in which D can be called for Item1.

Apologies if the question is too basic. My knowledge on graph is very minimal and I am using cosmosDB to model this.

Upvotes: 0

Views: 70

Answers (1)

stephen mallette
stephen mallette

Reputation: 46206

I suppose I would start at "D" and follow "Item1" paths from there using repeat(). Assuming "D" is the actual T.id (element identifier):

g.V("D").repeat(inE('calls').has('for','Item1').outV()).emit().path()

The above is the beginnings of such a query. You might need a terminating condition to that repeat() loop and methods to avoid cycles (i.e. simplePath()) if your graph contains such things so that you avoid infinite traversals along such paths.

Upvotes: 1

Related Questions