Sample database: TinkerPop Modern
Objective: Find People who have not developed a Software.
ie. Vertex type "Person" that is not directly connected to Vertex type "Software"
Person connected to Software [Works]
g.V().hasLabel("Person").as("from")
.project("title", "node")
.by(select("from").unfold().values("name").fold())
.by(select("from").unfold().label().fold())
Find Person not connected to Software [Does not work]
g.V().hasLabel("Person").as("from")
.filter(both().not(hasLabel("Software")))
.project("title", "node")
.by(select("from").unfold().values("name").fold())
.by(select("from").unfold().label().fold())
I believe its ignoring an edge that does not satisfy the condition, but does not skip the Vertex.
Tried to do a loop but did not find an example for it.
Cypher Query equivalent (for reference only): MATCH (n:People) WHERE NOT (n)--(:Software) RETURN n
Sample database:
I believe that you just need to change your filter criteria:
gremlin> g.V().hasLabel('person').
......1> filter(__.not(outE('created'))).
......2> project("title", "node").
......3> by('name').
......4> by(label)
==>[title:vadas,node:person]
As you can see, you also don't need to select back to that as()
step for any reason - you already have that vertex as the current traverser in project()
.