Gremlin - select a vertex, create new vertices and edges in single query

陌路散爱 提交于 2019-12-13 02:48:23

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!