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
When you want to return all nodes, relationships and paths found in a query, you can use the * symbol. This returns the two nodes, the relationship and the path used in the query.
If you want to get the labels of a specify node, then use labels(node) ; If you only want to get all node labels in neo4j, then use this function instead: call db. labels; , never ever use this query: MATCH n RETURN DISTINCT LABELS(n) . It will do a full table scan, which is very very slow..
Using count(*) to return the number of nodes. The function count(*) can be used to return the number of nodes; for example, the number of nodes connected to some node n . The labels and age property of the start node n and the number of nodes related to n are returned.
Syntax: Creating relationships When you create the relationship, it must have direction. You can query nodes for a relationship in either direction, but you must create the relationship with a direction.
The simplest way to get all relationships for a single node is like this:
MATCH (:User {username: 'user6'})-[r]-() RETURN r
The above solution doesn't return a graph representation in 3.1 anymore. Instead below solution should work
MATCH (a:User {username: 'user6'})-[r]-(b) RETURN r, a, b
This was answered in another SO question
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With