How do I see if DELETE was successful om Neo4j via

2019-05-11 23:43发布

问题:

How do I see if DELETE was successful om Neo4j via REST API ? Here is my query.

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 get following response regardless of whether anything was deleted or not.

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

回答1:

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 such as

"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 applies to the transactional cypher endpoint. If you're using the legacy cypher endpoint, see http://neo4j.com/docs/2.2.1/rest-api-cypher.html#rest-api-retrieve-query-metadata



回答2:

Have you tried to set the database to retrieve the "graph" and also the removed item?

It will mark the node as "removed" on the metadata of the node.

You should add that information on the POST request on the following parameter resultDataContents.

The request JSON must contains this:

resultDataContents: ["graph"]

If you read the data using the "row" schema you can set the database to give the response of both, but you need to remember that this will increase the received data. In that case, that parameter should be like this one:

resultDataContents: ["graph","row"]

Example of query:

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

The possible result would be something like this:

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

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


标签: neo4j cypher