你可以
project()
将元素转换为
Map
:
gremlin> g.V(1).project('name','age').by('name').by('age')
==>[name:marko,age:29]
如您所见,采用这种方法可以在控制
by()
阶跃调制器。如果返回的顶点没有同质属性键,则需要以某种方式对此进行说明-有一种可能性:
gremlin> g.V().project('name','age').
......1> by('name').
......2> by(coalesce(values('age'),constant('none')))
==>[name:marko,age:29]
==>[name:vadas,age:27]
==>[name:lop,age:none]
==>[name:josh,age:32]
==>[name:ripple,age:none]
==>[name:peter,age:35]
如果不使用project,您也可以执行以下操作:
gremlin> g.V().local(properties().group().by(key()).by(value()))
==>[name:marko,age:29]
==>[name:vadas,age:27]
==>[name:lop,lang:java]
==>[name:josh,age:32]
==>[name:ripple,lang:java]
==>[name:peter,age:35]
没有那么清楚
项目()
并将获得通常不鼓励的所有属性,但显然这种方法会起作用。我想您可以按如下方式逐项列出属性:
gremlin> g.V().local(properties('name','age').group().by(key()).by(value()))
==>[name:marko,age:29]
==>[name:vadas,age:27]
==>[name:lop]
==>[name:josh,age:32]
==>[name:ripple]
==>[name:peter,age:35]