我尝试添加(如果它们不存在)2个顶点并在单个查询中添加从第一个到另一个的边。它看起来像:
g.V().has("label1", "property1", "value1").fold().coalesce(
__.unfold(),
g.addV("label1").property("property1", "value1")
).as_("a").V().has("label2", "property2", "value2").fold().coalesce(
__.unfold(),
g.addV("label2").property("property2", value2)
).coalesce(
__.inE("link").where(__.outV().as_("a")),
__.addE("link").from_("a")
).next()
但是作为fold()
障碍物,它删除了我放在第一个顶点上的标签“a”。我的解决方法如下:
g.V().has("label1", "property1", "value1").fold().coalesce(
__.unfold(),
g.addV("label1").property("property1", "value1")
).as_("a").V().has("label2", "property2", "value2").fold().coalesce(
__.unfold(),
g.addV("label2").property("property2", value2)
).coalesce(
__.inE("link").where(__.outV().has("label1", "property1", value1)),
__.addE("link").from_(__.V().has("label1", "property1", value1))
).next()
我能做得更好吗?这……丑?
好的,store
解决方案有效 :) 但我对最后一个合并的第一部分有疑问。我这样做了:
g.V().has("label1", "property1", "value1").fold().coalesce(
__.unfold(),
g.addV("label1").property("property1", "value1")
).as_("a").V().has("label2", "property2", "value2").fold().coalesce(
__.unfold(),
g.addV("label2").property("property2", value2)
).coalesce(
__.inE("link").where(__.outV().where(within("a"))),
__.addE("link").from_(select("a").unfold())
).next()
它工作正常,感谢 Kelvin Lawrence :)