有没有一种有效的方法来查看在 gremlin Upsert 中创建了多少边和顶点?

问题描述

使用如下查询

g.V().has('person','name','marko').
           fold().
           coalesce(unfold(),addV('person').property('name','marko')).
           property('age',29)

是否有一种有效的方法也可以返回创建了多少个顶点?

标记顶点存在时为0,标记顶点不存在时为1。

解决方法

我想我会选择union()

gremlin> g.V().has('person','name','marko').
......1>   fold().
......2>   union(coalesce(unfold(),......3>                  addV('person').property('name','marko')).
......4>         property('age',29),......5>         count(local))
==>v[1]
==>1
gremlin> g.V().has('person','darko').
......1>   fold().
......2>   union(coalesce(unfold(),......5>         count(local))
==>v[13]
==>0

这与您在 1 和 0 存在方面所要求的相反,但我认为如果您确实需要,这很容易补救,但它会为围绕 count(local) 的遍历增加额外的复杂性现在很容易阅读。