首页 文章

使用gremlin添加边缘(如果不存在)

提问于
浏览
1

我在azure中使用cosmos graph db .

有没有人知道是否有办法在两个顶点之间添加边缘,如果它不存在(使用gremlin图形查询)?

我可以在添加顶点时执行此操作,但不能添加边缘 . 我从here获取了代码:

g.Inject(0).coalesce(__.V().has('id', 'idOne'), addV('User').property('id', 'idOne'))

谢谢!

1 回答

  • 2

    边缘可以做到 . 该模式在概念上与 coalesce() 周围的顶点和中心相同 . 使用"modern" TinkerPop玩具图来演示:

    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() 的第一个参数 .

相关问题