Deleting Data
The object manager provides type-safe methods for deleting graph objects.
Delete by ID
Section titled “Delete by ID”// Delete a single node by UUIDval deleted = graphObjectManager.delete<Person>(uuid)
// Delete a GraphView's root node (relationships are detached)graphObjectManager.delete<RaisedAndAssignedIssue>(issueUuid)Delete with WHERE Clause
Section titled “Delete with WHERE Clause”// Delete only if condition is metgraphObjectManager.delete<Issue>(uuid, "n.state = 'closed'")
// For GraphViews, use the root fragment aliasgraphObjectManager.delete<RaisedAndAssignedIssue>(uuid, "issue.state = 'closed'")Delete All with Filter
Section titled “Delete All with Filter”// Delete all matching a conditiongraphObjectManager.deleteAll<Issue>("n.state = 'closed'")
// For GraphViewsgraphObjectManager.deleteAll<RaisedAndAssignedIssue>("issue.locked = true")Type-Safe DSL Delete
Section titled “Type-Safe DSL Delete”The most powerful way - uses generated DSL for compile-time type checking:
// Delete closed issuesgraphObjectManager.deleteAll<RaisedAndAssignedIssue> { where { issue.state eq "closed" }}
// Delete with multiple conditionsgraphObjectManager.deleteAll<RaisedAndAssignedIssue> { where { issue.state eq "open" issue.locked eq true }}
// Delete by relationship propertygraphObjectManager.deleteAll<RaisedAndAssignedIssue> { where { assignedTo.name eq "Former Employee" }}
// Delete all (no filter)graphObjectManager.deleteAll<RaisedAndAssignedIssue> { }Delete Behavior
Section titled “Delete Behavior”A delete with no cascade uses DETACH DELETE:
- Removes the node and all its relationships
- Related nodes are not deleted (only the relationships to them); a cascade, below, deletes them too
- Returns the count of deleted nodes
// Delete an issue - persons remain, only ASSIGNED_TO/RAISED_BY relationships removedgraphObjectManager.delete<RaisedAndAssignedIssue>(issueUuid)
// Verify related nodes still existval person = graphObjectManager.load<Person>(personUuid) // Still there!Delete with a Cascade
Section titled “Delete with a Cascade”Deleting a @GraphView by id can also delete the nodes the view reaches:
graphObjectManager.delete<SessionView>(sessionId) // NONE: the root onlygraphObjectManager.delete<SessionView>(sessionId, CascadeType.DELETE_ORPHAN) // and each node in the view left with no relationshipgraphObjectManager.delete<SessionView>(sessionId, CascadeType.DELETE_ALL) // and every node in the view- The cascade follows the view’s declared relationships, through nested views. A node outside the view is never deleted.
DELETE_ALLpermanently deletes nodes that other nodes may still point at. Use it for nodes the root owns.DELETE_ORPHANis not available on Memgraph.

