简体   繁体   中英

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)

As Frank Pavageau said in the comments, you made an error in your query by not passing i with d in tha second WITH clause. 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.

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