Search code examples
neo4jcypher

Invalid input: [, expected "+" or "-" neo4j


I ran this query in neo4j:

MATCH (n1:`Anumber`)-[*..2]-(n2)
WHERE n1 <> n2
AND all(node in nodes(n1)-[*..2]-(n2) WHERE node:`Anumber` OR node:`Bnumber`)
WITH n1, n2, COLLECT(p) AS paths
WHERE size(paths) > 1
RETURN n1, n2, size(paths) AS degree, paths

but got this error:

Invalid input '[': expected "+" or "-" (line 3, column 27 (offset: 76))
"AND all(node in nodes(n1)-[*..2]-(n2) WHERE node:`Anumber` OR node:`Bnumber`)"

How do I fix this problem?


Solution

  • You probably meant to use this logic:

    MATCH p=(n1:Anumber)-[*..2]-(n2)
    WHERE n1 <> n2 AND
      ALL(n IN NODES(p) WHERE n:Anumber OR n:Bnumber)
    WITH n1, n2, COLLECT(p) AS paths
    WHERE size(paths) > 1
    RETURN n1, n2, size(paths) AS degree, paths