Main Content

updateNode

Update node labels and properties in Neo4j database

Description

example

updateNode(neo4jconn,node,'Labels',labels) updates existing node labels with the specified node labels using a Neo4j® database connection.

example

updateNode(neo4jconn,node,'Properties',properties) updates existing node properties with the specified node properties.

example

updateNode(neo4jconn,node,'Labels',labels,'Properties',properties) updates existing node labels and properties.

example

nodeinfo = updateNode(___) returns updated node information as a Neo4jNode object for one node, or as a table for multiple nodes, using any of the input argument combinations in the previous syntaxes.

Examples

collapse all

Create a single node in a Neo4j® database and update its node labels.

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 database using the Neo4j database connection.

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

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

node is a Neo4jNode object with these properties:

  • Node identifier

  • Node data

  • Node label

Update the node by adding the labels Person and Employee.

labels = ["Person","Employee"];
updateNode(neo4jconn,node,'Labels',labels)

Display the updated node information. nodeinfo is a Neo4jNode object.

nodeid = node.NodeID;
nodeinfo = searchNodeByID(neo4jconn,nodeid);
nodeinfo.NodeLabels
ans = 2×1 cell array
    {'Person'  }
    {'Employee'}

Close the database connection.

close(neo4jconn)

Search for an existing node in a Neo4j® database, add a node property, and display the updated node properties.

Assume that you have graph data stored in a Neo4j database that represents a social neighborhood. This database has seven nodes and eight relationships. Each node has only one unique property key name with a value ranging from User1 through User7. Each relationship has the type knows.

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 =

     []

Search for a node with the label Person. Then, using the Neo4j database connection, filter the results by the property key and value for the person named User7.

nlabel = 'Person';
node = searchNode(neo4jconn,nlabel,'PropertyKey','name', ...
    'PropertyValue','User7')
node = 
  Neo4jNode with properties:

        NodeID: 9
      NodeData: [1×1 struct]
    NodeLabels: 'Person'

node is a Neo4jNode object with these properties:

  • Node identifier

  • Node data

  • Node labels

Retrieve the existing properties of the node by using the NodeData property of the Neo4jNode object. properties is a structure.

properties = node.NodeData
properties = struct with fields:
    name: 'User7'

Update the properties of the node. Add another node property by setting a new field in the structure to specify the job title of the person.

properties.title = 'Analyst';
updateNode(neo4jconn,node,'Properties',properties)

Display the updated node properties. nodeinfo is a Neo4jNode object.

nodeid = node.NodeID;
nodeinfo = searchNodeByID(neo4jconn,nodeid);
nodeinfo.NodeData
ans = struct with fields:
     name: 'User7'
    title: 'Analyst'

Close the database connection.

close(neo4jconn)

Create a single node in a Neo4j® database, update its node labels and properties, and display them.

Assume that you have graph data stored in a Neo4j database that represents a social neighborhood. This database has seven nodes and eight relationships. Each node has only one unique property key name with a value ranging from User1 through User7. Each relationship has the type knows.

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 database using the Neo4j database connection.

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

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

node is a Neo4jNode object with these properties:

  • Node identifier

  • Node data

  • Node labels

Create a table with one row that contains data about a person. Specify the name and job title of the person.

properties = table("User8","Analyst",'VariableNames',{'Name','Title'});

Update the node by adding the labels Person and Employee and the node properties defined in the table.

labels = ["Person","Employee"];
updateNode(neo4jconn,node,'Labels',labels, ...
    'Properties',properties)

Display the updated node labels. nodeinfo is a Neo4jNode object.

nodeid = node.NodeID;
nodeinfo = searchNodeByID(neo4jconn,nodeid);
nodeinfo.NodeLabels
ans = 2×1 cell array
    {'Person'  }
    {'Employee'}

Display the updated node properties.

nodeinfo.NodeData
ans = struct with fields:
    Title: 'Analyst'
     Name: 'User8'

Close the database connection.

close(neo4jconn)

Create two nodes in a Neo4j® database, update their node labels and properties, and display the labels and properties for the first node.

Assume that you have graph data stored in a Neo4j database that represents a social neighborhood. This database has seven nodes and eight relationships. Each node has only one unique property key name with a value ranging from User1 through User7. Each relationship has the type knows.

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 database using the Neo4j database connection. These nodes represent two people.

user8 = createNode(neo4jconn);
user9 = createNode(neo4jconn);

Create a table with two rows. Each row contains data about a person. Specify the name and job title for each person.

properties = table(["User8";"User9"],["Analyst";"Technician"], ...
    'VariableNames',{'Name','Title'});

Update the nodes by adding the labels Person and Employee and the node properties defined in the table.

labels = ["Person","Employee"];
updateNode(neo4jconn,[user8;user9],'Labels',labels, ...
    'Properties',properties)

Display the node labels for the nodes.

nodeid = [user8.NodeID user9.NodeID];
nodeinfo = searchNodeByID(neo4jconn,nodeid);
nodeinfo.NodeLabels{:}
ans = 2×1 cell array
    {'Person'  }
    {'Employee'}

ans = 2×1 cell array
    {'Person'  }
    {'Employee'}

Display the node properties for the nodes.

nodeinfo.NodeData{:}
ans = struct with fields:
    Title: 'Analyst'
     Name: 'User8'

ans = struct with fields:
    Title: 'Technician'
     Name: 'User9'

Close the database connection.

close(neo4jconn)

Create a single node in a Neo4j® database, update its properties, and display them. Access the updated node information using an output argument.

Assume that you have graph data stored in a Neo4j database that represents a social neighborhood. This database has seven nodes and eight relationships. Each node has only one unique property key name with a value ranging from User1 through User7. Each relationship has the type knows.

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 database using the Neo4j database connection.

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

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

node is a Neo4jNode object with these properties:

  • Node identifier

  • Node data

  • Node labels

Update the properties of a node that represents a person. Create a table with one row that contains the name and job title for this person. The nodeinfo output argument is a Neo4jNode object.

properties = table("User8","Analyst",'VariableNames',{'Name','Title'});
nodeinfo = updateNode(neo4jconn,node,'Properties',properties);

Display the node properties.

nodeinfo.NodeData
ans = struct with fields:
    Title: 'Analyst'
     Name: 'User8'

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]

Node labels, specified as a character vector, cell array of character vectors, string scalar, string array, cell array of cell arrays, or cell array of string arrays. To specify one node label, use a character vector or string scalar. For multiple node labels, use a cell array of character vectors or a string array. To update multiple nodes with different node labels, use a cell array of cell arrays or a cell array of string arrays.

Example: 'Person'

Data Types: char | string | cell

Node properties, specified as a structure, structure array, table, or cell array of structures.

When you specify a structure, the updateNode function converts each field and its corresponding value to a property and its corresponding value in the database node. The function also sets the NodeData property of the Neo4jNode object to this structure.

When you specify a table that contains one row, the updateNode function converts each variable and its corresponding value to a property and its corresponding value in the database node. The function also converts the variables and their corresponding values to fields and their corresponding values in a structure. The function sets this structure to the NodeData property of the Neo4jNode object.

To update multiple nodes, specify a structure array or table with multiple rows.

To update multiple nodes with different properties, specify a cell array of structures.

Note

If a property is missing its corresponding value, then the updated node does not contain this property.

Data Types: struct | table | cell

Output Arguments

collapse all

Node information in the Neo4j database, returned as a Neo4jNode object for one node or as a table for multiple nodes.

For multiple nodes, the table contains these variables:

  • NodeLabels — Cell array of character vectors that contains the node labels for each database node

  • NodeData — Cell array of structures that contains node information such as property keys

  • NodeObjectNeo4jNode object for each database node

The row names of the table are Neo4j node identifiers of each database node.

Introduced in R2018a