user3713080
user3713080

Reputation: 439

Referencing property in Gremlin query

I'm trying to do a query that looks somewhat like this:

g.V('myId').as('me').out('member').hasLabel('myLabel').in('member').has('identifier', 'me.identifier')

Where me.identifier would be changed to something that actually works. I just have no clue how to reference the property value of "identifier"

Upvotes: 1

Views: 115

Answers (1)

stephen mallette
stephen mallette

Reputation: 46206

Let's first consider what your query:

g.V('myId').as('me').
  out('member').hasLabel('myLabel').
  in('member').has('identifier', 'me.identifier')

says in English: "find a vertex with the id of 'myId', then traverse outgoing 'member' edges to vertices that have the label of 'myLabel', then traverse incoming 'member' edges to vertices that have a property value of 'me.identifier' for the 'identifier' property"

Now, maybe that's not exactly what you want. For some reason, I gather that you want to: "find a vertex with the id of 'myId', then traverse outgoing 'member' edges to vertices that have the label of 'myLabel', then traverse incoming 'member' edges to vertices that have an id of 'myId'" in which case it's:

g.V('myId').
  out('member').hasLabel('myLabel').
  in('member').hasId('myId')

But then I also gather than you might want to: "find a vertex with the id of 'myId', then traverse outgoing 'member' edges to vertices that have the label of 'myLabel', then traverse incoming 'member' edges to vertices that have an identifier property with the same value of as the 'identifier' property of the start vertex with 'myId'" in which case it's:

g.V('myId').as('me').
  out('member').hasLabel('myLabel').
  in('member').as('them').
  where('them', eq('me')).
    by('identifier')

Upvotes: 2

Related Questions