Main Content

deleteRelation

Delete relationships from Neo4j database

Description

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

example

Examples

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.

neo4jconn.Message
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.

deleteRelation(neo4jconn,relation)

Delete the two nodes by using a Neo4jNode object array.

nodes = [startnode,endnode];
deleteNode(neo4jconn,nodes)

Close the database connection.

close(neo4jconn)

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]

Version History

Introduced in R2018a