Issue 1:
Neo4j Version: 3.0.4

Objective of the below query is to eliminate duplicate bus service and bustop in a path, it work fine if i didn't provide the relationship count -[r:CONNECTSWITH]-> but if the relationship count defined -[r:CONNECTSWITH..3]->* ,then its throwing

Key not found: r

Working:

OPTIONAL MATCH p=(o:PORT{name:"busstop1"})-[r:CONNECTSWITH]->(d:PORT{name:"busstop2"}) where ALL(r1 in rels(p) WHERE 1=size(filter(r2 in rels(p)where(r1.service=r2.service)))) and ALL(n in nodes(p) where 1=size(filter(m in nodes(p) WHERE id(m)=id(n)))) RETURN p limit 10

Not Working:

OPTIONAL MATCH p=(o:PORT{name:"busstop1"})-[r:CONNECTSWITH*..3]->(d:PORT{name:"busstop2"}) where ALL(r1 in rels(p) WHERE 1=size(filter(r2 in rels(p)where(r1.service=r2.service)))) and ALL(n in nodes(p) where 1=size(filter(m in nodes(p) WHERE id(m)=id(n)))) RETURN p limit 10

Issue 2:
Is your feature request related to a problem? Please describe.

For better indexing, I'd like to increment a property on a node everytime a relationship is merged and decrement the same property everytime the relationship gets deleted.

Here is an example:

If I understand correctly, the following MERGE query effectively sets the properties ONLY ONCE on create, even on concurrent writes by locking the bound nodes and the relationship.

MATCH (p:Post{id:$postId})
MATCH (u:User{id:$userId})
MERGE (u)-[up:UPVOTED_POST]->(p)
ON CREATE SET p.numberOfUpvotes = p.numberOfUpvotes + 1
RETURN p, u

And to reproduce same behavior and decrement with DELETE, I've only found the following solution to work using apoc.lock.nodes:

MATCH (p:Post{id:$postId})
MATCH (u:User{id:$userId})
CALL apoc.lock.nodes([p, u])
MATCH (u)-[up:UPVOTED_POST]->(p)
DELETE up
SET p.numberOfUpvotes = p.numberOfUpvotes - 1
RETURN p, u

Without apoc.lock.nodes, concurrent writes will decrement the p.numberOfUpvotes property twice, resulting in an unreliable way to count the upvotes. This is because on concurrent writes, the MATCH (u)-[up:UPVOTED_POST]->(p) clause will effectively match in each concurrent query, the DELETE up clause will effectively return an empty up object in each concurrent query (so it's not possible to use that in a reliable way to conditionnally set the numberOfUpvotes) and the SET p.numberOfUpvotes = p.numberOfUpvotes - 1 clause will effectively decrement p.numberOfUpvotes twice. Thus, CALL apoc.lock.nodes([p, u]) or another approach to lock bound nodes is needed.

Describe the solution you'd like

Similar to MERGE, When DELETE is used on a relationship, it would acquire locks on all bound nodes and relationships in the pattern (on u, up and p in my example queries) before deleting the relationship.

Describe alternatives you've considered

Before finding the CALL apoc.lock.nodes([p, u]) solution, I thought about an ON DELETE SET syntax:

MATCH (p:Post{id:$postId})
MATCH (u:User{id:$userId})
OPTIONAL MATCH (u)-[up:UPVOTED_POST]->(p)
DELETE up
ON DELETE SET p.numberOfUpvotes = p.numberOfUpvotes - 1
RETURN p

The ON DELETE could be the syntax to add locks on bound nodes and relationships.

Additional context

Understanding the issue at play and finding the CALL apoc.lock.nodes([p, u]) solution took me about 3 days and a bit of luck. If this feature can't be implemented for reasons I didn't consider, it would be nice to have the workaround documented somewhere, at least on stack-overflow.