带有collect和delete子句的neo4j查询问题

时间:2013-11-09 15:31:14

标签: neo4j cypher

我是neo4j的新手。根据我的要求,我需要获取id列表(收集)并删除同一查询中的节点。

在下面的查询中,当我只返回id时,我得到正确的结果,即; 2 ids

START n=node:galleryid(galleryid='f0666ac5-9f61-4431-80b1-c9719ef8c1f9') 
MATCH n-[rels*1..]->p 
WITH n, rels, p, collect(p.photouniqueid) as photoids 
RETURN photoids;

按预期结果并得到它:["3dcd792b-9eed-4a74-826a-6801c9f2b707"] ["e5c91a60-41cf-4afb-8aa6-49a4af00dd38"]

但是当我尝试将delete子句附加到查询时,我只得到一个id。

START n=node:galleryid(galleryid='f0666ac5-9f61-4431-80b1-c9719ef8c1f9') 
MATCH n-[rels*1..]->p WITH n, rels, p, collect(p.photouniqueid) as photosid 
FOREACH(rel IN rels: DELETE rel) 
DELETE p 
WITH n, photosid 
MATCH n<-[r]-() 
DELETE n, r 
RETURN photosid;

Result - ["3dcd792b-9eed-4a74-826a-6801c9f2b707"]
==> 1 row
==> Nodes deleted: 3
==> Relationships deleted: 3

有人可以建议第二次查询的问题是什么?谢谢你的帮助。

1 个答案:

答案 0 :(得分:1)

试试这个:

START n=node:galleryid(galleryid='f0666ac5-9f61-4431-80b1-c9719ef8c1f9') 
MATCH n-[rels*1..]->p 
WITH n, collect(path as paths) collect(p.photouniqueid) as photosid 
FOREACH(p IN paths: 
  FOREACH(r in rels(p) :  DELETE rel)
  FOREACH(x in tail(nodes(p)) : DELETE x)
)
WITH n, photosid
MATCH n<-[r]-() 
DELETE n, r 
RETURN photosid;

如果第二场比赛找不到任何路径,则不会返回任何内容