Gremlin.Net return 同一个数组中的多个子顶点
Gremlin.Net return multi sub vertex in the same array
通常一个家庭有一个父亲和一个母亲,但有多个children,
在 gremlin 中我可以说得到一个家庭:
g.V(61464).as('me').outE('father').inV().as('father').select('me').outE('mother').inV().as('mother').select('me').inE('father').outV().as('child').select('father', 'mother', 'child')
这将 return 以下内容:
- ==> *{father=v[16408], mother=v[450608], child=v[139504]}*
- ==> *{father=v[16408], mother=v[450608], child=v[163880]}*
- ==> *{father=v[16408], mother=v[450608], child=v[176368]}*
但我想通过这种方式获取它们:
==> {father=v[16408], mother=v[450608], children=[v[139504], v[163880], v[176368]]
有没有办法在 gremlin 中做到这一点,在 Gremlin.Net 中更具体。谢谢
最简单的方法可能是 project
步骤:
gremlin> g.V(61464).project('father','mother','children').
by(out('father')).
by(out('mother')).
by(__.in('father').fold())
==>[father:v[4344],mother:v[4152],children:[v[8440],v[12536],v[40964200]]]
(ID 与您的不匹配,因为我必须自己创建图表并获得其他 ID。)
请注意,__.in('father')
的 __
只有 Gremlin-Groovy 是必需的,因为 in
是 Groovy 中的保留关键字,并且
out('father')
是 outE('father').inV()
.
的缩写形式
你可以在Gremlin.Net中编写相同的遍历。然后它看起来像这样:
g.V(61464).Project<object>("father", "mother", "children").
By(Out("father")).
By(Out("mother")).
By(In("father").Fold()).Next();
(您需要 using static Gremlin.Net.Process.Traversal.__;
才能像这样编写遍历。否则 By
-步骤将如下所示:By(__.Out("father"))
。请参阅 TinkerPop 文档了解 more information on this.)
通常一个家庭有一个父亲和一个母亲,但有多个children, 在 gremlin 中我可以说得到一个家庭:
g.V(61464).as('me').outE('father').inV().as('father').select('me').outE('mother').inV().as('mother').select('me').inE('father').outV().as('child').select('father', 'mother', 'child')
这将 return 以下内容:
- ==> *{father=v[16408], mother=v[450608], child=v[139504]}*
- ==> *{father=v[16408], mother=v[450608], child=v[163880]}*
- ==> *{father=v[16408], mother=v[450608], child=v[176368]}*
但我想通过这种方式获取它们:
==> {father=v[16408], mother=v[450608], children=[v[139504], v[163880], v[176368]]
有没有办法在 gremlin 中做到这一点,在 Gremlin.Net 中更具体。谢谢
最简单的方法可能是 project
步骤:
gremlin> g.V(61464).project('father','mother','children').
by(out('father')).
by(out('mother')).
by(__.in('father').fold())
==>[father:v[4344],mother:v[4152],children:[v[8440],v[12536],v[40964200]]]
(ID 与您的不匹配,因为我必须自己创建图表并获得其他 ID。)
请注意,__.in('father')
的 __
只有 Gremlin-Groovy 是必需的,因为 in
是 Groovy 中的保留关键字,并且
out('father')
是 outE('father').inV()
.
你可以在Gremlin.Net中编写相同的遍历。然后它看起来像这样:
g.V(61464).Project<object>("father", "mother", "children").
By(Out("father")).
By(Out("mother")).
By(In("father").Fold()).Next();
(您需要 using static Gremlin.Net.Process.Traversal.__;
才能像这样编写遍历。否则 By
-步骤将如下所示:By(__.Out("father"))
。请参阅 TinkerPop 文档了解 more information on this.)