Query to "collect" nodes

Hi,

I have the nodes in the format of
image

Here Label of the node at receiving end is "Label1" and the label of 3 nodes pointing to the other node is "Label2". All the nodes in here have 2 properties "Name" and "Id".

I wrote a query to get the nodes and the output was
image

Here I have 3 outputs, because I have 3 different nodes and L1 beign common to all the 3 ouputs. But I am looking for a query which will give me only 1 output like
image
Or atleast siomething similar to this. Basically I want 1 ouput with the "Label2" nodes inside a list.

The above output was achieved by having multiple cypher queries
image

So I am trying to get it in a single query .

I am looking for a solution which is the extended version of collect, because collects gives us a list for a single property, but I have 2 properties and I want with their Property name.

If someone could please share some links of refernce to achieve this would be helpful. Thanks in advance.

Try this:

match(n:Label1)--(m:Label2)
where n.name = 'Test'
with 
{L1Name: n.name, L1Id: n.Id} as L1,
{L2Name: m.name, L2Id: m.Id} as L2
with L1, collect(L2) as L2_nodes
return {Label1: L1, Label2: L2_nodes} as result

1 Like