How do I see if DELETE was successful om Neo4j via REST API?

非 Y 不嫁゛ 提交于 2019-12-07 17:15:54

问题


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
            }
          ],
          // ...


来源:https://stackoverflow.com/questions/30308842/how-do-i-see-if-delete-was-successful-om-neo4j-via-rest-api

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!