Cypher query to delete node and its relationships

37 views
Skip to first unread message

Abdul Azeez Shaik

unread,
Nov 13, 2012, 12:35:16 PM11/13/12
to ne...@googlegroups.com
Hi.

I am using following query to delete the following this of a node,
  1. Its incoming and outgoing relationships
  2. Outgoing nodes
  3. itself
  4. Return outgoing nodes ids

START n=node:stylesheetid(stylesheetid={0}) MATCH n-[rels*1..]->p WITH n, rels, p, collect(p.availableImages) as photosid 

FOREACH(rel IN rels: DELETE rel) DELETE p 

WITH n, photosid MATCH n<-[r]-() DELETE n, r 

RETURN DISTINCT photosid

However, this doesn't work in case of no outgoing relationships, as first MATCH fails, any other way of achieving this functionality in same query.

Kindly let me know your suggestions on this.

Thanks,
Abdul

Wes Freeman

unread,
Nov 13, 2012, 1:00:12 PM11/13/12
to ne...@googlegroups.com
I think you need to do "WITH n, collect(rels), collect(p) ...", so that a value is returned even if rels and p don't match anything.

Wes

--
 
 

Reply all
Reply to author
Forward
0 new messages