Gopi Gopi - 1 year ago 110
Scala Question

How to get all vertices of all outgoing edges from a vertex scala gremlin

I need to get all list of vertices label of all outgoing egdes from a vertex using scala gremlin.

My code looks like below,

val names :ListBuffer[String] = ListBuffer()
val toList: List[Vertex] = graph.V().hasLabel(100).outE().outV().toList()
for(vertex <- toList){
names += vertex.label()

Its returning the same label name for all vertex
Eg :
Vertex A is having outE to B,C,D . It returns the label of A.

ListBuffer(100, 100, 100)

Anything am i missing?

Answer Source

I believe you asking for the wrong vertex in the end. Honestly, I often make the same mistake. Maybe this is the traversal you looking for:


If you like me and often get confused by inV() and outV() you can use otherV which gets the opposite vertex. Like so:


Finally you can even shorten your traversal by not explicitly stating the edge part:


By using out() instead of outE() you don't need to specify you want the vertex, out() gets you the vertex directly.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download