I'm playing with 2.0 M6 neo4j server (oracle jdk7 on win7 64).
I'm trying to delete a node and its relationships using a single cypher query over the REST API.
The query I create (which works if I run it in the browser UI) looks like:
START n = node( 1916 ) MATCH n-[r]-() DELETE n, r
Which by the time I put it through gson comes out as:
{"query":"START n \u003d node( 1916 ) MATCH n-[r]-() DELETE n, r"}
Which when sent to the server gets the response:
{
"columns" : [ ],
"data" : [ ]
}
My test fails because the node can still be found in neo4j server by its id...
If I simplify my query to just delete a node (that has no relationships) so its:
START n = node( 1920 ) DELETE n
Which becomes
{"query":"START n \u003d node( 1920 ) DELETE n"}
Then the node is deleted.
Have I missed something?
Thanks, Andy
To delete nodes and relationships using Cypher, use the DELETE clause. The DELETE clause is used within the MATCH statement to delete whatever data was matched. So, the DELETE clause is used in the same place we used the RETURN clause in our previous examples.
There is a method to delete a node and all relationships related to that node. Use the DETACH DELETE statement: Example: MATCH (Kohli:player{name: "Virat Kohli"}) DETACH DELETE Kohli.
In Neo4j to delete a node or relations between nodes you have to use DELETE clause. To delete any node you need DELETE clause with the MATCH statement, the MATCH statement data will find the specific node and whichever node is matched with the statement that node will be vanished.
The Neo4j transactional HTTP endpoint allows you to execute a series of Cypher statements within the scope of a transaction.
For neo4j 2.0 you would do
START n=node(1916)
OPTIONAL MATCH n-[r]-()
DELETE r, n;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With