最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

tinkerpop - How to get all vertices which has at least one neighbour in gremlin? - Stack Overflow

matteradmin7PV0评论

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())

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())
Share Improve this question asked Nov 18, 2024 at 14:01 zjffduzjffdu 29.2k51 gold badges121 silver badges171 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

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./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/book/PracticalGremlin.html

Post a comment

comment list (0)

  1. No comments so far