1

My vertices have one of two labels 'User' and 'Group', and edges are labeled 'contains'. A 'Group' vertex may point to 'User' vertices or other 'Group' vertices. I use the following query to find 'User' vertices starting from a Group vertex. If a 'Group' vertex points to another 'Group' vertex, it traverses to that sub 'Group' vertex to find 'User' vertices.

g.V().hasLabel('Group').has('AccountName','oem').repeat(out('contains')).until(hasLabel('User'))

Now I need to traverse out to 'Group' vertices that do not point to any other vertices. After reading some other postings I tried the following, but I got "Gremlin Query Compilation Error: Ambiguity between 'P.not' and '__.not'" What's the correct way to express something like that?

g.V().hasLabel('Group').has('AccountName','oem').repeat(out('contains')).until(not(outE())) <<== Error
samsu
  • 63
  • 8

1 Answers1

2

Instead of using not(outE()) you could use outE().count().is(0) as another means to express this query. That would remove the required ambiguity of explicitly using the P class or the anonymous traversal (double underbar, __) with not().

Taylor Riggan
  • 1,963
  • 6
  • 12
  • 3
    I think you would want to prefer the use of the anonymous traversal spawned from `__` with `__.not(outE())` over use of `outE().count().is(0)` as it's more efficient. – stephen mallette Mar 27 '20 at 14:45
  • 2
    Correct. My suggestion was more "if explicitly adding the anonymous traversal doesn't work, here's an alternative". – Taylor Riggan Mar 27 '20 at 17:56