合并并在neo4j中的位置
merge and where in neo4j
我有 3 个具有以下属性和关系的节点:
LocationNode : location,
PersonNode : fullName,
CityNode: cityName
LocationNode<-[has_location]-(PersonNode)
PersonNode-[has_city]->(CityNode)
LocationNode是旧节点,需要删除。 LocationNode 数据将被移动到新节点 CityNode。对于所有与 LocationNode 有关系的 PersonNode,我需要删除该关系并创建与 CityNode 的新关系,其中 LocationNode.location = CityNode.cityName
注意:城市节点已经在数据库中创建,无需创建新节点。
我尝试了以下查询:
match (n:LocationNode)<-[r:has_location]-(j:PersonNode) delete r with n,j
merge (j)-[r2:has_city]->(h1:CityNode) where n.location = h1.cityName return j
我得到的错误是我在使用 MERGE 时无法使用 WHERE 条件。
谁能告诉我可以使用的正确查询?
条件 where
不能与 merge
一起使用。而由于CityNode
节点存在,你需要match
它,并且merge
它和PersonNode
之间的关系:
match (n:LocationNode)<-[r:has_location]-(j:PersonNode) delete r
with n, j
match (h1:CityNode) where n.location = h1.cityName
merge (j)-[r2:has_city]->(h1)
return j
我有 3 个具有以下属性和关系的节点:
LocationNode : location,
PersonNode : fullName,
CityNode: cityName
LocationNode<-[has_location]-(PersonNode)
PersonNode-[has_city]->(CityNode)
LocationNode是旧节点,需要删除。 LocationNode 数据将被移动到新节点 CityNode。对于所有与 LocationNode 有关系的 PersonNode,我需要删除该关系并创建与 CityNode 的新关系,其中 LocationNode.location = CityNode.cityName
注意:城市节点已经在数据库中创建,无需创建新节点。
我尝试了以下查询:
match (n:LocationNode)<-[r:has_location]-(j:PersonNode) delete r with n,j
merge (j)-[r2:has_city]->(h1:CityNode) where n.location = h1.cityName return j
我得到的错误是我在使用 MERGE 时无法使用 WHERE 条件。 谁能告诉我可以使用的正确查询?
条件 where
不能与 merge
一起使用。而由于CityNode
节点存在,你需要match
它,并且merge
它和PersonNode
之间的关系:
match (n:LocationNode)<-[r:has_location]-(j:PersonNode) delete r
with n, j
match (h1:CityNode) where n.location = h1.cityName
merge (j)-[r2:has_city]->(h1)
return j