How can I limit to only one relationship between two nodes in Neo4j?

前端 未结 1 943
谎友^
谎友^ 2021-01-23 04:30

I have the following graph:

Currently I am using this QUERY to add a relationship between two nodes:

MATCH (a:Service),(b:Service)
WHERE a.servi         


        
相关标签:
1条回答
  • 2021-01-23 04:44

    There is no built-in way to throw an error if you create a duplicate relationship. But that would also be a pretty expensive way to enforce such a policy.

    Instead, you can use MERGE instead of CREATE to avoid creating duplicate relationships.

    For example, this query will only create the DEPENDENT_ON relationship if it does not already exist; otherwise, it will just bind the existing relationship to r:

        MATCH (a:Service), (b:Service)
        WHERE a.service_id = 'cs2322' AND b.service_id = 'ab3232'
        MERGE (a)-[r:DEPENDENT_ON]->(b)
        RETURN TYPE(r)
    
    0 讨论(0)
提交回复
热议问题