Neo4j 是否可以在具有存在约束的属性上使用“在创建集时合并”?

Neo4j 是否可以在具有存在约束的属性上使用“在创建集时合并”?,neo4j,constraints,cypher,Neo4j,Constraints,Cypher,因为只有企业版的neo4j支持存在约束,所以我自己无法测试 例如,假设我对关系属性:Likes(createDate)有一个存在约束,通常用于一个:Person喜欢另一个人的地方 显然,这样的create调用将由于存在约束而失败: MATCH (a:Person{id:1}), (b:Person{id:2}) CREATE (a)-[:Likes]->(b) 我必须创建与createDate属性的关系以符合约束 但如果这种关系已经存在呢?我想这样做: MATCH (a:Person{i

因为只有企业版的neo4j支持存在约束,所以我自己无法测试

例如,假设我对关系属性:Likes(createDate)有一个存在约束,通常用于一个:Person喜欢另一个人的地方

显然,这样的create调用将由于存在约束而失败:

MATCH (a:Person{id:1}), (b:Person{id:2})
CREATE (a)-[:Likes]->(b)
我必须创建与createDate属性的关系以符合约束

但如果这种关系已经存在呢?我想这样做:

MATCH (a:Person{id:1}), (b:Person{id:2})
MERGE (a)-[v:Likes]->(b)
ON CREATE SET v.createDate = timestamp()

我担心这是不允许的,但我不知道是在合并时检查存在约束,还是在创建时检查存在约束。这似乎是一个相当标准的用例,我想知道企业版是否允许这样做而没有问题。

是的,Neo4j在调用创建时的
后检查节点的状态,并且该操作已完成:

neo4j-sh (?)$ CREATE CONSTRAINT ON ()-[r:Likes]-() ASSERT exists(r.createDate);
+-------------------+
| No data returned. |
+-------------------+
Property existence constraints added: 1
212 ms
neo4j-sh (?)$ CREATE (a:Person {uid: 1}), (b:Person {uid: 2});
+-------------------+
| No data returned. |
+-------------------+
Nodes created: 2
Properties set: 2
Labels added: 2
63 ms
neo4j-sh (?)$ MATCH (a:Person {uid: 1}), (b:Person {uid: 2}) MERGE (a)-[r:Likes]->(b);
+-------------------+
| No data returned. |
+-------------------+
Relationships created: 1
41 ms
ConstraintViolationException: Relationship 1398105 with type "Likes" must have the property "createDate" due to a constraint
neo4j-sh (?)$ MATCH (a:Person {uid: 1}), (b:Person {uid: 2}) MERGE (a)-[r:Likes]->(b) ON CREATE SET r.createDate = timestamp();
+-------------------+
| No data returned. |
+-------------------+
Relationships created: 1
Properties set: 1
43 ms
我使用的是Neo4j企业版3.0.3