updateRelation
Update relationship properties in Neo4j database
Syntax
Description
updateRelation(
updates the properties for one or more relationships in a Neo4j® database using a Neo4j database connection.neo4jconn
,relation
,properties
)
returns updated relationship information as a relationinfo
= updateRelation(neo4jconn
,relation
,properties
)Neo4jRelation
object for one relationship, or as a table for multiple
relationships.
Examples
Update Relationship Between Two Nodes
Create a single relationship between two nodes in a Neo4j® database and update the properties of 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
ans = []
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'; updateRelation(neo4jconn,relationinfo,properties)
Display the updated relationship information.
relationid = relationinfo.RelationID; relationinfo = searchRelationByID(neo4jconn,relationid); relationinfo.RelationType
ans = 'works with'
relationinfo.RelationData
ans = struct with fields:
StartDate: '09/01/2017'
Project: 'Database'
Close the database connection.
close(neo4jconn)
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
ans = []
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 = Neo4jRelation with properties: RelationID: 18 RelationData: [1×1 struct] StartNodeID: 50 RelationType: 'works with' EndNodeID: 51
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'
Close the database connection.
close(neo4jconn)
Update Multiple Relationships
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
.
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 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 database using the Neo4j database connection. Use the 'Labels'
name-value pair argument to specify the label Person
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 withUser7
User8
studies withUser9
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
___________ ______________ _________ ____________ _______________________________________
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.
relationinfo.RelationData{1}
ans = struct with fields:
Date: '01/02/2017'
Location: 'Workplace'
relationinfo.RelationData{2}
ans = struct with fields:
Date: '03/06/2017'
Location: 'Library'
Close the database connection.
close(neo4jconn)
Input Arguments
neo4jconn
— Neo4j database connection
Neo4jConnect
object
Neo4j database connection, specified as a Neo4jConnect
object created with the function neo4j
.
relation
— Relationship
Neo4jRelation
object | Neo4jRelation
object array | numeric scalar | numeric vector
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 a numeric scalar that contains the
relationship identifier. For multiple relationships, use a
Neo4jRelation
object array or a numeric vector that contains an
array of relationship identifiers.
Example: 15
Example: [15,16,17]
properties
— Relationship properties
structure | structure array | table | cell array of structures
Relationship properties, specified as a structure, structure array, table, or cell array of structures.
When you specify a structure, the updateRelation
function converts each
field and its corresponding value to a property and its corresponding value in the database
relationship. When you specify a table with one row, the function converts each variable and
its corresponding value to a property and its corresponding value in the database
relationship.
The updateRelation
function also 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 updated relationship does not contain this property.
Data Types: struct
| table
| cell
Output Arguments
relationinfo
— Relationship information
Neo4jRelation
object | table
Relationship information, returned as a Neo4jRelation
object for one relationship or as a table for multiple
relationships.
For multiple relationships, the table contains these variables:
StartNodeID
— Node identifier of the start node for each matched relationshipRelationType
— Character vector that denotes the relationship type for each matched relationshipEndNodeID
— Node identifier of the end node for each matched relationshipRelationData
— Structure array that contains property keys associated with each matched relationshipRelationObject
—Neo4jRelation
object for each matched relationship
The row names in the table are Neo4j relationship identifiers.
Version History
Introduced in R2018a
Comando MATLAB
Hai fatto clic su un collegamento che corrisponde a questo comando MATLAB:
Esegui il comando inserendolo nella finestra di comando MATLAB. I browser web non supportano i comandi MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)