Explain the basic building blocks of a Neo4j graph: nodes, relationships, and properties.

Beginner

Answer

Nodes represent entities in your data model (like Person, Product, Company). They can have:

  • Labels to categorize them (e.g., :Person, :Movie)
  • Properties as key-value pairs
    Relationships connect nodes and represent how entities are related. They:
  • Always have a direction (though can be traversed both ways)
  • Must have exactly one type (e.g., :ACTED_IN, :FRIENDS_WITH)
  • Can have properties
    Properties are key-value pairs that store data on both nodes and relationships.
    Example:
(person:Person {name: "Tom Hanks", born: 1956})
-[:ACTED_IN {role: "Forrest"}]->
(movie:Movie {title: "Forrest Gump", released: 1994})