Neo4j - Directional Relationships



In Neo4j, Relationships between two nodes are directional. They are either Uni-Directional or Bi-Directional.

As Neo4j follows Property Graph Data Model, it should support only directional relationships. If we try to create a Relationship without any direction, then Neo4j DB server should throw an error

In this chapter, we will provide an example to prove this.

We use the following syntax to create a relationship between two nodes.

CREATE (<node1-details>)-[<relationship-details>]->(<node2-details>)

Here -

    <node1-details> is "From Node" Node details

    <node2-details> is "To Node" Node details

    <relationship-details> is Relationship details

If we observe the above syntax, it is using an arrow mark: ( ) – [ ] → ( ) . It denotes a direction from left side node to right side node.

If we try to use same syntax without arrow mark like ( ) – [ ] – ( ) , it means a Relationship without direction. Then Neo4j DB server should throw an error message

Example -

This example will prove that all Neo4j Relationships are directional.

Step 1 - Open Neo4j Data Browser.

Neo4j CQL Tutorial

It is Neo4j Data Browser Homepage

Step 2 - Type the below command on Data Browser.

CREATE (n1:Node1)-[r1:Relationship]-(n2:Node2)
Neo4j CQL Tutorial

Step 3 - Click on "Execute" button and observe the message.

Neo4j CQL Tutorial

If we observe above error message, it shows that Neo4j CQL CREATE command supports only directional relationships.

Advertisements