%% Create Single Relationship Between Two Nodes
% Create a single relationship between two nodes in a Neo4j® database and display the relationship.
%
% 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.

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

%
% Search for the new relationship and display its relationship type.

direction = "out";
relinfo = searchRelation(neo4jconn,startnode,direction, ...
    'RelationTypes',relationtype,'Distance',2);
relinfo.Relations.RelationType

%
% Close the database connection.

close(neo4jconn)

% Copyright 2018 The MathWorks, Inc.