Michail Michailidis
Michail Michailidis

Reputation: 12181

How to drop outgoing edges except those with specific inVertices using Gremlin 3?

I would like to drop outgoing edges from vertex entity if their inVertices are not contained in the list of donttouch ones.

I have a traversal like that:

g.V(id).as("entity")
 .V(id2).as("donttouch1")
 .V(id3).as("donttouch2")
 .outE("hasType").drop();

The above query has three issues:

So I need something like that:

String[] donttouch= {"donttouch1","donttouch1"};

g.V(id).as("entity")
 .V(id2).as("donttouch1")
 .V(id3).as("donttouch2")
 .back("entity").outE("hasType")
 .where(not(inV().hasId(P.within(donttouch)))).drop().select("entity").next()

The list of donttouchs might be long so I would prefer to put them all at once and not as a conjunction of neqs

Thank you!

Upvotes: 1

Views: 610

Answers (1)

Daniel Kuppitz
Daniel Kuppitz

Reputation: 10904

I assume the list of untouchable ids is already present in a list / set. In that case you can do:

g.withSideEffect("x", untouchableIds).
  V(id).outE("hasType").not(inV().id().where(within("x"))).drop()

Upvotes: 2

Related Questions