This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


Delete relationships from Neo4j database





deleteRelation(neo4jconn,relation) deletes a single relationship or multiple relationships using the Neo4j® database connection.


collapse all

Create a single relationship between two nodes in a Neo4j® database. Then, delete the relationship and the corresponding nodes.

Create a Neo4j database connection using the URL http://localhost:7474/db/data, user name neo4j, and password matlab.

url = 'http://localhost:7474/db/data';
username = 'neo4j';
password = 'matlab';

neo4jconn = neo4j(url,username,password);

Check the Message property of the Neo4j connection object neo4jconn. The blank Message property indicates a successful connection.

ans =


Create two nodes in the Neo4j database using the Neo4j database connection. Use the 'Labels' name-value pair argument to specify the Person node label for each node.

label = 'Person';
startnode = createNode(neo4jconn,'Labels',label);
endnode = createNode(neo4jconn,'Labels',label);

Create a relationship between the two nodes using the Neo4j database connection. These nodes represent two colleagues who work together. Specify the relationship type as works with.

relationtype = 'works with';
relation = createRelation(neo4jconn,startnode,endnode,relationtype)
relation = 
  Neo4jRelation with properties:

      RelationID: 17
    RelationData: [1×1 struct]
     StartNodeID: 52
    RelationType: 'works with'
       EndNodeID: 6

relation is a Neo4jRelation object with these properties:

  • Relationship identifier

  • Relationship data

  • Start node identifier

  • Relationship type

  • End node identifier

Delete the relationship.


Delete the two nodes by using a Neo4jNode object array.

nodes = [startnode,endnode];

Close the database connection.


Input Arguments

collapse all

Neo4j database connection, specified as a Neo4jConnect object created with the function neo4j.

Relationship in a Neo4j database, specified as a Neo4jRelation object, Neo4jRelation object array, numeric scalar, or numeric vector. For a single relationship, use a Neo4jRelation object or a numeric scalar that contains the relationship identifier. For multiple relationships, use a Neo4jRelation object array or a numeric vector that contains an array of relationship identifiers.

Example: 15

Example: [15,16,17]

Introduced in R2018a