Search code examples
gremlintinkerpop3gremlin-server

List of vertices that can be reached by a specified list of vertices


Here's how my graph looks like.

g = TinkerGraph.open().traversal()
school1 = g.addV('school').property('id', '1').next()
school2 = g.addV('school').property('id', '2').next()
student1 = g.addV('student').property('id', '3').next() 
student2 = g.addV('student').property('id', '4').next()     
g.addE('students').from(school1).to(student1)
g.addE('students').from(school1).to(student2)
g.addE('students').from(school2).to(student1)

I want to find the out the students who are common to both the schools. To extend the logic, what'll happen if I want to write a generic infinite traversal logic for the same.


Solution

  • gremlin> g.V(school1).out('students').filter(__.in('students').is(school2)).valueMap(true)
    ==>[id:4,label:student,id:[3]]
    

    Not sure what you mean by "write a generic infinite traversal logic for the same" though.