mmr25
mmr25

Reputation: 93

How to get all incoming direct and indirect nodes with edges of a given node

I have a graph like below

a->b
b->c
d->c
a->c
e->d
c->e
e->a
f->g
g->a
c->h

If i select c, it should return all incoming direct and indirect nodes with edges along the path.

It should return a,b,d,e,f,g

I tried below and its not working

g.V(nodeId) 
  .repeat(__.inE().aggregate('edges').inV().aggregate('nodes').simplePath())
  .emit()
  .dedup()
  .cap('edges', 'nodes') 
  .project('edges', 'nodes')
  .by(select('edges').unfold().dedup().id().fold()) 
  .by(select('nodes').unfold().dedup().id().fold()) 
  .next()

it is returning all the direct edges, and only one direct node, im not able to find the issue.

Upvotes: 0

Views: 42

Answers (1)

Taylor Riggan
Taylor Riggan

Reputation: 2769

inE() followed by an inV() would dictate starting from a node, going to the edge, and then going back to the node where you started.

If you're looking to traverse an edge, you need to follow inE().outV() or outE().inV() or bothE().otherV() as the patterns to traverse from one node to the neighboring node.

Upvotes: 1

Related Questions