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.

updateRelation

Update relationship properties in Neo4j database

Syntax

relationinfo = updateRelation(neo4jconn,relation,properties)

Description

example

relationinfo = updateRelation(neo4jconn,relation,properties) updates the properties of a single relationship or multiple relationships using a Neo4j® database connection.

Examples

collapse all

Create a single relationship between two nodes in a Neo4j® database, update the properties of the relationship, and display the properties.

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. Specify the relationship type as works with. The relationship relationinfo is a Neo4jRelation object.

relationtype = 'works with';
relationinfo = createRelation(neo4jconn,startnode,endnode,relationtype);

Update the relationship to include two more properties. The nodes represent two colleagues who started working together on a project named Database on September 1, 2017. Specify the project name and start date as properties of the relationship by using the properties structure.

properties.Project = 'Database';
properties.StartDate = '09/01/2017';
relationinfo = updateRelation(neo4jconn,relationinfo,properties)
relationinfo = 

  Neo4jRelation with properties:

      RelationID: 25
    RelationData: [1×1 struct]
     StartNodeID: 26
    RelationType: 'works with'
       EndNodeID: 27

relationinfo is a Neo4jRelation object that contains these properties:

  • Relationship identifier

  • Relationship data

  • Start node identifier

  • Relationship type

  • End node identifier

Display the updated relationship properties.

relationinfo.RelationData
ans = 

  struct with fields:

    StartDate: '09/01/2017'
      Project: 'Database'

Create two relationships between nodes in a Neo4j® database, update the properties of the relationships, and display the 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 the node with the node label Person and the property key name set to the value User7 by using the Neo4j database connection.

nlabel = 'Person';
user7 = searchNode(neo4jconn,nlabel,'PropertyKey','name', ...
    'PropertyValue','User7');

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';
user8 = createNode(neo4jconn,'Labels',label);
user9 = createNode(neo4jconn,'Labels',label);

Create two relationships using the Neo4j database connection. Specify the relationship types as works with and studies with. The two relationships are:

  • User8 works with User7

  • User8 studies with User9

The relationship relationinfo is a table that contains the relationship and node information.

startnode = [user8,user8];
endnode = [user7,user9];
relationtype = {'works with','studies with'};
relationinfo = createRelation(neo4jconn,startnode,endnode,relationtype);

Create a table that defines the properties. Here, User8 works with User7 in the workplace, and User8 studies with User9 in the library. Also, User8 started working with User7 on January 2, 2017, and User8 started studying with User9 on March 6, 2017.

properties = table(["Workplace";"Library"],["01/02/2017";"03/06/2017"], ...
    'VariableNames',{'Location','Date'});

Update both relationships with these properties.

relations = relationinfo.RelationObject;
relationinfo = updateRelation(neo4jconn,relations,properties)
relationinfo =

  2×5 table

          StartNodeID     RelationType     EndNodeID    RelationData              RelationObject          
          ___________    ______________    _________    ____________    __________________________________

    30        28         'studies with'       38        [1×1 struct]    [1x1 database.neo4j.Neo4jRelation]
    29        28         'works with'          9        [1×1 struct]    [1x1 database.neo4j.Neo4jRelation]

relationinfo is a table with these variables:

  • Start node identifier

  • Relationship type

  • End node identifier

  • Relationship properties

  • Neo4jRelation object

Display the updated properties of the relationships.

relationinfo.RelationData{1}
relationinfo.RelationData{2}
ans = 

  struct with fields:

        Date: '01/02/2017'
    Location: 'Workplace'


ans = 

  struct with fields:

        Date: '03/06/2017'
    Location: 'Library'

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 numeric scalar that contains the relationship identifier. For multiple relationships, use a Neo4jRelation object array or numeric vector that contains an array of relationship identifiers.

Example: 15

Example: [15,16,17]

Relationship 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 relationship.

When you specify a table with one row, each variable and its corresponding value convert to a property and its corresponding value in the database relationship.

The updateRelation function sets the RelationObject variable of the relationinfo output argument to the Neo4jRelation object, which contains the relationship information.

For multiple relationships, specify a structure array or table with multiple rows.

For multiple relationships with different properties, specify a cell array of structures.

Note

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

Data Types: struct | table | cell

Output Arguments

collapse all

Relationship, returned as a Neo4jRelation object or table that contains relationship information. A Neo4jRelation object represents a single relationship. A table represents multiple relationships and contains these variables:

  • StartNodeID — Node identifier for the start node for each matched relationship

  • RelationType — Character vector that denotes the relationship type for each matched relationship

  • EndNodeID — Node identifier for the end node for each matched relationship

  • RelationData — Structure array that contains property keys associated with each matched relationship

  • RelationObjectNeo4jRelation object for each matched relationship

The row names in the table are Neo4j relationship identifiers.

Introduced in R2018a