Search code examples
memgraphdb

How to write queries traversing n hops in GQLAlchemy?


I have a query that I would like to model using GQLAlchemy:

MATCH (n)-[2]->(c)
RETURN Count()

How can I do this?


Solution

  • You can do the following within GQLAlchemy to traverse using hops.

    An alternative would be to use the current syntax and a small hack. This is how the following query could be implemented in the query builder:

    MATCH ({name: 'United Kingdom'})<-[:LIVING_IN*1..2]-(n) RETURN n;
    match().node(name="United Kingdom").from_(edge_label="LIVING_IN*1..2").node(variable="n").return_({"n", "n"}).execute()