Search code examples
neo4jcyphertruncatechain

Cypher Truncate Chain


I would like to cut the last node from a chain p. I get p by a query like this MATCH p=(A)-[*0..]->(B)-[*1..]->(C). I need (C) to identify the correct chain but I do not wan (C) in the chain. Can I somehow remove it from the selection p? (I do not wanr to remove it from the graph, just from the selection p)


Solution

  • If your original query looks like this:

    MATCH p=(a:A)-[*0..]->(b:B)-[*]->(c:C)
    RETURN p;
    

    You can do this, instead, to get what you want:

    MATCH p=(A)-[*0..]->(B)-[*]->(x)
    WHERE (x)-->(c:C)
    RETURN p;