I'm currently using TinkerPop java APIs for graph traversal. Currently I had to create a duplicate copy of the same traversal to compute the count.
Long allUsersCount = gt.V().hasLabel("user").has("name", "John").count().next();
List<Vertex> users = gt.V().hasLabel("user").has("name", "John").toList();
When I tried to reuse the traversal returned by gt.V().hasLabel("user").has("name", "John").count()
to get the list, it caused the error
java.lang.IllegalStateException: The traversal strategies are complete and the traversal can no longer be modulated
I just want to know if there is any way to avoid this repetition as the traversal is same for both cases gt.V().hasLabel("user").has("name", "John")
just the terminating operations are different.
Is there any way to store the count in-between(inside a java variable) and continue the traversal to get the list of users.
fold()
like you did above, and combined that withunfold().limit(1)
in the projection....fold().project('city','count').by(unfold().limit(1)).by(count(local))
– Deaconry