Search code examples
memgraphdb

Using patterns in expressions with Memgraph


When I run the follwing query, I get an error:

MATCH (n:NodeA)
WHERE NOT (n)-[]->(:NodeB)
RETURN n;

After executing it I receive an error:

Not yet implemented: atom expression '(n)-[]->(:NodeB)'

How can I run such query in Memgrpah?


Solution

  • The same query can be expressed using the OPTIONAL MATCH clause. The clause OPTIONAL MATCH behaves the same as a regular MATCH, but when it fails to find the pattern, missing parts of the pattern will be filled with null values.

    The example query would look like this:

    OPTIONAL MATCH (n:NodeA)-[]->(m:NodeB)
    WHERE m IS null
    RETURN DISTINCT n;