How to find out if DELETE was successful oo Neo4j via REST API?

How to find out if DELETE was successfully deleted by Neo4j via REST API? Here is my request.

MATCH (from_user:User),(to_user:User)
WHERE from_user.id = '522fed61e4b0a1f88d599ae0' AND to_user.id = '52b9f410e4b03902bd21629e'
MATCH from_user-[r]->to_user
DELETE r

      

via REST I am getting the following response no matter if anything was removed or not.

{
    "results": [
        {
            "columns": [],
            "data": []
        }
    ],
    "errors": []
}

      

+3


source to share


2 answers


Add this to your POST body

"includeStats":true

      

For example,

[
  {
    "statement": "MATCH (from_user:User),(to_user:User) WHERE from_user.id = '522fed61e4b0a1f88d599ae0' AND to_user.id = '52b9f410e4b03902bd21629e' MATCH from_user-[r]->to_user DELETE r",
    "parameters": {},
    "includeStats": true
  }
]
}

      



to get data like

"stats" : {
    "relationships_created" : 0,
    "nodes_deleted" : 0,
    "relationship_deleted" : 0,
    "indexes_added" : 0,
    "properties_set" : 0,
    "constraints_removed" : 0,
    "indexes_removed" : 0,
    "labels_removed" : 1,
    "constraints_added" : 0,
    "labels_added" : 1,
    "nodes_created" : 0,
    "contains_updates" : true

      

}

back. This refers to the endpoint of the transactional cache. If you are using the legacy cypher endpoint see http://neo4j.com/docs/2.2.1/rest-api-cypher.html#rest-api-retrieve-query-metadata

+3


source


Have you tried setting the database to retrieve the "graph" as well as the deleted item?

It marks node as "deleted" in the node metadata.

You must add this information to the POST request by the next parameter resultDataContents.

The JSON request should contain the following:

resultDataContents: ["graph"]

      

If you are reading data using a string schema, you can configure the database to respond to both, but you need to remember that this will increase the received data. In this case, this parameter should be like this:



resultDataContents: ["graph","row"]

      

Example request:

MATCH (from_user:User),(to_user:User)
WHERE from_user.id = '522fed61e4b0a1f88d599ae0' AND to_user.id = '52b9f410e4b03902bd21629e'
MATCH from_user-[r]->to_user
DELETE r
RETURN r

      

A possible result would be something like this:

{  
  "results":[  
    {  
      "columns":[  
        "a"
      ],
      "data":[  
        {
          "row":[  
            {  

            }
          ],
          "meta":[  
            {  
              "id":999999,
              "type":"node",
              "deleted":true
            }
          ],
          // ...

      

0


source