Duplicate relationships


Just starting today to read about Neo4j, I'm already loving it. But this is the very begining of my journey, and I'm wondering very simple questions. I hope I didn't miss the obvious answer in the documentation.

Is it possible to have several output relationships of the same type ?

Like in this diagram, is is legal to have several "HAS_VERSION" relationships coming from the same entity ?

Thanks a lot !

Hey munshine, welcome to Neo4j!

Yes, it is possible to have relationships of the same type from a single node. In fact, this is going to be how your graphs are modelled most of the time as it describes the relationship between your nodes. In this case, your Component and Version nodes in a one-to-many relationship.

The following cypher query will create a graph similar to your example

CREATE (c:Component)
CREATE (v1:Version {version: 'v001'})
CREATE (v2:Version {version: 'v002'})

...and to return the graph that you've created

MATCH p = (c:Component)-[:HAS_VERSION]->(v:Version)

Just be careful of the possibility of duplicate nodes. You might want to use MERGE in the place of CREATE to avoid creating duplicate Version nodes if it is unintended.

This documentation might help you get going

1 Like

Thank you very much for the clear answer :)