cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Bidirectional relation with self referencing nodes

The scenario is as follows
User A-[follows]->B and B-[follows]-A
with such bidirectional relation between same Node entities, load cypher for A takes indefinite to load.
<MATCH (n:User) WHERE n.id = $id WITH n, id(n) AS internalNeo4jId RETURN n{ .name, .passToken, .phoneNumber, nodeLabels: labels(n), internalNeo4jId: id(n), paths: [p = (n)-[:right_swiped|Knows|left_swiped|part_of]->()-[:right_swiped|Knows|left_swiped|part_of*0..]-()-[:right_swiped|Knows|left_swiped|part_of*0..]-()-[:right_swiped|Knows|left_swiped|part_of*0..]-() | p]}/>

This cypher is created by Spring Data neo4j but even if I copy-paste this to desktop neo4j, it times out.
My question is, does Neo4j support such relationship models? If yes than does Spring is creating the issue by creating a cypher which times out.

3 REPLIES 3

clem
Graph Steward

Do you really need an arbitrary length relationship? This fragment part_of *0.. will create a huge search space.

To see if this works at all, first try using no variable length, then a more modest variable length, e.g. part_of *1..3

I'm also not sure why you have 0 since a two nodes must have a minimum of 1 relationship.

Thanks, Clem
This cypher is created by Spring Data to fetch full Node.
I wanted to find out whether this is a Spring issue or Neo4j is not capable of handling such relation structures.

This is a problem that started coming with SDN 6. SDN 5 had @Depth annotation to limit the depth in the generated query.

I'm facing the issue and considering downgrading to SDN 5. See: java - How should one migrate from the removed @Depth annotation in Spring Data Neo4j 6? - Stack Ove...

My opinion is that it should be considered a bug in SDN where one issue is fixed but another opened. With this query, SDN attempts to load almost entire connected graph which is impractical and is not desired.