%% Update Relationship Between Two Nodes and Return Output
% Create a single relationship between two nodes in a Neo4j® database, update the properties of the relationship, and display the properties. Access the updated relationship information using an output argument.
%
% 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

%
% Create two nodes in the database using the Neo4j database connection. Use the 'Labels' name-value pair argument to specify the label Person 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 output 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 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

%
% Close the database connection.

close(neo4jconn)

%
% Copyright 2018 The MathWorks, Inc.