fatash
fatash

Reputation: 3

Neo4j 'match' within 'unwind' operation

I have a Neo4j query where I am trying to get all distinct ids and then, for each id, return all nodes that match that id. Here's what my query looks like:

match (x:Log) with collect(distinct x.id) as ids 
unwind ids as i 
match (y:Log {id:i}) return y;

I was hoping that the results of this query would be grouped by id aka have multiple nodes per row, where each row holds all nodes that share an id. Instead it is returning only one node per row, and there are multiple rows of the same id. How do I get the results to be grouped by id?

Example: Let's say there are five nodes of label Log. Two of the Log nodes have id='abc' and three of them have id='123'. Right now, my query is returning five rows that each contain one node, but I would like it to return two rows: one row that contains all the Log nodes of id='123', and another row that contains all the Log nodes of id='abc'.

Upvotes: 0

Views: 2164

Answers (1)

cybersam
cybersam

Reputation: 67044

This will return a distinct id per row, along with the nodes having that id:

MATCH (x:Log)
RETURN x.id AS id, COLLECT(x) as nodes;

Upvotes: 1

Related Questions