[英]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.