last day (14 days later) » 

11:08 AM
0
A: Neo4j how to delete nodes recursively from some start node

Stefan ArmbrusterI'd split that up into two queries. The first one recursively collects the the product hierarchy downwards and the second one deletes one product node and its direct environment. Getting the product hierarchy is simple: MATCH (p:Product)-[:CONTAINS*]->(childProduct) WHERE id(p) = {productId} RE...

 
Thanks for your answer ! So, I need to collect all child products Ids and then invoke the second query on each of these ids ? Does order matters?
 
Exactly. You can also pass in multiple ids as array parameter into the 2nd statement if you use WHERE id(p) in {myIdList}. Keep in mind to have a backup of your data before trying that.
Order does not matter.
 
Thanks ! Looks like this part of the query doesn't work - WHERE none(x in labels(t) WHERE x in ['User', 'Product']) because it deletes users and other Products also..
 
can you provide a sample graph?
 
I think yes.. could you please tell me in what way it can be provided ?
 
11:09 AM
hi, create a zip or tar.gz of your graph.db folder and upload here.
 
Hi ! thanks, just a moment please
 
11:23 AM
thedownloadplanet.com/files/techbook-test-db.zip
I have uploaded it here
instead of Product please use Decision entity
It is Neo4j 2.1.7 database
 
looks like you have PARENT and CONTAINS both between the same two Decisions. Does that make sense?
If CONTAINS and PARENT are sementically the same thing, you should omit one of them
ha, and it's a shame Neo4j is not a node on its own in your graph ;-)
 
Thanks ! I think I have a wrong direction in the entityt definition - Direction.INCOMING.. I need to change it to OUTGOING
@RelatedTo(type = PARENT, direction = Direction.INCOMING)
private Decision parent;
not it
@RelatedTo(type = PARENT, direction = Direction.OUTGOING)
private Decision parent;
 
is a Criterion really "owned" by a Decision? E.g. "Replication support" might apply to different kinds of databases (aka Decision) here?
 
according to idea, we can define different (the same also) Criteria for different Decisions
so, "owned" is a correct case here
the same I meant - with the same name
>>
ha, and it's a shame Neo4j is not a node on its own in your graph - I definitely will add this awesome DB to my graph !
 
11:56 AM
this query MATCH (d:Decision) OPTIONAL MATCH (d)-[r]-(t) WHERE id(d) IN {decisionsIds} DELETE r, d WITH t OPTIONAL MATCH (t)-[r2:VOTED_ON|:CREATED_BY]->() WHERE none(x in labels(t) WHERE x in ['user', 'decision']) DELETE t, r2 correctly deletes Criteria and Votes.. but also deletes other Decisions and User..
 
12:15 PM
try this one:

MATCH (p:Decision)
WHERE p.name = "NoSQL"
WITH p
OPTIONAL MATCH (p)-[r]-(t)
DELETE p,r
WITH t,r
OPTIONAL MATCH (t)-[r2:VOTED_ON|:CREATED_BY|:VOTED_FOR]-()
WITH t, r2,r
WHERE none(x in labels(t) WHERE x in ["User", "Decision"])
DELETE t,r2
need to leave, please provide feedback if that one solved the issue so I can update my public answer on SO. Cheers.
 
sure. thank you very much !
my test passed !!!
thank you so much !!!
 
updated the reply on SO. goodbye.
 

last day (14 days later) »