We find that writing and maintaining Cypher queries is a little painful when it comes to collecting items. We often want to collect something and discard the original node. The following is an example:
MATCH (p)-[]-(c) WITH p, collect(c) as c RETURN p, c
The above does not look too bad. The problem is the explicit name of p , the field we want to keep. As we add more MATCH and OPTIONAL MATCH with aggregation, this becomes a maintainability nightmare. We cannot reorder MATCH / WITH pairs without changing also all the fields that we reference. When we do collect , we always want to discard the original node.
WITH has * which can be used, but this will include the field we are collecting, and we cannot replace the value.
MATCH (p)-[]-(c) WITH *, collect(c) as c RETURN p, c
Is there a way to exclude something in a WITH statement without explicitly naming everything that should be included? Something like the following?
MATCH (p)-[]-(c) WITH *, without(c), collect(c) as cs RETURN p, cs
source share