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 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
.
Check the Message
property of the Neo4j connection object neo4jconn
. The blank Message
property indicates a successful connection.
Search for the node with the label Person
and the property key name
set to the value User7
by using the Neo4j database connection.
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.
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
relationinfo
is a table that contains the relationship and node information.
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.
Update both relationships with these properties.
relationinfo=2×5 table
StartNodeID RelationType EndNodeID RelationData RelationObject
___________ ______________ _________ ____________ _______________________________________
12 17 'works with' 9 [1×1 struct] [1x1 database.neo4j.http.Neo4jRelation]
11 17 'studies with' 18 [1×1 struct] [1x1 database.neo4j.http.Neo4jRelation]
relationinfo
is a table with these variables:
Start node identifier
Relationship type
End node identifier
Relationship data
Neo4jRelation
object
Display the updated properties of the relationships.
ans = struct with fields:
Date: '01/02/2017'
Location: 'Workplace'
ans = struct with fields:
Date: '03/06/2017'
Location: 'Library'
Close the database connection.