Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Neo4J - Creating Relationship on existing nodes

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.

like image 203
user3180997 Avatar asked Jan 24 '16 22:01

user3180997


People also ask

How do you create a relationship between existing nodes in Neo4j?

To create a relationship between two nodes, we first get the two nodes. Once the nodes are loaded, we simply create a relationship between them. The created relationship is returned by the query.

Can relationships have properties in Neo4j?

The graphs in the Neo4j Graph Data Science Library support properties for relationships. We provide multiple operations to work with the stored relationship-properties in projected graphs. Relationship properties are either added during the graph projection or when using the mutate mode of our graph algorithms.

Which clause is used to add new properties to an existing node or relationship?

SET clause is used to add new properties to an existing Node or Relationship.

Can a node have multiple labels Neo4j?

Neo4j CQL CREATE a Node Label We can say this Label name to a Relationship as "Relationship Type". We can use CQL CREATE command to create a single label to a Node or a Relationship and multiple labels to a Node. That means Neo4j supports only single Relationship Type between two nodes.


1 Answers

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
like image 135
barthr Avatar answered Oct 02 '22 09:10

barthr