1

Apologies if this has already been asked, but I was unable to find the answer

I would like to error when trying to create a relationship between nodes, where one or both of the nodes do not exist

For example, the following code just returns no results, but I would like it to raise an error to let me know that these nodes do not exist, so that I can surface that error to my application:

MATCH (user1: User{uuid: '123'}), (user2: User{uuid: '456'})
CREATE (user1)-[:LIKES]->(user2)

Please assume that the database is empty and therefore no nodes were matched

I tried to add a constraint, but I didn't know how to approach it and if this is possible - are you able to help please?

4

1 回答 1

0

当成功找到两个节点时,您的查询可以返回一些东西(如新关系),而不是错误。如果查询没有返回任何内容,则意味着一个或两个节点不存在。

例如:

MATCH (user1: User{uuid: '123'}), (user2: User{uuid: '456'})
CREATE (user1)-[r:LIKES]->(user2)
RETURN r;
于 2020-05-31T04:18:55.233 回答