Is it possible to associate a node with itself in Neo4J?

The specifics of my application require that node can be connected to itself. Can this be done in Neo4J? Can a new edge be created between node and itself using the CREATE statement? Can I get it using MATCH query?

+5
source share
1 answer

Yes, it can be done .

Quote from the docs:

While relationships always have a direction, you can ignore where this is not useful in your application.

 Note that a node can have relationships to itself as well 

You can create this relationship just like any other.

 CREATE (p:Person { name: "Sam" }); MATCH (p:Person { name: "Sam" }) MERGE (p)-[:knows]->(p); 

Although, for obvious reasons, the orientation of the relationship becomes less interesting if you point the node at yourself because there is no difference between the head and tail.

+6
source

Source: https://habr.com/ru/post/1209147/


All Articles