Search code examples
orientdbgraph-databasesgremlin

Gremlin : fetch result as an Array


I'm trying to select the entities as mentioned in Gremlin Docs for Select

gremlin> g.v(1).as('x').out('knows').as('y').select
==>[x:v[1], y:v[2]]
==>[x:v[1], y:v[4]]

But I'm trying to get result as like below

gremlin> g.v(1).as('x').out('knows').as('y').select
==>[[x:v[1]], [y:v[2],y:v[4]]]

Because current scenario for an entity 'x', it has more than 500 associated 'y' entities, So I'm ended up getting same 'x' data for all 'y' entities

gremlin> g.v(1).as('x').out('knows').as('y').select
==>[x:v[1], y:v[2]]
==>[x:v[1], y:v[4]]
==>.....
==>[x:v[1], y:v[500]]

Could someone guide me the way to do this?


Solution

  • You could use groupBy():

    g.V(1).groupBy{it}{it.out('knows')}.cap()