Skip to main content

How to delete and remove objects

You can use the methods delete() and remove() to construct queries that will remove nodes and relationships or remove properties and labels.

  • delete(variable_expressions: Union[str, List[str]], detach: Optional[bool] = False) - Remove nodes and relationships. Set the argument detach to true in order to delete nodes with their relationships.
  • remove(items: Union[str, List[str]]) - Remove properties and labels.

Delete nodes

To delete a node from the database, use the delete() method:

from gqlalchemy import Match

query = Match()
.node(labels="Person", variable="p")
.delete(variable_expressions="p")
.execute()

Delete relationships

To delete a relationship from the database, use the delete() method:

from gqlalchemy import match

query = Match()
.node(labels="Person")
.to(relationship_type="FRIENDS_WITH", variable="f")
.node(labels="Person")
.delete(variable_expressions="f")
.execute()

Remove properties

To remove a property (or properties) from the database, use the remove() method:

from gqlalchemy import Match

query = Match()
.node(labels="Person", variable="p")
.remove(items=["p.name", "p.last_name"])