The specifics of my app requires that a node can be linked to itself. Can it be done in Neo4J? Can a new edge be created between the node and itself using the CREATE
statement? Will I then be able to obtain it using the MATCH
query?
Yes, it can be done.
Citation from the docs:
While relationships always have a direction, you can ignore the direction where it is not useful in your application.
Note that a node can have relationships to itself as well
You can create these relationships just like any others.
CREATE (p:Person { name: "Sam" });
MATCH (p:Person { name: "Sam" })
MERGE (p)-[:knows]->(p);
Although, for obvious reasons, the directionality of a relationship becomes way less interesting if you're pointing a node to itself because there's no difference between the head and the tail.
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