How to Model Data

Graph Data Modelling

There is no data model within Neo4j until you create data within the database.

Neo4j is schema-optional - you create the data model as you create the data.

The Golden Rule

The golden rule of graph data modeling is to model your data as a graph of nouns and verbs:

(Noun)-[:VERB]→(Noun)

Noun VERB Noun

The nouns become nodes and the verbs become relationships:

(Person)-[:PURCHASED]→(Product)

Expanding Relationships

You can expand a relationship to include more detail:

(Person)-[:PLACED]→(Order)

Describe the Data

The (Noun)-[:VERB]→(Noun) pattern allows you to describe your data in a way that is easy to understand.

(Person)-[:PLACED]→(Order) (Order)-[*]-()

Properties

Nodes & relationships with the same label or type can have different properties.

Nodes with the same label but different properties

Labels

Node labels serve as an anchor point for a query.

Nodes with Person and Movie labels

By specifying a label, you are specifying a subset of one or more nodes with which to start a query.

Multiple Labels

You can segment your graph by using multiple labels on nodes:

Person nodes also categorized as Actors and Directors

Labels allow you to target specific sub-sections of your graph.

Node | Property

Depending on your use case, you may want to deduplicate properties into Nodes:

A Movie node with a language property of 'English|'French'

Node | Property

This model offers greater flexibility and improved query performance but at the cost of semantic complexity.

Language as a separate node connected to Movie nodes

Relationships

Relationships are fast to traverse and efficient. Specialized relationship allow you to traverse the graph quickly.

A specialized RATED_5 relationship for movies with a rating of 5

Relationships

Actors rated by a user:

A specialized RATED_ACTOR relationship for actors who appeared in a movie rated by a user

Summary

In this lesson, you explored graph data modeling concepts.

Chatbot

How can I help you today?