What are the collections in Cypher / Neo4J?

I really don’t understand what is the difference between collections and another type of output in Cypher. Can someone explain this to me please?

For example, request

match (c:Context) where c.name="health" or c.name="opinion" return collect(c);

returns 1 row, and the query

match (c:Context) where c.name="health" or c.name="opinion" return c;

returns 6 rows (I have 6 nodes in my database that match the criteria).

This is apparently the only difference.

So, is this just a way of presenting data? Or is there any advantage to using collections?

Thank you for your help!

+3
source share
1 answer

Collections return entities in an array, not a separate "string" for each result. The advantage of this, for example: I want to get all the addresses associated with the contact.

 Match (c:Contact)-[:AddressRelation]->(a:Address)
 return c,collect(a)

, ( )

- :

row = {name: "fred" }, [{address1}, {address2},...]

:

row = {name: "fred" }, {address1}

row = {name: "fred" }, {address2}

... ...

, , , node foreach ..

+4

All Articles