Jacobian
Jacobian

Reputation: 10812

Unable to delete Neo4j nodes based on condition

I added a bunch of nodes to the database. All the nodes have a format that looks like this:

{"id":"10","guid":"...", "type":"object_1_"}
{"id":"11","guid":"...", "type":"object_1_"}
...
{"id":"11","guid":"...", "type":"object_N_"}

And this ^^^ is exactly what I get when I run a START n=node(*) RETURN n query.

However, when I try to delete some nodes based on a condition, then it does not work. So, this

MATCH (n{type:"object_1_"}) OPTIONAL MATCH (n)-[r]-() DELETE n,r

does not work. And I wonder why. Only a trivial case works:

MATCH (n) OPTIONAL MATCH (n)-[r]-() DELETE n, r

but this is not what I want. I want to have some condition, like the above one where type attribute is object_1_. So, how can I do that?

Upvotes: 1

Views: 362

Answers (1)

Jacobian
Jacobian

Reputation: 10812

The whole trouble was in the way how I ran this query in curl. The incorrect way was:

curl http://... -H ... -d "{\"query\":\"MATCH (n{type:\"object_1_\"}) 
                           OPTIONAL MATCH (n)-[r]-() DELETE n,r\"}"

Neo4j parser did not throw any error message, but it was still incorrect. The right way to do was:

curl http://... -H ... -d "{\"query\":\"MATCH (n{type:'object_1_'})
                          OPTIONAL MATCH (n)-[r]-() DELETE n,r\"}"

Upvotes: 1

Related Questions