This method is really missing in Gremlin.Net right now. While this is not explicitly stated in the documentation, the documentation does list all terminal steps implemented by Gremlin.Net:
- ITraversal.Next()
- ITraversal.NextTraverser()
- ITraversal.ToList()
- ITraversal.ToSet()
- ITraversal.Iterate()
hasNext
is also such a terminal step but as you can see it is missing in this list.
The only workaround I can think of for situations like this is to use the count
step and then check in your application whether the returned count is greater than zero:
var count = g.V("1").Out("knows").HasId("2").Count().Next();
var exists = count > 0;
In some cases it could also make sense to limit the number of vertices going into the Count
step as you aren't interested in the exact count but only want to know whether at least one vertex exists:
g.V("1").Out("knows").HasId("2").Limit<Vertex>(1).Count().Next();
This is also the proposed workaround in the ticket for this feature: TINKERPOP-1921.