Gremlin - 一次遍历中的顶点和边 Upsert

Gremlin - Vertex and Edge Upsert in 1 traversal

我有一个 Vertex upsert 和一个 Edge upsert 在 2 个单独的遍历中工作。是否可以将 2 合并为 1 遍历?我已尝试但收到错误消息。

a = self.g.V().has('account', 'id', 'account-111111111').fold().coalesce(.unfold( ),.addV('account').属性(T.id, 'account-111111111')).has('customer', 'id' , 'cust-111111111').as_('v').V().has('account', 'id', 'account-111111111').coalesce(. inE('owns').where(.outV().as_('v')),.addE('owns').from_(.V('customer', 'id', 'cust-111111111')))

a.next()

作品:

顶点更新插入:

a = g.V().has('account', 'id', 'account-111111111').fold().coalesce(.unfold( ),.addV('account').属性(T.id, 'account-111111111')) a.next()

边更新插入:

a = g.V().has('customer', 'id', 'cust-111111111').as_('v').V().has ('account', 'id', 'account-111111111)。 \ 合并(.inE('owns').where(.outV().as_('v')),.addE('owns').from_(.V('customer', 'id', 'cust-111111111])))

a.next()

研究了一段时间,你的例子中有不少地方是行不通的。

首先,如果您知道顶点或边的 ID,则实际上没有必要检查标签或任何其他 属性。

其次T.id是一个ID。值 'id' 将是一个名为 'id' 的 属性。

根据你的问题,很难拼凑出你想要做什么,但这是我认为你想要做的第一次尝试。如果这实际上不是您想要的,请编辑问题以使其更清楚。无论如何,我希望这对您有所帮助

g.V('account-111111111').
  fold().
  coalesce(__.unfold(),
           __.addV('account').property(T.id, 'account-111111111')).
  coalesce(__.in('owns').hasId('cust-111111111')),
           __.addE('owns').from_(__.V('cust-111111111'))