Search code examples
neo4jcypher

get all relationships for a node with cypher


I would like to find out all the incoming and outgoing relationships for a node. I tried couple of queries suggested in other questions but not having much luck. These are the two I tried

MATCH (a:User {username: "user6"})-[r*]-(b)
RETURN a, r, b

I only have 500 nodes and it runs forever. I gave up after an hour.

I tried this

MATCH (c:User {username : 'user6'})-[r:*0..1]-(d)
WITH c, collect(r) as rs
RETURN c, rs

But I get this error

WARNING: Invalid input '*': expected whitespace or a rel type name (line 1, column 35 (offset: 34))
"MATCH (c {username : 'user6'})-[r:*0..1]-(d)"

What would be correct way to get all the relationships for a node?

I'm using version 3.0.3


Solution

  • The simplest way to get all relationships for a single node is like this:

    MATCH (:User {username: 'user6'})-[r]-()
    RETURN r