Main Content

updateNode

Update node labels and properties inNeo4jdatabase

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 aNeo4jNodeobject 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 URLhttp://localhost:7474/db/data, user nameneo4j, and passwordmatlab.

url ='http://localhost:7474/db/data'; username ='neo4j'; password ='matlab'; neo4jconn = neo4j(url,username,password);

Check theMessageproperty of the Neo4j connection objectneo4jconn. The blankMessageproperty 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: []

nodeis aNeo4jNodeobject with these properties:

  • Node identifier

  • Node data

  • Node label

Update the node by adding the labelsPersonandEmployee.

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

Display the updated node information.nodeinfois aNeo4jNodeobject.

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 keynamewith a value ranging fromUser1throughUser7. Each relationship has the typeknows.

Create a Neo4j database connection using the URLhttp://localhost:7474/db/data, user nameneo4j, and passwordmatlab.

url ='http://localhost:7474/db/data'; username ='neo4j'; password ='matlab'; neo4jconn = neo4j(url,username,password);

Check theMessageproperty of the Neo4j connection objectneo4jconn. The blankMessageproperty indicates a successful connection.

neo4jconn.Message
ans = []

Search for a node with the labelPerson. Then, using the Neo4j database connection, filter the results by the property key and value for the person namedUser7.

nlabel ='Person'; node = searchNode(neo4jconn,nlabel,'PropertyKey','name',...'PropertyValue','User7')
node = Neo4jNode with properties: NodeID: 9 NodeData: [1×1 struct] NodeLabels: 'Person'

nodeis aNeo4jNodeobject with these properties:

  • Node identifier

  • Node data

  • Node labels

Retrieve the existing properties of the node by using theNodeDataproperty of theNeo4jNodeobject.propertiesis 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)

显示更新后的节点支撑erties.nodeinfois aNeo4jNodeobject.

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

Close the database connection.

close(neo4jconn)

创建一个节点在一个Neo4j®数据库,更新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 keynamewith a value ranging fromUser1throughUser7. Each relationship has the typeknows.

Create a Neo4j database connection using the URLhttp://localhost:7474/db/data, user nameneo4j, and passwordmatlab.

url ='http://localhost:7474/db/data'; username ='neo4j'; password ='matlab'; neo4jconn = neo4j(url,username,password);

Check theMessageproperty of the Neo4j connection objectneo4jconn. The blankMessageproperty 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: []

nodeis aNeo4jNodeobject 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 labelsPersonandEmployeeand the node properties defined in the table.

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

Display the updated node labels.nodeinfois aNeo4jNodeobject.

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

显示更新后的节点支撑erties.

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 keynamewith a value ranging fromUser1throughUser7. Each relationship has the typeknows.

Create a Neo4j database connection using the URLhttp://localhost:7474/db/data, user nameneo4j, and passwordmatlab.

url ='http://localhost:7474/db/data'; username ='neo4j'; password ='matlab'; neo4jconn = neo4j(url,username,password);

Check theMessageproperty of the Neo4j connection objectneo4jconn. The blankMessageproperty 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 labelsPersonandEmployeeand 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)

创建一个节点在一个Neo4j®数据库,更新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 keynamewith a value ranging fromUser1throughUser7. Each relationship has the typeknows.

Create a Neo4j database connection using the URLhttp://localhost:7474/db/data, user nameneo4j, and passwordmatlab.

url ='http://localhost:7474/db/data'; username ='neo4j'; password ='matlab'; neo4jconn = neo4j(url,username,password);

Check theMessageproperty of the Neo4j connection objectneo4jconn. The blankMessageproperty 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: []

nodeis aNeo4jNodeobject 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. Thenodeinfooutput argument is aNeo4jNodeobject.

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 aNeo4jConnectobject created with the functionneo4j.

Node in a Neo4j database, specified as aNeo4jNodeobject,Neo4jNodeobject array, numeric scalar, or a numeric vector. For one node, specify aNeo4jNodeobject or a numeric scalar. For multiple nodes, specify aNeo4jNodeobject 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, theupdateNodefunction converts each field and its corresponding value to a property and its corresponding value in the database node. The function also sets theNodeDataproperty of theNeo4jNodeobject to this structure.

When you specify a table that contains one row, theupdateNode函数将每个变量及其对应ing 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 theNodeDataproperty of theNeo4jNodeobject.

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 aNeo4jNodeobject 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

  • NodeObjectNeo4jNodeobject for each database node

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

Version History

Introduced in R2018a