问题
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?
回答1:
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.
See it in action in GremlinBin.
来源:https://stackoverflow.com/questions/46207803/gremlin-select-a-vertex-create-new-vertices-and-edges-in-single-query