aggregate
Aggregate all objects into a collection at a particular point in a graph traversal.
Synopsis
aggregate('variable_name')
Syntax conventions | Description |
---|---|
Lowercase and uppercase | Literal keyword. Includes () . |
Italics |
Variable value. Replace with a user-defined value. |
[] |
Optional. Square brackets ( [] ) surround
optional command arguments. Do not type the square brackets. |
{} |
Group. Braces ( {} ) identify a group to choose
from. Do not type the braces. |
| |
Or. A vertical bar ( | ) separates alternative
elements. Type any one of the elements. Do not type the vertical
bar. |
... |
Repeatable. An ellipsis ( ... ) indicates that
you can repeat the syntax element as often as required. |
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
.