Set properties for relationships in Neo4j database
setRelationProperty(
sets 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
= setRelationProperty(neo4jconn
,relation
,properties
)Neo4jRelation
object for one relationship, or as a table for multiple relationships.
Set one property for a single relationship in a Neo4j® database and access 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 = []
Retrieve the second node in the table of node information. This node has the label Person
.
nlabel = "Person";
nodeinfo = searchNode(neo4jconn,nlabel);
node = nodeinfo.NodeObject(2);
Find the outgoing relationship from the origin node.
direction = "out";
relinfo = searchRelation(neo4jconn,node,direction);
relation = relinfo.Relations.RelationObject;
Set the StartDate
property for a single relationship in the database using the Neo4j database connection.
properties.StartDate = "01/01/2018";
setRelationProperty(neo4jconn,relation,properties)
Display the relationship information for the updated relationship.
relinfo = searchRelation(neo4jconn,node,direction); relinfo.Relations.RelationData{1}
ans = struct with fields:
StartDate: '01/01/2018'
Close the database connection.
close(neo4jconn)
Set relationship properties for multiple relationships in a Neo4j® database. 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 = []
Find the origin node with the node identifier 3
and retrieve its node information.
nodeid = 3; nodeinfo = searchNodeByID(neo4jconn,nodeid);
Find the outgoing relationships from the origin node.
direction = "out";
relinfo = searchRelation(neo4jconn,nodeinfo,direction);
relation = relinfo.Relations.RelationObject;
Set the MeetLocation
property for two outgoing relationships to different values using the Neo4j database connection. Create a structure array to store the properties. The relationinfo
output argument is a Neo4jRelation
object.
properties(1).MeetLocation = "Chicago"; properties(2).MeetLocation = "Miami"; relationinfo = setRelationProperty(neo4jconn,relation,properties);
Display the relationship information for the two updated relationships.
relationinfo.RelationData{1:2}
ans = struct with fields:
MeetLocation: 'Chicago'
ans = struct with fields:
MeetLocation: 'Miami'
Close the database connection.
close(neo4jconn)
neo4jconn
— Neo4j database connectionNeo4jConnect
objectNeo4j database connection, specified as a Neo4jConnect
object created with the function neo4j
.
relation
— RelationshipNeo4jRelation
object | Neo4jRelation
object array | numeric scalar | numeric vectorRelationship 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 propertiesRelationship properties, specified as a structure, structure array, or table.
If a property does not exist, then the setRelationProperty
function adds a new property. If the property exists, then the function sets a new value
for the existing property.
When you specify a structure, the setRelationProperty
function
converts each field and its corresponding value to a property and its corresponding
value in the database relationship. When you specify a table that contains one row, the
function converts each variable and its corresponding value to a property and its
corresponding value in the database relationship.
Specify a structure array or a table with multiple rows to update multiple relationships in the database.
The dimensions of the data in the structure array or table must be the same as the number of the specified relationships in the database to update. However, you can use a scalar structure to set the same values for multiple relationships in the database simultaneously.
Data Types: struct
| table
relationinfo
— Relationship informationNeo4jRelation
object | tableRelationship 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 relationship
RelationType
— Character vector that denotes the
relationship type for each matched relationship
EndNodeID
— Node identifier of the end node for each
matched relationship
RelationData
— Structure array that contains property
keys associated with each matched relationship
RelationObject
— Neo4jRelation
object
for each matched relationship
The row names in the table are Neo4j relationship identifiers.
close
| neo4j
| removeNodeProperty
| removeRelationProperty
| searchNode
| searchNodeByID
| searchRelation
| setNodeProperty
You have a modified version of this example. Do you want to open this example with your edits?