简体   繁体   中英

neo4j finding a node to create a relationship

neo4j is neo4j community edition, version 3.1.1

I create a node for a LUN

merge ( l3:lun {nom:"OS_SU1_", serie:"123456", coordonnees:"00:00:00"})
set l3.taille = 102400

latter on, I want to connect a host to this LUN, creating host is easy

 merge (hSUP_1:host {nom:"SUP_1"})

now the big deal, I want to find l by its coordinate and create the relationship, I tried

match (l:lun {coordonnees : "00:00:00"}) merge (hSUP_1) -[:connecte_a]-> (l)

and get an error:

WITH is required between MERGE and MATCH (line ...)

(I cannot keep l3 identifier above, those lines are generated by a script that parse different file)

what is correct syntax ?

man page searched : neo4j.com/docs/developer-manual/current/cypher/clauses/merge/ (3.3.8.4. Merge relationships )

Yop,

You can't make a MATCH after a MERGE,so you have to add a WITH between like this :

MERGE (hSUP_1:host {nom:"SUP_1"})
MATCH (l:lun {coordonnees : "00:00:00"}) 
WITH l, hSUP
  MERGE (hSUP_1) -[:connecte_a]-> (l)

Otherwise, you can also change the order like this :

MATCH (l:lun {coordonnees : "00:00:00"}) 
MERGE (hSUP_1:host {nom:"SUP_1"})
MERGE (hSUP_1) -[:connecte_a]-> (l)

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