Main Content

deleteNode

Delete nodes from Neo4j database

Description

example

deleteNode(neo4jconn,node) deletes a single node or multiple nodes using the Neo4j® database connection. If a specified node has an associated relationship, this syntax throws an error.

example

deleteNode(neo4jconn,node,'DeleteRelations','true') deletes nodes and their associated relationships without throwing an error.

Examples

collapse all

Create a single node in a Neo4j® database and delete the node.

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 a single node in the Neo4j database using the Neo4j database connection.

node = createNode(neo4jconn)
node = 
  Neo4jNode with properties:

        NodeID: 7
      NodeData: [1×1 struct]
    NodeLabels: []

node is a Neo4jNode object with these properties:

  • Node identifier

  • Node data

  • Node label

Delete the node using the Neo4j database connection.

deleteNode(neo4jconn,node)

Close the database connection.

close(neo4jconn)

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

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 two nodes using the Neo4j database connection. Specify the relationship type as works with.

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

      RelationID: 19
    RelationData: [1×1 struct]
     StartNodeID: 14
    RelationType: 'works with'
       EndNodeID: 15

relation is a Neo4jRelation object with these properties:

  • Relationship identifier

  • Relationship data

  • Start node identifier

  • Relationship type

  • End node identifier

Delete the first node and the associated relationship. Use this syntax to delete the node and relationship without throwing an error.

deleteNode(neo4jconn,startnode,'DeleteRelations',true)

Close the database connection.

close(neo4jconn)

Input Arguments

collapse all

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

Node in a Neo4j database, specified as a Neo4jNode object, Neo4jNode object array, numeric scalar, or a numeric vector. For one node, specify a Neo4jNode object or a numeric scalar. For multiple nodes, specify a Neo4jNode object array or a numeric vector.

The numeric scalar or vector must contain Neo4j database node identifiers.

Example: 15

Example: [2,3,4]

Version History

Introduced in R2018a