[英]Delete multiple nodes with their relationships in neo4j
I am trying to delete some connected node together say Photo , with other connected nodes with relationship. 我正在尝试删除一些连接的节点,例如Photo ,以及具有关系的其他连接的节点。 Case is like this:
情况是这样的:
Album -CONTAINS_PHOTO- Photos (here could be multiple images) 相册 -CONTAINS_PHOTO- 照片 (此处可能有多张图片)
Photo -taken_at- Location 照片 -taken_at- 位置
Photo -HAS- Comment 图片 -HAS- 评论
Comment -ADDED_BY- User 评论 -ADDED_BY- 用户
I want to delete from Photo to Comment node. 我想从“照片到评论”节点中删除。 (Since Album and user is parent node hence I dont need to delete them unless n until required)
(由于专辑和用户是父节点,因此除非需要,否则我不需要删除它们)
On neo4j webadmin console I am firing this query: 在neo4j Webadmin控制台上,我触发了以下查询:
start pht=node:__types__(className="org.sg.domain.Photo"),
cmt=node:__types__(className="org.sg.domain.Comments")
MATCH pht-[r:HAS]-x,pht-[t:taken_at]-x, cmt-[s]-y
WHERE pht.photoId="MhQ2W1GrJ" AND
pht.albumName="FirstAlbum" AND
pht.userName="abc" delete r,s,t,pht,cmt;
(where 'x' and 'y' is general placeholders.) (其中“ x”和“ y”是常规占位符。)
I am getting this output: 我得到以下输出:
Invalid query
Node[7] has been deleted in this tx
(where Node[7]
is denoted for Photo object. Although it shows Node[7] deleted but thats not correct). (其中将
Node[7]
表示为Photo对象。尽管它显示Node [7]已删除,但这并不正确)。
I changed my criteria to MATCH
node relationship as 我将条件更改为
MATCH
节点关系为
MATCH pht-[r]-x
, MATCH pht-[r?:HAS | :taken_at]-x
MATCH pht-[r]-x
, MATCH pht-[r?:HAS | :taken_at]-x
MATCH pht-[r?:HAS | :taken_at]-x
, MATCH pht-[r?:HAS | :taken_at]-x
,
MATCH pht-[r:HAS]-x, pht-[s:taken_at]-x
, but no result. MATCH pht-[r:HAS]-x, pht-[s:taken_at]-x
,但没有结果。
I went through this and official link , but I guess, I am little away from something.. Kindly help. 我通过了这个 官方链接 ,但是我想我离什么都没什么。
You need to separate query and modifing parts of a cypher query for updating the graph . 您需要分开查询和修改密码查询的各个部分才能更新图形 。
WITH
is used as separation token: WITH
用作分隔令牌:
START pht=node:__types__(className="org.sg.domain.Photo"),
cmt=node:__types__(className="org.sg.domain.Comments")
MATCH pht-[r:HAS]-x,pht-[t:taken_at]-x, cmt-[s]-y
WHERE pht.photoId="MhQ2W1GrJ" AND
pht.albumName="FirstAlbum" AND
pht.userName="abc"
WITH r,s,t,pht,cmt
delete r,s,t,pht,cmt;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.