1

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 Answer 1

5

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.

1
  • Sorry about the typos, the network structure is actually a bit more complex so I didn't copy and paste the real query. Either way, removing 'a' from the 'WITH' statement totally did the trick, thanks!
    – Cody Braun
    Commented Sep 18, 2015 at 18:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.