I have multiple relationships that stem from a node. Each of these relationships are of the same label. The relationships point to a child node (not neccesarily unique). Aft
You can use SET
to increment or decrement properties of existing relations first.
The following example shifts trueIndex
of existing relations and pushes a new relation (to an existing child node) at index 0:
MATCH (n:Root)-[r:HAS]->(c:Child)
WHERE id(n) = 0
SET r.trueIndex = r.trueIndex + 1
WITH n, min(r.trueIndex) as indexStart, max(r.trueIndex) as indexEnd
CREATE (n)-[r:HAS {trueIndex:(indexStart-1)}]->(c:Child)
WHERE id(c) = 12
RETURN n,r,c
You can modify the query according to your needs.
Design wise, I agree with @jjaderberg 's answer, it would be simpler to keep a linked list to represent an array.