%% Update Properties of Existing Node
% 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 a value ranging from 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

%
% Search for a node with the label Person. Then, using the Neo4j database connection, filter the results by the property key and value for the person named User7.

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

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

%
% 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)

%
% Display the updated node properties. nodeinfo is a Neo4jNode object.

nodeid = node.NodeID;
nodeinfo = searchNodeByID(neo4jconn,nodeid);
nodeinfo.NodeData

%
% Close the database connection.

close(neo4jconn)

%
% Copyright 2018 The MathWorks, Inc.