2014-12-26 118 views
2

我想刪除與子節點(65,66,67)和關係,從這個圖節點(64): Graph image的Neo4j/Cypher支架刪除節點和兒童的與關係

start n=node(64) 
match (e)-[r]->(n) 
match (n)-[r2*]->(e2) 
delete r 
foreach (rel in r2| delete rel) 
DELETE n, e2 

獲取例外:

javax.transaction.HeuristicRollbackException: Failed to commit transaction Transaction(1336, owner:"qtp1613738960-605")[STATUS_NO_TRANSACTION,Resources=1], transaction rolled back ---> Node record Node[66,used=false,rel=141,prop=-1,labels=Inline(0x0:[]),light] still has relationships 

如何更改查詢修復它?

+0

您的節點似乎仍然有其他關係,不僅僅是對於(過渡性地),您可能最終還會與沿着從n到e2的鏈中的其他孤兒節點結束 –

回答

3

我不是密碼專家,但你只能刪除沒有關係的節點,你的例外清楚地表明節點66仍然有關係。問題是,你不上65,66刪除傳入的關係(即來自左邊的),67

我會嘗試這樣的事:

START n=node(64) /*Select start node*/ 
MATCH()-[r1]->(n) /*Select all incoming relationships for start node*/ 
MATCH (n)-[*]->(o) /*Select "outgoing" nodes at any depth*/ 
MATCH()-[r2]->(o) /*Select all incoming relationships for "o", ie node 65,66,67*/ 
DELETE r1,r2,n,o 

通過萬一途中您只想刪除不需要使用的一組節點/關係foreach。一個簡單的delete將會很好。