Manu Bhat
Manu Bhat

Reputation: 155

Neo4j match node with Id and create relationship

I have a requirement to match two existing nodes with a specific Id and then create a relationship between these nodes. Below is my cypher. But when I execute this , I always get no changes done .

MATCH(i:`Mechanical Component`)
where ID(i)=9912
with(i)
match(d:Features{name:"Mechanical Component"})
with(d)
where ID(d)=9934
MERGE (i)-[:FEATURES]->(d)

Upvotes: 3

Views: 6190

Answers (1)

Supamiu
Supamiu

Reputation: 8731

As Frank Pavageau said in the comments, you made an error in your query by not passing i with d in tha second WITHclause. Here is the corrected query you need:

MATCH(i:Mechanical Component)
where ID(i)=9912
with(i)
match(d:Features{name:"Mechanical Component"})
with(d,i)
where ID(d)=9934
MERGE (i)-[:FEATURES]->(d)

Keep in mind that using the internal id is really not recommended since it's generated and may change (see Should we use the Neo4J internal id?). You should probably use your own unique ID (with constraints) and match your node using this ID.

Upvotes: 2

Related Questions