gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 13:30:28 25 4
gpt4 key购买 nike

我在蔚蓝中使用波斯菊图数据库。

有谁知道只有在不存在两个顶点之间才可以添加边的方法(使用gremlin图查询)?

我可以在添加顶点时做到这一点,但不能添加边。我从here取得了代码来做到这一点:

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

谢谢!

最佳答案

可以处理边缘。模式在概念上与顶点相同,并以coalesce()为中心。使用“现代” 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()的第一个参数。

关于graph - 使用gremlin添加边缘(如果不存在),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52447308/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com