Neo4J - Creating Relationship on existing nodes

user3180997 picture user3180997 · Jan 24, 2016 · Viewed 10.4k times · Source

I am new to Neo4J and I am looking to create a new relationship between an existing node and a new node.

I have a university node, and person node.

I am trying to assign a new person to an existing university.

I am trying to following code:

MATCH (p:Person {name:'Nick'}), (u:University {title:'Exeter'}) CREATE (p)-[:LIKES]->(u)

So in the above code: MATCH (p:Person {name:'Nick'}) is the new user

AND (u:University {title:'Exeter'}) is the exisiting univeristy.

But it is coming back (no changes, no rows)

I have even tried the query without the MATCH part but no luck either.

I have looked at few similar answers but they didn't seem to work either.

Any help would be very much appreciated. Thank you.

Answer

barthr picture barthr · Jan 25, 2016

Match before u create new one, as suggested in the comments!

MATCH(u:University {title:'Exeter'})
CREATE(p:Person {name:'Nick'})
CREATE(p)-[w:LIKES]->(u)
return w