Gremlin-选择一个顶点,在单个查询中创建新的顶点和边 [英] Gremlin - select a vertex, create new vertices and edges in single query
问题描述
我已经创建了一个用户顶点.
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?
推荐答案
您可以将步骤简单地链接在一起:
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')
请注意,我喜欢使用该表单,因此在property
步骤中设置了属性,但是您也可以在addV
步骤中直接添加它们.
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.
这篇关于Gremlin-选择一个顶点,在单个查询中创建新的顶点和边的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!