CYPHER store order of node relationships of the same label when I create

前端 未结 2 1447
庸人自扰
庸人自扰 2021-01-15 16:50

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

2条回答
  •  攒了一身酷
    2021-01-15 17:25

    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.

提交回复
热议问题