小编tha*_*c94的帖子

如果 1 个 Gremlin 查询中不存在顶点和边,则创建

如果边缘尚不存在,我找到以下代码来创建边缘。

g.V().hasLabel("V1")
.has("userId", userId).as("a")
.V().hasLabel("V1").has("userId", userId2)
.coalesce(
        bothE("link").where(outV().as("a")),
        addE("link").from("a")
)
Run Code Online (Sandbox Code Playgroud)

它工作正常,但我想创建顶点和边(如果它们不存在于 1 个查询中)。

我用新图尝试以下代码,它只是创建新顶点,但它们之间没有关系。

g.V().hasLabel("V1")
.has("userId", userId).fold()
.coalesce(
        unfold(),
        addV("V1").property("userId", userId1)
).as("a")
.V().hasLabel("V1").has("userId", userId2).fold()
.coalesce(
        unfold(),
        addV("V1").property("userId", userId2)
)
.coalesce(
        bothE("link").where(outV().as("a")),
        addE("link").from("a")
)
Run Code Online (Sandbox Code Playgroud)

graph gremlin janusgraph

2
推荐指数
1
解决办法
1860
查看次数

标签 统计

graph ×1

gremlin ×1

janusgraph ×1