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.

updateNode

Update node labels and properties in Neo4j database

Syntax

nodeinfo = updateNode(neo4jconn,node,'Labels',labels)
nodeinfo = updateNode(neo4jconn,node,'Properties',properties)
nodeinfo = updateNode(neo4jconn,node,'Labels',labels,'Properties',properties)

Description

example

nodeinfo = updateNode(neo4jconn,node,'Labels',labels) updates existing node labels by replacing them with the specified node labels for associated nodes by using a Neo4j® database connection.

example

nodeinfo = updateNode(neo4jconn,node,'Properties',properties) updates existing node properties by replacing them with the specified node properties.

example

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

Examples

collapse all

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

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: 16
      NodeData: [1×1 struct]
    NodeLabels: []

node is a Neo4jNode object with these properties:

  • Node identifier

  • Node data

  • Node labels

Update the node with the labels Person and Employee. The output argument nodeinfo is a Neo4jNode object.

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

Display the updated node labels.

nodeinfo.NodeLabels
ans =

  2×1 cell array

    {'Person'  }
    {'Employee'}

Create a single node in a Neo4j® database, update its 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 values 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 Neo4j database using the Neo4j database connection.

node = createNode(neo4jconn)
node = 

  Neo4jNode with properties:

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

node is a Neo4jNode object with these properties:

  • Node identifier

  • Node data

  • Node labels

Update the properties of the 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'

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 values 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 single node with the node label Person. Then, using the Neo4j database connection, filter the results further by the property key and value for a specific 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. The nodeinfo output argument is a Neo4jNode object.

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

Display the updated node properties.

nodeinfo.NodeData
ans = 

  struct with fields:

     name: 'User7'
    title: 'Analyst'

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

node = createNode(neo4jconn)
node = 

  Neo4jNode with properties:

        NodeID: 55
      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 with the labels Person and Employee and with the node properties defined in the table. The nodeinfo output argument is a Neo4jNode object.

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

Display the updated node labels.

nodeinfo.NodeLabels
ans =

  2×1 cell array

    {'Person'  }
    {'Employee'}

Display the updated node properties.

nodeinfo.NodeData
ans = 

  struct with fields:

    Title: 'Analyst'
     Name: 'User8'

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 values 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 Neo4j 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 with the labels Person and Employee and with the node properties defined in the table.

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

  2×3 table

          NodeLabels      NodeData                NodeObject          
          __________    ____________    ______________________________

    56    {2×1 cell}    [1×1 struct]    [1x1 database.neo4j.Neo4jNode]
    57    {2×1 cell}    [1×1 struct]    [1x1 database.neo4j.Neo4jNode]

nodeinfo is a table that contains these variables:

  • Node labels

  • Node properties

  • Neo4jNode objects

Display the node labels for the first node.

nodeinfo.NodeLabels{1}
ans =

  2×1 cell array

    {'Person'  }
    {'Employee'}

Display the node properties for the first node.

nodeinfo.NodeData{1}
ans = 

  struct with fields:

    Title: 'Analyst'
     Name: 'User8'

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 numeric vector. For one node, specify a Neo4jNode object or numeric scalar. For multiple nodes, specify a Neo4jNode object array or 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 string array. To update multiple nodes with different node labels, use a cell array of cell arrays or 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, each field and its corresponding value convert to a property and its corresponding value in the database node. The updateNode function sets the NodeData property of the Neo4jNode object to this structure.

When you specify a table that contains one row, each variable and its corresponding value convert to a property and its corresponding value in the database node. The updateNode function 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 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