简体   繁体   English

如何在Neo4j中对两个节点之间的关系数量创建约束

[英]How do I create a constraint on the number of relationships between two nodes in Neo4j

我想创建一个这样的约束:

create constraint on (a:NodeTypeA)-[r:TYPE_OF_REL]->(b:NodeTypeB) ASSERT count(r) < 2

You can kind of get the same result by using MERGE instead of CREATE whenever you create such a relationship. 每当创建这样的关系时,使用MERGE而不是CREATE都可以得到相同的结果。 For example: 例如:

MATCH (a:NodeTypeA {id: 123}), (b:NodeTypeB {id: 456})
MERGE (a)-[r:TYPE_OF_REL]->(b);

The MERGE will not create the relationship if it already exists. 如果已经存在,则MERGE将不会创建该关系。

(Note, however, that duplicate relationships are still possible if multiple MERGE operations can run concurrently. This is not a concern if you are using a neo4j 3.1.2 or later, or the DB is only asked to perform one operation at a time.) (但是,请注意,如果可以同时运行多个MERGE操作,则仍然可能存在重复关系。如果您使用的是neo4j 3.1.2或更高版本,或者只要求DB一次执行一个操作,则不必担心。 )

根据文档 ,Neo不支持此功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何显示 neo4j 中的所有节点和两个节点之间的关系? - How can i display the all nodes and relationships between two nodes in neo4j? 如何在两个节点之间的neo4j中创建关系? - How do I create a relationship in neo4j between two nodes? 如何使用neo4j cypher查询创建按关系数量划分的节点直方图? - How can I use neo4j cypher query to create a histogram of nodes bucketed by number of relationships? 在 Neo4j 中,如何在一个节点与其他节点的集合之间创建关系? - In Neo4j how can I create relationships between one node an a collection of other nodes? 如何使用 php 和 neo4j 在节点之间创建关系 - how can i create relationships between nodes using php and neo4j 如何通过在neo4j中导入csv文件来为现有节点创建关系? - How do i create relationships for existing nodes by importing csv file in neo4j? Neo4J查找节点之间的关系数(SIZE) - Neo4J find the the number(SIZE) of relationships between nodes 防止Neo4J中两个节点之间的多重关系 - Prevent Multiple Relationships between two nodes in Neo4J 如何在Neo4J中创建子串的关系 - How do I create relationships from substrings in Neo4J 在Neo4j中创建后续节点之间的关系(日期属性) - Create Relationships between Consequent Nodes (on date attribute) in Neo4j
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM