aggregate
Aggregate all objects into a collection at a particular point in a graph traversal.
Synopsis
aggregate('variable\_name')
Description
The aggregate()
step is a sideEffect.
A vertex is added from a traversal g using addV
.
A previously created vertex label must be specified.
Examples
Return a collection of all the people that John Doe knows as an aggregate:
g.V().has('person', 'name', 'John Doe'). out('knows').aggregate('x')
Return all the friends of John Doe’s friends, including those that are friends of John Doe:
g.V().has('person', 'name', 'John Doe'). out('knows').aggregate('x'). in('knows').out('knows').valueMap('name', 'gender')
Find all the friends of John Doe’s friends that are not friends of John Doe:
g.V().has('person', 'name', 'John Doe'). out('knows').aggregate('x'). in('knows').out('knows'). where(without('x'))
Note the use of the aggregate('x')
in the later step where(without('x'))
that is used to exclude John Doe’s friends using the aggregate assigned to the variable x
.