3
votes

I have two nodes representing two people:

(:Person {name:"John Smith"})
(:Person {name:"Jane Doe"})

Then I have a third node representing an article coauthored by these two people:

(:Article {title:"Some_article"}, {Coauthor:["John Smith", "Jane Doe"]})

My question is: Can I create a relationship between these nodes based on matching the names? Something like this:

MATCH (n1:Person {name:"Jane Doe"})
MATCH (n2:Article{Coauthor:"Jane Doe"})
CREATE (n2)-[:AUTHORED_BY]->(n1)

Is this possible or do I need to break up the array into separate node properties e.g. Coauthor_1, Coauthor_2 etc?

Thanks

Neo4j CE 3.0.1 on Windows 10

1

1 Answers

4
votes

You can use a loop for creating authorship relationships :

MATCH (a:Article {title:"some title"})
UNWIND a.Coauthor as author
MERGE (p:Person {name: author})
MERGE (a)-[:AUTHORED_BY]->(p)