I'm currently writing unit tests that handle the case of deletion of non-existing nodes and relationships by their ID. Both queries should return the deleted nodes and relationships as array.
Delete nodes by ID:
MATCH (n)
WHERE id(n) IN $ids
OPTIONAL MATCH (n)-[r]-()
DETACH DELETE n
RETURN COLLECT(DISTINCT n) as nodes, COLLECT(DISTINCT r) as relationships
Delete relationships by ID:
MATCH ()-[r]->()
WHERE id(r) IN $ids
DELETE r
RETURN [] as nodes, COLLECT(DISTINCT r) as relationships
If I test both queries with IDs $ids = [-1, -2] then I get different results even though the IDs don't exist in both cases.
The node query returns one record with two empty arrays:
[
{
"keys": [
"nodes",
"relationships"
],
"length": 2,
"_fields": [
[],
[]
],
"_fieldLookup": {
"nodes": 0,
"relationships": 1
}
}
]
Whereas the relationships query returns no record at all:
[]
Why is this the case?