Reputation: 1122
I am trying to delete all nodes having degree equal or less than 1 but it is not working. My query is as follows
CALL apoc.periodic.commit("
MATCH (n:RoadPoint)-[:ROAD_SEGMENT]-(m:RoadPoint)
WHERE NOT (:Depot)-[:LOCATED_AT]->(n)
WITH n , COUNT(DISTINCT m) AS c
WHERE c <= 1
WITH n limit {limit}
DETACH DELETE n
RETURN COUNT(*)
", {limit:1000})
Upvotes: 1
Views: 1798
Reputation: 7478
You can you try this query :
CALL apoc.periodic.commit(
"MATCH (n:RoadPoint)
WHERE
NOT (:Depot)-[:LOCATED_AT]->(n) AND
size((n)-[:ROAD_SEGMENT]-(:RoadPoint)) <=1
WITH n LIMIT $limit
DETACH DELETE n
RETURN COUNT(*)",
{limit:1000}
)
It should works and also be much faster, thanks to the size
function, that in this case use the degrree statistic that is stored on each nodes.
Upvotes: 1