Sales3 min read502 words

What is Neo4j? What are the benefits of Neo4j?

Burak Kaşıkcı

PlusClouds Author

Cloud & SaaS

What is Neo4j? What are the benefits of Neo4j?

Neo4j is a graph database that has the capability to store and process large and relational data, does not require much difficulty in usage (even has a query language they call similar to sql called cypher ) and is ranked high in the DB-Engines ranking. According to their own words, we can define it as "The Fastest Path to Graph" . After finding the answer to the question What is Neo4j?, there are a few important terms we use while determining our structure, let's go through them.

What are Nodes? What are Labels?

Before using the Neo4j database, let's answer the questions what are nodes and what are labels .

Nodes

Each record is a node for us. These are our main records, and we can add features we call "Properties" such as id, name, title into these records. While using these, we can utilize the label feature to keep everything more organized.

Labels

Labels, or tags, are the names we give to these groups of nodes. The information such as 'Person', 'Company', etc. that we can specify as a group will be tags representing separate nodes.

While creating a node without a label

Create (n)

we can create a node with a label as

Create (n:Person)

We can also create this node particularly together

Create (n:Person {id:1, companies: [1,2,3], name: 'Burak'})

Thus, I created a few bulk records below as I will use Person and Company information in our example.

Create (q:Person {id:1, companies: |1,2,3|, name: 'Burak'}),
(w:Person {id:2, companies: [1], name: 'Uzay'}),
(e:Person {id:3, companies: [2], name: 'Yaprak'}),
(r:Person {id:4, companies: [3], name: 'Ali'}),
(t:Person {id:5, companies: [2,4], name: 'Veli'}),
(y:Company {id:1, name: 'X Company'}),
(u:Company {id:2, name: 'Y Company'}),
(o:Company {id:3, name: 'Z Company'}),
(p:Company {id:4, name: 'Q Company'})
Here, 5 records belonging to the Person label and 4 nodes in the Company label were created.


Our Person nodes were formed as follows;

Our Company nodes are as follows;


A node can have multiple labels or none at all. These do not hold any extra features as they only perform grouping actions. All properties can be held by node information.

Relationships

Neo4j 's most important feature is the relationships we call relationships. Depending on the query we write here, it can yield amazing results quickly while establishing relationships between levels 1-1 as well as levels 2, 3, and above.

Going from the example above, it is seen that each person is connected with one or more companies. Here, we can create the relationship we will call PersonCompany by combining it with the where clause in sql logic, as follows.

Match (a:Person), (b:Company)
where (b.id IN a.companies)
create (a) - [r:PersonCompany {name:a.name+'<->'+b.name}] -> (b)
return type(r), a,b
After creating our relationships, our final view in Neo4j looks like this;



At a basic level, we have made an introduction to what a Neo4j database is and what gains it provides during use. It is up to you to develop and use these according to your needs.

Good luck! 

#There is no text provided for translation. Please provide the text you would like to be translated into English.

الأسئلة الشائعة

What is Neo4j?

Neo4j is a graph database that can store and process large relational data and is designed for ease of use. It uses a query language called Cypher, described as similar to SQL, and is promoted as The Fastest Path to Graph.

What is Cypher in Neo4j and how does it relate to SQL?

Cypher is Neo4j's query language and it is described as similar to SQL. It allows you to write queries to work with graph data and specify patterns and relationships.

What are nodes and properties in Neo4j?

Nodes are the main records in Neo4j and can have properties such as id, name, or title. Properties are stored on nodes and help describe each record.

What are labels and how are they used in Neo4j?

Labels are names assigned to groups of nodes, like Person or Company, to organize data. A node can have multiple labels or none, and labels themselves do not add features beyond grouping.

How do you create a node with or without a label in Neo4j?

To create a node without a label, you use Create (n). To create with a label, you use Create (n:Person). You can also create a labeled node with properties, such as Create (n:Person {id:1, name:'Burak'}).

How are relationships represented and created in Neo4j?

Relationships connect nodes and are a core feature. The post shows creating a PersonCompany relationship by matching a Person and a Company and then creating a directed relationship with a property describing the connection.

Can a node have multiple labels or none, and do labels add features?

Yes, a node can have multiple labels or none. Labels are used for grouping and do not add extra features; all properties remain stored on the node.