0

I have a user vertex already created.

g.V().has('user','username','vipul').as('user')

I want to create a new 'group' vertex with some properties and also a new 'options' vertex with some other properties.

g.addV(label,'group','group_name','DC11').as('group')
g.addV(label,'options','command_line_arguments','-D -n').as('options')

Now I want to create an edge from user to group and another edge from group to options.

user ---> group,   group ---> options

Can these queries be combined, selecting a vertex, creating new vertices and then creating new edges?

Vipul Sharma
  • 768
  • 3
  • 11
  • 25

1 Answers1

2

You can simply chain the steps together:

g.V().has('user','username','vipul').as('user').
  addV('group').property('group_name','DC11').as('group').
  addE('memberOfGroup').from('user').
  addV('options').property('command_line_arguments','-D -n').
  addE('hasOptions').from('group')

Note that I set the properties with the property step as I prefer that form, but you can also add them directly with the addV step.

Florian Hockmann
  • 2,634
  • 13
  • 24
  • thanks for the answer. I have a janusgraph setup and the gremlin version with which it came is 3.2.3 and this query is not working in it. This kind of addV and addE came with 3.3.0 for bulk loading. Any other alternative which you can suggest? that would be great – Vipul Sharma Sep 14 '17 at 09:34
  • 1
    You should keep the TinkerPop version aligned with the JanusGraph version. The syntax that Florian provided works on JanusGraph 0.1.1/TinkerPop 3.2.3 https://gist.github.com/pluradj/48a29692c07f700dc1350fcbb2b521f5 – Jason Plurad Sep 14 '17 at 13:38
  • See JanusGraph version compatibility matrix http://docs.janusgraph.org/latest/version-compat.html – Jason Plurad Sep 14 '17 at 13:39
  • yes it works. did some mistake while editing the query variables. Thanks a lot @JasonPlurad and Florian. Highly appreciated :) – Vipul Sharma Sep 15 '17 at 13:12