问题描述
我正在使用天蓝色的宇宙图数据库.
I'm using cosmos graph db in azure.
有谁知道是否有办法在两个顶点之间添加一条边,如果它不存在(使用 gremlin 图查询)?
Does anyone know if there is a way to add an edge between two vertex only if it doesn't exist (using gremlin graph query)?
我可以在添加顶点时这样做,但不能添加边.我从 这里:
I can do that when adding a vertex, but not with edges. I took the code to do so from here:
g.Inject(0).coalesce(__.V().has('id', 'idOne'), addV('User').property('id', 'idOne'))
谢谢!
推荐答案
可以使用边.该模式在概念上与顶点相同,并且以 coalesce()
为中心.使用现代"TinkerPop 玩具图来演示:
It is possible to do with edges. The pattern is conceptually the same as vertices and centers around coalesce()
. Using the "modern" TinkerPop toy graph to demonstrate:
gremlin> g.V().has('person','name','vadas').as('v').
V().has('software','name','ripple').
coalesce(__.inE('created').where(outV().as('v')),
addE('created').from('v').property('weight',0.5))
==>e[13][2-created->5]
这里我们在vadas"和ripple"之间添加一条边,但前提是它不存在.这里的关键是检查 coalesce()
的第一个参数.
Here we add an edge between "vadas" and "ripple" but only if it doesn't exist already. the key here is the check in the first argument to coalesce()
.
这篇关于如果不存在则使用 gremlin 添加边的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!