zjffdu
zjffdu

Reputation: 28794

How to get all vertices which has at least one neighbour in gremlin?

I tried to use filter to get all vertices which has at least one neighbour in gremlin, but get error, did I mis-use filter function? Thanks

g.V().hasLabel("Customer", "Loan", "Account", "CreditCard").filter(both().hasNext())

Upvotes: 0

Views: 23

Answers (1)

Taylor Riggan
Taylor Riggan

Reputation: 2759

hasNext() is a terminal step. It is only meant to be used at the end of a query, not within the query: https://tinkerpop.apache.org/docs/current/reference/#terminal-steps

You can achieve what you're looking for by doing something like:

g.V().hasLabel("Customer", "Loan", "Account","CreditCard").
    where(bothE().count().is(gt(0)))

If issuing this using one of the Gremlin clients, you'll need to end this with next(), toList() or some other Terminal step to send the query to your database and fetch a result.

If you're looking for a good resource to use in learning Gremlin, I highly suggest looking at: https://www.kelvinlawrence.net/book/PracticalGremlin.html

Upvotes: 0

Related Questions