Reputation: 934
Assuming a node for this example a User has many friends (they are Users aswell) lets assume as well that im looking the user by id which is unique.
How can i query to get one row back with a property of friends as array? Example:
MATCH (user:User {id: "some-id"})-[:FriendsWith]->(friend:User)
RETURN user, friend
Now I expected the result to be an array of length one,
like this [{user: data, friend: [array of users]}]
But instade I got rows [{user: , friend:}, {user, friend: }]
the user
was duplicated in each row..
Upvotes: 0
Views: 37
Reputation: 8556
You can use the collect
function to create a collection:
MATCH (user:User {id: "some-id"})-[:FriendsWith]->(friend:User)
RETURN user, collect(friend.name) AS friends
There is an implicit group by when using an aggregation.
Upvotes: 2