Where the aggregated relations would contain the number of relations it aggregated (so C1->M1 = 1, C2->M1 = 2, M1->C3 = 3).
I have tried using both ` apoc.create.vRelationship` and ` apoc.nodes.collapse` but I am unable to obtain my desired result. I can always resort to computing the aggregated relations and store them in the DB, but I would really like to avoid that as it requires me to rerun that computation each time new data is inserted into the DB.
Would anyone be able to help me on this? Let me know if I should provide more information.
match(m:Monitor{name:"M1"})
call{
match(m)--()-[:RECEIVES]-(c:Connection)
with m, c, count(*) as cnt
CALL apoc.create.vRelationship(c,'RECEIVES_AGG',{number:cnt},m) YIELD rel
return c, rel
union
match(m)--()-[:SENDS]-(c:Connection)
with m, c, count(*) as cnt
CALL apoc.create.vRelationship(m,'SENDS_AGG',{number:cnt},c) YIELD rel
return c, rel
}
return *
I don't get why this happens; we only match connections that are connected to M1 right? How are Connection nodes from another Monitor/subgraph then returned as well?
My mistake. I forgot to import 'm' into the call subquery, so each match was not constrained to 'M1'.
Try this:
match(m:Monitor{name:"M1"})
call{
with m
match(m)--()-[:RECEIVES]-(c:Connection)
with m, c, count(*) as cnt
CALL apoc.create.vRelationship(c,'RECEIVES_AGG',{number:cnt},m) YIELD rel
return c, rel
union
with m
match(m)--()-[:SENDS]-(c:Connection)
with m, c, count(*) as cnt
CALL apoc.create.vRelationship(m,'SENDS_AGG',{number:cnt},c) YIELD rel
return c, rel
}
return *