Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
03-05-2021 02:42 AM
match (a:User {name: "Some Name"}), (b)<-[:rel1]-(a), (c)<-[:rel2]-(a) return a.id as id, a.name as name, collect(apoc.map.fromValues(["key1", b.value1, "key2", b.value2])) as aray, collect (c.prop) as property
for the last 2 collect(), I get the same value multiples times.
For example:
[{key1: value1}, {key2: value2}, {key1: value1}, {key2: value2}, {key1: value1}, {key2: value2}]
[prop1, prop2,prop3, prop1, prop2,prop3, prop1, prop2,prop3]
Solved! Go to Solution.
03-05-2021 09:20 AM
Since you're matching on the patterns to b
and c
nodes at the same time, you're generating a cartesian product between those results, and that becomes apparent when you collect(). (try doing a RETURN *
after your MATCH in place of your current RETURN to see how the results look at that point in time to better understand this).
Don't be too hasty on your matching. Do a MATCH on a to b, then collect() the values involving b (leaving a
as your grouping key), then do a separate MATCH to c, then collect() your c values.
Alternately, use pattern comprehensions instead.
03-05-2021 09:20 AM
Since you're matching on the patterns to b
and c
nodes at the same time, you're generating a cartesian product between those results, and that becomes apparent when you collect(). (try doing a RETURN *
after your MATCH in place of your current RETURN to see how the results look at that point in time to better understand this).
Don't be too hasty on your matching. Do a MATCH on a to b, then collect() the values involving b (leaving a
as your grouping key), then do a separate MATCH to c, then collect() your c values.
Alternately, use pattern comprehensions instead.
03-05-2021 09:13 PM
Thank you for your response.
All the sessions of the conference are now available online