0
votes

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?

Example

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

Thank you

1

1 Answers

1
votes

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.