3 Graphs in the database

 

This chapter covers

  • An introduction to graph databases with a focus on Neo4j
  • The property graph data model
  • Using the Cypher query language to create and query data in Neo4j
  • Using client drivers for Neo4j, specifically the JavaScript Node.js driver

Fundamentally, a graph database is a software tool that allows the user to model, store, and query data as a graph. Working with a graph at the database level is often more intuitive for modeling complex connected data and can be more performant when working with complex queries that require traversing many connected entities.

In this chapter, we begin the process of creating a property graph data model using the business requirements from the previous chapter and compare it to the GraphQL schema created in the previous chapter. We then explore the Cypher query language, focusing on how to write Cypher queries to address the requirements of our application. Along the way, we show how to install Neo4j, use Neo4j Desktop to create new Neo4j projects locally, and use Neo4j Browser to query Neo4j and visualize the results. Finally, we show how to use the Neo4j JavaScript client driver to create a simple Node.js application that queries Neo4j.

3.1 Neo4j overview

3.2 Graph data modeling with Neo4j

3.2.1 The property graph model

3.2.2 Database constraints and indexes

3.3 Data modeling considerations

3.3.1 Node vs. property

3.3.2 Node vs. relationship

3.3.3 Indexes

3.3.4 Specificity of relationship types

3.3.5 Choosing a relationship direction

3.4 Tooling: Neo4j desktop

3.5 Tooling: Neo4j Browser

3.6 Cypher

3.6.1 Pattern matching

3.6.2 Properties