A Practical Guide to CRUD in Neo4j
Create, query, update, and delete data in a graph database using Cypher.

A Practical Guide to CRUD in Neo4j
Create, query, update, and delete data in a graph database using Cypher.
Relational databases store data in rows and tables. Graph databases like Neo4j store data as nodes connected by relationships — which makes them a natural fit for anything where connections matter: social networks, recommendation engines, fraud detection, and knowledge graphs.
In this guide we’ll walk through the four operations at the heart of any database — Create, Read, Update, Delete (CRUD) — using Neo4j’s query language, Cypher. By the end you’ll be able to build a small graph, ask questions of it, change it, and clean it up.
All the queries below run in the Neo4j Browser, Neo4j Aura, or through any Neo4j driver. If you’ve loaded the built-in
:play moviesdataset, most of these will feel familiar.
The Building Blocks: Nodes and Relationships
Before writing queries, it helps to know how Cypher describes a graph visually in text:
- Nodes are written in parentheses:
(p:Person)— herepis a variable andPersonis a label. - Properties live inside curly braces:
(p:Person {name: 'Kevin Bacon', born: 1958}). - Relationships are drawn as arrows with square brackets:
(p)-[:ACTED_IN]->(m:Movie).
Read that last line out loud and it makes sense: a Person acted in a Movie. That readability is Cypher’s superpower.
1. Create — Adding Nodes and Relationships
The CREATE clause makes new nodes. Let's add a movie and an actor.
CREATE (m:Movie {title: 'Get Out', released: 2017,
tagline: 'Just because you're invited, doesn't mean you're welcome.'})
RETURN m
To create a relationship, match the nodes you want to connect (or create them inline) and draw the arrow between them:
MATCH (p:Person {name: 'Daniel Kaluuya'})
MATCH (m:Movie {title: 'Get Out'})
CREATE (p)-[:ACTED_IN {roles: ['Chris']}]->(m)
RETURN p, m
MERGE: create only if it doesn’t already exist
CREATE always makes a new node — run it twice and you get duplicates. When you want "create it if missing, otherwise reuse it," use MERGE:
MERGE (m:Movie {title: 'Rocketman'})
ON CREATE SET m.createdAt = datetime()
ON MATCH SET m.updatedAt = datetime()
SET m.tagline = 'The Only Way to Tell His Story is to Live His Fantasy.',
m.released = 2019
RETURN m
The ON CREATE block runs only when the node is brand new; ON MATCH runs only when it already existed. This is the standard pattern for safe, repeatable "upserts."
2. Read — Querying the Graph
Reading is done with MATCH to describe a pattern and RETURN to choose what comes back.
Find a single property:
MATCH (p:Person {name: 'Kevin Bacon'})
RETURN p.born
Follow a relationship — who directed Cloud Atlas?
MATCH (m:Movie {title: 'Cloud Atlas'})<-[:DIRECTED]-(p:Person)
RETURN p.name
Note the arrow direction: <-[:DIRECTED]- reads "was directed by."
Filtering with WHERE
The WHERE clause filters your matches. It uses dot notation (p.born), and property names are case-sensitive.
MATCH (p:Person)-[:ACTED_IN]->(m:Movie)
WHERE m.title = 'As Good as It Gets' AND p.born > 1960
RETURN p.name
Common beginner mistake: access properties with a dot, not a colon. Write
p.born, neverp:born. A colon is reserved for labels like:Person.
3. Update — Changing Existing Data
Use SET to add or overwrite properties. To change more than one property, separate them with commas — not AND:
MATCH (m:Movie {title: 'Get Out'})
SET m.tagline = 'Gripping, scary, witty and timely!',
m.released = 2017
RETURN m.title, m.tagline, m.released
You can also add a new label to an existing node with SET:
MATCH (p:Person {name: 'Jordan Peele'})
SET p:Director
RETURN labels(p)
And remove a property or label with REMOVE:
MATCH (m:Movie {title: 'Get Out'})
REMOVE m.tagline
RETURN m
4. Delete — Removing Data
DELETE removes nodes and relationships. The catch: you cannot delete a node that still has relationships attached — Neo4j protects you from leaving dangling arrows.
Delete a relationship only:
MATCH (p:Person {name: 'Daniel Kaluuya'})-[r:ACTED_IN]->(m:Movie {title: 'Get Out'})
DELETE r
To remove a node and all its relationships in one shot, use DETACH DELETE:
MATCH (m:Movie {title: 'Get Out'})
DETACH DELETE m
Handle with care: the query below deletes your entire database. Only run it on scratch data.
MATCH (n)
DETACH DELETE n
Quick Reference
OperationClausePurposeCreateCREATE / MERGEAdd nodes & relationships (MERGE = create-if-missing)ReadMATCH … WHERE … RETURNFind and return dataUpdateSET / REMOVEChange properties and labelsDeleteDELETE / DETACH DELETERemove relationships and nodes
Gotchas Worth Memorizing
- Use a dot for properties (
m.title) and a colon for labels (:Movie). - Separate multiple
SETassignments with commas, notAND. - Property and label names are case-sensitive:
born≠Born. - Prefer
MERGEoverCREATEwhen a node might already exist, to avoid duplicates. - Reach for
DETACH DELETEwhen a node still has relationships.
Wrapping Up
That’s the full CRUD lifecycle in Neo4j: CREATE/MERGE to build your graph, MATCH to explore it, SET to evolve it, and DELETE to tidy up. Cypher's pattern syntax means your queries look like the graph they describe — once that clicks, working with connected data starts to feel less like writing SQL and more like drawing a picture.
The best next step is to open the Neo4j Browser, load the sample movie graph with :play movies, and try each query above against real data. Change a title, follow a relationship, break something, and fix it. That's how the patterns stick.
Happy graphing.
메타데이터
- post_id
- 8a3f6dff82b4
- slug
- a-practical-guide-to-crud-in-neo4j-8a3f6dff82b4
- url
- https://medium.com/@kh.m.umerjavaid/a-practical-guide-to-crud-in-neo4j-8a3f6dff82b4
- canonical_url
- https://medium.com/@kh.m.umerjavaid/a-practical-guide-to-crud-in-neo4j-8a3f6dff82b4
- author_url
- https://medium.com/@kh.m.umerjavaid
- status
- ok
- fetched_at
- 2026-07-09 05:53:33