CREATE UNIQUE in neo4j produces duplicate nodes

前端 未结 2 2004
花落未央
花落未央 2021-01-22 14:45

According to the neo4j documentation:

CREATE UNIQUE is in the middle of MATCH and CREATE — it will match what it can, and create what is missing. CREATE

2条回答
  •  伪装坚强ぢ
    2021-01-22 14:52

    Here is how you can do it with CREATE UNIQUE

    MATCH (a:Person {name: 'Alice'}), (b:Person {name:'Bob'}) 
    CREATE UNIQUE (a)-[:knows]->(b), (b)-[:knows]->(a)
    

    You need 2 match clauses otherwise you are always creating the node in the CREATE UNIQUE statement, not matching existing nodes.

提交回复
热议问题