Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
06-16-2022 04:17 AM
So I need to get all :REL relationships of a specific node d:Doc but I want to return the result in a very specific way:
So far this approach works but there is a warning of this being deprecated:
MATCH(d:Doc)
WHERE d.id = "xxxxx"
OPTIONAL MATCH (n)-[:REL]->(d)
WITH d.id as id,
CASE WHEN n:A THEN
{label:"A", ids: collect(n.id), type: n.type, code: n.code} END AS a,
CASE WHEN n:B THEN
{label:"B", id: n.id, prop: n.prop } END AS b
return id, collect(a) as as, collect(b) as bs
warning:
This feature is deprecated and will be removed in future versions.
Aggregation column contains implicit grouping expressions. Aggregation expressions with implicit grouping keys are deprecated and will be removed in a future version. For example, in 'RETURN n.a, n.a + n.b + count(*)' the aggregation expression 'n.a + n.b + count(*)' includes the implicit grouping key 'n.b', and this expression is now deprecated. It may be possible to rewrite the query by extracting these grouping/aggregation expressions into a preceding WITH clause.
I read this post: Getting a warning when using collect
And I came up with this, but the database will have millions of nodes, I'm not sure if this is the best approach.
MATCH (d:Doc)
WHERE d.id = "xxxxx"
MATCH (a:A)-[:REL]->(d)
WITH d, a.code as code, a.type as type, collect(a.id) AS ids
WITH d, {ids:ids, code:code, type: type} AS a
MATCH (b:B)-[:REL]->(d)
WITH d, e, collect({id: b.document, prop: b.prop}) AS b
RETURN d.id, collect(a), b
Is it possible to do it with one MATCH and using CASE like in my first query? (can't use apoc)
06-16-2022 10:56 AM
Is b the same as a ? in the matches? are you double matching?
but yes, in general it should work like this. move implicit inner aggregations to a previous WITH.
Your last collect should be
WITH d, collect(a) AS collectedAs, b
RETURN d.id, collectedAs, b
All the sessions of the conference are now available online