1

I am trying to delete some connected node together say Photo, with other connected nodes with relationship. Case is like this:
Album-CONTAINS_PHOTO-Photos (here could be multiple images)
Photo-taken_at-Location
Photo-HAS-Comment
Comment-ADDED_BY-User

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:

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.)

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).
I changed my criteria to MATCH node relationship as
MATCH pht-[r]-x,MATCH pht-[r?:HAS | :taken_at]-x,
MATCH pht-[r:HAS]-x, pht-[s:taken_at]-x, but no result.

I went through this and official link, but I guess, I am little away from something.. Kindly help.

Community
  • 1
  • 1
Aman Gupta
  • 5,548
  • 10
  • 52
  • 88

1 Answers1

2

You need to separate query and modifing parts of a cypher query for updating the graph. WITH is used as separation token:

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;
Thomas Fenzl
  • 4,342
  • 1
  • 17
  • 25
  • Thanks thomas, for updating my knowledge. I am trying little bit more in this to make query more specific. May I edit your answer a little bit so that I can accept it ? – Aman Gupta May 29 '13 at 04:01
  • Your change was rejected before I even saw it. It was considered too extensive and not fitting the question. – Thomas Fenzl May 29 '13 at 11:04
  • I just added `MATCH photo-[r?:HAS]->x-[s?:ADDED_BY]-y,photo-[t:taken_at]-z, photo<-[c:CONTAINS_PHOTO]-alb` and delete relationship first followed by node variable. It worked. – Aman Gupta May 29 '13 at 12:14