Chapter 2. Data modeling in Neo4j

 

This chapter covers

  • Why we need a data model for Neo4j
  • Domain modeling
  • Exploring additional domains

In this chapter, we’re going to talk about how and why we model data in Neo4j, and discuss approaches to data modeling in a graph database. We’ll look at alternative ways to model a given domain, making use of nodes, relationships, properties and labels in different ways. We’ll also present examples from different domains to give a sense of how flexible data modeling in Neo4j can be.

We’ll look at queries written in the Cypher query language. These are shown purely for illustration, to give an idea of how simple it is to query the models shown here: you don’t need to know anything about Cypher to start modeling data, and the language will be introduced in more detail later on.

2.1. What is a data model for Neo4j?

Unlike a traditional RDBMS (relational database management system), Neo4j is a schemaless database. You don’t need to define tables and relationships before you can start adding data. A node can have any properties you like, and any node can be related to any other node. The data model for a Neo4j database is implicit in the data it contains, rather than explicitly defined as part of the database itself. It’s a description of what you want to put in your database, rather than a set of prescriptions enforced by the database that constrain what it will accept.

2.2. Domain modeling

2.3. Further examples

2.4. Summary