简体   繁体   中英

Neo4J how to add a relationship between 2 nodes that already exist

i have a little problem with neo4j and i don't know how to resolve it.

I use the sintax: create(p1)-[:wow]->(p2) and it works fine, this actually make a relationship between node p1 and node p2 , but what if I want to make a relatioship between the first one and the third?

When I try with create(p1)-[:wow]->(p3) it create something like 4 more nodes that I don't want. What can I do?

例

for example in this image how can i make a relation ship between node 1 and 3 without make any other nodes?

Thank you

You have to first match your nodes then create relation between them:

You created nodes:

CREATE (a:Foo{name:"foo"}), (b:Bar{name:"bar"})

Then you want to create relation between them:

MATCH (f:Foo{name:"foo"}), (h:Bar{name:"bar"})
with f,h
CREATE (f)-[:LOVES]->(h)

If you don't match the nodes before, Neo4j will create those nodes for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM