1

假设我有一个节点链/列表:

 (:node {uid:333})-->(:node {uid:102})-->(:node {uid:155})-->...

我想用另一条节点链替换/替换一个或多个连续节点。

 (:node {uid:255})-->(:node {uid:107})

在我看来,实现这一目标的操作数量太多,无法将它们放在单个查询中。

 1. input [255,107]
 2. create the (255)-->(107)
 3. find the place where to insert in the original chain
 4. connect this node to (255)-->(107)
 5. connect the tail-107 to the original chain (if it does not end)
 6. delete the part to be replaced..

问题是,如果它不是单个查询,那么它会变得更加复杂。

你会怎么做?(必须像字符串替换一样工作)

简化它的一个想法是找到链中的位置并使用索引。

4

1 回答 1

2

我希望我正确理解了你的问题

MATCH ({uid:333})-[]->(s {uid:102})-[e0]->({uid:155})-[e1]->()
CREATE (s)-[:R]->({uid:255})-[:R]->({uid:107})
DELETE e0, e1

MATCH 将找到您要修改的链。

CREATE 将引入新的子链。

DELETE 将断开被替换的原始子链,根据您的用例,您可能想要删除替换的节点而不是边缘。

于 2020-11-13T21:21:10.863 回答