1
votes

I have a Neo4j graph containing PI and officer nodes, with relationships between them (each of which has an institution property). I'm trying to create an inst_list property for each PI which lists all the institution properties of all of their edges. I'm still learning my way around Cypher, but confused as to why this is only creating an empty array for each PI:

MATCH (p:pi:DOE)-[a:award]-(o:officer:DOE)
WITH pi, a, COLLECT(distinct a.instituion) as insts
SET pi.inst_list=insts

It seems like it is an issue with COLLECT, as

MATCH (p:pi:DOE)-[a:award]-(o:officer:DOE)
WITH a.institution AS insts
RETURN insts

returns all the expected values.

1

1 Answers

4
votes

You just need to remove the a from your WITH clause.

MATCH (p:pi:DOE)-[a:award]-(o:officer:DOE)
WITH p, COLLECT(distinct a.institution) as insts
SET pi.inst_list=insts

By including the a, you were not collecting the institution property for each p, you were collecting it for each p and a, essentially doing nothing.

I also assume you meant p and not pi; in your query above, p is the identifier and pi is one of the labels. You also had a typo in institution, which is probably why your array was empty instead of the single value.