Reputation: 1092
I want to do a simple query in which I have a user and a group. Users have an edge "memberOf" to group vertex. Given a userId and a groupId, I want to write a query that returns true or false if there is an edge between the user and the group.
Upvotes: 2
Views: 471
Reputation: 14371
Just adding a second answer to mention that you can also use the hasNext
step for this. It will return true or false depending on whether the target exists.
g.V().hasId('userid').
out().hasId('group1').
hasNext()
Upvotes: 3
Reputation: 877
You can use coalesce
to do such operation.
g.V().hasId('userid').coalesce(out().hasId('group1').constant(true), constant(false))
Upvotes: 2